]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/grid.h
Allow building in unicode mode with just "make -f makefile.g95 UNICODE=1"
[wxWidgets.git] / include / wx / generic / grid.h
CommitLineData
f85afd4e 1/////////////////////////////////////////////////////////////////////////////
43947979 2// Name: wx/generic/grid.h
f85afd4e
MB
3// Purpose: wxGrid and related classes
4// Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5// Modified by:
6// Created: 1/08/1999
7// RCS-ID: $Id$
8// Copyright: (c) Michael Bedward
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
f85afd4e
MB
12#include "wx/defs.h"
13
14#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
30bc4a8f 15#include "wx/generic/gridg.h"
f85afd4e
MB
16#else
17
18#ifndef __WXGRID_H__
19#define __WXGRID_H__
20
af49c4b8 21#if defined(__GNUG__) && !defined(__APPLE__)
f85afd4e
MB
22#pragma interface "grid.h"
23#endif
24
43947979 25#include "wx/hash.h"
f85afd4e 26#include "wx/panel.h"
2d66e025 27#include "wx/scrolwin.h"
f85afd4e
MB
28#include "wx/string.h"
29#include "wx/scrolbar.h"
30#include "wx/event.h"
f85afd4e
MB
31#include "wx/combobox.h"
32#include "wx/dynarray.h"
025562fe 33#include "wx/timer.h"
afbd598c 34#include "wx/clntdata.h"
f85afd4e 35
816be743
VZ
36// ----------------------------------------------------------------------------
37// constants
38// ----------------------------------------------------------------------------
39
f85afd4e
MB
40// Default parameters for wxGrid
41//
42#define WXGRID_DEFAULT_NUMBER_ROWS 10
43#define WXGRID_DEFAULT_NUMBER_COLS 10
44#ifdef __WXMSW__
45#define WXGRID_DEFAULT_ROW_HEIGHT 25
46#else
47#define WXGRID_DEFAULT_ROW_HEIGHT 30
48#endif // __WXMSW__
49#define WXGRID_DEFAULT_COL_WIDTH 80
50#define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
51#define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
f1567cdd 52#define WXGRID_LABEL_EDGE_ZONE 2
f85afd4e
MB
53#define WXGRID_MIN_ROW_HEIGHT 15
54#define WXGRID_MIN_COL_WIDTH 15
55#define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
f85afd4e 56
816be743
VZ
57// type names for grid table values
58#define wxGRID_VALUE_STRING _T("string")
59#define wxGRID_VALUE_BOOL _T("bool")
60#define wxGRID_VALUE_NUMBER _T("long")
61#define wxGRID_VALUE_FLOAT _T("double")
c4608a8a 62#define wxGRID_VALUE_CHOICE _T("choice")
816be743
VZ
63
64#define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
65#define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
66
b99be8fb
VZ
67// ----------------------------------------------------------------------------
68// forward declarations
69// ----------------------------------------------------------------------------
70
ab79958a
VZ
71class WXDLLEXPORT wxGrid;
72class WXDLLEXPORT wxGridCellAttr;
b99be8fb 73class WXDLLEXPORT wxGridCellAttrProviderData;
b99be8fb
VZ
74class WXDLLEXPORT wxGridColLabelWindow;
75class WXDLLEXPORT wxGridCornerLabelWindow;
ab79958a
VZ
76class WXDLLEXPORT wxGridRowLabelWindow;
77class WXDLLEXPORT wxGridTableBase;
b99be8fb 78class WXDLLEXPORT wxGridWindow;
f2d76237 79class WXDLLEXPORT wxGridTypeRegistry;
b5808881 80class WXDLLEXPORT wxGridSelection;
ab79958a 81
508011ce 82class WXDLLEXPORT wxCheckBox;
4ee5fc9c 83class WXDLLEXPORT wxComboBox;
508011ce 84class WXDLLEXPORT wxTextCtrl;
816be743 85class WXDLLEXPORT wxSpinCtrl;
508011ce 86
39bcce60
VZ
87// ----------------------------------------------------------------------------
88// macros
89// ----------------------------------------------------------------------------
90
91#define wxSafeIncRef(p) if ( p ) (p)->IncRef()
92#define wxSafeDecRef(p) if ( p ) (p)->DecRef()
93
ab79958a 94// ----------------------------------------------------------------------------
c4608a8a
VZ
95// wxGridCellWorker: common base class for wxGridCellRenderer and
96// wxGridCellEditor
97//
98// NB: this is more an implementation convenience than a design issue, so this
99// class is not documented and is not public at all
ab79958a
VZ
100// ----------------------------------------------------------------------------
101
afbd598c 102class WXDLLEXPORT wxGridCellWorker : public wxClientDataContainer
ab79958a
VZ
103{
104public:
c4608a8a 105 wxGridCellWorker() { m_nRef = 1; }
39bcce60
VZ
106
107 // this class is ref counted: it is created with ref count of 1, so
108 // calling DecRef() once will delete it. Calling IncRef() allows to lock
109 // it until the matching DecRef() is called
110 void IncRef() { m_nRef++; }
111 void DecRef() { if ( !--m_nRef ) delete this; }
112
c4608a8a
VZ
113 // interpret renderer parameters: arbitrary string whose interpretatin is
114 // left to the derived classes
115 virtual void SetParameters(const wxString& params);
116
117protected:
118 // virtual dtor for any base class - private because only DecRef() can
119 // delete us
120 virtual ~wxGridCellWorker();
121
122private:
123 size_t m_nRef;
124
125 // suppress the stupid gcc warning about the class having private dtor and
126 // no friends
127 friend class wxGridCellWorkerDummyFriend;
128};
129
130// ----------------------------------------------------------------------------
131// wxGridCellRenderer: this class is responsible for actually drawing the cell
132// in the grid. You may pass it to the wxGridCellAttr (below) to change the
133// format of one given cell or to wxGrid::SetDefaultRenderer() to change the
134// view of all cells. This is an ABC, you will normally use one of the
135// predefined derived classes or derive your own class from it.
136// ----------------------------------------------------------------------------
137
138class WXDLLEXPORT wxGridCellRenderer : public wxGridCellWorker
139{
140public:
ab79958a
VZ
141 // draw the given cell on the provided DC inside the given rectangle
142 // using the style specified by the attribute and the default or selected
143 // state corresponding to the isSelected value.
144 //
145 // this pure virtual function has a default implementation which will
146 // prepare the DC using the given attribute: it will draw the rectangle
147 // with the bg colour from attr and set the text colour and font
148 virtual void Draw(wxGrid& grid,
2796cce3 149 wxGridCellAttr& attr,
ab79958a
VZ
150 wxDC& dc,
151 const wxRect& rect,
152 int row, int col,
153 bool isSelected) = 0;
816be743 154
65e4e78e
VZ
155 // get the preferred size of the cell for its contents
156 virtual wxSize GetBestSize(wxGrid& grid,
157 wxGridCellAttr& attr,
158 wxDC& dc,
159 int row, int col) = 0;
160
e72b4213
VZ
161 // create a new object which is the copy of this one
162 virtual wxGridCellRenderer *Clone() const = 0;
ab79958a
VZ
163};
164
165// the default renderer for the cells containing string data
166class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer
167{
168public:
169 // draw the string
170 virtual void Draw(wxGrid& grid,
2796cce3 171 wxGridCellAttr& attr,
ab79958a
VZ
172 wxDC& dc,
173 const wxRect& rect,
174 int row, int col,
175 bool isSelected);
816be743 176
65e4e78e
VZ
177 // return the string extent
178 virtual wxSize GetBestSize(wxGrid& grid,
179 wxGridCellAttr& attr,
180 wxDC& dc,
181 int row, int col);
182
e72b4213
VZ
183 virtual wxGridCellRenderer *Clone() const
184 { return new wxGridCellStringRenderer; }
185
816be743
VZ
186protected:
187 // set the text colours before drawing
188 void SetTextColoursAndFont(wxGrid& grid,
189 wxGridCellAttr& attr,
190 wxDC& dc,
191 bool isSelected);
65e4e78e
VZ
192
193 // calc the string extent for given string/font
194 wxSize DoGetBestSize(wxGridCellAttr& attr,
195 wxDC& dc,
196 const wxString& text);
816be743
VZ
197};
198
199// the default renderer for the cells containing numeric (long) data
200class WXDLLEXPORT wxGridCellNumberRenderer : public wxGridCellStringRenderer
201{
202public:
203 // draw the string right aligned
204 virtual void Draw(wxGrid& grid,
205 wxGridCellAttr& attr,
206 wxDC& dc,
207 const wxRect& rect,
208 int row, int col,
209 bool isSelected);
65e4e78e
VZ
210
211 virtual wxSize GetBestSize(wxGrid& grid,
212 wxGridCellAttr& attr,
213 wxDC& dc,
214 int row, int col);
215
e72b4213
VZ
216 virtual wxGridCellRenderer *Clone() const
217 { return new wxGridCellNumberRenderer; }
218
65e4e78e
VZ
219protected:
220 wxString GetString(wxGrid& grid, int row, int col);
816be743
VZ
221};
222
223class WXDLLEXPORT wxGridCellFloatRenderer : public wxGridCellStringRenderer
224{
225public:
0b190b0f 226 wxGridCellFloatRenderer(int width = -1, int precision = -1);
816be743
VZ
227
228 // get/change formatting parameters
229 int GetWidth() const { return m_width; }
0b190b0f 230 void SetWidth(int width) { m_width = width; m_format.clear(); }
816be743 231 int GetPrecision() const { return m_precision; }
0b190b0f 232 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
816be743
VZ
233
234 // draw the string right aligned with given width/precision
235 virtual void Draw(wxGrid& grid,
236 wxGridCellAttr& attr,
237 wxDC& dc,
238 const wxRect& rect,
239 int row, int col,
240 bool isSelected);
241
65e4e78e
VZ
242 virtual wxSize GetBestSize(wxGrid& grid,
243 wxGridCellAttr& attr,
244 wxDC& dc,
245 int row, int col);
0b190b0f
VZ
246
247 // parameters string format is "width[,precision]"
248 virtual void SetParameters(const wxString& params);
249
e72b4213
VZ
250 virtual wxGridCellRenderer *Clone() const;
251
65e4e78e
VZ
252protected:
253 wxString GetString(wxGrid& grid, int row, int col);
254
816be743
VZ
255private:
256 // formatting parameters
257 int m_width,
0b190b0f 258 m_precision;
816be743
VZ
259
260 wxString m_format;
ab79958a 261};
f85afd4e 262
508011ce
VZ
263// renderer for boolean fields
264class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer
265{
266public:
508011ce
VZ
267 // draw a check mark or nothing
268 virtual void Draw(wxGrid& grid,
269 wxGridCellAttr& attr,
270 wxDC& dc,
271 const wxRect& rect,
272 int row, int col,
273 bool isSelected);
65e4e78e
VZ
274
275 // return the checkmark size
276 virtual wxSize GetBestSize(wxGrid& grid,
277 wxGridCellAttr& attr,
278 wxDC& dc,
279 int row, int col);
280
e72b4213
VZ
281 virtual wxGridCellRenderer *Clone() const
282 { return new wxGridCellBoolRenderer; }
283
65e4e78e
VZ
284private:
285 static wxSize ms_sizeCheckMark;
508011ce 286};
2796cce3
RD
287
288// ----------------------------------------------------------------------------
289// wxGridCellEditor: This class is responsible for providing and manipulating
290// the in-place edit controls for the grid. Instances of wxGridCellEditor
291// (actually, instances of derived classes since it is an ABC) can be
292// associated with the cell attributes for individual cells, rows, columns, or
293// even for the entire grid.
294// ----------------------------------------------------------------------------
295
c4608a8a 296class WXDLLEXPORT wxGridCellEditor : public wxGridCellWorker
2796cce3
RD
297{
298public:
299 wxGridCellEditor();
39bcce60 300
2796cce3 301 bool IsCreated() { return m_control != NULL; }
f6bcfd97
BP
302 wxControl* GetControl() { return m_control; }
303 void SetControl(wxControl* control) { m_control = control; }
2796cce3 304
1bd71df9
JS
305 wxGridCellAttr* GetCellAttr() { return m_attr; }
306 void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }
307
2796cce3
RD
308 // Creates the actual edit control
309 virtual void Create(wxWindow* parent,
310 wxWindowID id,
2796cce3
RD
311 wxEvtHandler* evtHandler) = 0;
312
313 // Size and position the edit control
314 virtual void SetSize(const wxRect& rect);
315
3da93aae
VZ
316 // Show or hide the edit control, use the specified attributes to set
317 // colours/fonts for it
318 virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
2796cce3 319
189d0213
VZ
320 // Draws the part of the cell not occupied by the control: the base class
321 // version just fills it with background colour from the attribute
322 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
323
2796cce3
RD
324 // Fetch the value from the table and prepare the edit control
325 // to begin editing. Set the focus to the edit control.
3da93aae 326 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
2796cce3 327
3324d5f5
VZ
328 // Complete the editing of the current cell. Returns true if the value has
329 // changed. If necessary, the control may be destroyed.
330 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
2796cce3
RD
331
332 // Reset the value in the control back to its starting value
333 virtual void Reset() = 0;
334
f6bcfd97
BP
335 // return TRUE to allow the given key to start editing: the base class
336 // version only checks that the event has no modifiers. The derived
337 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
338 // their IsAcceptedKey() implementation, although, of course, it is not a
339 // mandatory requirment.
340 //
341 // NB: if the key is F2 (special), editing will always start and this
342 // method will not be called at all (but StartingKey() will)
343 virtual bool IsAcceptedKey(wxKeyEvent& event);
344
345 // If the editor is enabled by pressing keys on the grid, this will be
346 // called to let the editor do something about that first key if desired
2c9a89e0
RD
347 virtual void StartingKey(wxKeyEvent& event);
348
e195a54c
VZ
349 // if the editor is enabled by clicking on the cell, this method will be
350 // called
351 virtual void StartingClick();
352
2796cce3
RD
353 // Some types of controls on some platforms may need some help
354 // with the Return key.
355 virtual void HandleReturn(wxKeyEvent& event);
356
357 // Final cleanup
358 virtual void Destroy();
359
c4608a8a
VZ
360 // create a new object which is the copy of this one
361 virtual wxGridCellEditor *Clone() const = 0;
362
73145b0e
JS
363 // DJC MAPTEK
364 // added GetValue so we can get the value which is in the control
365 virtual wxString GetValue() const = 0;
366
2796cce3 367protected:
39bcce60
VZ
368 // the dtor is private because only DecRef() can delete us
369 virtual ~wxGridCellEditor();
370
3da93aae 371 // the control we show on screen
2796cce3 372 wxControl* m_control;
3da93aae 373
1bd71df9
JS
374 // a temporary pointer to the attribute being edited
375 wxGridCellAttr* m_attr;
376
3da93aae
VZ
377 // if we change the colours/font of the control from the default ones, we
378 // must restore the default later and we save them here between calls to
379 // Show(TRUE) and Show(FALSE)
380 wxColour m_colFgOld,
381 m_colBgOld;
382 wxFont m_fontOld;
39bcce60
VZ
383
384 // suppress the stupid gcc warning about the class having private dtor and
385 // no friends
386 friend class wxGridCellEditorDummyFriend;
2796cce3
RD
387};
388
3379ed37
VZ
389#if wxUSE_TEXTCTRL
390
508011ce 391// the editor for string/text data
2796cce3
RD
392class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor
393{
394public:
395 wxGridCellTextEditor();
396
397 virtual void Create(wxWindow* parent,
398 wxWindowID id,
2796cce3 399 wxEvtHandler* evtHandler);
99306db2 400 virtual void SetSize(const wxRect& rect);
2796cce3 401
189d0213
VZ
402 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
403
f6bcfd97 404 virtual bool IsAcceptedKey(wxKeyEvent& event);
3da93aae 405 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 406 virtual bool EndEdit(int row, int col, wxGrid* grid);
2796cce3
RD
407
408 virtual void Reset();
2c9a89e0 409 virtual void StartingKey(wxKeyEvent& event);
2796cce3
RD
410 virtual void HandleReturn(wxKeyEvent& event);
411
c4608a8a
VZ
412 // parameters string format is "max_width"
413 virtual void SetParameters(const wxString& params);
414
415 virtual wxGridCellEditor *Clone() const
416 { return new wxGridCellTextEditor; }
417
73145b0e
JS
418 // DJC MAPTEK
419 // added GetValue so we can get the value which is in the control
420 virtual wxString GetValue() const;
b54ba671
VZ
421protected:
422 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
2796cce3 423
816be743
VZ
424 // parts of our virtual functions reused by the derived classes
425 void DoBeginEdit(const wxString& startValue);
426 void DoReset(const wxString& startValue);
427
2796cce3 428private:
c4608a8a 429 size_t m_maxChars; // max number of chars allowed
2796cce3
RD
430 wxString m_startValue;
431};
432
816be743
VZ
433// the editor for numeric (long) data
434class WXDLLEXPORT wxGridCellNumberEditor : public wxGridCellTextEditor
435{
436public:
437 // allows to specify the range - if min == max == -1, no range checking is
438 // done
439 wxGridCellNumberEditor(int min = -1, int max = -1);
440
441 virtual void Create(wxWindow* parent,
442 wxWindowID id,
443 wxEvtHandler* evtHandler);
444
f6bcfd97 445 virtual bool IsAcceptedKey(wxKeyEvent& event);
816be743 446 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 447 virtual bool EndEdit(int row, int col, wxGrid* grid);
816be743
VZ
448
449 virtual void Reset();
450 virtual void StartingKey(wxKeyEvent& event);
451
c4608a8a
VZ
452 // parameters string format is "min,max"
453 virtual void SetParameters(const wxString& params);
454
455 virtual wxGridCellEditor *Clone() const
456 { return new wxGridCellNumberEditor(m_min, m_max); }
73145b0e
JS
457 // DJC MAPTEK
458 // added GetValue so we can get the value which is in the control
459 virtual wxString GetValue() const;
c4608a8a 460
816be743
VZ
461protected:
462 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
463
464 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
465 bool HasRange() const { return m_min != m_max; }
466
467 // string representation of m_valueOld
468 wxString GetString() const
469 { return wxString::Format(_T("%ld"), m_valueOld); }
470
471private:
472 int m_min,
473 m_max;
474
475 long m_valueOld;
476};
477
478// the editor for floating point numbers (double) data
479class WXDLLEXPORT wxGridCellFloatEditor : public wxGridCellTextEditor
480{
481public:
f6bcfd97
BP
482 wxGridCellFloatEditor(int width = -1, int precision = -1);
483
816be743
VZ
484 virtual void Create(wxWindow* parent,
485 wxWindowID id,
486 wxEvtHandler* evtHandler);
487
f6bcfd97 488 virtual bool IsAcceptedKey(wxKeyEvent& event);
816be743 489 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 490 virtual bool EndEdit(int row, int col, wxGrid* grid);
816be743
VZ
491
492 virtual void Reset();
493 virtual void StartingKey(wxKeyEvent& event);
494
c4608a8a 495 virtual wxGridCellEditor *Clone() const
ec53826c 496 { return new wxGridCellFloatEditor(m_width, m_precision); }
c4608a8a 497
f6bcfd97
BP
498 // parameters string format is "width,precision"
499 virtual void SetParameters(const wxString& params);
500
816be743
VZ
501protected:
502 // string representation of m_valueOld
f6bcfd97 503 wxString GetString() const;
816be743
VZ
504
505private:
f6bcfd97
BP
506 int m_width,
507 m_precision;
816be743
VZ
508 double m_valueOld;
509};
510
3379ed37
VZ
511#endif // wxUSE_TEXTCTRL
512
513#if wxUSE_CHECKBOX
514
508011ce
VZ
515// the editor for boolean data
516class WXDLLEXPORT wxGridCellBoolEditor : public wxGridCellEditor
517{
518public:
519 virtual void Create(wxWindow* parent,
520 wxWindowID id,
521 wxEvtHandler* evtHandler);
522
523 virtual void SetSize(const wxRect& rect);
524 virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL);
525
f6bcfd97 526 virtual bool IsAcceptedKey(wxKeyEvent& event);
508011ce 527 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 528 virtual bool EndEdit(int row, int col, wxGrid* grid);
508011ce
VZ
529
530 virtual void Reset();
e195a54c 531 virtual void StartingClick();
508011ce 532
c4608a8a
VZ
533 virtual wxGridCellEditor *Clone() const
534 { return new wxGridCellBoolEditor; }
73145b0e
JS
535 // DJC MAPTEK
536 // added GetValue so we can get the value which is in the control
537 virtual wxString GetValue() const;
c4608a8a 538
508011ce
VZ
539protected:
540 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
541
542private:
543 bool m_startValue;
508011ce
VZ
544};
545
3379ed37
VZ
546#endif // wxUSE_CHECKBOX
547
548#if wxUSE_COMBOBOX
549
4ee5fc9c
VZ
550// the editor for string data allowing to choose from the list of strings
551class WXDLLEXPORT wxGridCellChoiceEditor : public wxGridCellEditor
552{
553public:
554 // if !allowOthers, user can't type a string not in choices array
c4608a8a 555 wxGridCellChoiceEditor(size_t count = 0,
f6bcfd97 556 const wxString choices[] = NULL,
4ee5fc9c
VZ
557 bool allowOthers = FALSE);
558
559 virtual void Create(wxWindow* parent,
560 wxWindowID id,
561 wxEvtHandler* evtHandler);
562
563 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
564
565 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 566 virtual bool EndEdit(int row, int col, wxGrid* grid);
4ee5fc9c
VZ
567
568 virtual void Reset();
569
c4608a8a
VZ
570 // parameters string format is "item1[,item2[...,itemN]]"
571 virtual void SetParameters(const wxString& params);
572
573 virtual wxGridCellEditor *Clone() const;
73145b0e
JS
574 // DJC MAPTEK
575 // added GetValue so we can get the value which is in the control
576 virtual wxString GetValue() const;
c4608a8a 577
4ee5fc9c
VZ
578protected:
579 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
580
73145b0e
JS
581// DJC - (MAPTEK) you at least need access to m_choices if you
582// wish to override this class
583protected:
4ee5fc9c
VZ
584 wxString m_startValue;
585 wxArrayString m_choices;
586 bool m_allowOthers;
587};
a68c1246 588
3379ed37
VZ
589#endif // wxUSE_COMBOBOX
590
b99be8fb
VZ
591// ----------------------------------------------------------------------------
592// wxGridCellAttr: this class can be used to alter the cells appearance in
593// the grid by changing their colour/font/... from default. An object of this
594// class may be returned by wxGridTable::GetAttr().
595// ----------------------------------------------------------------------------
596
afbd598c 597class WXDLLEXPORT wxGridCellAttr : public wxClientDataContainer
b99be8fb
VZ
598{
599public:
19d7140e
VZ
600 enum wxAttrKind
601 {
602 Any,
603 Default,
604 Cell,
605 Row,
606 Col,
607 Merged
608 };
609
b99be8fb 610 // ctors
1df4050d 611 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL)
b99be8fb 612 {
1df4050d
VZ
613 Init(attrDefault);
614
0767cb6f
MB
615 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
616 SetAlignment(-1, -1);
b99be8fb
VZ
617 }
618
283b7808
VZ
619 // VZ: considering the number of members wxGridCellAttr has now, this ctor
620 // seems to be pretty useless... may be we should just remove it?
b99be8fb
VZ
621 wxGridCellAttr(const wxColour& colText,
622 const wxColour& colBack,
623 const wxFont& font,
624 int hAlign,
625 int vAlign)
626 : m_colText(colText), m_colBack(colBack), m_font(font)
627 {
2e9a6788 628 Init();
b99be8fb
VZ
629 SetAlignment(hAlign, vAlign);
630 }
631
39bcce60
VZ
632 // creates a new copy of this object
633 wxGridCellAttr *Clone() const;
19d7140e 634 void MergeWith(wxGridCellAttr *mergefrom);
b99be8fb 635
2e9a6788
VZ
636 // this class is ref counted: it is created with ref count of 1, so
637 // calling DecRef() once will delete it. Calling IncRef() allows to lock
638 // it until the matching DecRef() is called
639 void IncRef() { m_nRef++; }
640 void DecRef() { if ( !--m_nRef ) delete this; }
2e9a6788 641
b99be8fb
VZ
642 // setters
643 void SetTextColour(const wxColour& colText) { m_colText = colText; }
644 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
645 void SetFont(const wxFont& font) { m_font = font; }
646 void SetAlignment(int hAlign, int vAlign)
647 {
648 m_hAlign = hAlign;
649 m_vAlign = vAlign;
650 }
27f35b66
SN
651 void SetSize(int num_rows, int num_cols);
652 void SetOverflow( bool allow ) { m_overflow = allow; }
19d7140e
VZ
653 void SetReadOnly(bool isReadOnly = TRUE)
654 { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
b99be8fb 655
ab79958a
VZ
656 // takes ownership of the pointer
657 void SetRenderer(wxGridCellRenderer *renderer)
39bcce60 658 { wxSafeDecRef(m_renderer); m_renderer = renderer; }
07296f0b 659 void SetEditor(wxGridCellEditor* editor)
39bcce60 660 { wxSafeDecRef(m_editor); m_editor = editor; }
ab79958a 661
19d7140e
VZ
662 void SetKind(wxAttrKind kind) { m_attrkind = kind; }
663
b99be8fb
VZ
664 // accessors
665 bool HasTextColour() const { return m_colText.Ok(); }
666 bool HasBackgroundColour() const { return m_colBack.Ok(); }
667 bool HasFont() const { return m_font.Ok(); }
0767cb6f 668 bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
2796cce3 669 bool HasRenderer() const { return m_renderer != NULL; }
07296f0b 670 bool HasEditor() const { return m_editor != NULL; }
19d7140e 671 bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
b99be8fb 672
2796cce3
RD
673 const wxColour& GetTextColour() const;
674 const wxColour& GetBackgroundColour() const;
675 const wxFont& GetFont() const;
676 void GetAlignment(int *hAlign, int *vAlign) const;
27f35b66
SN
677 void GetSize(int *num_rows, int *num_cols) const;
678 bool GetOverflow() const { return m_overflow; }
28a77bc4
RD
679 wxGridCellRenderer *GetRenderer(wxGrid* grid, int row, int col) const;
680 wxGridCellEditor *GetEditor(wxGrid* grid, int row, int col) const;
b99be8fb 681
19d7140e
VZ
682 bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
683
684 wxAttrKind GetKind() { return m_attrkind; }
283b7808 685
2796cce3 686 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
ab79958a 687
b99be8fb 688private:
19d7140e
VZ
689 enum wxAttrReadMode
690 {
691 Unset = -1,
692 ReadWrite,
693 ReadOnly
30bc4a8f 694 };
19d7140e 695
2e9a6788 696 // the common part of all ctors
1df4050d 697 void Init(wxGridCellAttr *attrDefault = NULL);
2e9a6788
VZ
698
699 // the dtor is private because only DecRef() can delete us
39bcce60
VZ
700 ~wxGridCellAttr()
701 {
702 wxSafeDecRef(m_renderer);
703 wxSafeDecRef(m_editor);
704 }
2e9a6788
VZ
705
706 // the ref count - when it goes to 0, we die
707 size_t m_nRef;
708
b99be8fb
VZ
709 wxColour m_colText,
710 m_colBack;
711 wxFont m_font;
712 int m_hAlign,
713 m_vAlign;
27f35b66
SN
714 int m_sizeRows,
715 m_sizeCols;
716 bool m_overflow;
2e9a6788 717
07296f0b
RD
718 wxGridCellRenderer* m_renderer;
719 wxGridCellEditor* m_editor;
720 wxGridCellAttr* m_defGridAttr;
ab79958a 721
19d7140e
VZ
722 wxAttrReadMode m_isReadOnly;
723
724 wxAttrKind m_attrkind;
283b7808 725
a68c1246 726 // use Clone() instead
7ef4c90b 727 DECLARE_NO_COPY_CLASS(wxGridCellAttr)
a68c1246 728
2e9a6788
VZ
729 // suppress the stupid gcc warning about the class having private dtor and
730 // no friends
731 friend class wxGridCellAttrDummyFriend;
b99be8fb
VZ
732};
733
734// ----------------------------------------------------------------------------
735// wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
736// cell attributes.
737// ----------------------------------------------------------------------------
738
739// implementation note: we separate it from wxGridTableBase because we wish to
740// avoid deriving a new table class if possible, and sometimes it will be
741// enough to just derive another wxGridCellAttrProvider instead
758cbedf
VZ
742//
743// the default implementation is reasonably efficient for the generic case,
744// but you might still wish to implement your own for some specific situations
745// if you have performance problems with the stock one
afbd598c 746class WXDLLEXPORT wxGridCellAttrProvider : public wxClientDataContainer
b99be8fb
VZ
747{
748public:
749 wxGridCellAttrProvider();
750 virtual ~wxGridCellAttrProvider();
751
2e9a6788 752 // DecRef() must be called on the returned pointer
19d7140e
VZ
753 virtual wxGridCellAttr *GetAttr(int row, int col,
754 wxGridCellAttr::wxAttrKind kind ) const;
2e9a6788 755
758cbedf
VZ
756 // all these functions take ownership of the pointer, don't call DecRef()
757 // on it
2e9a6788 758 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
758cbedf
VZ
759 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
760 virtual void SetColAttr(wxGridCellAttr *attr, int col);
d1c0b4f9
VZ
761
762 // these functions must be called whenever some rows/cols are deleted
763 // because the internal data must be updated then
4d60017a
SN
764 void UpdateAttrRows( size_t pos, int numRows );
765 void UpdateAttrCols( size_t pos, int numCols );
b99be8fb
VZ
766
767private:
768 void InitData();
769
770 wxGridCellAttrProviderData *m_data;
771};
f85afd4e
MB
772
773//////////////////////////////////////////////////////////////////////
774//
775// Grid table classes
776//
777//////////////////////////////////////////////////////////////////////
778
779
afbd598c 780class WXDLLEXPORT wxGridTableBase : public wxObject, public wxClientDataContainer
f85afd4e 781{
60ff3b99 782public:
f85afd4e
MB
783 wxGridTableBase();
784 virtual ~wxGridTableBase();
785
786 // You must override these functions in a derived table class
787 //
e32352cf
SN
788 virtual int GetNumberRows() = 0;
789 virtual int GetNumberCols() = 0;
f85afd4e 790 virtual bool IsEmptyCell( int row, int col ) = 0;
f2d76237
RD
791 virtual wxString GetValue( int row, int col ) = 0;
792 virtual void SetValue( int row, int col, const wxString& value ) = 0;
793
794 // Data type determination and value access
795 virtual wxString GetTypeName( int row, int col );
796 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
797 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
798
799 virtual long GetValueAsLong( int row, int col );
800 virtual double GetValueAsDouble( int row, int col );
801 virtual bool GetValueAsBool( int row, int col );
802
803 virtual void SetValueAsLong( int row, int col, long value );
804 virtual void SetValueAsDouble( int row, int col, double value );
805 virtual void SetValueAsBool( int row, int col, bool value );
806
807 // For user defined types
808 virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
809 virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
810
60ff3b99 811
f85afd4e
MB
812 // Overriding these is optional
813 //
814 virtual void SetView( wxGrid *grid ) { m_view = grid; }
815 virtual wxGrid * GetView() const { return m_view; }
816
817 virtual void Clear() {}
818 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
819 virtual bool AppendRows( size_t numRows = 1 );
820 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
821 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
822 virtual bool AppendCols( size_t numCols = 1 );
823 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
824
825 virtual wxString GetRowLabelValue( int row );
826 virtual wxString GetColLabelValue( int col );
af111fc3
JS
827 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
828 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
60ff3b99 829
b99be8fb
VZ
830 // Attribute handling
831 //
832
833 // give us the attr provider to use - we take ownership of the pointer
834 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
835
836 // get the currently used attr provider (may be NULL)
837 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
838
f2d76237
RD
839 // Does this table allow attributes? Default implementation creates
840 // a wxGridCellAttrProvider if necessary.
841 virtual bool CanHaveAttributes();
842
b99be8fb 843 // by default forwarded to wxGridCellAttrProvider if any. May be
f2d76237 844 // overridden to handle attributes directly in the table.
19d7140e
VZ
845 virtual wxGridCellAttr *GetAttr( int row, int col,
846 wxGridCellAttr::wxAttrKind kind );
847
b99be8fb 848
758cbedf
VZ
849 // these functions take ownership of the pointer
850 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
851 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
852 virtual void SetColAttr(wxGridCellAttr *attr, int col);
b99be8fb 853
60ff3b99
VZ
854private:
855 wxGrid * m_view;
b99be8fb 856 wxGridCellAttrProvider *m_attrProvider;
60ff3b99 857
f85afd4e
MB
858 DECLARE_ABSTRACT_CLASS( wxGridTableBase );
859};
860
861
b99be8fb
VZ
862// ----------------------------------------------------------------------------
863// wxGridTableMessage
864// ----------------------------------------------------------------------------
f85afd4e
MB
865
866// IDs for messages sent from grid table to view
867//
60ff3b99
VZ
868enum wxGridTableRequest
869{
f85afd4e
MB
870 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
871 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
872 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
873 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
874 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
875 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
876 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
877 wxGRIDTABLE_NOTIFY_COLS_DELETED
878};
879
2d66e025 880class WXDLLEXPORT wxGridTableMessage
f85afd4e 881{
60ff3b99 882public:
f85afd4e
MB
883 wxGridTableMessage();
884 wxGridTableMessage( wxGridTableBase *table, int id,
885 int comInt1 = -1,
886 int comInt2 = -1 );
887
888 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
889 wxGridTableBase * GetTableObject() const { return m_table; }
890 void SetId( int id ) { m_id = id; }
891 int GetId() { return m_id; }
892 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
893 int GetCommandInt() { return m_comInt1; }
894 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
60ff3b99
VZ
895 int GetCommandInt2() { return m_comInt2; }
896
897private:
898 wxGridTableBase *m_table;
899 int m_id;
900 int m_comInt1;
901 int m_comInt2;
f85afd4e
MB
902};
903
904
905
906// ------ wxGridStringArray
907// A 2-dimensional array of strings for data values
908//
909
2d66e025
MB
910WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray);
911
f85afd4e
MB
912
913
914// ------ wxGridStringTable
915//
916// Simplest type of data table for a grid for small tables of strings
917// that are stored in memory
918//
919
2d66e025 920class WXDLLEXPORT wxGridStringTable : public wxGridTableBase
f85afd4e 921{
60ff3b99 922public:
f85afd4e
MB
923 wxGridStringTable();
924 wxGridStringTable( int numRows, int numCols );
e669d97a 925 virtual ~wxGridStringTable();
f85afd4e
MB
926
927 // these are pure virtual in wxGridTableBase
928 //
e32352cf
SN
929 int GetNumberRows();
930 int GetNumberCols();
f85afd4e
MB
931 wxString GetValue( int row, int col );
932 void SetValue( int row, int col, const wxString& s );
933 bool IsEmptyCell( int row, int col );
60ff3b99 934
f85afd4e
MB
935 // overridden functions from wxGridTableBase
936 //
937 void Clear();
938 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
939 bool AppendRows( size_t numRows = 1 );
940 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
941 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
942 bool AppendCols( size_t numCols = 1 );
943 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
944
945 void SetRowLabelValue( int row, const wxString& );
946 void SetColLabelValue( int col, const wxString& );
947 wxString GetRowLabelValue( int row );
948 wxString GetColLabelValue( int col );
60ff3b99
VZ
949
950private:
951 wxGridStringArray m_data;
952
953 // These only get used if you set your own labels, otherwise the
954 // GetRow/ColLabelValue functions return wxGridTableBase defaults
955 //
956 wxArrayString m_rowLabels;
957 wxArrayString m_colLabels;
958
f85afd4e
MB
959 DECLARE_DYNAMIC_CLASS( wxGridStringTable )
960};
961
962
963
43947979 964// ============================================================================
f85afd4e 965// Grid view classes
43947979
VZ
966// ============================================================================
967
968// ----------------------------------------------------------------------------
969// wxGridCellCoords: location of a cell in the grid
970// ----------------------------------------------------------------------------
f85afd4e 971
2d66e025 972class WXDLLEXPORT wxGridCellCoords
f85afd4e 973{
60ff3b99 974public:
f85afd4e
MB
975 wxGridCellCoords() { m_row = m_col = -1; }
976 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
977
978 // default copy ctor is ok
979
e32352cf
SN
980 int GetRow() const { return m_row; }
981 void SetRow( int n ) { m_row = n; }
982 int GetCol() const { return m_col; }
983 void SetCol( int n ) { m_col = n; }
984 void Set( int row, int col ) { m_row = row; m_col = col; }
60ff3b99 985
f85afd4e
MB
986 wxGridCellCoords& operator=( const wxGridCellCoords& other )
987 {
988 if ( &other != this )
989 {
990 m_row=other.m_row;
991 m_col=other.m_col;
992 }
993 return *this;
994 }
995
508011ce 996 bool operator==( const wxGridCellCoords& other ) const
f85afd4e
MB
997 {
998 return (m_row == other.m_row && m_col == other.m_col);
999 }
1000
508011ce 1001 bool operator!=( const wxGridCellCoords& other ) const
f85afd4e
MB
1002 {
1003 return (m_row != other.m_row || m_col != other.m_col);
1004 }
1005
508011ce 1006 bool operator!() const
f85afd4e
MB
1007 {
1008 return (m_row == -1 && m_col == -1 );
1009 }
60ff3b99
VZ
1010
1011private:
e32352cf
SN
1012 int m_row;
1013 int m_col;
f85afd4e
MB
1014};
1015
1016
1017// For comparisons...
1018//
f6bcfd97
BP
1019extern WXDLLEXPORT wxGridCellCoords wxGridNoCellCoords;
1020extern WXDLLEXPORT wxRect wxGridNoCellRect;
f85afd4e 1021
2d66e025
MB
1022// An array of cell coords...
1023//
1024WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray);
1025
b99be8fb
VZ
1026// ----------------------------------------------------------------------------
1027// wxGrid
1028// ----------------------------------------------------------------------------
f85afd4e 1029
60ff3b99
VZ
1030class WXDLLEXPORT wxGrid : public wxScrolledWindow
1031{
1032public:
f85afd4e 1033 wxGrid()
b99be8fb 1034 {
2c9a89e0 1035 Create();
58dd5b3b 1036 }
60ff3b99 1037
f85afd4e
MB
1038 wxGrid( wxWindow *parent,
1039 wxWindowID id,
1040 const wxPoint& pos = wxDefaultPosition,
1041 const wxSize& size = wxDefaultSize,
ebd773c6 1042 long style = wxWANTS_CHARS,
2d66e025
MB
1043 const wxString& name = wxPanelNameStr );
1044
e669d97a 1045 virtual ~wxGrid();
f85afd4e 1046
b5808881
SN
1047 enum wxGridSelectionModes {wxGridSelectCells,
1048 wxGridSelectRows,
1049 wxGridSelectColumns};
1050
1051 bool CreateGrid( int numRows, int numCols,
1052 wxGrid::wxGridSelectionModes selmode =
1053 wxGrid::wxGridSelectCells );
2d66e025 1054
f1567cdd 1055 void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
aa5b8857 1056 wxGrid::wxGridSelectionModes GetSelectionMode() const;
60ff3b99 1057
2d66e025
MB
1058 // ------ grid dimensions
1059 //
1060 int GetNumberRows() { return m_numRows; }
1061 int GetNumberCols() { return m_numCols; }
1062
60ff3b99 1063
2d66e025
MB
1064 // ------ display update functions
1065 //
d10f4bf9 1066 wxArrayInt CalcRowLabelsExposed( const wxRegion& reg );
8fb66724 1067
d10f4bf9
VZ
1068 wxArrayInt CalcColLabelsExposed( const wxRegion& reg );
1069 wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg );
60ff3b99 1070
2d66e025 1071
2d66e025
MB
1072 // ------ event handlers
1073 //
1074 void ProcessRowLabelMouseEvent( wxMouseEvent& event );
1075 void ProcessColLabelMouseEvent( wxMouseEvent& event );
1076 void ProcessCornerLabelMouseEvent( wxMouseEvent& event );
60ff3b99 1077 void ProcessGridCellMouseEvent( wxMouseEvent& event );
2d66e025 1078 bool ProcessTableMessage( wxGridTableMessage& );
f85afd4e 1079
6d004f67
MB
1080 void DoEndDragResizeRow();
1081 void DoEndDragResizeCol();
60ff3b99 1082
f85afd4e 1083 wxGridTableBase * GetTable() const { return m_table; }
043d16b2 1084 bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE,
5c8fc7c1
SN
1085 wxGrid::wxGridSelectionModes selmode =
1086 wxGrid::wxGridSelectCells );
f85afd4e
MB
1087
1088 void ClearGrid();
1089 bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1090 bool AppendRows( int numRows = 1, bool updateLabels=TRUE );
1091 bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE );
1092 bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
1093 bool AppendCols( int numCols = 1, bool updateLabels=TRUE );
60ff3b99 1094 bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE );
f85afd4e 1095
d10f4bf9 1096 void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells );
7c8a8ad5 1097 void DrawGridSpace( wxDC& dc );
2d66e025 1098 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
4634a5d6 1099 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
2d66e025 1100 void DrawCell( wxDC& dc, const wxGridCellCoords& );
d10f4bf9 1101 void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells);
d16c04bb
VZ
1102
1103 // this function is called when the current cell highlight must be redrawn
1104 // and may be overridden by the user
1105 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1f1ce288 1106
d10f4bf9 1107 void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
2d66e025 1108 void DrawRowLabel( wxDC& dc, int row );
8fb66724 1109
d10f4bf9 1110 void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
2d66e025 1111 void DrawColLabel( wxDC& dc, int col );
60ff3b99 1112
f85afd4e 1113
2d66e025 1114 // ------ Cell text drawing functions
f85afd4e 1115 //
2d66e025 1116 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
4c7277db
MB
1117 int horizontalAlignment = wxALIGN_LEFT,
1118 int verticalAlignment = wxALIGN_TOP );
30bc4a8f 1119
d10f4bf9
VZ
1120 void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
1121 int horizontalAlignment = wxALIGN_LEFT,
1122 int verticalAlignment = wxALIGN_TOP );
1123
f85afd4e 1124
2d66e025
MB
1125 // Split a string containing newline chararcters into an array of
1126 // strings and return the number of lines
1127 //
1128 void StringToLines( const wxString& value, wxArrayString& lines );
60ff3b99 1129
2d66e025 1130 void GetTextBoxSize( wxDC& dc,
d10f4bf9 1131 const wxArrayString& lines,
2d66e025 1132 long *width, long *height );
60ff3b99 1133
2d66e025 1134
f85afd4e
MB
1135 // ------
1136 // Code that does a lot of grid modification can be enclosed
1137 // between BeginBatch() and EndBatch() calls to avoid screen
1138 // flicker
1139 //
1140 void BeginBatch() { m_batchCount++; }
f6bcfd97
BP
1141 void EndBatch();
1142
f85afd4e
MB
1143 int GetBatchCount() { return m_batchCount; }
1144
b7282ad2
DW
1145 virtual void Refresh(bool eraseb = TRUE,
1146 const wxRect* rect = (const wxRect *) NULL);
27f35b66 1147
d8232393
MB
1148 // Use this, rather than wxWindow::Refresh(), to force an
1149 // immediate repainting of the grid. Has no effect if you are
1150 // already inside a BeginBatch / EndBatch block.
1151 //
1152 // This function is necessary because wxGrid has a minimal OnPaint()
1153 // handler to reduce screen flicker.
1154 //
1155 void ForceRefresh();
d2520c85 1156
2d66e025
MB
1157
1158 // ------ edit control functions
1159 //
84035150 1160 bool IsEditable() const { return m_editable; }
2d66e025
MB
1161 void EnableEditing( bool edit );
1162
b54ba671
VZ
1163 void EnableCellEditControl( bool enable = TRUE );
1164 void DisableCellEditControl() { EnableCellEditControl(FALSE); }
1165 bool CanEnableCellControl() const;
1166 bool IsCellEditControlEnabled() const;
f6bcfd97 1167 bool IsCellEditControlShown() const;
2d66e025 1168
b54ba671 1169 bool IsCurrentCellReadOnly() const;
2d66e025 1170
2d66e025
MB
1171 void ShowCellEditControl();
1172 void HideCellEditControl();
2d66e025
MB
1173 void SaveEditControlValue();
1174
60ff3b99 1175
2d66e025 1176 // ------ grid location functions
60ff3b99 1177 // Note that all of these functions work with the logical coordinates of
2d66e025
MB
1178 // grid cells and labels so you will need to convert from device
1179 // coordinates for mouse events etc.
1180 //
1181 void XYToCell( int x, int y, wxGridCellCoords& );
1182 int YToRow( int y );
1183 int XToCol( int x );
1184
1185 int YToEdgeOfRow( int y );
1186 int XToEdgeOfCol( int x );
1187
1188 wxRect CellToRect( int row, int col );
1189 wxRect CellToRect( const wxGridCellCoords& coords )
1190 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
1191
1192 int GetGridCursorRow() { return m_currentCellCoords.GetRow(); }
1193 int GetGridCursorCol() { return m_currentCellCoords.GetCol(); }
60ff3b99 1194
2d66e025
MB
1195 // check to see if a cell is either wholly visible (the default arg) or
1196 // at least partially visible in the grid window
1197 //
1198 bool IsVisible( int row, int col, bool wholeCellVisible = TRUE );
1199 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE )
1200 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
1201 void MakeCellVisible( int row, int col );
1202 void MakeCellVisible( const wxGridCellCoords& coords )
1203 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
1204
60ff3b99 1205
2d66e025
MB
1206 // ------ grid cursor movement functions
1207 //
dfaf42d2 1208 void SetGridCursor( int row, int col )
b27f2615 1209 { SetCurrentCell( wxGridCellCoords(row, col) ); }
dfaf42d2 1210
5c8fc7c1
SN
1211 bool MoveCursorUp( bool expandSelection );
1212 bool MoveCursorDown( bool expandSelection );
1213 bool MoveCursorLeft( bool expandSelection );
1214 bool MoveCursorRight( bool expandSelection );
2d66e025
MB
1215 bool MovePageDown();
1216 bool MovePageUp();
5c8fc7c1
SN
1217 bool MoveCursorUpBlock( bool expandSelection );
1218 bool MoveCursorDownBlock( bool expandSelection );
1219 bool MoveCursorLeftBlock( bool expandSelection );
1220 bool MoveCursorRightBlock( bool expandSelection );
2d66e025 1221
60ff3b99 1222
f85afd4e
MB
1223 // ------ label and gridline formatting
1224 //
1225 int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
1226 int GetRowLabelSize() { return m_rowLabelWidth; }
60ff3b99 1227 int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
f85afd4e
MB
1228 int GetColLabelSize() { return m_colLabelHeight; }
1229 wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; }
1230 wxColour GetLabelTextColour() { return m_labelTextColour; }
1231 wxFont GetLabelFont() { return m_labelFont; }
1232 void GetRowLabelAlignment( int *horiz, int *vert );
1233 void GetColLabelAlignment( int *horiz, int *vert );
1234 wxString GetRowLabelValue( int row );
1235 wxString GetColLabelValue( int col );
1236 wxColour GetGridLineColour() { return m_gridLineColour; }
f6bcfd97 1237 wxColour GetCellHighlightColour() { return m_cellHighlightColour; }
d2520c85
RD
1238 int GetCellHighlightPenWidth() { return m_cellHighlightPenWidth; }
1239 int GetCellHighlightROPenWidth() { return m_cellHighlightROPenWidth; }
f85afd4e 1240
ab79958a 1241 void SetRowLabelSize( int width );
f85afd4e
MB
1242 void SetColLabelSize( int height );
1243 void SetLabelBackgroundColour( const wxColour& );
1244 void SetLabelTextColour( const wxColour& );
1245 void SetLabelFont( const wxFont& );
1246 void SetRowLabelAlignment( int horiz, int vert );
1247 void SetColLabelAlignment( int horiz, int vert );
1248 void SetRowLabelValue( int row, const wxString& );
1249 void SetColLabelValue( int col, const wxString& );
1250 void SetGridLineColour( const wxColour& );
f6bcfd97 1251 void SetCellHighlightColour( const wxColour& );
d2520c85
RD
1252 void SetCellHighlightPenWidth(int width);
1253 void SetCellHighlightROPenWidth(int width);
28a77bc4 1254
6e8524b1
MB
1255 void EnableDragRowSize( bool enable = TRUE );
1256 void DisableDragRowSize() { EnableDragRowSize( FALSE ); }
1257 bool CanDragRowSize() { return m_canDragRowSize; }
1258 void EnableDragColSize( bool enable = TRUE );
1259 void DisableDragColSize() { EnableDragColSize( FALSE ); }
1260 bool CanDragColSize() { return m_canDragColSize; }
4cfa5de6
RD
1261 void EnableDragGridSize(bool enable = TRUE);
1262 void DisableDragGridSize() { EnableDragGridSize(FALSE); }
1263 bool CanDragGridSize() { return m_canDragGridSize; }
1264
27f35b66
SN
1265 // this sets the specified attribute for this cell or in this row/col
1266 void SetAttr(int row, int col, wxGridCellAttr *attr);
758cbedf
VZ
1267 void SetRowAttr(int row, wxGridCellAttr *attr);
1268 void SetColAttr(int col, wxGridCellAttr *attr);
1269
0b190b0f
VZ
1270 // shortcuts for setting the column parameters
1271
1272 // set the format for the data in the column: default is string
1273 void SetColFormatBool(int col);
1274 void SetColFormatNumber(int col);
1275 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1276 void SetColFormatCustom(int col, const wxString& typeName);
1277
f85afd4e
MB
1278 void EnableGridLines( bool enable = TRUE );
1279 bool GridLinesEnabled() { return m_gridLinesEnabled; }
1280
f85afd4e
MB
1281 // ------ row and col formatting
1282 //
1283 int GetDefaultRowSize();
1284 int GetRowSize( int row );
1285 int GetDefaultColSize();
1286 int GetColSize( int col );
1287 wxColour GetDefaultCellBackgroundColour();
1288 wxColour GetCellBackgroundColour( int row, int col );
1289 wxColour GetDefaultCellTextColour();
1290 wxColour GetCellTextColour( int row, int col );
f85afd4e
MB
1291 wxFont GetDefaultCellFont();
1292 wxFont GetCellFont( int row, int col );
1293 void GetDefaultCellAlignment( int *horiz, int *vert );
1294 void GetCellAlignment( int row, int col, int *horiz, int *vert );
27f35b66
SN
1295 bool GetDefaultCellOverflow();
1296 bool GetCellOverflow( int row, int col );
1297 void GetCellSize( int row, int col, int *num_rows, int *num_cols );
60ff3b99 1298
f85afd4e
MB
1299 void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE );
1300 void SetRowSize( int row, int height );
1301 void SetDefaultColSize( int width, bool resizeExistingCols = FALSE );
8fb66724 1302
f85afd4e 1303 void SetColSize( int col, int width );
43947979 1304
af547d51
VZ
1305 // automatically size the column or row to fit to its contents, if
1306 // setAsMin is TRUE, this optimal width will also be set as minimal width
1307 // for this column
1308 void AutoSizeColumn( int col, bool setAsMin = TRUE )
1309 { AutoSizeColOrRow(col, setAsMin, TRUE); }
1310 void AutoSizeRow( int row, bool setAsMin = TRUE )
1311 { AutoSizeColOrRow(row, setAsMin, FALSE); }
65e4e78e
VZ
1312
1313 // auto size all columns (very ineffective for big grids!)
266e8367 1314 void AutoSizeColumns( bool setAsMin = TRUE )
ad115b2d 1315 { (void)SetOrCalcColumnSizes(FALSE, setAsMin); }
65e4e78e 1316
266e8367 1317 void AutoSizeRows( bool setAsMin = TRUE )
ad115b2d 1318 { (void)SetOrCalcRowSizes(FALSE, setAsMin); }
57c086ef
VZ
1319
1320 // auto size the grid, that is make the columns/rows of the "right" size
1321 // and also set the grid size to just fit its contents
1322 void AutoSize();
1323
43947979
VZ
1324 // column won't be resized to be lesser width - this must be called during
1325 // the grid creation because it won't resize the column if it's already
1326 // narrower than the minimal width
1327 void SetColMinimalWidth( int col, int width );
af547d51 1328 void SetRowMinimalHeight( int row, int width );
43947979 1329
f85afd4e
MB
1330 void SetDefaultCellBackgroundColour( const wxColour& );
1331 void SetCellBackgroundColour( int row, int col, const wxColour& );
1332 void SetDefaultCellTextColour( const wxColour& );
8fb66724 1333
f85afd4e 1334 void SetCellTextColour( int row, int col, const wxColour& );
f85afd4e
MB
1335 void SetDefaultCellFont( const wxFont& );
1336 void SetCellFont( int row, int col, const wxFont& );
1337 void SetDefaultCellAlignment( int horiz, int vert );
1338 void SetCellAlignment( int row, int col, int horiz, int vert );
27f35b66
SN
1339 void SetDefaultCellOverflow( bool allow );
1340 void SetCellOverflow( int row, int col, bool allow );
1341 void SetCellSize( int row, int col, int num_rows, int num_cols );
f85afd4e 1342
ab79958a 1343 // takes ownership of the pointer
2796cce3 1344 void SetDefaultRenderer(wxGridCellRenderer *renderer);
ab79958a 1345 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
2796cce3
RD
1346 wxGridCellRenderer *GetDefaultRenderer() const;
1347 wxGridCellRenderer* GetCellRenderer(int row, int col);
1348
283b7808 1349 // takes ownership of the pointer
0ba143c9 1350 void SetDefaultEditor(wxGridCellEditor *editor);
9b4aede2 1351 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
0ba143c9 1352 wxGridCellEditor *GetDefaultEditor() const;
9b4aede2
RD
1353 wxGridCellEditor* GetCellEditor(int row, int col);
1354
60a67569 1355
f2d76237 1356
f85afd4e
MB
1357 // ------ cell value accessors
1358 //
1359 wxString GetCellValue( int row, int col )
1360 {
1361 if ( m_table )
1362 {
1363 return m_table->GetValue( row, col );
1364 }
1365 else
1366 {
1367 return wxEmptyString;
1368 }
1369 }
1370
1371 wxString GetCellValue( const wxGridCellCoords& coords )
1372 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
60ff3b99 1373
f85afd4e
MB
1374 void SetCellValue( int row, int col, const wxString& s );
1375 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1376 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
f85afd4e 1377
283b7808
VZ
1378 // returns TRUE if the cell can't be edited
1379 bool IsReadOnly(int row, int col) const;
60ff3b99 1380
283b7808
VZ
1381 // make the cell editable/readonly
1382 void SetReadOnly(int row, int col, bool isReadOnly = TRUE);
f85afd4e 1383
aa5b8857 1384 // ------ select blocks of cells
f85afd4e
MB
1385 //
1386 void SelectRow( int row, bool addToSelected = FALSE );
1387 void SelectCol( int col, bool addToSelected = FALSE );
60ff3b99 1388
c9097836
MB
1389 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
1390 bool addToSelected = FALSE );
f85afd4e
MB
1391
1392 void SelectBlock( const wxGridCellCoords& topLeft,
c9097836
MB
1393 const wxGridCellCoords& bottomRight,
1394 bool addToSelected = FALSE )
f85afd4e 1395 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
c9097836
MB
1396 bottomRight.GetRow(), bottomRight.GetCol(),
1397 addToSelected ); }
f85afd4e
MB
1398
1399 void SelectAll();
60ff3b99 1400
b5808881 1401 bool IsSelection();
f85afd4e 1402
aa5b8857 1403 // ------ deselect blocks or cells
f7b4b343
VZ
1404 //
1405 void DeselectRow( int row );
1406 void DeselectCol( int col );
1407 void DeselectCell( int row, int col );
1408
f85afd4e
MB
1409 void ClearSelection();
1410
84035150 1411 bool IsInSelection( int row, int col ) const;
f85afd4e 1412
84035150 1413 bool IsInSelection( const wxGridCellCoords& coords ) const
f85afd4e
MB
1414 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
1415
aa5b8857
SN
1416 wxGridCellCoordsArray GetSelectedCells() const;
1417 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1418 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1419 wxArrayInt GetSelectedRows() const;
1420 wxArrayInt GetSelectedCols() const;
c3baf426
SN
1421
1422 // This function returns the rectangle that encloses the block of cells
1423 // limited by TopLeft and BottomRight cell in device coords and clipped
1424 // to the client size of the grid window.
1425 //
58dd5b3b 1426 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
b99be8fb 1427 const wxGridCellCoords & bottomRight );
c3baf426 1428
2796cce3
RD
1429 // Access or update the selection fore/back colours
1430 wxColour GetSelectionBackground() const
1431 { return m_selectionBackground; }
1432 wxColour GetSelectionForeground() const
1433 { return m_selectionForeground; }
1434
1435 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
1436 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
1437
1438
f2d76237
RD
1439 // Methods for a registry for mapping data types to Renderers/Editors
1440 void RegisterDataType(const wxString& typeName,
1441 wxGridCellRenderer* renderer,
1442 wxGridCellEditor* editor);
73145b0e
JS
1443 // DJC MAPTEK
1444 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
99306db2
VZ
1445 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1446 { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
73145b0e
JS
1447 virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1448 virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1449 virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
f2d76237 1450
266e8367
VZ
1451 // grid may occupy more space than needed for its rows/columns, this
1452 // function allows to set how big this extra space is
1453 void SetMargins(int extraWidth, int extraHeight)
1454 {
1455 m_extraWidth = extraWidth;
1456 m_extraHeight = extraHeight;
b8125adf
VZ
1457
1458 CalcDimensions();
266e8367 1459 }
f85afd4e 1460
d2520c85
RD
1461 // Accessors for component windows
1462 wxWindow* GetGridWindow() { return (wxWindow*)m_gridWin; }
1463 wxWindow* GetGridRowLabelWindow() { return (wxWindow*)m_rowLabelWin; }
1464 wxWindow* GetGridColLabelWindow() { return (wxWindow*)m_colLabelWin; }
1465 wxWindow* GetGridCornerLabelWindow() { return (wxWindow*)m_cornerLabelWin; }
1466
1467
1468
f85afd4e
MB
1469 // ------ For compatibility with previous wxGrid only...
1470 //
1471 // ************************************************
1472 // ** Don't use these in new code because they **
1473 // ** are liable to disappear in a future **
1474 // ** revision **
1475 // ************************************************
1476 //
1477
1478 wxGrid( wxWindow *parent,
6daa30a0 1479 int x, int y, int w = -1, int h = -1,
ebd773c6 1480 long style = wxWANTS_CHARS,
f85afd4e 1481 const wxString& name = wxPanelNameStr )
f6bcfd97 1482 : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h),
ebd773c6 1483 (style|wxWANTS_CHARS), name )
60ff3b99 1484 {
f85afd4e 1485 Create();
60ff3b99 1486 }
f85afd4e
MB
1487
1488 void SetCellValue( const wxString& val, int row, int col )
1489 { SetCellValue( row, col, val ); }
60ff3b99 1490
f85afd4e
MB
1491 void UpdateDimensions()
1492 { CalcDimensions(); }
1493
1494 int GetRows() { return GetNumberRows(); }
1495 int GetCols() { return GetNumberCols(); }
1496 int GetCursorRow() { return GetGridCursorRow(); }
1497 int GetCursorColumn() { return GetGridCursorCol(); }
60ff3b99 1498
2d66e025
MB
1499 int GetScrollPosX() { return 0; }
1500 int GetScrollPosY() { return 0; }
60ff3b99 1501
aa5e1f75
SN
1502 void SetScrollX( int WXUNUSED(x) ) { }
1503 void SetScrollY( int WXUNUSED(y) ) { }
f85afd4e
MB
1504
1505 void SetColumnWidth( int col, int width )
1506 { SetColSize( col, width ); }
60ff3b99 1507
f85afd4e
MB
1508 int GetColumnWidth( int col )
1509 { return GetColSize( col ); }
60ff3b99 1510
f85afd4e
MB
1511 void SetRowHeight( int row, int height )
1512 { SetRowSize( row, height ); }
60ff3b99 1513
7c1cb261 1514 // GetRowHeight() is below
60ff3b99 1515
2d66e025
MB
1516 int GetViewHeight() // returned num whole rows visible
1517 { return 0; }
60ff3b99 1518
2d66e025
MB
1519 int GetViewWidth() // returned num whole cols visible
1520 { return 0; }
f85afd4e
MB
1521
1522 void SetLabelSize( int orientation, int sz )
1523 {
1524 if ( orientation == wxHORIZONTAL )
1525 SetColLabelSize( sz );
1526 else
1527 SetRowLabelSize( sz );
1528 }
1529
1530 int GetLabelSize( int orientation )
1531 {
1532 if ( orientation == wxHORIZONTAL )
1533 return GetColLabelSize();
1534 else
1535 return GetRowLabelSize();
1536 }
1537
1538 void SetLabelAlignment( int orientation, int align )
1539 {
1540 if ( orientation == wxHORIZONTAL )
1541 SetColLabelAlignment( align, -1 );
1542 else
1543 SetRowLabelAlignment( align, -1 );
1544 }
1545
af111fc3 1546 int GetLabelAlignment( int orientation, int WXUNUSED(align) )
f85afd4e
MB
1547 {
1548 int h, v;
1549 if ( orientation == wxHORIZONTAL )
1550 {
1551 GetColLabelAlignment( &h, &v );
1552 return h;
1553 }
1554 else
1555 {
1556 GetRowLabelAlignment( &h, &v );
1557 return h;
1558 }
1559 }
1560
1561 void SetLabelValue( int orientation, const wxString& val, int pos )
1562 {
1563 if ( orientation == wxHORIZONTAL )
1564 SetColLabelValue( pos, val );
1565 else
1566 SetRowLabelValue( pos, val );
1567 }
60ff3b99 1568
f85afd4e
MB
1569 wxString GetLabelValue( int orientation, int pos)
1570 {
1571 if ( orientation == wxHORIZONTAL )
1572 return GetColLabelValue( pos );
1573 else
1574 return GetRowLabelValue( pos );
1575 }
1576
60ff3b99 1577 wxFont GetCellTextFont() const
2796cce3 1578 { return m_defaultCellAttr->GetFont(); }
60ff3b99 1579
af111fc3 1580 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
2796cce3 1581 { return m_defaultCellAttr->GetFont(); }
60ff3b99 1582
f85afd4e
MB
1583 void SetCellTextFont(const wxFont& fnt)
1584 { SetDefaultCellFont( fnt ); }
60ff3b99 1585
f85afd4e
MB
1586 void SetCellTextFont(const wxFont& fnt, int row, int col)
1587 { SetCellFont( row, col, fnt ); }
60ff3b99 1588
f85afd4e
MB
1589 void SetCellTextColour(const wxColour& val, int row, int col)
1590 { SetCellTextColour( row, col, val ); }
60ff3b99 1591
f85afd4e
MB
1592 void SetCellTextColour(const wxColour& col)
1593 { SetDefaultCellTextColour( col ); }
60ff3b99 1594
f85afd4e
MB
1595 void SetCellBackgroundColour(const wxColour& col)
1596 { SetDefaultCellBackgroundColour( col ); }
60ff3b99 1597
f85afd4e
MB
1598 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1599 { SetCellBackgroundColour( row, col, colour ); }
60ff3b99 1600
f85afd4e
MB
1601 bool GetEditable() { return IsEditable(); }
1602 void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); }
1603 bool GetEditInPlace() { return IsCellEditControlEnabled(); }
8fb66724 1604
aa5e1f75 1605 void SetEditInPlace(bool WXUNUSED(edit) = TRUE) { }
f85afd4e 1606
60a67569 1607 void SetCellAlignment( int align, int row, int col)
4c7277db 1608 { SetCellAlignment(row, col, align, wxALIGN_CENTER); }
60a67569
JS
1609 void SetCellAlignment( int WXUNUSED(align) ) {}
1610 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1611 { }
1612 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
6fc0f38f 1613 wxPen& GetDividerPen() const;
60a67569 1614 void OnActivate(bool WXUNUSED(active)) {}
60ff3b99 1615
f85afd4e
MB
1616 // ******** End of compatibility functions **********
1617
2d66e025
MB
1618
1619
f85afd4e 1620 // ------ control IDs
2d66e025 1621 enum { wxGRID_CELLCTRL = 2000,
f85afd4e
MB
1622 wxGRID_TOPCTRL };
1623
1624 // ------ control types
2d66e025 1625 enum { wxGRID_TEXTCTRL = 2100,
f85afd4e
MB
1626 wxGRID_CHECKBOX,
1627 wxGRID_CHOICE,
1628 wxGRID_COMBOBOX };
1629
266e8367
VZ
1630 // overridden wxWindow methods
1631 virtual void Fit();
1632
60ff3b99 1633protected:
266e8367
VZ
1634 virtual wxSize DoGetBestSize() const;
1635
60ff3b99
VZ
1636 bool m_created;
1637
1638 wxGridWindow *m_gridWin;
1639 wxGridRowLabelWindow *m_rowLabelWin;
1640 wxGridColLabelWindow *m_colLabelWin;
1641 wxGridCornerLabelWindow *m_cornerLabelWin;
1642
60ff3b99 1643 wxGridTableBase *m_table;
2796cce3 1644 bool m_ownTable;
60ff3b99 1645
60ff3b99
VZ
1646 int m_numRows;
1647 int m_numCols;
1648
1649 wxGridCellCoords m_currentCellCoords;
1650
b5808881
SN
1651 wxGridCellCoords m_selectingTopLeft;
1652 wxGridCellCoords m_selectingBottomRight;
d95b0c2b 1653 wxGridCellCoords m_selectingKeyboard;
b5808881 1654 wxGridSelection *m_selection;
2796cce3
RD
1655 wxColour m_selectionBackground;
1656 wxColour m_selectionForeground;
60ff3b99 1657
7c1cb261
VZ
1658 // NB: *never* access m_row/col arrays directly because they are created
1659 // on demand, *always* use accessor functions instead!
1660
1661 // init the m_rowHeights/Bottoms arrays with default values
1662 void InitRowHeights();
1663
60ff3b99
VZ
1664 int m_defaultRowHeight;
1665 wxArrayInt m_rowHeights;
1666 wxArrayInt m_rowBottoms;
1667
7c1cb261
VZ
1668 // init the m_colWidths/Rights arrays
1669 void InitColWidths();
1670
60ff3b99
VZ
1671 int m_defaultColWidth;
1672 wxArrayInt m_colWidths;
1673 wxArrayInt m_colRights;
7c1cb261
VZ
1674
1675 // get the col/row coords
1676 int GetColWidth(int col) const;
1677 int GetColLeft(int col) const;
1678 int GetColRight(int col) const;
1679
1680 // this function must be public for compatibility...
1681public:
1682 int GetRowHeight(int row) const;
1683protected:
1684
1685 int GetRowTop(int row) const;
1686 int GetRowBottom(int row) const;
1687
60ff3b99
VZ
1688 int m_rowLabelWidth;
1689 int m_colLabelHeight;
1690
266e8367
VZ
1691 // the size of the margin left to the right and bottom of the cell area
1692 int m_extraWidth,
1693 m_extraHeight;
1694
60ff3b99
VZ
1695 wxColour m_labelBackgroundColour;
1696 wxColour m_labelTextColour;
1697 wxFont m_labelFont;
1698
1699 int m_rowLabelHorizAlign;
1700 int m_rowLabelVertAlign;
1701 int m_colLabelHorizAlign;
1702 int m_colLabelVertAlign;
1703
1704 bool m_defaultRowLabelValues;
1705 bool m_defaultColLabelValues;
1706
1707 wxColour m_gridLineColour;
1708 bool m_gridLinesEnabled;
f6bcfd97 1709 wxColour m_cellHighlightColour;
d2520c85
RD
1710 int m_cellHighlightPenWidth;
1711 int m_cellHighlightROPenWidth;
1712
60ff3b99 1713
266e8367
VZ
1714 // common part of AutoSizeColumn/Row() and GetBestSize()
1715 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = TRUE);
1716 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = TRUE);
1717
af547d51
VZ
1718 // common part of AutoSizeColumn/Row()
1719 void AutoSizeColOrRow(int n, bool setAsMin, bool column /* or row? */);
1720
43947979
VZ
1721 // if a column has a minimal width, it will be the value for it in this
1722 // hash table
af547d51
VZ
1723 wxHashTableLong m_colMinWidths,
1724 m_rowMinHeights;
43947979 1725
af547d51
VZ
1726 // get the minimal width of the given column/row
1727 int GetColMinimalWidth(int col) const;
1728 int GetRowMinimalHeight(int col) const;
b99be8fb
VZ
1729
1730 // do we have some place to store attributes in?
1731 bool CanHaveAttributes();
60ff3b99 1732
2e9a6788
VZ
1733 // returns the attribute we may modify in place: a new one if this cell
1734 // doesn't have any yet or the existing one if it does
1735 //
1736 // DecRef() must be called on the returned pointer, as usual
0a976765
VZ
1737 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1738
1739 // cell attribute cache (currently we only cache 1, may be will do
1740 // more/better later)
1741 struct CachedAttr
1742 {
1743 int row, col;
1744 wxGridCellAttr *attr;
1745 } m_attrCache;
1746
1747 // invalidates the attribute cache
1748 void ClearAttrCache();
1749
1750 // adds an attribute to cache
1751 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
1752
1753 // looks for an attr in cache, returns TRUE if found
1754 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
1755
1756 // looks for the attr in cache, if not found asks the table and caches the
1757 // result
2e9a6788 1758 wxGridCellAttr *GetCellAttr(int row, int col) const;
2c9a89e0
RD
1759 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords )
1760 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
2e9a6788 1761
2796cce3
RD
1762 // the default cell attr object for cells that don't have their own
1763 wxGridCellAttr* m_defaultCellAttr;
1764
1765
60ff3b99
VZ
1766 bool m_inOnKeyDown;
1767 int m_batchCount;
1768
f2d76237
RD
1769
1770 wxGridTypeRegistry* m_typeRegistry;
1771
e2b42eeb
VZ
1772 enum CursorMode
1773 {
1774 WXGRID_CURSOR_SELECT_CELL,
1775 WXGRID_CURSOR_RESIZE_ROW,
1776 WXGRID_CURSOR_RESIZE_COL,
1777 WXGRID_CURSOR_SELECT_ROW,
1778 WXGRID_CURSOR_SELECT_COL
60ff3b99
VZ
1779 };
1780
e2b42eeb
VZ
1781 // this method not only sets m_cursorMode but also sets the correct cursor
1782 // for the given mode and, if captureMouse is not FALSE releases the mouse
1783 // if it was captured and captures it if it must be captured
1784 //
1785 // for this to work, you should always use it and not set m_cursorMode
1786 // directly!
1787 void ChangeCursorMode(CursorMode mode,
1788 wxWindow *win = (wxWindow *)NULL,
1789 bool captureMouse = TRUE);
1790
1791 wxWindow *m_winCapture; // the window which captured the mouse
1792 CursorMode m_cursorMode;
1793
6e8524b1
MB
1794 bool m_canDragRowSize;
1795 bool m_canDragColSize;
4cfa5de6 1796 bool m_canDragGridSize;
07296f0b
RD
1797 int m_dragLastPos;
1798 int m_dragRowOrCol;
1799 bool m_isDragging;
1800 wxPoint m_startDragPos;
60ff3b99 1801
75ecbe45 1802 bool m_waitForSlowClick;
025562fe 1803
60ff3b99
VZ
1804 wxGridCellCoords m_selectionStart;
1805
1806 wxCursor m_rowResizeCursor;
1807 wxCursor m_colResizeCursor;
1808
b54ba671
VZ
1809 bool m_editable; // applies to whole grid
1810 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
60ff3b99
VZ
1811
1812
1813 void Create();
1814 void Init();
1815 void CalcDimensions();
7807d81c 1816 void CalcWindowSizes();
60ff3b99
VZ
1817 bool Redimension( wxGridTableMessage& );
1818
1819
fe7b9ed6
VZ
1820 int SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
1821 int SendEvent( const wxEventType, int row, int col );
1822 int SendEvent( const wxEventType type)
b54ba671
VZ
1823 {
1824 return SendEvent(type,
1825 m_currentCellCoords.GetRow(),
1826 m_currentCellCoords.GetCol());
1827 }
60ff3b99
VZ
1828
1829 void OnPaint( wxPaintEvent& );
1830 void OnSize( wxSizeEvent& );
1831 void OnKeyDown( wxKeyEvent& );
f6bcfd97 1832 void OnKeyUp( wxKeyEvent& );
2796cce3 1833 void OnEraseBackground( wxEraseEvent& );
60ff3b99
VZ
1834
1835
1836 void SetCurrentCell( const wxGridCellCoords& coords );
1837 void SetCurrentCell( int row, int col )
1838 { SetCurrentCell( wxGridCellCoords(row, col) ); }
1839
c9097836
MB
1840 void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol );
1841
1842 void HighlightBlock( const wxGridCellCoords& topLeft,
d2520c85 1843 const wxGridCellCoords& bottomRight )
c9097836
MB
1844 { HighlightBlock( topLeft.GetRow(), topLeft.GetCol(),
1845 bottomRight.GetRow(), bottomRight.GetCol() ); }
60ff3b99
VZ
1846
1847 // ------ functions to get/send data (see also public functions)
1848 //
1849 bool GetModelValues();
1850 bool SetModelValues();
1851
2b5f62a0 1852 friend class WXDLLEXPORT wxGridSelection;
60ff3b99 1853
2d66e025 1854 DECLARE_DYNAMIC_CLASS( wxGrid )
f85afd4e
MB
1855 DECLARE_EVENT_TABLE()
1856};
1857
43947979
VZ
1858// ----------------------------------------------------------------------------
1859// Grid event class and event types
1860// ----------------------------------------------------------------------------
f85afd4e
MB
1861
1862class WXDLLEXPORT wxGridEvent : public wxNotifyEvent
1863{
60ff3b99 1864public:
f85afd4e
MB
1865 wxGridEvent()
1866 : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1),
5c8fc7c1 1867 m_selecting(0), m_control(0), m_meta(0), m_shift(0), m_alt(0)
f85afd4e
MB
1868 {
1869 }
1870
1871 wxGridEvent(int id, wxEventType type, wxObject* obj,
5c8fc7c1 1872 int row=-1, int col=-1, int x=-1, int y=-1, bool sel = TRUE,
f85afd4e
MB
1873 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1874
1875 virtual int GetRow() { return m_row; }
1876 virtual int GetCol() { return m_col; }
1877 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
5c8fc7c1 1878 bool Selecting() { return m_selecting; }
f85afd4e
MB
1879 bool ControlDown() { return m_control; }
1880 bool MetaDown() { return m_meta; }
1881 bool ShiftDown() { return m_shift; }
1882 bool AltDown() { return m_alt; }
2d66e025 1883
60ff3b99
VZ
1884protected:
1885 int m_row;
1886 int m_col;
f85afd4e
MB
1887 int m_x;
1888 int m_y;
5c8fc7c1 1889 bool m_selecting;
f85afd4e
MB
1890 bool m_control;
1891 bool m_meta;
1892 bool m_shift;
1893 bool m_alt;
60ff3b99
VZ
1894
1895 DECLARE_DYNAMIC_CLASS(wxGridEvent)
1896};
1897
60ff3b99
VZ
1898class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent
1899{
1900public:
f85afd4e
MB
1901 wxGridSizeEvent()
1902 : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1),
1903 m_control(0), m_meta(0), m_shift(0), m_alt(0)
1904 {
1905 }
1906
1907 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
1908 int rowOrCol=-1, int x=-1, int y=-1,
1909 bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE);
1910
1911 int GetRowOrCol() { return m_rowOrCol; }
1912 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
1913 bool ControlDown() { return m_control; }
1914 bool MetaDown() { return m_meta; }
1915 bool ShiftDown() { return m_shift; }
1916 bool AltDown() { return m_alt; }
2d66e025 1917
60ff3b99
VZ
1918protected:
1919 int m_rowOrCol;
1920 int m_x;
1921 int m_y;
1922 bool m_control;
1923 bool m_meta;
1924 bool m_shift;
1925 bool m_alt;
1926
2d66e025 1927 DECLARE_DYNAMIC_CLASS(wxGridSizeEvent)
f85afd4e
MB
1928};
1929
1930
1931class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent
1932{
60ff3b99 1933public:
f85afd4e 1934 wxGridRangeSelectEvent()
60ff3b99
VZ
1935 : wxNotifyEvent()
1936 {
1937 m_topLeft = wxGridNoCellCoords;
1938 m_bottomRight = wxGridNoCellCoords;
5c8fc7c1 1939 m_selecting = FALSE;
60ff3b99
VZ
1940 m_control = FALSE;
1941 m_meta = FALSE;
1942 m_shift = FALSE;
1943 m_alt = FALSE;
1944 }
f85afd4e
MB
1945
1946 wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
60ff3b99
VZ
1947 const wxGridCellCoords& topLeft,
1948 const wxGridCellCoords& bottomRight,
5c8fc7c1 1949 bool sel = TRUE,
60ff3b99
VZ
1950 bool control=FALSE, bool shift=FALSE,
1951 bool alt=FALSE, bool meta=FALSE);
f85afd4e
MB
1952
1953 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
1954 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
1955 int GetTopRow() { return m_topLeft.GetRow(); }
1956 int GetBottomRow() { return m_bottomRight.GetRow(); }
1957 int GetLeftCol() { return m_topLeft.GetCol(); }
1958 int GetRightCol() { return m_bottomRight.GetCol(); }
5c8fc7c1 1959 bool Selecting() { return m_selecting; }
f85afd4e
MB
1960 bool ControlDown() { return m_control; }
1961 bool MetaDown() { return m_meta; }
1962 bool ShiftDown() { return m_shift; }
1963 bool AltDown() { return m_alt; }
2d66e025 1964
60ff3b99
VZ
1965protected:
1966 wxGridCellCoords m_topLeft;
1967 wxGridCellCoords m_bottomRight;
5c8fc7c1 1968 bool m_selecting;
60ff3b99
VZ
1969 bool m_control;
1970 bool m_meta;
1971 bool m_shift;
1972 bool m_alt;
1973
2d66e025 1974 DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent)
f85afd4e
MB
1975};
1976
bf7945ce
RD
1977
1978class WXDLLEXPORT wxGridEditorCreatedEvent : public wxCommandEvent {
1979public:
1980 wxGridEditorCreatedEvent()
1981 : wxCommandEvent()
1982 {
1983 m_row = 0;
1984 m_col = 0;
1985 m_ctrl = NULL;
1986 }
1987
1988 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
1989 int row, int col, wxControl* ctrl);
1990
1991 int GetRow() { return m_row; }
1992 int GetCol() { return m_col; }
1993 wxControl* GetControl() { return m_ctrl; }
1994 void SetRow(int row) { m_row = row; }
1995 void SetCol(int col) { m_col = col; }
1996 void SetControl(wxControl* ctrl) { m_ctrl = ctrl; }
1997
1998private:
1999 int m_row;
2000 int m_col;
2001 wxControl* m_ctrl;
2002
2003 DECLARE_DYNAMIC_CLASS(wxGridEditorCreatedEvent)
2004};
2005
2006
2e4df4bf
VZ
2007BEGIN_DECLARE_EVENT_TYPES()
2008 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK, 1580)
2009 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK, 1581)
2010 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK, 1582)
2011 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK, 1583)
2012 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK, 1584)
2013 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK, 1585)
2014 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK, 1586)
2015 DECLARE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK, 1587)
2016 DECLARE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE, 1588)
2017 DECLARE_EVENT_TYPE(wxEVT_GRID_COL_SIZE, 1589)
2018 DECLARE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT, 1590)
2019 DECLARE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE, 1591)
2020 DECLARE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL, 1592)
2021 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN, 1593)
2022 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN, 1594)
bf7945ce 2023 DECLARE_EVENT_TYPE(wxEVT_GRID_EDITOR_CREATED, 1595)
2e4df4bf 2024END_DECLARE_EVENT_TYPES()
749692cc 2025
f85afd4e
MB
2026
2027typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
2028typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
2029typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
bf7945ce 2030typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
f85afd4e 2031
2e4df4bf
VZ
2032#define EVT_GRID_CELL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2033#define EVT_GRID_CELL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2034#define EVT_GRID_CELL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2035#define EVT_GRID_CELL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2036#define EVT_GRID_LABEL_LEFT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2037#define EVT_GRID_LABEL_RIGHT_CLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2038#define EVT_GRID_LABEL_LEFT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2039#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2040#define EVT_GRID_ROW_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
2041#define EVT_GRID_COL_SIZE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL ),
2042#define EVT_GRID_RANGE_SELECT(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL ),
2043#define EVT_GRID_CELL_CHANGE(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2044#define EVT_GRID_SELECT_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2045#define EVT_GRID_EDITOR_SHOWN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2046#define EVT_GRID_EDITOR_HIDDEN(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
bf7945ce 2047#define EVT_GRID_EDITOR_CREATED(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_EDITOR_CREATED, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEditorCreatedEventFunction) &fn, NULL ),
f85afd4e
MB
2048
2049
2050#if 0 // TODO: implement these ? others ?
2051
77d4384e
RR
2052extern const int wxEVT_GRID_CREATE_CELL;
2053extern const int wxEVT_GRID_CHANGE_LABELS;
2054extern const int wxEVT_GRID_CHANGE_SEL_LABEL;
f85afd4e 2055
2e4df4bf
VZ
2056#define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2057#define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
2058#define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL ),
f85afd4e
MB
2059
2060#endif
2061
2062#endif // #ifndef __WXGRID_H__
2063
2064#endif // ifndef wxUSE_NEW_GRID