GridCell.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /////////////////////////////////////////////////////////////////////////////
  2. // GridCell.h : header file
  3. //
  4. // MFC Grid Control - Grid cell 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.20+
  22. //
  23. //////////////////////////////////////////////////////////////////////
  24. #if !defined(AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
  25. #define AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
  26. #if _MSC_VER >= 1000
  27. #pragma once
  28. #endif // _MSC_VER >= 1000
  29. class CGridCtrl;
  30. #include "GridCellBase.h"
  31. // Each cell contains one of these. Fields "row" and "column" are not stored since we
  32. // will usually have acces to them in other ways, and they are an extra 8 bytes per
  33. // cell that is probably unnecessary.
  34. class CGridCell : public CGridCellBase
  35. {
  36. friend class CGridCtrl;
  37. DECLARE_DYNCREATE(CGridCell)
  38. // Construction/Destruction
  39. public:
  40. CGridCell();
  41. virtual ~CGridCell();
  42. // Attributes
  43. public:
  44. void operator=(const CGridCell& cell);
  45. virtual void SetText(LPCTSTR szText) { m_strText = szText; }
  46. virtual void SetImage(int nImage) { m_nImage = nImage; }
  47. virtual void SetData(LPARAM lParam) { m_lParam = lParam; }
  48. virtual void SetGrid(CGridCtrl* pGrid) { m_pGrid = pGrid; }
  49. // virtual void SetState(const DWORD nState); - use base class version
  50. virtual void SetFormat(DWORD nFormat) { m_nFormat = nFormat; }
  51. virtual void SetTextClr(COLORREF clr) { m_crFgClr = clr; }
  52. virtual void SetBackClr(COLORREF clr) { m_crBkClr = clr; }
  53. virtual void SetFont(const LOGFONT* plf);
  54. virtual void SetMargin(UINT nMargin) { m_nMargin = nMargin; }
  55. virtual CWnd* GetEditWnd() const { return m_pEditWnd; }
  56. virtual void SetCoords(int /* nRow */, int /* nCol */) {} // don't need to know the row and
  57. // column for base implementation
  58. virtual LPCTSTR GetText() const { return (m_strText.IsEmpty()) ? _T("") : m_strText; }
  59. virtual int GetImage() const { return m_nImage; }
  60. virtual LPARAM GetData() const { return m_lParam; }
  61. virtual CGridCtrl* GetGrid() const { return m_pGrid; }
  62. // virtual DWORD GetState() const - use base class
  63. virtual DWORD GetFormat() const;
  64. virtual COLORREF GetTextClr() const { return m_crFgClr; } // TODO: change to use default cell
  65. virtual COLORREF GetBackClr() const { return m_crBkClr; }
  66. virtual LOGFONT* GetFont() const;
  67. virtual CFont* GetFontObject() const;
  68. virtual UINT GetMargin() const;
  69. virtual BOOL IsEditing() const { return m_bEditing; }
  70. virtual BOOL IsDefaultFont() const { return (m_plfFont == NULL); }
  71. virtual void Reset();
  72. // editing cells
  73. public:
  74. virtual BOOL Edit(int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar);
  75. virtual void EndEdit();
  76. protected:
  77. virtual void OnEndEdit();
  78. protected:
  79. CString m_strText; // Cell text (or binary data if you wish...)
  80. LPARAM m_lParam; // 32-bit value to associate with item
  81. int m_nImage; // Index of the list view item’s icon
  82. DWORD m_nFormat;
  83. COLORREF m_crFgClr;
  84. COLORREF m_crBkClr;
  85. LOGFONT* m_plfFont;
  86. UINT m_nMargin;
  87. BOOL m_bEditing; // Cell being edited?
  88. CGridCtrl* m_pGrid; // Parent grid control
  89. CWnd* m_pEditWnd;
  90. };
  91. // This class is for storing grid default values. It's a little heavy weight, so
  92. // don't use it in bulk
  93. class CGridDefaultCell : public CGridCell
  94. {
  95. DECLARE_DYNCREATE(CGridDefaultCell)
  96. // Construction/Destruction
  97. public:
  98. CGridDefaultCell();
  99. virtual ~CGridDefaultCell();
  100. public:
  101. virtual DWORD GetStyle() const { return m_dwStyle; }
  102. virtual void SetStyle(DWORD dwStyle) { m_dwStyle = dwStyle; }
  103. virtual int GetWidth() const { return m_Size.cx; }
  104. virtual int GetHeight() const { return m_Size.cy; }
  105. virtual void SetWidth(int nWidth) { m_Size.cx = nWidth; }
  106. virtual void SetHeight(int nHeight) { m_Size.cy = nHeight; }
  107. // Disable these properties
  108. virtual void SetData(LPARAM /*lParam*/) { ASSERT(FALSE); }
  109. virtual void SetState(DWORD /*nState*/) { ASSERT(FALSE); }
  110. virtual DWORD GetState() const { return CGridCell::GetState() | GVIS_READONLY; }
  111. virtual void SetCoords(int /*row*/, int /*col*/) { ASSERT(FALSE); }
  112. virtual void SetFont(const LOGFONT* /*plf*/);
  113. virtual LOGFONT* GetFont() const;
  114. virtual CFont* GetFontObject() const;
  115. protected:
  116. CSize m_Size; // Default Size
  117. CFont m_Font; // Cached font
  118. DWORD m_dwStyle; // Cell Style - unused
  119. };
  120. //{{AFX_INSERT_LOCATION}}
  121. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  122. #endif // !defined(AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)