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