GridCellBase.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /////////////////////////////////////////////////////////////////////////////
  2. // GridCellBase.h : header file
  3. //
  4. // MFC Grid Control - Grid cell base class header file
  5. //
  6. // Written by Chris Maunder <cmaunder@mail.com>
  7. // Copyright (c) 1998-2001. All Rights Reserved.
  8. //
  9. // This code may be used in compiled form in any way you desire. This
  10. // file may be redistributed unmodified by any means PROVIDING it is
  11. // not sold for profit without the authors written consent, and
  12. // providing that this notice and the authors name and all copyright
  13. // notices remains intact.
  14. //
  15. // An email letting me know how you are using it would be nice as well.
  16. //
  17. // This file is provided "as is" with no expressed or implied warranty.
  18. // The author accepts no liability for any damage/loss of business that
  19. // this product may cause.
  20. //
  21. // For use with CGridCtrl v2.22+
  22. //
  23. //////////////////////////////////////////////////////////////////////
  24. #if !defined(AFX_GRIDCELLBASE_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
  25. #define AFX_GRIDCELLBASE_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
  26. #if _MSC_VER >= 1000
  27. #pragma once
  28. #endif // _MSC_VER >= 1000
  29. class CGridCtrl;
  30. // Cell states
  31. #define GVIS_FOCUSED 0x0001
  32. #define GVIS_SELECTED 0x0002
  33. #define GVIS_DROPHILITED 0x0004
  34. #define GVIS_READONLY 0x0008
  35. #define GVIS_FIXED 0x0010
  36. #define GVIS_FIXEDROW 0x0020
  37. #define GVIS_FIXEDCOL 0x0040
  38. #define GVIS_MODIFIED 0x0080
  39. // Cell data mask
  40. #define GVIF_TEXT LVIF_TEXT
  41. #define GVIF_IMAGE LVIF_IMAGE
  42. #define GVIF_PARAM LVIF_PARAM
  43. #define GVIF_STATE LVIF_STATE
  44. #define GVIF_BKCLR (GVIF_STATE<<1)
  45. #define GVIF_FGCLR (GVIF_STATE<<2)
  46. #define GVIF_FORMAT (GVIF_STATE<<3)
  47. #define GVIF_FONT (GVIF_STATE<<4)
  48. #define GVIF_MARGIN (GVIF_STATE<<5)
  49. #define GVIF_ALL (GVIF_TEXT|GVIF_IMAGE|GVIF_PARAM|GVIF_STATE|GVIF_BKCLR|GVIF_FGCLR| \
  50. GVIF_FORMAT|GVIF_FONT|GVIF_MARGIN)
  51. // Used for Get/SetItem calls.
  52. typedef struct _GV_ITEM {
  53. int row, col; // Row and Column of item
  54. UINT mask; // Mask for use in getting/setting cell data
  55. UINT nState; // cell state (focus/hilighted etc)
  56. DWORD nFormat; // Format of cell
  57. int iImage; // index of the list view item’s icon
  58. COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
  59. COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
  60. LPARAM lParam; // 32-bit value to associate with item
  61. LOGFONT lfFont; // Cell font
  62. UINT nMargin; // Internal cell margin
  63. CString strText; // Text in cell
  64. } GV_ITEM;
  65. // Each cell contains one of these. Fields "row" and "column" are not stored since we
  66. // will usually have acces to them in other ways, and they are an extra 8 bytes per
  67. // cell that is probably unnecessary.
  68. class CGridCellBase : public CObject
  69. {
  70. friend class CGridCtrl;
  71. DECLARE_DYNCREATE(CGridCellBase)
  72. // Construction/Destruction
  73. public:
  74. CGridCellBase();
  75. virtual ~CGridCellBase();
  76. // Attributes
  77. public:
  78. // can't do pure virtual because of DECLARE_DYNCREATE requirement
  79. // use ASSERT() to require that programmer overrides all that should
  80. // be pure virtuals
  81. virtual void SetText(LPCTSTR /* szText */) { ASSERT(FALSE); }
  82. virtual void SetImage(int /* nImage */) { ASSERT(FALSE); }
  83. virtual void SetData(LPARAM /* lParam */) { ASSERT(FALSE); }
  84. virtual void SetState(DWORD nState) { m_nState = nState; }
  85. virtual void SetFormat(DWORD /* nFormat */) { ASSERT(FALSE); }
  86. virtual void SetTextClr(COLORREF /* clr */) { ASSERT(FALSE); }
  87. virtual void SetBackClr(COLORREF /* clr */) { ASSERT(FALSE); }
  88. virtual void SetFont(const LOGFONT* /* plf */) { ASSERT(FALSE); }
  89. virtual void SetMargin(UINT /* nMargin */) { ASSERT(FALSE); }
  90. virtual void SetGrid(CGridCtrl* /* pGrid */) { ASSERT(FALSE); }
  91. virtual void SetCoords(int /* nRow */, int /* nCol */) { ASSERT(FALSE); }
  92. virtual LPCTSTR GetText() const { ASSERT(FALSE); return NULL; }
  93. virtual LPCTSTR GetTipText() const { return GetText(); } // may override TitleTip return
  94. virtual int GetImage() const { ASSERT(FALSE); return -1; }
  95. virtual LPARAM GetData() const { ASSERT(FALSE); return 0; }
  96. virtual DWORD GetState() const { return m_nState; }
  97. virtual DWORD GetFormat() const { ASSERT(FALSE); return 0; }
  98. virtual COLORREF GetTextClr() const { ASSERT(FALSE); return 0; }
  99. virtual COLORREF GetBackClr() const { ASSERT(FALSE); return 0; }
  100. virtual LOGFONT* GetFont() const { ASSERT(FALSE); return NULL; }
  101. virtual CFont* GetFontObject() const { ASSERT(FALSE); return NULL; }
  102. virtual CGridCtrl* GetGrid() const { ASSERT(FALSE); return NULL; }
  103. virtual CWnd* GetEditWnd() const { ASSERT(FALSE); return NULL; }
  104. virtual UINT GetMargin() const { ASSERT(FALSE); return 0; }
  105. virtual CGridCellBase* GetDefaultCell() const;
  106. virtual BOOL IsDefaultFont() const { ASSERT(FALSE); return FALSE; }
  107. virtual BOOL IsEditing() const { ASSERT(FALSE); return FALSE; }
  108. virtual BOOL IsFocused() const { return (m_nState & GVIS_FOCUSED); }
  109. virtual BOOL IsFixed() const { return (m_nState & GVIS_FIXED); }
  110. virtual BOOL IsFixedCol() const { return (m_nState & GVIS_FIXEDCOL); }
  111. virtual BOOL IsFixedRow() const { return (m_nState & GVIS_FIXEDROW); }
  112. virtual BOOL IsSelected() const { return (m_nState & GVIS_SELECTED); }
  113. virtual BOOL IsReadOnly() const { return (m_nState & GVIS_READONLY); }
  114. virtual BOOL IsModified() const { return (m_nState & GVIS_MODIFIED); }
  115. virtual BOOL IsDropHighlighted() const { return (m_nState & GVIS_DROPHILITED); }
  116. // Operators
  117. public:
  118. virtual void operator=(const CGridCellBase& cell);
  119. // Operations
  120. public:
  121. virtual void Reset();
  122. virtual BOOL Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd = TRUE);
  123. virtual BOOL GetTextRect(LPRECT pRect); // i/o: i=dims of cell rect; o=dims of text rect
  124. virtual BOOL GetTipTextRect(LPRECT pRect) { return GetTextRect(pRect); } // may override for btns, etc.
  125. virtual CSize GetTextExtent(LPCTSTR str, CDC* pDC = NULL);
  126. virtual CSize GetCellExtent(CDC* pDC);
  127. // Editing
  128. virtual BOOL Edit(int /* nRow */, int /* nCol */, CRect /* rect */, CPoint /* point */,
  129. UINT /* nID */, UINT /* nChar */) {
  130. ASSERT(FALSE); return FALSE;
  131. }
  132. virtual BOOL ValidateEdit(LPCTSTR str);
  133. virtual void EndEdit() {}
  134. // EFW - Added to print cells properly
  135. virtual BOOL PrintCell(CDC* pDC, int nRow, int nCol, CRect rect);
  136. // add additional protected grid members required of cells
  137. LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
  138. protected:
  139. virtual void OnEndEdit();
  140. virtual void OnMouseEnter();
  141. virtual void OnMouseOver();
  142. virtual void OnMouseLeave();
  143. virtual void OnClick(CPoint PointCellRelative);
  144. virtual void OnClickDown(CPoint PointCellRelative);
  145. virtual void OnRClick(CPoint PointCellRelative);
  146. virtual void OnDblClick(CPoint PointCellRelative);
  147. virtual BOOL OnSetCursor();
  148. protected:
  149. DWORD m_nState; // Cell state (selected/focus etc)
  150. };
  151. //{{AFX_INSERT_LOCATION}}
  152. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  153. #endif // !defined(AFX_GRIDCELLBASE_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)