UIList.cpp 86 KB

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