UIList.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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 32
  12. typedef struct tagTListInfoUI
  13. {
  14. int nColumns;
  15. RECT rcColumn[UILIST_MAX_COLUMNS];
  16. int nFont;
  17. UINT uTextStyle;
  18. RECT rcTextPadding;
  19. DWORD dwTextColor;
  20. DWORD dwBkColor;
  21. TDrawInfo diBk;
  22. bool bAlternateBk;
  23. DWORD dwSelectedTextColor;
  24. DWORD dwSelectedBkColor;
  25. TDrawInfo diSelected;
  26. DWORD dwHotTextColor;
  27. DWORD dwHotBkColor;
  28. TDrawInfo diHot;
  29. DWORD dwDisabledTextColor;
  30. DWORD dwDisabledBkColor;
  31. TDrawInfo diDisabled;
  32. DWORD dwLineColor;
  33. bool bShowHtml;
  34. bool bMultiExpandable;
  35. } TListInfoUI;
  36. /////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. class IListCallbackUI
  39. {
  40. public:
  41. virtual LPCTSTR GetItemText(CControlUI* pList, int iItem, int iSubItem) = 0;
  42. };
  43. class IListOwnerUI
  44. {
  45. public:
  46. virtual TListInfoUI* GetListInfo() = 0;
  47. virtual int GetCurSel() const = 0;
  48. virtual bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true) = 0;
  49. virtual void DoEvent(TEventUI& event) = 0;
  50. };
  51. class IListUI : public IListOwnerUI
  52. {
  53. public:
  54. virtual CListHeaderUI* GetHeader() const = 0;
  55. virtual CContainerUI* GetList() const = 0;
  56. virtual IListCallbackUI* GetTextCallback() const = 0;
  57. virtual void SetTextCallback(IListCallbackUI* pCallback) = 0;
  58. virtual bool ExpandItem(int iIndex, bool bExpand = true) = 0;
  59. virtual int GetExpandedItem() const = 0;
  60. };
  61. class IListItemUI
  62. {
  63. public:
  64. virtual int GetIndex() const = 0;
  65. virtual void SetIndex(int iIndex) = 0;
  66. virtual IListOwnerUI* GetOwner() = 0;
  67. virtual void SetOwner(CControlUI* pOwner) = 0;
  68. virtual bool IsSelected() const = 0;
  69. virtual bool Select(bool bSelect = true, bool bTriggerEvent=true) = 0;
  70. virtual bool IsExpanded() const = 0;
  71. virtual bool Expand(bool bExpand = true) = 0;
  72. virtual void DrawItemText(HDC hDC, const RECT& rcItem) = 0;
  73. };
  74. /////////////////////////////////////////////////////////////////////////////////////
  75. //
  76. class CListBodyUI;
  77. class CListHeaderUI;
  78. class UILIB_API CListUI : public CVerticalLayoutUI, public IListUI
  79. {
  80. public:
  81. CListUI();
  82. LPCTSTR GetClass() const;
  83. UINT GetControlFlags() const;
  84. LPVOID GetInterface(LPCTSTR pstrName);
  85. bool GetScrollSelect();
  86. void SetScrollSelect(bool bScrollSelect);
  87. int GetCurSel() const;
  88. bool SelectItem(int iIndex, bool bTakeFocus = false, bool bTriggerEvent=true);
  89. CListHeaderUI* GetHeader() const;
  90. CContainerUI* GetList() const;
  91. TListInfoUI* GetListInfo();
  92. CControlUI* GetItemAt(int iIndex) const;
  93. int GetItemIndex(CControlUI* pControl) const;
  94. bool SetItemIndex(CControlUI* pControl, int iIndex);
  95. int GetCount() const;
  96. bool Add(CControlUI* pControl);
  97. CControlUI* Add (LPCTSTR lpXMLFile);
  98. bool AddAt(CControlUI* pControl, int iIndex);
  99. bool Remove(CControlUI* pControl);
  100. bool RemoveAt(int iIndex);
  101. void RemoveAll();
  102. void EnsureVisible(int iIndex);
  103. void Scroll(int dx, int dy);
  104. int GetChildPadding() const;
  105. void SetChildPadding(int iPadding);
  106. void SetItemFont(int index);
  107. void SetItemTextStyle(UINT uStyle);
  108. void SetItemTextPadding(RECT rc);
  109. void SetItemTextColor(DWORD dwTextColor);
  110. void SetItemBkColor(DWORD dwBkColor);
  111. void SetItemBkImage(LPCTSTR pStrImage);
  112. bool IsAlternateBk() const;
  113. void SetAlternateBk(bool bAlternateBk);
  114. void SetSelectedItemTextColor(DWORD dwTextColor);
  115. void SetSelectedItemBkColor(DWORD dwBkColor);
  116. void SetSelectedItemImage(LPCTSTR pStrImage);
  117. void SetHotItemTextColor(DWORD dwTextColor);
  118. void SetHotItemBkColor(DWORD dwBkColor);
  119. void SetHotItemImage(LPCTSTR pStrImage);
  120. void SetDisabledItemTextColor(DWORD dwTextColor);
  121. void SetDisabledItemBkColor(DWORD dwBkColor);
  122. void SetDisabledItemImage(LPCTSTR pStrImage);
  123. void SetItemLineColor(DWORD dwLineColor);
  124. bool IsItemShowHtml();
  125. void SetItemShowHtml(bool bShowHtml = true);
  126. RECT GetItemTextPadding() const;
  127. DWORD GetItemTextColor() const;
  128. DWORD GetItemBkColor() const;
  129. LPCTSTR GetItemBkImage() const;
  130. DWORD GetSelectedItemTextColor() const;
  131. DWORD GetSelectedItemBkColor() const;
  132. LPCTSTR GetSelectedItemImage() const;
  133. DWORD GetHotItemTextColor() const;
  134. DWORD GetHotItemBkColor() const;
  135. LPCTSTR GetHotItemImage() const;
  136. DWORD GetDisabledItemTextColor() const;
  137. DWORD GetDisabledItemBkColor() const;
  138. LPCTSTR GetDisabledItemImage() const;
  139. DWORD GetItemLineColor() const;
  140. void SetMultiExpanding(bool bMultiExpandable);
  141. int GetExpandedItem() const;
  142. bool ExpandItem(int iIndex, bool bExpand = true);
  143. void SetPos(RECT rc, bool bNeedInvalidate = true);
  144. void Move(SIZE szOffset, bool bNeedInvalidate = true);
  145. void DoEvent(TEventUI& event);
  146. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  147. IListCallbackUI* GetTextCallback() const;
  148. void SetTextCallback(IListCallbackUI* pCallback);
  149. SIZE GetScrollPos() const;
  150. SIZE GetScrollRange() const;
  151. void SetScrollPos(SIZE szPos);
  152. void LineUp();
  153. void LineDown();
  154. void PageUp();
  155. void PageDown();
  156. void HomeUp();
  157. void EndDown();
  158. void LineLeft();
  159. void LineRight();
  160. void PageLeft();
  161. void PageRight();
  162. void HomeLeft();
  163. void EndRight();
  164. void EnableScrollBar(bool bEnableVertical = true, bool bEnableHorizontal = false);
  165. virtual CScrollBarUI* GetVerticalScrollBar() const;
  166. virtual CScrollBarUI* GetHorizontalScrollBar() const;
  167. BOOL SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData);
  168. protected:
  169. bool m_bScrollSelect;
  170. int m_iCurSel;
  171. int m_iExpandedItem;
  172. IListCallbackUI* m_pCallback;
  173. CListBodyUI* m_pList;
  174. CListHeaderUI* m_pHeader;
  175. TListInfoUI m_ListInfo;
  176. };
  177. /////////////////////////////////////////////////////////////////////////////////////
  178. //
  179. class UILIB_API CListBodyUI : public CVerticalLayoutUI
  180. {
  181. public:
  182. CListBodyUI(CListUI* pOwner);
  183. void SetScrollPos(SIZE szPos);
  184. void SetPos(RECT rc, bool bNeedInvalidate = true);
  185. void DoEvent(TEventUI& event);
  186. BOOL SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData, int& iCurSel);
  187. protected:
  188. static int __cdecl ItemComareFunc(void *pvlocale, const void *item1, const void *item2);
  189. int __cdecl ItemComareFunc(const void *item1, const void *item2);
  190. protected:
  191. CListUI* m_pOwner;
  192. PULVCompareFunc m_pCompareFunc;
  193. UINT_PTR m_compareData;
  194. };
  195. /////////////////////////////////////////////////////////////////////////////////////
  196. //
  197. class UILIB_API CListHeaderUI : public CHorizontalLayoutUI
  198. {
  199. public:
  200. CListHeaderUI();
  201. LPCTSTR GetClass() const;
  202. LPVOID GetInterface(LPCTSTR pstrName);
  203. SIZE EstimateSize(SIZE szAvailable);
  204. };
  205. /////////////////////////////////////////////////////////////////////////////////////
  206. //
  207. class UILIB_API CListHeaderItemUI : public CControlUI
  208. {
  209. public:
  210. CListHeaderItemUI();
  211. LPCTSTR GetClass() const;
  212. LPVOID GetInterface(LPCTSTR pstrName);
  213. UINT GetControlFlags() const;
  214. void SetEnabled(bool bEnable = true);
  215. bool IsDragable() const;
  216. void SetDragable(bool bDragable);
  217. DWORD GetSepWidth() const;
  218. void SetSepWidth(int iWidth);
  219. DWORD GetTextStyle() const;
  220. void SetTextStyle(UINT uStyle);
  221. DWORD GetTextColor() const;
  222. void SetTextColor(DWORD dwTextColor);
  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. int m_iFont;
  251. UINT m_uTextStyle;
  252. bool m_bShowHtml;
  253. RECT m_rcTextPadding;
  254. TDrawInfo m_diNormal;
  255. TDrawInfo m_diHot;
  256. TDrawInfo m_diPushed;
  257. TDrawInfo m_diFocused;
  258. TDrawInfo m_diSep;
  259. };
  260. /////////////////////////////////////////////////////////////////////////////////////
  261. //
  262. class UILIB_API CListElementUI : public CControlUI, public IListItemUI
  263. {
  264. public:
  265. CListElementUI();
  266. LPCTSTR GetClass() const;
  267. UINT GetControlFlags() const;
  268. LPVOID GetInterface(LPCTSTR pstrName);
  269. void SetEnabled(bool bEnable = true);
  270. int GetIndex() const;
  271. void SetIndex(int iIndex);
  272. IListOwnerUI* GetOwner();
  273. void SetOwner(CControlUI* pOwner);
  274. void SetVisible(bool bVisible = true);
  275. bool IsSelected() const;
  276. bool Select(bool bSelect = true, bool bTriggerEvent=true);
  277. bool IsExpanded() const;
  278. bool Expand(bool bExpand = true);
  279. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  280. bool Activate();
  281. void DoEvent(TEventUI& event);
  282. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  283. void DrawItemBk(HDC hDC, const RECT& rcItem);
  284. protected:
  285. int m_iIndex;
  286. bool m_bSelected;
  287. UINT m_uButtonState;
  288. IListOwnerUI* m_pOwner;
  289. };
  290. /////////////////////////////////////////////////////////////////////////////////////
  291. //
  292. class UILIB_API CListLabelElementUI : public CListElementUI
  293. {
  294. public:
  295. CListLabelElementUI();
  296. LPCTSTR GetClass() const;
  297. LPVOID GetInterface(LPCTSTR pstrName);
  298. void DoEvent(TEventUI& event);
  299. SIZE EstimateSize(SIZE szAvailable);
  300. void DoPaint(HDC hDC, const RECT& rcPaint);
  301. void SetItemTextColor (DWORD dwTextcolor);
  302. DWORD GetItemTextColor () const;
  303. void DrawItemText(HDC hDC, const RECT& rcItem);
  304. private:
  305. DWORD m_iTextColor = 0;
  306. };
  307. /////////////////////////////////////////////////////////////////////////////////////
  308. //
  309. class UILIB_API CListTextElementUI : public CListLabelElementUI
  310. {
  311. public:
  312. CListTextElementUI();
  313. ~CListTextElementUI();
  314. LPCTSTR GetClass() const;
  315. LPVOID GetInterface(LPCTSTR pstrName);
  316. UINT GetControlFlags() const;
  317. LPCTSTR GetText(int iIndex) const;
  318. void SetText(int iIndex, LPCSTR pstrText);
  319. void SetText(int iIndex, LPCTSTR pstrText);
  320. void SetText(int iIndex, LPSTR pstrText);
  321. void SetOwner(CControlUI* pOwner);
  322. CDuiString* GetLinkContent(int iIndex);
  323. void DoEvent(TEventUI& event);
  324. SIZE EstimateSize(SIZE szAvailable);
  325. void DrawItemText(HDC hDC, const RECT& rcItem);
  326. protected:
  327. enum { MAX_LINK = 8 };
  328. int m_nLinks;
  329. RECT m_rcLinks[MAX_LINK];
  330. CDuiString m_sLinks[MAX_LINK];
  331. int m_nHoverLink;
  332. IListUI* m_pOwner;
  333. CStdPtrArray m_aTexts;
  334. };
  335. /////////////////////////////////////////////////////////////////////////////////////
  336. //
  337. class UILIB_API CListContainerElementUI : public CContainerUI, public IListItemUI
  338. {
  339. public:
  340. CListContainerElementUI();
  341. LPCTSTR GetClass() const;
  342. UINT GetControlFlags() const;
  343. LPVOID GetInterface(LPCTSTR pstrName);
  344. int GetIndex() const;
  345. void SetIndex(int iIndex);
  346. IListOwnerUI* GetOwner();
  347. void SetOwner(CControlUI* pOwner);
  348. void SetVisible(bool bVisible = true);
  349. void SetEnabled(bool bEnable = true);
  350. bool IsSelected() const;
  351. bool Select(bool bSelect = true, bool bTriggerEvent=true);
  352. bool IsExpanded() const;
  353. bool Expand(bool bExpand = true);
  354. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  355. bool Activate();
  356. void DoEvent(TEventUI& event);
  357. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  358. void DoPaint(HDC hDC, const RECT& rcPaint);
  359. void DrawItemText(HDC hDC, const RECT& rcItem);
  360. void DrawItemBk(HDC hDC, const RECT& rcItem);
  361. protected:
  362. int m_iIndex;
  363. bool m_bSelected;
  364. UINT m_uButtonState;
  365. IListOwnerUI* m_pOwner;
  366. };
  367. } // namespace DuiLib
  368. #endif // __UILIST_H__