GridCtrl.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. #if !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
  2. #define AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
  3. #if _MSC_VER >= 1000
  4. #pragma once
  5. #endif // _MSC_VER >= 1000
  6. #include <WinSDKVer.h>
  7. /////////////////////////////////////////////////////////////////////////////
  8. // GridCtrl.h : header file
  9. //
  10. // MFC Grid Control header file
  11. //
  12. // Written by Chris Maunder (chrismaunder@codeguru.com)
  13. // Copyright (c) 1998.
  14. //
  15. // The code contained in this file is based on the original
  16. // WorldCom Grid control written by Joe Willcoxson,
  17. // E-mail: chinajoe@aol.com
  18. // URL: http://users.aol.com/chinajoe
  19. //
  20. // This code may be used in compiled form in any way you desire. This
  21. // file may be redistributed unmodified by any means PROVIDING it is
  22. // not sold for profit without the authors written consent, and
  23. // providing that this notice and the authors name and all copyright
  24. // notices remains intact. If the source code in this file is used in
  25. // any commercial application then a statement along the lines of
  26. // "Portions copyright (c) Chris Maunder, 1998" must be included in
  27. // the startup banner, "About" box or printed documentation. An email
  28. // letting me know that you are using it would be nice as well. That's
  29. // not much to ask considering the amount of work that went into this.
  30. //
  31. // This file is provided "as is" with no expressed or implied warranty.
  32. // The author accepts no liability for any damage/loss of business that
  33. // this product may cause.
  34. //
  35. // Expect bugs!
  36. //
  37. // Please use and enjoy. Please let me know of any bugs/mods/improvements
  38. // that you have found/implemented and I will fix/incorporate them into this
  39. // file.
  40. //
  41. /////////////////////////////////////////////////////////////////////////////
  42. //#define GRIDCONTROL_NO_TITLETIPS // Do not use titletips for cells with large data
  43. //#define GRIDCONTROL_NO_DRAGDROP // Do not use OLE drag and drop
  44. //#define GRIDCONTROL_NO_CLIPBOARD // Do not use clipboard routines
  45. #include "CellRange.h"
  46. #include <afxtempl.h>
  47. #ifdef _WIN32_WCE
  48. #define GRIDCONTROL_NO_TITLETIPS // Do not use titletips for cells with large data
  49. #define GRIDCONTROL_NO_DRAGDROP // Do not use OLE drag and drop
  50. #define GRIDCONTROL_NO_CLIPBOARD // Do not use clipboard routines
  51. #define GRIDCONTROL_NO_PRINTING // Do not use printing routines
  52. #ifdef WCE_NO_PRINTING
  53. #define _WIN32_WCE_NO_PRINTING
  54. #endif
  55. #ifdef WCE_NO_CURSOR
  56. #define _WIN32_WCE_NO_CURSOR
  57. #endif
  58. #else
  59. // Use C++ exception handling instead of structured.
  60. #undef TRY
  61. #undef CATCH
  62. #undef END_CATCH
  63. #define TRY try
  64. #define CATCH(ex_class, ex_object) catch(ex_class* ex_object)
  65. #define END_CATCH
  66. #endif // _WIN32_WCE
  67. #ifndef GRIDCONTROL_NO_TITLETIPS
  68. #include "TitleTip.h"
  69. #endif
  70. #ifndef GRIDCONTROL_NO_DRAGDROP
  71. #include "GridDropTarget.h"
  72. #undef GRIDCONTROL_NO_CLIPBOARD // Force clipboard functions on
  73. #endif
  74. #ifndef GRIDCONTROL_NO_CLIPBOARD
  75. #include <afxole.h>
  76. #endif
  77. // Use this as the classname when inserting this control as a custom control
  78. // in the MSVC++ dialog editor
  79. #define GRIDCTRL_CLASSNAME _T("MFCGridCtrl") // Window class name
  80. #define IDC_INPLACE_CONTROL 8 // ID of inplace edit controls
  81. #define IsSHIFTpressed() ( (GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT)*8-1))) != 0 )
  82. #define IsCTRLpressed() ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )
  83. // Used for Get/SetItem calls.
  84. typedef struct _GV_ITEM {
  85. int row,col; // Row and Column of item
  86. UINT mask; // Mask for use in getting/setting cell data
  87. UINT state; // cell state (focus/hilighted etc)
  88. UINT nFormat; // Format of cell
  89. CString szText; // Text in cell
  90. int iImage; // index of the list view item’s icon
  91. COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
  92. COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
  93. LPARAM lParam; // 32-bit value to associate with item
  94. LOGFONT lfFont; // Cell font
  95. } GV_ITEM;
  96. // Grid line selection
  97. #define GVL_NONE 0
  98. #define GVL_HORZ 1
  99. #define GVL_VERT 2
  100. #define GVL_BOTH 3
  101. // Cell data mask
  102. #define GVIF_TEXT LVIF_TEXT
  103. #define GVIF_IMAGE LVIF_IMAGE
  104. #define GVIF_PARAM LVIF_PARAM
  105. #define GVIF_STATE LVIF_STATE
  106. #define GVIF_BKCLR (GVIF_STATE<<1)
  107. #define GVIF_FGCLR (GVIF_STATE<<2)
  108. #define GVIF_FORMAT (GVIF_STATE<<3)
  109. #define GVIF_FONT (GVIF_STATE<<4)
  110. // Cell states
  111. #define GVIS_FOCUSED 0x0001
  112. #define GVIS_SELECTED 0x0002
  113. #define GVIS_DROPHILITED 0x0004
  114. #define GVIS_READONLY 0x0008
  115. #define GVIS_FIXED 0x0010 // not yet used
  116. #define GVIS_MODIFIED 0x0020
  117. // Cell Searching options
  118. #define GVNI_FOCUSED 0x0001
  119. #define GVNI_SELECTED 0x0002
  120. #define GVNI_DROPHILITED 0x0004
  121. #define GVNI_READONLY 0x0008
  122. #define GVNI_FIXED 0x0010 // not yet used
  123. #define GVNI_MODIFIED 0x0020
  124. #define GVNI_ABOVE LVNI_ABOVE
  125. #define GVNI_BELOW LVNI_BELOW
  126. #define GVNI_TOLEFT LVNI_TOLEFT
  127. #define GVNI_TORIGHT LVNI_TORIGHT
  128. #define GVNI_ALL (LVNI_BELOW|LVNI_TORIGHT|LVNI_TOLEFT)
  129. #define GVNI_AREA (LVNI_BELOW|LVNI_TORIGHT)
  130. // Hit test values (not yet implemented)
  131. #define GVHT_DATA 0x0000
  132. #define GVHT_TOPLEFT 0x0001
  133. #define GVHT_COLHDR 0x0002
  134. #define GVHT_ROWHDR 0x0004
  135. #define GVHT_COLSIZER 0x0008
  136. #define GVHT_ROWSIZER 0x0010
  137. #define GVHT_LEFT 0x0020
  138. #define GVHT_RIGHT 0x0040
  139. #define GVHT_ABOVE 0x0080
  140. #define GVHT_BELOW 0x0100
  141. typedef struct tagNM_GRIDVIEW {
  142. NMHDR hdr;
  143. int iRow;
  144. int iColumn;
  145. } NM_GRIDVIEW;
  146. typedef struct tagGV_DISPINFO {
  147. NMHDR hdr;
  148. GV_ITEM item;
  149. } GV_DISPINFO;
  150. // Messages sent to the grid's parent (More will be added in future)
  151. #define GVN_BEGINDRAG LVN_BEGINDRAG // LVN_FIRST-9
  152. #define GVN_BEGINLABELEDIT LVN_BEGINLABELEDIT // LVN_FIRST-5
  153. #define GVN_BEGINRDRAG LVN_BEGINRDRAG
  154. #define GVN_COLUMNCLICK LVN_COLUMNCLICK
  155. #define GVN_DELETEITEM LVN_DELETEITEM
  156. #define GVN_ENDLABELEDIT LVN_ENDLABELEDIT // LVN_FIRST-6
  157. #define GVN_SELCHANGING LVN_ITEMCHANGING
  158. #define GVN_SELCHANGED LVN_ITEMCHANGED
  159. // Each cell contains one of these. Fields "row" and "column" are not stored since we
  160. // will usually have acces to them in other ways, and they are an extra 8 bytes per
  161. // cell that is probably unnecessary.
  162. class CGridCell : public CObject
  163. {
  164. public:
  165. CGridCell()
  166. {
  167. state = 0;
  168. nFormat = 0;
  169. szText.Empty();
  170. iImage = -1;
  171. crBkClr = CLR_DEFAULT;
  172. crFgClr = CLR_DEFAULT;
  173. lParam = 0;
  174. }
  175. UINT state; // Cell state (selected/focus etc)
  176. UINT nFormat; // Cell format
  177. CString szText; // Cell text (or binary data if you wish...)
  178. int iImage; // Index of the list view item’s icon
  179. COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
  180. COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
  181. LOGFONT lfFont; // Cell font
  182. LPARAM lParam; // 32-bit value to associate with item
  183. };
  184. // storage typedef for each row in the grid
  185. typedef CTypedPtrArray<CObArray, CGridCell*> GRID_ROW;
  186. // DDX_GridControl is used where a DDX_Control call is needed. In some strange
  187. // situations the usual DDX_Control does not result in CGridCtrl::SubclassWindow
  188. // or CGridCtrl::PreSubclassWindow being called. Using this version calls
  189. // CGridCtrl::SubclassWindow directly - ensuring that cell metrics are set properly
  190. class CGridCtrl;
  191. void AFXAPI DDX_GridControl(CDataExchange* pDX, int nIDC, CGridCtrl& rControl);
  192. /////////////////////////////////////////////////////////////////////////////
  193. // CGridCtrl window
  194. class CGridCtrl : public CWnd
  195. {
  196. DECLARE_DYNCREATE(CGridCtrl)
  197. // Construction
  198. public:
  199. BYTE nParentType;
  200. bool bEditing;
  201. CGridCtrl(int nRows = 0, int nCols = 0, int nFixedRows = 0, int nFixedCols = 0);
  202. BOOL Create(const RECT& rect, CWnd* parent, UINT nID,
  203. DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
  204. BOOL SubclassWindow(HWND hWnd);
  205. // Attributes
  206. public:
  207. int GetRowCount() const { return m_nRows; }
  208. int GetColumnCount() const { return m_nCols; }
  209. int GetFixedRowCount() const { return m_nFixedRows; }
  210. int GetFixedColumnCount() const { return m_nFixedCols; }
  211. BOOL SetRowCount(int nRows = 10);
  212. BOOL SetColumnCount(int nCols = 10);
  213. BOOL SetFixedRowCount(int nFixedRows = 1);
  214. BOOL SetFixedColumnCount(int nFixedCols = 1);
  215. int GetRowHeight(int nRow) const;
  216. BOOL SetRowHeight(int row, int height);
  217. int GetColumnWidth(int nCol) const;
  218. BOOL SetColumnWidth(int col, int width);
  219. BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p) const;
  220. BOOL GetCellOrigin(const CCellID& cell, LPPOINT p) const;
  221. BOOL GetCellRect(int nRow, int nCol, LPRECT pRect) const;
  222. BOOL GetCellRect(const CCellID& cell, LPRECT pRect) const;
  223. BOOL GetTextRect(const CCellID& cell, LPRECT pRect);
  224. BOOL GetTextRect(int nRow, int nCol, LPRECT pRect);
  225. int GetFixedRowHeight() const;
  226. int GetFixedColumnWidth() const;
  227. long GetVirtualWidth() const;
  228. long GetVirtualHeight() const;
  229. void SetTextColor(COLORREF clr) { m_crTextColour = clr; }
  230. COLORREF GetTextColor() const { return m_crTextColour; }
  231. void SetTextBkColor(COLORREF clr) { m_crTextBkColour = clr; }
  232. COLORREF GetTextBkColor() const { return m_crTextBkColour; }
  233. void SetBkColor(COLORREF clr) { m_crBkColour = clr; }
  234. COLORREF GetBkColor() const { return m_crBkColour; }
  235. void SetFixedTextColor(COLORREF clr) { m_crFixedTextColour = clr; }
  236. COLORREF GetFixedTextColor() const { return m_crFixedTextColour; }
  237. void SetFixedBkColor(COLORREF clr) { m_crFixedBkColour = clr; }
  238. COLORREF GetFixedBkColor() const { return m_crFixedBkColour; }
  239. void SetGridColor(COLORREF clr) { m_crGridColour = clr; }
  240. COLORREF GetGridColor() const { return m_crGridColour; }
  241. int GetSelectedCount() const { return m_SelectedCellMap.GetCount(); }
  242. CCellID GetFocusCell() const { return m_idCurrentCell; }
  243. void SetImageList(CImageList* pList) { m_pImageList = pList; }
  244. CImageList* GetImageList() const { return m_pImageList; }
  245. void SetGridLines(int nWhichLines = GVL_BOTH) { m_nGridLines = nWhichLines;
  246. if (::IsWindow(GetSafeHwnd())) Invalidate(); }
  247. int GetGridLines() const { return m_nGridLines; }
  248. void SetEditable(BOOL bEditable = TRUE) { m_bEditable = bEditable; }
  249. BOOL IsEditable() const { return m_bEditable; }
  250. void SetListMode(BOOL bEnableListMode = TRUE) { m_bListMode = bEnableListMode; }
  251. BOOL GetListMode() const { return m_bListMode; }
  252. void SetSingleRowSelection(BOOL bSing = TRUE) { m_bSingleRowSelection = bSing; }
  253. BOOL GetSingleRowSelection() { return m_bSingleRowSelection; }
  254. void EnableSelection(BOOL bEnable = TRUE) { ResetSelectedRange(); m_bEnableSelection = bEnable; ResetSelectedRange(); }
  255. BOOL IsSelectable() const { return m_bEnableSelection; }
  256. void EnableDragAndDrop(BOOL bAllow = TRUE) { m_bAllowDragAndDrop = bAllow; }
  257. BOOL GetDragAndDrop() const { return m_bAllowDragAndDrop; }
  258. void SetRowResize(BOOL bResize = TRUE) { m_bAllowRowResize = bResize; }
  259. BOOL GetRowResize() const { return m_bAllowRowResize; }
  260. void SetColumnResize(BOOL bResize = TRUE) { m_bAllowColumnResize = bResize; }
  261. BOOL GetColumnResize() const { return m_bAllowColumnResize; }
  262. void SetHeaderSort(BOOL bSortOnClick = TRUE) { m_bSortOnClick = bSortOnClick; }
  263. BOOL GetHeaderSort() const { return m_bSortOnClick; }
  264. void SetHandleTabKey(BOOL bHandleTab = TRUE) { m_bHandleTabKey = bHandleTab; }
  265. BOOL GetHandleTabKey() const { return m_bHandleTabKey; }
  266. void SetDoubleBuffering(BOOL bBuffer = TRUE) { m_bDoubleBuffer = bBuffer; }
  267. BOOL GetDoubleBuffering() const { return m_bDoubleBuffer; }
  268. void EnableTitleTips(BOOL bEnable = TRUE) { m_bTitleTips = bEnable; }
  269. BOOL GetTitleTips() { return m_bTitleTips; }
  270. void SetModified(BOOL bModified = TRUE, int nRow = -1, int nCol = -1);
  271. BOOL GetModified(int nRow = -1, int nCol = -1);
  272. BOOL IsCellFixed(int nRow, int nCol);
  273. virtual BOOL SetItem(const GV_ITEM* pItem);
  274. BOOL GetItem(GV_ITEM* pItem);
  275. virtual BOOL SetItemText(int nRow, int nCol, LPCTSTR str);
  276. virtual CString GetItemText(int nRow, int nCol);
  277. BOOL SetItemData(int nRow, int nCol, LPARAM lParam);
  278. LPARAM GetItemData(int nRow, int nCol) const;
  279. BOOL SetItemImage(int nRow, int nCol, int iImage);
  280. int GetItemImage(int nRow, int nCol) const;
  281. BOOL SetItemState(int nRow, int nCol, UINT state);
  282. UINT GetItemState(int nRow, int nCol) const;
  283. BOOL SetItemFormat(int nRow, int nCol, UINT nFormat);
  284. UINT GetItemFormat(int nRow, int nCol) const;
  285. BOOL SetItemBkColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
  286. COLORREF GetItemBkColour(int nRow, int nCol) const;
  287. BOOL SetItemFgColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
  288. COLORREF GetItemFgColour(int nRow, int nCol) const;
  289. BOOL SetItemFont(int nRow, int nCol, LOGFONT* lf);
  290. LOGFONT* GetItemFont(int nRow, int nCol);
  291. // Operations
  292. public:
  293. int InsertColumn(LPCTSTR strHeading, UINT nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE,
  294. int nColumn = -1);
  295. int InsertRow(LPCTSTR strHeading, int nRow = -1);
  296. BOOL DeleteColumn(int nColumn);
  297. BOOL DeleteRow(int nRow);
  298. BOOL DeleteNonFixedRows();
  299. BOOL DeleteAllItems();
  300. BOOL AutoSizeRow(int nRow);
  301. BOOL AutoSizeColumn(int nCol);
  302. void AutoSizeRows();
  303. void AutoSizeColumns();
  304. void AutoSize();
  305. void ExpandColumnsToFit();
  306. void ExpandRowsToFit();
  307. void ExpandToFit();
  308. CSize GetTextExtent(LPCTSTR str, BOOL bUseSelectedFont = TRUE);
  309. void EnsureVisible(CCellID &cell) { EnsureVisible(cell.row, cell.col); }
  310. void EnsureVisible(int nRow, int nCol);
  311. BOOL IsCellVisible(int nRow, int nCol) const;
  312. BOOL IsCellVisible(CCellID cell) const;
  313. BOOL IsCellEditable(int nRow, int nCol) const;
  314. BOOL IsCellEditable(CCellID &cell) const;
  315. // SetRedraw stops/starts redraws on things like changing the # rows/columns
  316. // and autosizing, but not for user-intervention such as resizes
  317. void SetRedraw(BOOL bAllowDraw, BOOL bResetScrollBars = FALSE);
  318. BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
  319. BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL);
  320. BOOL RedrawRow(int row);
  321. BOOL RedrawColumn(int col);
  322. #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
  323. void Print();
  324. #endif
  325. #ifndef _WIN32_WCE
  326. BOOL Save(LPCTSTR filename);
  327. BOOL Load(LPCTSTR filename);
  328. #endif
  329. CCellRange GetCellRange() const;
  330. CCellRange GetSelectedCellRange() const;
  331. void SetSelectedRange(const CCellRange& Range, BOOL bForceRepaint = FALSE);
  332. void SetSelectedRange(int nMinRow, int nMinCol, int nMaxRow, int nMaxCol,
  333. BOOL bForceRepaint = FALSE);
  334. BOOL IsValid(int nRow, int nCol) const;
  335. BOOL IsValid(const CCellID& cell) const;
  336. BOOL IsValid(const CCellRange& range) const;
  337. #ifndef GRIDCONTROL_NO_CLIPBOARD
  338. // Clipboard and cut n' paste operations
  339. virtual void CutSelectedText();
  340. virtual COleDataSource* CopyTextFromGrid();
  341. virtual BOOL PasteTextToGrid(CCellID cell, COleDataObject* pDataObject);
  342. #endif
  343. #ifndef GRIDCONTROL_NO_DRAGDROP
  344. void OnBeginDrag();
  345. DROPEFFECT OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
  346. DROPEFFECT OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
  347. void OnDragLeave();
  348. BOOL OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
  349. #endif
  350. #ifndef GRIDCONTROL_NO_CLIPBOARD
  351. virtual void OnEditCut();
  352. virtual void OnEditCopy();
  353. virtual void OnEditPaste();
  354. #endif
  355. virtual void OnEditSelectAll();
  356. CCellID GetNextItem(CCellID& cell, int nFlags) const;
  357. BOOL SortTextItems(int nCol, BOOL bAscending);
  358. BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data = 0);
  359. // Overrides
  360. // ClassWizard generated virtual function overrides
  361. //{{AFX_VIRTUAL(CGridCtrl)
  362. protected:
  363. virtual void PreSubclassWindow();
  364. //}}AFX_VIRTUAL
  365. #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
  366. public:
  367. virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
  368. virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
  369. virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
  370. #endif
  371. // Implementation
  372. public:
  373. virtual ~CGridCtrl();
  374. public:
  375. BOOL RegisterWindowClass();
  376. LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
  377. BOOL InvalidateCellRect(const CCellID& cell);
  378. BOOL InvalidateCellRect(const CCellRange& cellRange);
  379. void EraseBkgnd(CDC* pDC);
  380. BOOL GetCellRangeRect(const CCellRange& cellRange, LPRECT lpRect) const;
  381. CGridCell* GetCell(int nRow, int nCol) const;
  382. BOOL SetCell(int nRow, int nCol, CGridCell* pCell);
  383. int SetMouseMode(int nMode) { int nOldMode = m_MouseMode; m_MouseMode = nMode; return nOldMode; }
  384. int GetMouseMode() const { return m_MouseMode; }
  385. BOOL MouseOverRowResizeArea(CPoint& point) const;
  386. BOOL MouseOverColumnResizeArea(CPoint& point) const;
  387. CCellID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE) const;
  388. CCellID GetTopleftNonFixedCell() const;
  389. CCellRange GetUnobstructedNonFixedCellRange() const;
  390. CCellRange GetVisibleNonFixedCellRange(LPRECT pRect = NULL) const;
  391. CCellID SetFocusCell(CCellID cell);
  392. CCellID SetFocusCell(int nRow, int nCol);
  393. void ResetSelectedRange();
  394. void ResetScrollBars();
  395. int GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
  396. BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);
  397. BOOL SortTextItems(int nCol, BOOL bAscending, int low, int high);
  398. BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data,
  399. int low, int high);
  400. // Overrrides
  401. protected:
  402. public:
  403. // Printing
  404. #if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
  405. virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
  406. virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
  407. virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
  408. #endif
  409. #ifndef GRIDCONTROL_NO_DRAGDROP
  410. // Drag n' drop
  411. virtual CImageList* CreateDragImage(CPoint *pHotSpot); // no longer necessary
  412. #endif
  413. // Mouse Clicks
  414. virtual void OnFixedColumnClick(CCellID& cell);
  415. virtual void OnFixedRowClick(CCellID& cell);
  416. // Editing
  417. virtual CSize GetCellExtent(int nRow, int nCol, CDC* pDC);
  418. virtual void OnEndEditCell(int nRow, int nCol, CString str);
  419. virtual void OnEditCell(int nRow, int nCol, UINT nChar);
  420. virtual void CreateInPlaceEditControl(CRect& rect, DWORD dwStyle, UINT nID,
  421. int nRow, int nCol,
  422. LPCTSTR szText, int nChar);
  423. // Drawing
  424. virtual void OnDraw(CDC* pDC);
  425. virtual BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
  426. virtual BOOL DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
  427. // GridCell Creation and Cleanup
  428. virtual CGridCell* CreateCell(int nRow, int nCol);
  429. virtual void EmptyCell(CGridCell* pCell, int nRow, int nCol);
  430. // Attributes
  431. protected:
  432. // General attributes
  433. COLORREF m_crTextColour, m_crTextBkColour, m_crBkColour, // Grid colours
  434. m_crFixedTextColour, m_crFixedBkColour, m_crGridColour;
  435. COLORREF m_crWindowText, m_crWindowColour, m_cr3DFace, // System colours
  436. m_crShadow;
  437. int m_nGridLines;
  438. BOOL m_bEditable;
  439. BOOL m_bModified;
  440. BOOL m_bAllowDragAndDrop;
  441. BOOL m_bListMode;
  442. BOOL m_bSingleRowSelection;
  443. BOOL m_bAllowDraw;
  444. BOOL m_bEnableSelection;
  445. BOOL m_bSortOnClick;
  446. BOOL m_bHandleTabKey;
  447. BOOL m_bDoubleBuffer;
  448. BOOL m_bTitleTips;
  449. // Cell size details
  450. int m_nRows, m_nFixedRows, m_nCols, m_nFixedCols;
  451. CUIntArray m_arRowHeights, m_arColWidths;
  452. int m_nMargin;
  453. int m_nDefCellWidth, m_nDefCellHeight;
  454. int m_nVScrollMax, m_nHScrollMax;
  455. // Fonts and images
  456. LOGFONT m_Logfont;
  457. CFont m_PrinterFont, // for the printer
  458. m_Font; // for the grid
  459. CImageList* m_pImageList;
  460. // Cell data
  461. CTypedPtrArray<CObArray, GRID_ROW*> m_RowData;
  462. // Mouse operations such as cell selection
  463. int m_MouseMode;
  464. CPoint m_LeftClickDownPoint, m_LastMousePoint;
  465. CCellID m_LeftClickDownCell, m_SelectionStartCell;
  466. CCellID m_idCurrentCell;
  467. int m_nTimerID;
  468. int m_nTimerInterval;
  469. int m_nResizeCaptureRange;
  470. BOOL m_bAllowRowResize, m_bAllowColumnResize;
  471. int m_nRowsPerWheelNotch;
  472. CMap<DWORD,DWORD, CCellID, CCellID&> m_SelectedCellMap, m_PrevSelectedCellMap;
  473. #ifndef GRIDCONTROL_NO_TITLETIPS
  474. CTitleTip m_TitleTip; // Title tips for cells
  475. #endif
  476. // Drag and drop
  477. BOOL m_bMustUninitOLE; // Do we need to uninitialise OLE?
  478. CCellID m_LastDragOverCell;
  479. #ifndef GRIDCONTROL_NO_DRAGDROP
  480. CGridDropTarget m_DropTarget; // OLE Drop target for the grid
  481. #endif
  482. // Printing information
  483. CSize m_CharSize;
  484. int m_nPageHeight;
  485. CSize m_LogicalPageSize, // Page size in gridctrl units.
  486. m_PaperSize; // Page size in device units.
  487. // sorting
  488. int m_bAscending;
  489. int m_SortColumn;
  490. protected:
  491. void SelectAllCells();
  492. void SelectColumns(CCellID currentCell);
  493. void SelectRows(CCellID currentCell);
  494. void SelectCells(CCellID currentCell);
  495. void OnSelecting(const CCellID& currentCell);
  496. // Generated message map functions
  497. //{{AFX_MSG(CGridCtrl)
  498. afx_msg void OnPaint();
  499. afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  500. afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  501. afx_msg void OnSize(UINT nType, int cx, int cy);
  502. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  503. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  504. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  505. afx_msg void OnTimer(UINT nIDEvent);
  506. afx_msg UINT OnGetDlgCode();
  507. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  508. afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  509. afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  510. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  511. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  512. afx_msg void OnSysColorChange();
  513. afx_msg void OnCaptureChanged(CWnd *pWnd);
  514. afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
  515. afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
  516. afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
  517. afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI);
  518. //}}AFX_MSG
  519. #if (_MFC_VER >= 0x0421) || (_WIN32_WCE >= 210)
  520. afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
  521. #endif
  522. #if !defined(_WIN32_WCE) && (_MFC_VER >= 0x0421)
  523. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  524. #endif
  525. afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam);
  526. afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
  527. afx_msg void OnEndInPlaceEdit(NMHDR* pNMHDR, LRESULT* pResult);
  528. DECLARE_MESSAGE_MAP()
  529. enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW,
  530. MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS,
  531. MOUSE_OVER_ROW_DIVIDE, MOUSE_SIZING_ROW,
  532. MOUSE_OVER_COL_DIVIDE, MOUSE_SIZING_COL,
  533. MOUSE_PREPARE_EDIT,
  534. #ifndef GRIDCONTROL_NO_DRAGDROP
  535. MOUSE_PREPARE_DRAG, MOUSE_DRAGGING
  536. #endif
  537. };
  538. };
  539. inline CGridCell* CGridCtrl::GetCell(int nRow, int nCol) const
  540. {
  541. if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return NULL;
  542. GRID_ROW* pRow = m_RowData[nRow];
  543. if (!pRow) return NULL;
  544. return pRow->GetAt(nCol);
  545. }
  546. inline BOOL CGridCtrl::SetCell(int nRow, int nCol, CGridCell* pCell)
  547. {
  548. if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return FALSE;
  549. GRID_ROW* pRow = m_RowData[nRow];
  550. if (!pRow) return FALSE;
  551. pRow->SetAt(nCol, pCell);
  552. return TRUE;
  553. }
  554. /////////////////////////////////////////////////////////////////////////////
  555. //{{AFX_INSERT_LOCATION}}
  556. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  557. #endif // !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)