XListCtrl.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. // XListCtrl.h Version 1.4
  2. //
  3. // Author: Hans Dietrich
  4. // hdietrich@gmail.com
  5. //
  6. // License:
  7. // This software is released into the public domain. You are free to use
  8. // it in any way you like, except that you may not sell this source code.
  9. //
  10. // This software is provided "as is" with no expressed or implied warranty.
  11. // I accept no liability for any damage or loss of business that this
  12. // software may cause.
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #ifndef XLISTCTRL_H
  16. #define XLISTCTRL_H
  17. #include "XHeaderCtrl.h"
  18. #ifndef DO_NOT_INCLUDE_XCOMBOLIST
  19. #include "XCombo.h"
  20. #include "AdvComboBox.h"
  21. #endif
  22. #include "XEdit.h"
  23. #if defined XLISTCTRLLIB_STATIC
  24. #define XLISTCTRLLIBDLLEXPORT
  25. #else
  26. #ifdef XLISTCTRLLIB_EXPORTS
  27. #define XLISTCTRLLIBDLLEXPORT _declspec(dllexport)
  28. #else
  29. #define XLISTCTRLLIBDLLEXPORT _declspec(dllimport)
  30. #endif
  31. #endif
  32. ///////////////////////////////////////////////////////////////////////////////
  33. // The first two letters of the library name specify the MFC/XListCtrl
  34. // build configuration as follows:
  35. // MFC MFC XListCtrl XListCtrl
  36. // DLL Static DLL Static
  37. // DD x x
  38. // DS x x
  39. // SS x x
  40. // SD ----------- not provided -----------
  41. //
  42. // The third letter specifies Release/Debug.
  43. // The fourth letter specifies ANSI/UNICODE.
  44. ///////////////////////////////////////////////////////////////////////////////
  45. #if 0 // ²»Ê¹ÓÃlib;
  46. #ifndef XLISTCTRLLIB_NOAUTOLIB
  47. #if defined _AFXDLL && !defined XLISTCTRLLIB_STATIC
  48. // MFC shared DLL with XListCtrl shared DLL
  49. #ifdef _UNICODE
  50. #ifdef _DEBUG
  51. #pragma comment(lib,"XListCtrlDDDU.lib")
  52. #pragma message("Automatically linking with XListCtrlDDDU.lib")
  53. #else
  54. #pragma comment(lib,"XListCtrlDDRU.lib")
  55. #pragma message("Automatically linking with XListCtrlDDRU.lib")
  56. #endif
  57. #else
  58. #ifdef _DEBUG
  59. #pragma comment(lib,"XListCtrlDDDA.lib")
  60. #pragma message("Automatically linking with XListCtrlDDDA.lib")
  61. #else
  62. #pragma comment(lib,"XListCtrlDDRA.lib")
  63. #pragma message("Automatically linking with XListCtrlDDRA.lib")
  64. #endif
  65. #endif
  66. #elif defined _AFXDLL && defined XLISTCTRLLIB_STATIC
  67. // MFC shared DLL with XListCtrl static lib
  68. #ifdef _UNICODE
  69. #ifdef _DEBUG
  70. #pragma comment(lib,"XListCtrlDSDU.lib")
  71. #pragma message("Automatically linking with XListCtrlDSDU.lib")
  72. #else
  73. #pragma comment(lib,"XListCtrlDSRU.lib")
  74. #pragma message("Automatically linking with XListCtrlDSRU.lib")
  75. #endif
  76. #else
  77. #ifdef _DEBUG
  78. #pragma comment(lib,"XListCtrlDSDA.lib")
  79. #pragma message("Automatically linking with XListCtrlDSDA.lib")
  80. #else
  81. #pragma comment(lib,"XListCtrlDSRA.lib")
  82. #pragma message("Automatically linking with XListCtrlDSRA.lib")
  83. #endif
  84. #endif
  85. #elif !defined _AFXDLL && defined XLISTCTRLLIB_STATIC
  86. // MFC static lib with XListCtrl static lib
  87. #ifdef _UNICODE
  88. #ifdef _DEBUG
  89. #pragma comment(lib,"XListCtrlSSDU.lib")
  90. #pragma message("Automatically linking with XListCtrlSSDU.lib")
  91. #else
  92. #pragma comment(lib,"XListCtrlSSRU.lib")
  93. #pragma message("Automatically linking with XListCtrlSSRU.lib")
  94. #endif
  95. #else
  96. #ifdef _DEBUG
  97. #pragma comment(lib,"XListCtrlSSDA.lib")
  98. #pragma message("Automatically linking with XListCtrlSSDA.lib")
  99. #else
  100. #pragma comment(lib,"XListCtrlSSRA.lib")
  101. #pragma message("Automatically linking with XListCtrlSSRA.lib")
  102. #endif
  103. #endif
  104. #else
  105. #pragma message(" ")
  106. #pragma message("--------------------------------------------------------------------------------")
  107. #pragma message(" The SD build configuration (MFC static, XListCtrl DLL) is not available. ")
  108. #pragma message("--------------------------------------------------------------------------------")
  109. #pragma message(" ")
  110. #error This build configuration is not available.
  111. #endif
  112. #endif
  113. #endif // ²»Ê¹ÓÃlib;
  114. #if !defined XLISTCTRLLIB_EXPORTS && !defined XLISTCTRLLIB_STATIC
  115. XLISTCTRLLIBDLLEXPORT UINT WM_XLISTCTRL_COMBO_SELECTION;
  116. XLISTCTRLLIBDLLEXPORT UINT WM_XLISTCTRL_EDIT_END;
  117. XLISTCTRLLIBDLLEXPORT UINT WM_XLISTCTRL_CHECKBOX_CLICKED;
  118. #elif !defined XLISTCTRLLIB_EXPORTS && defined XLISTCTRLLIB_STATIC
  119. extern UINT WM_XLISTCTRL_COMBO_SELECTION;
  120. extern UINT WM_XLISTCTRL_EDIT_END;
  121. extern UINT WM_XLISTCTRL_CHECKBOX_CLICKED;
  122. #endif
  123. ///////////////////////////////////////////////////////////////////////////////
  124. // CXListCtrl data
  125. struct XLISTCTRLDATA
  126. {
  127. // ctor
  128. XLISTCTRLDATA()
  129. {
  130. bEnabled = TRUE;
  131. bBold = FALSE;
  132. bModified = FALSE;
  133. nImage = -1;
  134. #ifndef NO_XLISTCTRL_TOOL_TIPS
  135. strToolTip = _T("");
  136. #endif
  137. bCombo = FALSE;
  138. bSort = FALSE;
  139. psa = NULL;
  140. nComboListHeight = 10;
  141. nInitialComboSel = -1; // use default
  142. bEdit = FALSE;
  143. crText = ::GetSysColor(COLOR_WINDOWTEXT);
  144. crBackground = ::GetSysColor(COLOR_WINDOW);
  145. bShowProgress = FALSE;
  146. nProgressPercent = 0;
  147. strProgressMessage = _T("");
  148. bShowProgressMessage = TRUE;
  149. nCheckedState = -1;
  150. dwItemData = 0;
  151. }
  152. BOOL bEnabled; // TRUE = enabled, FALSE = disabled (gray text)
  153. BOOL bBold; // TRUE = display bold text
  154. BOOL bModified; // TRUE = subitem has been modified
  155. int nImage; // index in image list, else -1
  156. #ifndef NO_XLISTCTRL_TOOL_TIPS
  157. CString strToolTip; // tool tip text for cell
  158. #endif
  159. // for combo
  160. BOOL bCombo; // TRUE = display combobox
  161. BOOL bSort; // TRUE = add CBS_SORT style; this means
  162. // that the list will be re-sorted on
  163. // each AddString()
  164. CStringArray * psa; // pointer to string array for combo listbox
  165. int nComboListHeight; // combo listbox height (in rows)
  166. int nInitialComboSel; // initial combo listbox selection (0 = first)
  167. //for edit
  168. BOOL bEdit; // true = enable editing
  169. // for color
  170. COLORREF crText;
  171. COLORREF crBackground;
  172. // for progress
  173. BOOL bShowProgress; // true = show progress control
  174. int nProgressPercent; // 0 - 100
  175. CString strProgressMessage; // custom message for progress indicator -
  176. // MUST INCLUDE %d
  177. BOOL bShowProgressMessage; // TRUE = display % message, or custom message
  178. // if one is supplied
  179. // for checkbox
  180. int nCheckedState; // -1 = don't show, 0 = unchecked, 1 = checked
  181. DWORD dwItemData; // pointer to app's data
  182. };
  183. ///////////////////////////////////////////////////////////////////////////////
  184. // CXListCtrl class
  185. class XLISTCTRLLIBDLLEXPORT CXListCtrl : public CListCtrl
  186. {
  187. // Construction
  188. public:
  189. CXListCtrl();
  190. virtual ~CXListCtrl();
  191. // Attributes
  192. public:
  193. // Operations
  194. public:
  195. int CountCheckedItems(int nSubItem);
  196. BOOL DeleteAllItems();
  197. BOOL DeleteItem(int nItem);
  198. void DeleteProgress(int nItem, int nSubItem);
  199. int FindDataItem(DWORD dwData); //+++
  200. BOOL GetBold(int nItem, int nSubItem);
  201. int GetCellPadding() { return m_nPadding; } //+++
  202. int GetCheckbox(int nItem, int nSubItem);
  203. int GetColumns();
  204. CString GetComboText(int iItem, int iSubItem);
  205. int GetCurSel();
  206. BOOL GetEllipsis() { return m_bUseEllipsis; } //+++
  207. BOOL GetEnabled(int nItem);
  208. DWORD GetExtendedStyleX() { return m_dwExtendedStyleX; }
  209. int GetHeaderCheckedState(int nSubItem);
  210. int GetItemCheckedState(int nItem, int nSubItem); //+++
  211. BOOL GetItemColors(int nItem, //+++
  212. int nSubItem,
  213. COLORREF& crText,
  214. COLORREF& crBackground);
  215. DWORD GetItemData(int nItem);
  216. BOOL GetListModified() { return m_bListModified; } //+++
  217. BOOL GetModified(int nItem, int nSubItem); //+++
  218. BOOL GetSubItemRect(int iItem, int iSubItem, int nArea, CRect& rect);
  219. int InsertItem(int nItem, LPCTSTR lpszItem);
  220. int InsertItem(int nItem,
  221. LPCTSTR lpszItem,
  222. COLORREF crText,
  223. COLORREF crBackground);
  224. int InsertItem(const LVITEM* pItem);
  225. BOOL SetBold(int nItem, int nSubItem, BOOL bBold);
  226. void SetCellPadding(int nPadding) { m_nPadding = nPadding; } //+++
  227. BOOL SetComboBox(int nItem,
  228. int nSubItem,
  229. BOOL bEnableCombo,
  230. CStringArray *psa,
  231. int nComboListHeight,
  232. int nInitialComboSel,
  233. BOOL bSort = FALSE); //+++
  234. BOOL SetCheckbox(int nItem, int nSubItem, int nCheckedState);
  235. virtual int SetColumnWidth(int nCol, int cx)
  236. {
  237. CListCtrl::SetColumnWidth(nCol, cx);
  238. int w = CListCtrl::GetColumnWidth(nCol);
  239. return CListCtrl::SetColumnWidth(nCol, w + (m_HeaderCtrl.GetSpacing()*2));
  240. }
  241. BOOL SetCurSel(int nItem, BOOL bEnsureVisible = FALSE); //+++
  242. BOOL SetEdit(int nItem, int nSubItem);
  243. BOOL SetEllipsis(BOOL bEllipsis) //+++
  244. {
  245. BOOL bOldEllipsis = m_bUseEllipsis;
  246. m_bUseEllipsis = bEllipsis;
  247. return bOldEllipsis;
  248. }
  249. BOOL SetEnabled(int nItem, BOOL bEnable);
  250. DWORD SetExtendedStyleX(DWORD dwNewStyle)
  251. {
  252. DWORD dwOldStyle = m_dwExtendedStyleX;
  253. m_dwExtendedStyleX = dwNewStyle;
  254. return dwOldStyle;
  255. }
  256. void SetHeaderAlignment(UINT nFormat) { m_HeaderCtrl.SetAlignment(nFormat); } //+++
  257. void SetHeaderTextColor(COLORREF rgbText) { m_HeaderCtrl.SetTextColor(rgbText); } //+++
  258. void SetHeaderCtrlFillRectColor(COLORREF clrFillRect) { m_HeaderCtrl.SetFillRectColor(clrFillRect);}
  259. void SetHeaderCtrl3DRectColor(COLORREF clrTopLeft, COLORREF clrBottomRight) {m_HeaderCtrl.Set3DRectColor(clrTopLeft,clrBottomRight);}
  260. BOOL SetHeaderCheckedState(int nSubItem, int nCheckedState);
  261. void SetItemCheckedState(int nItem, int nSubItem, int nCheckedState); //+++
  262. int SetItem(const LVITEM* pItem);
  263. void SetItemColors(int nItem, //+++
  264. int nSubItem,
  265. COLORREF crText,
  266. COLORREF crBackground);
  267. BOOL SetItemData(int nItem, DWORD dwData);
  268. BOOL SetItemImage(int nItem, int nSubItem, int nImage);
  269. BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText);
  270. BOOL SetItemText(int nItem,
  271. int nSubItem,
  272. LPCTSTR lpszText,
  273. COLORREF crText,
  274. COLORREF crBackground);
  275. void SetListModified(BOOL bListModified) { m_bListModified = bListModified; } //+++
  276. void SetModified(int nItem, int nSubItem, BOOL bModified); //+++
  277. BOOL SetProgress(int nItem,
  278. int nSubItem,
  279. BOOL bShowProgressText = TRUE,
  280. LPCTSTR lpszProgressText = NULL);
  281. void UpdateProgress(int nItem, int nSubItem, int nPercent);
  282. void UpdateSubItem(int nItem, int nSubItem);
  283. #ifndef NO_XLISTCTRL_TOOL_TIPS
  284. void DeleteAllToolTips();
  285. BOOL SetItemToolTipText(int nItem, int nSubItem, LPCTSTR lpszToolTipText);
  286. CString GetItemToolTipText(int nItem, int nSubItem);
  287. virtual int OnToolHitTest(CPoint point, TOOLINFO * pTI) const;
  288. #endif
  289. // Overrides
  290. // ClassWizard generated virtual function overrides
  291. //{{AFX_VIRTUAL(CXListCtrl)
  292. public:
  293. virtual void PreSubclassWindow();
  294. //}}AFX_VIRTUAL
  295. // Implementation
  296. public:
  297. CXHeaderCtrl m_HeaderCtrl;
  298. CImageList m_cImageList; // Image list for the header control
  299. protected:
  300. void DrawCheckbox(int nItem,
  301. int nSubItem,
  302. CDC *pDC,
  303. COLORREF crText,
  304. COLORREF crBkgnd,
  305. CRect& rect,
  306. XLISTCTRLDATA *pCLD);
  307. #ifndef DO_NOT_INCLUDE_XCOMBOLIST
  308. void DrawComboBox(int nItem,
  309. int nSubItem);
  310. #endif
  311. void DrawEdit(int nItem, int nSubItem);
  312. int DrawImage(int nItem,
  313. int nSubItem,
  314. CDC* pDC,
  315. COLORREF crText,
  316. COLORREF crBkgnd,
  317. CRect rect,
  318. XLISTCTRLDATA *pXLCD);
  319. void DrawProgress(int nItem,
  320. int nSubItem,
  321. CDC *pDC,
  322. COLORREF crText,
  323. COLORREF crBkgnd,
  324. CRect& rect,
  325. XLISTCTRLDATA *pCLD);
  326. void DrawText(int nItem,
  327. int nSubItem,
  328. CDC *pDC,
  329. COLORREF crText,
  330. COLORREF crBkgnd,
  331. CRect& rect,
  332. XLISTCTRLDATA *pCLD);
  333. void GetColors();
  334. void GetDrawColors(int nItem,
  335. int nSubItem,
  336. COLORREF& colorText,
  337. COLORREF& colorBkgnd);
  338. void SubclassHeaderControl();
  339. BOOL m_bHeaderIsSubclassed;
  340. BOOL m_bUseEllipsis; //+++
  341. BOOL m_bListModified; //+++
  342. DWORD m_dwExtendedStyleX;
  343. int m_nPadding; //+++
  344. CString m_strInitialString; // used to save the initial string
  345. // for edit and combo fields
  346. BOOL m_bInitialCheck; // initial check state of a checkbox field
  347. // for edit box
  348. CXEdit * m_pEdit; //+++
  349. int m_nEditItem;
  350. int m_nEditSubItem;
  351. #ifndef DO_NOT_INCLUDE_XCOMBOLIST //-----------------------------------------
  352. BOOL m_bComboIsClicked;
  353. int m_nComboItem;
  354. int m_nComboSubItem;
  355. CRect m_rectComboButton;
  356. CRect m_rectComboList;
  357. CXCombo * m_pCombo;
  358. CFont m_ListboxFont;
  359. BOOL m_bFontIsCreated;
  360. #endif //---------------------------------------------------------------------
  361. COLORREF m_cr3DFace;
  362. COLORREF m_cr3DHighLight;
  363. COLORREF m_cr3DShadow;
  364. COLORREF m_crActiveCaption;
  365. COLORREF m_crBtnFace;
  366. COLORREF m_crBtnShadow;
  367. COLORREF m_crBtnText;
  368. COLORREF m_crGrayText;
  369. COLORREF m_crHighLight;
  370. COLORREF m_crHighLightText;
  371. COLORREF m_crInactiveCaption;
  372. COLORREF m_crInactiveCaptionText;
  373. COLORREF m_crWindow;
  374. COLORREF m_crWindowText;
  375. // Generated message map functions
  376. protected:
  377. //{{AFX_MSG(CXListCtrl)
  378. afx_msg BOOL OnClick(NMHDR* pNMHDR, LRESULT* pResult);
  379. afx_msg BOOL OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
  380. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  381. afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
  382. afx_msg void OnDestroy();
  383. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  384. afx_msg void OnPaint();
  385. afx_msg void OnSysColorChange();
  386. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  387. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  388. afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  389. afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
  390. //}}AFX_MSG
  391. #ifndef DO_NOT_INCLUDE_XCOMBOLIST
  392. afx_msg void OnTimer(UINT nIDEvent);
  393. afx_msg LRESULT OnComboEscape(WPARAM, LPARAM);
  394. afx_msg LRESULT OnComboComplete(WPARAM, LPARAM);
  395. #endif
  396. #ifndef NO_XLISTCTRL_TOOL_TIPS
  397. virtual afx_msg BOOL OnToolTipText(UINT id, NMHDR * pNMHDR, LRESULT * pResult);
  398. #endif
  399. afx_msg LRESULT OnXEditKillFocus(WPARAM, LPARAM);
  400. afx_msg LRESULT OnXEditEscape(WPARAM, LPARAM);
  401. DECLARE_MESSAGE_MAP()
  402. };
  403. /////////////////////////////////////////////////////////////////////////////
  404. //{{AFX_INSERT_LOCATION}}
  405. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  406. #endif //XLISTCTRL_H