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