UIList.cpp 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253
  1. #include "StdAfx.h"
  2. namespace DuiLib {
  3. /////////////////////////////////////////////////////////////////////////////////////
  4. //
  5. //
  6. IMPLEMENT_DUICONTROL(CListUI)
  7. CListUI::CListUI()
  8. : m_pCallback(NULL)
  9. , m_bScrollSelect(false)
  10. , m_iCurSel(-1)
  11. , m_iExpandedItem(-1)
  12. , m_bMultiSel(false)
  13. , m_iFirstSel(-1)
  14. {
  15. m_pList = new CListBodyUI(this);
  16. m_pHeader = new CListHeaderUI;
  17. Add(m_pHeader);
  18. Add(m_pList);
  19. // 列表配置
  20. m_ListInfo.nColumns = 0;
  21. m_ListInfo.nFont = -1;
  22. m_ListInfo.uTextStyle = DT_VCENTER | DT_SINGLELINE;
  23. m_ListInfo.dwTextColor = 0xFF000000;
  24. m_ListInfo.dwBkColor = 0;
  25. m_ListInfo.bAlternateBk = false;
  26. m_ListInfo.dwSelectedTextColor = 0xFF000000;
  27. m_ListInfo.dwSelectedBkColor = 0xFFC1E3FF;
  28. m_ListInfo.dwHotTextColor = 0xFF000000;
  29. m_ListInfo.dwHotBkColor = 0xFFE9F5FF;
  30. m_ListInfo.dwDisabledTextColor = 0xFFCCCCCC;
  31. m_ListInfo.dwDisabledBkColor = 0xFFFFFFFF;
  32. m_ListInfo.dwLineColor = 0;
  33. m_ListInfo.bShowRowLine = false;
  34. m_ListInfo.bShowColumnLine = false;
  35. m_ListInfo.bShowHtml = false;
  36. m_ListInfo.bMultiExpandable = false;
  37. m_ListInfo.bRSelected = false;
  38. ::ZeroMemory(&m_ListInfo.rcTextPadding, sizeof(m_ListInfo.rcTextPadding));
  39. ::ZeroMemory(&m_ListInfo.rcColumn, sizeof(m_ListInfo.rcColumn));
  40. }
  41. LPCTSTR CListUI::GetClass() const
  42. {
  43. return _T("ListUI");
  44. }
  45. UINT CListUI::GetControlFlags() const
  46. {
  47. return UIFLAG_TABSTOP;
  48. }
  49. LPVOID CListUI::GetInterface(LPCTSTR pstrName)
  50. {
  51. if (_tcsicmp(pstrName, DUI_CTR_LIST) == 0) return static_cast<CListUI*>(this);
  52. if (_tcsicmp(pstrName, _T("IList")) == 0) return static_cast<IListUI*>(this);
  53. if (_tcsicmp(pstrName, _T("IListOwner")) == 0) return static_cast<IListOwnerUI*>(this);
  54. return CVerticalLayoutUI::GetInterface(pstrName);
  55. }
  56. CControlUI* CListUI::GetItemAt(int iIndex) const
  57. {
  58. return m_pList->GetItemAt(iIndex);
  59. }
  60. int CListUI::GetItemIndex(CControlUI* pControl) const
  61. {
  62. if (pControl->GetInterface(_T("ListHeader")) != NULL) return CVerticalLayoutUI::GetItemIndex(pControl);
  63. // We also need to recognize header sub-items
  64. if (_tcsstr(pControl->GetClass(), _T("ListHeaderItemUI")) != NULL) return m_pHeader->GetItemIndex(pControl);
  65. return m_pList->GetItemIndex(pControl);
  66. }
  67. bool CListUI::SetItemIndex(CControlUI* pControl, int iIndex)
  68. {
  69. if (pControl->GetInterface(_T("ListHeader")) != NULL) return CVerticalLayoutUI::SetItemIndex(pControl, iIndex);
  70. // We also need to recognize header sub-items
  71. if (_tcsstr(pControl->GetClass(), _T("ListHeaderItemUI")) != NULL) return m_pHeader->SetItemIndex(pControl, iIndex);
  72. int iOrginIndex = m_pList->GetItemIndex(pControl);
  73. if (iOrginIndex == -1) return false;
  74. if (iOrginIndex == iIndex) return true;
  75. IListItemUI* pSelectedListItem = NULL;
  76. if (m_iCurSel >= 0) pSelectedListItem =
  77. static_cast<IListItemUI*>(GetItemAt(m_iCurSel)->GetInterface(_T("ListItem")));
  78. if (!m_pList->SetItemIndex(pControl, iIndex)) return false;
  79. int iMinIndex = min(iOrginIndex, iIndex);
  80. int iMaxIndex = max(iOrginIndex, iIndex);
  81. for (int i = iMinIndex; i < iMaxIndex + 1; ++i) {
  82. CControlUI* p = m_pList->GetItemAt(i);
  83. IListItemUI* pListItem = static_cast<IListItemUI*>(p->GetInterface(_T("ListItem")));
  84. if (pListItem != NULL) {
  85. pListItem->SetIndex(i);
  86. }
  87. }
  88. if (m_iCurSel >= 0 && pSelectedListItem != NULL) m_iCurSel = pSelectedListItem->GetIndex();
  89. return true;
  90. }
  91. int CListUI::GetCount() const
  92. {
  93. return m_pList->GetCount();
  94. }
  95. bool CListUI::Add(CControlUI* pControl)
  96. {
  97. // Override the Add() method so we can add items specifically to
  98. // the intended widgets. Headers are assumed to be
  99. // answer the correct interface so we can add multiple list headers.
  100. if (pControl->GetInterface(_T("ListHeader")) != NULL) {
  101. if (m_pHeader != pControl && m_pHeader->GetCount() == 0) {
  102. CVerticalLayoutUI::Remove(m_pHeader);
  103. m_pHeader = static_cast<CListHeaderUI*>(pControl);
  104. }
  105. m_ListInfo.nColumns = MIN(m_pHeader->GetCount(), UILIST_MAX_COLUMNS);
  106. return CVerticalLayoutUI::AddAt(pControl, 0);
  107. }
  108. // We also need to recognize header sub-items
  109. if (_tcsstr(pControl->GetClass(), _T("ListHeaderItemUI")) != NULL) {
  110. bool ret = m_pHeader->Add(pControl);
  111. m_ListInfo.nColumns = MIN(m_pHeader->GetCount(), UILIST_MAX_COLUMNS);
  112. return ret;
  113. }
  114. // The list items should know about us
  115. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  116. if (pListItem != NULL) {
  117. pListItem->SetOwner(this);
  118. pListItem->SetIndex(GetCount());
  119. return m_pList->Add(pControl);
  120. }
  121. if (_tcsstr(pControl->GetClass(), _T("LabelUI")) != NULL)
  122. {
  123. return m_pList->Add(pControl);
  124. }
  125. return CVerticalLayoutUI::Add(pControl);
  126. }
  127. bool CListUI::AddAt(CControlUI* pControl, int iIndex)
  128. {
  129. // Override the AddAt() method so we can add items specifically to
  130. // the intended widgets. Headers and are assumed to be
  131. // answer the correct interface so we can add multiple list headers.
  132. if (pControl->GetInterface(_T("ListHeader")) != NULL) {
  133. if (m_pHeader != pControl && m_pHeader->GetCount() == 0) {
  134. CVerticalLayoutUI::Remove(m_pHeader);
  135. m_pHeader = static_cast<CListHeaderUI*>(pControl);
  136. }
  137. m_ListInfo.nColumns = MIN(m_pHeader->GetCount(), UILIST_MAX_COLUMNS);
  138. return CVerticalLayoutUI::AddAt(pControl, 0);
  139. }
  140. // We also need to recognize header sub-items
  141. if (_tcsstr(pControl->GetClass(), _T("ListHeaderItemUI")) != NULL) {
  142. bool ret = m_pHeader->AddAt(pControl, iIndex);
  143. m_ListInfo.nColumns = MIN(m_pHeader->GetCount(), UILIST_MAX_COLUMNS);
  144. return ret;
  145. }
  146. if (!m_pList->AddAt(pControl, iIndex)) return false;
  147. // The list items should know about us
  148. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  149. if (pListItem != NULL) {
  150. pListItem->SetOwner(this);
  151. pListItem->SetIndex(iIndex);
  152. }
  153. for (int i = iIndex + 1; i < m_pList->GetCount(); ++i) {
  154. CControlUI* p = m_pList->GetItemAt(i);
  155. pListItem = static_cast<IListItemUI*>(p->GetInterface(_T("ListItem")));
  156. if (pListItem != NULL) {
  157. pListItem->SetIndex(i);
  158. }
  159. }
  160. if (m_iCurSel >= iIndex) {
  161. int idx = m_aSelItems.Find((LPVOID)m_iCurSel);
  162. if (idx != -1) {
  163. m_aSelItems.SetAt(idx, (LPVOID*)(m_iCurSel + 1));
  164. }
  165. m_iCurSel += 1;
  166. }
  167. return true;
  168. }
  169. bool CListUI::Remove(CControlUI* pControl)
  170. {
  171. if (pControl->GetInterface(_T("ListHeader")) != NULL) return CVerticalLayoutUI::Remove(pControl);
  172. // We also need to recognize header sub-items
  173. if (_tcsstr(pControl->GetClass(), _T("ListHeaderItemUI")) != NULL) return m_pHeader->Remove(pControl);
  174. int iIndex = m_pList->GetItemIndex(pControl);
  175. if (iIndex == -1) return false;
  176. if (!m_pList->RemoveAt(iIndex)) return false;
  177. for (int i = iIndex; i < m_pList->GetCount(); ++i) {
  178. CControlUI* p = m_pList->GetItemAt(i);
  179. IListItemUI* pListItem = static_cast<IListItemUI*>(p->GetInterface(_T("ListItem")));
  180. if (pListItem != NULL) {
  181. pListItem->SetIndex(i);
  182. }
  183. }
  184. if (iIndex == m_iCurSel && m_iCurSel >= 0) {
  185. int iSel = m_iCurSel;
  186. m_iCurSel = -1;
  187. int idx = m_aSelItems.Find((LPVOID)iSel);
  188. if(idx != -1) {
  189. m_aSelItems.Remove(idx);
  190. }
  191. SelectItem(FindSelectable(iSel, false));
  192. }
  193. else if (iIndex < m_iCurSel) {
  194. m_iCurSel -= 1;
  195. for (int i = 0; i < m_aSelItems.GetSize(); ++i)
  196. {
  197. int sel = (int)m_aSelItems.GetAt(i);
  198. if (iIndex < sel)
  199. m_aSelItems.SetAt(i, (LPVOID*)(sel - 1));
  200. }
  201. }
  202. return true;
  203. }
  204. bool CListUI::RemoveAt(int iIndex)
  205. {
  206. if (!m_pList->RemoveAt(iIndex)) return false;
  207. for (int i = iIndex; i < m_pList->GetCount(); ++i) {
  208. CControlUI* p = m_pList->GetItemAt(i);
  209. IListItemUI* pListItem = static_cast<IListItemUI*>(p->GetInterface(_T("ListItem")));
  210. if (pListItem != NULL) pListItem->SetIndex(i);
  211. }
  212. if (iIndex == m_iCurSel && m_iCurSel >= 0) {
  213. int iSel = m_iCurSel;
  214. m_iCurSel = -1;
  215. int idx = m_aSelItems.Find((LPVOID)iSel);
  216. if(idx != -1) {
  217. m_aSelItems.Remove(idx);
  218. }
  219. SelectItem(FindSelectable(iSel, false));
  220. }
  221. else if (iIndex < m_iCurSel) {
  222. m_iCurSel -= 1;
  223. for (int i = 0; i < m_aSelItems.GetSize(); ++i)
  224. {
  225. int sel = (int)m_aSelItems.GetAt(i);
  226. if (iIndex < sel)
  227. m_aSelItems.SetAt(i, (LPVOID*)(sel - 1));
  228. }
  229. }
  230. return true;
  231. }
  232. void CListUI::RemoveAll()
  233. {
  234. m_iCurSel = -1;
  235. m_iExpandedItem = -1;
  236. m_aSelItems.Empty();
  237. m_pList->RemoveAll();
  238. }
  239. void CListUI::SetPos(RECT rc, bool bNeedInvalidate)
  240. {
  241. CVerticalLayoutUI::SetPos(rc, bNeedInvalidate);
  242. if (m_pHeader == NULL) return;
  243. // Determine general list information and the size of header columns
  244. m_ListInfo.nColumns = MIN(m_pHeader->GetCount(), UILIST_MAX_COLUMNS);
  245. // The header/columns may or may not be visible at runtime. In either case
  246. // we should determine the correct dimensions...
  247. if (!m_pHeader->IsVisible()) {
  248. for (int it = 0; it < m_pHeader->GetCount(); it++) {
  249. static_cast<CControlUI*>(m_pHeader->GetItemAt(it))->SetInternVisible(true);
  250. }
  251. m_pHeader->SetPos(CDuiRect(rc.left, 0, rc.right, 0), bNeedInvalidate);
  252. }
  253. for (int i = 0; i < m_ListInfo.nColumns; i++) {
  254. CControlUI* pControl = static_cast<CControlUI*>(m_pHeader->GetItemAt(i));
  255. if (!pControl->IsVisible()) continue;
  256. if (pControl->IsFloat()) continue;
  257. RECT rcPos = pControl->GetPos();
  258. m_ListInfo.rcColumn[i] = pControl->GetPos();
  259. }
  260. if (!m_pHeader->IsVisible()) {
  261. for (int it = 0; it < m_pHeader->GetCount(); it++) {
  262. static_cast<CControlUI*>(m_pHeader->GetItemAt(it))->SetInternVisible(false);
  263. }
  264. }
  265. m_pList->SetPos(m_pList->GetPos(), bNeedInvalidate);
  266. }
  267. void CListUI::Move(SIZE szOffset, bool bNeedInvalidate)
  268. {
  269. CVerticalLayoutUI::Move(szOffset, bNeedInvalidate);
  270. if (!m_pHeader->IsVisible()) m_pHeader->Move(szOffset, false);
  271. }
  272. int CListUI::GetMinSelItemIndex()
  273. {
  274. if (m_aSelItems.GetSize() <= 0)
  275. return -1;
  276. int min = (int)m_aSelItems.GetAt(0);
  277. int index;
  278. for (int i = 0; i < m_aSelItems.GetSize(); ++i)
  279. {
  280. index = (int)m_aSelItems.GetAt(i);
  281. if (min > index)
  282. min = index;
  283. }
  284. return min;
  285. }
  286. int CListUI::GetMaxSelItemIndex()
  287. {
  288. if (m_aSelItems.GetSize() <= 0)
  289. return -1;
  290. int max = (int)m_aSelItems.GetAt(0);
  291. int index;
  292. for (int i = 0; i < m_aSelItems.GetSize(); ++i)
  293. {
  294. index = (int)m_aSelItems.GetAt(i);
  295. if (max < index)
  296. max = index;
  297. }
  298. return max;
  299. }
  300. void CListUI::DoEvent(TEventUI& event)
  301. {
  302. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  303. if (m_pParent != NULL) m_pParent->DoEvent(event);
  304. else CVerticalLayoutUI::DoEvent(event);
  305. return;
  306. }
  307. if (event.Type == UIEVENT_SETFOCUS)
  308. {
  309. m_bFocused = true;
  310. return;
  311. }
  312. if (event.Type == UIEVENT_KILLFOCUS)
  313. {
  314. m_bFocused = false;
  315. return;
  316. }
  317. switch (event.Type) {
  318. case UIEVENT_KEYDOWN:
  319. switch (event.chKey) {
  320. case VK_UP:
  321. {
  322. if (m_aSelItems.GetSize() > 0) {
  323. int index = GetMinSelItemIndex() - 1;
  324. UnSelectAllItems();
  325. index > 0 ? SelectItem(index, true) : SelectItem(0, true);
  326. }
  327. }
  328. return;
  329. case VK_DOWN:
  330. {
  331. if (m_aSelItems.GetSize() > 0) {
  332. int index = GetMaxSelItemIndex() + 1;
  333. UnSelectAllItems();
  334. index + 1 > m_pList->GetCount() ? SelectItem(GetCount() - 1, true) : SelectItem(index, true);
  335. }
  336. }
  337. return;
  338. case VK_PRIOR:
  339. PageUp();
  340. return;
  341. case VK_NEXT:
  342. PageDown();
  343. return;
  344. case VK_HOME:
  345. SelectItem(FindSelectable(0, false), true);
  346. return;
  347. case VK_END:
  348. SelectItem(FindSelectable(GetCount() - 1, true), true);
  349. return;
  350. case VK_RETURN:
  351. if (m_iCurSel != -1) GetItemAt(m_iCurSel)->Activate();
  352. return;
  353. case 0x41:// Ctrl+A
  354. {
  355. //全选
  356. if (IsMultiSelect() && (GetKeyState(VK_CONTROL) & 0x8000)) {
  357. UnSelectAllItems();
  358. SelectAllItems();
  359. }
  360. return;
  361. }
  362. }
  363. break;
  364. case UIEVENT_SCROLLWHEEL:
  365. {
  366. // ★【R46】滚轮不该被「滚不动」的列表吞掉。
  367. // 原实现无论列表有没有滚动条都无条件 return(认领)。于是列表
  368. // vscrollbar="false" 时(库存台账就是这样:高度按行数写死、整页交给外层
  369. // 滚动容器滚),光标一移到表格上滚轮就被这里吃掉 —— LineUp/LineDown
  370. // 内部因 m_pVerticalScrollBar==NULL 直接 return false,什么也没发生,
  371. // 而事件**再也冒泡不上去**(CControlUI::DoEvent 末尾那条 m_pParent->DoEvent
  372. // 链被这里的 return 跳过了)。
  373. // 现在只有本列表真的能上下滚时才认领;否则落到函数末尾的
  374. // CVerticalLayoutUI::DoEvent → CControlUI::DoEvent 继续冒泡给父容器,
  375. // 由页面级滚动容器接手(等价于浏览器的 scroll chaining)。
  376. // m_bScrollSelect(滚轮挪选中项)的原语义保持优先 —— 它默认 false。
  377. switch (LOWORD(event.wParam)) {
  378. case SB_LINEUP:
  379. if (m_bScrollSelect && !IsMultiSelect()) { SelectItem(FindSelectable(m_iCurSel - 1, false), true); return; }
  380. break;
  381. case SB_LINEDOWN:
  382. if (m_bScrollSelect && !IsMultiSelect()) { SelectItem(FindSelectable(m_iCurSel + 1, true), true); return; }
  383. break;
  384. }
  385. if (m_pVerticalScrollBar != NULL && m_pVerticalScrollBar->IsVisible()
  386. && m_pVerticalScrollBar->IsEnabled()) {
  387. switch (LOWORD(event.wParam)) {
  388. case SB_LINEUP: LineUp(); return;
  389. case SB_LINEDOWN: LineDown(); return;
  390. }
  391. }
  392. }
  393. break;
  394. }
  395. CVerticalLayoutUI::DoEvent(event);
  396. }
  397. CListHeaderUI* CListUI::GetHeader() const
  398. {
  399. return m_pHeader;
  400. }
  401. CContainerUI* CListUI::GetList() const
  402. {
  403. return m_pList;
  404. }
  405. bool CListUI::GetScrollSelect()
  406. {
  407. return m_bScrollSelect;
  408. }
  409. void CListUI::SetScrollSelect(bool bScrollSelect)
  410. {
  411. m_bScrollSelect = bScrollSelect;
  412. }
  413. int CListUI::GetCurSelActivate() const
  414. {
  415. return m_iCurSelActivate;
  416. }
  417. bool CListUI::SelectItemActivate(int iIndex)
  418. {
  419. if (!SelectItem(iIndex, true)) {
  420. return false;
  421. }
  422. m_iCurSelActivate = iIndex;
  423. return true;
  424. }
  425. int CListUI::GetCurSel() const
  426. {
  427. if (m_aSelItems.GetSize() <= 0) {
  428. return -1;
  429. }
  430. else {
  431. return (int)m_aSelItems.GetAt(0);
  432. }
  433. return -1;
  434. }
  435. bool CListUI::SelectItem(int iIndex, bool bTakeFocus)
  436. {
  437. // 重置多选起始序号
  438. m_iFirstSel = -1;
  439. // 取消其它选择项
  440. UnSelectItem(iIndex, true);
  441. // 判断是否合法列表项
  442. if (iIndex < 0) return false;
  443. // 已经选择
  444. int aIndex = m_aSelItems.Find((LPVOID)iIndex);
  445. if (aIndex != -1) {
  446. return true;
  447. }
  448. // 选择当前列表项
  449. CControlUI* pControl = GetItemAt(iIndex);
  450. if (pControl == NULL) return false;
  451. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  452. if (pListItem == NULL) return false;
  453. if (!pListItem->Select(true)) {
  454. return false;
  455. }
  456. int iLastSel = m_iCurSel;
  457. m_iCurSel = iIndex;
  458. //如果已经选中了就无需要再重复加入by nakkler
  459. if(m_aSelItems.Find((LPVOID)iIndex)==-1)
  460. m_aSelItems.Add((LPVOID)iIndex);
  461. EnsureVisible(iIndex);
  462. if (bTakeFocus) pControl->SetFocus();
  463. if (m_pManager != NULL && iLastSel != m_iCurSel)
  464. {
  465. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, iIndex);
  466. }
  467. return true;
  468. }
  469. bool CListUI::SelectMultiItem(int iIndex, bool bTakeFocus)
  470. {
  471. // 未开启多选
  472. if (!IsMultiSelect()) return SelectItem(iIndex, bTakeFocus);
  473. // 全部取消
  474. if (iIndex < 0) {
  475. UnSelectAllItems();
  476. return true;
  477. }
  478. // 多选起始序号
  479. if (m_iFirstSel == -1) {
  480. if (m_iCurSel != -1) {
  481. m_iFirstSel = m_iCurSel;
  482. }
  483. else {
  484. m_iFirstSel = iIndex;
  485. }
  486. }
  487. CControlUI* pControl = GetItemAt(iIndex);
  488. if (pControl == NULL) return false;
  489. if (!pControl->IsEnabled()) return false;
  490. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  491. if (pListItem == NULL) return false;
  492. // 多选判断
  493. if ((GetKeyState(VK_CONTROL) & 0x8000)) {
  494. int aIndex = m_aSelItems.Find((LPVOID)iIndex);
  495. if (aIndex != -1) {
  496. if (!pListItem->SelectMulti(false)) return false;
  497. if (m_iCurSel == iIndex) m_iCurSel = -1;
  498. m_aSelItems.Remove(aIndex);
  499. if (m_pManager != NULL) {
  500. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, -1);
  501. }
  502. }
  503. else {
  504. if (!pListItem->SelectMulti(true)) return false;
  505. m_iCurSel = iIndex;
  506. m_aSelItems.Add((LPVOID)iIndex);
  507. EnsureVisible(iIndex);
  508. if (bTakeFocus) pControl->SetFocus();
  509. if (m_pManager != NULL) {
  510. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, iIndex);
  511. }
  512. }
  513. }
  514. else if ((GetKeyState(VK_SHIFT) & 0x8000)) {
  515. UnSelectAllItems();
  516. int iStart = m_iFirstSel;
  517. int iEnd = iIndex;
  518. if (iStart > iEnd) {
  519. iStart = iEnd;
  520. iEnd = m_iFirstSel;
  521. }
  522. for (int index = iStart; index <= iEnd; index++) {
  523. CControlUI* pSelControl = GetItemAt(index);
  524. if (pSelControl == NULL) continue;
  525. if (!pSelControl->IsEnabled()) continue;
  526. IListItemUI* pSelListItem = static_cast<IListItemUI*>(pSelControl->GetInterface(_T("ListItem")));
  527. if (pSelListItem == NULL) continue;
  528. if (!pSelListItem->SelectMulti(true)) continue;
  529. m_aSelItems.Add((LPVOID)index);
  530. }
  531. m_iCurSel = iIndex;
  532. EnsureVisible(iIndex);
  533. if (bTakeFocus) pControl->SetFocus();
  534. if (m_pManager != NULL) {
  535. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, iIndex, m_iFirstSel);
  536. }
  537. }
  538. else {
  539. if (!pListItem->SelectMulti(true)) return false;
  540. m_iCurSel = iIndex;
  541. m_aSelItems.Add((LPVOID)iIndex);
  542. EnsureVisible(iIndex);
  543. if (bTakeFocus) pControl->SetFocus();
  544. if (m_pManager != NULL) {
  545. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, iIndex);
  546. }
  547. }
  548. return true;
  549. }
  550. void CListUI::SetMultiSelect(bool bMultiSel)
  551. {
  552. m_bMultiSel = bMultiSel;
  553. if (!bMultiSel) UnSelectAllItems();
  554. }
  555. bool CListUI::IsMultiSelect() const
  556. {
  557. return m_bMultiSel;
  558. }
  559. bool CListUI::UnSelectItem(int iIndex, bool bOthers)
  560. {
  561. if (bOthers) {
  562. for (int i = m_aSelItems.GetSize() - 1; i >= 0; --i) {
  563. int iSelIndex = (int)m_aSelItems.GetAt(i);
  564. if (iSelIndex == iIndex) continue;
  565. CControlUI* pControl = GetItemAt(iSelIndex);
  566. if (pControl == NULL) continue;
  567. if (!pControl->IsEnabled()) continue;
  568. IListItemUI* pSelListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  569. if (pSelListItem == NULL) continue;
  570. if (!pSelListItem->SelectMulti(false)) continue;
  571. if (m_iCurSel == iSelIndex) m_iCurSel = -1;
  572. m_aSelItems.Remove(i);
  573. }
  574. if(IsMultiSelect()) {
  575. if (m_pManager != NULL) {
  576. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, -1, -1);
  577. }
  578. }
  579. }
  580. else {
  581. if (iIndex < 0) return false;
  582. CControlUI* pControl = GetItemAt(iIndex);
  583. if (pControl == NULL) return false;
  584. if (!pControl->IsEnabled()) return false;
  585. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  586. if (pListItem == NULL) return false;
  587. int aIndex = m_aSelItems.Find((LPVOID)iIndex);
  588. if (aIndex < 0) return false;
  589. if (!pListItem->SelectMulti(false)) return false;
  590. if (m_iCurSel == iIndex) m_iCurSel = -1;
  591. m_aSelItems.Remove(aIndex);
  592. }
  593. return true;
  594. }
  595. void CListUI::SelectAllItems()
  596. {
  597. for (int i = 0; i < GetCount(); ++i) {
  598. CControlUI* pControl = GetItemAt(i);
  599. if (pControl == NULL) continue;
  600. if (!pControl->IsVisible()) continue;
  601. if (!pControl->IsEnabled()) continue;
  602. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  603. if (pListItem == NULL) continue;
  604. if (!pListItem->SelectMulti(true)) continue;
  605. int aIndex = m_aSelItems.Find((LPVOID)i);
  606. if (aIndex < 0) {
  607. m_aSelItems.Add((LPVOID)i);
  608. }
  609. m_iCurSel = i;
  610. }
  611. if(IsMultiSelect()) {
  612. if (m_pManager != NULL) {
  613. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMSELECT, -1, -1);
  614. }
  615. }
  616. }
  617. void CListUI::UnSelectAllItems()
  618. {
  619. for (int i = 0; i < m_aSelItems.GetSize(); ++i) {
  620. int iSelIndex = (int)m_aSelItems.GetAt(i);
  621. CControlUI* pControl = GetItemAt(iSelIndex);
  622. if (pControl == NULL) continue;
  623. if (!pControl->IsEnabled()) continue;
  624. IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  625. if (pListItem == NULL) continue;
  626. if (!pListItem->SelectMulti(false)) continue;
  627. }
  628. m_aSelItems.Empty();
  629. m_iCurSel = -1;
  630. }
  631. int CListUI::GetSelectItemCount() const
  632. {
  633. return m_aSelItems.GetSize();
  634. }
  635. int CListUI::GetNextSelItem(int nItem) const
  636. {
  637. if (m_aSelItems.GetSize() <= 0)
  638. return -1;
  639. if (nItem < 0) {
  640. return (int)m_aSelItems.GetAt(0);
  641. }
  642. int aIndex = m_aSelItems.Find((LPVOID)nItem);
  643. if (aIndex < 0) return -1;
  644. if (aIndex + 1 > m_aSelItems.GetSize() - 1)
  645. return -1;
  646. return (int)m_aSelItems.GetAt(aIndex + 1);
  647. }
  648. UINT CListUI::GetListType()
  649. {
  650. return LT_LIST;
  651. }
  652. TListInfoUI* CListUI::GetListInfo()
  653. {
  654. return &m_ListInfo;
  655. }
  656. bool CListUI::IsDelayedDestroy() const
  657. {
  658. return m_pList->IsDelayedDestroy();
  659. }
  660. void CListUI::SetDelayedDestroy(bool bDelayed)
  661. {
  662. m_pList->SetDelayedDestroy(bDelayed);
  663. }
  664. int CListUI::GetChildPadding() const
  665. {
  666. return m_pList->GetChildPadding();
  667. }
  668. void CListUI::SetChildPadding(int iPadding)
  669. {
  670. m_pList->SetChildPadding(iPadding);
  671. }
  672. void CListUI::SetItemFont(int index)
  673. {
  674. m_ListInfo.nFont = index;
  675. NeedUpdate();
  676. }
  677. void CListUI::SetItemTextStyle(UINT uStyle)
  678. {
  679. m_ListInfo.uTextStyle = uStyle;
  680. NeedUpdate();
  681. }
  682. void CListUI::SetItemTextPadding(RECT rc)
  683. {
  684. m_ListInfo.rcTextPadding = rc;
  685. NeedUpdate();
  686. }
  687. RECT CListUI::GetItemTextPadding() const
  688. {
  689. RECT rect = m_ListInfo.rcTextPadding;
  690. GetManager()->GetDPIObj()->Scale(&rect);
  691. return rect;
  692. }
  693. void CListUI::SetItemTextColor(DWORD dwTextColor)
  694. {
  695. m_ListInfo.dwTextColor = dwTextColor;
  696. Invalidate();
  697. }
  698. void CListUI::SetItemBkColor(DWORD dwBkColor)
  699. {
  700. m_ListInfo.dwBkColor = dwBkColor;
  701. Invalidate();
  702. }
  703. void CListUI::SetItemBkImage(LPCTSTR pStrImage)
  704. {
  705. m_ListInfo.sBkImage = pStrImage;
  706. Invalidate();
  707. }
  708. void CListUI::SetAlternateBk(bool bAlternateBk)
  709. {
  710. m_ListInfo.bAlternateBk = bAlternateBk;
  711. Invalidate();
  712. }
  713. DWORD CListUI::GetItemTextColor() const
  714. {
  715. return m_ListInfo.dwTextColor;
  716. }
  717. DWORD CListUI::GetItemBkColor() const
  718. {
  719. return m_ListInfo.dwBkColor;
  720. }
  721. LPCTSTR CListUI::GetItemBkImage() const
  722. {
  723. return m_ListInfo.sBkImage;
  724. }
  725. bool CListUI::IsAlternateBk() const
  726. {
  727. return m_ListInfo.bAlternateBk;
  728. }
  729. void CListUI::SetSelectedItemTextColor(DWORD dwTextColor)
  730. {
  731. m_ListInfo.dwSelectedTextColor = dwTextColor;
  732. Invalidate();
  733. }
  734. void CListUI::SetSelectedItemBkColor(DWORD dwBkColor)
  735. {
  736. m_ListInfo.dwSelectedBkColor = dwBkColor;
  737. Invalidate();
  738. }
  739. void CListUI::SetSelectedItemImage(LPCTSTR pStrImage)
  740. {
  741. m_ListInfo.sSelectedImage = pStrImage;
  742. Invalidate();
  743. }
  744. DWORD CListUI::GetSelectedItemTextColor() const
  745. {
  746. return m_ListInfo.dwSelectedTextColor;
  747. }
  748. DWORD CListUI::GetSelectedItemBkColor() const
  749. {
  750. return m_ListInfo.dwSelectedBkColor;
  751. }
  752. LPCTSTR CListUI::GetSelectedItemImage() const
  753. {
  754. return m_ListInfo.sSelectedImage;
  755. }
  756. void CListUI::SetHotItemTextColor(DWORD dwTextColor)
  757. {
  758. m_ListInfo.dwHotTextColor = dwTextColor;
  759. Invalidate();
  760. }
  761. void CListUI::SetHotItemBkColor(DWORD dwBkColor)
  762. {
  763. m_ListInfo.dwHotBkColor = dwBkColor;
  764. Invalidate();
  765. }
  766. void CListUI::SetHotItemImage(LPCTSTR pStrImage)
  767. {
  768. m_ListInfo.sHotImage = pStrImage;
  769. Invalidate();
  770. }
  771. DWORD CListUI::GetHotItemTextColor() const
  772. {
  773. return m_ListInfo.dwHotTextColor;
  774. }
  775. DWORD CListUI::GetHotItemBkColor() const
  776. {
  777. return m_ListInfo.dwHotBkColor;
  778. }
  779. LPCTSTR CListUI::GetHotItemImage() const
  780. {
  781. return m_ListInfo.sHotImage;
  782. }
  783. void CListUI::SetDisabledItemTextColor(DWORD dwTextColor)
  784. {
  785. m_ListInfo.dwDisabledTextColor = dwTextColor;
  786. Invalidate();
  787. }
  788. void CListUI::SetDisabledItemBkColor(DWORD dwBkColor)
  789. {
  790. m_ListInfo.dwDisabledBkColor = dwBkColor;
  791. Invalidate();
  792. }
  793. void CListUI::SetDisabledItemImage(LPCTSTR pStrImage)
  794. {
  795. m_ListInfo.sDisabledImage = pStrImage;
  796. Invalidate();
  797. }
  798. DWORD CListUI::GetDisabledItemTextColor() const
  799. {
  800. return m_ListInfo.dwDisabledTextColor;
  801. }
  802. DWORD CListUI::GetDisabledItemBkColor() const
  803. {
  804. return m_ListInfo.dwDisabledBkColor;
  805. }
  806. LPCTSTR CListUI::GetDisabledItemImage() const
  807. {
  808. return m_ListInfo.sDisabledImage;
  809. }
  810. DWORD CListUI::GetItemLineColor() const
  811. {
  812. return m_ListInfo.dwLineColor;
  813. }
  814. void CListUI::SetItemLineColor(DWORD dwLineColor)
  815. {
  816. m_ListInfo.dwLineColor = dwLineColor;
  817. Invalidate();
  818. }
  819. void CListUI::SetItemShowRowLine(bool bShowLine)
  820. {
  821. m_ListInfo.bShowRowLine = bShowLine;
  822. Invalidate();
  823. }
  824. void CListUI::SetItemShowColumnLine(bool bShowLine)
  825. {
  826. m_ListInfo.bShowColumnLine = bShowLine;
  827. Invalidate();
  828. }
  829. bool CListUI::IsItemShowHtml()
  830. {
  831. return m_ListInfo.bShowHtml;
  832. }
  833. void CListUI::SetItemShowHtml(bool bShowHtml)
  834. {
  835. if (m_ListInfo.bShowHtml == bShowHtml) return;
  836. m_ListInfo.bShowHtml = bShowHtml;
  837. NeedUpdate();
  838. }
  839. bool CListUI::IsItemRSelected()
  840. {
  841. return m_ListInfo.bRSelected;
  842. }
  843. void CListUI::SetItemRSelected(bool bSelected)
  844. {
  845. if (m_ListInfo.bRSelected == bSelected) return;
  846. m_ListInfo.bRSelected = bSelected;
  847. NeedUpdate();
  848. }
  849. void CListUI::SetMultiExpanding(bool bMultiExpandable)
  850. {
  851. m_ListInfo.bMultiExpandable = bMultiExpandable;
  852. }
  853. bool CListUI::ExpandItem(int iIndex, bool bExpand /*= true*/)
  854. {
  855. if (m_iExpandedItem >= 0 && !m_ListInfo.bMultiExpandable) {
  856. CControlUI* pControl = GetItemAt(m_iExpandedItem);
  857. if (pControl != NULL) {
  858. IListItemUI* pItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  859. if (pItem != NULL) pItem->Expand(false);
  860. }
  861. m_iExpandedItem = -1;
  862. }
  863. if (bExpand) {
  864. CControlUI* pControl = GetItemAt(iIndex);
  865. if (pControl == NULL) return false;
  866. if (!pControl->IsVisible()) return false;
  867. IListItemUI* pItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem")));
  868. if (pItem == NULL) return false;
  869. m_iExpandedItem = iIndex;
  870. if (!pItem->Expand(true)) {
  871. m_iExpandedItem = -1;
  872. return false;
  873. }
  874. }
  875. NeedUpdate();
  876. return true;
  877. }
  878. int CListUI::GetExpandedItem() const
  879. {
  880. return m_iExpandedItem;
  881. }
  882. void CListUI::EnsureVisible(int iIndex)
  883. {
  884. //if (m_iCurSel < 0) return;
  885. RECT rcItem = m_pList->GetItemAt(iIndex)->GetPos();
  886. RECT rcList = m_pList->GetPos();
  887. RECT rcListInset = m_pList->GetInset();
  888. rcList.left += rcListInset.left;
  889. rcList.top += rcListInset.top;
  890. rcList.right -= rcListInset.right;
  891. rcList.bottom -= rcListInset.bottom;
  892. CScrollBarUI* pHorizontalScrollBar = m_pList->GetHorizontalScrollBar();
  893. if (pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()) rcList.bottom -= pHorizontalScrollBar->GetFixedHeight();
  894. int iPos = m_pList->GetScrollPos().cy;
  895. if (rcItem.top >= rcList.top && rcItem.bottom < rcList.bottom) return;
  896. int dx = 0;
  897. if (rcItem.top < rcList.top) dx = rcItem.top - rcList.top;
  898. if (rcItem.bottom > rcList.bottom) dx = rcItem.bottom - rcList.bottom;
  899. Scroll(0, dx);
  900. }
  901. void CListUI::Scroll(int dx, int dy)
  902. {
  903. if (dx == 0 && dy == 0) return;
  904. SIZE sz = m_pList->GetScrollPos();
  905. m_pList->SetScrollPos(CDuiSize(sz.cx + dx, sz.cy + dy));
  906. }
  907. void CListUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  908. {
  909. if (_tcsicmp(pstrName, _T("header")) == 0) GetHeader()->SetVisible(_tcsicmp(pstrValue, _T("hidden")) != 0);
  910. else if (_tcsicmp(pstrName, _T("headerbkimage")) == 0) GetHeader()->SetBkImage(pstrValue);
  911. else if (_tcsicmp(pstrName, _T("scrollselect")) == 0) SetScrollSelect(_tcsicmp(pstrValue, _T("true")) == 0);
  912. else if (_tcsicmp(pstrName, _T("multiexpanding")) == 0) SetMultiExpanding(_tcsicmp(pstrValue, _T("true")) == 0);
  913. else if (_tcsicmp(pstrName, _T("itemfont")) == 0) m_ListInfo.nFont = _ttoi(pstrValue);
  914. else if (_tcsicmp(pstrName, _T("itemalign")) == 0) {
  915. if (_tcsstr(pstrValue, _T("left")) != NULL) {
  916. m_ListInfo.uTextStyle &= ~(DT_CENTER | DT_RIGHT);
  917. m_ListInfo.uTextStyle |= DT_LEFT;
  918. }
  919. if (_tcsstr(pstrValue, _T("center")) != NULL) {
  920. m_ListInfo.uTextStyle &= ~(DT_LEFT | DT_RIGHT);
  921. m_ListInfo.uTextStyle |= DT_CENTER;
  922. }
  923. if (_tcsstr(pstrValue, _T("right")) != NULL) {
  924. m_ListInfo.uTextStyle &= ~(DT_LEFT | DT_CENTER);
  925. m_ListInfo.uTextStyle |= DT_RIGHT;
  926. }
  927. }
  928. else if (_tcsicmp(pstrName, _T("itemvalign")) == 0) {
  929. if (_tcsstr(pstrValue, _T("top")) != NULL) {
  930. m_ListInfo.uTextStyle &= ~(DT_VCENTER | DT_BOTTOM);
  931. m_ListInfo.uTextStyle |= DT_TOP;
  932. }
  933. if (_tcsstr(pstrValue, _T("vcenter")) != NULL) {
  934. m_ListInfo.uTextStyle &= ~(DT_TOP | DT_BOTTOM | DT_WORDBREAK);
  935. m_ListInfo.uTextStyle |= DT_VCENTER | DT_SINGLELINE;
  936. }
  937. if (_tcsstr(pstrValue, _T("bottom")) != NULL) {
  938. m_ListInfo.uTextStyle &= ~(DT_TOP | DT_VCENTER);
  939. m_ListInfo.uTextStyle |= DT_BOTTOM;
  940. }
  941. }
  942. else if (_tcsicmp(pstrName, _T("itemendellipsis")) == 0) {
  943. if (_tcsicmp(pstrValue, _T("true")) == 0) m_ListInfo.uTextStyle |= DT_END_ELLIPSIS;
  944. else m_ListInfo.uTextStyle &= ~DT_END_ELLIPSIS;
  945. }
  946. else if (_tcsicmp(pstrName, _T("itemtextpadding")) == 0) {
  947. RECT rcTextPadding = { 0 };
  948. LPTSTR pstr = NULL;
  949. rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  950. rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  951. rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  952. rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  953. SetItemTextPadding(rcTextPadding);
  954. }
  955. else if (_tcsicmp(pstrName, _T("itemtextcolor")) == 0) {
  956. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  957. LPTSTR pstr = NULL;
  958. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  959. SetItemTextColor(clrColor);
  960. }
  961. else if (_tcsicmp(pstrName, _T("itembkcolor")) == 0) {
  962. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  963. LPTSTR pstr = NULL;
  964. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  965. SetItemBkColor(clrColor);
  966. }
  967. else if (_tcsicmp(pstrName, _T("itembkimage")) == 0) SetItemBkImage(pstrValue);
  968. else if (_tcsicmp(pstrName, _T("itemaltbk")) == 0) SetAlternateBk(_tcsicmp(pstrValue, _T("true")) == 0);
  969. else if( _tcsicmp(pstrName, _T("itemforeimage")) == 0 ) {m_ListInfo.sForeImage = pstrValue; Invalidate();}
  970. else if( _tcsicmp(pstrName, _T("itemhotforeimage")) == 0 ) {m_ListInfo.sHotForeImage = pstrValue; Invalidate();}
  971. else if( _tcsicmp(pstrName, _T("itemselectedforeimage")) == 0 ) {m_ListInfo.sSelectedForeImage = pstrValue; Invalidate();}
  972. else if (_tcsicmp(pstrName, _T("itemselectedtextcolor")) == 0) {
  973. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  974. LPTSTR pstr = NULL;
  975. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  976. SetSelectedItemTextColor(clrColor);
  977. }
  978. else if (_tcsicmp(pstrName, _T("itemselectedbkcolor")) == 0) {
  979. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  980. LPTSTR pstr = NULL;
  981. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  982. SetSelectedItemBkColor(clrColor);
  983. }
  984. else if (_tcsicmp(pstrName, _T("itemselectedimage")) == 0) SetSelectedItemImage(pstrValue);
  985. else if (_tcsicmp(pstrName, _T("itemhottextcolor")) == 0) {
  986. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  987. LPTSTR pstr = NULL;
  988. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  989. SetHotItemTextColor(clrColor);
  990. }
  991. else if (_tcsicmp(pstrName, _T("itemhotbkcolor")) == 0) {
  992. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  993. LPTSTR pstr = NULL;
  994. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  995. SetHotItemBkColor(clrColor);
  996. }
  997. else if (_tcsicmp(pstrName, _T("itemhotimage")) == 0) SetHotItemImage(pstrValue);
  998. else if (_tcsicmp(pstrName, _T("itemdisabledtextcolor")) == 0) {
  999. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1000. LPTSTR pstr = NULL;
  1001. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1002. SetDisabledItemTextColor(clrColor);
  1003. }
  1004. else if (_tcsicmp(pstrName, _T("itemdisabledbkcolor")) == 0) {
  1005. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1006. LPTSTR pstr = NULL;
  1007. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1008. SetDisabledItemBkColor(clrColor);
  1009. }
  1010. else if (_tcsicmp(pstrName, _T("itemdisabledimage")) == 0) SetDisabledItemImage(pstrValue);
  1011. else if (_tcsicmp(pstrName, _T("itemlinecolor")) == 0) {
  1012. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1013. LPTSTR pstr = NULL;
  1014. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1015. SetItemLineColor(clrColor);
  1016. }
  1017. else if (_tcsicmp(pstrName, _T("itemshowrowline")) == 0) SetItemShowRowLine(_tcsicmp(pstrValue, _T("true")) == 0);
  1018. else if (_tcsicmp(pstrName, _T("itemshowcolumnline")) == 0) SetItemShowColumnLine(_tcsicmp(pstrValue, _T("true")) == 0);
  1019. else if (_tcsicmp(pstrName, _T("itemshowhtml")) == 0) SetItemShowHtml(_tcsicmp(pstrValue, _T("true")) == 0);
  1020. else if (_tcscmp(pstrName, _T("multiselect")) == 0) SetMultiSelect(_tcscmp(pstrValue, _T("true")) == 0);
  1021. else if (_tcscmp(pstrName, _T("itemrselected")) == 0) SetItemRSelected(_tcscmp(pstrValue, _T("true")) == 0);
  1022. else CVerticalLayoutUI::SetAttribute(pstrName, pstrValue);
  1023. }
  1024. IListCallbackUI* CListUI::GetTextCallback() const
  1025. {
  1026. return m_pCallback;
  1027. }
  1028. void CListUI::SetTextCallback(IListCallbackUI* pCallback)
  1029. {
  1030. m_pCallback = pCallback;
  1031. }
  1032. SIZE CListUI::GetScrollPos() const
  1033. {
  1034. return m_pList->GetScrollPos();
  1035. }
  1036. SIZE CListUI::GetScrollRange() const
  1037. {
  1038. return m_pList->GetScrollRange();
  1039. }
  1040. void CListUI::SetScrollPos(SIZE szPos, bool bMsg)
  1041. {
  1042. m_pList->SetScrollPos(szPos, bMsg);
  1043. }
  1044. void CListUI::LineUp()
  1045. {
  1046. m_pList->LineUp();
  1047. }
  1048. void CListUI::LineDown()
  1049. {
  1050. m_pList->LineDown();
  1051. }
  1052. void CListUI::PageUp()
  1053. {
  1054. m_pList->PageUp();
  1055. }
  1056. void CListUI::PageDown()
  1057. {
  1058. m_pList->PageDown();
  1059. }
  1060. void CListUI::HomeUp()
  1061. {
  1062. m_pList->HomeUp();
  1063. }
  1064. void CListUI::EndDown()
  1065. {
  1066. m_pList->EndDown();
  1067. }
  1068. void CListUI::LineLeft()
  1069. {
  1070. m_pList->LineLeft();
  1071. }
  1072. void CListUI::LineRight()
  1073. {
  1074. m_pList->LineRight();
  1075. }
  1076. void CListUI::PageLeft()
  1077. {
  1078. m_pList->PageLeft();
  1079. }
  1080. void CListUI::PageRight()
  1081. {
  1082. m_pList->PageRight();
  1083. }
  1084. void CListUI::HomeLeft()
  1085. {
  1086. m_pList->HomeLeft();
  1087. }
  1088. void CListUI::EndRight()
  1089. {
  1090. m_pList->EndRight();
  1091. }
  1092. void CListUI::EnableScrollBar(bool bEnableVertical, bool bEnableHorizontal)
  1093. {
  1094. m_pList->EnableScrollBar(bEnableVertical, bEnableHorizontal);
  1095. }
  1096. CScrollBarUI* CListUI::GetVerticalScrollBar() const
  1097. {
  1098. return m_pList->GetVerticalScrollBar();
  1099. }
  1100. CScrollBarUI* CListUI::GetHorizontalScrollBar() const
  1101. {
  1102. return m_pList->GetHorizontalScrollBar();
  1103. }
  1104. BOOL CListUI::SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData)
  1105. {
  1106. if (!m_pList)
  1107. return FALSE;
  1108. return m_pList->SortItems(pfnCompare, dwData);
  1109. }
  1110. /////////////////////////////////////////////////////////////////////////////////////
  1111. //
  1112. //
  1113. CListBodyUI::CListBodyUI(CListUI* pOwner) : m_pOwner(pOwner)
  1114. {
  1115. ASSERT(m_pOwner);
  1116. }
  1117. BOOL CListBodyUI::SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData)
  1118. {
  1119. if (!pfnCompare)
  1120. return FALSE;
  1121. m_pCompareFunc = pfnCompare;
  1122. m_compareData = dwData;
  1123. CControlUI **pData = (CControlUI **)m_items.GetData();
  1124. qsort_s(m_items.GetData(), m_items.GetSize(), sizeof(CControlUI*), CListBodyUI::ItemComareFunc, this);
  1125. IListItemUI *pItem = NULL;
  1126. for (int i = 0; i < m_items.GetSize(); ++i)
  1127. {
  1128. pItem = (IListItemUI*)(static_cast<CControlUI*>(m_items[i])->GetInterface(TEXT("ListItem")));
  1129. if (pItem)
  1130. {
  1131. pItem->SetIndex(i);
  1132. pItem->Select(false);
  1133. }
  1134. }
  1135. m_pOwner->SelectItem(-1);
  1136. if (m_pManager)
  1137. {
  1138. SetPos(GetPos());
  1139. Invalidate();
  1140. }
  1141. return TRUE;
  1142. }
  1143. int __cdecl CListBodyUI::ItemComareFunc(void *pvlocale, const void *item1, const void *item2)
  1144. {
  1145. CListBodyUI *pThis = (CListBodyUI*)pvlocale;
  1146. if (!pThis || !item1 || !item2)
  1147. return 0;
  1148. return pThis->ItemComareFunc(item1, item2);
  1149. }
  1150. int __cdecl CListBodyUI::ItemComareFunc(const void *item1, const void *item2)
  1151. {
  1152. CControlUI *pControl1 = *(CControlUI**)item1;
  1153. CControlUI *pControl2 = *(CControlUI**)item2;
  1154. return m_pCompareFunc((UINT_PTR)pControl1, (UINT_PTR)pControl2, m_compareData);
  1155. }
  1156. int CListBodyUI::GetScrollStepSize() const
  1157. {
  1158. if (m_pOwner != NULL) return m_pOwner->GetScrollStepSize();
  1159. return CVerticalLayoutUI::GetScrollStepSize();
  1160. }
  1161. void CListBodyUI::SetScrollPos(SIZE szPos, bool bMsg)
  1162. {
  1163. int cx = 0;
  1164. int cy = 0;
  1165. if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()) {
  1166. int iLastScrollPos = m_pVerticalScrollBar->GetScrollPos();
  1167. m_pVerticalScrollBar->SetScrollPos(szPos.cy);
  1168. cy = m_pVerticalScrollBar->GetScrollPos() - iLastScrollPos;
  1169. }
  1170. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible()) {
  1171. int iLastScrollPos = m_pHorizontalScrollBar->GetScrollPos();
  1172. m_pHorizontalScrollBar->SetScrollPos(szPos.cx);
  1173. cx = m_pHorizontalScrollBar->GetScrollPos() - iLastScrollPos;
  1174. }
  1175. RECT rcPos;
  1176. for (int it2 = 0; it2 < m_items.GetSize(); it2++) {
  1177. CControlUI* pControl = static_cast<CControlUI*>(m_items[it2]);
  1178. if (!pControl->IsVisible()) continue;
  1179. if (pControl->IsFloat()) continue;
  1180. rcPos = pControl->GetPos();
  1181. rcPos.left -= cx;
  1182. rcPos.right -= cx;
  1183. rcPos.top -= cy;
  1184. rcPos.bottom -= cy;
  1185. pControl->SetPos(rcPos, true);
  1186. }
  1187. Invalidate();
  1188. if (m_pOwner) {
  1189. CListHeaderUI* pHeader = m_pOwner->GetHeader();
  1190. if (pHeader == NULL) return;
  1191. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  1192. pInfo->nColumns = MIN(pHeader->GetCount(), UILIST_MAX_COLUMNS);
  1193. if (!pHeader->IsVisible()) {
  1194. for (int it = 0; it < pHeader->GetCount(); it++) {
  1195. static_cast<CControlUI*>(pHeader->GetItemAt(it))->SetInternVisible(true);
  1196. }
  1197. }
  1198. for (int i = 0; i < pInfo->nColumns; i++) {
  1199. CControlUI* pControl = static_cast<CControlUI*>(pHeader->GetItemAt(i));
  1200. if (!pControl->IsVisible()) continue;
  1201. if (pControl->IsFloat()) continue;
  1202. RECT rcPos = pControl->GetPos();
  1203. rcPos.left -= cx;
  1204. rcPos.right -= cx;
  1205. pControl->SetPos(rcPos);
  1206. pInfo->rcColumn[i] = pControl->GetPos();
  1207. }
  1208. if (!pHeader->IsVisible()) {
  1209. for (int it = 0; it < pHeader->GetCount(); it++) {
  1210. static_cast<CControlUI*>(pHeader->GetItemAt(it))->SetInternVisible(false);
  1211. }
  1212. }
  1213. }
  1214. }
  1215. void CListBodyUI::SetPos(RECT rc, bool bNeedInvalidate)
  1216. {
  1217. CControlUI::SetPos(rc, bNeedInvalidate);
  1218. for (int nPass = 0; nPass < 2; ++nPass)
  1219. {
  1220. RECT rcWork = rc;
  1221. int iChildPadding = GetChildPadding();
  1222. RECT rcInset = GetInset();
  1223. rcWork.left += rcInset.left;
  1224. rcWork.top += rcInset.top;
  1225. rcWork.right -= rcInset.right;
  1226. rcWork.bottom -= rcInset.bottom;
  1227. if (m_pOwner->IsFixedScrollbar() && m_pVerticalScrollBar)
  1228. {
  1229. rcWork.right -= m_pVerticalScrollBar->GetFixedWidth();
  1230. }
  1231. else if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible())
  1232. {
  1233. rcWork.right -= m_pVerticalScrollBar->GetFixedWidth();
  1234. }
  1235. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1236. {
  1237. rcWork.bottom -= m_pHorizontalScrollBar->GetFixedHeight();
  1238. }
  1239. SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top };
  1240. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1241. {
  1242. szAvailable.cx += m_pHorizontalScrollBar->GetScrollRange();
  1243. }
  1244. int cxNeeded = 0;
  1245. int nAdjustables = 0;
  1246. int cyFixed = 0;
  1247. int nEstimateNum = 0;
  1248. for (int it1 = 0; it1 < m_items.GetSize(); it1++)
  1249. {
  1250. CControlUI* pControl = static_cast<CControlUI*>(m_items[it1]);
  1251. if (!pControl->IsVisible()) continue;
  1252. if (pControl->IsFloat()) continue;
  1253. SIZE sz = pControl->EstimateSize(szAvailable);
  1254. if (sz.cy == 0)
  1255. {
  1256. nAdjustables++;
  1257. }
  1258. else
  1259. {
  1260. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1261. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1262. }
  1263. cyFixed += sz.cy + pControl->GetPadding().top + pControl->GetPadding().bottom;
  1264. sz.cx = MAX(sz.cx, 0);
  1265. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1266. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1267. cxNeeded = MAX(cxNeeded, sz.cx);
  1268. nEstimateNum++;
  1269. }
  1270. cyFixed += (nEstimateNum - 1) * iChildPadding;
  1271. if (m_pOwner)
  1272. {
  1273. CListHeaderUI* pHeader = m_pOwner->GetHeader();
  1274. if (pHeader != NULL && pHeader->GetCount() > 0)
  1275. {
  1276. cxNeeded = MAX(0, pHeader->EstimateSize(CDuiSize(rcWork.right - rcWork.left, rcWork.bottom - rcWork.top)).cx);
  1277. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1278. {
  1279. int nOffset = m_pHorizontalScrollBar->GetScrollPos();
  1280. RECT rcHeader = pHeader->GetPos();
  1281. rcHeader.left = rcWork.left - nOffset;
  1282. pHeader->SetPos(rcHeader);
  1283. }
  1284. }
  1285. }
  1286. int cyExpand = 0;
  1287. if (nAdjustables > 0)
  1288. {
  1289. cyExpand = MAX(0, (szAvailable.cy - cyFixed) / nAdjustables);
  1290. }
  1291. SIZE szRemaining = szAvailable;
  1292. // 可见布局坐标:受滚动条影响
  1293. int iPosY = rcWork.top;
  1294. if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible())
  1295. {
  1296. iPosY -= m_pVerticalScrollBar->GetScrollPos();
  1297. }
  1298. int iPosX = rcWork.left;
  1299. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1300. {
  1301. iPosX -= m_pHorizontalScrollBar->GetScrollPos();
  1302. }
  1303. int iAdjustable = 0;
  1304. int cyFixedRemaining = cyFixed;
  1305. // 真实内容高度:不受滚动条影响
  1306. int iContentY = rcWork.top;
  1307. int nVisibleIndex = 0;
  1308. for (int it2 = 0; it2 < m_items.GetSize(); it2++)
  1309. {
  1310. CControlUI* pControl = static_cast<CControlUI*>(m_items[it2]);
  1311. if (!pControl->IsVisible()) continue;
  1312. if (pControl->IsFloat())
  1313. {
  1314. SetFloatPos(it2);
  1315. continue;
  1316. }
  1317. RECT rcPadding = pControl->GetPadding();
  1318. szRemaining.cy -= rcPadding.top;
  1319. SIZE sz = pControl->EstimateSize(szRemaining);
  1320. if (sz.cy == 0)
  1321. {
  1322. iAdjustable++;
  1323. sz.cy = cyExpand;
  1324. if (iAdjustable == nAdjustables)
  1325. {
  1326. sz.cy = MAX(0, szRemaining.cy - rcPadding.bottom - cyFixedRemaining);
  1327. }
  1328. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1329. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1330. }
  1331. else
  1332. {
  1333. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1334. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1335. cyFixedRemaining -= sz.cy;
  1336. }
  1337. sz.cx = MAX(cxNeeded, szAvailable.cx - rcPadding.left - rcPadding.right);
  1338. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1339. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1340. RECT rcCtrl = {
  1341. iPosX + rcPadding.left,
  1342. iPosY + rcPadding.top,
  1343. iPosX + rcPadding.left + sz.cx,
  1344. iPosY + sz.cy + rcPadding.top + rcPadding.bottom
  1345. };
  1346. pControl->SetPos(rcCtrl);
  1347. // 真实内容高度按未滚动坐标累计
  1348. iContentY += sz.cy + rcPadding.top + rcPadding.bottom;
  1349. nVisibleIndex++;
  1350. if (nVisibleIndex < nEstimateNum)
  1351. {
  1352. iContentY += iChildPadding;
  1353. }
  1354. iPosY += sz.cy + iChildPadding + rcPadding.top + rcPadding.bottom;
  1355. szRemaining.cy -= sz.cy + iChildPadding + rcPadding.bottom;
  1356. }
  1357. int cyNeeded = MAX(0, iContentY - rcWork.top);
  1358. if (m_pHorizontalScrollBar != NULL)
  1359. {
  1360. if (cxNeeded > rcWork.right - rcWork.left)
  1361. {
  1362. if (m_pHorizontalScrollBar->IsVisible())
  1363. {
  1364. m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rcWork.right - rcWork.left));
  1365. }
  1366. else
  1367. {
  1368. m_pHorizontalScrollBar->SetVisible(true);
  1369. m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rcWork.right - rcWork.left));
  1370. m_pHorizontalScrollBar->SetScrollPos(0);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. if (m_pHorizontalScrollBar->IsVisible())
  1376. {
  1377. m_pHorizontalScrollBar->SetVisible(false);
  1378. m_pHorizontalScrollBar->SetScrollRange(0);
  1379. m_pHorizontalScrollBar->SetScrollPos(0);
  1380. }
  1381. }
  1382. }
  1383. ProcessScrollBar(rcWork, cxNeeded, cyNeeded);
  1384. }
  1385. }
  1386. void CListBodyUI::DoEvent(TEventUI& event)
  1387. {
  1388. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  1389. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  1390. else CVerticalLayoutUI::DoEvent(event);
  1391. return;
  1392. }
  1393. CVerticalLayoutUI::DoEvent(event);
  1394. }
  1395. /////////////////////////////////////////////////////////////////////////////////////
  1396. //
  1397. //
  1398. IMPLEMENT_DUICONTROL(CListHeaderUI)
  1399. CListHeaderUI::CListHeaderUI() :
  1400. m_bIsScaleHeader(false)
  1401. {
  1402. }
  1403. CListHeaderUI::~CListHeaderUI()
  1404. {
  1405. }
  1406. LPCTSTR CListHeaderUI::GetClass() const
  1407. {
  1408. return _T("ListHeaderUI");
  1409. }
  1410. LPVOID CListHeaderUI::GetInterface(LPCTSTR pstrName)
  1411. {
  1412. if (_tcsicmp(pstrName, DUI_CTR_LISTHEADER) == 0) return this;
  1413. return CHorizontalLayoutUI::GetInterface(pstrName);
  1414. }
  1415. SIZE CListHeaderUI::EstimateSize(SIZE szAvailable)
  1416. {
  1417. SIZE cXY = { 0, m_cxyFixed.cy };
  1418. if (cXY.cy == 0 && m_pManager != NULL) {
  1419. for (int it = 0; it < m_items.GetSize(); it++) {
  1420. cXY.cy = MAX(cXY.cy, static_cast<CControlUI*>(m_items[it])->EstimateSize(szAvailable).cy);
  1421. }
  1422. int nMin = m_pManager->GetDefaultFontInfo()->tm.tmHeight + 6;
  1423. cXY.cy = MAX(cXY.cy, nMin);
  1424. }
  1425. for (int it = 0; it < m_items.GetSize(); it++) {
  1426. cXY.cx += static_cast<CControlUI*>(m_items[it])->EstimateSize(szAvailable).cx;
  1427. }
  1428. if (cXY.cx < szAvailable.cx) cXY.cx = szAvailable.cx;
  1429. return cXY;
  1430. }
  1431. void CListHeaderUI::SetPos(RECT rc, bool bNeedInvalidate)
  1432. {
  1433. CControlUI::SetPos(rc, bNeedInvalidate);
  1434. rc = m_rcItem;
  1435. RECT rcInset = GetInset();
  1436. // Adjust for inset
  1437. rc.left += rcInset.left;
  1438. rc.top += rcInset.top;
  1439. rc.right -= rcInset.right;
  1440. rc.bottom -= rcInset.bottom;
  1441. if (m_items.GetSize() == 0) {
  1442. return;
  1443. }
  1444. int iChildPadding = GetChildPadding();
  1445. // Determine the width of elements that are sizeable
  1446. SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top };
  1447. int nAdjustables = 0;
  1448. int cxFixed = 0;
  1449. int nEstimateNum = 0;
  1450. for (int it1 = 0; it1 < m_items.GetSize(); it1++) {
  1451. CControlUI* pControl = static_cast<CControlUI*>(m_items[it1]);
  1452. if (!pControl->IsVisible()) continue;
  1453. if (pControl->IsFloat()) continue;
  1454. SIZE sz = pControl->EstimateSize(szAvailable);
  1455. if (sz.cx == 0) {
  1456. nAdjustables++;
  1457. }
  1458. else {
  1459. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1460. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1461. }
  1462. cxFixed += sz.cx + pControl->GetPadding().left + pControl->GetPadding().right;
  1463. nEstimateNum++;
  1464. }
  1465. cxFixed += (nEstimateNum - 1) * iChildPadding;
  1466. int cxExpand = 0;
  1467. int cxNeeded = 0;
  1468. if (nAdjustables > 0) cxExpand = MAX(0, (szAvailable.cx - cxFixed) / nAdjustables);
  1469. int nHeaderWidth = rc.right - rc.left;
  1470. CListUI *pList = static_cast<CListUI*>(GetParent());
  1471. if (pList != NULL) {
  1472. CScrollBarUI* pVScroll = pList->GetVerticalScrollBar();
  1473. if (pVScroll != NULL) {
  1474. nHeaderWidth -= pVScroll->GetWidth();
  1475. szAvailable.cx = nHeaderWidth;
  1476. }
  1477. }
  1478. // Position the elements
  1479. SIZE szRemaining = szAvailable;
  1480. int iPosX = rc.left;
  1481. int iAdjustable = 0;
  1482. int cxFixedRemaining = cxFixed;
  1483. for (int it2 = 0; it2 < m_items.GetSize(); it2++) {
  1484. CControlUI* pControl = static_cast<CControlUI*>(m_items[it2]);
  1485. if (!pControl->IsVisible()) continue;
  1486. if (pControl->IsFloat()) {
  1487. SetFloatPos(it2);
  1488. continue;
  1489. }
  1490. RECT rcPadding = pControl->GetPadding();
  1491. szRemaining.cx -= rcPadding.left;
  1492. SIZE sz = { 0,0 };
  1493. if (m_bIsScaleHeader) {
  1494. CListHeaderItemUI* pHeaderItem = static_cast<CListHeaderItemUI*>(pControl);
  1495. sz.cx = int(nHeaderWidth * (float)pHeaderItem->GetScale() / 100);
  1496. }
  1497. else {
  1498. sz = pControl->EstimateSize(szRemaining);
  1499. }
  1500. if (sz.cx == 0) {
  1501. iAdjustable++;
  1502. sz.cx = cxExpand;
  1503. // Distribute remaining to last element (usually round-off left-overs)
  1504. if (iAdjustable == nAdjustables) {
  1505. sz.cx = MAX(0, szRemaining.cx - rcPadding.right - cxFixedRemaining);
  1506. }
  1507. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1508. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1509. }
  1510. else {
  1511. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1512. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1513. cxFixedRemaining -= sz.cx;
  1514. }
  1515. sz.cy = pControl->GetFixedHeight();
  1516. if (sz.cy == 0) sz.cy = rc.bottom - rc.top - rcPadding.top - rcPadding.bottom;
  1517. if (sz.cy < 0) sz.cy = 0;
  1518. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1519. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1520. RECT rcCtrl = { iPosX + rcPadding.left, rc.top + rcPadding.top, iPosX + sz.cx + rcPadding.left + rcPadding.right, rc.top + rcPadding.top + sz.cy };
  1521. pControl->SetPos(rcCtrl);
  1522. iPosX += sz.cx + iChildPadding + rcPadding.left + rcPadding.right;
  1523. cxNeeded += sz.cx + rcPadding.left + rcPadding.right;
  1524. szRemaining.cx -= sz.cx + iChildPadding + rcPadding.right;
  1525. }
  1526. cxNeeded += (nEstimateNum - 1) * iChildPadding;
  1527. }
  1528. void CListHeaderUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  1529. {
  1530. if (_tcsicmp(pstrName, _T("scaleheader")) == 0) SetScaleHeader(_tcsicmp(pstrValue, _T("true")) == 0);
  1531. else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue);
  1532. }
  1533. void CListHeaderUI::SetScaleHeader(bool bIsScale)
  1534. {
  1535. m_bIsScaleHeader = bIsScale;
  1536. }
  1537. bool CListHeaderUI::IsScaleHeader() const
  1538. {
  1539. return m_bIsScaleHeader;
  1540. }
  1541. void CListHeaderUI::DoInit()
  1542. {
  1543. }
  1544. void CListHeaderUI::DoPostPaint(HDC hDC, const RECT& rcPaint)
  1545. {
  1546. }
  1547. /////////////////////////////////////////////////////////////////////////////////////
  1548. //
  1549. //
  1550. IMPLEMENT_DUICONTROL(CListHeaderItemUI)
  1551. CListHeaderItemUI::CListHeaderItemUI() : m_bDragable(true), m_uButtonState(0), m_iSepWidth(4),
  1552. m_uTextStyle(DT_VCENTER | DT_CENTER | DT_SINGLELINE), m_dwTextColor(0), m_iFont(-1), m_bShowHtml(false), m_nScale(0)
  1553. {
  1554. SetTextPadding(CDuiRect(2, 0, 2, 0));
  1555. ptLastMouse.x = ptLastMouse.y = 0;
  1556. SetMinWidth(16);
  1557. }
  1558. LPCTSTR CListHeaderItemUI::GetClass() const
  1559. {
  1560. return _T("ListHeaderItemUI");
  1561. }
  1562. LPVOID CListHeaderItemUI::GetInterface(LPCTSTR pstrName)
  1563. {
  1564. if (_tcsicmp(pstrName, DUI_CTR_LISTHEADERITEM) == 0) return this;
  1565. return CContainerUI::GetInterface(pstrName);
  1566. }
  1567. UINT CListHeaderItemUI::GetControlFlags() const
  1568. {
  1569. if (IsEnabled() && m_iSepWidth != 0) return UIFLAG_SETCURSOR;
  1570. else return 0;
  1571. }
  1572. void CListHeaderItemUI::SetEnabled(bool bEnable)
  1573. {
  1574. CContainerUI::SetEnabled(bEnable);
  1575. if (!IsEnabled()) {
  1576. m_uButtonState = 0;
  1577. }
  1578. }
  1579. bool CListHeaderItemUI::IsDragable() const
  1580. {
  1581. return m_bDragable;
  1582. }
  1583. void CListHeaderItemUI::SetDragable(bool bDragable)
  1584. {
  1585. m_bDragable = bDragable;
  1586. if (!m_bDragable) m_uButtonState &= ~UISTATE_CAPTURED;
  1587. }
  1588. DWORD CListHeaderItemUI::GetSepWidth() const
  1589. {
  1590. if(m_pManager != NULL) return m_pManager->GetDPIObj()->Scale(m_iSepWidth);
  1591. return m_iSepWidth;
  1592. }
  1593. void CListHeaderItemUI::SetSepWidth(int iWidth)
  1594. {
  1595. m_iSepWidth = iWidth;
  1596. }
  1597. DWORD CListHeaderItemUI::GetTextStyle() const
  1598. {
  1599. return m_uTextStyle;
  1600. }
  1601. void CListHeaderItemUI::SetTextStyle(UINT uStyle)
  1602. {
  1603. m_uTextStyle = uStyle;
  1604. Invalidate();
  1605. }
  1606. DWORD CListHeaderItemUI::GetTextColor() const
  1607. {
  1608. return m_dwTextColor;
  1609. }
  1610. void CListHeaderItemUI::SetTextColor(DWORD dwTextColor)
  1611. {
  1612. m_dwTextColor = dwTextColor;
  1613. }
  1614. RECT CListHeaderItemUI::GetTextPadding() const
  1615. {
  1616. RECT rcTextPadding = m_rcTextPadding;
  1617. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcTextPadding);
  1618. return rcTextPadding;
  1619. }
  1620. void CListHeaderItemUI::SetTextPadding(RECT rc)
  1621. {
  1622. m_rcTextPadding = rc;
  1623. Invalidate();
  1624. }
  1625. void CListHeaderItemUI::SetFont(int index)
  1626. {
  1627. m_iFont = index;
  1628. }
  1629. bool CListHeaderItemUI::IsShowHtml()
  1630. {
  1631. return m_bShowHtml;
  1632. }
  1633. void CListHeaderItemUI::SetShowHtml(bool bShowHtml)
  1634. {
  1635. if (m_bShowHtml == bShowHtml) return;
  1636. m_bShowHtml = bShowHtml;
  1637. Invalidate();
  1638. }
  1639. LPCTSTR CListHeaderItemUI::GetNormalImage() const
  1640. {
  1641. return m_sNormalImage;
  1642. }
  1643. void CListHeaderItemUI::SetNormalImage(LPCTSTR pStrImage)
  1644. {
  1645. m_sNormalImage = pStrImage;
  1646. Invalidate();
  1647. }
  1648. LPCTSTR CListHeaderItemUI::GetHotImage() const
  1649. {
  1650. return m_sHotImage;
  1651. }
  1652. void CListHeaderItemUI::SetHotImage(LPCTSTR pStrImage)
  1653. {
  1654. m_sHotImage = pStrImage;
  1655. Invalidate();
  1656. }
  1657. LPCTSTR CListHeaderItemUI::GetPushedImage() const
  1658. {
  1659. return m_sPushedImage;
  1660. }
  1661. void CListHeaderItemUI::SetPushedImage(LPCTSTR pStrImage)
  1662. {
  1663. m_sPushedImage = pStrImage;
  1664. Invalidate();
  1665. }
  1666. LPCTSTR CListHeaderItemUI::GetFocusedImage() const
  1667. {
  1668. return m_sFocusedImage;
  1669. }
  1670. void CListHeaderItemUI::SetFocusedImage(LPCTSTR pStrImage)
  1671. {
  1672. m_sFocusedImage = pStrImage;
  1673. Invalidate();
  1674. }
  1675. LPCTSTR CListHeaderItemUI::GetSepImage() const
  1676. {
  1677. return m_sSepImage;
  1678. }
  1679. void CListHeaderItemUI::SetSepImage(LPCTSTR pStrImage)
  1680. {
  1681. m_sSepImage = pStrImage;
  1682. Invalidate();
  1683. }
  1684. void CListHeaderItemUI::SetScale(int nScale)
  1685. {
  1686. m_nScale = nScale;
  1687. }
  1688. int CListHeaderItemUI::GetScale() const
  1689. {
  1690. return m_nScale;
  1691. }
  1692. void CListHeaderItemUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  1693. {
  1694. if (_tcsicmp(pstrName, _T("dragable")) == 0) SetDragable(_tcsicmp(pstrValue, _T("true")) == 0);
  1695. else if (_tcsicmp(pstrName, _T("sepwidth")) == 0) SetSepWidth(_ttoi(pstrValue));
  1696. else if (_tcsicmp(pstrName, _T("align")) == 0) {
  1697. if (_tcsstr(pstrValue, _T("left")) != NULL) {
  1698. m_uTextStyle &= ~(DT_CENTER | DT_RIGHT);
  1699. m_uTextStyle |= DT_LEFT;
  1700. }
  1701. if (_tcsstr(pstrValue, _T("center")) != NULL) {
  1702. m_uTextStyle &= ~(DT_LEFT | DT_RIGHT);
  1703. m_uTextStyle |= DT_CENTER;
  1704. }
  1705. if (_tcsstr(pstrValue, _T("right")) != NULL) {
  1706. m_uTextStyle &= ~(DT_LEFT | DT_CENTER);
  1707. m_uTextStyle |= DT_RIGHT;
  1708. }
  1709. }
  1710. else if (_tcsicmp(pstrName, _T("endellipsis")) == 0) {
  1711. if (_tcsicmp(pstrValue, _T("true")) == 0) m_uTextStyle |= DT_END_ELLIPSIS;
  1712. else m_uTextStyle &= ~DT_END_ELLIPSIS;
  1713. }
  1714. else if (_tcsicmp(pstrName, _T("font")) == 0) SetFont(_ttoi(pstrValue));
  1715. else if (_tcsicmp(pstrName, _T("textcolor")) == 0) {
  1716. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1717. LPTSTR pstr = NULL;
  1718. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1719. SetTextColor(clrColor);
  1720. }
  1721. else if (_tcsicmp(pstrName, _T("textpadding")) == 0) {
  1722. RECT rcTextPadding = { 0 };
  1723. LPTSTR pstr = NULL;
  1724. rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  1725. rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1726. rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1727. rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1728. SetTextPadding(rcTextPadding);
  1729. }
  1730. else if (_tcsicmp(pstrName, _T("showhtml")) == 0) SetShowHtml(_tcsicmp(pstrValue, _T("true")) == 0);
  1731. else if (_tcsicmp(pstrName, _T("normalimage")) == 0) SetNormalImage(pstrValue);
  1732. else if (_tcsicmp(pstrName, _T("hotimage")) == 0) SetHotImage(pstrValue);
  1733. else if (_tcsicmp(pstrName, _T("pushedimage")) == 0) SetPushedImage(pstrValue);
  1734. else if (_tcsicmp(pstrName, _T("focusedimage")) == 0) SetFocusedImage(pstrValue);
  1735. else if (_tcsicmp(pstrName, _T("sepimage")) == 0) SetSepImage(pstrValue);
  1736. else if (_tcsicmp(pstrName, _T("scale")) == 0) {
  1737. LPTSTR pstr = NULL;
  1738. SetScale(_tcstol(pstrValue, &pstr, 10));
  1739. }
  1740. else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue);
  1741. }
  1742. void CListHeaderItemUI::DoEvent(TEventUI& event)
  1743. {
  1744. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  1745. if (m_pParent != NULL) m_pParent->DoEvent(event);
  1746. else CContainerUI::DoEvent(event);
  1747. return;
  1748. }
  1749. if (event.Type == UIEVENT_SETFOCUS)
  1750. {
  1751. Invalidate();
  1752. }
  1753. if (event.Type == UIEVENT_KILLFOCUS)
  1754. {
  1755. Invalidate();
  1756. }
  1757. if (event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK)
  1758. {
  1759. if (!IsEnabled()) return;
  1760. RECT rcSeparator = GetThumbRect();
  1761. if (m_iSepWidth >= 0)
  1762. rcSeparator.left -= 4;
  1763. else
  1764. rcSeparator.right += 4;
  1765. if (::PtInRect(&rcSeparator, event.ptMouse)) {
  1766. if (m_bDragable) {
  1767. m_uButtonState |= UISTATE_CAPTURED;
  1768. ptLastMouse = event.ptMouse;
  1769. }
  1770. }
  1771. else {
  1772. m_uButtonState |= UISTATE_PUSHED;
  1773. m_pManager->SendNotify(this, DUI_MSGTYPE_HEADERCLICK);
  1774. Invalidate();
  1775. }
  1776. return;
  1777. }
  1778. if (event.Type == UIEVENT_BUTTONUP)
  1779. {
  1780. if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
  1781. m_uButtonState &= ~UISTATE_CAPTURED;
  1782. if (GetParent())
  1783. GetParent()->NeedParentUpdate();
  1784. }
  1785. else if ((m_uButtonState & UISTATE_PUSHED) != 0) {
  1786. m_uButtonState &= ~UISTATE_PUSHED;
  1787. Invalidate();
  1788. }
  1789. return;
  1790. }
  1791. if (event.Type == UIEVENT_MOUSEMOVE)
  1792. {
  1793. if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
  1794. RECT rcPadding = GetPadding();
  1795. RECT rc = m_rcItem;
  1796. if (m_iSepWidth >= 0) {
  1797. rc.right -= ptLastMouse.x - event.ptMouse.x;
  1798. }
  1799. else {
  1800. rc.left -= ptLastMouse.x - event.ptMouse.x;
  1801. }
  1802. if (rc.right - rc.left - rcPadding.right > GetMinWidth()) {
  1803. m_cxyFixed.cx = rc.right - rc.left - rcPadding.right;
  1804. ptLastMouse = event.ptMouse;
  1805. if (GetParent())
  1806. GetParent()->NeedParentUpdate();
  1807. }
  1808. }
  1809. return;
  1810. }
  1811. if (event.Type == UIEVENT_SETCURSOR)
  1812. {
  1813. RECT rcSeparator = GetThumbRect();
  1814. if (m_iSepWidth >= 0)
  1815. rcSeparator.left -= 4;
  1816. else
  1817. rcSeparator.right += 4;
  1818. if (IsEnabled() && m_bDragable && ::PtInRect(&rcSeparator, event.ptMouse)) {
  1819. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
  1820. return;
  1821. }
  1822. }
  1823. if (event.Type == UIEVENT_MOUSEENTER)
  1824. {
  1825. if (IsEnabled()) {
  1826. m_uButtonState |= UISTATE_HOT;
  1827. Invalidate();
  1828. }
  1829. return;
  1830. }
  1831. if (event.Type == UIEVENT_MOUSELEAVE)
  1832. {
  1833. if (IsEnabled()) {
  1834. m_uButtonState &= ~UISTATE_HOT;
  1835. Invalidate();
  1836. }
  1837. return;
  1838. }
  1839. CHorizontalLayoutUI::DoEvent(event);
  1840. }
  1841. SIZE CListHeaderItemUI::EstimateSize(SIZE szAvailable)
  1842. {
  1843. if (m_cxyFixed.cy == 0) return CDuiSize(m_cxyFixed.cx, m_pManager->GetDefaultFontInfo()->tm.tmHeight + 14);
  1844. return CHorizontalLayoutUI::EstimateSize(szAvailable);
  1845. }
  1846. RECT CListHeaderItemUI::GetThumbRect() const
  1847. {
  1848. if (m_iSepWidth >= 0) return CDuiRect(m_rcItem.right - m_iSepWidth, m_rcItem.top, m_rcItem.right, m_rcItem.bottom);
  1849. else return CDuiRect(m_rcItem.left, m_rcItem.top, m_rcItem.left - m_iSepWidth, m_rcItem.bottom);
  1850. }
  1851. void CListHeaderItemUI::PaintStatusImage(HDC hDC)
  1852. {
  1853. if (IsFocused()) m_uButtonState |= UISTATE_FOCUSED;
  1854. else m_uButtonState &= ~UISTATE_FOCUSED;
  1855. if ((m_uButtonState & UISTATE_PUSHED) != 0) {
  1856. if (m_sPushedImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1857. if (!DrawImage(hDC, (LPCTSTR)m_sPushedImage)) {}
  1858. }
  1859. else if ((m_uButtonState & UISTATE_HOT) != 0) {
  1860. if (m_sHotImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1861. if (!DrawImage(hDC, (LPCTSTR)m_sHotImage)) {}
  1862. }
  1863. else if ((m_uButtonState & UISTATE_FOCUSED) != 0) {
  1864. if (m_sFocusedImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1865. if (!DrawImage(hDC, (LPCTSTR)m_sFocusedImage)) {}
  1866. }
  1867. else {
  1868. if (!m_sNormalImage.IsEmpty()) {
  1869. if (!DrawImage(hDC, (LPCTSTR)m_sNormalImage)) {}
  1870. }
  1871. }
  1872. if (!m_sSepImage.IsEmpty()) {
  1873. RECT rcThumb = GetThumbRect();
  1874. rcThumb.left -= m_rcItem.left;
  1875. rcThumb.top -= m_rcItem.top;
  1876. rcThumb.right -= m_rcItem.left;
  1877. rcThumb.bottom -= m_rcItem.top;
  1878. m_sSepImageModify.Empty();
  1879. m_sSepImageModify.SmallFormat(_T("dest='%d,%d,%d,%d'"), rcThumb.left, rcThumb.top, rcThumb.right, rcThumb.bottom);
  1880. if (!DrawImage(hDC, (LPCTSTR)m_sSepImage, (LPCTSTR)m_sSepImageModify)) {}
  1881. }
  1882. }
  1883. void CListHeaderItemUI::PaintText(HDC hDC)
  1884. {
  1885. if (m_dwTextColor == 0) m_dwTextColor = m_pManager->GetDefaultFontColor();
  1886. RECT rcText = m_rcItem;
  1887. rcText.left += m_rcTextPadding.left;
  1888. rcText.top += m_rcTextPadding.top;
  1889. rcText.right -= m_rcTextPadding.right;
  1890. rcText.bottom -= m_rcTextPadding.bottom;
  1891. CDuiString sText = GetText();
  1892. if (sText.IsEmpty()) return;
  1893. int nLinks = 0;
  1894. if (m_bShowHtml)
  1895. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, m_dwTextColor, \
  1896. NULL, NULL, nLinks, m_iFont, m_uTextStyle);
  1897. else
  1898. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, m_dwTextColor, \
  1899. m_iFont, m_uTextStyle);
  1900. }
  1901. /////////////////////////////////////////////////////////////////////////////////////
  1902. //
  1903. //
  1904. CListElementUI::CListElementUI() : m_iIndex(-1),
  1905. m_pOwner(NULL),
  1906. m_bSelected(false),
  1907. m_uButtonState(0)
  1908. {
  1909. }
  1910. LPCTSTR CListElementUI::GetClass() const
  1911. {
  1912. return _T("ListElementUI");
  1913. }
  1914. UINT CListElementUI::GetControlFlags() const
  1915. {
  1916. return UIFLAG_WANTRETURN;
  1917. }
  1918. LPVOID CListElementUI::GetInterface(LPCTSTR pstrName)
  1919. {
  1920. if (_tcsicmp(pstrName, DUI_CTR_LISTITEM) == 0) return static_cast<IListItemUI*>(this);
  1921. if (_tcsicmp(pstrName, DUI_CTR_LISTELEMENT) == 0) return static_cast<CListElementUI*>(this);
  1922. return CControlUI::GetInterface(pstrName);
  1923. }
  1924. IListOwnerUI* CListElementUI::GetOwner()
  1925. {
  1926. return m_pOwner;
  1927. }
  1928. void CListElementUI::SetOwner(CControlUI* pOwner)
  1929. {
  1930. m_pOwner = static_cast<IListOwnerUI*>(pOwner->GetInterface(_T("IListOwner")));
  1931. }
  1932. void CListElementUI::SetVisible(bool bVisible)
  1933. {
  1934. CControlUI::SetVisible(bVisible);
  1935. if (!IsVisible() && m_bSelected)
  1936. {
  1937. m_bSelected = false;
  1938. if (m_pOwner != NULL) m_pOwner->SelectItem(-1);
  1939. }
  1940. }
  1941. void CListElementUI::SetEnabled(bool bEnable)
  1942. {
  1943. CControlUI::SetEnabled(bEnable);
  1944. if (!IsEnabled()) {
  1945. m_uButtonState = 0;
  1946. }
  1947. }
  1948. int CListElementUI::GetIndex() const
  1949. {
  1950. return m_iIndex;
  1951. }
  1952. void CListElementUI::SetIndex(int iIndex)
  1953. {
  1954. m_iIndex = iIndex;
  1955. }
  1956. void CListElementUI::Invalidate()
  1957. {
  1958. if (!IsVisible()) return;
  1959. if (GetParent()) {
  1960. CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
  1961. if (pParentContainer) {
  1962. RECT rc = pParentContainer->GetPos();
  1963. RECT rcInset = pParentContainer->GetInset();
  1964. rc.left += rcInset.left;
  1965. rc.top += rcInset.top;
  1966. rc.right -= rcInset.right;
  1967. rc.bottom -= rcInset.bottom;
  1968. CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
  1969. if (pVerticalScrollBar && pVerticalScrollBar->IsVisible()) rc.right -= pVerticalScrollBar->GetFixedWidth();
  1970. CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
  1971. if (pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
  1972. RECT invalidateRc = m_rcItem;
  1973. if (!::IntersectRect(&invalidateRc, &m_rcItem, &rc))
  1974. {
  1975. return;
  1976. }
  1977. CControlUI* pParent = GetParent();
  1978. RECT rcTemp;
  1979. RECT rcParent;
  1980. while (pParent = pParent->GetParent())
  1981. {
  1982. rcTemp = invalidateRc;
  1983. rcParent = pParent->GetPos();
  1984. if (!::IntersectRect(&invalidateRc, &rcTemp, &rcParent))
  1985. {
  1986. return;
  1987. }
  1988. }
  1989. if (m_pManager != NULL) m_pManager->Invalidate(invalidateRc);
  1990. }
  1991. else {
  1992. CControlUI::Invalidate();
  1993. }
  1994. }
  1995. else {
  1996. CControlUI::Invalidate();
  1997. }
  1998. }
  1999. bool CListElementUI::Activate()
  2000. {
  2001. if (!CControlUI::Activate()) return false;
  2002. if (m_pManager != NULL) m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMACTIVATE);
  2003. return true;
  2004. }
  2005. bool CListElementUI::IsSelected() const
  2006. {
  2007. return m_bSelected;
  2008. }
  2009. bool CListElementUI::Select(bool bSelect)
  2010. {
  2011. if (!IsEnabled()) return false;
  2012. // 取消其它列表项数据
  2013. if (m_pOwner) {
  2014. m_pOwner->UnSelectItem(m_iIndex, true);
  2015. }
  2016. if (bSelect == m_bSelected) return true;
  2017. m_bSelected = bSelect;
  2018. if (m_pOwner) {
  2019. if (bSelect) m_pOwner->SelectItem(m_iIndex);
  2020. else m_pOwner->UnSelectItem(m_iIndex);
  2021. }
  2022. Invalidate();
  2023. return true;
  2024. }
  2025. bool CListElementUI::SelectMulti(bool bSelect)
  2026. {
  2027. if (!IsEnabled()) return false;
  2028. if (bSelect == m_bSelected) return true;
  2029. m_bSelected = bSelect;
  2030. Invalidate();
  2031. return true;
  2032. }
  2033. bool CListElementUI::IsExpanded() const
  2034. {
  2035. return false;
  2036. }
  2037. bool CListElementUI::Expand(bool /*bExpand = true*/)
  2038. {
  2039. return false;
  2040. }
  2041. void CListElementUI::DoEvent(TEventUI& event)
  2042. {
  2043. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2044. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2045. else CControlUI::DoEvent(event);
  2046. return;
  2047. }
  2048. if (event.Type == UIEVENT_DBLCLICK)
  2049. {
  2050. if (IsEnabled()) {
  2051. Activate();
  2052. Invalidate();
  2053. }
  2054. return;
  2055. }
  2056. if (event.Type == UIEVENT_KEYDOWN && IsEnabled())
  2057. {
  2058. if (event.chKey == VK_RETURN) {
  2059. Activate();
  2060. Invalidate();
  2061. return;
  2062. }
  2063. }
  2064. // An important twist: The list-item will send the event not to its immediate
  2065. // parent but to the "attached" list. A list may actually embed several components
  2066. // in its path to the item, but key-presses etc. needs to go to the actual list.
  2067. if (m_pOwner != NULL) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event);
  2068. }
  2069. void CListElementUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  2070. {
  2071. if (_tcsicmp(pstrName, _T("selected")) == 0) Select();
  2072. else CControlUI::SetAttribute(pstrName, pstrValue);
  2073. }
  2074. void CListElementUI::DrawItemBk(HDC hDC, const RECT& rcItem)
  2075. {
  2076. ASSERT(m_pOwner);
  2077. if (m_pOwner == NULL) return;
  2078. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2079. DWORD iBackColor = 0;
  2080. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) iBackColor = pInfo->dwBkColor;
  2081. if ((m_uButtonState & UISTATE_HOT) != 0 && pInfo->dwHotBkColor > 0) {
  2082. iBackColor = pInfo->dwHotBkColor;
  2083. }
  2084. if (IsSelected() && pInfo->dwSelectedBkColor > 0) {
  2085. iBackColor = pInfo->dwSelectedBkColor;
  2086. }
  2087. if (!IsEnabled() && pInfo->dwDisabledBkColor > 0) {
  2088. iBackColor = pInfo->dwDisabledBkColor;
  2089. }
  2090. if (iBackColor != 0) {
  2091. CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(iBackColor));
  2092. }
  2093. if (!IsEnabled()) {
  2094. if (!pInfo->sDisabledImage.IsEmpty()) {
  2095. if (!DrawImage(hDC, (LPCTSTR)pInfo->sDisabledImage)) {}
  2096. else return;
  2097. }
  2098. }
  2099. if (IsSelected()) {
  2100. if (!pInfo->sSelectedImage.IsEmpty()) {
  2101. if (!DrawImage(hDC, (LPCTSTR)pInfo->sSelectedImage)) {}
  2102. else return;
  2103. }
  2104. }
  2105. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2106. if (!pInfo->sHotImage.IsEmpty()) {
  2107. if (!DrawImage(hDC, (LPCTSTR)pInfo->sHotImage)) {}
  2108. else return;
  2109. }
  2110. }
  2111. if (!m_sBkImage.IsEmpty()) {
  2112. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) {
  2113. if (!DrawImage(hDC, (LPCTSTR)m_sBkImage)) {}
  2114. }
  2115. }
  2116. if (m_sBkImage.IsEmpty()) {
  2117. if (!pInfo->sBkImage.IsEmpty()) {
  2118. if (!DrawImage(hDC, (LPCTSTR)pInfo->sBkImage)) {}
  2119. else return;
  2120. }
  2121. }
  2122. if (pInfo->dwLineColor != 0) {
  2123. if (pInfo->bShowRowLine) {
  2124. RECT rcLine = { m_rcItem.left, m_rcItem.bottom - 1, m_rcItem.right, m_rcItem.bottom - 1 };
  2125. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2126. }
  2127. if (pInfo->bShowColumnLine) {
  2128. for (int i = 0; i < pInfo->nColumns; i++) {
  2129. RECT rcLine = { pInfo->rcColumn[i].right - 1, m_rcItem.top, pInfo->rcColumn[i].right - 1, m_rcItem.bottom };
  2130. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2131. }
  2132. }
  2133. }
  2134. }
  2135. /////////////////////////////////////////////////////////////////////////////////////
  2136. //
  2137. //
  2138. IMPLEMENT_DUICONTROL(CListLabelElementUI)
  2139. CListLabelElementUI::CListLabelElementUI()
  2140. {
  2141. }
  2142. LPCTSTR CListLabelElementUI::GetClass() const
  2143. {
  2144. return _T("ListLabelElementUI");
  2145. }
  2146. LPVOID CListLabelElementUI::GetInterface(LPCTSTR pstrName)
  2147. {
  2148. if (_tcsicmp(pstrName, DUI_CTR_LISTLABELELEMENT) == 0) return static_cast<CListLabelElementUI*>(this);
  2149. return CListElementUI::GetInterface(pstrName);
  2150. }
  2151. void CListLabelElementUI::DoEvent(TEventUI& event)
  2152. {
  2153. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2154. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2155. else CListElementUI::DoEvent(event);
  2156. return;
  2157. }
  2158. // 右键选择
  2159. if (m_pOwner != NULL)
  2160. {
  2161. if (m_pOwner->GetListInfo()->bRSelected && event.Type == UIEVENT_RBUTTONDOWN)
  2162. {
  2163. if (IsEnabled()) {
  2164. // 多选
  2165. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2166. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2167. }
  2168. else {
  2169. Select(true);
  2170. }
  2171. }
  2172. return;
  2173. }
  2174. }
  2175. if (event.Type == UIEVENT_BUTTONDOWN)
  2176. {
  2177. if (IsEnabled()) {
  2178. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_BUTTONDOWN);
  2179. // 多选
  2180. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2181. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2182. }
  2183. else {
  2184. Select(true);
  2185. }
  2186. }
  2187. return;
  2188. }
  2189. if (event.Type == UIEVENT_BUTTONUP)
  2190. {
  2191. if (IsEnabled()) {
  2192. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMCLICK);
  2193. }
  2194. return;
  2195. }
  2196. if (event.Type == UIEVENT_MOUSEENTER)
  2197. {
  2198. if (IsEnabled()) {
  2199. m_uButtonState |= UISTATE_HOT;
  2200. Invalidate();
  2201. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSEENTER);
  2202. }
  2203. return;
  2204. }
  2205. if (event.Type == UIEVENT_MOUSELEAVE)
  2206. {
  2207. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2208. m_uButtonState &= ~UISTATE_HOT;
  2209. Invalidate();
  2210. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSELEAVE);
  2211. }
  2212. return;
  2213. }
  2214. CListElementUI::DoEvent(event);
  2215. }
  2216. SIZE CListLabelElementUI::EstimateSize(SIZE szAvailable)
  2217. {
  2218. if (m_pOwner == NULL) return CDuiSize(0, 0);
  2219. CDuiString sText = GetText();
  2220. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2221. SIZE cXY = m_cxyFixed;
  2222. if (cXY.cy == 0 && m_pManager != NULL) {
  2223. cXY.cy = m_pManager->GetFontInfo(pInfo->nFont)->tm.tmHeight + 8;
  2224. cXY.cy += pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom;
  2225. }
  2226. if (cXY.cx == 0) {
  2227. cXY.cx = szAvailable.cx;
  2228. }
  2229. return cXY;
  2230. }
  2231. bool CListLabelElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  2232. {
  2233. DrawItemBk(hDC, m_rcItem);
  2234. DrawItemText(hDC, m_rcItem);
  2235. return true;
  2236. }
  2237. void CListLabelElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2238. {
  2239. CDuiString sText = GetText();
  2240. if (sText.IsEmpty()) return;
  2241. if (m_pOwner == NULL) return;
  2242. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2243. DWORD iTextColor = pInfo->dwTextColor;
  2244. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2245. iTextColor = pInfo->dwHotTextColor;
  2246. }
  2247. if (IsSelected()) {
  2248. iTextColor = pInfo->dwSelectedTextColor;
  2249. }
  2250. if (!IsEnabled()) {
  2251. iTextColor = pInfo->dwDisabledTextColor;
  2252. }
  2253. int nLinks = 0;
  2254. RECT rcText = rcItem;
  2255. RECT rcTextPadding = GetManager()->GetDPIObj()->Scale(pInfo->rcTextPadding);
  2256. rcText.left += rcTextPadding.left;
  2257. rcText.right -= rcTextPadding.right;
  2258. rcText.top += rcTextPadding.top;
  2259. rcText.bottom -= rcTextPadding.bottom;
  2260. if (pInfo->bShowHtml)
  2261. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, iTextColor, \
  2262. NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle);
  2263. else
  2264. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, iTextColor, \
  2265. pInfo->nFont, pInfo->uTextStyle);
  2266. }
  2267. /////////////////////////////////////////////////////////////////////////////////////
  2268. //
  2269. //
  2270. IMPLEMENT_DUICONTROL(CListTextElementUI)
  2271. CListTextElementUI::CListTextElementUI() : m_nLinks(0), m_nHoverLink(-1), m_pOwner(NULL)
  2272. {
  2273. ::ZeroMemory(&m_rcLinks, sizeof(m_rcLinks));
  2274. }
  2275. CListTextElementUI::~CListTextElementUI()
  2276. {
  2277. CDuiString* pText;
  2278. for (int it = 0; it < m_aTexts.GetSize(); it++) {
  2279. pText = static_cast<CDuiString*>(m_aTexts[it]);
  2280. if (pText) delete pText;
  2281. }
  2282. m_aTexts.Empty();
  2283. }
  2284. LPCTSTR CListTextElementUI::GetClass() const
  2285. {
  2286. return _T("ListTextElementUI");
  2287. }
  2288. LPVOID CListTextElementUI::GetInterface(LPCTSTR pstrName)
  2289. {
  2290. if (_tcsicmp(pstrName, DUI_CTR_LISTTEXTELEMENT) == 0) return static_cast<CListTextElementUI*>(this);
  2291. return CListLabelElementUI::GetInterface(pstrName);
  2292. }
  2293. UINT CListTextElementUI::GetControlFlags() const
  2294. {
  2295. return UIFLAG_WANTRETURN | ((IsEnabled() && m_nLinks > 0) ? UIFLAG_SETCURSOR : 0);
  2296. }
  2297. LPCTSTR CListTextElementUI::GetText(int iIndex) const
  2298. {
  2299. CDuiString* pText = static_cast<CDuiString*>(m_aTexts.GetAt(iIndex));
  2300. if (pText) {
  2301. if (!IsResourceText())
  2302. return pText->GetData();
  2303. return CResourceManager::GetInstance()->GetText(*pText);
  2304. }
  2305. return NULL;
  2306. }
  2307. void CListTextElementUI::SetText(int iIndex, LPCTSTR pstrText)
  2308. {
  2309. if (m_pOwner == NULL) return;
  2310. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2311. if (iIndex < 0 || iIndex >= pInfo->nColumns) return;
  2312. while (m_aTexts.GetSize() < pInfo->nColumns) { m_aTexts.Add(NULL); }
  2313. CDuiString* pText = static_cast<CDuiString*>(m_aTexts[iIndex]);
  2314. if ((pText == NULL && pstrText == NULL) || (pText && *pText == pstrText)) return;
  2315. if (pText) { delete pText; pText = NULL; }
  2316. m_aTexts.SetAt(iIndex, new CDuiString(pstrText));
  2317. Invalidate();
  2318. }
  2319. DWORD CListTextElementUI::GetTextColor(int iIndex) const
  2320. {
  2321. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2322. if( iIndex < 0 || iIndex >= pInfo->nColumns || m_aTextColors.GetSize() <= 0 ) return pInfo->dwTextColor;
  2323. DWORD dwColor = (DWORD)m_aTextColors.GetAt(iIndex);
  2324. return dwColor;
  2325. }
  2326. void CListTextElementUI::SetTextColor(int iIndex, DWORD dwTextColor)
  2327. {
  2328. if( m_pOwner == NULL ) return;
  2329. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2330. if( iIndex < 0 || iIndex >= pInfo->nColumns ) return;
  2331. while( m_aTextColors.GetSize() < pInfo->nColumns ) { m_aTextColors.Add((LPVOID)pInfo->dwTextColor); }
  2332. m_aTextColors.SetAt(iIndex, (LPVOID)dwTextColor);
  2333. Invalidate();
  2334. }
  2335. void CListTextElementUI::SetOwner(CControlUI* pOwner)
  2336. {
  2337. CListElementUI::SetOwner(pOwner);
  2338. m_pOwner = static_cast<IListUI*>(pOwner->GetInterface(_T("IList")));
  2339. }
  2340. CDuiString* CListTextElementUI::GetLinkContent(int iIndex)
  2341. {
  2342. if (iIndex >= 0 && iIndex < m_nLinks) return &m_sLinks[iIndex];
  2343. return NULL;
  2344. }
  2345. void CListTextElementUI::DoEvent(TEventUI& event)
  2346. {
  2347. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2348. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2349. else CListLabelElementUI::DoEvent(event);
  2350. return;
  2351. }
  2352. // When you hover over a link
  2353. if (event.Type == UIEVENT_SETCURSOR) {
  2354. for (int i = 0; i < m_nLinks; i++) {
  2355. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2356. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
  2357. return;
  2358. }
  2359. }
  2360. }
  2361. if (event.Type == UIEVENT_BUTTONUP && IsEnabled()) {
  2362. for (int i = 0; i < m_nLinks; i++) {
  2363. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2364. m_pManager->SendNotify(this, DUI_MSGTYPE_LINK, i);
  2365. return;
  2366. }
  2367. }
  2368. }
  2369. if (m_nLinks > 0 && event.Type == UIEVENT_MOUSEMOVE) {
  2370. int nHoverLink = -1;
  2371. for (int i = 0; i < m_nLinks; i++) {
  2372. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2373. nHoverLink = i;
  2374. break;
  2375. }
  2376. }
  2377. if (m_nHoverLink != nHoverLink) {
  2378. Invalidate();
  2379. m_nHoverLink = nHoverLink;
  2380. }
  2381. }
  2382. if (m_nLinks > 0 && event.Type == UIEVENT_MOUSELEAVE) {
  2383. if (m_nHoverLink != -1) {
  2384. Invalidate();
  2385. m_nHoverLink = -1;
  2386. }
  2387. }
  2388. CListLabelElementUI::DoEvent(event);
  2389. }
  2390. SIZE CListTextElementUI::EstimateSize(SIZE szAvailable)
  2391. {
  2392. TListInfoUI* pInfo = NULL;
  2393. if (m_pOwner) pInfo = m_pOwner->GetListInfo();
  2394. SIZE cXY = m_cxyFixed;
  2395. if (cXY.cy == 0 && m_pManager != NULL) {
  2396. cXY.cy = m_pManager->GetFontInfo(pInfo->nFont)->tm.tmHeight + 8;
  2397. if (pInfo) cXY.cy += pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom;
  2398. }
  2399. return cXY;
  2400. }
  2401. void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2402. {
  2403. if( m_pOwner == NULL ) return;
  2404. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2405. IListCallbackUI* pCallback = m_pOwner->GetTextCallback();
  2406. m_nLinks = 0;
  2407. int nLinks = lengthof(m_rcLinks);
  2408. for( int i = 0; i < pInfo->nColumns; i++ )
  2409. {
  2410. RECT rcItem = { pInfo->rcColumn[i].left, m_rcItem.top, pInfo->rcColumn[i].right, m_rcItem.bottom };
  2411. rcItem.left += pInfo->rcTextPadding.left;
  2412. rcItem.right -= pInfo->rcTextPadding.right;
  2413. rcItem.top += pInfo->rcTextPadding.top;
  2414. rcItem.bottom -= pInfo->rcTextPadding.bottom;
  2415. DWORD iTextColor = pInfo->dwTextColor;
  2416. CDuiString strText;
  2417. if( pCallback ) {
  2418. strText = pCallback->GetItemText(this, m_iIndex, i);
  2419. int iState = 0;
  2420. if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  2421. iState = 1;
  2422. }
  2423. if( IsSelected() ) {
  2424. iState = 2;
  2425. }
  2426. if( !IsEnabled() ) {
  2427. iState = 3;
  2428. }
  2429. iTextColor = pCallback->GetItemTextColor(this, m_iIndex, i, iState);
  2430. }
  2431. else {
  2432. strText.Assign(GetText(i));
  2433. iTextColor = GetTextColor(i);
  2434. if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  2435. iTextColor = pInfo->dwHotTextColor;
  2436. }
  2437. if( IsSelected() ) {
  2438. iTextColor = pInfo->dwSelectedTextColor;
  2439. }
  2440. if( !IsEnabled() ) {
  2441. iTextColor = pInfo->dwDisabledTextColor;
  2442. }
  2443. }
  2444. if( pInfo->bShowHtml )
  2445. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, \
  2446. &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], nLinks, pInfo->nFont, pInfo->uTextStyle);
  2447. else
  2448. CRenderEngine::DrawText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, \
  2449. pInfo->nFont, pInfo->uTextStyle);
  2450. m_nLinks += nLinks;
  2451. nLinks = lengthof(m_rcLinks) - m_nLinks;
  2452. }
  2453. for( int i = m_nLinks; i < lengthof(m_rcLinks); i++ ) {
  2454. ::ZeroMemory(m_rcLinks + i, sizeof(RECT));
  2455. ((CDuiString*)(m_sLinks + i))->Empty();
  2456. }
  2457. }
  2458. /////////////////////////////////////////////////////////////////////////////////////
  2459. //
  2460. //
  2461. IMPLEMENT_DUICONTROL(CListContainerElementUI)
  2462. CListContainerElementUI::CListContainerElementUI() :
  2463. m_iIndex(-1),
  2464. m_pOwner(NULL),
  2465. m_bSelected(false),
  2466. m_uButtonState(0)
  2467. {
  2468. }
  2469. LPCTSTR CListContainerElementUI::GetClass() const
  2470. {
  2471. return _T("ListContainerElementUI");
  2472. }
  2473. UINT CListContainerElementUI::GetControlFlags() const
  2474. {
  2475. return UIFLAG_WANTRETURN;
  2476. }
  2477. LPVOID CListContainerElementUI::GetInterface(LPCTSTR pstrName)
  2478. {
  2479. if (_tcsicmp(pstrName, DUI_CTR_LISTITEM) == 0) return static_cast<IListItemUI*>(this);
  2480. if (_tcsicmp(pstrName, DUI_CTR_LISTCONTAINERELEMENT) == 0) return static_cast<CListContainerElementUI*>(this);
  2481. return CContainerUI::GetInterface(pstrName);
  2482. }
  2483. IListOwnerUI* CListContainerElementUI::GetOwner()
  2484. {
  2485. return m_pOwner;
  2486. }
  2487. void CListContainerElementUI::SetOwner(CControlUI* pOwner)
  2488. {
  2489. m_pOwner = static_cast<IListOwnerUI*>(pOwner->GetInterface(_T("IListOwner")));
  2490. }
  2491. void CListContainerElementUI::SetVisible(bool bVisible)
  2492. {
  2493. CContainerUI::SetVisible(bVisible);
  2494. if (!IsVisible() && m_bSelected)
  2495. {
  2496. m_bSelected = false;
  2497. if (m_pOwner != NULL) m_pOwner->SelectItem(-1);
  2498. }
  2499. }
  2500. void CListContainerElementUI::SetEnabled(bool bEnable)
  2501. {
  2502. CControlUI::SetEnabled(bEnable);
  2503. if (!IsEnabled()) {
  2504. m_uButtonState = 0;
  2505. }
  2506. }
  2507. int CListContainerElementUI::GetIndex() const
  2508. {
  2509. return m_iIndex;
  2510. }
  2511. void CListContainerElementUI::SetIndex(int iIndex)
  2512. {
  2513. m_iIndex = iIndex;
  2514. }
  2515. void CListContainerElementUI::Invalidate()
  2516. {
  2517. if (!IsVisible()) return;
  2518. if (GetParent()) {
  2519. CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
  2520. if (pParentContainer) {
  2521. RECT rc = pParentContainer->GetPos();
  2522. RECT rcInset = pParentContainer->GetInset();
  2523. rc.left += rcInset.left;
  2524. rc.top += rcInset.top;
  2525. rc.right -= rcInset.right;
  2526. rc.bottom -= rcInset.bottom;
  2527. CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
  2528. if (pVerticalScrollBar && pVerticalScrollBar->IsVisible()) rc.right -= pVerticalScrollBar->GetFixedWidth();
  2529. CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
  2530. if (pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
  2531. RECT invalidateRc = m_rcItem;
  2532. if (!::IntersectRect(&invalidateRc, &m_rcItem, &rc))
  2533. {
  2534. return;
  2535. }
  2536. CControlUI* pParent = GetParent();
  2537. RECT rcTemp;
  2538. RECT rcParent;
  2539. while (pParent = pParent->GetParent())
  2540. {
  2541. rcTemp = invalidateRc;
  2542. rcParent = pParent->GetPos();
  2543. if (!::IntersectRect(&invalidateRc, &rcTemp, &rcParent))
  2544. {
  2545. return;
  2546. }
  2547. }
  2548. if (m_pManager != NULL) m_pManager->Invalidate(invalidateRc);
  2549. }
  2550. else {
  2551. CContainerUI::Invalidate();
  2552. }
  2553. }
  2554. else {
  2555. CContainerUI::Invalidate();
  2556. }
  2557. }
  2558. bool CListContainerElementUI::Activate()
  2559. {
  2560. if (!CContainerUI::Activate()) return false;
  2561. if (m_pManager != NULL) m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMACTIVATE);
  2562. return true;
  2563. }
  2564. bool CListContainerElementUI::IsSelected() const
  2565. {
  2566. return m_bSelected;
  2567. }
  2568. bool CListContainerElementUI::Select(bool bSelect)
  2569. {
  2570. if (!IsEnabled()) return false;
  2571. // 取消其它列表项数据
  2572. if (m_pOwner) {
  2573. m_pOwner->UnSelectItem(m_iIndex, true);
  2574. }
  2575. if (bSelect == m_bSelected) return true;
  2576. m_bSelected = bSelect;
  2577. if (m_pOwner) {
  2578. if (bSelect) m_pOwner->SelectItem(m_iIndex);
  2579. else m_pOwner->UnSelectItem(m_iIndex);
  2580. }
  2581. Invalidate();
  2582. return true;
  2583. }
  2584. bool CListContainerElementUI::SelectMulti(bool bSelect)
  2585. {
  2586. if (!IsEnabled()) return false;
  2587. if (bSelect == m_bSelected) return true;
  2588. m_bSelected = bSelect;
  2589. Invalidate();
  2590. return true;
  2591. }
  2592. bool CListContainerElementUI::IsExpanded() const
  2593. {
  2594. return false;
  2595. }
  2596. bool CListContainerElementUI::Expand(bool /*bExpand = true*/)
  2597. {
  2598. return false;
  2599. }
  2600. void CListContainerElementUI::DoEvent(TEventUI& event)
  2601. {
  2602. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2603. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2604. else CContainerUI::DoEvent(event);
  2605. return;
  2606. }
  2607. if (event.Type == UIEVENT_DBLCLICK)
  2608. {
  2609. if (IsEnabled()) {
  2610. Activate();
  2611. Invalidate();
  2612. }
  2613. return;
  2614. }
  2615. if (event.Type == UIEVENT_KEYDOWN && IsEnabled())
  2616. {
  2617. if (event.chKey == VK_RETURN) {
  2618. Activate();
  2619. Invalidate();
  2620. return;
  2621. }
  2622. }
  2623. if (event.Type == UIEVENT_BUTTONDOWN)
  2624. {
  2625. if (IsEnabled()) {
  2626. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_BUTTONDOWN);
  2627. // 多选
  2628. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2629. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2630. }
  2631. else {
  2632. Select(true);
  2633. }
  2634. }
  2635. return;
  2636. }
  2637. // 右键选择
  2638. if (m_pOwner != NULL)
  2639. {
  2640. if (m_pOwner->GetListInfo()->bRSelected && event.Type == UIEVENT_RBUTTONDOWN)
  2641. {
  2642. if (IsEnabled()) {
  2643. // 多选
  2644. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2645. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2646. }
  2647. else {
  2648. Select(true);
  2649. }
  2650. }
  2651. return;
  2652. }
  2653. }
  2654. if (event.Type == UIEVENT_BUTTONUP)
  2655. {
  2656. if (IsEnabled()) {
  2657. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMCLICK);
  2658. }
  2659. return;
  2660. }
  2661. if (event.Type == UIEVENT_MOUSEENTER)
  2662. {
  2663. if (IsEnabled()) {
  2664. m_uButtonState |= UISTATE_HOT;
  2665. Invalidate();
  2666. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSEENTER);
  2667. }
  2668. return;
  2669. }
  2670. if (event.Type == UIEVENT_MOUSELEAVE)
  2671. {
  2672. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2673. m_uButtonState &= ~UISTATE_HOT;
  2674. Invalidate();
  2675. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSELEAVE);
  2676. }
  2677. return;
  2678. }
  2679. if (event.Type == UIEVENT_TIMER)
  2680. {
  2681. m_pManager->SendNotify(this, DUI_MSGTYPE_TIMER, event.wParam, event.lParam);
  2682. return;
  2683. }
  2684. if (event.Type == UIEVENT_CONTEXTMENU)
  2685. {
  2686. if (IsContextMenuUsed()) {
  2687. m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam);
  2688. return;
  2689. }
  2690. }
  2691. // An important twist: The list-item will send the event not to its immediate
  2692. // parent but to the "attached" list. A list may actually embed several components
  2693. // in its path to the item, but key-presses etc. needs to go to the actual list.
  2694. if (m_pOwner != NULL) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event);
  2695. }
  2696. void CListContainerElementUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  2697. {
  2698. if (_tcsicmp(pstrName, _T("selected")) == 0) Select();
  2699. //else if( _tcscmp(pstrName, _T("expandable")) == 0 ) SetExpandable(_tcscmp(pstrValue, _T("true")) == 0);
  2700. else CContainerUI::SetAttribute(pstrName, pstrValue);
  2701. }
  2702. bool CListContainerElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  2703. {
  2704. DrawItemBk(hDC, m_rcItem);
  2705. return CContainerUI::DoPaint(hDC, rcPaint, pStopControl);
  2706. }
  2707. void CListContainerElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2708. {
  2709. CDuiString sText = GetText();
  2710. if (sText.IsEmpty()) return;
  2711. if (m_pOwner == NULL) return;
  2712. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2713. DWORD iTextColor = pInfo->dwTextColor;
  2714. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2715. iTextColor = pInfo->dwHotTextColor;
  2716. }
  2717. if (IsSelected()) {
  2718. iTextColor = pInfo->dwSelectedTextColor;
  2719. }
  2720. if (!IsEnabled()) {
  2721. iTextColor = pInfo->dwDisabledTextColor;
  2722. }
  2723. int nLinks = 0;
  2724. RECT rcText = rcItem;
  2725. RECT rcTextPadding = GetManager()->GetDPIObj()->Scale(pInfo->rcTextPadding);
  2726. rcText.left += rcTextPadding.left;
  2727. rcText.right -= rcTextPadding.right;
  2728. rcText.top += rcTextPadding.top;
  2729. rcText.bottom -= rcTextPadding.bottom;
  2730. if (pInfo->bShowHtml)
  2731. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, iTextColor, \
  2732. NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle);
  2733. else
  2734. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, iTextColor, \
  2735. pInfo->nFont, pInfo->uTextStyle);
  2736. }
  2737. void CListContainerElementUI::DrawItemBk(HDC hDC, const RECT& rcItem)
  2738. {
  2739. ASSERT(m_pOwner);
  2740. if (m_pOwner == NULL) return;
  2741. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2742. DWORD iBackColor = 0;
  2743. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) iBackColor = pInfo->dwBkColor;
  2744. CDuiString sForeImage = pInfo->sForeImage;
  2745. if ((m_uButtonState & UISTATE_HOT) != 0 && pInfo->dwHotBkColor > 0) {
  2746. iBackColor = pInfo->dwHotBkColor;
  2747. if(!pInfo->sHotForeImage.IsEmpty()) {
  2748. sForeImage = pInfo->sHotForeImage;
  2749. }
  2750. }
  2751. if (IsSelected() && pInfo->dwSelectedBkColor > 0) {
  2752. iBackColor = pInfo->dwSelectedBkColor;
  2753. }
  2754. if (!IsEnabled() && pInfo->dwDisabledBkColor > 0) {
  2755. iBackColor = pInfo->dwDisabledBkColor;
  2756. }
  2757. if (iBackColor != 0) {
  2758. CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(iBackColor));
  2759. }
  2760. if (!IsEnabled()) {
  2761. if (!pInfo->sDisabledImage.IsEmpty()) {
  2762. if (!DrawImage(hDC, (LPCTSTR)pInfo->sDisabledImage)) {}
  2763. else return;
  2764. }
  2765. }
  2766. if (IsSelected()) {
  2767. if (!pInfo->sSelectedImage.IsEmpty()) {
  2768. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sSelectedImage);
  2769. if(!pInfo->sSelectedForeImage.IsEmpty()) {
  2770. DrawImage(hDC, (LPCTSTR)pInfo->sSelectedForeImage);
  2771. }
  2772. if(bDrawOk) return;
  2773. }
  2774. }
  2775. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2776. if (!pInfo->sHotImage.IsEmpty()) {
  2777. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sHotImage);
  2778. if(!pInfo->sHotForeImage.IsEmpty()) {
  2779. DrawImage(hDC, (LPCTSTR)pInfo->sHotForeImage);
  2780. }
  2781. if(bDrawOk) return;
  2782. }
  2783. }
  2784. if (!m_sBkImage.IsEmpty()) {
  2785. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) {
  2786. if (!DrawImage(hDC, (LPCTSTR)m_sBkImage)) {}
  2787. if(!pInfo->sForeImage.IsEmpty()) {
  2788. DrawImage(hDC, (LPCTSTR)pInfo->sForeImage);
  2789. }
  2790. }
  2791. }
  2792. if (m_sBkImage.IsEmpty()) {
  2793. if (!pInfo->sBkImage.IsEmpty()) {
  2794. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sBkImage);
  2795. if(!pInfo->sForeImage.IsEmpty()) {
  2796. DrawImage(hDC, (LPCTSTR)pInfo->sForeImage);
  2797. }
  2798. }
  2799. }
  2800. if (pInfo->dwLineColor != 0) {
  2801. if (pInfo->bShowRowLine) {
  2802. RECT rcLine = { m_rcItem.left, m_rcItem.bottom - 1, m_rcItem.right, m_rcItem.bottom - 1 };
  2803. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2804. }
  2805. if (pInfo->bShowColumnLine) {
  2806. for (int i = 0; i < pInfo->nColumns; i++) {
  2807. RECT rcLine = { pInfo->rcColumn[i].right - 1, m_rcItem.top, pInfo->rcColumn[i].right - 1, m_rcItem.bottom };
  2808. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2809. }
  2810. }
  2811. }
  2812. }
  2813. void CListContainerElementUI::SetPos(RECT rc, bool bNeedInvalidate)
  2814. {
  2815. if (m_pOwner == NULL) return;
  2816. UINT uListType = m_pOwner->GetListType();
  2817. // 直接按普通纵向布局处理,不再对 LT_LIST 做网格重排
  2818. CHorizontalLayoutUI::SetPos(rc, bNeedInvalidate);
  2819. // 只有 LT_LIST / LT_TREE 需要做表头列宽同步
  2820. if (uListType != LT_LIST && uListType != LT_TREE) return;
  2821. CListUI* pList = static_cast<CListUI*>(m_pOwner);
  2822. if (uListType == LT_TREE)
  2823. {
  2824. pList = (CListUI*)pList->CControlUI::GetInterface(_T("List"));
  2825. if (pList == NULL) return;
  2826. }
  2827. CListHeaderUI* pHeader = pList->GetHeader();
  2828. if (pHeader == NULL || !pHeader->IsVisible()) return;
  2829. int nCount = m_items.GetSize();
  2830. for (int i = 0; i < nCount; i++)
  2831. {
  2832. CControlUI* pListItem = static_cast<CControlUI*>(m_items[i]);
  2833. CControlUI* pHeaderItem = pHeader->GetItemAt(i);
  2834. if (pHeaderItem == NULL) return;
  2835. RECT rcHeaderItem = pHeaderItem->GetPos();
  2836. if (pListItem != NULL && !(rcHeaderItem.left == 0 && rcHeaderItem.right == 0))
  2837. {
  2838. RECT rt = pListItem->GetPos();
  2839. rt.left = rcHeaderItem.left;
  2840. rt.right = rcHeaderItem.right;
  2841. pListItem->SetPos(rt);
  2842. }
  2843. }
  2844. }
  2845. } // namespace DuiLib