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