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