UIList.cpp 86 KB

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