UIList.cpp 86 KB

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