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