This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
GridCtrl.h
executable file
·654 lines (555 loc) · 26.2 KB
/
GridCtrl.h
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#if !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
#define AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// GridCtrl.h : header file
//
// MFC Grid Control header file
//
// Written by Chris Maunder ([email protected])
// Copyright (c) 1998.
//
// The code contained in this file is based on the original
// WorldCom Grid control written by Joe Willcoxson,
// E-mail: [email protected]
// URL: http://users.aol.com/chinajoe
//
// 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. If the source code in this file is used in
// any commercial application then a statement along the lines of
// "Portions copyright (c) Chris Maunder, 1998" must be included in
// the startup banner, "About" box or printed documentation. An email
// letting me know that you are using it would be nice as well. That's
// not much to ask considering the amount of work that went into this.
//
// 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.
//
// Expect bugs!
//
// Please use and enjoy. Please let me know of any bugs/mods/improvements
// that you have found/implemented and I will fix/incorporate them into this
// file.
//
/////////////////////////////////////////////////////////////////////////////
//#define GRIDCONTROL_NO_TITLETIPS // Do not use titletips for cells with large data
//#define GRIDCONTROL_NO_DRAGDROP // Do not use OLE drag and drop
//#define GRIDCONTROL_NO_CLIPBOARD // Do not use clipboard routines
#include "CellRange.h"
#include <afxtempl.h>
#ifdef _WIN32_WCE
#define GRIDCONTROL_NO_TITLETIPS // Do not use titletips for cells with large data
#define GRIDCONTROL_NO_DRAGDROP // Do not use OLE drag and drop
#define GRIDCONTROL_NO_CLIPBOARD // Do not use clipboard routines
#define GRIDCONTROL_NO_PRINTING // Do not use printing routines
#ifdef WCE_NO_PRINTING
#define _WIN32_WCE_NO_PRINTING
#endif
#ifdef WCE_NO_CURSOR
#define _WIN32_WCE_NO_CURSOR
#endif
#else
// Use C++ exception handling instead of structured.
#undef TRY
#undef CATCH
#undef END_CATCH
#define TRY try
#define CATCH(ex_class, ex_object) catch(ex_class* ex_object)
#define END_CATCH
#endif // _WIN32_WCE
#ifndef GRIDCONTROL_NO_TITLETIPS
#include "TitleTip.h"
#endif
#ifndef GRIDCONTROL_NO_DRAGDROP
#include "GridDropTarget.h"
#undef GRIDCONTROL_NO_CLIPBOARD // Force clipboard functions on
#endif
#ifndef GRIDCONTROL_NO_CLIPBOARD
#include <afxole.h>
#endif
// Use this as the classname when inserting this control as a custom control
// in the MSVC++ dialog editor
#define GRIDCTRL_CLASSNAME _T("MFCGridCtrl") // Window class name
#define IDC_INPLACE_CONTROL 8 // ID of inplace edit controls
#define IsSHIFTpressed() ( (GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT)*8-1))) != 0 )
#define IsCTRLpressed() ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )
// 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 state; // cell state (focus/hilighted etc)
UINT nFormat; // Format of cell
CString szText; // Text in cell
int iImage; // index of the list view item’s 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
} GV_ITEM;
// Grid line selection
#define GVL_NONE 0
#define GVL_HORZ 1
#define GVL_VERT 2
#define GVL_BOTH 3
// 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)
// Cell states
#define GVIS_FOCUSED 0x0001
#define GVIS_SELECTED 0x0002
#define GVIS_DROPHILITED 0x0004
#define GVIS_READONLY 0x0008
#define GVIS_FIXED 0x0010 // not yet used
#define GVIS_MODIFIED 0x0020
// Cell Searching options
#define GVNI_FOCUSED 0x0001
#define GVNI_SELECTED 0x0002
#define GVNI_DROPHILITED 0x0004
#define GVNI_READONLY 0x0008
#define GVNI_FIXED 0x0010 // not yet used
#define GVNI_MODIFIED 0x0020
#define GVNI_ABOVE LVNI_ABOVE
#define GVNI_BELOW LVNI_BELOW
#define GVNI_TOLEFT LVNI_TOLEFT
#define GVNI_TORIGHT LVNI_TORIGHT
#define GVNI_ALL (LVNI_BELOW|LVNI_TORIGHT|LVNI_TOLEFT)
#define GVNI_AREA (LVNI_BELOW|LVNI_TORIGHT)
// Hit test values (not yet implemented)
#define GVHT_DATA 0x0000
#define GVHT_TOPLEFT 0x0001
#define GVHT_COLHDR 0x0002
#define GVHT_ROWHDR 0x0004
#define GVHT_COLSIZER 0x0008
#define GVHT_ROWSIZER 0x0010
#define GVHT_LEFT 0x0020
#define GVHT_RIGHT 0x0040
#define GVHT_ABOVE 0x0080
#define GVHT_BELOW 0x0100
typedef struct tagNM_GRIDVIEW {
NMHDR hdr;
int iRow;
int iColumn;
} NM_GRIDVIEW;
typedef struct tagGV_DISPINFO {
NMHDR hdr;
GV_ITEM item;
} GV_DISPINFO;
// Messages sent to the grid's parent (More will be added in future)
#define GVN_BEGINDRAG LVN_BEGINDRAG // LVN_FIRST-9
#define GVN_BEGINLABELEDIT LVN_BEGINLABELEDIT // LVN_FIRST-5
#define GVN_BEGINRDRAG LVN_BEGINRDRAG
#define GVN_COLUMNCLICK LVN_COLUMNCLICK
#define GVN_DELETEITEM LVN_DELETEITEM
#define GVN_ENDLABELEDIT LVN_ENDLABELEDIT // LVN_FIRST-6
#define GVN_SELCHANGING LVN_ITEMCHANGING
#define GVN_SELCHANGED LVN_ITEMCHANGED
// 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.
class CGridCell : public CObject
{
public:
CGridCell()
{
state = 0;
nFormat = 0;
szText.Empty();
iImage = -1;
crBkClr = CLR_DEFAULT;
crFgClr = CLR_DEFAULT;
lParam = 0;
}
UINT state; // Cell state (selected/focus etc)
UINT nFormat; // Cell format
CString szText; // Cell text (or binary data if you wish...)
int iImage; // Index of the list view item’s icon
COLORREF crBkClr; // Background colour (or CLR_DEFAULT)
COLORREF crFgClr; // Forground colour (or CLR_DEFAULT)
LOGFONT lfFont; // Cell font
LPARAM lParam; // 32-bit value to associate with item
};
// storage typedef for each row in the grid
typedef CTypedPtrArray<CObArray, CGridCell*> GRID_ROW;
// DDX_GridControl is used where a DDX_Control call is needed. In some strange
// situations the usual DDX_Control does not result in CGridCtrl::SubclassWindow
// or CGridCtrl::PreSubclassWindow being called. Using this version calls
// CGridCtrl::SubclassWindow directly - ensuring that cell metrics are set properly
class CGridCtrl;
void AFXAPI DDX_GridControl(CDataExchange* pDX, int nIDC, CGridCtrl& rControl);
/////////////////////////////////////////////////////////////////////////////
// CGridCtrl window
class CGridCtrl : public CWnd
{
DECLARE_DYNCREATE(CGridCtrl)
// Construction
public:
CGridCtrl(int nRows = 0, int nCols = 0, int nFixedRows = 0, int nFixedCols = 0);
BOOL Create(const RECT& rect, CWnd* parent, UINT nID,
DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
BOOL SubclassWindow(HWND hWnd);
// Attributes
public:
int GetRowCount() const { return m_nRows; }
int GetColumnCount() const { return m_nCols; }
int GetFixedRowCount() const { return m_nFixedRows; }
int GetFixedColumnCount() const { return m_nFixedCols; }
BOOL SetRowCount(int nRows = 10);
BOOL SetColumnCount(int nCols = 10);
BOOL SetFixedRowCount(int nFixedRows = 1);
BOOL SetFixedColumnCount(int nFixedCols = 1);
int GetRowHeight(int nRow) const;
BOOL SetRowHeight(int row, int height);
int GetColumnWidth(int nCol) const;
BOOL SetColumnWidth(int col, int width);
BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p) const;
BOOL GetCellOrigin(const CCellID& cell, LPPOINT p) const;
BOOL GetCellRect(int nRow, int nCol, LPRECT pRect) const;
BOOL GetCellRect(const CCellID& cell, LPRECT pRect) const;
BOOL GetTextRect(const CCellID& cell, LPRECT pRect);
BOOL GetTextRect(int nRow, int nCol, LPRECT pRect);
int GetFixedRowHeight() const;
int GetFixedColumnWidth() const;
long GetVirtualWidth() const;
long GetVirtualHeight() const;
void SetTextColor(COLORREF clr) { m_crTextColour = clr; }
COLORREF GetTextColor() const { return m_crTextColour; }
void SetTextBkColor(COLORREF clr) { m_crTextBkColour = clr; }
COLORREF GetTextBkColor() const { return m_crTextBkColour; }
void SetBkColor(COLORREF clr) { m_crBkColour = clr; }
COLORREF GetBkColor() const { return m_crBkColour; }
void SetFixedTextColor(COLORREF clr) { m_crFixedTextColour = clr; }
COLORREF GetFixedTextColor() const { return m_crFixedTextColour; }
void SetFixedBkColor(COLORREF clr) { m_crFixedBkColour = clr; }
COLORREF GetFixedBkColor() const { return m_crFixedBkColour; }
void SetGridColor(COLORREF clr) { m_crGridColour = clr; }
COLORREF GetGridColor() const { return m_crGridColour; }
int GetSelectedCount() const { return m_SelectedCellMap.GetCount(); }
CCellID GetFocusCell() const { return m_idCurrentCell; }
void SetImageList(CImageList* pList) { m_pImageList = pList; }
CImageList* GetImageList() const { return m_pImageList; }
void SetGridLines(int nWhichLines = GVL_BOTH) { m_nGridLines = nWhichLines;
if (::IsWindow(GetSafeHwnd())) Invalidate(); }
int GetGridLines() const { return m_nGridLines; }
void SetEditable(BOOL bEditable = TRUE) { m_bEditable = bEditable; }
BOOL IsEditable() const { return m_bEditable; }
void SetListMode(BOOL bEnableListMode = TRUE) { m_bListMode = bEnableListMode; }
BOOL GetListMode() const { return m_bListMode; }
void SetSingleRowSelection(BOOL bSing = TRUE) { m_bSingleRowSelection = bSing; }
BOOL GetSingleRowSelection() { return m_bSingleRowSelection; }
void EnableSelection(BOOL bEnable = TRUE) { ResetSelectedRange(); m_bEnableSelection = bEnable; ResetSelectedRange(); }
BOOL IsSelectable() const { return m_bEnableSelection; }
void EnableDragAndDrop(BOOL bAllow = TRUE) { m_bAllowDragAndDrop = bAllow; }
BOOL GetDragAndDrop() const { return m_bAllowDragAndDrop; }
void SetRowResize(BOOL bResize = TRUE) { m_bAllowRowResize = bResize; }
BOOL GetRowResize() const { return m_bAllowRowResize; }
void SetColumnResize(BOOL bResize = TRUE) { m_bAllowColumnResize = bResize; }
BOOL GetColumnResize() const { return m_bAllowColumnResize; }
void SetHeaderSort(BOOL bSortOnClick = TRUE) { m_bSortOnClick = bSortOnClick; }
BOOL GetHeaderSort() const { return m_bSortOnClick; }
void SetHandleTabKey(BOOL bHandleTab = TRUE) { m_bHandleTabKey = bHandleTab; }
BOOL GetHandleTabKey() const { return m_bHandleTabKey; }
void SetDoubleBuffering(BOOL bBuffer = TRUE) { m_bDoubleBuffer = bBuffer; }
BOOL GetDoubleBuffering() const { return m_bDoubleBuffer; }
void EnableTitleTips(BOOL bEnable = TRUE) { m_bTitleTips = bEnable; }
BOOL GetTitleTips() { return m_bTitleTips; }
void SetModified(BOOL bModified = TRUE, int nRow = -1, int nCol = -1);
BOOL GetModified(int nRow = -1, int nCol = -1);
BOOL IsCellFixed(int nRow, int nCol);
BOOL SetItem(const GV_ITEM* pItem);
BOOL GetItem(GV_ITEM* pItem);
BOOL SetItemText(int nRow, int nCol, LPCTSTR str);
virtual CString GetItemText(int nRow, int nCol);
BOOL SetItemData(int nRow, int nCol, LPARAM lParam);
LPARAM GetItemData(int nRow, int nCol) const;
BOOL SetItemImage(int nRow, int nCol, int iImage);
int GetItemImage(int nRow, int nCol) const;
BOOL SetItemState(int nRow, int nCol, UINT state);
UINT GetItemState(int nRow, int nCol) const;
BOOL SetItemFormat(int nRow, int nCol, UINT nFormat);
UINT GetItemFormat(int nRow, int nCol) const;
BOOL SetItemBkColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
COLORREF GetItemBkColour(int nRow, int nCol) const;
BOOL SetItemFgColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
COLORREF GetItemFgColour(int nRow, int nCol) const;
BOOL SetItemFont(int nRow, int nCol, LOGFONT* lf);
LOGFONT* GetItemFont(int nRow, int nCol);
// Operations
public:
int InsertColumn(LPCTSTR strHeading, UINT nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE,
int nColumn = -1);
int InsertRow(LPCTSTR strHeading, int nRow = -1);
BOOL DeleteColumn(int nColumn);
BOOL DeleteRow(int nRow);
BOOL DeleteNonFixedRows();
BOOL DeleteAllItems();
BOOL AutoSizeRow(int nRow);
BOOL AutoSizeColumn(int nCol);
void AutoSizeRows();
void AutoSizeColumns();
void AutoSize();
void ExpandColumnsToFit();
void ExpandRowsToFit();
void ExpandToFit();
CSize GetTextExtent(LPCTSTR str, BOOL bUseSelectedFont = TRUE);
void EnsureVisible(CCellID &cell) { EnsureVisible(cell.row, cell.col); }
void EnsureVisible(int nRow, int nCol);
BOOL IsCellVisible(int nRow, int nCol) const;
BOOL IsCellVisible(CCellID cell) const;
BOOL IsCellEditable(int nRow, int nCol) const;
BOOL IsCellEditable(CCellID &cell) const;
// SetRedraw stops/starts redraws on things like changing the # rows/columns
// and autosizing, but not for user-intervention such as resizes
void SetRedraw(BOOL bAllowDraw, BOOL bResetScrollBars = FALSE);
BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL);
BOOL RedrawRow(int row);
BOOL RedrawColumn(int col);
#if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
void Print();
#endif
#ifndef _WIN32_WCE
BOOL Save(LPCTSTR filename);
BOOL Load(LPCTSTR filename);
#endif
CCellRange GetCellRange() const;
CCellRange GetSelectedCellRange() const;
void SetSelectedRange(const CCellRange& Range, BOOL bForceRepaint = FALSE);
void SetSelectedRange(int nMinRow, int nMinCol, int nMaxRow, int nMaxCol,
BOOL bForceRepaint = FALSE);
BOOL IsValid(int nRow, int nCol) const;
BOOL IsValid(const CCellID& cell) const;
BOOL IsValid(const CCellRange& range) const;
#ifndef GRIDCONTROL_NO_CLIPBOARD
// Clipboard and cut n' paste operations
virtual void CutSelectedText();
virtual COleDataSource* CopyTextFromGrid();
virtual BOOL PasteTextToGrid(CCellID cell, COleDataObject* pDataObject);
#endif
#ifndef GRIDCONTROL_NO_DRAGDROP
void OnBeginDrag();
DROPEFFECT OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
DROPEFFECT OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
void OnDragLeave();
BOOL OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
#endif
#ifndef GRIDCONTROL_NO_CLIPBOARD
virtual void OnEditCut();
virtual void OnEditCopy();
virtual void OnEditPaste();
#endif
virtual void OnEditSelectAll();
CCellID GetNextItem(CCellID& cell, int nFlags) const;
BOOL SortTextItems(int nCol, BOOL bAscending);
BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data = 0);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGridCtrl)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
#if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
public:
virtual void OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo);
virtual void OnPrint(CDC *pDC, CPrintInfo *pInfo);
virtual void OnEndPrinting(CDC *pDC, CPrintInfo *pInfo);
#endif
// Implementation
public:
virtual ~CGridCtrl();
protected:
BOOL RegisterWindowClass();
LRESULT SendMessageToParent(int nRow, int nCol, int nMessage);
BOOL InvalidateCellRect(const CCellID& cell);
BOOL InvalidateCellRect(const CCellRange& cellRange);
void EraseBkgnd(CDC* pDC);
BOOL GetCellRangeRect(const CCellRange& cellRange, LPRECT lpRect) const;
CGridCell* GetCell(int nRow, int nCol) const;
BOOL SetCell(int nRow, int nCol, CGridCell* pCell);
int SetMouseMode(int nMode) { int nOldMode = m_MouseMode; m_MouseMode = nMode; return nOldMode; }
int GetMouseMode() const { return m_MouseMode; }
BOOL MouseOverRowResizeArea(CPoint& point) const;
BOOL MouseOverColumnResizeArea(CPoint& point) const;
CCellID GetCellFromPt(CPoint point, BOOL bAllowFixedCellCheck = TRUE) const;
CCellID GetTopleftNonFixedCell() const;
CCellRange GetUnobstructedNonFixedCellRange() const;
CCellRange GetVisibleNonFixedCellRange(LPRECT pRect = NULL) const;
CCellID SetFocusCell(CCellID cell);
CCellID SetFocusCell(int nRow, int nCol);
void ResetSelectedRange();
void ResetScrollBars();
int GetScrollPos32(int nBar, BOOL bGetTrackPos = FALSE);
BOOL SetScrollPos32(int nBar, int nPos, BOOL bRedraw = TRUE);
BOOL SortTextItems(int nCol, BOOL bAscending, int low, int high);
BOOL SortItems(PFNLVCOMPARE pfnCompare, int nCol, BOOL bAscending, LPARAM data,
int low, int high);
// Overrrides
protected:
// Printing
#if !defined(_WIN32_WCE_NO_PRINTING) && !defined(GRIDCONTROL_NO_PRINTING)
virtual void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
virtual void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
#endif
#ifndef GRIDCONTROL_NO_DRAGDROP
// Drag n' drop
virtual CImageList* CreateDragImage(CPoint *pHotSpot); // no longer necessary
#endif
// Mouse Clicks
virtual void OnFixedColumnClick(CCellID& cell);
virtual void OnFixedRowClick(CCellID& cell);
// Editing
virtual CSize GetCellExtent(int nRow, int nCol, CDC* pDC);
virtual void OnEndEditCell(int nRow, int nCol, CString str);
virtual void OnEditCell(int nRow, int nCol, UINT nChar);
virtual void CreateInPlaceEditControl(CRect& rect, DWORD dwStyle, UINT nID,
int nRow, int nCol,
LPCTSTR szText, int nChar);
// Drawing
virtual void OnDraw(CDC* pDC);
virtual BOOL DrawFixedCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
virtual BOOL DrawCell(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBk=FALSE);
// GridCell Creation and Cleanup
virtual CGridCell* CreateCell(int nRow, int nCol);
virtual void EmptyCell(CGridCell* pCell, int nRow, int nCol);
// Attributes
protected:
// General attributes
COLORREF m_crTextColour, m_crTextBkColour, m_crBkColour, // Grid colours
m_crFixedTextColour, m_crFixedBkColour, m_crGridColour;
COLORREF m_crWindowText, m_crWindowColour, m_cr3DFace, // System colours
m_crShadow;
int m_nGridLines;
BOOL m_bEditable;
BOOL m_bModified;
BOOL m_bAllowDragAndDrop;
BOOL m_bListMode;
BOOL m_bSingleRowSelection;
BOOL m_bAllowDraw;
BOOL m_bEnableSelection;
BOOL m_bSortOnClick;
BOOL m_bHandleTabKey;
BOOL m_bDoubleBuffer;
BOOL m_bTitleTips;
// Cell size details
int m_nRows, m_nFixedRows, m_nCols, m_nFixedCols;
CUIntArray m_arRowHeights, m_arColWidths;
int m_nMargin;
public:
int m_nDefCellWidth, m_nDefCellHeight;
protected:
int m_nVScrollMax, m_nHScrollMax;
// Fonts and images
LOGFONT m_Logfont;
CFont m_PrinterFont, // for the printer
m_Font; // for the grid
CImageList* m_pImageList;
// Cell data
CTypedPtrArray<CObArray, GRID_ROW*> m_RowData;
// Mouse operations such as cell selection
int m_MouseMode;
CPoint m_LeftClickDownPoint, m_LastMousePoint;
CCellID m_LeftClickDownCell, m_SelectionStartCell;
CCellID m_idCurrentCell;
int m_nTimerID;
int m_nTimerInterval;
int m_nResizeCaptureRange;
BOOL m_bAllowRowResize, m_bAllowColumnResize;
int m_nRowsPerWheelNotch;
CMap<DWORD,DWORD, CCellID, CCellID&> m_SelectedCellMap, m_PrevSelectedCellMap;
#ifndef GRIDCONTROL_NO_TITLETIPS
CTitleTip m_TitleTip; // Title tips for cells
#endif
// Drag and drop
BOOL m_bMustUninitOLE; // Do we need to uninitialise OLE?
CCellID m_LastDragOverCell;
#ifndef GRIDCONTROL_NO_DRAGDROP
CGridDropTarget m_DropTarget; // OLE Drop target for the grid
#endif
// Printing information
CSize m_CharSize;
int m_nPageHeight;
CSize m_LogicalPageSize, // Page size in gridctrl units.
m_PaperSize; // Page size in device units.
// sorting
int m_bAscending;
int m_SortColumn;
protected:
void SelectAllCells();
void SelectColumns(CCellID currentCell);
void SelectRows(CCellID currentCell);
void SelectCells(CCellID currentCell);
void OnSelecting(const CCellID& currentCell);
// Generated message map functions
//{{AFX_MSG(CGridCtrl)
afx_msg void OnPaint();
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg UINT OnGetDlgCode();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnSysColorChange();
afx_msg void OnCaptureChanged(CWnd *pWnd);
afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI);
//}}AFX_MSG
#if (_MFC_VER >= 0x0421) || (_WIN32_WCE >= 210)
afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection);
#endif
#if !defined(_WIN32_WCE) && (_MFC_VER >= 0x0421)
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
#endif
afx_msg LRESULT OnSetFont(WPARAM hFont, LPARAM lParam);
afx_msg LRESULT OnGetFont(WPARAM hFont, LPARAM lParam);
afx_msg void OnEndInPlaceEdit(NMHDR* pNMHDR, LRESULT* pResult);
DECLARE_MESSAGE_MAP()
enum eMouseModes { MOUSE_NOTHING, MOUSE_SELECT_ALL, MOUSE_SELECT_COL, MOUSE_SELECT_ROW,
MOUSE_SELECT_CELLS, MOUSE_SCROLLING_CELLS,
MOUSE_OVER_ROW_DIVIDE, MOUSE_SIZING_ROW,
MOUSE_OVER_COL_DIVIDE, MOUSE_SIZING_COL,
MOUSE_PREPARE_EDIT,
#ifndef GRIDCONTROL_NO_DRAGDROP
MOUSE_PREPARE_DRAG, MOUSE_DRAGGING
#endif
};
};
inline CGridCell* CGridCtrl::GetCell(int nRow, int nCol) const
{
if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return NULL;
GRID_ROW* pRow = m_RowData[nRow];
if (!pRow) return NULL;
return pRow->GetAt(nCol);
}
inline BOOL CGridCtrl::SetCell(int nRow, int nCol, CGridCell* pCell)
{
if (nRow < 0 || nRow >= m_nRows || nCol < 0 || nCol >= m_nCols) return FALSE;
GRID_ROW* pRow = m_RowData[nRow];
if (!pRow) return FALSE;
pRow->SetAt(nCol, pCell);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)