XListCtrl.h 14 KB

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