UIList.cpp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237
  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. sz.cx = MAX(sz.cx, 0);
  1249. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1250. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1251. cxNeeded = MAX(cxNeeded, sz.cx);
  1252. nEstimateNum++;
  1253. }
  1254. cyFixed += (nEstimateNum - 1) * iChildPadding;
  1255. if (m_pOwner)
  1256. {
  1257. CListHeaderUI* pHeader = m_pOwner->GetHeader();
  1258. if (pHeader != NULL && pHeader->GetCount() > 0)
  1259. {
  1260. cxNeeded = MAX(0, pHeader->EstimateSize(CDuiSize(rcWork.right - rcWork.left, rcWork.bottom - rcWork.top)).cx);
  1261. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1262. {
  1263. int nOffset = m_pHorizontalScrollBar->GetScrollPos();
  1264. RECT rcHeader = pHeader->GetPos();
  1265. rcHeader.left = rcWork.left - nOffset;
  1266. pHeader->SetPos(rcHeader);
  1267. }
  1268. }
  1269. }
  1270. int cyExpand = 0;
  1271. if (nAdjustables > 0)
  1272. {
  1273. cyExpand = MAX(0, (szAvailable.cy - cyFixed) / nAdjustables);
  1274. }
  1275. SIZE szRemaining = szAvailable;
  1276. // 可见布局坐标:受滚动条影响
  1277. int iPosY = rcWork.top;
  1278. if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible())
  1279. {
  1280. iPosY -= m_pVerticalScrollBar->GetScrollPos();
  1281. }
  1282. int iPosX = rcWork.left;
  1283. if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible())
  1284. {
  1285. iPosX -= m_pHorizontalScrollBar->GetScrollPos();
  1286. }
  1287. int iAdjustable = 0;
  1288. int cyFixedRemaining = cyFixed;
  1289. // 真实内容高度:不受滚动条影响
  1290. int iContentY = rcWork.top;
  1291. int nVisibleIndex = 0;
  1292. for (int it2 = 0; it2 < m_items.GetSize(); it2++)
  1293. {
  1294. CControlUI* pControl = static_cast<CControlUI*>(m_items[it2]);
  1295. if (!pControl->IsVisible()) continue;
  1296. if (pControl->IsFloat())
  1297. {
  1298. SetFloatPos(it2);
  1299. continue;
  1300. }
  1301. RECT rcPadding = pControl->GetPadding();
  1302. szRemaining.cy -= rcPadding.top;
  1303. SIZE sz = pControl->EstimateSize(szRemaining);
  1304. if (sz.cy == 0)
  1305. {
  1306. iAdjustable++;
  1307. sz.cy = cyExpand;
  1308. if (iAdjustable == nAdjustables)
  1309. {
  1310. sz.cy = MAX(0, szRemaining.cy - rcPadding.bottom - cyFixedRemaining);
  1311. }
  1312. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1313. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1314. }
  1315. else
  1316. {
  1317. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1318. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1319. cyFixedRemaining -= sz.cy;
  1320. }
  1321. sz.cx = MAX(cxNeeded, szAvailable.cx - rcPadding.left - rcPadding.right);
  1322. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1323. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1324. RECT rcCtrl = {
  1325. iPosX + rcPadding.left,
  1326. iPosY + rcPadding.top,
  1327. iPosX + rcPadding.left + sz.cx,
  1328. iPosY + sz.cy + rcPadding.top + rcPadding.bottom
  1329. };
  1330. pControl->SetPos(rcCtrl);
  1331. // 真实内容高度按未滚动坐标累计
  1332. iContentY += sz.cy + rcPadding.top + rcPadding.bottom;
  1333. nVisibleIndex++;
  1334. if (nVisibleIndex < nEstimateNum)
  1335. {
  1336. iContentY += iChildPadding;
  1337. }
  1338. iPosY += sz.cy + iChildPadding + rcPadding.top + rcPadding.bottom;
  1339. szRemaining.cy -= sz.cy + iChildPadding + rcPadding.bottom;
  1340. }
  1341. int cyNeeded = MAX(0, iContentY - rcWork.top);
  1342. if (m_pHorizontalScrollBar != NULL)
  1343. {
  1344. if (cxNeeded > rcWork.right - rcWork.left)
  1345. {
  1346. if (m_pHorizontalScrollBar->IsVisible())
  1347. {
  1348. m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rcWork.right - rcWork.left));
  1349. }
  1350. else
  1351. {
  1352. m_pHorizontalScrollBar->SetVisible(true);
  1353. m_pHorizontalScrollBar->SetScrollRange(cxNeeded - (rcWork.right - rcWork.left));
  1354. m_pHorizontalScrollBar->SetScrollPos(0);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. if (m_pHorizontalScrollBar->IsVisible())
  1360. {
  1361. m_pHorizontalScrollBar->SetVisible(false);
  1362. m_pHorizontalScrollBar->SetScrollRange(0);
  1363. m_pHorizontalScrollBar->SetScrollPos(0);
  1364. }
  1365. }
  1366. }
  1367. ProcessScrollBar(rcWork, cxNeeded, cyNeeded);
  1368. }
  1369. }
  1370. void CListBodyUI::DoEvent(TEventUI& event)
  1371. {
  1372. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  1373. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  1374. else CVerticalLayoutUI::DoEvent(event);
  1375. return;
  1376. }
  1377. CVerticalLayoutUI::DoEvent(event);
  1378. }
  1379. /////////////////////////////////////////////////////////////////////////////////////
  1380. //
  1381. //
  1382. IMPLEMENT_DUICONTROL(CListHeaderUI)
  1383. CListHeaderUI::CListHeaderUI() :
  1384. m_bIsScaleHeader(false)
  1385. {
  1386. }
  1387. CListHeaderUI::~CListHeaderUI()
  1388. {
  1389. }
  1390. LPCTSTR CListHeaderUI::GetClass() const
  1391. {
  1392. return _T("ListHeaderUI");
  1393. }
  1394. LPVOID CListHeaderUI::GetInterface(LPCTSTR pstrName)
  1395. {
  1396. if (_tcsicmp(pstrName, DUI_CTR_LISTHEADER) == 0) return this;
  1397. return CHorizontalLayoutUI::GetInterface(pstrName);
  1398. }
  1399. SIZE CListHeaderUI::EstimateSize(SIZE szAvailable)
  1400. {
  1401. SIZE cXY = { 0, m_cxyFixed.cy };
  1402. if (cXY.cy == 0 && m_pManager != NULL) {
  1403. for (int it = 0; it < m_items.GetSize(); it++) {
  1404. cXY.cy = MAX(cXY.cy, static_cast<CControlUI*>(m_items[it])->EstimateSize(szAvailable).cy);
  1405. }
  1406. int nMin = m_pManager->GetDefaultFontInfo()->tm.tmHeight + 6;
  1407. cXY.cy = MAX(cXY.cy, nMin);
  1408. }
  1409. for (int it = 0; it < m_items.GetSize(); it++) {
  1410. cXY.cx += static_cast<CControlUI*>(m_items[it])->EstimateSize(szAvailable).cx;
  1411. }
  1412. if (cXY.cx < szAvailable.cx) cXY.cx = szAvailable.cx;
  1413. return cXY;
  1414. }
  1415. void CListHeaderUI::SetPos(RECT rc, bool bNeedInvalidate)
  1416. {
  1417. CControlUI::SetPos(rc, bNeedInvalidate);
  1418. rc = m_rcItem;
  1419. RECT rcInset = GetInset();
  1420. // Adjust for inset
  1421. rc.left += rcInset.left;
  1422. rc.top += rcInset.top;
  1423. rc.right -= rcInset.right;
  1424. rc.bottom -= rcInset.bottom;
  1425. if (m_items.GetSize() == 0) {
  1426. return;
  1427. }
  1428. int iChildPadding = GetChildPadding();
  1429. // Determine the width of elements that are sizeable
  1430. SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top };
  1431. int nAdjustables = 0;
  1432. int cxFixed = 0;
  1433. int nEstimateNum = 0;
  1434. for (int it1 = 0; it1 < m_items.GetSize(); it1++) {
  1435. CControlUI* pControl = static_cast<CControlUI*>(m_items[it1]);
  1436. if (!pControl->IsVisible()) continue;
  1437. if (pControl->IsFloat()) continue;
  1438. SIZE sz = pControl->EstimateSize(szAvailable);
  1439. if (sz.cx == 0) {
  1440. nAdjustables++;
  1441. }
  1442. else {
  1443. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1444. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1445. }
  1446. cxFixed += sz.cx + pControl->GetPadding().left + pControl->GetPadding().right;
  1447. nEstimateNum++;
  1448. }
  1449. cxFixed += (nEstimateNum - 1) * iChildPadding;
  1450. int cxExpand = 0;
  1451. int cxNeeded = 0;
  1452. if (nAdjustables > 0) cxExpand = MAX(0, (szAvailable.cx - cxFixed) / nAdjustables);
  1453. int nHeaderWidth = rc.right - rc.left;
  1454. CListUI *pList = static_cast<CListUI*>(GetParent());
  1455. if (pList != NULL) {
  1456. CScrollBarUI* pVScroll = pList->GetVerticalScrollBar();
  1457. if (pVScroll != NULL) {
  1458. nHeaderWidth -= pVScroll->GetWidth();
  1459. szAvailable.cx = nHeaderWidth;
  1460. }
  1461. }
  1462. // Position the elements
  1463. SIZE szRemaining = szAvailable;
  1464. int iPosX = rc.left;
  1465. int iAdjustable = 0;
  1466. int cxFixedRemaining = cxFixed;
  1467. for (int it2 = 0; it2 < m_items.GetSize(); it2++) {
  1468. CControlUI* pControl = static_cast<CControlUI*>(m_items[it2]);
  1469. if (!pControl->IsVisible()) continue;
  1470. if (pControl->IsFloat()) {
  1471. SetFloatPos(it2);
  1472. continue;
  1473. }
  1474. RECT rcPadding = pControl->GetPadding();
  1475. szRemaining.cx -= rcPadding.left;
  1476. SIZE sz = { 0,0 };
  1477. if (m_bIsScaleHeader) {
  1478. CListHeaderItemUI* pHeaderItem = static_cast<CListHeaderItemUI*>(pControl);
  1479. sz.cx = int(nHeaderWidth * (float)pHeaderItem->GetScale() / 100);
  1480. }
  1481. else {
  1482. sz = pControl->EstimateSize(szRemaining);
  1483. }
  1484. if (sz.cx == 0) {
  1485. iAdjustable++;
  1486. sz.cx = cxExpand;
  1487. // Distribute remaining to last element (usually round-off left-overs)
  1488. if (iAdjustable == nAdjustables) {
  1489. sz.cx = MAX(0, szRemaining.cx - rcPadding.right - cxFixedRemaining);
  1490. }
  1491. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1492. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1493. }
  1494. else {
  1495. if (sz.cx < pControl->GetMinWidth()) sz.cx = pControl->GetMinWidth();
  1496. if (sz.cx > pControl->GetMaxWidth()) sz.cx = pControl->GetMaxWidth();
  1497. cxFixedRemaining -= sz.cx;
  1498. }
  1499. sz.cy = pControl->GetFixedHeight();
  1500. if (sz.cy == 0) sz.cy = rc.bottom - rc.top - rcPadding.top - rcPadding.bottom;
  1501. if (sz.cy < 0) sz.cy = 0;
  1502. if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
  1503. if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
  1504. RECT rcCtrl = { iPosX + rcPadding.left, rc.top + rcPadding.top, iPosX + sz.cx + rcPadding.left + rcPadding.right, rc.top + rcPadding.top + sz.cy };
  1505. pControl->SetPos(rcCtrl);
  1506. iPosX += sz.cx + iChildPadding + rcPadding.left + rcPadding.right;
  1507. cxNeeded += sz.cx + rcPadding.left + rcPadding.right;
  1508. szRemaining.cx -= sz.cx + iChildPadding + rcPadding.right;
  1509. }
  1510. cxNeeded += (nEstimateNum - 1) * iChildPadding;
  1511. }
  1512. void CListHeaderUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  1513. {
  1514. if (_tcsicmp(pstrName, _T("scaleheader")) == 0) SetScaleHeader(_tcsicmp(pstrValue, _T("true")) == 0);
  1515. else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue);
  1516. }
  1517. void CListHeaderUI::SetScaleHeader(bool bIsScale)
  1518. {
  1519. m_bIsScaleHeader = bIsScale;
  1520. }
  1521. bool CListHeaderUI::IsScaleHeader() const
  1522. {
  1523. return m_bIsScaleHeader;
  1524. }
  1525. void CListHeaderUI::DoInit()
  1526. {
  1527. }
  1528. void CListHeaderUI::DoPostPaint(HDC hDC, const RECT& rcPaint)
  1529. {
  1530. }
  1531. /////////////////////////////////////////////////////////////////////////////////////
  1532. //
  1533. //
  1534. IMPLEMENT_DUICONTROL(CListHeaderItemUI)
  1535. CListHeaderItemUI::CListHeaderItemUI() : m_bDragable(true), m_uButtonState(0), m_iSepWidth(4),
  1536. m_uTextStyle(DT_VCENTER | DT_CENTER | DT_SINGLELINE), m_dwTextColor(0), m_iFont(-1), m_bShowHtml(false), m_nScale(0)
  1537. {
  1538. SetTextPadding(CDuiRect(2, 0, 2, 0));
  1539. ptLastMouse.x = ptLastMouse.y = 0;
  1540. SetMinWidth(16);
  1541. }
  1542. LPCTSTR CListHeaderItemUI::GetClass() const
  1543. {
  1544. return _T("ListHeaderItemUI");
  1545. }
  1546. LPVOID CListHeaderItemUI::GetInterface(LPCTSTR pstrName)
  1547. {
  1548. if (_tcsicmp(pstrName, DUI_CTR_LISTHEADERITEM) == 0) return this;
  1549. return CContainerUI::GetInterface(pstrName);
  1550. }
  1551. UINT CListHeaderItemUI::GetControlFlags() const
  1552. {
  1553. if (IsEnabled() && m_iSepWidth != 0) return UIFLAG_SETCURSOR;
  1554. else return 0;
  1555. }
  1556. void CListHeaderItemUI::SetEnabled(bool bEnable)
  1557. {
  1558. CContainerUI::SetEnabled(bEnable);
  1559. if (!IsEnabled()) {
  1560. m_uButtonState = 0;
  1561. }
  1562. }
  1563. bool CListHeaderItemUI::IsDragable() const
  1564. {
  1565. return m_bDragable;
  1566. }
  1567. void CListHeaderItemUI::SetDragable(bool bDragable)
  1568. {
  1569. m_bDragable = bDragable;
  1570. if (!m_bDragable) m_uButtonState &= ~UISTATE_CAPTURED;
  1571. }
  1572. DWORD CListHeaderItemUI::GetSepWidth() const
  1573. {
  1574. if(m_pManager != NULL) return m_pManager->GetDPIObj()->Scale(m_iSepWidth);
  1575. return m_iSepWidth;
  1576. }
  1577. void CListHeaderItemUI::SetSepWidth(int iWidth)
  1578. {
  1579. m_iSepWidth = iWidth;
  1580. }
  1581. DWORD CListHeaderItemUI::GetTextStyle() const
  1582. {
  1583. return m_uTextStyle;
  1584. }
  1585. void CListHeaderItemUI::SetTextStyle(UINT uStyle)
  1586. {
  1587. m_uTextStyle = uStyle;
  1588. Invalidate();
  1589. }
  1590. DWORD CListHeaderItemUI::GetTextColor() const
  1591. {
  1592. return m_dwTextColor;
  1593. }
  1594. void CListHeaderItemUI::SetTextColor(DWORD dwTextColor)
  1595. {
  1596. m_dwTextColor = dwTextColor;
  1597. }
  1598. RECT CListHeaderItemUI::GetTextPadding() const
  1599. {
  1600. RECT rcTextPadding = m_rcTextPadding;
  1601. if(m_pManager != NULL) m_pManager->GetDPIObj()->Scale(&rcTextPadding);
  1602. return rcTextPadding;
  1603. }
  1604. void CListHeaderItemUI::SetTextPadding(RECT rc)
  1605. {
  1606. m_rcTextPadding = rc;
  1607. Invalidate();
  1608. }
  1609. void CListHeaderItemUI::SetFont(int index)
  1610. {
  1611. m_iFont = index;
  1612. }
  1613. bool CListHeaderItemUI::IsShowHtml()
  1614. {
  1615. return m_bShowHtml;
  1616. }
  1617. void CListHeaderItemUI::SetShowHtml(bool bShowHtml)
  1618. {
  1619. if (m_bShowHtml == bShowHtml) return;
  1620. m_bShowHtml = bShowHtml;
  1621. Invalidate();
  1622. }
  1623. LPCTSTR CListHeaderItemUI::GetNormalImage() const
  1624. {
  1625. return m_sNormalImage;
  1626. }
  1627. void CListHeaderItemUI::SetNormalImage(LPCTSTR pStrImage)
  1628. {
  1629. m_sNormalImage = pStrImage;
  1630. Invalidate();
  1631. }
  1632. LPCTSTR CListHeaderItemUI::GetHotImage() const
  1633. {
  1634. return m_sHotImage;
  1635. }
  1636. void CListHeaderItemUI::SetHotImage(LPCTSTR pStrImage)
  1637. {
  1638. m_sHotImage = pStrImage;
  1639. Invalidate();
  1640. }
  1641. LPCTSTR CListHeaderItemUI::GetPushedImage() const
  1642. {
  1643. return m_sPushedImage;
  1644. }
  1645. void CListHeaderItemUI::SetPushedImage(LPCTSTR pStrImage)
  1646. {
  1647. m_sPushedImage = pStrImage;
  1648. Invalidate();
  1649. }
  1650. LPCTSTR CListHeaderItemUI::GetFocusedImage() const
  1651. {
  1652. return m_sFocusedImage;
  1653. }
  1654. void CListHeaderItemUI::SetFocusedImage(LPCTSTR pStrImage)
  1655. {
  1656. m_sFocusedImage = pStrImage;
  1657. Invalidate();
  1658. }
  1659. LPCTSTR CListHeaderItemUI::GetSepImage() const
  1660. {
  1661. return m_sSepImage;
  1662. }
  1663. void CListHeaderItemUI::SetSepImage(LPCTSTR pStrImage)
  1664. {
  1665. m_sSepImage = pStrImage;
  1666. Invalidate();
  1667. }
  1668. void CListHeaderItemUI::SetScale(int nScale)
  1669. {
  1670. m_nScale = nScale;
  1671. }
  1672. int CListHeaderItemUI::GetScale() const
  1673. {
  1674. return m_nScale;
  1675. }
  1676. void CListHeaderItemUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  1677. {
  1678. if (_tcsicmp(pstrName, _T("dragable")) == 0) SetDragable(_tcsicmp(pstrValue, _T("true")) == 0);
  1679. else if (_tcsicmp(pstrName, _T("sepwidth")) == 0) SetSepWidth(_ttoi(pstrValue));
  1680. else if (_tcsicmp(pstrName, _T("align")) == 0) {
  1681. if (_tcsstr(pstrValue, _T("left")) != NULL) {
  1682. m_uTextStyle &= ~(DT_CENTER | DT_RIGHT);
  1683. m_uTextStyle |= DT_LEFT;
  1684. }
  1685. if (_tcsstr(pstrValue, _T("center")) != NULL) {
  1686. m_uTextStyle &= ~(DT_LEFT | DT_RIGHT);
  1687. m_uTextStyle |= DT_CENTER;
  1688. }
  1689. if (_tcsstr(pstrValue, _T("right")) != NULL) {
  1690. m_uTextStyle &= ~(DT_LEFT | DT_CENTER);
  1691. m_uTextStyle |= DT_RIGHT;
  1692. }
  1693. }
  1694. else if (_tcsicmp(pstrName, _T("endellipsis")) == 0) {
  1695. if (_tcsicmp(pstrValue, _T("true")) == 0) m_uTextStyle |= DT_END_ELLIPSIS;
  1696. else m_uTextStyle &= ~DT_END_ELLIPSIS;
  1697. }
  1698. else if (_tcsicmp(pstrName, _T("font")) == 0) SetFont(_ttoi(pstrValue));
  1699. else if (_tcsicmp(pstrName, _T("textcolor")) == 0) {
  1700. if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
  1701. LPTSTR pstr = NULL;
  1702. DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
  1703. SetTextColor(clrColor);
  1704. }
  1705. else if (_tcsicmp(pstrName, _T("textpadding")) == 0) {
  1706. RECT rcTextPadding = { 0 };
  1707. LPTSTR pstr = NULL;
  1708. rcTextPadding.left = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  1709. rcTextPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1710. rcTextPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1711. rcTextPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  1712. SetTextPadding(rcTextPadding);
  1713. }
  1714. else if (_tcsicmp(pstrName, _T("showhtml")) == 0) SetShowHtml(_tcsicmp(pstrValue, _T("true")) == 0);
  1715. else if (_tcsicmp(pstrName, _T("normalimage")) == 0) SetNormalImage(pstrValue);
  1716. else if (_tcsicmp(pstrName, _T("hotimage")) == 0) SetHotImage(pstrValue);
  1717. else if (_tcsicmp(pstrName, _T("pushedimage")) == 0) SetPushedImage(pstrValue);
  1718. else if (_tcsicmp(pstrName, _T("focusedimage")) == 0) SetFocusedImage(pstrValue);
  1719. else if (_tcsicmp(pstrName, _T("sepimage")) == 0) SetSepImage(pstrValue);
  1720. else if (_tcsicmp(pstrName, _T("scale")) == 0) {
  1721. LPTSTR pstr = NULL;
  1722. SetScale(_tcstol(pstrValue, &pstr, 10));
  1723. }
  1724. else CHorizontalLayoutUI::SetAttribute(pstrName, pstrValue);
  1725. }
  1726. void CListHeaderItemUI::DoEvent(TEventUI& event)
  1727. {
  1728. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  1729. if (m_pParent != NULL) m_pParent->DoEvent(event);
  1730. else CContainerUI::DoEvent(event);
  1731. return;
  1732. }
  1733. if (event.Type == UIEVENT_SETFOCUS)
  1734. {
  1735. Invalidate();
  1736. }
  1737. if (event.Type == UIEVENT_KILLFOCUS)
  1738. {
  1739. Invalidate();
  1740. }
  1741. if (event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK)
  1742. {
  1743. if (!IsEnabled()) return;
  1744. RECT rcSeparator = GetThumbRect();
  1745. if (m_iSepWidth >= 0)
  1746. rcSeparator.left -= 4;
  1747. else
  1748. rcSeparator.right += 4;
  1749. if (::PtInRect(&rcSeparator, event.ptMouse)) {
  1750. if (m_bDragable) {
  1751. m_uButtonState |= UISTATE_CAPTURED;
  1752. ptLastMouse = event.ptMouse;
  1753. }
  1754. }
  1755. else {
  1756. m_uButtonState |= UISTATE_PUSHED;
  1757. m_pManager->SendNotify(this, DUI_MSGTYPE_HEADERCLICK);
  1758. Invalidate();
  1759. }
  1760. return;
  1761. }
  1762. if (event.Type == UIEVENT_BUTTONUP)
  1763. {
  1764. if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
  1765. m_uButtonState &= ~UISTATE_CAPTURED;
  1766. if (GetParent())
  1767. GetParent()->NeedParentUpdate();
  1768. }
  1769. else if ((m_uButtonState & UISTATE_PUSHED) != 0) {
  1770. m_uButtonState &= ~UISTATE_PUSHED;
  1771. Invalidate();
  1772. }
  1773. return;
  1774. }
  1775. if (event.Type == UIEVENT_MOUSEMOVE)
  1776. {
  1777. if ((m_uButtonState & UISTATE_CAPTURED) != 0) {
  1778. RECT rcPadding = GetPadding();
  1779. RECT rc = m_rcItem;
  1780. if (m_iSepWidth >= 0) {
  1781. rc.right -= ptLastMouse.x - event.ptMouse.x;
  1782. }
  1783. else {
  1784. rc.left -= ptLastMouse.x - event.ptMouse.x;
  1785. }
  1786. if (rc.right - rc.left - rcPadding.right > GetMinWidth()) {
  1787. m_cxyFixed.cx = rc.right - rc.left - rcPadding.right;
  1788. ptLastMouse = event.ptMouse;
  1789. if (GetParent())
  1790. GetParent()->NeedParentUpdate();
  1791. }
  1792. }
  1793. return;
  1794. }
  1795. if (event.Type == UIEVENT_SETCURSOR)
  1796. {
  1797. RECT rcSeparator = GetThumbRect();
  1798. if (m_iSepWidth >= 0)
  1799. rcSeparator.left -= 4;
  1800. else
  1801. rcSeparator.right += 4;
  1802. if (IsEnabled() && m_bDragable && ::PtInRect(&rcSeparator, event.ptMouse)) {
  1803. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
  1804. return;
  1805. }
  1806. }
  1807. if (event.Type == UIEVENT_MOUSEENTER)
  1808. {
  1809. if (IsEnabled()) {
  1810. m_uButtonState |= UISTATE_HOT;
  1811. Invalidate();
  1812. }
  1813. return;
  1814. }
  1815. if (event.Type == UIEVENT_MOUSELEAVE)
  1816. {
  1817. if (IsEnabled()) {
  1818. m_uButtonState &= ~UISTATE_HOT;
  1819. Invalidate();
  1820. }
  1821. return;
  1822. }
  1823. CHorizontalLayoutUI::DoEvent(event);
  1824. }
  1825. SIZE CListHeaderItemUI::EstimateSize(SIZE szAvailable)
  1826. {
  1827. if (m_cxyFixed.cy == 0) return CDuiSize(m_cxyFixed.cx, m_pManager->GetDefaultFontInfo()->tm.tmHeight + 14);
  1828. return CHorizontalLayoutUI::EstimateSize(szAvailable);
  1829. }
  1830. RECT CListHeaderItemUI::GetThumbRect() const
  1831. {
  1832. if (m_iSepWidth >= 0) return CDuiRect(m_rcItem.right - m_iSepWidth, m_rcItem.top, m_rcItem.right, m_rcItem.bottom);
  1833. else return CDuiRect(m_rcItem.left, m_rcItem.top, m_rcItem.left - m_iSepWidth, m_rcItem.bottom);
  1834. }
  1835. void CListHeaderItemUI::PaintStatusImage(HDC hDC)
  1836. {
  1837. if (IsFocused()) m_uButtonState |= UISTATE_FOCUSED;
  1838. else m_uButtonState &= ~UISTATE_FOCUSED;
  1839. if ((m_uButtonState & UISTATE_PUSHED) != 0) {
  1840. if (m_sPushedImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1841. if (!DrawImage(hDC, (LPCTSTR)m_sPushedImage)) {}
  1842. }
  1843. else if ((m_uButtonState & UISTATE_HOT) != 0) {
  1844. if (m_sHotImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1845. if (!DrawImage(hDC, (LPCTSTR)m_sHotImage)) {}
  1846. }
  1847. else if ((m_uButtonState & UISTATE_FOCUSED) != 0) {
  1848. if (m_sFocusedImage.IsEmpty() && !m_sNormalImage.IsEmpty()) DrawImage(hDC, (LPCTSTR)m_sNormalImage);
  1849. if (!DrawImage(hDC, (LPCTSTR)m_sFocusedImage)) {}
  1850. }
  1851. else {
  1852. if (!m_sNormalImage.IsEmpty()) {
  1853. if (!DrawImage(hDC, (LPCTSTR)m_sNormalImage)) {}
  1854. }
  1855. }
  1856. if (!m_sSepImage.IsEmpty()) {
  1857. RECT rcThumb = GetThumbRect();
  1858. rcThumb.left -= m_rcItem.left;
  1859. rcThumb.top -= m_rcItem.top;
  1860. rcThumb.right -= m_rcItem.left;
  1861. rcThumb.bottom -= m_rcItem.top;
  1862. m_sSepImageModify.Empty();
  1863. m_sSepImageModify.SmallFormat(_T("dest='%d,%d,%d,%d'"), rcThumb.left, rcThumb.top, rcThumb.right, rcThumb.bottom);
  1864. if (!DrawImage(hDC, (LPCTSTR)m_sSepImage, (LPCTSTR)m_sSepImageModify)) {}
  1865. }
  1866. }
  1867. void CListHeaderItemUI::PaintText(HDC hDC)
  1868. {
  1869. if (m_dwTextColor == 0) m_dwTextColor = m_pManager->GetDefaultFontColor();
  1870. RECT rcText = m_rcItem;
  1871. rcText.left += m_rcTextPadding.left;
  1872. rcText.top += m_rcTextPadding.top;
  1873. rcText.right -= m_rcTextPadding.right;
  1874. rcText.bottom -= m_rcTextPadding.bottom;
  1875. CDuiString sText = GetText();
  1876. if (sText.IsEmpty()) return;
  1877. int nLinks = 0;
  1878. if (m_bShowHtml)
  1879. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, m_dwTextColor, \
  1880. NULL, NULL, nLinks, m_iFont, m_uTextStyle);
  1881. else
  1882. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, m_dwTextColor, \
  1883. m_iFont, m_uTextStyle);
  1884. }
  1885. /////////////////////////////////////////////////////////////////////////////////////
  1886. //
  1887. //
  1888. CListElementUI::CListElementUI() : m_iIndex(-1),
  1889. m_pOwner(NULL),
  1890. m_bSelected(false),
  1891. m_uButtonState(0)
  1892. {
  1893. }
  1894. LPCTSTR CListElementUI::GetClass() const
  1895. {
  1896. return _T("ListElementUI");
  1897. }
  1898. UINT CListElementUI::GetControlFlags() const
  1899. {
  1900. return UIFLAG_WANTRETURN;
  1901. }
  1902. LPVOID CListElementUI::GetInterface(LPCTSTR pstrName)
  1903. {
  1904. if (_tcsicmp(pstrName, DUI_CTR_LISTITEM) == 0) return static_cast<IListItemUI*>(this);
  1905. if (_tcsicmp(pstrName, DUI_CTR_LISTELEMENT) == 0) return static_cast<CListElementUI*>(this);
  1906. return CControlUI::GetInterface(pstrName);
  1907. }
  1908. IListOwnerUI* CListElementUI::GetOwner()
  1909. {
  1910. return m_pOwner;
  1911. }
  1912. void CListElementUI::SetOwner(CControlUI* pOwner)
  1913. {
  1914. m_pOwner = static_cast<IListOwnerUI*>(pOwner->GetInterface(_T("IListOwner")));
  1915. }
  1916. void CListElementUI::SetVisible(bool bVisible)
  1917. {
  1918. CControlUI::SetVisible(bVisible);
  1919. if (!IsVisible() && m_bSelected)
  1920. {
  1921. m_bSelected = false;
  1922. if (m_pOwner != NULL) m_pOwner->SelectItem(-1);
  1923. }
  1924. }
  1925. void CListElementUI::SetEnabled(bool bEnable)
  1926. {
  1927. CControlUI::SetEnabled(bEnable);
  1928. if (!IsEnabled()) {
  1929. m_uButtonState = 0;
  1930. }
  1931. }
  1932. int CListElementUI::GetIndex() const
  1933. {
  1934. return m_iIndex;
  1935. }
  1936. void CListElementUI::SetIndex(int iIndex)
  1937. {
  1938. m_iIndex = iIndex;
  1939. }
  1940. void CListElementUI::Invalidate()
  1941. {
  1942. if (!IsVisible()) return;
  1943. if (GetParent()) {
  1944. CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
  1945. if (pParentContainer) {
  1946. RECT rc = pParentContainer->GetPos();
  1947. RECT rcInset = pParentContainer->GetInset();
  1948. rc.left += rcInset.left;
  1949. rc.top += rcInset.top;
  1950. rc.right -= rcInset.right;
  1951. rc.bottom -= rcInset.bottom;
  1952. CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
  1953. if (pVerticalScrollBar && pVerticalScrollBar->IsVisible()) rc.right -= pVerticalScrollBar->GetFixedWidth();
  1954. CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
  1955. if (pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
  1956. RECT invalidateRc = m_rcItem;
  1957. if (!::IntersectRect(&invalidateRc, &m_rcItem, &rc))
  1958. {
  1959. return;
  1960. }
  1961. CControlUI* pParent = GetParent();
  1962. RECT rcTemp;
  1963. RECT rcParent;
  1964. while (pParent = pParent->GetParent())
  1965. {
  1966. rcTemp = invalidateRc;
  1967. rcParent = pParent->GetPos();
  1968. if (!::IntersectRect(&invalidateRc, &rcTemp, &rcParent))
  1969. {
  1970. return;
  1971. }
  1972. }
  1973. if (m_pManager != NULL) m_pManager->Invalidate(invalidateRc);
  1974. }
  1975. else {
  1976. CControlUI::Invalidate();
  1977. }
  1978. }
  1979. else {
  1980. CControlUI::Invalidate();
  1981. }
  1982. }
  1983. bool CListElementUI::Activate()
  1984. {
  1985. if (!CControlUI::Activate()) return false;
  1986. if (m_pManager != NULL) m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMACTIVATE);
  1987. return true;
  1988. }
  1989. bool CListElementUI::IsSelected() const
  1990. {
  1991. return m_bSelected;
  1992. }
  1993. bool CListElementUI::Select(bool bSelect)
  1994. {
  1995. if (!IsEnabled()) return false;
  1996. // 取消其它列表项数据
  1997. if (m_pOwner) {
  1998. m_pOwner->UnSelectItem(m_iIndex, true);
  1999. }
  2000. if (bSelect == m_bSelected) return true;
  2001. m_bSelected = bSelect;
  2002. if (m_pOwner) {
  2003. if (bSelect) m_pOwner->SelectItem(m_iIndex);
  2004. else m_pOwner->UnSelectItem(m_iIndex);
  2005. }
  2006. Invalidate();
  2007. return true;
  2008. }
  2009. bool CListElementUI::SelectMulti(bool bSelect)
  2010. {
  2011. if (!IsEnabled()) return false;
  2012. if (bSelect == m_bSelected) return true;
  2013. m_bSelected = bSelect;
  2014. Invalidate();
  2015. return true;
  2016. }
  2017. bool CListElementUI::IsExpanded() const
  2018. {
  2019. return false;
  2020. }
  2021. bool CListElementUI::Expand(bool /*bExpand = true*/)
  2022. {
  2023. return false;
  2024. }
  2025. void CListElementUI::DoEvent(TEventUI& event)
  2026. {
  2027. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2028. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2029. else CControlUI::DoEvent(event);
  2030. return;
  2031. }
  2032. if (event.Type == UIEVENT_DBLCLICK)
  2033. {
  2034. if (IsEnabled()) {
  2035. Activate();
  2036. Invalidate();
  2037. }
  2038. return;
  2039. }
  2040. if (event.Type == UIEVENT_KEYDOWN && IsEnabled())
  2041. {
  2042. if (event.chKey == VK_RETURN) {
  2043. Activate();
  2044. Invalidate();
  2045. return;
  2046. }
  2047. }
  2048. // An important twist: The list-item will send the event not to its immediate
  2049. // parent but to the "attached" list. A list may actually embed several components
  2050. // in its path to the item, but key-presses etc. needs to go to the actual list.
  2051. if (m_pOwner != NULL) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event);
  2052. }
  2053. void CListElementUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  2054. {
  2055. if (_tcsicmp(pstrName, _T("selected")) == 0) Select();
  2056. else CControlUI::SetAttribute(pstrName, pstrValue);
  2057. }
  2058. void CListElementUI::DrawItemBk(HDC hDC, const RECT& rcItem)
  2059. {
  2060. ASSERT(m_pOwner);
  2061. if (m_pOwner == NULL) return;
  2062. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2063. DWORD iBackColor = 0;
  2064. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) iBackColor = pInfo->dwBkColor;
  2065. if ((m_uButtonState & UISTATE_HOT) != 0 && pInfo->dwHotBkColor > 0) {
  2066. iBackColor = pInfo->dwHotBkColor;
  2067. }
  2068. if (IsSelected() && pInfo->dwSelectedBkColor > 0) {
  2069. iBackColor = pInfo->dwSelectedBkColor;
  2070. }
  2071. if (!IsEnabled() && pInfo->dwDisabledBkColor > 0) {
  2072. iBackColor = pInfo->dwDisabledBkColor;
  2073. }
  2074. if (iBackColor != 0) {
  2075. CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(iBackColor));
  2076. }
  2077. if (!IsEnabled()) {
  2078. if (!pInfo->sDisabledImage.IsEmpty()) {
  2079. if (!DrawImage(hDC, (LPCTSTR)pInfo->sDisabledImage)) {}
  2080. else return;
  2081. }
  2082. }
  2083. if (IsSelected()) {
  2084. if (!pInfo->sSelectedImage.IsEmpty()) {
  2085. if (!DrawImage(hDC, (LPCTSTR)pInfo->sSelectedImage)) {}
  2086. else return;
  2087. }
  2088. }
  2089. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2090. if (!pInfo->sHotImage.IsEmpty()) {
  2091. if (!DrawImage(hDC, (LPCTSTR)pInfo->sHotImage)) {}
  2092. else return;
  2093. }
  2094. }
  2095. if (!m_sBkImage.IsEmpty()) {
  2096. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) {
  2097. if (!DrawImage(hDC, (LPCTSTR)m_sBkImage)) {}
  2098. }
  2099. }
  2100. if (m_sBkImage.IsEmpty()) {
  2101. if (!pInfo->sBkImage.IsEmpty()) {
  2102. if (!DrawImage(hDC, (LPCTSTR)pInfo->sBkImage)) {}
  2103. else return;
  2104. }
  2105. }
  2106. if (pInfo->dwLineColor != 0) {
  2107. if (pInfo->bShowRowLine) {
  2108. RECT rcLine = { m_rcItem.left, m_rcItem.bottom - 1, m_rcItem.right, m_rcItem.bottom - 1 };
  2109. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2110. }
  2111. if (pInfo->bShowColumnLine) {
  2112. for (int i = 0; i < pInfo->nColumns; i++) {
  2113. RECT rcLine = { pInfo->rcColumn[i].right - 1, m_rcItem.top, pInfo->rcColumn[i].right - 1, m_rcItem.bottom };
  2114. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2115. }
  2116. }
  2117. }
  2118. }
  2119. /////////////////////////////////////////////////////////////////////////////////////
  2120. //
  2121. //
  2122. IMPLEMENT_DUICONTROL(CListLabelElementUI)
  2123. CListLabelElementUI::CListLabelElementUI()
  2124. {
  2125. }
  2126. LPCTSTR CListLabelElementUI::GetClass() const
  2127. {
  2128. return _T("ListLabelElementUI");
  2129. }
  2130. LPVOID CListLabelElementUI::GetInterface(LPCTSTR pstrName)
  2131. {
  2132. if (_tcsicmp(pstrName, DUI_CTR_LISTLABELELEMENT) == 0) return static_cast<CListLabelElementUI*>(this);
  2133. return CListElementUI::GetInterface(pstrName);
  2134. }
  2135. void CListLabelElementUI::DoEvent(TEventUI& event)
  2136. {
  2137. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2138. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2139. else CListElementUI::DoEvent(event);
  2140. return;
  2141. }
  2142. // 右键选择
  2143. if (m_pOwner != NULL)
  2144. {
  2145. if (m_pOwner->GetListInfo()->bRSelected && event.Type == UIEVENT_RBUTTONDOWN)
  2146. {
  2147. if (IsEnabled()) {
  2148. // 多选
  2149. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2150. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2151. }
  2152. else {
  2153. Select(true);
  2154. }
  2155. }
  2156. return;
  2157. }
  2158. }
  2159. if (event.Type == UIEVENT_BUTTONDOWN)
  2160. {
  2161. if (IsEnabled()) {
  2162. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_BUTTONDOWN);
  2163. // 多选
  2164. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2165. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2166. }
  2167. else {
  2168. Select(true);
  2169. }
  2170. }
  2171. return;
  2172. }
  2173. if (event.Type == UIEVENT_BUTTONUP)
  2174. {
  2175. if (IsEnabled()) {
  2176. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMCLICK);
  2177. }
  2178. return;
  2179. }
  2180. if (event.Type == UIEVENT_MOUSEENTER)
  2181. {
  2182. if (IsEnabled()) {
  2183. m_uButtonState |= UISTATE_HOT;
  2184. Invalidate();
  2185. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSEENTER);
  2186. }
  2187. return;
  2188. }
  2189. if (event.Type == UIEVENT_MOUSELEAVE)
  2190. {
  2191. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2192. m_uButtonState &= ~UISTATE_HOT;
  2193. Invalidate();
  2194. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSELEAVE);
  2195. }
  2196. return;
  2197. }
  2198. CListElementUI::DoEvent(event);
  2199. }
  2200. SIZE CListLabelElementUI::EstimateSize(SIZE szAvailable)
  2201. {
  2202. if (m_pOwner == NULL) return CDuiSize(0, 0);
  2203. CDuiString sText = GetText();
  2204. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2205. SIZE cXY = m_cxyFixed;
  2206. if (cXY.cy == 0 && m_pManager != NULL) {
  2207. cXY.cy = m_pManager->GetFontInfo(pInfo->nFont)->tm.tmHeight + 8;
  2208. cXY.cy += pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom;
  2209. }
  2210. if (cXY.cx == 0) {
  2211. cXY.cx = szAvailable.cx;
  2212. }
  2213. return cXY;
  2214. }
  2215. bool CListLabelElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  2216. {
  2217. DrawItemBk(hDC, m_rcItem);
  2218. DrawItemText(hDC, m_rcItem);
  2219. return true;
  2220. }
  2221. void CListLabelElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2222. {
  2223. CDuiString sText = GetText();
  2224. if (sText.IsEmpty()) return;
  2225. if (m_pOwner == NULL) return;
  2226. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2227. DWORD iTextColor = pInfo->dwTextColor;
  2228. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2229. iTextColor = pInfo->dwHotTextColor;
  2230. }
  2231. if (IsSelected()) {
  2232. iTextColor = pInfo->dwSelectedTextColor;
  2233. }
  2234. if (!IsEnabled()) {
  2235. iTextColor = pInfo->dwDisabledTextColor;
  2236. }
  2237. int nLinks = 0;
  2238. RECT rcText = rcItem;
  2239. RECT rcTextPadding = GetManager()->GetDPIObj()->Scale(pInfo->rcTextPadding);
  2240. rcText.left += rcTextPadding.left;
  2241. rcText.right -= rcTextPadding.right;
  2242. rcText.top += rcTextPadding.top;
  2243. rcText.bottom -= rcTextPadding.bottom;
  2244. if (pInfo->bShowHtml)
  2245. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, iTextColor, \
  2246. NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle);
  2247. else
  2248. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, iTextColor, \
  2249. pInfo->nFont, pInfo->uTextStyle);
  2250. }
  2251. /////////////////////////////////////////////////////////////////////////////////////
  2252. //
  2253. //
  2254. IMPLEMENT_DUICONTROL(CListTextElementUI)
  2255. CListTextElementUI::CListTextElementUI() : m_nLinks(0), m_nHoverLink(-1), m_pOwner(NULL)
  2256. {
  2257. ::ZeroMemory(&m_rcLinks, sizeof(m_rcLinks));
  2258. }
  2259. CListTextElementUI::~CListTextElementUI()
  2260. {
  2261. CDuiString* pText;
  2262. for (int it = 0; it < m_aTexts.GetSize(); it++) {
  2263. pText = static_cast<CDuiString*>(m_aTexts[it]);
  2264. if (pText) delete pText;
  2265. }
  2266. m_aTexts.Empty();
  2267. }
  2268. LPCTSTR CListTextElementUI::GetClass() const
  2269. {
  2270. return _T("ListTextElementUI");
  2271. }
  2272. LPVOID CListTextElementUI::GetInterface(LPCTSTR pstrName)
  2273. {
  2274. if (_tcsicmp(pstrName, DUI_CTR_LISTTEXTELEMENT) == 0) return static_cast<CListTextElementUI*>(this);
  2275. return CListLabelElementUI::GetInterface(pstrName);
  2276. }
  2277. UINT CListTextElementUI::GetControlFlags() const
  2278. {
  2279. return UIFLAG_WANTRETURN | ((IsEnabled() && m_nLinks > 0) ? UIFLAG_SETCURSOR : 0);
  2280. }
  2281. LPCTSTR CListTextElementUI::GetText(int iIndex) const
  2282. {
  2283. CDuiString* pText = static_cast<CDuiString*>(m_aTexts.GetAt(iIndex));
  2284. if (pText) {
  2285. if (!IsResourceText())
  2286. return pText->GetData();
  2287. return CResourceManager::GetInstance()->GetText(*pText);
  2288. }
  2289. return NULL;
  2290. }
  2291. void CListTextElementUI::SetText(int iIndex, LPCTSTR pstrText)
  2292. {
  2293. if (m_pOwner == NULL) return;
  2294. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2295. if (iIndex < 0 || iIndex >= pInfo->nColumns) return;
  2296. while (m_aTexts.GetSize() < pInfo->nColumns) { m_aTexts.Add(NULL); }
  2297. CDuiString* pText = static_cast<CDuiString*>(m_aTexts[iIndex]);
  2298. if ((pText == NULL && pstrText == NULL) || (pText && *pText == pstrText)) return;
  2299. if (pText) { delete pText; pText = NULL; }
  2300. m_aTexts.SetAt(iIndex, new CDuiString(pstrText));
  2301. Invalidate();
  2302. }
  2303. DWORD CListTextElementUI::GetTextColor(int iIndex) const
  2304. {
  2305. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2306. if( iIndex < 0 || iIndex >= pInfo->nColumns || m_aTextColors.GetSize() <= 0 ) return pInfo->dwTextColor;
  2307. DWORD dwColor = (DWORD)m_aTextColors.GetAt(iIndex);
  2308. return dwColor;
  2309. }
  2310. void CListTextElementUI::SetTextColor(int iIndex, DWORD dwTextColor)
  2311. {
  2312. if( m_pOwner == NULL ) return;
  2313. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2314. if( iIndex < 0 || iIndex >= pInfo->nColumns ) return;
  2315. while( m_aTextColors.GetSize() < pInfo->nColumns ) { m_aTextColors.Add((LPVOID)pInfo->dwTextColor); }
  2316. m_aTextColors.SetAt(iIndex, (LPVOID)dwTextColor);
  2317. Invalidate();
  2318. }
  2319. void CListTextElementUI::SetOwner(CControlUI* pOwner)
  2320. {
  2321. CListElementUI::SetOwner(pOwner);
  2322. m_pOwner = static_cast<IListUI*>(pOwner->GetInterface(_T("IList")));
  2323. }
  2324. CDuiString* CListTextElementUI::GetLinkContent(int iIndex)
  2325. {
  2326. if (iIndex >= 0 && iIndex < m_nLinks) return &m_sLinks[iIndex];
  2327. return NULL;
  2328. }
  2329. void CListTextElementUI::DoEvent(TEventUI& event)
  2330. {
  2331. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2332. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2333. else CListLabelElementUI::DoEvent(event);
  2334. return;
  2335. }
  2336. // When you hover over a link
  2337. if (event.Type == UIEVENT_SETCURSOR) {
  2338. for (int i = 0; i < m_nLinks; i++) {
  2339. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2340. ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
  2341. return;
  2342. }
  2343. }
  2344. }
  2345. if (event.Type == UIEVENT_BUTTONUP && IsEnabled()) {
  2346. for (int i = 0; i < m_nLinks; i++) {
  2347. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2348. m_pManager->SendNotify(this, DUI_MSGTYPE_LINK, i);
  2349. return;
  2350. }
  2351. }
  2352. }
  2353. if (m_nLinks > 0 && event.Type == UIEVENT_MOUSEMOVE) {
  2354. int nHoverLink = -1;
  2355. for (int i = 0; i < m_nLinks; i++) {
  2356. if (::PtInRect(&m_rcLinks[i], event.ptMouse)) {
  2357. nHoverLink = i;
  2358. break;
  2359. }
  2360. }
  2361. if (m_nHoverLink != nHoverLink) {
  2362. Invalidate();
  2363. m_nHoverLink = nHoverLink;
  2364. }
  2365. }
  2366. if (m_nLinks > 0 && event.Type == UIEVENT_MOUSELEAVE) {
  2367. if (m_nHoverLink != -1) {
  2368. Invalidate();
  2369. m_nHoverLink = -1;
  2370. }
  2371. }
  2372. CListLabelElementUI::DoEvent(event);
  2373. }
  2374. SIZE CListTextElementUI::EstimateSize(SIZE szAvailable)
  2375. {
  2376. TListInfoUI* pInfo = NULL;
  2377. if (m_pOwner) pInfo = m_pOwner->GetListInfo();
  2378. SIZE cXY = m_cxyFixed;
  2379. if (cXY.cy == 0 && m_pManager != NULL) {
  2380. cXY.cy = m_pManager->GetFontInfo(pInfo->nFont)->tm.tmHeight + 8;
  2381. if (pInfo) cXY.cy += pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom;
  2382. }
  2383. return cXY;
  2384. }
  2385. void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2386. {
  2387. if( m_pOwner == NULL ) return;
  2388. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2389. IListCallbackUI* pCallback = m_pOwner->GetTextCallback();
  2390. m_nLinks = 0;
  2391. int nLinks = lengthof(m_rcLinks);
  2392. for( int i = 0; i < pInfo->nColumns; i++ )
  2393. {
  2394. RECT rcItem = { pInfo->rcColumn[i].left, m_rcItem.top, pInfo->rcColumn[i].right, m_rcItem.bottom };
  2395. rcItem.left += pInfo->rcTextPadding.left;
  2396. rcItem.right -= pInfo->rcTextPadding.right;
  2397. rcItem.top += pInfo->rcTextPadding.top;
  2398. rcItem.bottom -= pInfo->rcTextPadding.bottom;
  2399. DWORD iTextColor = pInfo->dwTextColor;
  2400. CDuiString strText;
  2401. if( pCallback ) {
  2402. strText = pCallback->GetItemText(this, m_iIndex, i);
  2403. int iState = 0;
  2404. if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  2405. iState = 1;
  2406. }
  2407. if( IsSelected() ) {
  2408. iState = 2;
  2409. }
  2410. if( !IsEnabled() ) {
  2411. iState = 3;
  2412. }
  2413. iTextColor = pCallback->GetItemTextColor(this, m_iIndex, i, iState);
  2414. }
  2415. else {
  2416. strText.Assign(GetText(i));
  2417. iTextColor = GetTextColor(i);
  2418. if( (m_uButtonState & UISTATE_HOT) != 0 ) {
  2419. iTextColor = pInfo->dwHotTextColor;
  2420. }
  2421. if( IsSelected() ) {
  2422. iTextColor = pInfo->dwSelectedTextColor;
  2423. }
  2424. if( !IsEnabled() ) {
  2425. iTextColor = pInfo->dwDisabledTextColor;
  2426. }
  2427. }
  2428. if( pInfo->bShowHtml )
  2429. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, \
  2430. &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], nLinks, pInfo->nFont, pInfo->uTextStyle);
  2431. else
  2432. CRenderEngine::DrawText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, \
  2433. pInfo->nFont, pInfo->uTextStyle);
  2434. m_nLinks += nLinks;
  2435. nLinks = lengthof(m_rcLinks) - m_nLinks;
  2436. }
  2437. for( int i = m_nLinks; i < lengthof(m_rcLinks); i++ ) {
  2438. ::ZeroMemory(m_rcLinks + i, sizeof(RECT));
  2439. ((CDuiString*)(m_sLinks + i))->Empty();
  2440. }
  2441. }
  2442. /////////////////////////////////////////////////////////////////////////////////////
  2443. //
  2444. //
  2445. IMPLEMENT_DUICONTROL(CListContainerElementUI)
  2446. CListContainerElementUI::CListContainerElementUI() :
  2447. m_iIndex(-1),
  2448. m_pOwner(NULL),
  2449. m_bSelected(false),
  2450. m_uButtonState(0)
  2451. {
  2452. }
  2453. LPCTSTR CListContainerElementUI::GetClass() const
  2454. {
  2455. return _T("ListContainerElementUI");
  2456. }
  2457. UINT CListContainerElementUI::GetControlFlags() const
  2458. {
  2459. return UIFLAG_WANTRETURN;
  2460. }
  2461. LPVOID CListContainerElementUI::GetInterface(LPCTSTR pstrName)
  2462. {
  2463. if (_tcsicmp(pstrName, DUI_CTR_LISTITEM) == 0) return static_cast<IListItemUI*>(this);
  2464. if (_tcsicmp(pstrName, DUI_CTR_LISTCONTAINERELEMENT) == 0) return static_cast<CListContainerElementUI*>(this);
  2465. return CContainerUI::GetInterface(pstrName);
  2466. }
  2467. IListOwnerUI* CListContainerElementUI::GetOwner()
  2468. {
  2469. return m_pOwner;
  2470. }
  2471. void CListContainerElementUI::SetOwner(CControlUI* pOwner)
  2472. {
  2473. m_pOwner = static_cast<IListOwnerUI*>(pOwner->GetInterface(_T("IListOwner")));
  2474. }
  2475. void CListContainerElementUI::SetVisible(bool bVisible)
  2476. {
  2477. CContainerUI::SetVisible(bVisible);
  2478. if (!IsVisible() && m_bSelected)
  2479. {
  2480. m_bSelected = false;
  2481. if (m_pOwner != NULL) m_pOwner->SelectItem(-1);
  2482. }
  2483. }
  2484. void CListContainerElementUI::SetEnabled(bool bEnable)
  2485. {
  2486. CControlUI::SetEnabled(bEnable);
  2487. if (!IsEnabled()) {
  2488. m_uButtonState = 0;
  2489. }
  2490. }
  2491. int CListContainerElementUI::GetIndex() const
  2492. {
  2493. return m_iIndex;
  2494. }
  2495. void CListContainerElementUI::SetIndex(int iIndex)
  2496. {
  2497. m_iIndex = iIndex;
  2498. }
  2499. void CListContainerElementUI::Invalidate()
  2500. {
  2501. if (!IsVisible()) return;
  2502. if (GetParent()) {
  2503. CContainerUI* pParentContainer = static_cast<CContainerUI*>(GetParent()->GetInterface(_T("Container")));
  2504. if (pParentContainer) {
  2505. RECT rc = pParentContainer->GetPos();
  2506. RECT rcInset = pParentContainer->GetInset();
  2507. rc.left += rcInset.left;
  2508. rc.top += rcInset.top;
  2509. rc.right -= rcInset.right;
  2510. rc.bottom -= rcInset.bottom;
  2511. CScrollBarUI* pVerticalScrollBar = pParentContainer->GetVerticalScrollBar();
  2512. if (pVerticalScrollBar && pVerticalScrollBar->IsVisible()) rc.right -= pVerticalScrollBar->GetFixedWidth();
  2513. CScrollBarUI* pHorizontalScrollBar = pParentContainer->GetHorizontalScrollBar();
  2514. if (pHorizontalScrollBar && pHorizontalScrollBar->IsVisible()) rc.bottom -= pHorizontalScrollBar->GetFixedHeight();
  2515. RECT invalidateRc = m_rcItem;
  2516. if (!::IntersectRect(&invalidateRc, &m_rcItem, &rc))
  2517. {
  2518. return;
  2519. }
  2520. CControlUI* pParent = GetParent();
  2521. RECT rcTemp;
  2522. RECT rcParent;
  2523. while (pParent = pParent->GetParent())
  2524. {
  2525. rcTemp = invalidateRc;
  2526. rcParent = pParent->GetPos();
  2527. if (!::IntersectRect(&invalidateRc, &rcTemp, &rcParent))
  2528. {
  2529. return;
  2530. }
  2531. }
  2532. if (m_pManager != NULL) m_pManager->Invalidate(invalidateRc);
  2533. }
  2534. else {
  2535. CContainerUI::Invalidate();
  2536. }
  2537. }
  2538. else {
  2539. CContainerUI::Invalidate();
  2540. }
  2541. }
  2542. bool CListContainerElementUI::Activate()
  2543. {
  2544. if (!CContainerUI::Activate()) return false;
  2545. if (m_pManager != NULL) m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMACTIVATE);
  2546. return true;
  2547. }
  2548. bool CListContainerElementUI::IsSelected() const
  2549. {
  2550. return m_bSelected;
  2551. }
  2552. bool CListContainerElementUI::Select(bool bSelect)
  2553. {
  2554. if (!IsEnabled()) return false;
  2555. // 取消其它列表项数据
  2556. if (m_pOwner) {
  2557. m_pOwner->UnSelectItem(m_iIndex, true);
  2558. }
  2559. if (bSelect == m_bSelected) return true;
  2560. m_bSelected = bSelect;
  2561. if (m_pOwner) {
  2562. if (bSelect) m_pOwner->SelectItem(m_iIndex);
  2563. else m_pOwner->UnSelectItem(m_iIndex);
  2564. }
  2565. Invalidate();
  2566. return true;
  2567. }
  2568. bool CListContainerElementUI::SelectMulti(bool bSelect)
  2569. {
  2570. if (!IsEnabled()) return false;
  2571. if (bSelect == m_bSelected) return true;
  2572. m_bSelected = bSelect;
  2573. Invalidate();
  2574. return true;
  2575. }
  2576. bool CListContainerElementUI::IsExpanded() const
  2577. {
  2578. return false;
  2579. }
  2580. bool CListContainerElementUI::Expand(bool /*bExpand = true*/)
  2581. {
  2582. return false;
  2583. }
  2584. void CListContainerElementUI::DoEvent(TEventUI& event)
  2585. {
  2586. if (!IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND) {
  2587. if (m_pOwner != NULL) m_pOwner->DoEvent(event);
  2588. else CContainerUI::DoEvent(event);
  2589. return;
  2590. }
  2591. if (event.Type == UIEVENT_DBLCLICK)
  2592. {
  2593. if (IsEnabled()) {
  2594. Activate();
  2595. Invalidate();
  2596. }
  2597. return;
  2598. }
  2599. if (event.Type == UIEVENT_KEYDOWN && IsEnabled())
  2600. {
  2601. if (event.chKey == VK_RETURN) {
  2602. Activate();
  2603. Invalidate();
  2604. return;
  2605. }
  2606. }
  2607. if (event.Type == UIEVENT_BUTTONDOWN)
  2608. {
  2609. if (IsEnabled()) {
  2610. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_BUTTONDOWN);
  2611. // 多选
  2612. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2613. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2614. }
  2615. else {
  2616. Select(true);
  2617. }
  2618. }
  2619. return;
  2620. }
  2621. // 右键选择
  2622. if (m_pOwner != NULL)
  2623. {
  2624. if (m_pOwner->GetListInfo()->bRSelected && event.Type == UIEVENT_RBUTTONDOWN)
  2625. {
  2626. if (IsEnabled()) {
  2627. // 多选
  2628. if ((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000)) {
  2629. if (m_pOwner != NULL) m_pOwner->SelectMultiItem(m_iIndex);
  2630. }
  2631. else {
  2632. Select(true);
  2633. }
  2634. }
  2635. return;
  2636. }
  2637. }
  2638. if (event.Type == UIEVENT_BUTTONUP)
  2639. {
  2640. if (IsEnabled()) {
  2641. m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMCLICK);
  2642. }
  2643. return;
  2644. }
  2645. if (event.Type == UIEVENT_MOUSEENTER)
  2646. {
  2647. if (IsEnabled()) {
  2648. m_uButtonState |= UISTATE_HOT;
  2649. Invalidate();
  2650. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSEENTER);
  2651. }
  2652. return;
  2653. }
  2654. if (event.Type == UIEVENT_MOUSELEAVE)
  2655. {
  2656. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2657. m_uButtonState &= ~UISTATE_HOT;
  2658. Invalidate();
  2659. if(IsRichEvent()) m_pManager->SendNotify(this, DUI_MSGTYPE_MOUSELEAVE);
  2660. }
  2661. return;
  2662. }
  2663. if (event.Type == UIEVENT_TIMER)
  2664. {
  2665. m_pManager->SendNotify(this, DUI_MSGTYPE_TIMER, event.wParam, event.lParam);
  2666. return;
  2667. }
  2668. if (event.Type == UIEVENT_CONTEXTMENU)
  2669. {
  2670. if (IsContextMenuUsed()) {
  2671. m_pManager->SendNotify(this, DUI_MSGTYPE_MENU, event.wParam, event.lParam);
  2672. return;
  2673. }
  2674. }
  2675. // An important twist: The list-item will send the event not to its immediate
  2676. // parent but to the "attached" list. A list may actually embed several components
  2677. // in its path to the item, but key-presses etc. needs to go to the actual list.
  2678. if (m_pOwner != NULL) m_pOwner->DoEvent(event); else CControlUI::DoEvent(event);
  2679. }
  2680. void CListContainerElementUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
  2681. {
  2682. if (_tcsicmp(pstrName, _T("selected")) == 0) Select();
  2683. //else if( _tcscmp(pstrName, _T("expandable")) == 0 ) SetExpandable(_tcscmp(pstrValue, _T("true")) == 0);
  2684. else CContainerUI::SetAttribute(pstrName, pstrValue);
  2685. }
  2686. bool CListContainerElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl)
  2687. {
  2688. DrawItemBk(hDC, m_rcItem);
  2689. return CContainerUI::DoPaint(hDC, rcPaint, pStopControl);
  2690. }
  2691. void CListContainerElementUI::DrawItemText(HDC hDC, const RECT& rcItem)
  2692. {
  2693. CDuiString sText = GetText();
  2694. if (sText.IsEmpty()) return;
  2695. if (m_pOwner == NULL) return;
  2696. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2697. DWORD iTextColor = pInfo->dwTextColor;
  2698. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2699. iTextColor = pInfo->dwHotTextColor;
  2700. }
  2701. if (IsSelected()) {
  2702. iTextColor = pInfo->dwSelectedTextColor;
  2703. }
  2704. if (!IsEnabled()) {
  2705. iTextColor = pInfo->dwDisabledTextColor;
  2706. }
  2707. int nLinks = 0;
  2708. RECT rcText = rcItem;
  2709. RECT rcTextPadding = GetManager()->GetDPIObj()->Scale(pInfo->rcTextPadding);
  2710. rcText.left += rcTextPadding.left;
  2711. rcText.right -= rcTextPadding.right;
  2712. rcText.top += rcTextPadding.top;
  2713. rcText.bottom -= rcTextPadding.bottom;
  2714. if (pInfo->bShowHtml)
  2715. CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, sText, iTextColor, \
  2716. NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle);
  2717. else
  2718. CRenderEngine::DrawText(hDC, m_pManager, rcText, sText, iTextColor, \
  2719. pInfo->nFont, pInfo->uTextStyle);
  2720. }
  2721. void CListContainerElementUI::DrawItemBk(HDC hDC, const RECT& rcItem)
  2722. {
  2723. ASSERT(m_pOwner);
  2724. if (m_pOwner == NULL) return;
  2725. TListInfoUI* pInfo = m_pOwner->GetListInfo();
  2726. DWORD iBackColor = 0;
  2727. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) iBackColor = pInfo->dwBkColor;
  2728. CDuiString sForeImage = pInfo->sForeImage;
  2729. if ((m_uButtonState & UISTATE_HOT) != 0 && pInfo->dwHotBkColor > 0) {
  2730. iBackColor = pInfo->dwHotBkColor;
  2731. if(!pInfo->sHotForeImage.IsEmpty()) {
  2732. sForeImage = pInfo->sHotForeImage;
  2733. }
  2734. }
  2735. if (IsSelected() && pInfo->dwSelectedBkColor > 0) {
  2736. iBackColor = pInfo->dwSelectedBkColor;
  2737. }
  2738. if (!IsEnabled() && pInfo->dwDisabledBkColor > 0) {
  2739. iBackColor = pInfo->dwDisabledBkColor;
  2740. }
  2741. if (iBackColor != 0) {
  2742. CRenderEngine::DrawColor(hDC, m_rcItem, GetAdjustColor(iBackColor));
  2743. }
  2744. if (!IsEnabled()) {
  2745. if (!pInfo->sDisabledImage.IsEmpty()) {
  2746. if (!DrawImage(hDC, (LPCTSTR)pInfo->sDisabledImage)) {}
  2747. else return;
  2748. }
  2749. }
  2750. if (IsSelected()) {
  2751. if (!pInfo->sSelectedImage.IsEmpty()) {
  2752. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sSelectedImage);
  2753. if(!pInfo->sSelectedForeImage.IsEmpty()) {
  2754. DrawImage(hDC, (LPCTSTR)pInfo->sSelectedForeImage);
  2755. }
  2756. if(bDrawOk) return;
  2757. }
  2758. }
  2759. if ((m_uButtonState & UISTATE_HOT) != 0) {
  2760. if (!pInfo->sHotImage.IsEmpty()) {
  2761. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sHotImage);
  2762. if(!pInfo->sHotForeImage.IsEmpty()) {
  2763. DrawImage(hDC, (LPCTSTR)pInfo->sHotForeImage);
  2764. }
  2765. if(bDrawOk) return;
  2766. }
  2767. }
  2768. if (!m_sBkImage.IsEmpty()) {
  2769. if (!pInfo->bAlternateBk || m_iIndex % 2 == 0) {
  2770. if (!DrawImage(hDC, (LPCTSTR)m_sBkImage)) {}
  2771. if(!pInfo->sForeImage.IsEmpty()) {
  2772. DrawImage(hDC, (LPCTSTR)pInfo->sForeImage);
  2773. }
  2774. }
  2775. }
  2776. if (m_sBkImage.IsEmpty()) {
  2777. if (!pInfo->sBkImage.IsEmpty()) {
  2778. bool bDrawOk = DrawImage(hDC, (LPCTSTR)pInfo->sBkImage);
  2779. if(!pInfo->sForeImage.IsEmpty()) {
  2780. DrawImage(hDC, (LPCTSTR)pInfo->sForeImage);
  2781. }
  2782. }
  2783. }
  2784. if (pInfo->dwLineColor != 0) {
  2785. if (pInfo->bShowRowLine) {
  2786. RECT rcLine = { m_rcItem.left, m_rcItem.bottom - 1, m_rcItem.right, m_rcItem.bottom - 1 };
  2787. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2788. }
  2789. if (pInfo->bShowColumnLine) {
  2790. for (int i = 0; i < pInfo->nColumns; i++) {
  2791. RECT rcLine = { pInfo->rcColumn[i].right - 1, m_rcItem.top, pInfo->rcColumn[i].right - 1, m_rcItem.bottom };
  2792. CRenderEngine::DrawLine(hDC, rcLine, 1, GetAdjustColor(pInfo->dwLineColor));
  2793. }
  2794. }
  2795. }
  2796. }
  2797. void CListContainerElementUI::SetPos(RECT rc, bool bNeedInvalidate)
  2798. {
  2799. if (m_pOwner == NULL) return;
  2800. UINT uListType = m_pOwner->GetListType();
  2801. // 直接按普通纵向布局处理,不再对 LT_LIST 做网格重排
  2802. CHorizontalLayoutUI::SetPos(rc, bNeedInvalidate);
  2803. // 只有 LT_LIST / LT_TREE 需要做表头列宽同步
  2804. if (uListType != LT_LIST && uListType != LT_TREE) return;
  2805. CListUI* pList = static_cast<CListUI*>(m_pOwner);
  2806. if (uListType == LT_TREE)
  2807. {
  2808. pList = (CListUI*)pList->CControlUI::GetInterface(_T("List"));
  2809. if (pList == NULL) return;
  2810. }
  2811. CListHeaderUI* pHeader = pList->GetHeader();
  2812. if (pHeader == NULL || !pHeader->IsVisible()) return;
  2813. int nCount = m_items.GetSize();
  2814. for (int i = 0; i < nCount; i++)
  2815. {
  2816. CControlUI* pListItem = static_cast<CControlUI*>(m_items[i]);
  2817. CControlUI* pHeaderItem = pHeader->GetItemAt(i);
  2818. if (pHeaderItem == NULL) return;
  2819. RECT rcHeaderItem = pHeaderItem->GetPos();
  2820. if (pListItem != NULL && !(rcHeaderItem.left == 0 && rcHeaderItem.right == 0))
  2821. {
  2822. RECT rt = pListItem->GetPos();
  2823. rt.left = rcHeaderItem.left;
  2824. rt.right = rcHeaderItem.right;
  2825. pListItem->SetPos(rt);
  2826. }
  2827. }
  2828. }
  2829. } // namespace DuiLib