00001 00002 // GridCell.h : header file 00003 // 00004 // MFC Grid Control - Grid cell class header file 00005 // 00006 // Written by Chris Maunder <cmaunder@mail.com> 00007 // Copyright (c) 1998-2002. All Rights Reserved. 00008 // 00009 // This code may be used in compiled form in any way you desire. This 00010 // file may be redistributed unmodified by any means PROVIDING it is 00011 // not sold for profit without the authors written consent, and 00012 // providing that this notice and the authors name and all copyright 00013 // notices remains intact. 00014 // 00015 // An email letting me know how you are using it would be nice as well. 00016 // 00017 // This file is provided "as is" with no expressed or implied warranty. 00018 // The author accepts no liability for any damage/loss of business that 00019 // this product may cause. 00020 // 00021 // For use with CGridCtrl v2.20+ 00022 // 00024 00025 #if !defined(AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_) 00026 #define AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_ 00027 00028 #if _MSC_VER >= 1000 00029 #pragma once 00030 #endif // _MSC_VER >= 1000 00031 00032 class CGridCtrl; 00033 #include "GridCellBase.h" 00034 00035 // Each cell contains one of these. Fields "row" and "column" are not stored since we 00036 // will usually have acces to them in other ways, and they are an extra 8 bytes per 00037 // cell that is probably unnecessary. 00038 00039 class CGridCell : public CGridCellBase 00040 { 00041 friend class CGridCtrl; 00042 DECLARE_DYNCREATE(CGridCell) 00043 00044 // Construction/Destruction 00045 public: 00046 CGridCell(); 00047 virtual ~CGridCell(); 00048 00049 // Attributes 00050 public: 00051 void operator=(const CGridCell& cell); 00052 00053 virtual void SetText(LPCTSTR szText) { m_strText = szText; } 00054 virtual void SetImage(int nImage) { m_nImage = nImage; } 00055 virtual void SetData(LPARAM lParam) { m_lParam = lParam; } 00056 virtual void SetGrid(CGridCtrl* pGrid) { m_pGrid = pGrid; } 00057 // virtual void SetState(const DWORD nState); - use base class version 00058 virtual void SetFormat(DWORD nFormat) { m_nFormat = nFormat; } 00059 virtual void SetTextClr(COLORREF clr) { m_crFgClr = clr; } 00060 virtual void SetBackClr(COLORREF clr) { m_crBkClr = clr; } 00061 virtual void SetFont(const LOGFONT* plf); 00062 virtual void SetMargin(UINT nMargin) { m_nMargin = nMargin; } 00063 virtual CWnd* GetEditWnd() const { return m_pEditWnd; } 00064 virtual void SetCoords(int /*nRow*/, int /*nCol*/) {} // don't need to know the row and 00065 // column for base implementation 00066 00067 virtual LPCTSTR GetText() const { return (m_strText.IsEmpty())? _T("") : LPCTSTR(m_strText); } 00068 virtual int GetImage() const { return m_nImage; } 00069 virtual LPARAM GetData() const { return m_lParam; } 00070 virtual CGridCtrl* GetGrid() const { return m_pGrid; } 00071 // virtual DWORD GetState() const - use base class 00072 virtual DWORD GetFormat() const; 00073 virtual COLORREF GetTextClr() const { return m_crFgClr; } // TODO: change to use default cell 00074 virtual COLORREF GetBackClr() const { return m_crBkClr; } 00075 virtual LOGFONT* GetFont() const; 00076 virtual CFont* GetFontObject() const; 00077 virtual UINT GetMargin() const; 00078 00079 virtual BOOL IsEditing() const { return m_bEditing; } 00080 virtual BOOL IsDefaultFont() const { return (m_plfFont == NULL); } 00081 virtual void Reset(); 00082 00083 // editing cells 00084 public: 00085 virtual BOOL Edit(int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar); 00086 virtual void EndEdit(); 00087 protected: 00088 virtual void OnEndEdit(); 00089 00090 protected: 00091 CString m_strText; // Cell text (or binary data if you wish...) 00092 LPARAM m_lParam; // 32-bit value to associate with item 00093 int m_nImage; // Index of the list view item’s icon 00094 DWORD m_nFormat; 00095 COLORREF m_crFgClr; 00096 COLORREF m_crBkClr; 00097 LOGFONT* m_plfFont; 00098 UINT m_nMargin; 00099 00100 BOOL m_bEditing; // Cell being edited? 00101 00102 CGridCtrl* m_pGrid; // Parent grid control 00103 CWnd* m_pEditWnd; 00104 }; 00105 00106 // This class is for storing grid default values. It's a little heavy weight, so 00107 // don't use it in bulk 00108 class CGridDefaultCell : public CGridCell 00109 { 00110 DECLARE_DYNCREATE(CGridDefaultCell) 00111 00112 // Construction/Destruction 00113 public: 00114 CGridDefaultCell(); 00115 virtual ~CGridDefaultCell(); 00116 00117 public: 00118 virtual DWORD GetStyle() const { return m_dwStyle; } 00119 virtual void SetStyle(DWORD dwStyle) { m_dwStyle = dwStyle; } 00120 virtual int GetWidth() const { return m_Size.cx; } 00121 virtual int GetHeight() const { return m_Size.cy; } 00122 virtual void SetWidth(int nWidth) { m_Size.cx = nWidth; } 00123 virtual void SetHeight(int nHeight) { m_Size.cy = nHeight; } 00124 00125 // Disable these properties 00126 virtual void SetData(LPARAM /*lParam*/) { ASSERT(FALSE); } 00127 virtual void SetState(DWORD /*nState*/) { ASSERT(FALSE); } 00128 virtual DWORD GetState() const { return CGridCell::GetState()|GVIS_READONLY; } 00129 virtual void SetCoords( int /*row*/, int /*col*/) { ASSERT(FALSE); } 00130 virtual void SetFont(const LOGFONT* /*plf*/); 00131 virtual LOGFONT* GetFont() const; 00132 virtual CFont* GetFontObject() const; 00133 00134 protected: 00135 CSize m_Size; // Default Size 00136 CFont m_Font; // Cached font 00137 DWORD m_dwStyle; // Cell Style - unused 00138 }; 00139 00140 //{{AFX_INSERT_LOCATION}} 00141 // Microsoft Developer Studio will insert additional declarations immediately before the previous line. 00142 00143 #endif // !defined(AFX_GRIDCELL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)