GridCellBase.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include <afx.h>
  3. #include "CellRange.h" // Added by ClassView
  4. class CGridCtrl;
  5. // Cell states
  6. #define GVIS_FOCUSED 0x0001
  7. #define GVIS_SELECTED 0x0002
  8. #define GVIS_DROPHILITED 0x0004
  9. #define GVIS_READONLY 0x0008
  10. #define GVIS_FIXED 0x0010
  11. #define GVIS_FIXEDROW 0x0020
  12. #define GVIS_FIXEDCOL 0x0040
  13. #define GVIS_MODIFIED 0x0080
  14. // Cell data mask
  15. #define GVIF_TEXT LVIF_TEXT
  16. #define GVIF_IMAGE LVIF_IMAGE
  17. #define GVIF_PARAM LVIF_PARAM
  18. #define GVIF_STATE LVIF_STATE
  19. #define GVIF_BKCLR (GVIF_STATE<<1)
  20. #define GVIF_FGCLR (GVIF_STATE<<2)
  21. #define GVIF_FORMAT (GVIF_STATE<<3)
  22. #define GVIF_FONT (GVIF_STATE<<4)
  23. #define GVIF_MARGIN (GVIF_STATE<<5)
  24. #define GVIF_BORDER (GVIF_STATE<<6) // BORDER
  25. #define GVIF_BORDERCLR (GVIF_STATE<<7) // BORDER CLR
  26. #define GVIF_ALL (GVIF_TEXT|GVIF_IMAGE|GVIF_PARAM|GVIF_STATE|GVIF_BKCLR|GVIF_FGCLR| \
  27. GVIF_FORMAT|GVIF_FONT|GVIF_MARGIN|GVIF_BORDER)
  28. // CELL Border States
  29. #define GVIS_BDR_TOP 0X0001
  30. #define GVIS_BDR_RIGHT 0x0002
  31. #define GVIS_BDR_BOTTOM 0x0004
  32. #define GVIS_BDR_LEFT 0x0008
  33. // Used for Get/SetItem calls.
  34. typedef struct _GV_ITEM {
  35. int row, col; // Row and Column of item
  36. UINT mask; // Mask for use in getting/setting cell data
  37. UINT nState; // cell state (focus/hilighted etc)
  38. DWORD nFormat; // Format of cell
  39. int iImage; // index of the list view item’s icon
  40. COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
  41. COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
  42. UINT nBorder; // Border
  43. COLORREF crBorderClr; // Border Color
  44. LPARAM lParam; // 32-bit value to associate with item
  45. LOGFONT lfFont; // Cell font
  46. UINT nMargin; // Internal cell margin
  47. CString strText; // Text in cell
  48. } GV_ITEM;
  49. // Each cell contains one of these. Fields "row" and "column" are not stored since we
  50. // will usually have acces to them in other ways, and they are an extra 8 bytes per
  51. // cell that is probably unnecessary.
  52. class CGridCellBase : public CObject
  53. {
  54. friend class CGridCtrl;
  55. DECLARE_DYNAMIC(CGridCellBase)
  56. // Construction/Destruction
  57. public:
  58. CGridCellBase();
  59. virtual ~CGridCellBase();
  60. // Attributes
  61. public:
  62. virtual void SetText(LPCTSTR /* szText */) = 0;
  63. virtual void SetImage(int /* nImage */) = 0;
  64. virtual void SetData(LPARAM /* lParam */) = 0;
  65. virtual void SetState(DWORD nState) { m_nState = nState; }
  66. virtual void SetFormat(DWORD /* nFormat */) = 0;
  67. virtual void SetTextClr(COLORREF /* clr */) = 0;
  68. virtual void SetBackClr(COLORREF /* clr */) = 0;
  69. virtual void SetFont(const LOGFONT* /* plf */) = 0;
  70. virtual void SetMargin(UINT /* nMargin */) = 0;
  71. virtual void SetGrid(CGridCtrl* /* pGrid */) = 0;
  72. virtual void SetCoords(int /* nRow */, int /* nCol */) = 0;
  73. /*************************************************/
  74. virtual void SetBorderClr(COLORREF /* clr */) = 0;
  75. virtual void SetBorder(UINT /* BdrState */) = 0;
  76. virtual COLORREF GetBorderClr() const = 0;
  77. virtual UINT GetBorder() const = 0;
  78. /*************************************************/
  79. virtual LPCTSTR GetText() const = 0;
  80. virtual LPCTSTR GetTipText() const { return GetText(); } // may override TitleTip return
  81. virtual int GetImage() const = 0;
  82. virtual LPARAM GetData() const = 0;
  83. virtual DWORD GetState() const { return m_nState; }
  84. virtual DWORD GetFormat() const = 0;
  85. virtual COLORREF GetTextClr() const = 0;
  86. virtual COLORREF GetBackClr() const = 0;
  87. virtual LOGFONT * GetFont() const = 0;
  88. virtual CFont * GetFontObject() const = 0;
  89. virtual CGridCtrl* GetGrid() const = 0;
  90. virtual CWnd * GetEditWnd() const = 0;
  91. virtual UINT GetMargin() const = 0;
  92. virtual CGridCellBase* GetDefaultCell() const;
  93. virtual BOOL IsDefaultFont() const = 0;
  94. virtual BOOL IsEditing() const = 0;
  95. virtual BOOL IsFocused() const { return (m_nState & GVIS_FOCUSED); }
  96. virtual BOOL IsFixed() const { return (m_nState & GVIS_FIXED); }
  97. virtual BOOL IsFixedCol() const { return (m_nState & GVIS_FIXEDCOL); }
  98. virtual BOOL IsFixedRow() const { return (m_nState & GVIS_FIXEDROW); }
  99. virtual BOOL IsSelected() const { return (m_nState & GVIS_SELECTED); }
  100. virtual BOOL IsReadOnly() const { return (m_nState & GVIS_READONLY); }
  101. virtual BOOL IsModified() const { return (m_nState & GVIS_MODIFIED); }
  102. virtual BOOL IsDropHighlighted() const { return (m_nState & GVIS_DROPHILITED); }
  103. // Operators
  104. public:
  105. virtual void operator=(CGridCellBase& cell);
  106. // Operations
  107. public:
  108. bool IsMerged();
  109. void SetMergeRange(CCellRange range);
  110. void Show(bool IsShow);
  111. virtual void Reset();
  112. virtual BOOL Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd = TRUE);
  113. virtual BOOL GetTextRect(LPRECT pRect); // i/o: i=dims of cell rect; o=dims of text rect
  114. virtual BOOL GetTipTextRect(LPRECT pRect) { return GetTextRect(pRect); } // may override for btns, etc.
  115. virtual CSize GetTextExtent(LPCTSTR str, CDC* pDC = NULL);
  116. virtual CSize GetCellExtent(CDC* pDC);
  117. // Editing
  118. virtual BOOL Edit(int /* nRow */, int /* nCol */, CRect /* rect */, CPoint /* point */,
  119. UINT /* nID */, UINT /* nChar */) {
  120. ASSERT(FALSE); return FALSE;
  121. }
  122. virtual BOOL ValidateEdit(LPCTSTR str);
  123. virtual void EndEdit() {}
  124. // EFW - Added to print cells properly
  125. virtual BOOL PrintCell(CDC* pDC, int nRow, int nCol, CRect rect);
  126. // add additional protected grid members required of cells
  127. LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
  128. protected:
  129. virtual void OnEndEdit();
  130. virtual void OnMouseEnter();
  131. virtual void OnMouseOver();
  132. virtual void OnMouseLeave();
  133. virtual void OnClick(CPoint PointCellRelative);
  134. virtual void OnClickDown(CPoint PointCellRelative);
  135. virtual void OnRClick(CPoint PointCellRelative);
  136. virtual void OnDblClick(CPoint PointCellRelative);
  137. virtual BOOL OnSetCursor();
  138. public:
  139. void UnMerge();
  140. virtual bool IsShow();
  141. virtual CCellRange GetMergeRange();
  142. virtual bool IsMergeWithOthers();
  143. virtual CCellID GetMergeCellID();
  144. virtual void SetMergeCellID(CCellID cell);
  145. protected:
  146. DWORD m_nState; // Cell state (selected/focus etc)
  147. private:
  148. CCellRange m_MergeRange;
  149. bool m_IsMergeWithOthers;
  150. CCellID m_MergeCellID;
  151. bool m_Hide;
  152. };