Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

GridCellBase.h

00001 
00002 // GridCellBase.h : header file
00003 //
00004 // MFC Grid Control - Grid cell base 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.22+
00022 //
00024 
00025 #if !defined(AFX_GRIDCELLBASE_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
00026 #define AFX_GRIDCELLBASE_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 
00034 // Cell states
00035 #define GVIS_FOCUSED            0x0001
00036 #define GVIS_SELECTED           0x0002
00037 #define GVIS_DROPHILITED        0x0004
00038 #define GVIS_READONLY           0x0008
00039 #define GVIS_FIXED              0x0010
00040 #define GVIS_FIXEDROW           0x0020
00041 #define GVIS_FIXEDCOL           0x0040
00042 #define GVIS_MODIFIED           0x0080
00043 
00044 // Cell data mask
00045 #define GVIF_TEXT               LVIF_TEXT
00046 #define GVIF_IMAGE              LVIF_IMAGE
00047 #define GVIF_PARAM              LVIF_PARAM
00048 #define GVIF_STATE              LVIF_STATE
00049 #define GVIF_BKCLR              (GVIF_STATE<<1)
00050 #define GVIF_FGCLR              (GVIF_STATE<<2)
00051 #define GVIF_FORMAT             (GVIF_STATE<<3)
00052 #define GVIF_FONT               (GVIF_STATE<<4)
00053 #define GVIF_MARGIN             (GVIF_STATE<<5)
00054 #define GVIF_ALL                (GVIF_TEXT|GVIF_IMAGE|GVIF_PARAM|GVIF_STATE|GVIF_BKCLR|GVIF_FGCLR| \
00055                                  GVIF_FORMAT|GVIF_FONT|GVIF_MARGIN)
00056 
00057 // Used for Get/SetItem calls.
00058 typedef struct _GV_ITEM {
00059     int      row,col;     // Row and Column of item
00060     UINT     mask;        // Mask for use in getting/setting cell data
00061     UINT     nState;      // cell state (focus/hilighted etc)
00062     DWORD    nFormat;     // Format of cell
00063     int      iImage;      // index of the list view item’s icon
00064     COLORREF crBkClr;     // Background colour (or CLR_DEFAULT)
00065     COLORREF crFgClr;     // Forground colour (or CLR_DEFAULT)
00066     LPARAM   lParam;      // 32-bit value to associate with item
00067     LOGFONT  lfFont;      // Cell font
00068     UINT     nMargin;     // Internal cell margin
00069     CString  strText;     // Text in cell
00070 } GV_ITEM;
00071 
00072 
00073 // Each cell contains one of these. Fields "row" and "column" are not stored since we
00074 // will usually have acces to them in other ways, and they are an extra 8 bytes per
00075 // cell that is probably unnecessary.
00076 
00077 class CGridCellBase : public CObject
00078 {
00079     friend class CGridCtrl;
00080     DECLARE_DYNAMIC(CGridCellBase)
00081 
00082 // Construction/Destruction
00083 public:
00084     CGridCellBase();
00085     virtual ~CGridCellBase();
00086 
00087 // Attributes
00088 public:
00089     virtual void SetText(LPCTSTR /* szText */)              = 0 ;
00090     virtual void SetImage(int /* nImage */)                 = 0 ;
00091     virtual void SetData(LPARAM /* lParam */)               = 0 ;
00092     virtual void SetState(DWORD nState)                     { m_nState = nState; }
00093     virtual void SetFormat(DWORD /* nFormat */)             = 0 ;
00094     virtual void SetTextClr(COLORREF /* clr */)             = 0 ;
00095     virtual void SetBackClr(COLORREF /* clr */)             = 0 ;
00096     virtual void SetFont(const LOGFONT* /* plf */)          = 0 ;
00097     virtual void SetMargin( UINT /* nMargin */)             = 0 ;
00098     virtual void SetGrid(CGridCtrl* /* pGrid */)            = 0 ;
00099     virtual void SetCoords( int /* nRow */, int /* nCol */) = 0 ;
00100 
00101     virtual LPCTSTR    GetText()       const                = 0 ;
00102     virtual LPCTSTR    GetTipText()    const                { return GetText(); } // may override TitleTip return
00103     virtual int        GetImage()      const                = 0 ;
00104     virtual LPARAM     GetData()       const                = 0 ;
00105     virtual DWORD      GetState()      const                { return m_nState;  }
00106     virtual DWORD      GetFormat()     const                = 0 ;
00107     virtual COLORREF   GetTextClr()    const                = 0 ;
00108     virtual COLORREF   GetBackClr()    const                = 0 ;
00109     virtual LOGFONT  * GetFont()       const                = 0 ;
00110     virtual CFont    * GetFontObject() const                = 0 ;
00111     virtual CGridCtrl* GetGrid()       const                = 0 ;
00112     virtual CWnd     * GetEditWnd()    const                = 0 ;
00113     virtual UINT       GetMargin()     const                = 0 ;
00114 
00115     virtual CGridCellBase* GetDefaultCell() const;
00116 
00117     virtual BOOL IsDefaultFont()       const                = 0 ;
00118     virtual BOOL IsEditing()           const                = 0 ;
00119     virtual BOOL IsFocused()           const                { return (m_nState & GVIS_FOCUSED);  }
00120     virtual BOOL IsFixed()             const                { return (m_nState & GVIS_FIXED);    }
00121     virtual BOOL IsFixedCol()          const                { return (m_nState & GVIS_FIXEDCOL); }
00122     virtual BOOL IsFixedRow()          const                { return (m_nState & GVIS_FIXEDROW); }
00123     virtual BOOL IsSelected()          const                { return (m_nState & GVIS_SELECTED); }
00124     virtual BOOL IsReadOnly()          const                { return (m_nState & GVIS_READONLY); }
00125     virtual BOOL IsModified()          const                { return (m_nState & GVIS_MODIFIED); }
00126     virtual BOOL IsDropHighlighted()   const                { return (m_nState & GVIS_DROPHILITED); }
00127 
00128 // Operators
00129 public:
00130     virtual void operator=(const CGridCellBase& cell);
00131 
00132 // Operations
00133 public:
00134     virtual void Reset();
00135 
00136     virtual BOOL Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd = TRUE);
00137     virtual BOOL GetTextRect( LPRECT pRect);    // i/o:  i=dims of cell rect; o=dims of text rect
00138     virtual BOOL GetTipTextRect( LPRECT pRect) { return GetTextRect( pRect); }  // may override for btns, etc.
00139     virtual CSize GetTextExtent(LPCTSTR str, CDC* pDC = NULL);
00140     virtual CSize GetCellExtent(CDC* pDC);
00141 
00142     // Editing
00143     virtual BOOL Edit( int /* nRow */, int /* nCol */, CRect /* rect */, CPoint /* point */, 
00144                        UINT /* nID */, UINT /* nChar */) { ASSERT( FALSE); return FALSE;}
00145         virtual BOOL ValidateEdit(LPCTSTR str);
00146     virtual void EndEdit() {}
00147 
00148     // EFW - Added to print cells properly
00149     virtual BOOL PrintCell(CDC* pDC, int nRow, int nCol, CRect rect);
00150 
00151     // add additional protected grid members required of cells
00152     LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
00153 
00154 protected:
00155     virtual void OnEndEdit();
00156     virtual void OnMouseEnter();
00157     virtual void OnMouseOver();
00158     virtual void OnMouseLeave();
00159     virtual void OnClick( CPoint PointCellRelative);
00160     virtual void OnClickDown( CPoint PointCellRelative);
00161     virtual void OnRClick( CPoint PointCellRelative);
00162     virtual void OnDblClick( CPoint PointCellRelative);
00163     virtual BOOL OnSetCursor();
00164 
00165 protected:
00166     DWORD    m_nState;      // Cell state (selected/focus etc)
00167 };
00168 
00169 //{{AFX_INSERT_LOCATION}}
00170 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
00171 
00172 #endif // !defined(AFX_GRIDCELLBASE_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)

Generated on Tue Feb 17 02:03:03 2004 for harlem by doxygen 1.3.6