GridCtrl.h 26 KB

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