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