UIList.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. #ifndef __UILIST_H__
  2. #define __UILIST_H__
  3. namespace DuiLib {
  4. /////////////////////////////////////////////////////////////////////////////////////
  5. //
  6. typedef int (CALLBACK *PULVCompareFunc)(UINT_PTR, UINT_PTR, UINT_PTR);
  7. class CListHeaderUI;
  8. #define UILIST_MAX_COLUMNS 32
  9. typedef struct tagTListInfoUI
  10. {
  11. int nColumns;
  12. RECT rcColumn[UILIST_MAX_COLUMNS];
  13. int nFont;
  14. UINT uTextStyle;
  15. RECT rcTextPadding;
  16. DWORD dwTextColor;
  17. DWORD dwBkColor;
  18. CDuiString sBkImage;
  19. bool bAlternateBk;
  20. DWORD dwSelectedTextColor;
  21. DWORD dwSelectedBkColor;
  22. CDuiString sSelectedImage;
  23. DWORD dwHotTextColor;
  24. DWORD dwHotBkColor;
  25. CDuiString sHotImage;
  26. DWORD dwDisabledTextColor;
  27. DWORD dwDisabledBkColor;
  28. CDuiString sDisabledImage;
  29. CDuiString sForeImage;
  30. CDuiString sHotForeImage;
  31. CDuiString sSelectedForeImage;
  32. DWORD dwLineColor;
  33. bool bShowRowLine;
  34. bool bShowColumnLine;
  35. bool bShowHtml;
  36. bool bMultiExpandable;
  37. bool bRSelected;
  38. } TListInfoUI;
  39. /////////////////////////////////////////////////////////////////////////////////////
  40. //
  41. class IListCallbackUI
  42. {
  43. public:
  44. virtual LPCTSTR GetItemText(CControlUI* pList, int iItem, int iSubItem) = 0;
  45. virtual DWORD GetItemTextColor(CControlUI* pList, int iItem, int iSubItem, int iState) = 0;// iState:0-正常、1-激活、2-选择、3-禁用
  46. };
  47. class IListOwnerUI
  48. {
  49. public:
  50. virtual UINT GetListType() = 0;
  51. virtual TListInfoUI* GetListInfo() = 0;
  52. virtual int GetCurSel() const = 0;
  53. virtual bool SelectItem(int iIndex, bool bTakeFocus = false) = 0;
  54. virtual bool SelectMultiItem(int iIndex, bool bTakeFocus = false) = 0;
  55. virtual bool UnSelectItem(int iIndex, bool bOthers = false) = 0;
  56. virtual void DoEvent(TEventUI& event) = 0;
  57. };
  58. class IListUI : public IListOwnerUI
  59. {
  60. public:
  61. virtual CListHeaderUI* GetHeader() const = 0;
  62. virtual CContainerUI* GetList() const = 0;
  63. virtual IListCallbackUI* GetTextCallback() const = 0;
  64. virtual void SetTextCallback(IListCallbackUI* pCallback) = 0;
  65. virtual bool ExpandItem(int iIndex, bool bExpand = true) = 0;
  66. virtual int GetExpandedItem() const = 0;
  67. virtual void SetMultiSelect(bool bMultiSel) = 0;
  68. virtual bool IsMultiSelect() const = 0;
  69. virtual void SelectAllItems() = 0;
  70. virtual void UnSelectAllItems() = 0;
  71. virtual int GetSelectItemCount() const = 0;
  72. virtual int GetNextSelItem(int nItem) const = 0;
  73. };
  74. class IListItemUI
  75. {
  76. public:
  77. virtual int GetIndex() const = 0;
  78. virtual void SetIndex(int iIndex) = 0;
  79. virtual IListOwnerUI* GetOwner() = 0;
  80. virtual void SetOwner(CControlUI* pOwner) = 0;
  81. virtual bool IsSelected() const = 0;
  82. virtual bool Select(bool bSelect = true) = 0;
  83. virtual bool SelectMulti(bool bSelect = true) = 0;
  84. virtual bool IsExpanded() const = 0;
  85. virtual bool Expand(bool bExpand = true) = 0;
  86. virtual void DrawItemText(HDC hDC, const RECT& rcItem) = 0;
  87. };
  88. /////////////////////////////////////////////////////////////////////////////////////
  89. //
  90. class CListBodyUI;
  91. class CListHeaderUI;
  92. class CEditUI;
  93. class CComboBoxUI;
  94. class UILIB_API CListUI : public CVerticalLayoutUI, public IListUI
  95. {
  96. DECLARE_DUICONTROL(CListUI)
  97. public:
  98. CListUI();
  99. LPCTSTR GetClass() const;
  100. UINT GetControlFlags() const;
  101. LPVOID GetInterface(LPCTSTR pstrName);
  102. bool GetScrollSelect();
  103. void SetScrollSelect(bool bScrollSelect);
  104. int GetCurSel() const;
  105. int GetCurSelActivate() const;
  106. bool SelectItem(int iIndex, bool bTakeFocus = false);
  107. bool SelectItemActivate(int iIndex); // 双击选中
  108. bool SelectMultiItem(int iIndex, bool bTakeFocus = false);
  109. void SetMultiSelect(bool bMultiSel);
  110. bool IsMultiSelect() const;
  111. bool UnSelectItem(int iIndex, bool bOthers = false);
  112. void SelectAllItems();
  113. void UnSelectAllItems();
  114. int GetSelectItemCount() const;
  115. int GetNextSelItem(int nItem) const;
  116. CListHeaderUI* GetHeader() const;
  117. CContainerUI* GetList() const;
  118. UINT GetListType();
  119. TListInfoUI* GetListInfo();
  120. CControlUI* GetItemAt(int iIndex) const;
  121. int GetItemIndex(CControlUI* pControl) const;
  122. bool SetItemIndex(CControlUI* pControl, int iIndex);
  123. int GetCount() const;
  124. bool Add(CControlUI* pControl);
  125. bool AddAt(CControlUI* pControl, int iIndex);
  126. bool Remove(CControlUI* pControl);
  127. bool RemoveAt(int iIndex);
  128. void RemoveAll();
  129. void EnsureVisible(int iIndex);
  130. void Scroll(int dx, int dy);
  131. bool IsDelayedDestroy() const;
  132. void SetDelayedDestroy(bool bDelayed);
  133. int GetChildPadding() const;
  134. void SetChildPadding(int iPadding);
  135. void SetItemFont(int index);
  136. void SetItemTextStyle(UINT uStyle);
  137. void SetItemTextPadding(RECT rc);
  138. void SetItemTextColor(DWORD dwTextColor);
  139. void SetItemBkColor(DWORD dwBkColor);
  140. void SetItemBkImage(LPCTSTR pStrImage);
  141. void SetAlternateBk(bool bAlternateBk);
  142. void SetSelectedItemTextColor(DWORD dwTextColor);
  143. void SetSelectedItemBkColor(DWORD dwBkColor);
  144. void SetSelectedItemImage(LPCTSTR pStrImage);
  145. void SetHotItemTextColor(DWORD dwTextColor);
  146. void SetHotItemBkColor(DWORD dwBkColor);
  147. void SetHotItemImage(LPCTSTR pStrImage);
  148. void SetDisabledItemTextColor(DWORD dwTextColor);
  149. void SetDisabledItemBkColor(DWORD dwBkColor);
  150. void SetDisabledItemImage(LPCTSTR pStrImage);
  151. void SetItemLineColor(DWORD dwLineColor);
  152. void SetItemShowRowLine(bool bShowLine = false);
  153. void SetItemShowColumnLine(bool bShowLine = false);
  154. bool IsItemShowHtml();
  155. void SetItemShowHtml(bool bShowHtml = true);
  156. bool IsItemRSelected();
  157. void SetItemRSelected(bool bSelected = true);
  158. RECT GetItemTextPadding() const;
  159. DWORD GetItemTextColor() const;
  160. DWORD GetItemBkColor() const;
  161. LPCTSTR GetItemBkImage() const;
  162. bool IsAlternateBk() const;
  163. DWORD GetSelectedItemTextColor() const;
  164. DWORD GetSelectedItemBkColor() const;
  165. LPCTSTR GetSelectedItemImage() const;
  166. DWORD GetHotItemTextColor() const;
  167. DWORD GetHotItemBkColor() const;
  168. LPCTSTR GetHotItemImage() const;
  169. DWORD GetDisabledItemTextColor() const;
  170. DWORD GetDisabledItemBkColor() const;
  171. LPCTSTR GetDisabledItemImage() const;
  172. DWORD GetItemLineColor() const;
  173. void SetMultiExpanding(bool bMultiExpandable);
  174. int GetExpandedItem() const;
  175. bool ExpandItem(int iIndex, bool bExpand = true);
  176. void SetPos(RECT rc, bool bNeedInvalidate = true);
  177. void Move(SIZE szOffset, bool bNeedInvalidate = true);
  178. void DoEvent(TEventUI& event);
  179. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  180. IListCallbackUI* GetTextCallback() const;
  181. void SetTextCallback(IListCallbackUI* pCallback);
  182. SIZE GetScrollPos() const;
  183. SIZE GetScrollRange() const;
  184. void SetScrollPos(SIZE szPos, bool bMsg = true);
  185. void LineUp();
  186. void LineDown();
  187. void PageUp();
  188. void PageDown();
  189. void HomeUp();
  190. void EndDown();
  191. void LineLeft();
  192. void LineRight();
  193. void PageLeft();
  194. void PageRight();
  195. void HomeLeft();
  196. void EndRight();
  197. void EnableScrollBar(bool bEnableVertical = true, bool bEnableHorizontal = false);
  198. virtual CScrollBarUI* GetVerticalScrollBar() const;
  199. virtual CScrollBarUI* GetHorizontalScrollBar() const;
  200. BOOL SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData);
  201. virtual BOOL CheckColumEditable(int nColum) { return FALSE; };
  202. virtual CRichEditUI* GetEditUI() { return NULL; };
  203. virtual BOOL CheckColumComboBoxable(int nColum) { return FALSE; };
  204. virtual CComboBoxUI* GetComboBoxUI() { return NULL; };
  205. protected:
  206. int GetMinSelItemIndex();
  207. int GetMaxSelItemIndex();
  208. protected:
  209. bool m_bScrollSelect;
  210. bool m_bMultiSel;
  211. int m_iCurSel;
  212. int m_iFirstSel;
  213. CStdPtrArray m_aSelItems;
  214. int m_iCurSelActivate; // 双击的列
  215. int m_iExpandedItem;
  216. IListCallbackUI* m_pCallback;
  217. CListBodyUI* m_pList;
  218. CListHeaderUI* m_pHeader;
  219. TListInfoUI m_ListInfo;
  220. };
  221. /////////////////////////////////////////////////////////////////////////////////////
  222. //
  223. class UILIB_API CListBodyUI : public CVerticalLayoutUI
  224. {
  225. public:
  226. CListBodyUI(CListUI* pOwner);
  227. int GetScrollStepSize() const;
  228. void SetScrollPos(SIZE szPos, bool bMsg = true);
  229. void SetPos(RECT rc, bool bNeedInvalidate = true);
  230. void DoEvent(TEventUI& event);
  231. BOOL SortItems(PULVCompareFunc pfnCompare, UINT_PTR dwData);
  232. protected:
  233. static int __cdecl ItemComareFunc(void *pvlocale, const void *item1, const void *item2);
  234. int __cdecl ItemComareFunc(const void *item1, const void *item2);
  235. protected:
  236. CListUI* m_pOwner;
  237. PULVCompareFunc m_pCompareFunc;
  238. UINT_PTR m_compareData;
  239. };
  240. /////////////////////////////////////////////////////////////////////////////////////
  241. //
  242. class UILIB_API CListHeaderUI : public CHorizontalLayoutUI
  243. {
  244. DECLARE_DUICONTROL(CListHeaderUI)
  245. public:
  246. CListHeaderUI();
  247. virtual ~CListHeaderUI();
  248. LPCTSTR GetClass() const;
  249. LPVOID GetInterface(LPCTSTR pstrName);
  250. SIZE EstimateSize(SIZE szAvailable);
  251. void SetPos(RECT rc, bool bNeedInvalidate = true);
  252. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  253. void SetScaleHeader(bool bIsScale);
  254. bool IsScaleHeader() const;
  255. void DoInit();
  256. void DoPostPaint(HDC hDC, const RECT& rcPaint);
  257. private:
  258. bool m_bIsScaleHeader;
  259. };
  260. /////////////////////////////////////////////////////////////////////////////////////
  261. //
  262. class UILIB_API CListHeaderItemUI : public CHorizontalLayoutUI
  263. {
  264. DECLARE_DUICONTROL(CListHeaderItemUI)
  265. public:
  266. CListHeaderItemUI();
  267. LPCTSTR GetClass() const;
  268. LPVOID GetInterface(LPCTSTR pstrName);
  269. UINT GetControlFlags() const;
  270. void SetEnabled(bool bEnable = true);
  271. bool IsDragable() const;
  272. void SetDragable(bool bDragable);
  273. DWORD GetSepWidth() const;
  274. void SetSepWidth(int iWidth);
  275. DWORD GetTextStyle() const;
  276. void SetTextStyle(UINT uStyle);
  277. DWORD GetTextColor() const;
  278. void SetTextColor(DWORD dwTextColor);
  279. void SetTextPadding(RECT rc);
  280. RECT GetTextPadding() const;
  281. void SetFont(int index);
  282. bool IsShowHtml();
  283. void SetShowHtml(bool bShowHtml = true);
  284. LPCTSTR GetNormalImage() const;
  285. void SetNormalImage(LPCTSTR pStrImage);
  286. LPCTSTR GetHotImage() const;
  287. void SetHotImage(LPCTSTR pStrImage);
  288. LPCTSTR GetPushedImage() const;
  289. void SetPushedImage(LPCTSTR pStrImage);
  290. LPCTSTR GetFocusedImage() const;
  291. void SetFocusedImage(LPCTSTR pStrImage);
  292. LPCTSTR GetSepImage() const;
  293. void SetSepImage(LPCTSTR pStrImage);
  294. void SetScale(int nScale);
  295. int GetScale() const;
  296. void DoEvent(TEventUI& event);
  297. SIZE EstimateSize(SIZE szAvailable);
  298. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  299. RECT GetThumbRect() const;
  300. void PaintText(HDC hDC);
  301. void PaintStatusImage(HDC hDC);
  302. protected:
  303. POINT ptLastMouse;
  304. bool m_bDragable;
  305. UINT m_uButtonState;
  306. int m_iSepWidth;
  307. DWORD m_dwTextColor;
  308. int m_iFont;
  309. UINT m_uTextStyle;
  310. bool m_bShowHtml;
  311. RECT m_rcTextPadding;
  312. CDuiString m_sNormalImage;
  313. CDuiString m_sHotImage;
  314. CDuiString m_sPushedImage;
  315. CDuiString m_sFocusedImage;
  316. CDuiString m_sSepImage;
  317. CDuiString m_sSepImageModify;
  318. int m_nScale;
  319. };
  320. /////////////////////////////////////////////////////////////////////////////////////
  321. //
  322. class UILIB_API CListElementUI : public CControlUI, public IListItemUI
  323. {
  324. public:
  325. CListElementUI();
  326. LPCTSTR GetClass() const;
  327. UINT GetControlFlags() const;
  328. LPVOID GetInterface(LPCTSTR pstrName);
  329. void SetEnabled(bool bEnable = true);
  330. int GetIndex() const;
  331. void SetIndex(int iIndex);
  332. IListOwnerUI* GetOwner();
  333. void SetOwner(CControlUI* pOwner);
  334. void SetVisible(bool bVisible = true);
  335. bool IsSelected() const;
  336. bool Select(bool bSelect = true);
  337. bool SelectMulti(bool bSelect = true);
  338. bool IsExpanded() const;
  339. bool Expand(bool bExpand = true);
  340. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  341. bool Activate();
  342. void DoEvent(TEventUI& event);
  343. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  344. void DrawItemBk(HDC hDC, const RECT& rcItem);
  345. protected:
  346. int m_iIndex;
  347. bool m_bSelected;
  348. UINT m_uButtonState;
  349. IListOwnerUI* m_pOwner;
  350. };
  351. /////////////////////////////////////////////////////////////////////////////////////
  352. //
  353. class UILIB_API CListLabelElementUI : public CListElementUI
  354. {
  355. DECLARE_DUICONTROL(CListLabelElementUI)
  356. public:
  357. CListLabelElementUI();
  358. LPCTSTR GetClass() const;
  359. LPVOID GetInterface(LPCTSTR pstrName);
  360. void DoEvent(TEventUI& event);
  361. SIZE EstimateSize(SIZE szAvailable);
  362. bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
  363. void DrawItemText(HDC hDC, const RECT& rcItem);
  364. };
  365. /////////////////////////////////////////////////////////////////////////////////////
  366. //
  367. class UILIB_API CListTextElementUI : public CListLabelElementUI
  368. {
  369. DECLARE_DUICONTROL(CListTextElementUI)
  370. public:
  371. CListTextElementUI();
  372. ~CListTextElementUI();
  373. LPCTSTR GetClass() const;
  374. LPVOID GetInterface(LPCTSTR pstrName);
  375. UINT GetControlFlags() const;
  376. LPCTSTR GetText(int iIndex) const;
  377. void SetText(int iIndex, LPCTSTR pstrText);
  378. DWORD GetTextColor(int iIndex) const;
  379. void SetTextColor(int iIndex, DWORD dwTextColor);
  380. void SetOwner(CControlUI* pOwner);
  381. CDuiString* GetLinkContent(int iIndex);
  382. void DoEvent(TEventUI& event);
  383. SIZE EstimateSize(SIZE szAvailable);
  384. void DrawItemText(HDC hDC, const RECT& rcItem);
  385. protected:
  386. enum { MAX_LINK = 8 };
  387. int m_nLinks;
  388. RECT m_rcLinks[MAX_LINK];
  389. CDuiString m_sLinks[MAX_LINK];
  390. int m_nHoverLink;
  391. IListUI* m_pOwner;
  392. CStdPtrArray m_aTexts;
  393. CStdPtrArray m_aTextColors;
  394. };
  395. /////////////////////////////////////////////////////////////////////////////////////
  396. //
  397. class UILIB_API CListContainerElementUI : public CHorizontalLayoutUI, public IListItemUI
  398. {
  399. DECLARE_DUICONTROL(CListContainerElementUI)
  400. public:
  401. CListContainerElementUI();
  402. LPCTSTR GetClass() const;
  403. UINT GetControlFlags() const;
  404. LPVOID GetInterface(LPCTSTR pstrName);
  405. int GetIndex() const;
  406. void SetIndex(int iIndex);
  407. IListOwnerUI* GetOwner();
  408. void SetOwner(CControlUI* pOwner);
  409. void SetVisible(bool bVisible = true);
  410. void SetEnabled(bool bEnable = true);
  411. bool IsSelected() const;
  412. bool Select(bool bSelect = true);
  413. bool SelectMulti(bool bSelect = true);
  414. bool IsExpanded() const;
  415. bool Expand(bool bExpand = true);
  416. void Invalidate(); // 直接CControl::Invalidate会导致滚动条刷新,重写减少刷新区域
  417. bool Activate();
  418. void DoEvent(TEventUI& event);
  419. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  420. bool DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl);
  421. virtual void DrawItemText(HDC hDC, const RECT& rcItem);
  422. virtual void DrawItemBk(HDC hDC, const RECT& rcItem);
  423. void SetPos(RECT rc, bool bNeedInvalidate = true);
  424. protected:
  425. int m_iIndex;
  426. bool m_bSelected;
  427. UINT m_uButtonState;
  428. IListOwnerUI* m_pOwner;
  429. };
  430. } // namespace DuiLib
  431. #endif // __UILIST_H__