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