UIList.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. #ifndef __UILIST_H__
  2. #define __UILIST_H__
  3. #pragma once
  4. #include "Layout/UIVerticalLayout.h"
  5. #include "Layout/UIHorizontalLayout.h"
  6. namespace DuiLib {
  7. /////////////////////////////////////////////////////////////////////////////////////
  8. //
  9. typedef int (CALLBACK *PULVCompareFunc)(UINT_PTR, UINT_PTR, UINT_PTR);
  10. class CListHeaderUI;
  11. #define UILIST_MAX_COLUMNS 64
  12. typedef struct tagTListInfoUI
  13. {
  14. int nColumns;
  15. RECT rcColumn[UILIST_MAX_COLUMNS];
  16. UINT uFixedHeight;
  17. int nFont;
  18. UINT uTextStyle;
  19. RECT rcTextPadding;
  20. DWORD dwTextColor;
  21. DWORD dwBkColor;
  22. TDrawInfo diBk;
  23. bool bAlternateBk;
  24. DWORD dwSelectedTextColor;
  25. DWORD dwSelectedBkColor;
  26. TDrawInfo diSelected;
  27. DWORD dwHotTextColor;
  28. DWORD dwHotBkColor;
  29. TDrawInfo diHot;
  30. DWORD dwDisabledTextColor;
  31. DWORD dwDisabledBkColor;
  32. TDrawInfo diDisabled;
  33. int iHLineSize;
  34. DWORD dwHLineColor;
  35. int iVLineSize;
  36. DWORD dwVLineColor;
  37. bool bShowHtml;
  38. bool bMultiExpandable;
  39. } TListInfoUI;
  40. /////////////////////////////////////////////////////////////////////////////////////
  41. //
  42. class IListCallbackUI
  43. {
  44. public:
  45. virtual LPCTSTR GetItemText(CControlUI* pList, int iItem, int iSubItem) = 0;
  46. };
  47. class IListOwnerUI
  48. {
  49. public:
  50. virtual TListInfoUI* GetListInfo() = 0;
  51. virtual int GetCurSel() const = 0;
  52. virtual bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true) = 0;
  53. virtual void DoEvent(TEventUI& event) = 0;
  54. virtual bool ExpandItem(int iIndex, bool bExpand = true) = 0;
  55. virtual int GetExpandedItem() const = 0;
  56. };
  57. class IListUI : public IListOwnerUI
  58. {
  59. public:
  60. virtual CListHeaderUI* GetHeader() const = 0;
  61. virtual CContainerUI* GetList() const = 0;
  62. virtual IListCallbackUI* GetTextCallback() const = 0;
  63. virtual void SetTextCallback(IListCallbackUI* pCallback) = 0;
  64. };
  65. class IListItemUI
  66. {
  67. public:
  68. virtual int GetIndex() const = 0;
  69. virtual void SetIndex(int iIndex) = 0;
  70. virtual int GetDrawIndex() const = 0;
  71. virtual void SetDrawIndex(int iIndex) = 0;
  72. virtual IListOwnerUI* GetOwner() = 0;
  73. virtual void SetOwner(CControlUI* pOwner) = 0;
  74. virtual bool IsSelected() const = 0;
  75. virtual bool Select(bool bSelect = true, bool bTriggerEvent=true) = 0;
  76. virtual bool IsExpanded() const = 0;
  77. virtual bool Expand(bool bExpand = true) = 0;
  78. virtual void DrawItemText(HDC hDC, const RECT& rcItem) = 0;
  79. };
  80. /////////////////////////////////////////////////////////////////////////////////////
  81. //
  82. class CListBodyUI;
  83. class CListHeaderUI;
  84. class DUILIB_API CListUI : public CVerticalLayoutUI, public IListUI
  85. {
  86. public:
  87. CListUI();
  88. LPCTSTR GetClass() const;
  89. UINT GetControlFlags() const;
  90. LPVOID GetInterface(LPCTSTR pstrName);
  91. bool GetScrollSelect();
  92. void SetScrollSelect(bool bScrollSelect);
  93. int GetCurSel() const;
  94. bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true);
  95. CControlUI* GetItemAt(int iIndex) const;
  96. int GetItemIndex(CControlUI* pControl) const;
  97. bool SetItemIndex(CControlUI* pControl, int iIndex);
  98. bool SetMultiItemIndex(CControlUI* pStartControl, int iCount, int iNewStartIndex);
  99. int GetCount() const;
  100. bool Add(CControlUI* pControl);
  101. bool AddAt(CControlUI* pControl, int iIndex);
  102. bool Remove(CControlUI* pControl, bool bDoNotDestroy=false);
  103. bool RemoveAt(int iIndex, bool bDoNotDestroy=false);
  104. void RemoveAll();
  105. void EnsureVisible(int iIndex);
  106. void Scroll(int dx, int dy);
  107. int GetChildPadding() const;
  108. void SetChildPadding(int iPadding);
  109. CListHeaderUI* GetHeader() const;
  110. CContainerUI* GetList() const;
  111. TListInfoUI* GetListInfo();
  112. UINT GetItemFixedHeight();
  113. void SetItemFixedHeight(UINT nHeight);
  114. int GetItemFont(int index);
  115. void SetItemFont(int index);
  116. UINT GetItemTextStyle();
  117. void SetItemTextStyle(UINT uStyle);
  118. RECT GetItemTextPadding() const;
  119. void SetItemTextPadding(RECT rc);
  120. DWORD GetItemTextColor() const;
  121. void SetItemTextColor(DWORD dwTextColor);
  122. DWORD GetItemBkColor() const;
  123. void SetItemBkColor(DWORD dwBkColor);
  124. LPCTSTR GetItemBkImage() const;
  125. void SetItemBkImage(LPCTSTR pStrImage);
  126. bool IsAlternateBk() const;
  127. void SetAlternateBk(bool bAlternateBk);
  128. DWORD GetSelectedItemTextColor() const;
  129. void SetSelectedItemTextColor(DWORD dwTextColor);
  130. DWORD GetSelectedItemBkColor() const;
  131. void SetSelectedItemBkColor(DWORD dwBkColor);
  132. LPCTSTR GetSelectedItemImage() const;
  133. void SetSelectedItemImage(LPCTSTR pStrImage);
  134. DWORD GetHotItemTextColor() const;
  135. void SetHotItemTextColor(DWORD dwTextColor);
  136. DWORD GetHotItemBkColor() const;
  137. void SetHotItemBkColor(DWORD dwBkColor);
  138. LPCTSTR GetHotItemImage() const;
  139. void SetHotItemImage(LPCTSTR pStrImage);
  140. DWORD GetDisabledItemTextColor() const;
  141. void SetDisabledItemTextColor(DWORD dwTextColor);
  142. DWORD GetDisabledItemBkColor() const;
  143. void SetDisabledItemBkColor(DWORD dwBkColor);
  144. LPCTSTR GetDisabledItemImage() const;
  145. void SetDisabledItemImage(LPCTSTR pStrImage);
  146. int GetItemHLineSize() const;
  147. void SetItemHLineSize(int iSize);
  148. DWORD GetItemHLineColor() const;
  149. void SetItemHLineColor(DWORD dwLineColor);
  150. int GetItemVLineSize() const;
  151. void SetItemVLineSize(int iSize);
  152. DWORD GetItemVLineColor() const;
  153. void SetItemVLineColor(DWORD dwLineColor);
  154. bool IsItemShowHtml();
  155. void SetItemShowHtml(bool bShowHtml = true);
  156. void SetMultiExpanding(bool bMultiExpandable);
  157. int GetExpandedItem() const;
  158. bool ExpandItem(int iIndex, bool bExpand = true);
  159. void SetPos(RECT rc, bool bNeedInvalidate = true);
  160. void Move(SIZE szOffset, bool bNeedInvalidate = true);
  161. void DoEvent(TEventUI& event);
  162. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  163. IListCallbackUI* GetTextCallback() const;
  164. void SetTextCallback(IListCallbackUI* pCallback);
  165. SIZE GetScrollPos() const;
  166. SIZE GetScrollRange() const;
  167. void SetScrollPos(SIZE szPos);
  168. void LineUp();
  169. void LineDown();
  170. void PageUp();
  171. void PageDown();
  172. void HomeUp();
  173. void EndDown();
  174. void LineLeft();
  175. void LineRight();
  176. void PageLeft();
  177. void PageRight();
  178. void HomeLeft();
  179. void EndRight();
  180. void EnableScrollBar(bool bEnableVertical = true, bool bEnableHorizontal = false);
  181. virtual CScrollBarUI* GetVerticalScrollBar() const;
  182. virtual CScrollBarUI* GetHorizontalScrollBar() const;
  183. bool SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData);
  184. protected:
  185. bool m_bScrollSelect;
  186. int m_iCurSel;
  187. int m_iExpandedItem;
  188. IListCallbackUI* m_pCallback;
  189. CListBodyUI* m_pList;
  190. CListHeaderUI* m_pHeader;
  191. TListInfoUI m_ListInfo;
  192. };
  193. /////////////////////////////////////////////////////////////////////////////////////
  194. //
  195. class DUILIB_API CListHeaderUI : public CHorizontalLayoutUI
  196. {
  197. public:
  198. CListHeaderUI();
  199. LPCTSTR GetClass() const;
  200. LPVOID GetInterface(LPCTSTR pstrName);
  201. SIZE EstimateSize(SIZE szAvailable);
  202. };
  203. /////////////////////////////////////////////////////////////////////////////////////
  204. //
  205. class DUILIB_API CListHeaderItemUI : public CControlUI
  206. {
  207. public:
  208. CListHeaderItemUI();
  209. LPCTSTR GetClass() const;
  210. LPVOID GetInterface(LPCTSTR pstrName);
  211. UINT GetControlFlags() const;
  212. void SetEnabled(bool bEnable = true);
  213. bool IsDragable() const;
  214. void SetDragable(bool bDragable);
  215. DWORD GetSepWidth() const;
  216. void SetSepWidth(int iWidth);
  217. DWORD GetTextStyle() const;
  218. void SetTextStyle(UINT uStyle);
  219. DWORD GetTextColor() const;
  220. void SetTextColor(DWORD dwTextColor);
  221. DWORD GetSepColor() const;
  222. void SetSepColor(DWORD dwSepColor);
  223. void SetTextPadding(RECT rc);
  224. RECT GetTextPadding() const;
  225. void SetFont(int index);
  226. bool IsShowHtml();
  227. void SetShowHtml(bool bShowHtml = true);
  228. LPCTSTR GetNormalImage() const;
  229. void SetNormalImage(LPCTSTR pStrImage);
  230. LPCTSTR GetHotImage() const;
  231. void SetHotImage(LPCTSTR pStrImage);
  232. LPCTSTR GetPushedImage() const;
  233. void SetPushedImage(LPCTSTR pStrImage);
  234. LPCTSTR GetFocusedImage() const;
  235. void SetFocusedImage(LPCTSTR pStrImage);
  236. LPCTSTR GetSepImage() const;
  237. void SetSepImage(LPCTSTR pStrImage);
  238. void DoEvent(TEventUI& event);
  239. SIZE EstimateSize(SIZE szAvailable);
  240. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  241. RECT GetThumbRect() const;
  242. void PaintText(HDC hDC);
  243. void PaintStatusImage(HDC hDC);
  244. protected:
  245. POINT ptLastMouse;
  246. bool m_bDragable;
  247. UINT m_uButtonState;
  248. int m_iSepWidth;
  249. DWORD m_dwTextColor;
  250. DWORD m_dwSepColor;
  251. int m_iFont;
  252. UINT m_uTextStyle;
  253. bool m_bShowHtml;
  254. RECT m_rcTextPadding;
  255. TDrawInfo m_diNormal;
  256. TDrawInfo m_diHot;
  257. TDrawInfo m_diPushed;
  258. TDrawInfo m_diFocused;
  259. TDrawInfo m_diSep;
  260. };
  261. /////////////////////////////////////////////////////////////////////////////////////
  262. //
  263. class DUILIB_API CListElementUI : public CControlUI, public IListItemUI
  264. {
  265. public:
  266. CListElementUI();
  267. LPCTSTR GetClass() const;
  268. UINT GetControlFlags() const;
  269. LPVOID GetInterface(LPCTSTR pstrName);
  270. void SetEnabled(bool bEnable = true);
  271. int GetIndex() const;
  272. void SetIndex(int iIndex);
  273. int GetDrawIndex() const;
  274. void SetDrawIndex(int iIndex);
  275. IListOwnerUI* GetOwner();
  276. void SetOwner(CControlUI* pOwner);
  277. void SetVisible(bool bVisible = true);
  278. bool IsSelected() const;
  279. bool Select(bool bSelect = true, bool bTriggerEvent=true);
  280. bool IsExpanded() const;
  281. bool Expand(bool bExpand = true);
  282. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  283. bool Activate();
  284. void DoEvent(TEventUI& event);
  285. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  286. void DrawItemBk(HDC hDC, const RECT& rcItem);
  287. protected:
  288. int m_iIndex;
  289. int m_iDrawIndex;
  290. bool m_bSelected;
  291. UINT m_uButtonState;
  292. IListOwnerUI* m_pOwner;
  293. };
  294. /////////////////////////////////////////////////////////////////////////////////////
  295. //
  296. class DUILIB_API CListLabelElementUI : public CListElementUI
  297. {
  298. public:
  299. CListLabelElementUI();
  300. LPCTSTR GetClass() const;
  301. LPVOID GetInterface(LPCTSTR pstrName);
  302. void SetOwner(CControlUI* pOwner);
  303. void SetFixedWidth(int cx);
  304. void SetFixedHeight(int cy);
  305. void SetText(LPCTSTR pstrText);
  306. void DoEvent(TEventUI& event);
  307. SIZE EstimateSize(SIZE szAvailable);
  308. bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
  309. void DrawItemText(HDC hDC, const RECT& rcItem);
  310. protected:
  311. SIZE m_cxyFixedLast;
  312. bool m_bNeedEstimateSize;
  313. SIZE m_szAvailableLast;
  314. UINT m_uFixedHeightLast;
  315. int m_nFontLast;
  316. UINT m_uTextStyleLast;
  317. RECT m_rcTextPaddingLast;
  318. };
  319. /////////////////////////////////////////////////////////////////////////////////////
  320. //
  321. class DUILIB_API CListTextElementUI : public CListLabelElementUI
  322. {
  323. public:
  324. CListTextElementUI();
  325. ~CListTextElementUI();
  326. LPCTSTR GetClass() const;
  327. LPVOID GetInterface(LPCTSTR pstrName);
  328. UINT GetControlFlags() const;
  329. LPCTSTR GetText(int iIndex) const;
  330. void SetText(int iIndex, LPCTSTR pstrText);
  331. void SetOwner(CControlUI* pOwner);
  332. CDuiString* GetLinkContent(int iIndex);
  333. void DoEvent(TEventUI& event);
  334. SIZE EstimateSize(SIZE szAvailable);
  335. void DrawItemText(HDC hDC, const RECT& rcItem);
  336. protected:
  337. enum { MAX_LINK = 8 };
  338. int m_nLinks;
  339. RECT m_rcLinks[MAX_LINK];
  340. CDuiString m_sLinks[MAX_LINK];
  341. int m_nHoverLink;
  342. IListUI* m_pOwner;
  343. CDuiPtrArray m_aTexts;
  344. CDuiString m_sTextLast;
  345. };
  346. /////////////////////////////////////////////////////////////////////////////////////
  347. //
  348. class DUILIB_API CListContainerElementUI : public CContainerUI, public IListItemUI
  349. {
  350. public:
  351. CListContainerElementUI();
  352. LPCTSTR GetClass() const;
  353. UINT GetControlFlags() const;
  354. LPVOID GetInterface(LPCTSTR pstrName);
  355. int GetIndex() const;
  356. void SetIndex(int iIndex);
  357. int GetDrawIndex() const;
  358. void SetDrawIndex(int iIndex);
  359. IListOwnerUI* GetOwner();
  360. void SetOwner(CControlUI* pOwner);
  361. void SetVisible(bool bVisible = true);
  362. void SetEnabled(bool bEnable = true);
  363. bool IsSelected() const;
  364. bool Select(bool bSelect = true, bool bTriggerEvent=true);
  365. bool IsExpandable() const;
  366. void SetExpandable(bool bExpandable);
  367. bool IsExpanded() const;
  368. bool Expand(bool bExpand = true);
  369. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  370. bool Activate();
  371. void DoEvent(TEventUI& event);
  372. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  373. bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
  374. void DrawItemText(HDC hDC, const RECT& rcItem);
  375. void DrawItemBk(HDC hDC, const RECT& rcItem);
  376. SIZE EstimateSize(SIZE szAvailable);
  377. protected:
  378. int m_iIndex;
  379. int m_iDrawIndex;
  380. bool m_bSelected;
  381. bool m_bExpandable;
  382. bool m_bExpand;
  383. UINT m_uButtonState;
  384. IListOwnerUI* m_pOwner;
  385. };
  386. /////////////////////////////////////////////////////////////////////////////////////
  387. //
  388. class DUILIB_API CListHBoxElementUI : public CListContainerElementUI
  389. {
  390. public:
  391. CListHBoxElementUI();
  392. LPCTSTR GetClass() const;
  393. LPVOID GetInterface(LPCTSTR pstrName);
  394. void SetPos(RECT rc, bool bNeedInvalidate = true);
  395. bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
  396. };
  397. } // namespace DuiLib
  398. #endif // __UILIST_H__