]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/grid.h
don't use the hack with adding hidden columns to the native control because it doesn...
[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)
d4175745 5// Modified by: Santiago Palacios
f85afd4e
MB
6// Created: 1/08/1999
7// RCS-ID: $Id$
8// Copyright: (c) Michael Bedward
65571936 9// Licence: wxWindows licence
f85afd4e
MB
10/////////////////////////////////////////////////////////////////////////////
11
df9fac6d
PC
12#ifndef _WX_GENERIC_GRID_H_
13#define _WX_GENERIC_GRID_H_
14
15#include "wx/defs.h"
16
17#if wxUSE_GRID
f85afd4e 18
2d66e025 19#include "wx/scrolwin.h"
f85afd4e 20
816be743
VZ
21// ----------------------------------------------------------------------------
22// constants
23// ----------------------------------------------------------------------------
24
23318a53 25extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr[];
61961a3c 26
f85afd4e
MB
27// Default parameters for wxGrid
28//
29#define WXGRID_DEFAULT_NUMBER_ROWS 10
30#define WXGRID_DEFAULT_NUMBER_COLS 10
e6002250 31#if defined(__WXMSW__) || defined(__WXGTK20__)
f85afd4e
MB
32#define WXGRID_DEFAULT_ROW_HEIGHT 25
33#else
34#define WXGRID_DEFAULT_ROW_HEIGHT 30
35#endif // __WXMSW__
36#define WXGRID_DEFAULT_COL_WIDTH 80
37#define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32
38#define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82
f1567cdd 39#define WXGRID_LABEL_EDGE_ZONE 2
f85afd4e
MB
40#define WXGRID_MIN_ROW_HEIGHT 15
41#define WXGRID_MIN_COL_WIDTH 15
42#define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16
f85afd4e 43
816be743
VZ
44// type names for grid table values
45#define wxGRID_VALUE_STRING _T("string")
46#define wxGRID_VALUE_BOOL _T("bool")
47#define wxGRID_VALUE_NUMBER _T("long")
48#define wxGRID_VALUE_FLOAT _T("double")
c4608a8a 49#define wxGRID_VALUE_CHOICE _T("choice")
816be743
VZ
50
51#define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING
52#define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER
53
733f486a
VZ
54// magic constant which tells (to some functions) to automatically calculate
55// the appropriate size
56#define wxGRID_AUTOSIZE (-1)
57
58// many wxGrid methods work either with columns or rows, this enum is used for
59// the parameter indicating which one should it be
60enum wxGridDirection
61{
62 wxGRID_COLUMN,
05cc594a 63 wxGRID_ROW
733f486a
VZ
64};
65
b99be8fb
VZ
66// ----------------------------------------------------------------------------
67// forward declarations
68// ----------------------------------------------------------------------------
69
b5dbe15d
VS
70class WXDLLIMPEXP_FWD_ADV wxGrid;
71class WXDLLIMPEXP_FWD_ADV wxGridCellAttr;
72class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData;
73class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow;
74class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow;
75class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow;
76class WXDLLIMPEXP_FWD_ADV wxGridWindow;
77class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry;
78class WXDLLIMPEXP_FWD_ADV wxGridSelection;
79
ad805b9e 80class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl;
b5dbe15d
VS
81class WXDLLIMPEXP_FWD_CORE wxCheckBox;
82class WXDLLIMPEXP_FWD_CORE wxComboBox;
83class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
0e871ad0 84#if wxUSE_SPINCTRL
b5dbe15d 85class WXDLLIMPEXP_FWD_CORE wxSpinCtrl;
0e871ad0 86#endif
508011ce 87
bec70262
VZ
88class wxGridOperations;
89class wxGridRowOperations;
90class wxGridColumnOperations;
10a4531d 91class wxGridDirectionOperations;
bec70262 92
39bcce60
VZ
93// ----------------------------------------------------------------------------
94// macros
95// ----------------------------------------------------------------------------
96
97#define wxSafeIncRef(p) if ( p ) (p)->IncRef()
98#define wxSafeDecRef(p) if ( p ) (p)->DecRef()
99
ab79958a 100// ----------------------------------------------------------------------------
c4608a8a
VZ
101// wxGridCellWorker: common base class for wxGridCellRenderer and
102// wxGridCellEditor
103//
104// NB: this is more an implementation convenience than a design issue, so this
105// class is not documented and is not public at all
ab79958a
VZ
106// ----------------------------------------------------------------------------
107
12f190b0 108class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer
ab79958a
VZ
109{
110public:
c4608a8a 111 wxGridCellWorker() { m_nRef = 1; }
39bcce60
VZ
112
113 // this class is ref counted: it is created with ref count of 1, so
114 // calling DecRef() once will delete it. Calling IncRef() allows to lock
115 // it until the matching DecRef() is called
116 void IncRef() { m_nRef++; }
8d7eaf91 117 void DecRef() { if ( --m_nRef == 0 ) delete this; }
39bcce60 118
c4608a8a
VZ
119 // interpret renderer parameters: arbitrary string whose interpretatin is
120 // left to the derived classes
121 virtual void SetParameters(const wxString& params);
122
123protected:
124 // virtual dtor for any base class - private because only DecRef() can
125 // delete us
126 virtual ~wxGridCellWorker();
127
128private:
129 size_t m_nRef;
130
131 // suppress the stupid gcc warning about the class having private dtor and
132 // no friends
133 friend class wxGridCellWorkerDummyFriend;
134};
135
136// ----------------------------------------------------------------------------
137// wxGridCellRenderer: this class is responsible for actually drawing the cell
138// in the grid. You may pass it to the wxGridCellAttr (below) to change the
139// format of one given cell or to wxGrid::SetDefaultRenderer() to change the
140// view of all cells. This is an ABC, you will normally use one of the
141// predefined derived classes or derive your own class from it.
142// ----------------------------------------------------------------------------
143
12f190b0 144class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker
c4608a8a
VZ
145{
146public:
ab79958a
VZ
147 // draw the given cell on the provided DC inside the given rectangle
148 // using the style specified by the attribute and the default or selected
149 // state corresponding to the isSelected value.
150 //
151 // this pure virtual function has a default implementation which will
152 // prepare the DC using the given attribute: it will draw the rectangle
153 // with the bg colour from attr and set the text colour and font
154 virtual void Draw(wxGrid& grid,
2796cce3 155 wxGridCellAttr& attr,
ab79958a
VZ
156 wxDC& dc,
157 const wxRect& rect,
158 int row, int col,
159 bool isSelected) = 0;
816be743 160
65e4e78e
VZ
161 // get the preferred size of the cell for its contents
162 virtual wxSize GetBestSize(wxGrid& grid,
163 wxGridCellAttr& attr,
164 wxDC& dc,
165 int row, int col) = 0;
166
e72b4213
VZ
167 // create a new object which is the copy of this one
168 virtual wxGridCellRenderer *Clone() const = 0;
ab79958a
VZ
169};
170
171// the default renderer for the cells containing string data
12f190b0 172class WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer
ab79958a
VZ
173{
174public:
175 // draw the string
176 virtual void Draw(wxGrid& grid,
2796cce3 177 wxGridCellAttr& attr,
ab79958a
VZ
178 wxDC& dc,
179 const wxRect& rect,
180 int row, int col,
181 bool isSelected);
816be743 182
65e4e78e
VZ
183 // return the string extent
184 virtual wxSize GetBestSize(wxGrid& grid,
185 wxGridCellAttr& attr,
186 wxDC& dc,
187 int row, int col);
188
e72b4213
VZ
189 virtual wxGridCellRenderer *Clone() const
190 { return new wxGridCellStringRenderer; }
191
816be743
VZ
192protected:
193 // set the text colours before drawing
fbfb8bcc
VZ
194 void SetTextColoursAndFont(const wxGrid& grid,
195 const wxGridCellAttr& attr,
816be743
VZ
196 wxDC& dc,
197 bool isSelected);
65e4e78e
VZ
198
199 // calc the string extent for given string/font
fbfb8bcc 200 wxSize DoGetBestSize(const wxGridCellAttr& attr,
65e4e78e
VZ
201 wxDC& dc,
202 const wxString& text);
816be743
VZ
203};
204
205// the default renderer for the cells containing numeric (long) data
12f190b0 206class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer
816be743
VZ
207{
208public:
209 // draw the string right aligned
210 virtual void Draw(wxGrid& grid,
211 wxGridCellAttr& attr,
212 wxDC& dc,
213 const wxRect& rect,
214 int row, int col,
215 bool isSelected);
65e4e78e
VZ
216
217 virtual wxSize GetBestSize(wxGrid& grid,
218 wxGridCellAttr& attr,
219 wxDC& dc,
220 int row, int col);
221
e72b4213
VZ
222 virtual wxGridCellRenderer *Clone() const
223 { return new wxGridCellNumberRenderer; }
224
65e4e78e 225protected:
fbfb8bcc 226 wxString GetString(const wxGrid& grid, int row, int col);
816be743
VZ
227};
228
12f190b0 229class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer
816be743
VZ
230{
231public:
0b190b0f 232 wxGridCellFloatRenderer(int width = -1, int precision = -1);
816be743
VZ
233
234 // get/change formatting parameters
235 int GetWidth() const { return m_width; }
0b190b0f 236 void SetWidth(int width) { m_width = width; m_format.clear(); }
816be743 237 int GetPrecision() const { return m_precision; }
0b190b0f 238 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
816be743
VZ
239
240 // draw the string right aligned with given width/precision
241 virtual void Draw(wxGrid& grid,
242 wxGridCellAttr& attr,
243 wxDC& dc,
244 const wxRect& rect,
245 int row, int col,
246 bool isSelected);
247
65e4e78e
VZ
248 virtual wxSize GetBestSize(wxGrid& grid,
249 wxGridCellAttr& attr,
250 wxDC& dc,
251 int row, int col);
0b190b0f
VZ
252
253 // parameters string format is "width[,precision]"
254 virtual void SetParameters(const wxString& params);
255
e72b4213
VZ
256 virtual wxGridCellRenderer *Clone() const;
257
65e4e78e 258protected:
fbfb8bcc 259 wxString GetString(const wxGrid& grid, int row, int col);
65e4e78e 260
816be743
VZ
261private:
262 // formatting parameters
263 int m_width,
0b190b0f 264 m_precision;
816be743
VZ
265
266 wxString m_format;
ab79958a 267};
f85afd4e 268
508011ce 269// renderer for boolean fields
12f190b0 270class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer
508011ce
VZ
271{
272public:
508011ce
VZ
273 // draw a check mark or nothing
274 virtual void Draw(wxGrid& grid,
275 wxGridCellAttr& attr,
276 wxDC& dc,
277 const wxRect& rect,
278 int row, int col,
279 bool isSelected);
65e4e78e
VZ
280
281 // return the checkmark size
282 virtual wxSize GetBestSize(wxGrid& grid,
283 wxGridCellAttr& attr,
284 wxDC& dc,
285 int row, int col);
286
e72b4213
VZ
287 virtual wxGridCellRenderer *Clone() const
288 { return new wxGridCellBoolRenderer; }
289
65e4e78e
VZ
290private:
291 static wxSize ms_sizeCheckMark;
508011ce 292};
2796cce3
RD
293
294// ----------------------------------------------------------------------------
295// wxGridCellEditor: This class is responsible for providing and manipulating
296// the in-place edit controls for the grid. Instances of wxGridCellEditor
297// (actually, instances of derived classes since it is an ABC) can be
298// associated with the cell attributes for individual cells, rows, columns, or
299// even for the entire grid.
300// ----------------------------------------------------------------------------
301
12f190b0 302class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker
2796cce3
RD
303{
304public:
305 wxGridCellEditor();
39bcce60 306
2796cce3 307 bool IsCreated() { return m_control != NULL; }
f6bcfd97
BP
308 wxControl* GetControl() { return m_control; }
309 void SetControl(wxControl* control) { m_control = control; }
2796cce3 310
1bd71df9
JS
311 wxGridCellAttr* GetCellAttr() { return m_attr; }
312 void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; }
313
2796cce3
RD
314 // Creates the actual edit control
315 virtual void Create(wxWindow* parent,
316 wxWindowID id,
2796cce3
RD
317 wxEvtHandler* evtHandler) = 0;
318
319 // Size and position the edit control
320 virtual void SetSize(const wxRect& rect);
321
3da93aae
VZ
322 // Show or hide the edit control, use the specified attributes to set
323 // colours/fonts for it
8a3e536c 324 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
2796cce3 325
189d0213
VZ
326 // Draws the part of the cell not occupied by the control: the base class
327 // version just fills it with background colour from the attribute
328 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
329
2796cce3
RD
330 // Fetch the value from the table and prepare the edit control
331 // to begin editing. Set the focus to the edit control.
3da93aae 332 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
2796cce3 333
3324d5f5
VZ
334 // Complete the editing of the current cell. Returns true if the value has
335 // changed. If necessary, the control may be destroyed.
336 virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
2796cce3
RD
337
338 // Reset the value in the control back to its starting value
339 virtual void Reset() = 0;
340
ca65c044 341 // return true to allow the given key to start editing: the base class
f6bcfd97
BP
342 // version only checks that the event has no modifiers. The derived
343 // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in
344 // their IsAcceptedKey() implementation, although, of course, it is not a
345 // mandatory requirment.
346 //
347 // NB: if the key is F2 (special), editing will always start and this
348 // method will not be called at all (but StartingKey() will)
349 virtual bool IsAcceptedKey(wxKeyEvent& event);
350
351 // If the editor is enabled by pressing keys on the grid, this will be
352 // called to let the editor do something about that first key if desired
2c9a89e0
RD
353 virtual void StartingKey(wxKeyEvent& event);
354
e195a54c
VZ
355 // if the editor is enabled by clicking on the cell, this method will be
356 // called
357 virtual void StartingClick();
358
2796cce3
RD
359 // Some types of controls on some platforms may need some help
360 // with the Return key.
361 virtual void HandleReturn(wxKeyEvent& event);
362
363 // Final cleanup
364 virtual void Destroy();
365
c4608a8a
VZ
366 // create a new object which is the copy of this one
367 virtual wxGridCellEditor *Clone() const = 0;
368
73145b0e
JS
369 // added GetValue so we can get the value which is in the control
370 virtual wxString GetValue() const = 0;
371
2796cce3 372protected:
39bcce60
VZ
373 // the dtor is private because only DecRef() can delete us
374 virtual ~wxGridCellEditor();
375
3da93aae 376 // the control we show on screen
2796cce3 377 wxControl* m_control;
3da93aae 378
1bd71df9
JS
379 // a temporary pointer to the attribute being edited
380 wxGridCellAttr* m_attr;
381
3da93aae
VZ
382 // if we change the colours/font of the control from the default ones, we
383 // must restore the default later and we save them here between calls to
ca65c044 384 // Show(true) and Show(false)
3da93aae
VZ
385 wxColour m_colFgOld,
386 m_colBgOld;
387 wxFont m_fontOld;
39bcce60
VZ
388
389 // suppress the stupid gcc warning about the class having private dtor and
390 // no friends
391 friend class wxGridCellEditorDummyFriend;
22f3361e
VZ
392
393 DECLARE_NO_COPY_CLASS(wxGridCellEditor)
2796cce3
RD
394};
395
3379ed37
VZ
396#if wxUSE_TEXTCTRL
397
508011ce 398// the editor for string/text data
12f190b0 399class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor
2796cce3
RD
400{
401public:
402 wxGridCellTextEditor();
403
404 virtual void Create(wxWindow* parent,
405 wxWindowID id,
2796cce3 406 wxEvtHandler* evtHandler);
99306db2 407 virtual void SetSize(const wxRect& rect);
2796cce3 408
189d0213
VZ
409 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
410
f6bcfd97 411 virtual bool IsAcceptedKey(wxKeyEvent& event);
3da93aae 412 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 413 virtual bool EndEdit(int row, int col, wxGrid* grid);
2796cce3
RD
414
415 virtual void Reset();
2c9a89e0 416 virtual void StartingKey(wxKeyEvent& event);
2796cce3
RD
417 virtual void HandleReturn(wxKeyEvent& event);
418
c4608a8a
VZ
419 // parameters string format is "max_width"
420 virtual void SetParameters(const wxString& params);
421
422 virtual wxGridCellEditor *Clone() const
423 { return new wxGridCellTextEditor; }
424
73145b0e
JS
425 // added GetValue so we can get the value which is in the control
426 virtual wxString GetValue() const;
9c71a138 427
b54ba671
VZ
428protected:
429 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
2796cce3 430
816be743 431 // parts of our virtual functions reused by the derived classes
1d5fda5d
VZ
432 void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
433 long style = 0);
816be743
VZ
434 void DoBeginEdit(const wxString& startValue);
435 void DoReset(const wxString& startValue);
436
2796cce3 437private:
c4608a8a 438 size_t m_maxChars; // max number of chars allowed
2796cce3 439 wxString m_startValue;
fc7a2a60
VZ
440
441 DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
2796cce3
RD
442};
443
816be743 444// the editor for numeric (long) data
12f190b0 445class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
816be743
VZ
446{
447public:
448 // allows to specify the range - if min == max == -1, no range checking is
449 // done
450 wxGridCellNumberEditor(int min = -1, int max = -1);
451
452 virtual void Create(wxWindow* parent,
453 wxWindowID id,
454 wxEvtHandler* evtHandler);
455
f6bcfd97 456 virtual bool IsAcceptedKey(wxKeyEvent& event);
816be743 457 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 458 virtual bool EndEdit(int row, int col, wxGrid* grid);
816be743
VZ
459
460 virtual void Reset();
461 virtual void StartingKey(wxKeyEvent& event);
462
c4608a8a
VZ
463 // parameters string format is "min,max"
464 virtual void SetParameters(const wxString& params);
465
466 virtual wxGridCellEditor *Clone() const
467 { return new wxGridCellNumberEditor(m_min, m_max); }
9c71a138 468
73145b0e
JS
469 // added GetValue so we can get the value which is in the control
470 virtual wxString GetValue() const;
c4608a8a 471
816be743 472protected:
0e871ad0 473#if wxUSE_SPINCTRL
816be743 474 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
0e871ad0 475#endif
816be743
VZ
476
477 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
0e871ad0
WS
478 bool HasRange() const
479 {
480#if wxUSE_SPINCTRL
481 return m_min != m_max;
482#else
483 return false;
484#endif
485 }
816be743
VZ
486
487 // string representation of m_valueOld
488 wxString GetString() const
489 { return wxString::Format(_T("%ld"), m_valueOld); }
490
491private:
492 int m_min,
493 m_max;
494
495 long m_valueOld;
fc7a2a60
VZ
496
497 DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
816be743
VZ
498};
499
500// the editor for floating point numbers (double) data
12f190b0 501class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
816be743
VZ
502{
503public:
f6bcfd97
BP
504 wxGridCellFloatEditor(int width = -1, int precision = -1);
505
816be743
VZ
506 virtual void Create(wxWindow* parent,
507 wxWindowID id,
508 wxEvtHandler* evtHandler);
509
f6bcfd97 510 virtual bool IsAcceptedKey(wxKeyEvent& event);
816be743 511 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 512 virtual bool EndEdit(int row, int col, wxGrid* grid);
816be743
VZ
513
514 virtual void Reset();
515 virtual void StartingKey(wxKeyEvent& event);
516
c4608a8a 517 virtual wxGridCellEditor *Clone() const
ec53826c 518 { return new wxGridCellFloatEditor(m_width, m_precision); }
c4608a8a 519
f6bcfd97
BP
520 // parameters string format is "width,precision"
521 virtual void SetParameters(const wxString& params);
522
816be743
VZ
523protected:
524 // string representation of m_valueOld
f6bcfd97 525 wxString GetString() const;
816be743
VZ
526
527private:
f6bcfd97
BP
528 int m_width,
529 m_precision;
816be743 530 double m_valueOld;
fc7a2a60
VZ
531
532 DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
816be743
VZ
533};
534
3379ed37
VZ
535#endif // wxUSE_TEXTCTRL
536
537#if wxUSE_CHECKBOX
538
508011ce 539// the editor for boolean data
12f190b0 540class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
508011ce
VZ
541{
542public:
fc7a2a60
VZ
543 wxGridCellBoolEditor() { }
544
508011ce
VZ
545 virtual void Create(wxWindow* parent,
546 wxWindowID id,
547 wxEvtHandler* evtHandler);
548
549 virtual void SetSize(const wxRect& rect);
9c71a138 550 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
508011ce 551
f6bcfd97 552 virtual bool IsAcceptedKey(wxKeyEvent& event);
508011ce 553 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 554 virtual bool EndEdit(int row, int col, wxGrid* grid);
508011ce
VZ
555
556 virtual void Reset();
e195a54c 557 virtual void StartingClick();
63e2147c 558 virtual void StartingKey(wxKeyEvent& event);
508011ce 559
c4608a8a
VZ
560 virtual wxGridCellEditor *Clone() const
561 { return new wxGridCellBoolEditor; }
9c71a138
VZ
562
563 // added GetValue so we can get the value which is in the control, see
564 // also UseStringValues()
73145b0e 565 virtual wxString GetValue() const;
c4608a8a 566
9c71a138
VZ
567 // set the string values returned by GetValue() for the true and false
568 // states, respectively
569 static void UseStringValues(const wxString& valueTrue = _T("1"),
570 const wxString& valueFalse = wxEmptyString);
571
572 // return true if the given string is equal to the string representation of
573 // true value which we currently use
574 static bool IsTrueValue(const wxString& value);
575
508011ce
VZ
576protected:
577 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
578
579private:
580 bool m_startValue;
fc7a2a60 581
9c71a138
VZ
582 static wxString ms_stringValues[2];
583
fc7a2a60 584 DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor)
508011ce
VZ
585};
586
3379ed37
VZ
587#endif // wxUSE_CHECKBOX
588
589#if wxUSE_COMBOBOX
590
4ee5fc9c 591// the editor for string data allowing to choose from the list of strings
12f190b0 592class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
4ee5fc9c
VZ
593{
594public:
595 // if !allowOthers, user can't type a string not in choices array
c4608a8a 596 wxGridCellChoiceEditor(size_t count = 0,
f6bcfd97 597 const wxString choices[] = NULL,
ca65c044 598 bool allowOthers = false);
7db33cc3 599 wxGridCellChoiceEditor(const wxArrayString& choices,
ca65c044 600 bool allowOthers = false);
4ee5fc9c
VZ
601
602 virtual void Create(wxWindow* parent,
603 wxWindowID id,
604 wxEvtHandler* evtHandler);
605
606 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
607
608 virtual void BeginEdit(int row, int col, wxGrid* grid);
3324d5f5 609 virtual bool EndEdit(int row, int col, wxGrid* grid);
4ee5fc9c
VZ
610
611 virtual void Reset();
612
c4608a8a
VZ
613 // parameters string format is "item1[,item2[...,itemN]]"
614 virtual void SetParameters(const wxString& params);
615
616 virtual wxGridCellEditor *Clone() const;
9c71a138 617
73145b0e
JS
618 // added GetValue so we can get the value which is in the control
619 virtual wxString GetValue() const;
c4608a8a 620
4ee5fc9c
VZ
621protected:
622 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
623
73145b0e
JS
624// DJC - (MAPTEK) you at least need access to m_choices if you
625// wish to override this class
626protected:
4ee5fc9c
VZ
627 wxString m_startValue;
628 wxArrayString m_choices;
629 bool m_allowOthers;
fc7a2a60
VZ
630
631 DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor)
4ee5fc9c 632};
a68c1246 633
3379ed37
VZ
634#endif // wxUSE_COMBOBOX
635
b99be8fb
VZ
636// ----------------------------------------------------------------------------
637// wxGridCellAttr: this class can be used to alter the cells appearance in
638// the grid by changing their colour/font/... from default. An object of this
639// class may be returned by wxGridTable::GetAttr().
640// ----------------------------------------------------------------------------
641
12f190b0 642class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer
b99be8fb
VZ
643{
644public:
19d7140e
VZ
645 enum wxAttrKind
646 {
647 Any,
648 Default,
649 Cell,
650 Row,
651 Col,
652 Merged
653 };
654
b99be8fb 655 // ctors
1df4050d 656 wxGridCellAttr(wxGridCellAttr *attrDefault = NULL)
b99be8fb 657 {
1df4050d
VZ
658 Init(attrDefault);
659
0767cb6f
MB
660 // MB: args used to be 0,0 here but wxALIGN_LEFT is 0
661 SetAlignment(-1, -1);
b99be8fb
VZ
662 }
663
283b7808
VZ
664 // VZ: considering the number of members wxGridCellAttr has now, this ctor
665 // seems to be pretty useless... may be we should just remove it?
b99be8fb
VZ
666 wxGridCellAttr(const wxColour& colText,
667 const wxColour& colBack,
668 const wxFont& font,
669 int hAlign,
670 int vAlign)
671 : m_colText(colText), m_colBack(colBack), m_font(font)
672 {
2e9a6788 673 Init();
b99be8fb
VZ
674 SetAlignment(hAlign, vAlign);
675 }
676
39bcce60
VZ
677 // creates a new copy of this object
678 wxGridCellAttr *Clone() const;
19d7140e 679 void MergeWith(wxGridCellAttr *mergefrom);
b99be8fb 680
2e9a6788
VZ
681 // this class is ref counted: it is created with ref count of 1, so
682 // calling DecRef() once will delete it. Calling IncRef() allows to lock
683 // it until the matching DecRef() is called
684 void IncRef() { m_nRef++; }
8d7eaf91 685 void DecRef() { if ( --m_nRef == 0 ) delete this; }
2e9a6788 686
b99be8fb
VZ
687 // setters
688 void SetTextColour(const wxColour& colText) { m_colText = colText; }
689 void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
690 void SetFont(const wxFont& font) { m_font = font; }
691 void SetAlignment(int hAlign, int vAlign)
692 {
693 m_hAlign = hAlign;
694 m_vAlign = vAlign;
695 }
27f35b66 696 void SetSize(int num_rows, int num_cols);
ca65c044 697 void SetOverflow(bool allow = true)
ef5df12b 698 { m_overflow = allow ? Overflow : SingleCell; }
ca65c044 699 void SetReadOnly(bool isReadOnly = true)
19d7140e 700 { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; }
b99be8fb 701
ab79958a
VZ
702 // takes ownership of the pointer
703 void SetRenderer(wxGridCellRenderer *renderer)
39bcce60 704 { wxSafeDecRef(m_renderer); m_renderer = renderer; }
07296f0b 705 void SetEditor(wxGridCellEditor* editor)
39bcce60 706 { wxSafeDecRef(m_editor); m_editor = editor; }
ab79958a 707
19d7140e
VZ
708 void SetKind(wxAttrKind kind) { m_attrkind = kind; }
709
b99be8fb
VZ
710 // accessors
711 bool HasTextColour() const { return m_colText.Ok(); }
712 bool HasBackgroundColour() const { return m_colBack.Ok(); }
713 bool HasFont() const { return m_font.Ok(); }
0767cb6f 714 bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); }
2796cce3 715 bool HasRenderer() const { return m_renderer != NULL; }
07296f0b 716 bool HasEditor() const { return m_editor != NULL; }
19d7140e 717 bool HasReadWriteMode() const { return m_isReadOnly != Unset; }
b63fce94 718 bool HasOverflowMode() const { return m_overflow != UnsetOverflow; }
3100c3db 719 bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; }
b99be8fb 720
2796cce3
RD
721 const wxColour& GetTextColour() const;
722 const wxColour& GetBackgroundColour() const;
723 const wxFont& GetFont() const;
724 void GetAlignment(int *hAlign, int *vAlign) const;
27f35b66 725 void GetSize(int *num_rows, int *num_cols) const;
ef5df12b 726 bool GetOverflow() const
b63fce94 727 { return m_overflow != SingleCell; }
ef316e23
VZ
728 wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const;
729 wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const;
b99be8fb 730
19d7140e
VZ
731 bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; }
732
733 wxAttrKind GetKind() { return m_attrkind; }
283b7808 734
2796cce3 735 void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; }
ab79958a 736
338d1deb
VZ
737protected:
738 // the dtor is private because only DecRef() can delete us
739 virtual ~wxGridCellAttr()
740 {
741 wxSafeDecRef(m_renderer);
742 wxSafeDecRef(m_editor);
743 }
744
b99be8fb 745private:
19d7140e
VZ
746 enum wxAttrReadMode
747 {
748 Unset = -1,
749 ReadWrite,
750 ReadOnly
30bc4a8f 751 };
19d7140e 752
b63fce94
RD
753 enum wxAttrOverflowMode
754 {
755 UnsetOverflow = -1,
756 Overflow,
757 SingleCell
758 };
759
2e9a6788 760 // the common part of all ctors
1df4050d 761 void Init(wxGridCellAttr *attrDefault = NULL);
2e9a6788 762
2e9a6788
VZ
763
764 // the ref count - when it goes to 0, we die
765 size_t m_nRef;
766
b99be8fb
VZ
767 wxColour m_colText,
768 m_colBack;
769 wxFont m_font;
770 int m_hAlign,
771 m_vAlign;
27f35b66
SN
772 int m_sizeRows,
773 m_sizeCols;
ef5df12b
RD
774
775 wxAttrOverflowMode m_overflow;
2e9a6788 776
07296f0b
RD
777 wxGridCellRenderer* m_renderer;
778 wxGridCellEditor* m_editor;
779 wxGridCellAttr* m_defGridAttr;
ab79958a 780
19d7140e
VZ
781 wxAttrReadMode m_isReadOnly;
782
783 wxAttrKind m_attrkind;
283b7808 784
a68c1246 785 // use Clone() instead
7ef4c90b 786 DECLARE_NO_COPY_CLASS(wxGridCellAttr)
a68c1246 787
2e9a6788
VZ
788 // suppress the stupid gcc warning about the class having private dtor and
789 // no friends
790 friend class wxGridCellAttrDummyFriend;
b99be8fb
VZ
791};
792
793// ----------------------------------------------------------------------------
794// wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the
795// cell attributes.
796// ----------------------------------------------------------------------------
797
798// implementation note: we separate it from wxGridTableBase because we wish to
799// avoid deriving a new table class if possible, and sometimes it will be
800// enough to just derive another wxGridCellAttrProvider instead
758cbedf
VZ
801//
802// the default implementation is reasonably efficient for the generic case,
803// but you might still wish to implement your own for some specific situations
804// if you have performance problems with the stock one
12f190b0 805class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer
b99be8fb
VZ
806{
807public:
808 wxGridCellAttrProvider();
809 virtual ~wxGridCellAttrProvider();
810
2e9a6788 811 // DecRef() must be called on the returned pointer
19d7140e
VZ
812 virtual wxGridCellAttr *GetAttr(int row, int col,
813 wxGridCellAttr::wxAttrKind kind ) const;
2e9a6788 814
758cbedf
VZ
815 // all these functions take ownership of the pointer, don't call DecRef()
816 // on it
2e9a6788 817 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
758cbedf
VZ
818 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
819 virtual void SetColAttr(wxGridCellAttr *attr, int col);
d1c0b4f9
VZ
820
821 // these functions must be called whenever some rows/cols are deleted
822 // because the internal data must be updated then
4d60017a
SN
823 void UpdateAttrRows( size_t pos, int numRows );
824 void UpdateAttrCols( size_t pos, int numCols );
b99be8fb
VZ
825
826private:
827 void InitData();
828
829 wxGridCellAttrProviderData *m_data;
22f3361e
VZ
830
831 DECLARE_NO_COPY_CLASS(wxGridCellAttrProvider)
b99be8fb 832};
f85afd4e 833
10a4531d
VZ
834// ----------------------------------------------------------------------------
835// wxGridCellCoords: location of a cell in the grid
836// ----------------------------------------------------------------------------
837
838class WXDLLIMPEXP_ADV wxGridCellCoords
839{
840public:
841 wxGridCellCoords() { m_row = m_col = -1; }
842 wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; }
843
844 // default copy ctor is ok
845
846 int GetRow() const { return m_row; }
847 void SetRow( int n ) { m_row = n; }
848 int GetCol() const { return m_col; }
849 void SetCol( int n ) { m_col = n; }
850 void Set( int row, int col ) { m_row = row; m_col = col; }
851
852 wxGridCellCoords& operator=( const wxGridCellCoords& other )
853 {
854 if ( &other != this )
855 {
856 m_row=other.m_row;
857 m_col=other.m_col;
858 }
859 return *this;
860 }
861
862 bool operator==( const wxGridCellCoords& other ) const
863 {
864 return (m_row == other.m_row && m_col == other.m_col);
865 }
866
867 bool operator!=( const wxGridCellCoords& other ) const
868 {
869 return (m_row != other.m_row || m_col != other.m_col);
870 }
871
872 bool operator!() const
873 {
874 return (m_row == -1 && m_col == -1 );
875 }
876
877private:
878 int m_row;
879 int m_col;
880};
881
882
883// For comparisons...
f85afd4e 884//
10a4531d
VZ
885extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords;
886extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect;
887
888// An array of cell coords...
f85afd4e 889//
10a4531d
VZ
890WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray,
891 class WXDLLIMPEXP_ADV);
f85afd4e 892
10a4531d
VZ
893// ----------------------------------------------------------------------------
894// Grid table classes
895// ----------------------------------------------------------------------------
f85afd4e 896
10a4531d
VZ
897// the abstract base class
898class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject,
899 public wxClientDataContainer
f85afd4e 900{
60ff3b99 901public:
f85afd4e
MB
902 wxGridTableBase();
903 virtual ~wxGridTableBase();
904
905 // You must override these functions in a derived table class
906 //
77d2c45c
VZ
907
908 // return the number of rows and columns in this table
e32352cf
SN
909 virtual int GetNumberRows() = 0;
910 virtual int GetNumberCols() = 0;
77d2c45c
VZ
911
912 // the methods above are unfortunately non-const even though they should
913 // have been const -- but changing it now is not possible any longer as it
914 // would break the existing code overriding them, so instead we provide
915 // these const synonyms which can be used from const-correct code
916 int GetRowsCount() const
5c33522f 917 { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); }
77d2c45c 918 int GetColsCount() const
5c33522f 919 { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); }
77d2c45c
VZ
920
921
8acad210
VZ
922 virtual bool IsEmptyCell( int row, int col )
923 {
924 return GetValue(row, col).empty();
925 }
10a4531d
VZ
926
927 bool IsEmpty(const wxGridCellCoords& coord)
928 {
929 return IsEmptyCell(coord.GetRow(), coord.GetCol());
930 }
931
f2d76237
RD
932 virtual wxString GetValue( int row, int col ) = 0;
933 virtual void SetValue( int row, int col, const wxString& value ) = 0;
934
935 // Data type determination and value access
936 virtual wxString GetTypeName( int row, int col );
937 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
938 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
939
940 virtual long GetValueAsLong( int row, int col );
941 virtual double GetValueAsDouble( int row, int col );
942 virtual bool GetValueAsBool( int row, int col );
943
944 virtual void SetValueAsLong( int row, int col, long value );
945 virtual void SetValueAsDouble( int row, int col, double value );
946 virtual void SetValueAsBool( int row, int col, bool value );
947
948 // For user defined types
949 virtual void* GetValueAsCustom( int row, int col, const wxString& typeName );
950 virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value );
951
60ff3b99 952
f85afd4e
MB
953 // Overriding these is optional
954 //
955 virtual void SetView( wxGrid *grid ) { m_view = grid; }
956 virtual wxGrid * GetView() const { return m_view; }
957
958 virtual void Clear() {}
959 virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
960 virtual bool AppendRows( size_t numRows = 1 );
961 virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
962 virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 );
963 virtual bool AppendCols( size_t numCols = 1 );
964 virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
965
966 virtual wxString GetRowLabelValue( int row );
967 virtual wxString GetColLabelValue( int col );
af111fc3
JS
968 virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
969 virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
60ff3b99 970
b99be8fb
VZ
971 // Attribute handling
972 //
973
974 // give us the attr provider to use - we take ownership of the pointer
975 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
976
977 // get the currently used attr provider (may be NULL)
978 wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; }
979
f2d76237
RD
980 // Does this table allow attributes? Default implementation creates
981 // a wxGridCellAttrProvider if necessary.
982 virtual bool CanHaveAttributes();
983
b99be8fb 984 // by default forwarded to wxGridCellAttrProvider if any. May be
f2d76237 985 // overridden to handle attributes directly in the table.
19d7140e
VZ
986 virtual wxGridCellAttr *GetAttr( int row, int col,
987 wxGridCellAttr::wxAttrKind kind );
988
b99be8fb 989
758cbedf
VZ
990 // these functions take ownership of the pointer
991 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
992 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
993 virtual void SetColAttr(wxGridCellAttr *attr, int col);
b99be8fb 994
60ff3b99
VZ
995private:
996 wxGrid * m_view;
b99be8fb 997 wxGridCellAttrProvider *m_attrProvider;
60ff3b99 998
3839f37e 999 DECLARE_ABSTRACT_CLASS(wxGridTableBase)
22f3361e 1000 DECLARE_NO_COPY_CLASS(wxGridTableBase)
f85afd4e
MB
1001};
1002
1003
b99be8fb
VZ
1004// ----------------------------------------------------------------------------
1005// wxGridTableMessage
1006// ----------------------------------------------------------------------------
f85afd4e
MB
1007
1008// IDs for messages sent from grid table to view
1009//
60ff3b99
VZ
1010enum wxGridTableRequest
1011{
f85afd4e
MB
1012 wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000,
1013 wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES,
1014 wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
1015 wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
1016 wxGRIDTABLE_NOTIFY_ROWS_DELETED,
1017 wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1018 wxGRIDTABLE_NOTIFY_COLS_APPENDED,
1019 wxGRIDTABLE_NOTIFY_COLS_DELETED
1020};
1021
12f190b0 1022class WXDLLIMPEXP_ADV wxGridTableMessage
f85afd4e 1023{
60ff3b99 1024public:
f85afd4e
MB
1025 wxGridTableMessage();
1026 wxGridTableMessage( wxGridTableBase *table, int id,
1027 int comInt1 = -1,
1028 int comInt2 = -1 );
1029
1030 void SetTableObject( wxGridTableBase *table ) { m_table = table; }
1031 wxGridTableBase * GetTableObject() const { return m_table; }
1032 void SetId( int id ) { m_id = id; }
1033 int GetId() { return m_id; }
1034 void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; }
1035 int GetCommandInt() { return m_comInt1; }
1036 void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; }
60ff3b99
VZ
1037 int GetCommandInt2() { return m_comInt2; }
1038
1039private:
1040 wxGridTableBase *m_table;
1041 int m_id;
1042 int m_comInt1;
1043 int m_comInt2;
22f3361e
VZ
1044
1045 DECLARE_NO_COPY_CLASS(wxGridTableMessage)
f85afd4e
MB
1046};
1047
1048
1049
1050// ------ wxGridStringArray
1051// A 2-dimensional array of strings for data values
1052//
1053
160ba750
VS
1054WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray,
1055 class WXDLLIMPEXP_ADV);
2d66e025 1056
f85afd4e
MB
1057
1058
1059// ------ wxGridStringTable
1060//
1061// Simplest type of data table for a grid for small tables of strings
1062// that are stored in memory
1063//
1064
12f190b0 1065class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase
f85afd4e 1066{
60ff3b99 1067public:
f85afd4e
MB
1068 wxGridStringTable();
1069 wxGridStringTable( int numRows, int numCols );
e669d97a 1070 virtual ~wxGridStringTable();
f85afd4e
MB
1071
1072 // these are pure virtual in wxGridTableBase
1073 //
e32352cf
SN
1074 int GetNumberRows();
1075 int GetNumberCols();
f85afd4e
MB
1076 wxString GetValue( int row, int col );
1077 void SetValue( int row, int col, const wxString& s );
60ff3b99 1078
f85afd4e
MB
1079 // overridden functions from wxGridTableBase
1080 //
1081 void Clear();
1082 bool InsertRows( size_t pos = 0, size_t numRows = 1 );
1083 bool AppendRows( size_t numRows = 1 );
1084 bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
1085 bool InsertCols( size_t pos = 0, size_t numCols = 1 );
1086 bool AppendCols( size_t numCols = 1 );
1087 bool DeleteCols( size_t pos = 0, size_t numCols = 1 );
1088
1089 void SetRowLabelValue( int row, const wxString& );
1090 void SetColLabelValue( int col, const wxString& );
1091 wxString GetRowLabelValue( int row );
1092 wxString GetColLabelValue( int col );
60ff3b99
VZ
1093
1094private:
1095 wxGridStringArray m_data;
1096
1097 // These only get used if you set your own labels, otherwise the
1098 // GetRow/ColLabelValue functions return wxGridTableBase defaults
1099 //
1100 wxArrayString m_rowLabels;
1101 wxArrayString m_colLabels;
1102
fc7a2a60 1103 DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable )
f85afd4e
MB
1104};
1105
1106
1107
43947979 1108// ============================================================================
f85afd4e 1109// Grid view classes
43947979
VZ
1110// ============================================================================
1111
b99be8fb
VZ
1112// ----------------------------------------------------------------------------
1113// wxGrid
1114// ----------------------------------------------------------------------------
f85afd4e 1115
12f190b0 1116class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow
60ff3b99
VZ
1117{
1118public:
bf2c8b31
VZ
1119 // possible selection modes
1120 enum wxGridSelectionModes
1121 {
1122 wxGridSelectCells = 0, // allow selecting anything
1123 wxGridSelectRows = 1, // allow selecting only entire rows
1124 wxGridSelectColumns = 2, // allow selecting only entire columns
1125 wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns
1126 };
1127
1128 // creation and destruction
1129 // ------------------------
1130
1131 // ctor and Create() create the grid window, as with the other controls
ad805b9e 1132 wxGrid() { Init(); }
986a98c6 1133
bf2c8b31 1134 wxGrid(wxWindow *parent,
986a98c6
SC
1135 wxWindowID id,
1136 const wxPoint& pos = wxDefaultPosition,
1137 const wxSize& size = wxDefaultSize,
1138 long style = wxWANTS_CHARS,
ad805b9e
VZ
1139 const wxString& name = wxGridNameStr)
1140 {
1141 Init();
1142
1143 Create(parent, id, pos, size, style, name);
1144 }
60ff3b99 1145
bf2c8b31
VZ
1146 bool Create(wxWindow *parent,
1147 wxWindowID id,
1148 const wxPoint& pos = wxDefaultPosition,
1149 const wxSize& size = wxDefaultSize,
1150 long style = wxWANTS_CHARS,
1151 const wxString& name = wxGridNameStr);
2d66e025 1152
e669d97a 1153 virtual ~wxGrid();
f85afd4e 1154
bf2c8b31
VZ
1155 // however to initialize grid data either CreateGrid() or SetTable() must
1156 // be also called
b5808881 1157
bf2c8b31
VZ
1158 // this is basically equivalent to
1159 //
1160 // SetTable(new wxGridStringTable(numRows, numCols), true, selmode)
1161 //
b5808881 1162 bool CreateGrid( int numRows, int numCols,
801a9641 1163 wxGridSelectionModes selmode = wxGridSelectCells );
2d66e025 1164
bf2c8b31
VZ
1165 bool SetTable( wxGridTableBase *table,
1166 bool takeOwnership = false,
1167 wxGridSelectionModes selmode = wxGridSelectCells );
1168
8a3e536c
VZ
1169 bool ProcessTableMessage(wxGridTableMessage&);
1170
1171 wxGridTableBase *GetTable() const { return m_table; }
1172
bf2c8b31 1173
801a9641
VZ
1174 void SetSelectionMode(wxGridSelectionModes selmode);
1175 wxGridSelectionModes GetSelectionMode() const;
60ff3b99 1176
2d66e025
MB
1177 // ------ grid dimensions
1178 //
ef316e23
VZ
1179 int GetNumberRows() const { return m_numRows; }
1180 int GetNumberCols() const { return m_numCols; }
2d66e025 1181
60ff3b99 1182
2d66e025
MB
1183 // ------ display update functions
1184 //
ef316e23 1185 wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const;
8fb66724 1186
ef316e23
VZ
1187 wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const;
1188 wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const;
60ff3b99 1189
2d66e025 1190
f85afd4e 1191 void ClearGrid();
10a4531d
VZ
1192 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true)
1193 {
1194 return DoModifyLines(&wxGridTableBase::InsertRows,
1195 pos, numRows, updateLabels);
1196 }
1197 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true)
1198 {
1199 return DoModifyLines(&wxGridTableBase::InsertCols,
1200 pos, numCols, updateLabels);
1201 }
1202
1203 bool AppendRows(int numRows = 1, bool updateLabels = true)
1204 {
1205 return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels);
1206 }
1207 bool AppendCols(int numCols = 1, bool updateLabels = true)
1208 {
1209 return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels);
1210 }
1211
1212 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true)
1213 {
1214 return DoModifyLines(&wxGridTableBase::DeleteRows,
1215 pos, numRows, updateLabels);
1216 }
1217 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true)
1218 {
1219 return DoModifyLines(&wxGridTableBase::DeleteCols,
1220 pos, numCols, updateLabels);
1221 }
f85afd4e 1222
d10f4bf9 1223 void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells );
7c8a8ad5 1224 void DrawGridSpace( wxDC& dc );
2d66e025 1225 void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
4634a5d6 1226 void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
2d66e025 1227 void DrawCell( wxDC& dc, const wxGridCellCoords& );
d10f4bf9 1228 void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells);
d16c04bb
VZ
1229
1230 // this function is called when the current cell highlight must be redrawn
1231 // and may be overridden by the user
1232 virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr );
1f1ce288 1233
6914b57a
JS
1234 virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows );
1235 virtual void DrawRowLabel( wxDC& dc, int row );
8fb66724 1236
6914b57a
JS
1237 virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols );
1238 virtual void DrawColLabel( wxDC& dc, int col );
60ff3b99 1239
ff72f628 1240 virtual void DrawCornerLabel(wxDC& dc);
f85afd4e 1241
2d66e025 1242 // ------ Cell text drawing functions
f85afd4e 1243 //
2d66e025 1244 void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
4c7277db 1245 int horizontalAlignment = wxALIGN_LEFT,
d43851f7
JS
1246 int verticalAlignment = wxALIGN_TOP,
1247 int textOrientation = wxHORIZONTAL );
30bc4a8f 1248
d10f4bf9
VZ
1249 void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
1250 int horizontalAlignment = wxALIGN_LEFT,
d43851f7
JS
1251 int verticalAlignment = wxALIGN_TOP,
1252 int textOrientation = wxHORIZONTAL );
d10f4bf9 1253
f85afd4e 1254
ef316e23 1255 // Split a string containing newline characters into an array of
2d66e025
MB
1256 // strings and return the number of lines
1257 //
ef316e23 1258 void StringToLines( const wxString& value, wxArrayString& lines ) const;
60ff3b99 1259
fbfb8bcc 1260 void GetTextBoxSize( const wxDC& dc,
d10f4bf9 1261 const wxArrayString& lines,
ef316e23 1262 long *width, long *height ) const;
60ff3b99 1263
2d66e025 1264
f85afd4e
MB
1265 // ------
1266 // Code that does a lot of grid modification can be enclosed
1267 // between BeginBatch() and EndBatch() calls to avoid screen
1268 // flicker
1269 //
1270 void BeginBatch() { m_batchCount++; }
f6bcfd97
BP
1271 void EndBatch();
1272
f85afd4e
MB
1273 int GetBatchCount() { return m_batchCount; }
1274
8a3e536c 1275 virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL);
27f35b66 1276
d8232393
MB
1277 // Use this, rather than wxWindow::Refresh(), to force an
1278 // immediate repainting of the grid. Has no effect if you are
1279 // already inside a BeginBatch / EndBatch block.
1280 //
1281 // This function is necessary because wxGrid has a minimal OnPaint()
1282 // handler to reduce screen flicker.
1283 //
1284 void ForceRefresh();
d2520c85 1285
2d66e025
MB
1286
1287 // ------ edit control functions
1288 //
84035150 1289 bool IsEditable() const { return m_editable; }
2d66e025
MB
1290 void EnableEditing( bool edit );
1291
ca65c044
WS
1292 void EnableCellEditControl( bool enable = true );
1293 void DisableCellEditControl() { EnableCellEditControl(false); }
b54ba671
VZ
1294 bool CanEnableCellControl() const;
1295 bool IsCellEditControlEnabled() const;
f6bcfd97 1296 bool IsCellEditControlShown() const;
2d66e025 1297
b54ba671 1298 bool IsCurrentCellReadOnly() const;
2d66e025 1299
2d66e025
MB
1300 void ShowCellEditControl();
1301 void HideCellEditControl();
2d66e025
MB
1302 void SaveEditControlValue();
1303
60ff3b99 1304
2d66e025 1305 // ------ grid location functions
60ff3b99 1306 // Note that all of these functions work with the logical coordinates of
2d66e025
MB
1307 // grid cells and labels so you will need to convert from device
1308 // coordinates for mouse events etc.
1309 //
8a3e536c
VZ
1310 wxGridCellCoords XYToCell(int x, int y) const;
1311 void XYToCell(int x, int y, wxGridCellCoords& coords) const
1312 { coords = XYToCell(x, y); }
1313 wxGridCellCoords XYToCell(const wxPoint& pos) const
1314 { return XYToCell(pos.x, pos.y); }
1315
cd4f6f5f
VZ
1316 // these functions return the index of the row/columns corresponding to the
1317 // given logical position in pixels
1318 //
1319 // if clipToMinMax is false (default, wxNOT_FOUND is returned if the
1320 // position is outside any row/column, otherwise the first/last element is
1321 // returned in this case
bec70262 1322 int YToRow( int y, bool clipToMinMax = false ) const;
ef316e23 1323 int XToCol( int x, bool clipToMinMax = false ) const;
2d66e025 1324
ef316e23
VZ
1325 int YToEdgeOfRow( int y ) const;
1326 int XToEdgeOfCol( int x ) const;
2d66e025 1327
ef316e23
VZ
1328 wxRect CellToRect( int row, int col ) const;
1329 wxRect CellToRect( const wxGridCellCoords& coords ) const
2d66e025
MB
1330 { return CellToRect( coords.GetRow(), coords.GetCol() ); }
1331
ef316e23
VZ
1332 int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); }
1333 int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); }
60ff3b99 1334
2d66e025
MB
1335 // check to see if a cell is either wholly visible (the default arg) or
1336 // at least partially visible in the grid window
1337 //
ef316e23
VZ
1338 bool IsVisible( int row, int col, bool wholeCellVisible = true ) const;
1339 bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const
2d66e025
MB
1340 { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); }
1341 void MakeCellVisible( int row, int col );
1342 void MakeCellVisible( const wxGridCellCoords& coords )
1343 { MakeCellVisible( coords.GetRow(), coords.GetCol() ); }
1344
60ff3b99 1345
2d66e025
MB
1346 // ------ grid cursor movement functions
1347 //
8a3e536c
VZ
1348 void SetGridCursor(int row, int col) { SetCurrentCell(row, col); }
1349 void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); }
1350
1351 void GoToCell(int row, int col)
1352 {
1353 if ( SetCurrentCell(row, col) )
1354 MakeCellVisible(row, col);
1355 }
1356
1357 void GoToCell(const wxGridCellCoords& coords)
1358 {
1359 if ( SetCurrentCell(coords) )
1360 MakeCellVisible(coords);
1361 }
dfaf42d2 1362
5c8fc7c1
SN
1363 bool MoveCursorUp( bool expandSelection );
1364 bool MoveCursorDown( bool expandSelection );
1365 bool MoveCursorLeft( bool expandSelection );
1366 bool MoveCursorRight( bool expandSelection );
2d66e025
MB
1367 bool MovePageDown();
1368 bool MovePageUp();
5c8fc7c1
SN
1369 bool MoveCursorUpBlock( bool expandSelection );
1370 bool MoveCursorDownBlock( bool expandSelection );
1371 bool MoveCursorLeftBlock( bool expandSelection );
1372 bool MoveCursorRightBlock( bool expandSelection );
2d66e025 1373
60ff3b99 1374
f85afd4e
MB
1375 // ------ label and gridline formatting
1376 //
ef316e23
VZ
1377 int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; }
1378 int GetRowLabelSize() const { return m_rowLabelWidth; }
1379 int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; }
1380 int GetColLabelSize() const { return m_colLabelHeight; }
1381 wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; }
1382 wxColour GetLabelTextColour() const { return m_labelTextColour; }
1383 wxFont GetLabelFont() const { return m_labelFont; }
1384 void GetRowLabelAlignment( int *horiz, int *vert ) const;
1385 void GetColLabelAlignment( int *horiz, int *vert ) const;
1386 int GetColLabelTextOrientation() const;
1387 wxString GetRowLabelValue( int row ) const;
1388 wxString GetColLabelValue( int col ) const;
3d3f3e37 1389
ef316e23
VZ
1390 wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
1391 int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
1392 int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; }
f85afd4e 1393
ad805b9e
VZ
1394 // this one will use wxHeaderCtrl for the column labels
1395 void UseNativeColHeader(bool native = true);
1396
1397 // this one will still draw them manually but using the native renderer
1398 // instead of using the same appearance as for the row labels
1399 void SetUseNativeColLabels( bool native = true );
1400
ab79958a 1401 void SetRowLabelSize( int width );
f85afd4e 1402 void SetColLabelSize( int height );
0a9ca9c4
RR
1403 void HideRowLabels() { SetRowLabelSize( 0 ); }
1404 void HideColLabels() { SetColLabelSize( 0 ); }
f85afd4e
MB
1405 void SetLabelBackgroundColour( const wxColour& );
1406 void SetLabelTextColour( const wxColour& );
1407 void SetLabelFont( const wxFont& );
1408 void SetRowLabelAlignment( int horiz, int vert );
1409 void SetColLabelAlignment( int horiz, int vert );
d43851f7 1410 void SetColLabelTextOrientation( int textOrientation );
f85afd4e
MB
1411 void SetRowLabelValue( int row, const wxString& );
1412 void SetColLabelValue( int col, const wxString& );
f6bcfd97 1413 void SetCellHighlightColour( const wxColour& );
d2520c85
RD
1414 void SetCellHighlightPenWidth(int width);
1415 void SetCellHighlightROPenWidth(int width);
28a77bc4 1416
ca65c044
WS
1417 void EnableDragRowSize( bool enable = true );
1418 void DisableDragRowSize() { EnableDragRowSize( false ); }
ef316e23 1419 bool CanDragRowSize() const { return m_canDragRowSize; }
ca65c044
WS
1420 void EnableDragColSize( bool enable = true );
1421 void DisableDragColSize() { EnableDragColSize( false ); }
ef316e23 1422 bool CanDragColSize() const { return m_canDragColSize; }
d4175745
VZ
1423 void EnableDragColMove( bool enable = true );
1424 void DisableDragColMove() { EnableDragColMove( false ); }
ef316e23 1425 bool CanDragColMove() const { return m_canDragColMove; }
ca65c044
WS
1426 void EnableDragGridSize(bool enable = true);
1427 void DisableDragGridSize() { EnableDragGridSize(false); }
ef316e23 1428 bool CanDragGridSize() const { return m_canDragGridSize; }
4cfa5de6 1429
79dbea21
RD
1430 void EnableDragCell( bool enable = true );
1431 void DisableDragCell() { EnableDragCell( false ); }
ef316e23 1432 bool CanDragCell() const { return m_canDragCell; }
79dbea21 1433
9f7aee01
VZ
1434
1435 // grid lines
1436 // ----------
1437
1438 // enable or disable drawing of the lines
1439 void EnableGridLines(bool enable = true);
1440 bool GridLinesEnabled() const { return m_gridLinesEnabled; }
1441
1442 // by default grid lines stop at last column/row, but this may be changed
1443 void ClipHorzGridLines(bool clip)
1444 { DoClipGridLines(m_gridLinesClipHorz, clip); }
1445 void ClipVertGridLines(bool clip)
1446 { DoClipGridLines(m_gridLinesClipVert, clip); }
1447 bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; }
1448 bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; }
1449
1450 // this can be used to change the global grid lines colour
1451 void SetGridLineColour(const wxColour& col);
1452 wxColour GetGridLineColour() const { return m_gridLineColour; }
1453
1454 // these methods may be overridden to customize individual grid lines
1455 // appearance
1456 virtual wxPen GetDefaultGridLinePen();
1457 virtual wxPen GetRowGridLinePen(int row);
1458 virtual wxPen GetColGridLinePen(int col);
1459
1460
1461 // attributes
1462 // ----------
1463
27f35b66
SN
1464 // this sets the specified attribute for this cell or in this row/col
1465 void SetAttr(int row, int col, wxGridCellAttr *attr);
758cbedf
VZ
1466 void SetRowAttr(int row, wxGridCellAttr *attr);
1467 void SetColAttr(int col, wxGridCellAttr *attr);
1468
71e60f70
RD
1469 // returns the attribute we may modify in place: a new one if this cell
1470 // doesn't have any yet or the existing one if it does
1471 //
1472 // DecRef() must be called on the returned pointer, as usual
1473 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
1474
d94c09cd 1475
0b190b0f
VZ
1476 // shortcuts for setting the column parameters
1477
1478 // set the format for the data in the column: default is string
1479 void SetColFormatBool(int col);
1480 void SetColFormatNumber(int col);
1481 void SetColFormatFloat(int col, int width = -1, int precision = -1);
1482 void SetColFormatCustom(int col, const wxString& typeName);
1483
f85afd4e
MB
1484 // ------ row and col formatting
1485 //
ef316e23
VZ
1486 int GetDefaultRowSize() const;
1487 int GetRowSize( int row ) const;
1488 int GetDefaultColSize() const;
1489 int GetColSize( int col ) const;
1490 wxColour GetDefaultCellBackgroundColour() const;
1491 wxColour GetCellBackgroundColour( int row, int col ) const;
1492 wxColour GetDefaultCellTextColour() const;
1493 wxColour GetCellTextColour( int row, int col ) const;
1494 wxFont GetDefaultCellFont() const;
1495 wxFont GetCellFont( int row, int col ) const;
1496 void GetDefaultCellAlignment( int *horiz, int *vert ) const;
1497 void GetCellAlignment( int row, int col, int *horiz, int *vert ) const;
1498 bool GetDefaultCellOverflow() const;
1499 bool GetCellOverflow( int row, int col ) const;
1500 void GetCellSize( int row, int col, int *num_rows, int *num_cols ) const;
bec70262
VZ
1501 wxSize GetCellSize(const wxGridCellCoords& coords)
1502 {
1503 wxSize s;
1504 GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y);
1505 return s;
1506 }
60ff3b99 1507
009c7216 1508 // ------ row and col sizes
ca65c044 1509 void SetDefaultRowSize( int height, bool resizeExistingRows = false );
f85afd4e 1510 void SetRowSize( int row, int height );
009c7216
VZ
1511 void HideRow(int row) { SetRowSize(row, 0); }
1512 void ShowRow(int row) { SetRowSize(row, -1); }
8fb66724 1513
009c7216 1514 void SetDefaultColSize( int width, bool resizeExistingCols = false );
f85afd4e 1515 void SetColSize( int col, int width );
009c7216
VZ
1516 void HideCol(int col) { SetColSize(col, 0); }
1517 void ShowCol(int col) { SetColSize(col, -1); }
1518
1519
1520 // ------- columns (only, for now) reordering
43947979 1521
cd4f6f5f
VZ
1522 // columns index <-> positions mapping: by default, the position of the
1523 // column is the same as its index, but the columns can also be reordered
1524 // (either by calling SetColPos() explicitly or by the user dragging the
1525 // columns around) in which case their indices don't correspond to their
1526 // positions on display any longer
1527 //
1528 // internally we always work with indices except for the functions which
1529 // have "Pos" in their names (and which work with columns, not pixels) and
1530 // only the display and hit testing code really cares about display
1531 // positions at all
1532
1533 // return the column index corresponding to the given (valid) position
1534 int GetColAt(int pos) const
d4175745 1535 {
cd4f6f5f 1536 return m_colAt.empty() ? pos : m_colAt[pos];
d4175745
VZ
1537 }
1538
cd4f6f5f
VZ
1539 // reorder the columns so that the column with the given index is now shown
1540 // as the position pos
1541 void SetColPos(int idx, int pos);
d4175745 1542
cd4f6f5f
VZ
1543 // return the position at which the column with the given index is
1544 // displayed: notice that this is a slow operation as we don't maintain the
1545 // reverse mapping currently
1546 int GetColPos(int idx) const
d4175745
VZ
1547 {
1548 if ( m_colAt.IsEmpty() )
cd4f6f5f
VZ
1549 return idx;
1550
1551 for ( int i = 0; i < m_numCols; i++ )
d4175745 1552 {
cd4f6f5f
VZ
1553 if ( m_colAt[i] == idx )
1554 return i;
d4175745
VZ
1555 }
1556
cd4f6f5f
VZ
1557 wxFAIL_MSG( "invalid column index" );
1558
1559 return wxNOT_FOUND;
d4175745
VZ
1560 }
1561
009c7216
VZ
1562 // reset the columns positions to the default order
1563 void ResetColPos();
cd4f6f5f
VZ
1564
1565
af547d51 1566 // automatically size the column or row to fit to its contents, if
ca65c044 1567 // setAsMin is true, this optimal width will also be set as minimal width
af547d51 1568 // for this column
ca65c044 1569 void AutoSizeColumn( int col, bool setAsMin = true )
733f486a 1570 { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); }
ca65c044 1571 void AutoSizeRow( int row, bool setAsMin = true )
733f486a 1572 { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); }
65e4e78e
VZ
1573
1574 // auto size all columns (very ineffective for big grids!)
ca65c044
WS
1575 void AutoSizeColumns( bool setAsMin = true )
1576 { (void)SetOrCalcColumnSizes(false, setAsMin); }
65e4e78e 1577
ca65c044
WS
1578 void AutoSizeRows( bool setAsMin = true )
1579 { (void)SetOrCalcRowSizes(false, setAsMin); }
57c086ef
VZ
1580
1581 // auto size the grid, that is make the columns/rows of the "right" size
1582 // and also set the grid size to just fit its contents
1583 void AutoSize();
1584
733f486a
VZ
1585 // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize:
1586 // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column
1587 // instead of data column. Note that this operation may be slow for large
1588 // tables.
d43851f7
JS
1589 // autosize row height depending on label text
1590 void AutoSizeRowLabelSize( int row );
1591
1592 // autosize column width depending on label text
1593 void AutoSizeColLabelSize( int col );
1594
43947979
VZ
1595 // column won't be resized to be lesser width - this must be called during
1596 // the grid creation because it won't resize the column if it's already
1597 // narrower than the minimal width
1598 void SetColMinimalWidth( int col, int width );
af547d51 1599 void SetRowMinimalHeight( int row, int width );
43947979 1600
b8d24d4e
RG
1601 /* These members can be used to query and modify the minimal
1602 * acceptable size of grid rows and columns. Call this function in
1603 * your code which creates the grid if you want to display cells
1604 * with a size smaller than the default acceptable minimum size.
1605 * Like the members SetColMinimalWidth and SetRowMinimalWidth,
1606 * the existing rows or columns will not be checked/resized.
1607 */
1608 void SetColMinimalAcceptableWidth( int width );
1609 void SetRowMinimalAcceptableHeight( int width );
1610 int GetColMinimalAcceptableWidth() const;
1611 int GetRowMinimalAcceptableHeight() const;
1612
f85afd4e
MB
1613 void SetDefaultCellBackgroundColour( const wxColour& );
1614 void SetCellBackgroundColour( int row, int col, const wxColour& );
1615 void SetDefaultCellTextColour( const wxColour& );
8fb66724 1616
f85afd4e 1617 void SetCellTextColour( int row, int col, const wxColour& );
f85afd4e
MB
1618 void SetDefaultCellFont( const wxFont& );
1619 void SetCellFont( int row, int col, const wxFont& );
1620 void SetDefaultCellAlignment( int horiz, int vert );
1621 void SetCellAlignment( int row, int col, int horiz, int vert );
27f35b66
SN
1622 void SetDefaultCellOverflow( bool allow );
1623 void SetCellOverflow( int row, int col, bool allow );
1624 void SetCellSize( int row, int col, int num_rows, int num_cols );
f85afd4e 1625
ab79958a 1626 // takes ownership of the pointer
2796cce3 1627 void SetDefaultRenderer(wxGridCellRenderer *renderer);
ab79958a 1628 void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer);
2796cce3 1629 wxGridCellRenderer *GetDefaultRenderer() const;
ef316e23 1630 wxGridCellRenderer* GetCellRenderer(int row, int col) const;
2796cce3 1631
283b7808 1632 // takes ownership of the pointer
0ba143c9 1633 void SetDefaultEditor(wxGridCellEditor *editor);
9b4aede2 1634 void SetCellEditor(int row, int col, wxGridCellEditor *editor);
0ba143c9 1635 wxGridCellEditor *GetDefaultEditor() const;
ef316e23 1636 wxGridCellEditor* GetCellEditor(int row, int col) const;
9b4aede2 1637
60a67569 1638
f2d76237 1639
f85afd4e
MB
1640 // ------ cell value accessors
1641 //
ef316e23 1642 wxString GetCellValue( int row, int col ) const
f85afd4e
MB
1643 {
1644 if ( m_table )
1645 {
1646 return m_table->GetValue( row, col );
1647 }
1648 else
1649 {
1650 return wxEmptyString;
1651 }
1652 }
1653
ef316e23 1654 wxString GetCellValue( const wxGridCellCoords& coords ) const
f85afd4e 1655 { return GetCellValue( coords.GetRow(), coords.GetCol() ); }
60ff3b99 1656
f85afd4e
MB
1657 void SetCellValue( int row, int col, const wxString& s );
1658 void SetCellValue( const wxGridCellCoords& coords, const wxString& s )
1659 { SetCellValue( coords.GetRow(), coords.GetCol(), s ); }
f85afd4e 1660
ca65c044 1661 // returns true if the cell can't be edited
283b7808 1662 bool IsReadOnly(int row, int col) const;
60ff3b99 1663
283b7808 1664 // make the cell editable/readonly
ca65c044 1665 void SetReadOnly(int row, int col, bool isReadOnly = true);
f85afd4e 1666
aa5b8857 1667 // ------ select blocks of cells
f85afd4e 1668 //
ca65c044
WS
1669 void SelectRow( int row, bool addToSelected = false );
1670 void SelectCol( int col, bool addToSelected = false );
60ff3b99 1671
c9097836 1672 void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
ca65c044 1673 bool addToSelected = false );
f85afd4e
MB
1674
1675 void SelectBlock( const wxGridCellCoords& topLeft,
c9097836 1676 const wxGridCellCoords& bottomRight,
ca65c044 1677 bool addToSelected = false )
f85afd4e 1678 { SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
c9097836
MB
1679 bottomRight.GetRow(), bottomRight.GetCol(),
1680 addToSelected ); }
f85afd4e
MB
1681
1682 void SelectAll();
60ff3b99 1683
ef316e23 1684 bool IsSelection() const;
f85afd4e 1685
aa5b8857 1686 // ------ deselect blocks or cells
f7b4b343
VZ
1687 //
1688 void DeselectRow( int row );
1689 void DeselectCol( int col );
1690 void DeselectCell( int row, int col );
1691
f85afd4e
MB
1692 void ClearSelection();
1693
84035150 1694 bool IsInSelection( int row, int col ) const;
f85afd4e 1695
84035150 1696 bool IsInSelection( const wxGridCellCoords& coords ) const
f85afd4e
MB
1697 { return IsInSelection( coords.GetRow(), coords.GetCol() ); }
1698
aa5b8857
SN
1699 wxGridCellCoordsArray GetSelectedCells() const;
1700 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
1701 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
1702 wxArrayInt GetSelectedRows() const;
1703 wxArrayInt GetSelectedCols() const;
c3baf426
SN
1704
1705 // This function returns the rectangle that encloses the block of cells
1706 // limited by TopLeft and BottomRight cell in device coords and clipped
1707 // to the client size of the grid window.
1708 //
58dd5b3b 1709 wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft,
ef316e23 1710 const wxGridCellCoords & bottomRight ) const;
c3baf426 1711
2796cce3
RD
1712 // Access or update the selection fore/back colours
1713 wxColour GetSelectionBackground() const
1714 { return m_selectionBackground; }
1715 wxColour GetSelectionForeground() const
1716 { return m_selectionForeground; }
1717
1718 void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; }
1719 void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; }
1720
1721
f2d76237
RD
1722 // Methods for a registry for mapping data types to Renderers/Editors
1723 void RegisterDataType(const wxString& typeName,
1724 wxGridCellRenderer* renderer,
1725 wxGridCellEditor* editor);
73145b0e
JS
1726 // DJC MAPTEK
1727 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
99306db2
VZ
1728 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
1729 { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); }
73145b0e
JS
1730 virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
1731 virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
1732 virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
f2d76237 1733
266e8367
VZ
1734 // grid may occupy more space than needed for its rows/columns, this
1735 // function allows to set how big this extra space is
1736 void SetMargins(int extraWidth, int extraHeight)
1737 {
1738 m_extraWidth = extraWidth;
1739 m_extraHeight = extraHeight;
b8125adf
VZ
1740
1741 CalcDimensions();
266e8367 1742 }
f85afd4e 1743
d2520c85 1744 // Accessors for component windows
ef316e23
VZ
1745 wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; }
1746 wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; }
ad805b9e 1747 wxWindow* GetGridColLabelWindow() const { return m_colWindow; }
ef316e23 1748 wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; }
d2520c85 1749
608754c4
JS
1750 // Allow adjustment of scroll increment. The default is (15, 15).
1751 void SetScrollLineX(int x) { m_scrollLineX = x; }
1752 void SetScrollLineY(int y) { m_scrollLineY = y; }
1753 int GetScrollLineX() const { return m_scrollLineX; }
1754 int GetScrollLineY() const { return m_scrollLineY; }
1755
1edce33f
VZ
1756 // ------- drag and drop
1757#if wxUSE_DRAG_AND_DROP
1758 virtual void SetDropTarget(wxDropTarget *dropTarget);
1759#endif // wxUSE_DRAG_AND_DROP
bf646121 1760
bf2c8b31 1761
11393d29
VZ
1762 // ------- sorting support
1763
1764 // wxGrid doesn't support sorting on its own but it can indicate the sort
1765 // order in the column header (currently only if native header control is
1766 // used though)
1767
1768 // return the column currently displaying the sort indicator or wxNOT_FOUND
1769 // if none
1770 int GetSortingColumn() const { return m_sortCol; }
1771
1772 // return true if this column is currently used for sorting
1773 bool IsSortingBy(int col) const { return GetSortingColumn() == col; }
1774
1775 // return the current sorting order (on GetSortingColumn()): true for
1776 // ascending sort and false for descending; it doesn't make sense to call
1777 // it if GetSortingColumn() returns wxNOT_FOUND
1778 bool IsSortOrderAscending() const { return m_sortIsAscending; }
1779
1780 // set the sorting column (or unsets any existing one if wxNOT_FOUND) and
1781 // the order in which to sort
1782 void SetSortingColumn(int col, bool ascending = true);
1783
1784 // unset any existing sorting column
1785 void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); }
1786
bf2c8b31 1787#ifdef WXWIN_COMPATIBILITY_2_8
f85afd4e
MB
1788 // ------ For compatibility with previous wxGrid only...
1789 //
1790 // ************************************************
1791 // ** Don't use these in new code because they **
1792 // ** are liable to disappear in a future **
1793 // ** revision **
1794 // ************************************************
1795 //
1796
1797 wxGrid( wxWindow *parent,
422d0ff0 1798 int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord,
ebd773c6 1799 long style = wxWANTS_CHARS,
f85afd4e 1800 const wxString& name = wxPanelNameStr )
ad805b9e
VZ
1801 {
1802 Init();
1803 Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name);
1804 }
f85afd4e
MB
1805
1806 void SetCellValue( const wxString& val, int row, int col )
1807 { SetCellValue( row, col, val ); }
60ff3b99 1808
f85afd4e
MB
1809 void UpdateDimensions()
1810 { CalcDimensions(); }
1811
ef316e23
VZ
1812 int GetRows() const { return GetNumberRows(); }
1813 int GetCols() const { return GetNumberCols(); }
1814 int GetCursorRow() const { return GetGridCursorRow(); }
1815 int GetCursorColumn() const { return GetGridCursorCol(); }
60ff3b99 1816
ef316e23
VZ
1817 int GetScrollPosX() const { return 0; }
1818 int GetScrollPosY() const { return 0; }
60ff3b99 1819
aa5e1f75
SN
1820 void SetScrollX( int WXUNUSED(x) ) { }
1821 void SetScrollY( int WXUNUSED(y) ) { }
f85afd4e
MB
1822
1823 void SetColumnWidth( int col, int width )
1824 { SetColSize( col, width ); }
60ff3b99 1825
ef316e23 1826 int GetColumnWidth( int col ) const
f85afd4e 1827 { return GetColSize( col ); }
60ff3b99 1828
f85afd4e
MB
1829 void SetRowHeight( int row, int height )
1830 { SetRowSize( row, height ); }
60ff3b99 1831
7c1cb261 1832 // GetRowHeight() is below
60ff3b99 1833
ef316e23 1834 int GetViewHeight() const // returned num whole rows visible
2d66e025 1835 { return 0; }
60ff3b99 1836
ef316e23 1837 int GetViewWidth() const // returned num whole cols visible
2d66e025 1838 { return 0; }
f85afd4e
MB
1839
1840 void SetLabelSize( int orientation, int sz )
1841 {
1842 if ( orientation == wxHORIZONTAL )
1843 SetColLabelSize( sz );
1844 else
1845 SetRowLabelSize( sz );
1846 }
1847
ef316e23 1848 int GetLabelSize( int orientation ) const
f85afd4e
MB
1849 {
1850 if ( orientation == wxHORIZONTAL )
1851 return GetColLabelSize();
1852 else
1853 return GetRowLabelSize();
1854 }
1855
1856 void SetLabelAlignment( int orientation, int align )
1857 {
1858 if ( orientation == wxHORIZONTAL )
1859 SetColLabelAlignment( align, -1 );
1860 else
1861 SetRowLabelAlignment( align, -1 );
1862 }
1863
ef316e23 1864 int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const
f85afd4e
MB
1865 {
1866 int h, v;
1867 if ( orientation == wxHORIZONTAL )
1868 {
1869 GetColLabelAlignment( &h, &v );
1870 return h;
1871 }
1872 else
1873 {
1874 GetRowLabelAlignment( &h, &v );
1875 return h;
1876 }
1877 }
1878
1879 void SetLabelValue( int orientation, const wxString& val, int pos )
1880 {
1881 if ( orientation == wxHORIZONTAL )
1882 SetColLabelValue( pos, val );
1883 else
1884 SetRowLabelValue( pos, val );
1885 }
60ff3b99 1886
ef316e23 1887 wxString GetLabelValue( int orientation, int pos) const
f85afd4e
MB
1888 {
1889 if ( orientation == wxHORIZONTAL )
1890 return GetColLabelValue( pos );
1891 else
1892 return GetRowLabelValue( pos );
1893 }
1894
60ff3b99 1895 wxFont GetCellTextFont() const
2796cce3 1896 { return m_defaultCellAttr->GetFont(); }
60ff3b99 1897
af111fc3 1898 wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const
2796cce3 1899 { return m_defaultCellAttr->GetFont(); }
60ff3b99 1900
f85afd4e
MB
1901 void SetCellTextFont(const wxFont& fnt)
1902 { SetDefaultCellFont( fnt ); }
60ff3b99 1903
f85afd4e
MB
1904 void SetCellTextFont(const wxFont& fnt, int row, int col)
1905 { SetCellFont( row, col, fnt ); }
60ff3b99 1906
f85afd4e
MB
1907 void SetCellTextColour(const wxColour& val, int row, int col)
1908 { SetCellTextColour( row, col, val ); }
60ff3b99 1909
f85afd4e
MB
1910 void SetCellTextColour(const wxColour& col)
1911 { SetDefaultCellTextColour( col ); }
60ff3b99 1912
f85afd4e
MB
1913 void SetCellBackgroundColour(const wxColour& col)
1914 { SetDefaultCellBackgroundColour( col ); }
60ff3b99 1915
f85afd4e
MB
1916 void SetCellBackgroundColour(const wxColour& colour, int row, int col)
1917 { SetCellBackgroundColour( row, col, colour ); }
60ff3b99 1918
ef316e23 1919 bool GetEditable() const { return IsEditable(); }
ca65c044 1920 void SetEditable( bool edit = true ) { EnableEditing( edit ); }
ef316e23 1921 bool GetEditInPlace() const { return IsCellEditControlEnabled(); }
8fb66724 1922
ca65c044 1923 void SetEditInPlace(bool WXUNUSED(edit) = true) { }
f85afd4e 1924
60a67569 1925 void SetCellAlignment( int align, int row, int col)
4c7277db 1926 { SetCellAlignment(row, col, align, wxALIGN_CENTER); }
60a67569
JS
1927 void SetCellAlignment( int WXUNUSED(align) ) {}
1928 void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col))
1929 { }
1930 void SetDividerPen(const wxPen& WXUNUSED(pen)) { }
6fc0f38f 1931 wxPen& GetDividerPen() const;
60a67569 1932 void OnActivate(bool WXUNUSED(active)) {}
60ff3b99 1933
f85afd4e
MB
1934 // ******** End of compatibility functions **********
1935
2d66e025
MB
1936
1937
f85afd4e 1938 // ------ control IDs
2d66e025 1939 enum { wxGRID_CELLCTRL = 2000,
f85afd4e
MB
1940 wxGRID_TOPCTRL };
1941
1942 // ------ control types
2d66e025 1943 enum { wxGRID_TEXTCTRL = 2100,
f85afd4e
MB
1944 wxGRID_CHECKBOX,
1945 wxGRID_CHOICE,
1946 wxGRID_COMBOBOX };
bf2c8b31
VZ
1947#endif // WXWIN_COMPATIBILITY_2_8
1948
f85afd4e 1949
bf2c8b31
VZ
1950 // override some base class functions
1951 virtual bool Enable(bool enable = true);
1952 virtual wxWindow *GetMainWindowOfCompositeControl()
1953 { return (wxWindow*)m_gridWin; }
266e8367
VZ
1954 virtual void Fit();
1955
86033c4b
VZ
1956 // implementation only
1957 void CancelMouseCapture();
1958
60ff3b99 1959protected:
266e8367
VZ
1960 virtual wxSize DoGetBestSize() const;
1961
60ff3b99
VZ
1962 bool m_created;
1963
1964 wxGridWindow *m_gridWin;
60ff3b99 1965 wxGridCornerLabelWindow *m_cornerLabelWin;
ad805b9e
VZ
1966 wxGridRowLabelWindow *m_rowLabelWin;
1967
1968 // the real type of the column window depends on m_useNativeHeader value:
1969 // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is
1970 // wxGridColLabelWindow, use accessors below when the real type matters
1971 wxWindow *m_colWindow;
1972
1973 wxHeaderCtrl *GetColHeader() const
1974 {
1975 wxASSERT_MSG( m_useNativeHeader, "no column header window" );
1976
1977 // static_cast<> doesn't work without the full class declaration in
1978 // view and we prefer to avoid adding more compile-time dependencies
1979 // even at the cost of using reinterpret_cast<>
1980 return reinterpret_cast<wxHeaderCtrl *>(m_colWindow);
1981 }
1982
1983 wxGridColLabelWindow *GetColLabelWindow() const
1984 {
1985 wxASSERT_MSG( !m_useNativeHeader, "no column label window" );
1986
1987 return reinterpret_cast<wxGridColLabelWindow *>(m_colWindow);
1988 }
60ff3b99 1989
60ff3b99 1990 wxGridTableBase *m_table;
2796cce3 1991 bool m_ownTable;
60ff3b99 1992
60ff3b99
VZ
1993 int m_numRows;
1994 int m_numCols;
1995
1996 wxGridCellCoords m_currentCellCoords;
1997
8a3e536c
VZ
1998 // the corners of the block being currently selected or wxGridNoCellCoords
1999 wxGridCellCoords m_selectedBlockTopLeft;
2000 wxGridCellCoords m_selectedBlockBottomRight;
2001
2002 // when selecting blocks of cells (either from the keyboard using Shift
2003 // with cursor keys, or by dragging the mouse), the selection is anchored
2004 // at m_currentCellCoords which defines one of the corners of the rectangle
2005 // being selected -- and this variable defines the other corner, i.e. it's
2006 // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on
2007 // which of them is not m_currentCellCoords
2008 //
2009 // if no block selection is in process, it is set to wxGridNoCellCoords
2010 wxGridCellCoords m_selectedBlockCorner;
2011
b5808881 2012 wxGridSelection *m_selection;
8a3e536c 2013
2796cce3
RD
2014 wxColour m_selectionBackground;
2015 wxColour m_selectionForeground;
60ff3b99 2016
7c1cb261
VZ
2017 // NB: *never* access m_row/col arrays directly because they are created
2018 // on demand, *always* use accessor functions instead!
2019
2020 // init the m_rowHeights/Bottoms arrays with default values
2021 void InitRowHeights();
2022
60ff3b99 2023 int m_defaultRowHeight;
b8d24d4e 2024 int m_minAcceptableRowHeight;
60ff3b99
VZ
2025 wxArrayInt m_rowHeights;
2026 wxArrayInt m_rowBottoms;
2027
7c1cb261
VZ
2028 // init the m_colWidths/Rights arrays
2029 void InitColWidths();
2030
60ff3b99 2031 int m_defaultColWidth;
b8d24d4e 2032 int m_minAcceptableColWidth;
60ff3b99
VZ
2033 wxArrayInt m_colWidths;
2034 wxArrayInt m_colRights;
bf2c8b31 2035
11393d29
VZ
2036 int m_sortCol;
2037 bool m_sortIsAscending;
2038
ad805b9e
VZ
2039 bool m_useNativeHeader,
2040 m_nativeColumnLabels;
7c1cb261
VZ
2041
2042 // get the col/row coords
2043 int GetColWidth(int col) const;
2044 int GetColLeft(int col) const;
2045 int GetColRight(int col) const;
2046
2047 // this function must be public for compatibility...
2048public:
2049 int GetRowHeight(int row) const;
2050protected:
2051
2052 int GetRowTop(int row) const;
2053 int GetRowBottom(int row) const;
2054
60ff3b99
VZ
2055 int m_rowLabelWidth;
2056 int m_colLabelHeight;
2057
266e8367
VZ
2058 // the size of the margin left to the right and bottom of the cell area
2059 int m_extraWidth,
2060 m_extraHeight;
2061
60ff3b99
VZ
2062 wxColour m_labelBackgroundColour;
2063 wxColour m_labelTextColour;
2064 wxFont m_labelFont;
2065
2066 int m_rowLabelHorizAlign;
2067 int m_rowLabelVertAlign;
2068 int m_colLabelHorizAlign;
2069 int m_colLabelVertAlign;
d43851f7 2070 int m_colLabelTextOrientation;
60ff3b99
VZ
2071
2072 bool m_defaultRowLabelValues;
2073 bool m_defaultColLabelValues;
2074
2075 wxColour m_gridLineColour;
2076 bool m_gridLinesEnabled;
9f7aee01
VZ
2077 bool m_gridLinesClipHorz,
2078 m_gridLinesClipVert;
f6bcfd97 2079 wxColour m_cellHighlightColour;
d2520c85
RD
2080 int m_cellHighlightPenWidth;
2081 int m_cellHighlightROPenWidth;
2082
60ff3b99 2083
266e8367 2084 // common part of AutoSizeColumn/Row() and GetBestSize()
ca65c044
WS
2085 int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true);
2086 int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true);
266e8367 2087
af547d51 2088 // common part of AutoSizeColumn/Row()
733f486a
VZ
2089 void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction);
2090
2091 // Calculate the minimum acceptable size for labels area
2092 wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction);
af547d51 2093
43947979
VZ
2094 // if a column has a minimal width, it will be the value for it in this
2095 // hash table
ba8c1601
MB
2096 wxLongToLongHashMap m_colMinWidths,
2097 m_rowMinHeights;
43947979 2098
af547d51
VZ
2099 // get the minimal width of the given column/row
2100 int GetColMinimalWidth(int col) const;
2101 int GetRowMinimalHeight(int col) const;
b99be8fb
VZ
2102
2103 // do we have some place to store attributes in?
ef316e23 2104 bool CanHaveAttributes() const;
60ff3b99 2105
0a976765
VZ
2106 // cell attribute cache (currently we only cache 1, may be will do
2107 // more/better later)
2108 struct CachedAttr
2109 {
2110 int row, col;
2111 wxGridCellAttr *attr;
2112 } m_attrCache;
2113
2114 // invalidates the attribute cache
2115 void ClearAttrCache();
2116
2117 // adds an attribute to cache
2118 void CacheAttr(int row, int col, wxGridCellAttr *attr) const;
2119
ca65c044 2120 // looks for an attr in cache, returns true if found
0a976765
VZ
2121 bool LookupAttr(int row, int col, wxGridCellAttr **attr) const;
2122
2123 // looks for the attr in cache, if not found asks the table and caches the
2124 // result
2e9a6788 2125 wxGridCellAttr *GetCellAttr(int row, int col) const;
ef316e23 2126 wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const
2c9a89e0 2127 { return GetCellAttr( coords.GetRow(), coords.GetCol() ); }
2e9a6788 2128
2796cce3
RD
2129 // the default cell attr object for cells that don't have their own
2130 wxGridCellAttr* m_defaultCellAttr;
2131
2132
60ff3b99
VZ
2133 bool m_inOnKeyDown;
2134 int m_batchCount;
2135
f2d76237
RD
2136
2137 wxGridTypeRegistry* m_typeRegistry;
2138
e2b42eeb
VZ
2139 enum CursorMode
2140 {
2141 WXGRID_CURSOR_SELECT_CELL,
2142 WXGRID_CURSOR_RESIZE_ROW,
2143 WXGRID_CURSOR_RESIZE_COL,
2144 WXGRID_CURSOR_SELECT_ROW,
d4175745
VZ
2145 WXGRID_CURSOR_SELECT_COL,
2146 WXGRID_CURSOR_MOVE_COL
60ff3b99
VZ
2147 };
2148
e2b42eeb 2149 // this method not only sets m_cursorMode but also sets the correct cursor
ca65c044 2150 // for the given mode and, if captureMouse is not false releases the mouse
e2b42eeb
VZ
2151 // if it was captured and captures it if it must be captured
2152 //
2153 // for this to work, you should always use it and not set m_cursorMode
2154 // directly!
2155 void ChangeCursorMode(CursorMode mode,
8a3e536c 2156 wxWindow *win = NULL,
ca65c044 2157 bool captureMouse = true);
e2b42eeb
VZ
2158
2159 wxWindow *m_winCapture; // the window which captured the mouse
8a3e536c
VZ
2160
2161 // this variable is used not for finding the correct current cursor but
2162 // mainly for finding out what is going to happen if the mouse starts being
2163 // dragged right now
2164 //
2165 // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is
2166 // going on, and it is set to one of RESIZE/SELECT/MOVE values while the
2167 // corresponding operation will be started if the user starts dragging the
2168 // mouse from the current position
e2b42eeb
VZ
2169 CursorMode m_cursorMode;
2170
8a3e536c 2171
d4175745
VZ
2172 //Column positions
2173 wxArrayInt m_colAt;
d4175745 2174
6e8524b1
MB
2175 bool m_canDragRowSize;
2176 bool m_canDragColSize;
d4175745 2177 bool m_canDragColMove;
4cfa5de6 2178 bool m_canDragGridSize;
79dbea21 2179 bool m_canDragCell;
bec70262
VZ
2180
2181 // the last position (horizontal or vertical depending on whether the user
2182 // is resizing a column or a row) where a row or column separator line was
2183 // dragged by the user or -1 of there is no drag operation in progress
07296f0b
RD
2184 int m_dragLastPos;
2185 int m_dragRowOrCol;
bec70262 2186
8a3e536c
VZ
2187 // true if a drag operation is in progress; when this is true,
2188 // m_startDragPos is valid, i.e. not wxDefaultPosition
07296f0b 2189 bool m_isDragging;
8a3e536c
VZ
2190
2191 // the position (in physical coordinates) where the user started dragging
2192 // the mouse or wxDefaultPosition if mouse isn't being dragged
2193 //
2194 // notice that this can be != wxDefaultPosition while m_isDragging is still
2195 // false because we wait until the mouse is moved some distance away before
2196 // setting m_isDragging to true
07296f0b 2197 wxPoint m_startDragPos;
60ff3b99 2198
75ecbe45 2199 bool m_waitForSlowClick;
025562fe 2200
60ff3b99
VZ
2201 wxGridCellCoords m_selectionStart;
2202
2203 wxCursor m_rowResizeCursor;
2204 wxCursor m_colResizeCursor;
2205
b54ba671
VZ
2206 bool m_editable; // applies to whole grid
2207 bool m_cellEditCtrlEnabled; // is in-place edit currently shown?
60ff3b99 2208
608754c4
JS
2209 int m_scrollLineX; // X scroll increment
2210 int m_scrollLineY; // Y scroll increment
60ff3b99 2211
ad805b9e 2212 void Init(); // common part of all ctors
60ff3b99 2213 void Create();
ad805b9e 2214 void CreateColumnWindow();
60ff3b99 2215 void CalcDimensions();
7807d81c 2216 void CalcWindowSizes();
60ff3b99
VZ
2217 bool Redimension( wxGridTableMessage& );
2218
2219
8a3e536c
VZ
2220 // generate the appropriate grid event and return -1 if it was vetoed, 1 if
2221 // it was processed (but not vetoed) and 0 if it wasn't processed
2222 int SendEvent(const wxEventType evtType,
2223 int row, int col,
2224 wxMouseEvent& e);
2225 int SendEvent(const wxEventType evtType,
2226 const wxGridCellCoords& coords,
2227 wxMouseEvent& e)
2228 { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); }
2229 int SendEvent(const wxEventType evtType, int row, int col);
2230 int SendEvent(const wxEventType evtType, const wxGridCellCoords& coords)
2231 { return SendEvent(evtType, coords.GetRow(), coords.GetCol()); }
2232 int SendEvent(const wxEventType evtType)
2233 { return SendEvent(evtType, m_currentCellCoords); }
60ff3b99
VZ
2234
2235 void OnPaint( wxPaintEvent& );
2236 void OnSize( wxSizeEvent& );
2237 void OnKeyDown( wxKeyEvent& );
f6bcfd97 2238 void OnKeyUp( wxKeyEvent& );
63e2147c 2239 void OnChar( wxKeyEvent& );
2796cce3 2240 void OnEraseBackground( wxEraseEvent& );
60ff3b99
VZ
2241
2242
8a3e536c
VZ
2243 bool SetCurrentCell( const wxGridCellCoords& coords );
2244 bool SetCurrentCell( int row, int col )
2245 { return SetCurrentCell( wxGridCellCoords(row, col) ); }
2246
60ff3b99 2247
8a3e536c
VZ
2248 // this function is called to extend the block being currently selected
2249 // from mouse and keyboard event handlers
2250 void UpdateBlockBeingSelected(int topRow, int leftCol,
2251 int bottomRow, int rightCol);
c9097836 2252
8a3e536c
VZ
2253 void UpdateBlockBeingSelected(const wxGridCellCoords& topLeft,
2254 const wxGridCellCoords& bottomRight)
2255 { UpdateBlockBeingSelected(topLeft.GetRow(), topLeft.GetCol(),
2256 bottomRight.GetRow(), bottomRight.GetCol()); }
60ff3b99
VZ
2257
2258 // ------ functions to get/send data (see also public functions)
2259 //
2260 bool GetModelValues();
2261 bool SetModelValues();
2262
b5dbe15d 2263 friend class WXDLLIMPEXP_FWD_ADV wxGridSelection;
bec70262
VZ
2264 friend class wxGridRowOperations;
2265 friend class wxGridColumnOperations;
60ff3b99 2266
8a3e536c
VZ
2267 // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent()
2268 friend class wxGridCornerLabelWindow;
2269 friend class wxGridColLabelWindow;
2270 friend class wxGridRowLabelWindow;
2271 friend class wxGridWindow;
2272
ad805b9e
VZ
2273 friend class wxGridHeaderCtrl;
2274
69367c56
VZ
2275private:
2276 // implement wxScrolledWindow method to return m_gridWin size
2277 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
2278
9f7aee01
VZ
2279 // redraw the grid lines, should be called after changing their attributes
2280 void RedrawGridLines();
2281
2282 // common part of Clip{Horz,Vert}GridLines
2283 void DoClipGridLines(bool& var, bool clip);
2284
11393d29
VZ
2285 // update the sorting indicator shown in the specified column (whose index
2286 // must be valid)
2287 //
2288 // this will use GetSortingColumn() and IsSortOrderAscending() to determine
2289 // the sorting indicator to effectively show
2290 void UpdateColumnSortingIndicator(int col);
2291
4797b014
VZ
2292 // update the grid after changing the columns order (common part of
2293 // SetColPos() and ResetColPos())
2294 void RefreshAfterColPosChange();
009c7216 2295
9f7aee01 2296
cd4f6f5f
VZ
2297 // return the position (not index) of the column at the given logical pixel
2298 // position
2299 //
2300 // this always returns a valid position, even if the coordinate is out of
2301 // bounds (in which case first/last column is returned)
2302 int XToPos(int x) const;
2303
2304
8a3e536c
VZ
2305 // event handlers and their helpers
2306 // --------------------------------
2307
2308 // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode
2309 void DoGridCellDrag(wxMouseEvent& event,
2310 const wxGridCellCoords& coords,
2311 bool isFirstDrag);
2312
2313 // process row/column resizing drag event
2314 void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper);
2315
2316 // process mouse drag event in the grid window
2317 void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords);
2318
2319 // process different clicks on grid cells
2320 void DoGridCellLeftDown(wxMouseEvent& event,
2321 const wxGridCellCoords& coords,
2322 const wxPoint& pos);
2323 void DoGridCellLeftDClick(wxMouseEvent& event,
2324 const wxGridCellCoords& coords,
2325 const wxPoint& pos);
2326 void DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords);
2327
2328 // process movement (but not dragging) event in the grid cell area
2329 void DoGridMouseMoveEvent(wxMouseEvent& event,
2330 const wxGridCellCoords& coords,
2331 const wxPoint& pos);
2332
2333 // process mouse events in the grid window
2334 void ProcessGridCellMouseEvent(wxMouseEvent& event);
2335
2336 // process mouse events in the row/column labels/corner windows
2337 void ProcessRowLabelMouseEvent(wxMouseEvent& event);
2338 void ProcessColLabelMouseEvent(wxMouseEvent& event);
2339 void ProcessCornerLabelMouseEvent(wxMouseEvent& event);
2340
11393d29
VZ
2341 void DoColHeaderClick(int col);
2342
ad805b9e
VZ
2343 void DoStartResizeCol(int col);
2344 void DoUpdateResizeCol(int x);
2345 void DoUpdateResizeColWidth(int w);
cd68daf5 2346 void DoStartMoveCol(int col);
ad805b9e 2347
8a3e536c 2348 void DoEndDragResizeRow();
ad805b9e 2349 void DoEndDragResizeCol(wxMouseEvent *event = NULL);
cd68daf5 2350 void DoEndMoveCol(int pos);
8a3e536c 2351
bec70262
VZ
2352
2353 // common implementations of methods defined for both rows and columns
2354 void DeselectLine(int line, const wxGridOperations& oper);
2355 void DoEndDragResizeLine(const wxGridOperations& oper);
cd4f6f5f
VZ
2356 int PosToLinePos(int pos, bool clipToMinMax,
2357 const wxGridOperations& oper) const;
2358 int PosToLine(int pos, bool clipToMinMax,
2359 const wxGridOperations& oper) const;
10a4531d
VZ
2360 int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const;
2361
2362 bool DoMoveCursor(bool expandSelection,
2363 const wxGridDirectionOperations& diroper);
2364 bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper);
2365 bool DoMoveCursorByBlock(bool expandSelection,
2366 const wxGridDirectionOperations& diroper);
2367 void AdvanceToNextNonEmpty(wxGridCellCoords& coords,
2368 const wxGridDirectionOperations& diroper);
2369
2370 // common part of {Insert,Delete}{Rows,Cols}
2371 bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t),
2372 int pos, int num, bool updateLabels);
2373 // Append{Rows,Cols} is a bit different because of one less parameter
2374 bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t),
2375 int num, bool updateLabels);
bec70262 2376
2d66e025 2377 DECLARE_DYNAMIC_CLASS( wxGrid )
f85afd4e 2378 DECLARE_EVENT_TABLE()
22f3361e 2379 DECLARE_NO_COPY_CLASS(wxGrid)
f85afd4e
MB
2380};
2381
b62f94ff
VZ
2382// ----------------------------------------------------------------------------
2383// wxGridUpdateLocker prevents updates to a grid during its lifetime
2384// ----------------------------------------------------------------------------
2385
2386class WXDLLIMPEXP_ADV wxGridUpdateLocker
2387{
2388public:
2389 // if the pointer is NULL, Create() can be called later
2390 wxGridUpdateLocker(wxGrid *grid = NULL)
2391 {
2392 Init(grid);
2393 }
2394
2395 // can be called if ctor was used with a NULL pointer, must not be called
2396 // more than once
2397 void Create(wxGrid *grid)
2398 {
2399 wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") );
2400
2401 Init(grid);
2402 }
2403
2404 ~wxGridUpdateLocker()
2405 {
2406 if ( m_grid )
2407 m_grid->EndBatch();
2408 }
2409
2410private:
2411 void Init(wxGrid *grid)
2412 {
2413 m_grid = grid;
2414 if ( m_grid )
2415 m_grid->BeginBatch();
2416 }
2417
2418 wxGrid *m_grid;
2419
2420 DECLARE_NO_COPY_CLASS(wxGridUpdateLocker)
2421};
2422
43947979
VZ
2423// ----------------------------------------------------------------------------
2424// Grid event class and event types
2425// ----------------------------------------------------------------------------
f85afd4e 2426
8b5f6d9d
VZ
2427class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent,
2428 public wxKeyboardState
f85afd4e 2429{
60ff3b99 2430public:
f85afd4e 2431 wxGridEvent()
8b5f6d9d
VZ
2432 : wxNotifyEvent()
2433 {
2434 Init(-1, -1, -1, -1, false);
2435 }
f85afd4e 2436
8b5f6d9d
VZ
2437 wxGridEvent(int id,
2438 wxEventType type,
2439 wxObject* obj,
2440 int row = -1, int col = -1,
2441 int x = -1, int y = -1,
2442 bool sel = true,
2443 const wxKeyboardState& kbd = wxKeyboardState())
2444 : wxNotifyEvent(type, id),
2445 wxKeyboardState(kbd)
2446 {
2447 Init(row, col, x, y, sel);
2448 SetEventObject(obj);
2449 }
2450
23318a53
FM
2451 // explicitly specifying inline allows gcc < 3.4 to
2452 // handle the deprecation attribute even in the constructor.
29fac1f6 2453 wxDEPRECATED( inline
8b5f6d9d
VZ
2454 wxGridEvent(int id,
2455 wxEventType type,
2456 wxObject* obj,
2457 int row, int col,
2458 int x, int y,
2459 bool sel,
2460 bool control,
2461 bool shift = false, bool alt = false, bool meta = false));
f85afd4e
MB
2462
2463 virtual int GetRow() { return m_row; }
2464 virtual int GetCol() { return m_col; }
2465 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
5c8fc7c1 2466 bool Selecting() { return m_selecting; }
2d66e025 2467
e1f8ec29
RD
2468 virtual wxEvent *Clone() const { return new wxGridEvent(*this); }
2469
60ff3b99
VZ
2470protected:
2471 int m_row;
2472 int m_col;
f85afd4e
MB
2473 int m_x;
2474 int m_y;
5c8fc7c1 2475 bool m_selecting;
8b5f6d9d
VZ
2476
2477private:
2478 void Init(int row, int col, int x, int y, bool sel)
2479 {
2480 m_row = row;
2481 m_col = col;
2482 m_x = x;
2483 m_y = y;
2484 m_selecting = sel;
2485 }
60ff3b99 2486
e1f8ec29 2487 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent)
60ff3b99
VZ
2488};
2489
8b5f6d9d
VZ
2490class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent,
2491 public wxKeyboardState
60ff3b99
VZ
2492{
2493public:
f85afd4e 2494 wxGridSizeEvent()
8b5f6d9d
VZ
2495 : wxNotifyEvent()
2496 {
2497 Init(-1, -1, -1);
2498 }
2499
2500 wxGridSizeEvent(int id,
2501 wxEventType type,
2502 wxObject* obj,
2503 int rowOrCol = -1,
2504 int x = -1, int y = -1,
2505 const wxKeyboardState& kbd = wxKeyboardState())
2506 : wxNotifyEvent(type, id),
2507 wxKeyboardState(kbd)
2508 {
2509 Init(rowOrCol, x, y);
f85afd4e 2510
8b5f6d9d
VZ
2511 SetEventObject(obj);
2512 }
2513
29fac1f6 2514 wxDEPRECATED( inline
8b5f6d9d
VZ
2515 wxGridSizeEvent(int id,
2516 wxEventType type,
2517 wxObject* obj,
2518 int rowOrCol,
2519 int x, int y,
2520 bool control,
2521 bool shift = false,
2522 bool alt = false,
2523 bool meta = false) );
f85afd4e
MB
2524
2525 int GetRowOrCol() { return m_rowOrCol; }
2526 wxPoint GetPosition() { return wxPoint( m_x, m_y ); }
733f486a 2527
e1f8ec29 2528 virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); }
2d66e025 2529
60ff3b99
VZ
2530protected:
2531 int m_rowOrCol;
2532 int m_x;
2533 int m_y;
8b5f6d9d
VZ
2534
2535private:
2536 void Init(int rowOrCol, int x, int y)
2537 {
2538 m_rowOrCol = rowOrCol;
2539 m_x = x;
2540 m_y = y;
2541 }
60ff3b99 2542
e1f8ec29 2543 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent)
f85afd4e
MB
2544};
2545
2546
8b5f6d9d
VZ
2547class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent,
2548 public wxKeyboardState
f85afd4e 2549{
60ff3b99 2550public:
f85afd4e 2551 wxGridRangeSelectEvent()
60ff3b99 2552 : wxNotifyEvent()
8b5f6d9d
VZ
2553 {
2554 Init(wxGridNoCellCoords, wxGridNoCellCoords, false);
2555 }
f85afd4e 2556
8b5f6d9d
VZ
2557 wxGridRangeSelectEvent(int id,
2558 wxEventType type,
2559 wxObject* obj,
60ff3b99
VZ
2560 const wxGridCellCoords& topLeft,
2561 const wxGridCellCoords& bottomRight,
ca65c044 2562 bool sel = true,
8b5f6d9d
VZ
2563 const wxKeyboardState& kbd = wxKeyboardState())
2564 : wxNotifyEvent(type, id),
2565 wxKeyboardState(kbd)
2566 {
2567 Init(topLeft, bottomRight, sel);
2568
2569 SetEventObject(obj);
2570 }
2571
29fac1f6 2572 wxDEPRECATED( inline
8b5f6d9d
VZ
2573 wxGridRangeSelectEvent(int id,
2574 wxEventType type,
2575 wxObject* obj,
2576 const wxGridCellCoords& topLeft,
2577 const wxGridCellCoords& bottomRight,
2578 bool sel,
2579 bool control,
2580 bool shift = false,
2581 bool alt = false,
2582 bool meta = false) );
f85afd4e
MB
2583
2584 wxGridCellCoords GetTopLeftCoords() { return m_topLeft; }
2585 wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; }
2586 int GetTopRow() { return m_topLeft.GetRow(); }
2587 int GetBottomRow() { return m_bottomRight.GetRow(); }
2588 int GetLeftCol() { return m_topLeft.GetCol(); }
2589 int GetRightCol() { return m_bottomRight.GetCol(); }
5c8fc7c1 2590 bool Selecting() { return m_selecting; }
733f486a 2591
e1f8ec29 2592 virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); }
2d66e025 2593
60ff3b99 2594protected:
8b5f6d9d
VZ
2595 void Init(const wxGridCellCoords& topLeft,
2596 const wxGridCellCoords& bottomRight,
2597 bool selecting)
2598 {
2599 m_topLeft = topLeft;
2600 m_bottomRight = bottomRight;
2601 m_selecting = selecting;
2602 }
2603
60ff3b99
VZ
2604 wxGridCellCoords m_topLeft;
2605 wxGridCellCoords m_bottomRight;
5c8fc7c1 2606 bool m_selecting;
60ff3b99 2607
e1f8ec29 2608 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent)
f85afd4e
MB
2609};
2610
bf7945ce 2611
8b5f6d9d
VZ
2612class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent
2613{
bf7945ce
RD
2614public:
2615 wxGridEditorCreatedEvent()
2616 : wxCommandEvent()
2617 {
2618 m_row = 0;
2619 m_col = 0;
2620 m_ctrl = NULL;
2621 }
2622
2623 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
2624 int row, int col, wxControl* ctrl);
2625
2626 int GetRow() { return m_row; }
2627 int GetCol() { return m_col; }
2628 wxControl* GetControl() { return m_ctrl; }
2629 void SetRow(int row) { m_row = row; }
2630 void SetCol(int col) { m_col = col; }
2631 void SetControl(wxControl* ctrl) { m_ctrl = ctrl; }
733f486a 2632
e1f8ec29 2633 virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); }
bf7945ce
RD
2634
2635private:
2636 int m_row;
2637 int m_col;
2638 wxControl* m_ctrl;
2639
e1f8ec29 2640 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent)
bf7945ce
RD
2641};
2642
2643
c058cafa
VZ
2644extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_CLICK;
2645extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK;
2646extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK;
2647extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK;
2648extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK;
2649extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK;
2650extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK;
2651extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK;
2652extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_ROW_SIZE;
2653extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SIZE;
2654extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_RANGE_SELECT;
2655extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_CHANGE;
2656extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_SELECT_CELL;
2657extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_SHOWN;
2658extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_HIDDEN;
2659extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_EDITOR_CREATED;
2660extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_CELL_BEGIN_DRAG;
2661extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_MOVE;
11393d29 2662extern WXDLLIMPEXP_ADV const wxEventType wxEVT_GRID_COL_SORT;
749692cc 2663
f85afd4e
MB
2664
2665typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&);
2666typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&);
2667typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&);
bf7945ce 2668typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&);
f85afd4e 2669
7fa03f04 2670#define wxGridEventHandler(func) \
d94c09cd 2671 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEventFunction, &func)
7fa03f04
VZ
2672
2673#define wxGridSizeEventHandler(func) \
d94c09cd 2674 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridSizeEventFunction, &func)
7fa03f04
VZ
2675
2676#define wxGridRangeSelectEventHandler(func) \
d94c09cd 2677 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridRangeSelectEventFunction, &func)
7fa03f04
VZ
2678
2679#define wxGridEditorCreatedEventHandler(func) \
d94c09cd 2680 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxGridEditorCreatedEventFunction, &func)
7fa03f04
VZ
2681
2682#define wx__DECLARE_GRIDEVT(evt, id, fn) \
2683 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn))
2684
2685#define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \
2686 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn))
2687
2688#define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \
2689 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn))
2690
2691#define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \
2692 wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn))
2693
2694#define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn)
2695#define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn)
2696#define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn)
2697#define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn)
2698#define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn)
2699#define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn)
2700#define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn)
2701#define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn)
2702#define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn)
2703#define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn)
5d984f5d 2704#define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn)
11393d29 2705#define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn)
7fa03f04
VZ
2706#define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn)
2707#define EVT_GRID_CMD_CELL_CHANGE(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGE, id, fn)
2708#define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn)
2709#define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn)
2710#define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn)
2711#define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn)
2712#define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn)
2713
2714// same as above but for any id (exists mainly for backwards compatibility but
2715// then it's also true that you rarely have multiple grid in the same window)
2716#define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn)
2717#define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn)
2718#define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn)
2719#define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn)
2720#define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn)
2721#define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn)
2722#define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn)
2723#define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn)
2724#define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn)
2725#define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn)
4d5a1b0a 2726#define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn)
11393d29 2727#define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn)
7fa03f04
VZ
2728#define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn)
2729#define EVT_GRID_CELL_CHANGE(fn) EVT_GRID_CMD_CELL_CHANGE(wxID_ANY, fn)
2730#define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn)
2731#define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn)
2732#define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn)
2733#define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn)
2734#define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn)
f85afd4e
MB
2735
2736#if 0 // TODO: implement these ? others ?
2737
77d4384e
RR
2738extern const int wxEVT_GRID_CREATE_CELL;
2739extern const int wxEVT_GRID_CHANGE_LABELS;
2740extern const int wxEVT_GRID_CHANGE_SEL_LABEL;
f85afd4e 2741
ca65c044
WS
2742#define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2743#define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
2744#define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ),
f85afd4e
MB
2745
2746#endif
2747
df9fac6d
PC
2748#endif // wxUSE_GRID
2749#endif // _WX_GENERIC_GRID_H_