]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/grid.h
Document that throwing exceptions from wxTimer::Notify() is unsupported.
[wxWidgets.git] / interface / wx / grid.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: grid.h
afe0e400 3// Purpose: interface of wxGrid and related classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
8b9ef005
BP
9/**
10 @class wxGridCellRenderer
11
12 This class is responsible for actually drawing the cell in the grid. You
13 may pass it to the wxGridCellAttr (below) to change the format of one given
14 cell or to wxGrid::SetDefaultRenderer() to change the view of all cells.
15 This is an abstract class, and you will normally use one of the predefined
16 derived classes or derive your own class from it.
17
18 @library{wxadv}
19 @category{grid}
20
21 @see wxGridCellBoolRenderer, wxGridCellFloatRenderer,
22 wxGridCellNumberRenderer, wxGridCellStringRenderer
23*/
24class wxGridCellRenderer
25{
26public:
27 /**
28 This function must be implemented in derived classes to return a copy
29 of itself.
30 */
31 virtual wxGridCellRenderer* Clone() const = 0;
32
33 /**
34 Draw the given cell on the provided DC inside the given rectangle using
35 the style specified by the attribute and the default or selected state
36 corresponding to the isSelected value.
37
38 This pure virtual function has a default implementation which will
39 prepare the DC using the given attribute: it will draw the rectangle
40 with the background colour from attr and set the text colour and font.
41 */
42 virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
43 const wxRect& rect, int row, int col,
44 bool isSelected) = 0;
45
46 /**
47 Get the preferred size of the cell for its contents.
48 */
49 virtual wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc,
50 int row, int col) = 0;
51};
52
53/**
54 @class wxGridCellBoolRenderer
55
56 This class may be used to format boolean data in a cell.
57
58 @library{wxadv}
59 @category{grid}
60
61 @see wxGridCellRenderer, wxGridCellFloatRenderer, wxGridCellNumberRenderer,
62 wxGridCellStringRenderer
63*/
64class wxGridCellBoolRenderer : public wxGridCellRenderer
65{
66public:
67 /**
68 Default constructor.
69 */
70 wxGridCellBoolRenderer();
71};
72
23324ae1
FM
73/**
74 @class wxGridCellFloatRenderer
7c913512 75
23324ae1 76 This class may be used to format floating point data in a cell.
7c913512 77
23324ae1 78 @library{wxadv}
42b5841f 79 @category{grid}
7c913512 80
afe0e400
BP
81 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellNumberRenderer,
82 wxGridCellStringRenderer
23324ae1
FM
83*/
84class wxGridCellFloatRenderer : public wxGridCellStringRenderer
85{
86public:
87 /**
7c913512 88 @param width
4cc4bfaf 89 Minimum number of characters to be shown.
7c913512 90 @param precision
4cc4bfaf 91 Number of digits after the decimal dot.
23324ae1
FM
92 */
93 wxGridCellFloatRenderer(int width = -1, int precision = -1);
94
95 /**
42b5841f 96 Returns the precision.
23324ae1 97 */
328f5751 98 int GetPrecision() const;
23324ae1
FM
99
100 /**
42b5841f 101 Returns the width.
23324ae1 102 */
328f5751 103 int GetWidth() const;
23324ae1
FM
104
105 /**
106 Parameters string format is "width[,precision]".
107 */
adaaa686 108 virtual void SetParameters(const wxString& params);
23324ae1
FM
109
110 /**
42b5841f 111 Sets the precision.
23324ae1
FM
112 */
113 void SetPrecision(int precision);
114
115 /**
42b5841f 116 Sets the width.
23324ae1
FM
117 */
118 void SetWidth(int width);
119};
120
23324ae1 121/**
8b9ef005 122 @class wxGridCellNumberRenderer
7c913512 123
8b9ef005 124 This class may be used to format integer data in a cell.
5039f140 125
8b9ef005
BP
126 @library{wxadv}
127 @category{grid}
5039f140 128
8b9ef005
BP
129 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellFloatRenderer,
130 wxGridCellStringRenderer
131*/
132class wxGridCellNumberRenderer : public wxGridCellStringRenderer
133{
134public:
135 /**
136 Default constructor.
137 */
138 wxGridCellNumberRenderer();
139};
5039f140 140
8b9ef005
BP
141/**
142 @class wxGridCellStringRenderer
143
144 This class may be used to format string data in a cell; it is the default
145 for string cells.
7c913512 146
23324ae1 147 @library{wxadv}
42b5841f 148 @category{grid}
8b9ef005
BP
149
150 @see wxGridCellRenderer, wxGridCellBoolRenderer, wxGridCellFloatRenderer,
151 wxGridCellNumberRenderer
23324ae1 152*/
8b9ef005 153class wxGridCellStringRenderer : public wxGridCellRenderer
23324ae1
FM
154{
155public:
afe0e400
BP
156 /**
157 Default constructor.
8b9ef005
BP
158 */
159 wxGridCellStringRenderer();
160};
23324ae1 161
3c4f71cc 162
77d2c45c 163
8b9ef005
BP
164/**
165 @class wxGridCellEditor
23324ae1 166
8b9ef005
BP
167 This class is responsible for providing and manipulating the in-place edit
168 controls for the grid. Instances of wxGridCellEditor (actually, instances
169 of derived classes since it is an abstract class) can be associated with
170 the cell attributes for individual cells, rows, columns, or even for the
171 entire grid.
77d2c45c 172
8b9ef005
BP
173 @library{wxadv}
174 @category{grid}
3c4f71cc 175
8b9ef005
BP
176 @see wxGridCellBoolEditor, wxGridCellChoiceEditor, wxGridCellFloatEditor,
177 wxGridCellNumberEditor, wxGridCellTextEditor
178*/
179class wxGridCellEditor
180{
181public:
77d2c45c 182 /**
8b9ef005
BP
183 Default constructor.
184 */
185 wxGridCellEditor();
77d2c45c
VZ
186
187 /**
8b9ef005 188 Fetch the value from the table and prepare the edit control to begin
763163a8
VZ
189 editing.
190
191 This function should save the original value of the grid cell at the
192 given @a row and @a col and show the control allowing the user to
193 change it.
194
195 @see EndEdit()
8b9ef005
BP
196 */
197 virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
77d2c45c 198
8b9ef005
BP
199 /**
200 Create a new object which is the copy of this one.
201 */
202 virtual wxGridCellEditor* Clone() const = 0;
23324ae1
FM
203
204 /**
8b9ef005
BP
205 Creates the actual edit control.
206 */
207 virtual void Create(wxWindow* parent, wxWindowID id,
208 wxEvtHandler* evtHandler) = 0;
3c4f71cc 209
afe0e400 210 /**
8b9ef005
BP
211 Final cleanup.
212 */
213 virtual void Destroy();
23324ae1 214
10a4531d 215 /**
763163a8 216 End editing the cell.
10a4531d 217
763163a8
VZ
218 This function must check if the current value of the editing control is
219 valid and different from the original value (available as @a oldval in
220 its string form and possibly saved internally using its real type by
78e78812
VZ
221 BeginEdit()). If it isn't, it just returns @false, otherwise it must do
222 the following:
223 # Save the new value internally so that ApplyEdit() could apply it.
224 # Fill @a newval (which is never @NULL) with the string
225 representation of the new value.
226 # Return @true
227
228 Notice that it must @em not modify the grid as the change could still
229 be vetoed.
763163a8
VZ
230
231 If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
232 this change, ApplyEdit() will be called next.
8b9ef005 233 */
78e78812
VZ
234 virtual bool EndEdit(int row, int col, const wxGrid* grid,
235 const wxString& oldval, wxString* newval) = 0;
10a4531d 236
763163a8
VZ
237 /**
238 Effectively save the changes in the grid.
239
240 This function should save the value of the control in the grid. It is
241 called only after EndEdit() returns @true.
242 */
243 virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
244
afe0e400 245 /**
8b9ef005
BP
246 Some types of controls on some platforms may need some help with the
247 Return key.
248 */
249 virtual void HandleReturn(wxKeyEvent& event);
3c4f71cc 250
afe0e400 251 /**
8b9ef005
BP
252 Returns @true if the edit control has been created.
253 */
254 bool IsCreated();
23324ae1
FM
255
256 /**
8b9ef005
BP
257 Draws the part of the cell not occupied by the control: the base class
258 version just fills it with background colour from the attribute.
259 */
260 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr* attr);
23324ae1
FM
261
262 /**
8b9ef005
BP
263 Reset the value in the control back to its starting value.
264 */
265 virtual void Reset() = 0;
3c4f71cc 266
8b9ef005
BP
267 /**
268 Size and position the edit control.
269 */
270 virtual void SetSize(const wxRect& rect);
23324ae1
FM
271
272 /**
8b9ef005
BP
273 Show or hide the edit control, use the specified attributes to set
274 colours/fonts for it.
275 */
276 virtual void Show(bool show, wxGridCellAttr* attr = NULL);
3c4f71cc 277
8b9ef005
BP
278 /**
279 If the editor is enabled by clicking on the cell, this method will be
280 called.
281 */
282 virtual void StartingClick();
23324ae1
FM
283
284 /**
8b9ef005
BP
285 If the editor is enabled by pressing keys on the grid, this will be
286 called to let the editor do something about that first key if desired.
287 */
288 virtual void StartingKey(wxKeyEvent& event);
3c4f71cc 289
8b9ef005 290protected:
23324ae1
FM
291
292 /**
8b9ef005
BP
293 The destructor is private because only DecRef() can delete us.
294 */
295 virtual ~wxGridCellEditor();
296};
3c4f71cc 297
8b9ef005
BP
298/**
299 @class wxGridCellBoolEditor
23324ae1 300
8b9ef005 301 Grid cell editor for boolean data.
23324ae1 302
8b9ef005
BP
303 @library{wxadv}
304 @category{grid}
23324ae1 305
8b9ef005
BP
306 @see wxGridCellEditor, wxGridCellChoiceEditor, wxGridCellFloatEditor,
307 wxGridCellNumberEditor, wxGridCellTextEditor
308*/
309class wxGridCellBoolEditor : public wxGridCellEditor
310{
311public:
23324ae1 312 /**
8b9ef005
BP
313 Default constructor.
314 */
315 wxGridCellBoolEditor();
5039f140 316
8b9ef005
BP
317 /**
318 Returns @true if the given @a value is equal to the string
319 representation of the truth value we currently use (see
320 UseStringValues()).
321 */
322 static bool IsTrueValue(const wxString& value);
3c4f71cc 323
23324ae1 324 /**
8b9ef005
BP
325 This method allows you to customize the values returned by GetValue()
326 for the cell using this editor. By default, the default values of the
327 arguments are used, i.e. @c "1" is returned if the cell is checked and
328 an empty string otherwise.
329 */
330 static void UseStringValues(const wxString& valueTrue = "1",
57bf907d 331 const wxString& valueFalse = wxEmptyString);
8b9ef005 332};
3c4f71cc 333
8b9ef005
BP
334/**
335 @class wxGridCellChoiceEditor
23324ae1 336
8b9ef005
BP
337 Grid cell editor for string data providing the user a choice from a list of
338 strings.
5039f140 339
8b9ef005
BP
340 @library{wxadv}
341 @category{grid}
23324ae1 342
8b9ef005
BP
343 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellFloatEditor,
344 wxGridCellNumberEditor, wxGridCellTextEditor
345*/
346class wxGridCellChoiceEditor : public wxGridCellEditor
347{
348public:
23324ae1 349 /**
8b9ef005
BP
350 @param count
351 Number of strings from which the user can choose.
352 @param choices
353 An array of strings from which the user can choose.
354 @param allowOthers
355 If allowOthers is @true, the user can type a string not in choices
356 array.
357 */
358 wxGridCellChoiceEditor(size_t count = 0,
359 const wxString choices[] = NULL,
360 bool allowOthers = false);
361 /**
362 @param choices
363 An array of strings from which the user can choose.
364 @param allowOthers
365 If allowOthers is @true, the user can type a string not in choices
366 array.
367 */
368 wxGridCellChoiceEditor(const wxArrayString& choices,
369 bool allowOthers = false);
23324ae1
FM
370
371 /**
8b9ef005
BP
372 Parameters string format is "item1[,item2[...,itemN]]"
373 */
374 virtual void SetParameters(const wxString& params);
375};
23324ae1 376
8b9ef005
BP
377/**
378 @class wxGridCellTextEditor
3c4f71cc 379
8b9ef005 380 Grid cell editor for string/text data.
23324ae1 381
8b9ef005
BP
382 @library{wxadv}
383 @category{grid}
afe0e400 384
8b9ef005
BP
385 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
386 wxGridCellFloatEditor, wxGridCellNumberEditor
387*/
388class wxGridCellTextEditor : public wxGridCellEditor
389{
390public:
23324ae1 391 /**
8b9ef005
BP
392 Default constructor.
393 */
394 wxGridCellTextEditor();
23324ae1
FM
395
396 /**
8b9ef005
BP
397 The parameters string format is "n" where n is a number representing
398 the maximum width.
399 */
400 virtual void SetParameters(const wxString& params);
401};
5039f140 402
8b9ef005
BP
403/**
404 @class wxGridCellFloatEditor
23324ae1 405
8b9ef005 406 The editor for floating point numbers data.
3c4f71cc 407
8b9ef005
BP
408 @library{wxadv}
409 @category{grid}
23324ae1 410
8b9ef005
BP
411 @see wxGridCellEditor, wxGridCellNumberEditor, wxGridCellBoolEditor,
412 wxGridCellTextEditor, wxGridCellChoiceEditor
413*/
414class wxGridCellFloatEditor : public wxGridCellTextEditor
415{
416public:
23324ae1 417 /**
8b9ef005
BP
418 @param width
419 Minimum number of characters to be shown.
420 @param precision
421 Number of digits after the decimal dot.
422 */
423 wxGridCellFloatEditor(int width = -1, int precision = -1);
23324ae1
FM
424
425 /**
8b9ef005
BP
426 Parameters string format is "width,precision"
427 */
428 virtual void SetParameters(const wxString& params);
429};
23324ae1 430
8b9ef005
BP
431/**
432 @class wxGridCellNumberEditor
3c4f71cc 433
8b9ef005 434 Grid cell editor for numeric integer data.
5039f140 435
8b9ef005
BP
436 @library{wxadv}
437 @category{grid}
23324ae1 438
8b9ef005
BP
439 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
440 wxGridCellFloatEditor, wxGridCellTextEditor
441*/
442class wxGridCellNumberEditor : public wxGridCellTextEditor
443{
444public:
23324ae1 445 /**
8b9ef005
BP
446 Allows you to specify the range for acceptable data. Values equal to
447 -1 for both @a min and @a max indicate that no range checking should be
448 done.
449 */
450 wxGridCellNumberEditor(int min = -1, int max = -1);
3c4f71cc 451
23324ae1 452
afe0e400 453 /**
8b9ef005
BP
454 Parameters string format is "min,max".
455 */
456 virtual void SetParameters(const wxString& params);
457
458protected:
3c4f71cc 459
afe0e400 460 /**
8b9ef005
BP
461 If the return value is @true, the editor uses a wxSpinCtrl to get user
462 input, otherwise it uses a wxTextCtrl.
463 */
464 bool HasRange() const;
23324ae1 465
afe0e400 466 /**
8b9ef005
BP
467 String representation of the value.
468 */
469 wxString GetString() const;
470};
23324ae1 471
23324ae1 472
3c4f71cc 473
8b9ef005
BP
474/**
475 @class wxGridCellAttr
23324ae1 476
8b9ef005
BP
477 This class can be used to alter the cells' appearance in the grid by
478 changing their attributes from the defaults. An object of this class may be
479 returned by wxGridTableBase::GetAttr().
5039f140 480
8b9ef005
BP
481 @library{wxadv}
482 @category{grid}
483*/
484class wxGridCellAttr
485{
486public:
62960a2c
VZ
487 /**
488 Kind of the attribute to retrieve.
489
490 @see wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr()
491 */
492 enum wxAttrKind
493 {
494 /// Return the combined effective attribute for the cell.
495 Any,
496
497 /// Return the attribute explicitly set for this cell.
498 Cell,
499
500 /// Return the attribute set for this cells row.
501 Row,
502
503 /// Return the attribute set for this cells column.
504 Col
505 };
506
afe0e400 507 /**
8b9ef005
BP
508 Default constructor.
509 */
ccf39540 510 wxGridCellAttr(wxGridCellAttr* attrDefault = NULL);
23324ae1 511 /**
8b9ef005
BP
512 Constructor specifying some of the often used attributes.
513 */
514 wxGridCellAttr(const wxColour& colText, const wxColour& colBack,
515 const wxFont& font, int hAlign, int vAlign);
5039f140 516
afe0e400 517 /**
8b9ef005
BP
518 Creates a new copy of this object.
519 */
520 wxGridCellAttr* Clone() const;
23324ae1
FM
521
522 /**
8b9ef005
BP
523 This class is reference counted: it is created with ref count of 1, so
524 calling DecRef() once will delete it. Calling IncRef() allows to lock
525 it until the matching DecRef() is called.
526 */
527 void DecRef();
23324ae1
FM
528
529 /**
8b9ef005
BP
530 See SetAlignment() for the returned values.
531 */
532 void GetAlignment(int* hAlign, int* vAlign) const;
23324ae1
FM
533
534 /**
8b9ef005
BP
535 Returns the background colour.
536 */
537 const wxColour& GetBackgroundColour() const;
23324ae1 538
23324ae1 539 /**
8b9ef005
BP
540 Returns the cell editor.
541 */
542 wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
23324ae1
FM
543
544 /**
8b9ef005
BP
545 Returns the font.
546 */
547 const wxFont& GetFont() const;
23324ae1
FM
548
549 /**
8b9ef005
BP
550 Returns the cell renderer.
551 */
552 wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
23324ae1
FM
553
554 /**
8b9ef005
BP
555 Returns the text colour.
556 */
557 const wxColour& GetTextColour() const;
5e6e278d
FM
558
559 /**
8b9ef005
BP
560 Returns @true if this attribute has a valid alignment set.
561 */
562 bool HasAlignment() const;
7c913512 563
23324ae1 564 /**
8b9ef005 565 Returns @true if this attribute has a valid background colour set.
23324ae1 566 */
8b9ef005 567 bool HasBackgroundColour() const;
23324ae1 568
23324ae1 569 /**
8b9ef005 570 Returns @true if this attribute has a valid cell editor set.
23324ae1 571 */
8b9ef005 572 bool HasEditor() const;
23324ae1
FM
573
574 /**
8b9ef005 575 Returns @true if this attribute has a valid font set.
23324ae1 576 */
8b9ef005 577 bool HasFont() const;
23324ae1
FM
578
579 /**
8b9ef005 580 Returns @true if this attribute has a valid cell renderer set.
23324ae1 581 */
8b9ef005 582 bool HasRenderer() const;
23324ae1
FM
583
584 /**
8b9ef005 585 Returns @true if this attribute has a valid text colour set.
23324ae1 586 */
8b9ef005 587 bool HasTextColour() const;
23324ae1
FM
588
589 /**
8b9ef005
BP
590 This class is reference counted: it is created with ref count of 1, so
591 calling DecRef() once will delete it. Calling IncRef() allows to lock
592 it until the matching DecRef() is called.
23324ae1 593 */
8b9ef005 594 void IncRef();
23324ae1
FM
595
596 /**
8b9ef005 597 Returns @true if this cell is set as read-only.
23324ae1 598 */
8b9ef005 599 bool IsReadOnly() const;
23324ae1
FM
600
601 /**
8b9ef005
BP
602 Sets the alignment. @a hAlign can be one of @c wxALIGN_LEFT,
603 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT and @a vAlign can be one of
604 @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
23324ae1 605 */
8b9ef005 606 void SetAlignment(int hAlign, int vAlign);
23324ae1
FM
607
608 /**
8b9ef005 609 Sets the background colour.
23324ae1 610 */
8b9ef005 611 void SetBackgroundColour(const wxColour& colBack);
23324ae1
FM
612
613 /**
8b9ef005 614 @todo Needs documentation.
23324ae1 615 */
8b9ef005 616 void SetDefAttr(wxGridCellAttr* defAttr);
23324ae1
FM
617
618 /**
8b9ef005 619 Sets the editor to be used with the cells with this attribute.
23324ae1 620 */
8b9ef005 621 void SetEditor(wxGridCellEditor* editor);
23324ae1
FM
622
623 /**
8b9ef005 624 Sets the font.
23324ae1 625 */
8b9ef005 626 void SetFont(const wxFont& font);
23324ae1
FM
627
628 /**
8b9ef005 629 Sets the cell as read-only.
23324ae1 630 */
8b9ef005 631 void SetReadOnly(bool isReadOnly = true);
23324ae1
FM
632
633 /**
8b9ef005
BP
634 Sets the renderer to be used for cells with this attribute. Takes
635 ownership of the pointer.
23324ae1 636 */
8b9ef005 637 void SetRenderer(wxGridCellRenderer* renderer);
5e6e278d
FM
638
639 /**
8b9ef005 640 Sets the text colour.
5e6e278d 641 */
8b9ef005 642 void SetTextColour(const wxColour& colText);
23324ae1
FM
643};
644
ba9574c3
VZ
645/**
646 Base class for corner window renderer.
647
648 This is the simplest of all header renderers and only has a single
649 function.
650
651 @see wxGridCellAttrProvider::GetCornerRenderer()
652
653 @since 2.9.1
654 */
655class wxGridCornerHeaderRenderer
656{
657public:
658 /**
659 Called by the grid to draw the corner window border.
660
661 This method is responsible for drawing the border inside the given @a
662 rect and adjusting the rectangle size to correspond to the area inside
663 the border, i.e. usually call wxRect::Deflate() to account for the
664 border width.
665
666 @param grid
667 The grid whose corner window is being drawn.
668 @param dc
669 The device context to use for drawing.
670 @param rect
671 Input/output parameter which contains the border rectangle on input
672 and should be updated to contain the area inside the border on
673 function return.
674 */
675 virtual void DrawBorder(const wxGrid& grid,
676 wxDC& dc,
677 wxRect& rect) const = 0;
678};
679/**
680 Common base class for row and column headers renderers.
681
682 @see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer
683
684 @since 2.9.1
685 */
686class wxGridHeaderLabelsRenderer : public wxGridCornerHeaderRenderer
687{
688public:
689 /**
690 Called by the grid to draw the specified label.
691
692 Notice that the base class DrawBorder() method is called before this
693 one.
694
695 The default implementation uses wxGrid::GetLabelTextColour() and
696 wxGrid::GetLabelFont() to draw the label.
697 */
698 virtual void DrawLabel(const wxGrid& grid,
699 wxDC& dc,
700 const wxString& value,
701 const wxRect& rect,
702 int horizAlign,
703 int vertAlign,
704 int textOrientation) const;
705};
706
707/**
708 Base class for row headers renderer.
709
710 This is the same as wxGridHeaderLabelsRenderer currently but we still use a
711 separate class for it to distinguish it from wxGridColumnHeaderRenderer.
712
713 @see wxGridRowHeaderRendererDefault
714
715 @see wxGridCellAttrProvider::GetRowHeaderRenderer()
716
717 @since 2.9.1
718 */
719class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer
720{
721};
722
723/**
724 Base class for column headers renderer.
725
726 This is the same as wxGridHeaderLabelsRenderer currently but we still use a
727 separate class for it to distinguish it from wxGridRowHeaderRenderer.
728
729 @see wxGridColumnHeaderRendererDefault
730
731 @see wxGridCellAttrProvider::GetColumnHeaderRenderer()
732
733 @since 2.9.1
734 */
735class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer
736{
737};
738
739/**
740 Default row header renderer.
741
742 You may derive from this class if you need to only override one of its
743 methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the
744 default implementation for the other one.
745
746 @see wxGridColumnHeaderRendererDefault
747
748 @since 2.9.1
749 */
750class wxGridRowHeaderRendererDefault : public wxGridRowHeaderRendererDefault
751{
752public:
753 /// Implement border drawing for the row labels.
754 virtual void DrawBorder(const wxGrid& grid,
755 wxDC& dc,
756 wxRect& rect) const;
757};
758
759/**
760 Default column header renderer.
761
762 @see wxGridRowHeaderRendererDefault
763
764 @since 2.9.1
765 */
766class wxGridColumnHeaderRendererDefault : public wxGridColumnHeaderRenderer
767{
768public:
769 /// Implement border drawing for the column labels.
770 virtual void DrawBorder(const wxGrid& grid,
771 wxDC& dc,
772 wxRect& rect) const;
773};
774
775/**
776 Default corner window renderer.
777
778 @see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault
779
780 @since 2.9.1
781 */
782class wxGridCornerHeaderRendererDefault : public wxGridCornerHeaderRenderer
783{
784public:
785 /// Implement border drawing for the corner window.
786 virtual void DrawBorder(const wxGrid& grid,
787 wxDC& dc,
788 wxRect& rect) const;
789};
790
62960a2c
VZ
791/**
792 Class providing attributes to be used for the grid cells.
793
794 This class both defines an interface which grid cell attributes providers
795 should implement -- and which can be implemented differently in derived
796 classes -- and a default implementation of this interface which is often
797 good enough to be used without modification, especially with not very large
798 grids for which the efficiency of attributes storage hardly matters (see
799 the discussion below).
800
801 An object of this class can be associated with a wxGrid using
802 wxGridTableBase::SetAttrProvider() but it's not necessary to call it if you
803 intend to use the default provider as it is used by wxGridTableBase by
804 default anyhow.
805
806 Notice that while attributes provided by this class can be set for
807 individual cells using SetAttr() or the entire rows or columns using
808 SetRowAttr() and SetColAttr() they are always retrieved using GetAttr()
809 function.
810
811
812 The default implementation of this class stores the attributes passed to
813 its SetAttr(), SetRowAttr() and SetColAttr() in a straightforward way. A
814 derived class may use its knowledge about how the attributes are used in
815 your program to implement it much more efficiently: for example, using a
816 special background colour for all even-numbered rows can be implemented by
817 simply returning the same attribute from GetAttr() if the row number is
818 even instead of having to store N/2 row attributes where N is the total
819 number of rows in the grid.
820
821 Notice that objects of this class can't be copied.
822 */
823class wxGridCellAttrProvider : public wxClientDataContainer
824{
825public:
826 /// Trivial default constructor.
827 wxGridCellAttrProvider();
828
829 /// Destructor releases any attributes held by this class.
830 virtual ~wxGridCellAttrProvider();
831
832 /**
833 Get the attribute to use for the specified cell.
834
835 If wxGridCellAttr::Any is used as @a kind value, this function combines
836 the attributes set for this cell using SetAttr() and those for its row
837 or column (set with SetRowAttr() or SetColAttr() respectively), with
838 the cell attribute having the highest precedence.
839
840 Notice that the caller must call DecRef() on the returned pointer if it
841 is non-@NULL.
842
843 @param row
844 The row of the cell.
845 @param col
846 The column of the cell.
847 @param kind
848 The kind of the attribute to return.
849 @return
850 The attribute to use which should be DecRef()'d by caller or @NULL
851 if no attributes are defined for this cell.
852 */
853 virtual wxGridCellAttr *GetAttr(int row, int col,
854 wxGridCellAttr::wxAttrKind kind) const;
855
856 /**
857 Setting attributes.
858
859 All these functions take ownership of the attribute passed to them,
860 i.e. will call DecRef() on it themselves later and so it should not be
861 destroyed by the caller. And the attribute can be @NULL to reset a
862 previously set value.
863 */
864 //@{
865
866 /// Set attribute for the specified cell.
867 virtual void SetAttr(wxGridCellAttr *attr, int row, int col);
868
869 /// Set attribute for the specified row.
870 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
871
872 /// Set attribute for the specified column.
873 virtual void SetColAttr(wxGridCellAttr *attr, int col);
874
875 //@}
ba9574c3
VZ
876
877 /**
878 Getting header renderers.
879
880 These functions return the renderers for the given row or column header
881 label and the corner window. Unlike cell attributes, these objects are
882 not reference counted and are never @NULL so they are returned by
883 reference and not pointer and DecRef() shouldn't (and can't) be called
884 for them.
885
886 All these functions were added in wxWidgets 2.9.1.
887 */
888 //@{
889
890 /**
891 Return the renderer used for drawing column headers.
892
893 By default wxGridColumnHeaderRendererDefault is returned.
894
895 @see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader()
896
897 @since 2.9.1
898 */
899 virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col);
900
901 /**
902 Return the renderer used for drawing row headers.
903
904 By default wxGridRowHeaderRendererDefault is returned.
905
906 @since 2.9.1
907 */
908 virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row);
909
910 /**
911 Return the renderer used for drawing the corner window.
912
913 By default wxGridCornerHeaderRendererDefault is returned.
914
915 @since 2.9.1
916 */
917 virtual const wxGridCornerHeaderRenderer& GetCornerRenderer();
918
919 //@}
62960a2c 920};
23324ae1 921
e54c96f1 922
23324ae1 923/**
8b9ef005 924 @class wxGridTableBase
7c913512 925
8b9ef005
BP
926 The almost abstract base class for grid tables.
927
928 A grid table is responsible for storing the grid data and, indirectly, grid
929 cell attributes. The data can be stored in the way most convenient for the
930 application but has to be provided in string form to wxGrid. It is also
931 possible to provide cells values in other formats if appropriate, e.g. as
932 numbers.
933
934 This base class is not quite abstract as it implements a trivial strategy
935 for storing the attributes by forwarding it to wxGridCellAttrProvider and
936 also provides stubs for some other functions. However it does have a number
937 of pure virtual methods which must be implemented in the derived classes.
938
939 @see wxGridStringTable
7c913512 940
23324ae1 941 @library{wxadv}
42b5841f 942 @category{grid}
23324ae1 943*/
8b9ef005 944class wxGridTableBase : public wxObject
23324ae1
FM
945{
946public:
947 /**
948 Default constructor.
8b9ef005
BP
949 */
950 wxGridTableBase();
23324ae1
FM
951
952 /**
8b9ef005
BP
953 Destructor frees the attribute provider if it was created.
954 */
955 virtual ~wxGridTableBase();
23324ae1 956
8b9ef005
BP
957 /**
958 Must be overridden to return the number of rows in the table.
e54c96f1 959
8b9ef005
BP
960 For backwards compatibility reasons, this method is not const.
961 Use GetRowsCount() instead of it in const methods of derived table
962 classes.
963 */
964 virtual int GetNumberRows() = 0;
7c913512 965
8b9ef005
BP
966 /**
967 Must be overridden to return the number of columns in the table.
7c913512 968
8b9ef005
BP
969 For backwards compatibility reasons, this method is not const.
970 Use GetColsCount() instead of it in const methods of derived table
971 classes,
972 */
973 virtual int GetNumberCols() = 0;
7c913512 974
23324ae1 975 /**
8b9ef005 976 Return the number of rows in the table.
23324ae1 977
8b9ef005
BP
978 This method is not virtual and is only provided as a convenience for
979 the derived classes which can't call GetNumberRows() without a
980 @c const_cast from their const methods.
981 */
982 int GetRowsCount() const;
23324ae1 983
8b9ef005
BP
984 /**
985 Return the number of columns in the table.
e54c96f1 986
8b9ef005
BP
987 This method is not virtual and is only provided as a convenience for
988 the derived classes which can't call GetNumberCols() without a
989 @c const_cast from their const methods.
990 */
991 int GetColsCount() const;
7c913512 992
7c913512 993
23324ae1 994 /**
8b9ef005
BP
995 @name Table Cell Accessors
996 */
997 //@{
23324ae1
FM
998
999 /**
8acad210
VZ
1000 May be overridden to implement testing for empty cells.
1001
1002 This method is used by the grid to test if the given cell is not used
1003 and so whether a neighbouring cell may overflow into it. By default it
1004 only returns true if the value of the given cell, as returned by
1005 GetValue(), is empty.
8b9ef005 1006 */
8acad210 1007 virtual bool IsEmptyCell(int row, int col);
e54c96f1 1008
8b9ef005
BP
1009 /**
1010 Same as IsEmptyCell() but taking wxGridCellCoords.
7c913512 1011
8b9ef005
BP
1012 Notice that this method is not virtual, only IsEmptyCell() should be
1013 overridden.
1014 */
1015 bool IsEmpty(const wxGridCellCoords& coords);
7c913512 1016
afe0e400 1017 /**
8b9ef005
BP
1018 Must be overridden to implement accessing the table values as text.
1019 */
1020 virtual wxString GetValue(int row, int col) = 0;
23324ae1
FM
1021
1022 /**
8b9ef005
BP
1023 Must be overridden to implement setting the table values as text.
1024 */
1025 virtual void SetValue(int row, int col, const wxString& value) = 0;
23324ae1
FM
1026
1027 /**
8b9ef005 1028 Returns the type of the value in the given cell.
23324ae1 1029
8b9ef005
BP
1030 By default all cells are strings and this method returns
1031 @c wxGRID_VALUE_STRING.
1032 */
1033 virtual wxString GetTypeName(int row, int col);
23324ae1
FM
1034
1035 /**
8b9ef005
BP
1036 Returns true if the value of the given cell can be accessed as if it
1037 were of the specified type.
23324ae1 1038
8b9ef005
BP
1039 By default the cells can only be accessed as strings. Note that a cell
1040 could be accessible in different ways, e.g. a numeric cell may return
1041 @true for @c wxGRID_VALUE_NUMBER but also for @c wxGRID_VALUE_STRING
1042 indicating that the value can be coerced to a string form.
1043 */
1044 virtual bool CanGetValueAs(int row, int col, const wxString& typeName);
23324ae1
FM
1045
1046 /**
8b9ef005
BP
1047 Returns true if the value of the given cell can be set as if it were of
1048 the specified type.
23324ae1 1049
8b9ef005
BP
1050 @see CanGetValueAs()
1051 */
1052 virtual bool CanSetValueAs(int row, int col, const wxString& typeName);
e54c96f1 1053
8b9ef005
BP
1054 /**
1055 Returns the value of the given cell as a long.
7c913512 1056
8b9ef005
BP
1057 This should only be called if CanGetValueAs() returns @true when called
1058 with @c wxGRID_VALUE_NUMBER argument. Default implementation always
1059 return 0.
1060 */
1061 virtual long GetValueAsLong(int row, int col);
7c913512 1062
afe0e400 1063 /**
8b9ef005 1064 Returns the value of the given cell as a double.
23324ae1 1065
8b9ef005
BP
1066 This should only be called if CanGetValueAs() returns @true when called
1067 with @c wxGRID_VALUE_FLOAT argument. Default implementation always
1068 return 0.0.
1069 */
1070 virtual double GetValueAsDouble(int row, int col);
23324ae1
FM
1071
1072 /**
8b9ef005 1073 Returns the value of the given cell as a boolean.
23324ae1 1074
8b9ef005
BP
1075 This should only be called if CanGetValueAs() returns @true when called
1076 with @c wxGRID_VALUE_BOOL argument. Default implementation always
1077 return false.
1078 */
1079 virtual bool GetValueAsBool(int row, int col);
23324ae1
FM
1080
1081 /**
8b9ef005
BP
1082 Returns the value of the given cell as a user-defined type.
1083
1084 This should only be called if CanGetValueAs() returns @true when called
1085 with @a typeName. Default implementation always return @NULL.
1086 */
1087 virtual void *GetValueAsCustom(int row, int col, const wxString& typeName);
23324ae1
FM
1088
1089 /**
8b9ef005
BP
1090 Sets the value of the given cell as a long.
1091
1092 This should only be called if CanSetValueAs() returns @true when called
1093 with @c wxGRID_VALUE_NUMBER argument. Default implementation doesn't do
1094 anything.
1095 */
1096 virtual void SetValueAsLong(int row, int col, long value);
23324ae1
FM
1097
1098 /**
8b9ef005
BP
1099 Sets the value of the given cell as a double.
1100
1101 This should only be called if CanSetValueAs() returns @true when called
1102 with @c wxGRID_VALUE_FLOAT argument. Default implementation doesn't do
1103 anything.
1104 */
1105 virtual void SetValueAsDouble(int row, int col, double value);
23324ae1
FM
1106
1107 /**
8b9ef005
BP
1108 Sets the value of the given cell as a boolean.
1109
1110 This should only be called if CanSetValueAs() returns @true when called
1111 with @c wxGRID_VALUE_BOOL argument. Default implementation doesn't do
1112 anything.
1113 */
1114 virtual void SetValueAsBool( int row, int col, bool value );
23324ae1
FM
1115
1116 /**
8b9ef005
BP
1117 Sets the value of the given cell as a user-defined type.
1118
1119 This should only be called if CanSetValueAs() returns @true when called
1120 with @a typeName. Default implementation doesn't do anything.
1121 */
1122 virtual void SetValueAsCustom(int row, int col, const wxString& typeName,
1123 void *value);
1124
1125 //@}
1126
23324ae1
FM
1127
1128 /**
8b9ef005
BP
1129 Called by the grid when the table is associated with it.
1130
1131 The default implementation stores the pointer and returns it from its
1132 GetView() and so only makes sense if the table cannot be associated
1133 with more than one grid at a time.
1134 */
1135 virtual void SetView(wxGrid *grid);
23324ae1
FM
1136
1137 /**
8b9ef005
BP
1138 Returns the last grid passed to SetView().
1139 */
1140 virtual wxGrid *GetView() const;
1141
23324ae1
FM
1142
1143 /**
8b9ef005 1144 @name Table Structure Modifiers
23324ae1 1145
8b9ef005
BP
1146 Notice that none of these functions are pure virtual as they don't have
1147 to be implemented if the table structure is never modified after
1148 creation, i.e. neither rows nor columns are never added or deleted but
1149 that you do need to implement them if they are called, i.e. if your
1150 code either calls them directly or uses the matching wxGrid methods, as
1151 by default they simply do nothing which is definitely inappropriate.
1152 */
1153 //@{
23324ae1 1154
8b9ef005
BP
1155 /**
1156 Clear the table contents.
e54c96f1 1157
8b9ef005
BP
1158 This method is used by wxGrid::ClearGrid().
1159 */
1160 virtual void Clear();
7c913512 1161
8b9ef005
BP
1162 /**
1163 Insert additional rows into the table.
7c913512 1164
8b9ef005
BP
1165 @param pos
1166 The position of the first new row.
1167 @param numRows
1168 The number of rows to insert.
1169 */
1170 virtual bool InsertRows(size_t pos = 0, size_t numRows = 1);
7c913512 1171
23324ae1 1172 /**
8b9ef005
BP
1173 Append additional rows at the end of the table.
1174
1175 This method is provided in addition to InsertRows() as some data models
1176 may only support appending rows to them but not inserting them at
1177 arbitrary locations. In such case you may implement this method only
1178 and leave InsertRows() unimplemented.
1179
1180 @param numRows
1181 The number of rows to add.
1182 */
1183 virtual bool AppendRows(size_t numRows = 1);
23324ae1
FM
1184
1185 /**
8b9ef005 1186 Delete rows from the table.
afe0e400 1187
8b9ef005
BP
1188 @param pos
1189 The first row to delete.
1190 @param numRows
1191 The number of rows to delete.
1192 */
1193 virtual bool DeleteRows(size_t pos = 0, size_t numRows = 1);
1194
1195 /**
1196 Exactly the same as InsertRows() but for columns.
1197 */
1198 virtual bool InsertCols(size_t pos = 0, size_t numCols = 1);
23324ae1
FM
1199
1200 /**
8b9ef005
BP
1201 Exactly the same as AppendRows() but for columns.
1202 */
1203 virtual bool AppendCols(size_t numCols = 1);
23324ae1 1204
8b9ef005
BP
1205 /**
1206 Exactly the same as DeleteRows() but for columns.
1207 */
1208 virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1);
e54c96f1 1209
8b9ef005 1210 //@}
7c913512 1211
8b9ef005
BP
1212 /**
1213 @name Table Row and Column Labels
7c913512 1214
8b9ef005
BP
1215 By default the numbers are used for labeling rows and Latin letters for
1216 labeling columns. If the table has more than 26 columns, the pairs of
1217 letters are used starting from the 27-th one and so on, i.e. the
1218 sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ,
1219 AAA, ...
1220 */
1221 //@{
7c913512 1222
23324ae1 1223 /**
8b9ef005
BP
1224 Return the label of the specified row.
1225 */
1226 virtual wxString GetRowLabelValue(int row);
23324ae1 1227
8b9ef005
BP
1228 /**
1229 Return the label of the specified column.
1230 */
1231 virtual wxString GetColLabelValue(int col);
5e6e278d 1232
23324ae1 1233 /**
8b9ef005 1234 Set the given label for the specified row.
5e6e278d 1235
8b9ef005
BP
1236 The default version does nothing, i.e. the label is not stored. You
1237 must override this method in your derived class if you wish
1238 wxGrid::SetRowLabelValue() to work.
1239 */
1240 virtual void SetRowLabelValue(int row, const wxString& label);
23324ae1
FM
1241
1242 /**
8b9ef005
BP
1243 Exactly the same as SetRowLabelValue() but for columns.
1244 */
1245 virtual void SetColLabelValue(int col, const wxString& label);
23324ae1 1246
8b9ef005 1247 //@}
23324ae1
FM
1248
1249
8b9ef005
BP
1250 /**
1251 @name Attributes Management
e54c96f1 1252
8b9ef005
BP
1253 By default the attributes management is delegated to
1254 wxGridCellAttrProvider class. You may override the methods in this
1255 section to handle the attributes directly if, for example, they can be
1256 computed from the cell values.
1257 */
1258 //@{
7c913512 1259
8b9ef005
BP
1260 /**
1261 Associate this attributes provider with the table.
7c913512 1262
8b9ef005
BP
1263 The table takes ownership of @a attrProvider pointer and will delete it
1264 when it doesn't need it any more. The pointer can be @NULL, however
1265 this won't disable attributes management in the table but will just
1266 result in a default attributes being recreated the next time any of the
1267 other functions in this section is called. To completely disable the
1268 attributes support, should this be needed, you need to override
1269 CanHaveAttributes() to return @false.
1270 */
1271 void SetAttrProvider(wxGridCellAttrProvider *attrProvider);
afe0e400 1272
23324ae1 1273 /**
8b9ef005 1274 Returns the attribute provider currently being used.
23324ae1 1275
8b9ef005
BP
1276 This function may return @NULL if the attribute provider hasn't been
1277 neither associated with this table by SetAttrProvider() nor created on
1278 demand by any other methods.
1279 */
1280 wxGridCellAttrProvider *GetAttrProvider() const;
23324ae1
FM
1281
1282 /**
8b9ef005 1283 Return the attribute for the given cell.
23324ae1 1284
8b9ef005
BP
1285 By default this function is simply forwarded to
1286 wxGridCellAttrProvider::GetAttr() but it may be overridden to handle
1287 attributes directly in the table.
1288 */
1289 virtual wxGridCellAttr *GetAttr(int row, int col,
1290 wxGridCellAttr::wxAttrKind kind);
23324ae1
FM
1291
1292 /**
8b9ef005 1293 Set attribute of the specified cell.
23324ae1 1294
8b9ef005
BP
1295 By default this function is simply forwarded to
1296 wxGridCellAttrProvider::SetAttr().
1297
1298 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1299 */
1300 virtual void SetAttr(wxGridCellAttr* attr, int row, int col);
23324ae1
FM
1301
1302 /**
8b9ef005 1303 Set attribute of the specified row.
23324ae1 1304
8b9ef005
BP
1305 By default this function is simply forwarded to
1306 wxGridCellAttrProvider::SetRowAttr().
23324ae1 1307
8b9ef005
BP
1308 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1309 */
1310 virtual void SetRowAttr(wxGridCellAttr *attr, int row);
e54c96f1 1311
8b9ef005
BP
1312 /**
1313 Set attribute of the specified column.
7c913512 1314
8b9ef005
BP
1315 By default this function is simply forwarded to
1316 wxGridCellAttrProvider::SetColAttr().
7c913512 1317
8b9ef005
BP
1318 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1319 */
1320 virtual void SetColAttr(wxGridCellAttr *attr, int col);
1321
1322 //@}
7c913512 1323
23324ae1 1324 /**
8b9ef005
BP
1325 Returns true if this table supports attributes or false otherwise.
1326
1327 By default, the table automatically creates a wxGridCellAttrProvider
1328 when this function is called if it had no attribute provider before and
1329 returns @true.
1330 */
1331 virtual bool CanHaveAttributes();
23324ae1
FM
1332};
1333
574e1c5a
VZ
1334/**
1335 @class wxGridSizesInfo
1336
1337 wxGridSizesInfo stores information about sizes of all wxGrid rows or
d455444a 1338 columns.
574e1c5a
VZ
1339
1340 It assumes that most of the rows or columns (which are both called elements
1341 here as the difference between them doesn't matter at this class level)
1342 have the default size and so stores it separately. And it uses a wxHashMap
1343 to store the sizes of all elements which have the non-default size.
1344
1345 This structure is particularly useful for serializing the sizes of all
1346 wxGrid elements at once.
1347
1348 @library{wxadv}
1349 @category{grid}
1350 */
1351struct wxGridSizesInfo
1352{
1353 /**
1354 Default constructor.
1355
1356 m_sizeDefault and m_customSizes must be initialized later.
1357 */
1358 wxGridSizesInfo();
1359
1360 /**
1361 Constructor.
1362
1363 This constructor is used by wxGrid::GetRowSizes() and GetColSizes()
1364 methods. User code will usually use the default constructor instead.
1365
1366 @param defSize
1367 The default element size.
d455444a 1368 @param allSizes
574e1c5a
VZ
1369 Array containing the sizes of @em all elements, including those
1370 which have the default size.
1371 */
1372 wxGridSizesInfo(int defSize, const wxArrayInt& allSizes);
1373
1374 /**
1375 Get the element size.
1376
1377 @param pos
1378 The index of the element.
1379 @return
1380 The size for this element, using m_customSizes if @a pos is in it
1381 or m_sizeDefault otherwise.
1382 */
1383 int GetSize(unsigned pos) const;
1384
1385
1386 /// Default size
1387 int m_sizeDefault;
1388
1389 /**
1390 Map with element indices as keys and their sizes as values.
1391
1392 This map only contains the elements with non-default size.
1393 */
1394 wxUnsignedToIntHashMap m_customSizes;
1395};
23324ae1 1396
e54c96f1 1397
23324ae1 1398/**
8b9ef005 1399 @class wxGrid
7c913512 1400
8b9ef005 1401 wxGrid and its related classes are used for displaying and editing tabular
caac7804
BP
1402 data. They provide a rich set of features for display, editing, and
1403 interacting with a variety of data sources. For simple applications, and to
1404 help you get started, wxGrid is the only class you need to refer to
1405 directly. It will set up default instances of the other classes and manage
1406 them for you. For more complex applications you can derive your own classes
1407 for custom grid views, grid data tables, cell editors and renderers. The
1408 @ref overview_grid has examples of simple and more complex applications,
8b9ef005
BP
1409 explains the relationship between the various grid classes and has a
1410 summary of the keyboard shortcuts and mouse functions provided by wxGrid.
7c913512 1411
8b9ef005
BP
1412 A wxGridTableBase class holds the actual data to be displayed by a wxGrid
1413 class. One or more wxGrid classes may act as a view for one table class.
1414 The default table class is called wxGridStringTable and holds an array of
caac7804 1415 strings. An instance of such a class is created by CreateGrid().
23324ae1 1416
8b9ef005
BP
1417 wxGridCellRenderer is the abstract base class for rendereing contents in a
1418 cell. The following renderers are predefined:
caac7804
BP
1419
1420 - wxGridCellBoolRenderer
1421 - wxGridCellFloatRenderer
1422 - wxGridCellNumberRenderer
1423 - wxGridCellStringRenderer
1424
8b9ef005 1425 The look of a cell can be further defined using wxGridCellAttr. An object
caac7804 1426 of this type may be returned by wxGridTableBase::GetAttr().
3c4f71cc 1427
8b9ef005
BP
1428 wxGridCellEditor is the abstract base class for editing the value of a
1429 cell. The following editors are predefined:
caac7804
BP
1430
1431 - wxGridCellBoolEditor
1432 - wxGridCellChoiceEditor
1433 - wxGridCellFloatEditor
1434 - wxGridCellNumberEditor
1435 - wxGridCellTextEditor
f8f31de6 1436
caac7804
BP
1437 Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and
1438 wxGridEditorCreatedEvent for the documentation of all event types you can
1439 use with wxGrid.
8b9ef005
BP
1440
1441 @library{wxadv}
1442 @category{grid}
23324ae1 1443
caac7804 1444 @see @ref overview_grid, wxGridUpdateLocker
8b9ef005
BP
1445*/
1446class wxGrid : public wxScrolledWindow
1447{
1448public:
caac7804 1449
23324ae1 1450 /**
8b9ef005
BP
1451 Different selection modes supported by the grid.
1452 */
1453 enum wxGridSelectionModes
1454 {
1455 /**
1456 The default selection mode allowing selection of the individual
1457 cells as well as of the entire rows and columns.
1458 */
1459 wxGridSelectCells,
23324ae1 1460
8b9ef005
BP
1461 /**
1462 The selection mode allowing the selection of the entire rows only.
3c4f71cc 1463
8b9ef005
BP
1464 The user won't be able to select any cells or columns in this mode.
1465 */
1466 wxGridSelectRows,
23324ae1 1467
8b9ef005
BP
1468 /**
1469 The selection mode allowing the selection of the entire columns only.
3c4f71cc 1470
8b9ef005
BP
1471 The user won't be able to select any cells or rows in this mode.
1472 */
1473 wxGridSelectColumns
1474 };
23324ae1 1475
caac7804
BP
1476
1477 /**
1478 @name Constructors and Initialization
1479 */
1480 //@{
1481
23324ae1 1482 /**
8b9ef005 1483 Default constructor.
3c4f71cc 1484
8b9ef005
BP
1485 You must call Create() to really create the grid window and also call
1486 CreateGrid() or SetTable() to initialize the grid contents.
1487 */
1488 wxGrid();
23324ae1 1489 /**
8b9ef005 1490 Constructor creating the grid window.
3c4f71cc 1491
8b9ef005
BP
1492 You must call either CreateGrid() or SetTable() to initialize the grid
1493 contents before using it.
23324ae1 1494 */
caac7804 1495 wxGrid(wxWindow* parent, wxWindowID id,
8b9ef005
BP
1496 const wxPoint& pos = wxDefaultPosition,
1497 const wxSize& size = wxDefaultSize,
1498 long style = wxWANTS_CHARS,
1499 const wxString& name = wxGridNameStr);
23324ae1 1500
caac7804
BP
1501 /**
1502 Destructor.
1503
1504 This will also destroy the associated grid table unless you passed a
1505 table object to the grid and specified that the grid should not take
1506 ownership of the table (see SetTable()).
1507 */
1508 virtual ~wxGrid();
1509
23324ae1 1510 /**
8b9ef005
BP
1511 Creates the grid window for an object initialized using the default
1512 constructor.
3c4f71cc 1513
8b9ef005
BP
1514 You must call either CreateGrid() or SetTable() to initialize the grid
1515 contents before using it.
1516 */
caac7804 1517 bool Create(wxWindow* parent, wxWindowID id,
8b9ef005
BP
1518 const wxPoint& pos = wxDefaultPosition,
1519 const wxSize& size = wxDefaultSize,
1520 long style = wxWANTS_CHARS,
1521 const wxString& name = wxGridNameStr);
23324ae1
FM
1522
1523 /**
caac7804 1524 Creates a grid with the specified initial number of rows and columns.
3c4f71cc 1525
caac7804
BP
1526 Call this directly after the grid constructor. When you use this
1527 function wxGrid will create and manage a simple table of string values
1528 for you. All of the grid data will be stored in memory.
1529
1530 For applications with more complex data types or relationships, or for
1531 dealing with very large datasets, you should derive your own grid table
1532 class and pass a table object to the grid with SetTable().
23324ae1 1533 */
caac7804
BP
1534 bool CreateGrid(int numRows, int numCols,
1535 wxGridSelectionModes selmode = wxGridSelectCells);
23324ae1
FM
1536
1537 /**
caac7804 1538 Passes a pointer to a custom grid table to be used by the grid.
3c4f71cc 1539
caac7804
BP
1540 This should be called after the grid constructor and before using the
1541 grid object. If @a takeOwnership is set to @true then the table will be
1542 deleted by the wxGrid destructor.
3c4f71cc 1543
caac7804
BP
1544 Use this function instead of CreateGrid() when your application
1545 involves complex or non-string data or data sets that are too large to
1546 fit wholly in memory.
23324ae1 1547 */
caac7804
BP
1548 bool SetTable(wxGridTableBase* table, bool takeOwnership = false,
1549 wxGridSelectionModes selmode = wxGridSelectCells);
23324ae1 1550
caac7804 1551 //@}
8b9ef005 1552
3c4f71cc 1553
caac7804
BP
1554 /**
1555 @name Grid Line Formatting
1556 */
1557 //@{
1558
1559 /**
1560 Turns the drawing of grid lines on or off.
23324ae1 1561 */
caac7804 1562 void EnableGridLines(bool enable = true);
23324ae1
FM
1563
1564 /**
caac7804 1565 Returns the pen used for vertical grid lines.
3c4f71cc 1566
caac7804
BP
1567 This virtual function may be overridden in derived classes in order to
1568 change the appearance of individual grid lines for the given column
1569 @a col.
23324ae1 1570
caac7804
BP
1571 See GetRowGridLinePen() for an example.
1572 */
1573 virtual wxPen GetColGridLinePen(int col);
23324ae1
FM
1574
1575 /**
caac7804 1576 Returns the pen used for grid lines.
23324ae1 1577
caac7804
BP
1578 This virtual function may be overridden in derived classes in order to
1579 change the appearance of grid lines. Note that currently the pen width
1580 must be 1.
3c4f71cc 1581
caac7804
BP
1582 @see GetColGridLinePen(), GetRowGridLinePen()
1583 */
1584 virtual wxPen GetDefaultGridLinePen();
23324ae1
FM
1585
1586 /**
caac7804
BP
1587 Returns the colour used for grid lines.
1588
1589 @see GetDefaultGridLinePen()
23324ae1 1590 */
caac7804 1591 wxColour GetGridLineColour() const;
23324ae1
FM
1592
1593 /**
caac7804
BP
1594 Returns the pen used for horizontal grid lines.
1595
1596 This virtual function may be overridden in derived classes in order to
1597 change the appearance of individual grid line for the given @a row.
1598
1599 Example:
1600 @code
1601 // in a grid displaying music notation, use a solid black pen between
1602 // octaves (C0=row 127, C1=row 115 etc.)
1603 wxPen MidiGrid::GetRowGridLinePen(int row)
1604 {
1605 if ( row % 12 == 7 )
1606 return wxPen(*wxBLACK, 1, wxSOLID);
1607 else
1608 return GetDefaultGridLinePen();
1609 }
1610 @endcode
23324ae1 1611 */
caac7804 1612 virtual wxPen GetRowGridLinePen(int row);
23324ae1
FM
1613
1614 /**
caac7804 1615 Returns @true if drawing of grid lines is turned on, @false otherwise.
23324ae1 1616 */
caac7804 1617 bool GridLinesEnabled() const;
23324ae1
FM
1618
1619 /**
caac7804 1620 Sets the colour used to draw grid lines.
23324ae1 1621 */
caac7804
BP
1622 void SetGridLineColour(const wxColour& colour);
1623
1624 //@}
1625
23324ae1
FM
1626
1627 /**
caac7804
BP
1628 @name Label Values and Formatting
1629 */
1630 //@{
23324ae1
FM
1631
1632 /**
caac7804
BP
1633 Sets the arguments to the current column label alignment values.
1634
1635 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1636 or @c wxALIGN_RIGHT.
1637
1638 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1639 @c wxALIGN_BOTTOM.
23324ae1 1640 */
caac7804 1641 void GetColLabelAlignment(int* horiz, int* vert) const;
23324ae1
FM
1642
1643 /**
caac7804
BP
1644 Returns the orientation of the column labels (either @c wxHORIZONTAL or
1645 @c wxVERTICAL).
23324ae1 1646 */
caac7804 1647 int GetColLabelTextOrientation() const;
23324ae1
FM
1648
1649 /**
caac7804 1650 Returns the specified column label.
7c913512 1651
caac7804
BP
1652 The default grid table class provides column labels of the form
1653 A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can
1654 override wxGridTableBase::GetColLabelValue() to provide your own
1655 labels.
23324ae1 1656 */
caac7804 1657 wxString GetColLabelValue(int col) const;
23324ae1 1658
8b9ef005 1659 /**
caac7804
BP
1660 Returns the colour used for the background of row and column labels.
1661 */
1662 wxColour GetLabelBackgroundColour() const;
e54c96f1 1663
caac7804
BP
1664 /**
1665 Returns the font used for row and column labels.
1666 */
1667 wxFont GetLabelFont() const;
7c913512 1668
caac7804
BP
1669 /**
1670 Returns the colour used for row and column label text.
8b9ef005 1671 */
caac7804 1672 wxColour GetLabelTextColour() const;
7c913512 1673
23324ae1 1674 /**
caac7804 1675 Returns the alignment used for row labels.
3c4f71cc 1676
caac7804
BP
1677 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1678 or @c wxALIGN_RIGHT.
1679
1680 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1681 @c wxALIGN_BOTTOM.
23324ae1 1682 */
caac7804 1683 void GetRowLabelAlignment(int* horiz, int* vert) const;
23324ae1
FM
1684
1685 /**
caac7804 1686 Returns the specified row label.
23324ae1 1687
caac7804
BP
1688 The default grid table class provides numeric row labels. If you are
1689 using a custom grid table you can override
1690 wxGridTableBase::GetRowLabelValue() to provide your own labels.
23324ae1 1691 */
caac7804 1692 wxString GetRowLabelValue(int row) const;
23324ae1
FM
1693
1694 /**
caac7804
BP
1695 Hides the column labels by calling SetColLabelSize() with a size of 0.
1696 Show labels again by calling that method with a width greater than 0.
23324ae1 1697 */
caac7804 1698 void HideColLabels();
23324ae1
FM
1699
1700 /**
caac7804 1701 Hides the row labels by calling SetRowLabelSize() with a size of 0.
23324ae1 1702
caac7804
BP
1703 The labels can be shown again by calling SetRowLabelSize() with a width
1704 greater than 0.
23324ae1 1705 */
caac7804 1706 void HideRowLabels();
23324ae1
FM
1707
1708 /**
caac7804 1709 Sets the horizontal and vertical alignment of column label text.
23324ae1 1710
caac7804
BP
1711 Horizontal alignment should be one of @c wxALIGN_LEFT,
1712 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
1713 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
23324ae1 1714 */
caac7804 1715 void SetColLabelAlignment(int horiz, int vert);
23324ae1
FM
1716
1717 /**
caac7804
BP
1718 Sets the orientation of the column labels (either @c wxHORIZONTAL or
1719 @c wxVERTICAL).
8b9ef005 1720 */
caac7804 1721 void SetColLabelTextOrientation(int textOrientation);
7c913512 1722
23324ae1 1723 /**
caac7804 1724 Set the value for the given column label.
8b9ef005 1725
caac7804
BP
1726 If you are using a custom grid table you must override
1727 wxGridTableBase::SetColLabelValue() for this to have any effect.
23324ae1 1728 */
caac7804 1729 void SetColLabelValue(int col, const wxString& value);
23324ae1
FM
1730
1731 /**
caac7804 1732 Sets the background colour for row and column labels.
23324ae1 1733 */
caac7804 1734 void SetLabelBackgroundColour(const wxColour& colour);
23324ae1 1735
8b9ef005 1736 /**
caac7804
BP
1737 Sets the font for row and column labels.
1738 */
1739 void SetLabelFont(const wxFont& font);
55f0bf1f 1740
8b9ef005 1741 /**
caac7804
BP
1742 Sets the colour for row and column label text.
1743 */
1744 void SetLabelTextColour(const wxColour& colour);
55f0bf1f 1745
8b9ef005 1746 /**
caac7804 1747 Sets the horizontal and vertical alignment of row label text.
7c913512 1748
caac7804
BP
1749 Horizontal alignment should be one of @c wxALIGN_LEFT,
1750 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
1751 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
8b9ef005 1752 */
caac7804 1753 void SetRowLabelAlignment(int horiz, int vert);
7c913512 1754
23324ae1 1755 /**
caac7804 1756 Sets the value for the given row label.
55f0bf1f 1757
caac7804
BP
1758 If you are using a derived grid table you must override
1759 wxGridTableBase::SetRowLabelValue() for this to have any effect.
8b9ef005 1760 */
caac7804 1761 void SetRowLabelValue(int row, const wxString& value);
55f0bf1f 1762
8b9ef005 1763 /**
caac7804 1764 Call this in order to make the column labels use a native look by using
03faec76 1765 wxRendererNative::DrawHeaderButton() internally.
55f0bf1f 1766
caac7804
BP
1767 There is no equivalent method for drawing row columns as there is not
1768 native look for that. This option is useful when using wxGrid for
1769 displaying tables and not as a spread-sheet.
ad805b9e 1770
03faec76 1771 @see UseNativeColHeader()
8b9ef005 1772 */
caac7804 1773 void SetUseNativeColLabels(bool native = true);
55f0bf1f 1774
ad805b9e
VZ
1775 /**
1776 Enable the use of native header window for column labels.
1777
1778 If this function is called with @true argument, a wxHeaderCtrl is used
1779 instead to display the column labels instead of drawing them in wxGrid
1780 code itself. This has the advantage of making the grid look and feel
1781 perfectly the same as native applications (using SetUseNativeColLabels()
1782 the grid can be made to look more natively but it still doesn't feel
1783 natively, notably the column resizing and dragging still works slightly
1784 differently as it is implemented in wxWidgets itself) but results in
1785 different behaviour for column and row headers, for which there is no
1786 equivalent function, and, most importantly, is unsuitable for grids
1787 with huge numbers of columns as wxHeaderCtrl doesn't support virtual
1788 mode. Because of this, by default the grid does not use the native
1789 header control but you should call this function to enable it if you
1790 are using the grid to display tabular data and don't have thousands of
1791 columns in it.
1792
03faec76
FM
1793 Also note that currently @c wxEVT_GRID_LABEL_LEFT_DCLICK and
1794 @c wxEVT_GRID_LABEL_RIGHT_DCLICK events are not generated for the column
ad805b9e
VZ
1795 labels if the native columns header is used (but this limitation could
1796 possibly be lifted in the future).
1797 */
1798 void UseNativeColHeader(bool native = true);
1799
caac7804 1800 //@}
55f0bf1f 1801
55f0bf1f
VZ
1802
1803 /**
caac7804 1804 @name Cell Formatting
55f0bf1f 1805
caac7804
BP
1806 Note that wxGridCellAttr can be used alternatively to most of these
1807 methods. See the "Attributes Management" of wxGridTableBase.
1808 */
1809 //@{
23324ae1
FM
1810
1811 /**
caac7804
BP
1812 Sets the arguments to the horizontal and vertical text alignment values
1813 for the grid cell at the specified location.
55f0bf1f 1814
caac7804
BP
1815 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1816 or @c wxALIGN_RIGHT.
1817
1818 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1819 @c wxALIGN_BOTTOM.
8b9ef005 1820 */
caac7804 1821 void GetCellAlignment(int row, int col, int* horiz, int* vert) const;
55f0bf1f
VZ
1822
1823 /**
caac7804 1824 Returns the background colour of the cell at the specified location.
23324ae1 1825 */
caac7804 1826 wxColour GetCellBackgroundColour(int row, int col) const;
23324ae1
FM
1827
1828 /**
caac7804
BP
1829 Returns the font for text in the grid cell at the specified location.
1830 */
1831 wxFont GetCellFont(int row, int col) const;
55f0bf1f 1832
caac7804
BP
1833 /**
1834 Returns the text colour for the grid cell at the specified location.
23324ae1 1835 */
caac7804 1836 wxColour GetCellTextColour(int row, int col) const;
23324ae1
FM
1837
1838 /**
caac7804
BP
1839 Returns the default cell alignment.
1840
1841 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1842 or @c wxALIGN_RIGHT.
55f0bf1f 1843
caac7804
BP
1844 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1845 @c wxALIGN_BOTTOM.
1846
1847 @see SetDefaultCellAlignment()
8b9ef005 1848 */
caac7804 1849 void GetDefaultCellAlignment(int* horiz, int* vert) const;
55f0bf1f 1850
8b9ef005 1851 /**
caac7804 1852 Returns the current default background colour for grid cells.
23324ae1 1853 */
caac7804 1854 wxColour GetDefaultCellBackgroundColour() const;
23324ae1 1855
9f7aee01 1856 /**
caac7804 1857 Returns the current default font for grid cell text.
8b9ef005 1858 */
caac7804 1859 wxFont GetDefaultCellFont() const;
9f7aee01 1860
8b9ef005 1861 /**
caac7804 1862 Returns the current default colour for grid cell text.
8b9ef005 1863 */
caac7804 1864 wxColour GetDefaultCellTextColour() const;
9f7aee01 1865
8b9ef005 1866 /**
caac7804
BP
1867 Sets the horizontal and vertical alignment for grid cell text at the
1868 specified location.
9f7aee01 1869
caac7804
BP
1870 Horizontal alignment should be one of @c wxALIGN_LEFT,
1871 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
1872
1873 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
1874 or @c wxALIGN_BOTTOM.
1875 */
1876 void SetCellAlignment(int row, int col, int horiz, int vert);
9f7aee01 1877 /**
caac7804
BP
1878 Sets the horizontal and vertical alignment for grid cell text at the
1879 specified location.
9f7aee01 1880
caac7804
BP
1881 Horizontal alignment should be one of @c wxALIGN_LEFT,
1882 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
9f7aee01 1883
caac7804
BP
1884 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
1885 or @c wxALIGN_BOTTOM.
8b9ef005 1886 */
caac7804 1887 void SetCellAlignment(int align, int row, int col);
9f7aee01 1888
23324ae1 1889 /**
caac7804 1890 Set the background colour for the given cell or all cells by default.
23324ae1 1891 */
caac7804 1892 void SetCellBackgroundColour(int row, int col, const wxColour& colour);
23324ae1
FM
1893
1894 /**
caac7804
BP
1895 Sets the font for text in the grid cell at the specified location.
1896 */
1897 void SetCellFont(int row, int col, const wxFont& font);
8b9ef005 1898
caac7804
BP
1899 /**
1900 Sets the text colour for the given cell.
1901 */
1902 void SetCellTextColour(int row, int col, const wxColour& colour);
1903 /**
1904 Sets the text colour for the given cell.
1905 */
1906 void SetCellTextColour(const wxColour& val, int row, int col);
1907 /**
1908 Sets the text colour for all cells by default.
1909 */
1910 void SetCellTextColour(const wxColour& colour);
8b9ef005 1911
caac7804
BP
1912 /**
1913 Sets the default horizontal and vertical alignment for grid cell text.
1914
1915 Horizontal alignment should be one of @c wxALIGN_LEFT,
1916 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
1917 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
23324ae1 1918 */
caac7804 1919 void SetDefaultCellAlignment(int horiz, int vert);
23324ae1
FM
1920
1921 /**
caac7804 1922 Sets the default background colour for grid cells.
23324ae1 1923 */
caac7804 1924 void SetDefaultCellBackgroundColour(const wxColour& colour);
23324ae1
FM
1925
1926 /**
caac7804
BP
1927 Sets the default font to be used for grid cell text.
1928 */
1929 void SetDefaultCellFont(const wxFont& font);
8b9ef005 1930
caac7804
BP
1931 /**
1932 Sets the current default colour for grid cell text.
23324ae1 1933 */
caac7804
BP
1934 void SetDefaultCellTextColour(const wxColour& colour);
1935
1936 //@}
1937
1938
1939 /**
1940 @name Cell Values, Editors, and Renderers
1941
1942 Note that wxGridCellAttr can be used alternatively to most of these
1943 methods. See the "Attributes Management" of wxGridTableBase.
1944 */
1945 //@{
23324ae1
FM
1946
1947 /**
caac7804
BP
1948 Returns @true if the in-place edit control for the current grid cell
1949 can be used and @false otherwise.
1950
1951 This function always returns @false for the read-only cells.
23324ae1 1952 */
caac7804 1953 bool CanEnableCellControl() const;
23324ae1
FM
1954
1955 /**
caac7804 1956 Disables in-place editing of grid cells.
8b9ef005 1957
caac7804
BP
1958 Equivalent to calling EnableCellEditControl(@false).
1959 */
1960 void DisableCellEditControl();
8b9ef005 1961
caac7804
BP
1962 /**
1963 Enables or disables in-place editing of grid cell data.
1964
1965 The grid will issue either a @c wxEVT_GRID_EDITOR_SHOWN or
1966 @c wxEVT_GRID_EDITOR_HIDDEN event.
23324ae1 1967 */
caac7804 1968 void EnableCellEditControl(bool enable = true);
23324ae1
FM
1969
1970 /**
caac7804
BP
1971 Makes the grid globally editable or read-only.
1972
1973 If the edit argument is @false this function sets the whole grid as
1974 read-only. If the argument is @true the grid is set to the default
1975 state where cells may be editable. In the default state you can set
1976 single grid cells and whole rows and columns to be editable or
1977 read-only via wxGridCellAttr::SetReadOnly(). For single cells you
1978 can also use the shortcut function SetReadOnly().
1979
1980 For more information about controlling grid cell attributes see the
1981 wxGridCellAttr class and the @ref overview_grid.
23324ae1 1982 */
caac7804 1983 void EnableEditing(bool edit);
23324ae1
FM
1984
1985 /**
8b9ef005 1986 Returns a pointer to the editor for the cell at the specified location.
3c4f71cc 1987
caac7804
BP
1988 See wxGridCellEditor and the @ref overview_grid for more information
1989 about cell editors and renderers.
3c4f71cc 1990
8b9ef005 1991 The caller must call DecRef() on the returned pointer.
23324ae1 1992 */
8b9ef005 1993 wxGridCellEditor* GetCellEditor(int row, int col) const;
23324ae1 1994
8b9ef005
BP
1995 /**
1996 Returns a pointer to the renderer for the grid cell at the specified
1997 location.
08dd9b5a 1998
caac7804
BP
1999 See wxGridCellRenderer and the @ref overview_grid for more information
2000 about cell editors and renderers.
8b9ef005
BP
2001
2002 The caller must call DecRef() on the returned pointer.
23324ae1 2003 */
8b9ef005 2004 wxGridCellRenderer* GetCellRenderer(int row, int col) const;
23324ae1
FM
2005
2006 /**
caac7804 2007 Returns the string contained in the cell at the specified location.
23324ae1 2008
caac7804
BP
2009 For simple applications where a grid object automatically uses a
2010 default grid table of string values you use this function together with
2011 SetCellValue() to access cell values. For more complex applications
2012 where you have derived your own grid table class that contains various
2013 data types (e.g. numeric, boolean or user-defined custom types) then
2014 you only use this function for those cells that contain string values.
2015
2016 See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
2017 more information.
2018 */
2019 wxString GetCellValue(int row, int col) const;
23324ae1 2020 /**
8b9ef005 2021 Returns the string contained in the cell at the specified location.
08dd9b5a 2022
8b9ef005
BP
2023 For simple applications where a grid object automatically uses a
2024 default grid table of string values you use this function together with
2025 SetCellValue() to access cell values. For more complex applications
2026 where you have derived your own grid table class that contains various
2027 data types (e.g. numeric, boolean or user-defined custom types) then
2028 you only use this function for those cells that contain string values.
2029
caac7804
BP
2030 See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
2031 more information.
23324ae1 2032 */
882678eb 2033 wxString GetCellValue(const wxGridCellCoords& coords) const;
23324ae1
FM
2034
2035 /**
caac7804
BP
2036 Returns a pointer to the current default grid cell editor.
2037
2038 See wxGridCellEditor and the @ref overview_grid for more information
2039 about cell editors and renderers.
23324ae1 2040 */
caac7804 2041 wxGridCellEditor* GetDefaultEditor() const;
23324ae1
FM
2042
2043 /**
caac7804 2044 Returns the default editor for the specified cell.
08dd9b5a 2045
caac7804
BP
2046 The base class version returns the editor appropriate for the current
2047 cell type but this method may be overridden in the derived classes to
2048 use custom editors for some cells by default.
8b9ef005 2049
caac7804
BP
2050 Notice that the same may be achieved in a usually simpler way by
2051 associating a custom editor with the given cell or cells.
23324ae1 2052
caac7804
BP
2053 The caller must call DecRef() on the returned pointer.
2054 */
2055 virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const;
23324ae1 2056 /**
caac7804 2057 Returns the default editor for the specified cell.
08dd9b5a 2058
caac7804
BP
2059 The base class version returns the editor appropriate for the current
2060 cell type but this method may be overridden in the derived classes to
2061 use custom editors for some cells by default.
8b9ef005 2062
caac7804
BP
2063 Notice that the same may be achieved in a usually simpler way by
2064 associating a custom editor with the given cell or cells.
23324ae1 2065
caac7804 2066 The caller must call DecRef() on the returned pointer.
23324ae1 2067 */
caac7804 2068 wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const;
23324ae1
FM
2069
2070 /**
caac7804
BP
2071 Returns the default editor for the cells containing values of the given
2072 type.
55f0bf1f 2073
caac7804
BP
2074 The base class version returns the editor which was associated with the
2075 specified @a typeName when it was registered RegisterDataType() but
2076 this function may be overridden to return something different. This
2077 allows to override an editor used for one of the standard types.
2078
2079 The caller must call DecRef() on the returned pointer.
23324ae1 2080 */
caac7804 2081 virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const;
23324ae1
FM
2082
2083 /**
caac7804 2084 Returns a pointer to the current default grid cell renderer.
8b9ef005 2085
caac7804
BP
2086 See wxGridCellRenderer and the @ref overview_grid for more information
2087 about cell editors and renderers.
2088
2089 The caller must call DecRef() on the returned pointer.
23324ae1 2090 */
caac7804 2091 wxGridCellRenderer* GetDefaultRenderer() const;
23324ae1 2092
9f7aee01 2093 /**
caac7804
BP
2094 Returns the default renderer for the given cell.
2095
2096 The base class version returns the renderer appropriate for the current
2097 cell type but this method may be overridden in the derived classes to
2098 use custom renderers for some cells by default.
2099
2100 The caller must call DecRef() on the returned pointer.
8b9ef005 2101 */
caac7804 2102 virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const;
9f7aee01 2103
8b9ef005 2104 /**
caac7804
BP
2105 Returns the default renderer for the cell containing values of the
2106 given type.
9f7aee01 2107
caac7804 2108 @see GetDefaultEditorForType()
8b9ef005 2109 */
caac7804 2110 virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const;
08dd9b5a 2111
8b9ef005 2112 /**
caac7804 2113 Hides the in-place cell edit control.
23324ae1 2114 */
caac7804 2115 void HideCellEditControl();
23324ae1
FM
2116
2117 /**
caac7804 2118 Returns @true if the in-place edit control is currently enabled.
8b9ef005 2119 */
caac7804 2120 bool IsCellEditControlEnabled() const;
3c4f71cc 2121
8b9ef005 2122 /**
caac7804 2123 Returns @true if the current cell is read-only.
3c4f71cc 2124
caac7804 2125 @see SetReadOnly(), IsReadOnly()
23324ae1 2126 */
caac7804 2127 bool IsCurrentCellReadOnly() const;
23324ae1
FM
2128
2129 /**
caac7804
BP
2130 Returns @false if the whole grid has been set as read-only or @true
2131 otherwise.
2132
2133 See EnableEditing() for more information about controlling the editing
2134 status of grid cells.
8b9ef005 2135 */
caac7804 2136 bool IsEditable() const;
23324ae1 2137
8b9ef005 2138 /**
caac7804 2139 Returns @true if the cell at the specified location can't be edited.
55f0bf1f 2140
caac7804 2141 @see SetReadOnly(), IsCurrentCellReadOnly()
23324ae1 2142 */
caac7804 2143 bool IsReadOnly(int row, int col) const;
23324ae1
FM
2144
2145 /**
caac7804 2146 Register a new data type.
08dd9b5a 2147
caac7804
BP
2148 The data types allow to naturally associate specific renderers and
2149 editors to the cells containing values of the given type. For example,
2150 the grid automatically registers a data type with the name
2151 @c wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and
2152 wxGridCellTextEditor as its renderer and editor respectively -- this is
2153 the data type used by all the cells of the default wxGridStringTable,
2154 so this renderer and editor are used by default for all grid cells.
8b9ef005 2155
caac7804
BP
2156 However if a custom table returns @c wxGRID_VALUE_BOOL from its
2157 wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and
2158 wxGridCellBoolEditor are used for it because the grid also registers a
2159 boolean data type with this name.
8b9ef005 2160
caac7804
BP
2161 And as this mechanism is completely generic, you may register your own
2162 data types using your own custom renderers and editors. Just remember
2163 that the table must identify a cell as being of the given type for them
2164 to be used for this cell.
2165
2166 @param typeName
2167 Name of the new type. May be any string, but if the type name is
2168 the same as the name of an already registered type, including one
2169 of the standard ones (which are @c wxGRID_VALUE_STRING, @c
2170 wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
2171 and @c wxGRID_VALUE_CHOICE), then the new registration information
2172 replaces the previously used renderer and editor.
2173 @param renderer
2174 The renderer to use for the cells of this type. Its ownership is
2175 taken by the grid, i.e. it will call DecRef() on this pointer when
2176 it doesn't need it any longer.
2177 @param editor
2178 The editor to use for the cells of this type. Its ownership is also
2179 taken by the grid.
23324ae1 2180 */
caac7804
BP
2181 void RegisterDataType(const wxString& typeName,
2182 wxGridCellRenderer* renderer,
2183 wxGridCellEditor* editor);
23324ae1
FM
2184
2185 /**
caac7804
BP
2186 Sets the value of the current grid cell to the current in-place edit
2187 control value.
55f0bf1f 2188
caac7804
BP
2189 This is called automatically when the grid cursor moves from the
2190 current cell to a new cell. It is also a good idea to call this
2191 function when closing a grid since any edits to the final cell location
2192 will not be saved otherwise.
23324ae1 2193 */
caac7804 2194 void SaveEditControlValue();
23324ae1
FM
2195
2196 /**
caac7804 2197 Sets the editor for the grid cell at the specified location.
55f0bf1f 2198
caac7804 2199 The grid will take ownership of the pointer.
8b9ef005 2200
caac7804
BP
2201 See wxGridCellEditor and the @ref overview_grid for more information
2202 about cell editors and renderers.
23324ae1 2203 */
caac7804 2204 void SetCellEditor(int row, int col, wxGridCellEditor* editor);
23324ae1
FM
2205
2206 /**
caac7804 2207 Sets the renderer for the grid cell at the specified location.
55f0bf1f 2208
caac7804 2209 The grid will take ownership of the pointer.
8b9ef005 2210
caac7804
BP
2211 See wxGridCellRenderer and the @ref overview_grid for more information
2212 about cell editors and renderers.
23324ae1 2213 */
caac7804 2214 void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer);
23324ae1
FM
2215
2216 /**
caac7804 2217 Sets the string value for the cell at the specified location.
55f0bf1f 2218
caac7804
BP
2219 For simple applications where a grid object automatically uses a
2220 default grid table of string values you use this function together with
2221 GetCellValue() to access cell values. For more complex applications
2222 where you have derived your own grid table class that contains various
2223 data types (e.g. numeric, boolean or user-defined custom types) then
2224 you only use this function for those cells that contain string values.
8b9ef005 2225
caac7804
BP
2226 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2227 more information.
23324ae1 2228 */
caac7804 2229 void SetCellValue(int row, int col, const wxString& s);
23324ae1 2230 /**
caac7804 2231 Sets the string value for the cell at the specified location.
55f0bf1f 2232
caac7804
BP
2233 For simple applications where a grid object automatically uses a
2234 default grid table of string values you use this function together with
2235 GetCellValue() to access cell values. For more complex applications
2236 where you have derived your own grid table class that contains various
2237 data types (e.g. numeric, boolean or user-defined custom types) then
2238 you only use this function for those cells that contain string values.
23324ae1 2239
caac7804
BP
2240 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2241 more information.
23324ae1 2242 */
caac7804 2243 void SetCellValue(const wxGridCellCoords& coords, const wxString& s);
23324ae1 2244 /**
caac7804
BP
2245 @deprecated Please use SetCellValue(int,int,const wxString&) or
2246 SetCellValue(const wxGridCellCoords&,const wxString&)
2247 instead.
23324ae1 2248
caac7804 2249 Sets the string value for the cell at the specified location.
23324ae1 2250
caac7804
BP
2251 For simple applications where a grid object automatically uses a
2252 default grid table of string values you use this function together with
2253 GetCellValue() to access cell values. For more complex applications
2254 where you have derived your own grid table class that contains various
2255 data types (e.g. numeric, boolean or user-defined custom types) then
2256 you only use this function for those cells that contain string values.
2257
2258 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2259 more information.
23324ae1 2260 */
caac7804 2261 void SetCellValue(const wxString& val, int row, int col);
23324ae1
FM
2262
2263 /**
caac7804 2264 Sets the specified column to display boolean values.
55f0bf1f 2265
caac7804 2266 @see SetColFormatCustom()
23324ae1 2267 */
caac7804 2268 void SetColFormatBool(int col);
23324ae1
FM
2269
2270 /**
caac7804 2271 Sets the specified column to display data in a custom format.
23324ae1 2272
caac7804
BP
2273 This method provides an alternative to defining a custom grid table
2274 which would return @a typeName from its GetTypeName() method for the
2275 cells in this column: while it doesn't really change the type of the
2276 cells in this column, it does associate the renderer and editor used
2277 for the cells of the specified type with them.
23324ae1 2278
caac7804
BP
2279 See the @ref overview_grid for more information on working with custom
2280 data types.
23324ae1 2281 */
caac7804 2282 void SetColFormatCustom(int col, const wxString& typeName);
23324ae1
FM
2283
2284 /**
caac7804
BP
2285 Sets the specified column to display floating point values with the
2286 given width and precision.
55f0bf1f 2287
caac7804 2288 @see SetColFormatCustom()
23324ae1 2289 */
caac7804 2290 void SetColFormatFloat(int col, int width = -1, int precision = -1);
23324ae1
FM
2291
2292 /**
caac7804 2293 Sets the specified column to display integer values.
8b9ef005 2294
caac7804 2295 @see SetColFormatCustom()
23324ae1 2296 */
caac7804 2297 void SetColFormatNumber(int col);
23324ae1
FM
2298
2299 /**
caac7804 2300 Sets the default editor for grid cells.
3c4f71cc 2301
caac7804 2302 The grid will take ownership of the pointer.
55f0bf1f 2303
caac7804
BP
2304 See wxGridCellEditor and the @ref overview_grid for more information
2305 about cell editors and renderers.
23324ae1 2306 */
caac7804 2307 void SetDefaultEditor(wxGridCellEditor* editor);
23324ae1
FM
2308
2309 /**
caac7804 2310 Sets the default renderer for grid cells.
8b9ef005 2311
caac7804 2312 The grid will take ownership of the pointer.
8b9ef005 2313
caac7804
BP
2314 See wxGridCellRenderer and the @ref overview_grid for more information
2315 about cell editors and renderers.
23324ae1 2316 */
caac7804 2317 void SetDefaultRenderer(wxGridCellRenderer* renderer);
23324ae1
FM
2318
2319 /**
caac7804 2320 Makes the cell at the specified location read-only or editable.
08dd9b5a 2321
caac7804 2322 @see IsReadOnly()
23324ae1 2323 */
caac7804 2324 void SetReadOnly(int row, int col, bool isReadOnly = true);
23324ae1
FM
2325
2326 /**
caac7804 2327 Displays the in-place cell edit control for the current cell.
23324ae1 2328 */
caac7804 2329 void ShowCellEditControl();
23324ae1 2330
caac7804 2331 //@}
23324ae1 2332
23324ae1 2333
23324ae1 2334 /**
caac7804 2335 @name Column and Row Sizes
82edfbe7 2336
32bcf974 2337 @see @ref overview_grid_resizing
caac7804
BP
2338 */
2339 //@{
08dd9b5a 2340
caac7804
BP
2341 /**
2342 Automatically sets the height and width of all rows and columns to fit
2343 their contents.
23324ae1 2344 */
caac7804 2345 void AutoSize();
23324ae1
FM
2346
2347 /**
caac7804 2348 Automatically adjusts width of the column to fit its label.
23324ae1 2349 */
caac7804 2350 void AutoSizeColLabelSize(int col);
23324ae1
FM
2351
2352 /**
caac7804
BP
2353 Automatically sizes the column to fit its contents. If @a setAsMin is
2354 @true the calculated width will also be set as the minimal width for
2355 the column.
2356 */
2357 void AutoSizeColumn(int col, bool setAsMin = true);
23324ae1
FM
2358
2359 /**
caac7804
BP
2360 Automatically sizes all columns to fit their contents. If @a setAsMin
2361 is @true the calculated widths will also be set as the minimal widths
2362 for the columns.
23324ae1 2363 */
caac7804 2364 void AutoSizeColumns(bool setAsMin = true);
23324ae1
FM
2365
2366 /**
caac7804
BP
2367 Automatically sizes the row to fit its contents. If @a setAsMin is
2368 @true the calculated height will also be set as the minimal height for
2369 the row.
23324ae1 2370 */
caac7804 2371 void AutoSizeRow(int row, bool setAsMin = true);
23324ae1 2372
23324ae1 2373 /**
caac7804 2374 Automatically adjusts height of the row to fit its label.
23324ae1 2375 */
caac7804 2376 void AutoSizeRowLabelSize(int col);
23324ae1 2377
23324ae1 2378 /**
caac7804
BP
2379 Automatically sizes all rows to fit their contents. If @a setAsMin is
2380 @true the calculated heights will also be set as the minimal heights
2381 for the rows.
23324ae1 2382 */
caac7804 2383 void AutoSizeRows(bool setAsMin = true);
23324ae1 2384
23324ae1 2385 /**
caac7804 2386 Returns the current height of the column labels.
23324ae1 2387 */
caac7804 2388 int GetColLabelSize() const;
23324ae1
FM
2389
2390 /**
caac7804 2391 Returns the minimal width to which a column may be resized.
08dd9b5a 2392
caac7804
BP
2393 Use SetColMinimalAcceptableWidth() to change this value globally or
2394 SetColMinimalWidth() to do it for individual columns.
08dd9b5a 2395
caac7804 2396 @see GetRowMinimalAcceptableHeight()
23324ae1 2397 */
caac7804 2398 int GetColMinimalAcceptableWidth() const;
23324ae1
FM
2399
2400 /**
caac7804 2401 Returns the width of the specified column.
23324ae1 2402 */
caac7804 2403 int GetColSize(int col) const;
23324ae1 2404
fe79f76b
VZ
2405 /**
2406 Returns @true if the specified column is not currently hidden.
2407 */
2408 bool IsColShown(int col) const;
2409
23324ae1 2410 /**
caac7804 2411 Returns the default height for column labels.
23324ae1 2412 */
caac7804 2413 int GetDefaultColLabelSize() const;
23324ae1
FM
2414
2415 /**
caac7804 2416 Returns the current default width for grid columns.
23324ae1 2417 */
caac7804 2418 int GetDefaultColSize() const;
23324ae1
FM
2419
2420 /**
caac7804
BP
2421 Returns the default width for the row labels.
2422 */
2423 int GetDefaultRowLabelSize() const;
08dd9b5a 2424
caac7804
BP
2425 /**
2426 Returns the current default height for grid rows.
23324ae1 2427 */
caac7804 2428 int GetDefaultRowSize() const;
23324ae1 2429
23324ae1 2430 /**
caac7804 2431 Returns the minimal size to which rows can be resized.
08dd9b5a 2432
caac7804
BP
2433 Use SetRowMinimalAcceptableHeight() to change this value globally or
2434 SetRowMinimalHeight() to do it for individual cells.
23324ae1 2435
caac7804 2436 @see GetColMinimalAcceptableWidth()
23324ae1 2437 */
caac7804 2438 int GetRowMinimalAcceptableHeight() const;
23324ae1
FM
2439
2440 /**
caac7804 2441 Returns the current width of the row labels.
23324ae1 2442 */
caac7804 2443 int GetRowLabelSize() const;
23324ae1
FM
2444
2445 /**
caac7804 2446 Returns the height of the specified row.
8b9ef005 2447 */
caac7804 2448 int GetRowSize(int row) const;
08dd9b5a 2449
fe79f76b
VZ
2450 /**
2451 Returns @true if the specified row is not currently hidden.
2452 */
2453 bool IsRowShown(int row) const;
2454
8b9ef005 2455 /**
caac7804 2456 Sets the height of the column labels.
08dd9b5a 2457
caac7804
BP
2458 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
2459 automatically so that no label is truncated. Note that this could be
2460 slow for a large table.
23324ae1 2461 */
caac7804 2462 void SetColLabelSize(int height);
23324ae1
FM
2463
2464 /**
caac7804 2465 Sets the minimal @a width to which the user can resize columns.
08dd9b5a 2466
caac7804 2467 @see GetColMinimalAcceptableWidth()
23324ae1 2468 */
caac7804 2469 void SetColMinimalAcceptableWidth(int width);
23324ae1
FM
2470
2471 /**
caac7804 2472 Sets the minimal @a width for the specified column @a col.
3c4f71cc 2473
caac7804
BP
2474 It is usually best to call this method during grid creation as calling
2475 it later will not resize the column to the given minimal width even if
2476 it is currently narrower than it.
23324ae1 2477
caac7804
BP
2478 @a width must be greater than the minimal acceptable column width as
2479 returned by GetColMinimalAcceptableWidth().
23324ae1 2480 */
caac7804 2481 void SetColMinimalWidth(int col, int width);
23324ae1
FM
2482
2483 /**
caac7804
BP
2484 Sets the width of the specified column.
2485
caac7804
BP
2486 @param col
2487 The column index.
2488 @param width
009c7216
VZ
2489 The new column width in pixels, 0 to hide the column or -1 to fit
2490 the column width to its label width.
23324ae1 2491 */
caac7804 2492 void SetColSize(int col, int width);
23324ae1 2493
009c7216
VZ
2494 /**
2495 Hides the specified column.
2496
2497 To show the column later you need to call SetColSize() with non-0
2498 width or ShowCol().
2499
2500 @param col
2501 The column index.
2502 */
2503 void HideCol(int col);
2504
2505 /**
2506 Shows the previously hidden column by resizing it to non-0 size.
2507
2508 @see HideCol(), SetColSize()
2509 */
2510 void ShowCol(int col);
2511
2512
23324ae1 2513 /**
caac7804 2514 Sets the default width for columns in the grid.
23324ae1 2515
caac7804
BP
2516 This will only affect columns subsequently added to the grid unless
2517 @a resizeExistingCols is @true.
2518
2519 If @a width is less than GetColMinimalAcceptableWidth(), then the
2520 minimal acceptable width is used instead of it.
23324ae1 2521 */
caac7804 2522 void SetDefaultColSize(int width, bool resizeExistingCols = false);
23324ae1
FM
2523
2524 /**
caac7804 2525 Sets the default height for rows in the grid.
3c4f71cc 2526
caac7804
BP
2527 This will only affect rows subsequently added to the grid unless
2528 @a resizeExistingRows is @true.
2529
2530 If @a height is less than GetRowMinimalAcceptableHeight(), then the
2531 minimal acceptable heihgt is used instead of it.
23324ae1 2532 */
caac7804 2533 void SetDefaultRowSize(int height, bool resizeExistingRows = false);
23324ae1
FM
2534
2535 /**
caac7804
BP
2536 Sets the width of the row labels.
2537
2538 If @a width equals @c wxGRID_AUTOSIZE then width is calculated
2539 automatically so that no label is truncated. Note that this could be
2540 slow for a large table.
23324ae1 2541 */
caac7804 2542 void SetRowLabelSize(int width);
23324ae1
FM
2543
2544 /**
caac7804 2545 Sets the minimal row @a height used by default.
8b9ef005 2546
caac7804 2547 See SetColMinimalAcceptableWidth() for more information.
23324ae1 2548 */
caac7804 2549 void SetRowMinimalAcceptableHeight(int height);
23324ae1
FM
2550
2551 /**
caac7804
BP
2552 Sets the minimal @a height for the specified @a row.
2553
2554 See SetColMinimalWidth() for more information.
23324ae1 2555 */
caac7804 2556 void SetRowMinimalHeight(int row, int height);
23324ae1
FM
2557
2558 /**
caac7804 2559 Sets the height of the specified row.
08dd9b5a 2560
caac7804 2561 See SetColSize() for more information.
23324ae1 2562 */
caac7804
BP
2563 void SetRowSize(int row, int height);
2564
009c7216
VZ
2565 /**
2566 Hides the specified row.
2567
2568 To show the row later you need to call SetRowSize() with non-0
2569 width or ShowRow().
2570
2571 @param col
2572 The row index.
2573 */
2574 void HideRow(int col);
2575
2576 /**
2577 Shows the previously hidden row by resizing it to non-0 size.
2578
2579 @see HideRow(), SetRowSize()
2580 */
2581 void ShowRow(int col);
2582
574e1c5a
VZ
2583 /**
2584 Get size information for all columns at once.
2585
2586 This method is useful when the information about all column widths
2587 needs to be saved. The widths can be later restored using
2588 SetColSizes().
2589
2590 @sa wxGridSizesInfo, GetRowSizes()
2591 */
2592 wxGridSizesInfo GetColSizes() const;
2593
2594 /**
2595 Get size information for all row at once.
2596
2597 @sa wxGridSizesInfo, GetColSizes()
2598 */
2599 wxGridSizesInfo GetRowSizes() const;
2600
2601 /**
2602 Restore all columns sizes.
2603
2604 This is usually called with wxGridSizesInfo object previously returned
2605 by GetColSizes().
2606
2607 @sa SetRowSizes()
2608 */
2609 void SetColSizes(const wxGridSizesInfo& sizeInfo);
2610
2611 /**
2612 Restore all rows sizes.
2613
2614 @sa SetColSizes()
2615 */
2616 void SetRowSizes(const wxGridSizesInfo& sizeInfo);
2617
8b9ef005 2618 //@}
23324ae1 2619
caac7804 2620
23324ae1 2621 /**
caac7804 2622 @name User-Resizing and Dragging
82edfbe7
VZ
2623
2624 Functions controlling various interactive mouse operations.
2625
2626 By default, columns and rows can be resized by dragging the edges of
2627 their labels (this can be disabled using DisableDragColSize() and
2628 DisableDragRowSize() methods). And if grid line dragging is enabled with
2629 EnableDragGridSize() they can also be resized by dragging the right or
2630 bottom edge of the grid cells.
2631
2632 Columns can also be moved to interactively change their order but this
2633 needs to be explicitly enabled with EnableDragColMove().
caac7804
BP
2634 */
2635 //@{
08dd9b5a 2636
caac7804
BP
2637 /**
2638 Return @true if the dragging of cells is enabled or @false otherwise.
23324ae1 2639 */
caac7804 2640 bool CanDragCell() const;
23324ae1
FM
2641
2642 /**
caac7804 2643 Returns @true if columns can be moved by dragging with the mouse.
08dd9b5a 2644
caac7804 2645 Columns can be moved by dragging on their labels.
23324ae1 2646 */
caac7804 2647 bool CanDragColMove() const;
23324ae1
FM
2648
2649 /**
82edfbe7
VZ
2650 Returns @true if the given column can be resized by dragging with the
2651 mouse.
8b9ef005 2652
82edfbe7
VZ
2653 This function returns @true if resizing the columns interactively is
2654 globally enabled, i.e. if DisableDragColSize() hadn't been called, and
2655 if this column wasn't explicitly marked as non-resizable with
2656 DisableColResize().
23324ae1 2657 */
82edfbe7 2658 bool CanDragColSize(int col) const;
23324ae1
FM
2659
2660 /**
caac7804
BP
2661 Return @true if the dragging of grid lines to resize rows and columns
2662 is enabled or @false otherwise.
2663 */
2664 bool CanDragGridSize() const;
2665
2666 /**
82edfbe7
VZ
2667 Returns @true if the given row can be resized by dragging with the
2668 mouse.
caac7804 2669
82edfbe7 2670 This is the same as CanDragColSize() but for rows.
caac7804 2671 */
82edfbe7
VZ
2672 bool CanDragRowSize(int row) const;
2673
2674 /**
2675 Disable interactive resizing of the specified column.
2676
2677 This method allows to disable resizing of an individual column in a
2678 grid where the columns are otherwise resizable (which is the case by
2679 default).
2680
2681 Notice that currently there is no way to make some columns resizable in
2682 a grid where columns can't be resized by default as there doesn't seem
2683 to be any need for this in practice. There is also no way to make the
2684 column marked as fixed using this method resizeable again because it is
2685 supposed that fixed columns are used for static parts of the grid and
2686 so should remain fixed during the entire grid lifetime.
2687
2688 Also notice that disabling interactive column resizing will not prevent
2689 the program from changing the column size.
2690
2691 @see EnableDragColSize()
2692 */
2693 void DisableColResize(int col);
2694
2695 /**
2696 Disable interactive resizing of the specified row.
2697
2698 This is the same as DisableColResize() but for rows.
2699
2700 @see EnableDragRowSize()
2701 */
2702 void DisableRowResize(int row);
caac7804
BP
2703
2704 /**
2705 Disables column moving by dragging with the mouse.
2706
2707 Equivalent to passing @false to EnableDragColMove().
2708 */
2709 void DisableDragColMove();
2710
2711 /**
2712 Disables column sizing by dragging with the mouse.
2713
2714 Equivalent to passing @false to EnableDragColSize().
2715 */
2716 void DisableDragColSize();
2717
2718 /**
2719 Disable mouse dragging of grid lines to resize rows and columns.
2720
2721 Equivalent to passing @false to EnableDragGridSize()
2722 */
2723 void DisableDragGridSize();
2724
2725 /**
2726 Disables row sizing by dragging with the mouse.
2727
2728 Equivalent to passing @false to EnableDragRowSize().
2729 */
2730 void DisableDragRowSize();
2731
2732 /**
2733 Enables or disables cell dragging with the mouse.
2734 */
2735 void EnableDragCell(bool enable = true);
2736
2737 /**
2738 Enables or disables column moving by dragging with the mouse.
2739 */
2740 void EnableDragColMove(bool enable = true);
2741
2742 /**
2743 Enables or disables column sizing by dragging with the mouse.
82edfbe7
VZ
2744
2745 @see DisableColResize()
caac7804
BP
2746 */
2747 void EnableDragColSize(bool enable = true);
2748
2749 /**
2750 Enables or disables row and column resizing by dragging gridlines with
2751 the mouse.
2752 */
2753 void EnableDragGridSize(bool enable = true);
2754
2755 /**
2756 Enables or disables row sizing by dragging with the mouse.
82edfbe7
VZ
2757
2758 @see DisableRowResize()
caac7804
BP
2759 */
2760 void EnableDragRowSize(bool enable = true);
2761
2762 /**
2763 Returns the column ID of the specified column position.
2764 */
2765 int GetColAt(int colPos) const;
2766
2767 /**
2768 Returns the position of the specified column.
2769 */
2770 int GetColPos(int colID) const;
2771
2772 /**
2773 Sets the position of the specified column.
2774 */
2775 void SetColPos(int colID, int newPos);
2776
31ec8b4e
VZ
2777 /**
2778 Sets the positions of all columns at once.
2779
2780 This method takes an array containing the indices of the columns in
2781 their display order, i.e. uses the same convention as
2782 wxHeaderCtrl::SetColumnsOrder().
f8f31de6 2783 */
31ec8b4e
VZ
2784 void SetColumnsOrder(const wxArrayInt& order);
2785
009c7216
VZ
2786 /**
2787 Resets the position of the columns to the default.
f8f31de6 2788 */
009c7216
VZ
2789 void ResetColPos();
2790
caac7804
BP
2791 //@}
2792
2793
2794 /**
2795 @name Cursor Movement
f8f31de6 2796 */
caac7804
BP
2797 //@{
2798
2799 /**
2800 Returns the current grid cell column position.
2801 */
2802 int GetGridCursorCol() const;
2803
2804 /**
2805 Returns the current grid cell row position.
2806 */
2807 int GetGridCursorRow() const;
2808
2809 /**
2810 Make the given cell current and ensure it is visible.
2811
2812 This method is equivalent to calling MakeCellVisible() and
2813 SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
2814 event is generated by it and the selected cell doesn't change if the
2815 event is vetoed.
2816 */
2817 void GoToCell(int row, int col);
2818 /**
2819 Make the given cell current and ensure it is visible.
2820
2821 This method is equivalent to calling MakeCellVisible() and
2822 SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
2823 event is generated by it and the selected cell doesn't change if the
2824 event is vetoed.
2825 */
2826 void GoToCell(const wxGridCellCoords& coords);
2827
2828 /**
2829 Moves the grid cursor down by one row.
2830
2831 If a block of cells was previously selected it will expand if the
2832 argument is @true or be cleared if the argument is @false.
2833 */
2834 bool MoveCursorDown(bool expandSelection);
2835
2836 /**
2837 Moves the grid cursor down in the current column such that it skips to
2838 the beginning or end of a block of non-empty cells.
2839
2840 If a block of cells was previously selected it will expand if the
2841 argument is @true or be cleared if the argument is @false.
2842 */
2843 bool MoveCursorDownBlock(bool expandSelection);
2844
2845 /**
2846 Moves the grid cursor left by one column.
08dd9b5a 2847
8b9ef005
BP
2848 If a block of cells was previously selected it will expand if the
2849 argument is @true or be cleared if the argument is @false.
23324ae1 2850 */
8b9ef005 2851 bool MoveCursorLeft(bool expandSelection);
23324ae1
FM
2852
2853 /**
8b9ef005
BP
2854 Moves the grid cursor left in the current row such that it skips to the
2855 beginning or end of a block of non-empty cells.
2856
2857 If a block of cells was previously selected it will expand if the
2858 argument is @true or be cleared if the argument is @false.
23324ae1 2859 */
8b9ef005 2860 bool MoveCursorLeftBlock(bool expandSelection);
23324ae1
FM
2861
2862 /**
8b9ef005 2863 Moves the grid cursor right by one column.
08dd9b5a 2864
8b9ef005
BP
2865 If a block of cells was previously selected it will expand if the
2866 argument is @true or be cleared if the argument is @false.
23324ae1 2867 */
8b9ef005 2868 bool MoveCursorRight(bool expandSelection);
23324ae1
FM
2869
2870 /**
8b9ef005
BP
2871 Moves the grid cursor right in the current row such that it skips to
2872 the beginning or end of a block of non-empty cells.
08dd9b5a 2873
8b9ef005
BP
2874 If a block of cells was previously selected it will expand if the
2875 argument is @true or be cleared if the argument is @false.
23324ae1 2876 */
8b9ef005 2877 bool MoveCursorRightBlock(bool expandSelection);
23324ae1 2878
23324ae1 2879 /**
8b9ef005
BP
2880 Moves the grid cursor up by one row.
2881
2882 If a block of cells was previously selected it will expand if the
2883 argument is @true or be cleared if the argument is @false.
23324ae1 2884 */
8b9ef005 2885 bool MoveCursorUp(bool expandSelection);
23324ae1
FM
2886
2887 /**
8b9ef005
BP
2888 Moves the grid cursor up in the current column such that it skips to
2889 the beginning or end of a block of non-empty cells.
3c4f71cc 2890
8b9ef005
BP
2891 If a block of cells was previously selected it will expand if the
2892 argument is @true or be cleared if the argument is @false.
23324ae1 2893 */
8b9ef005 2894 bool MoveCursorUpBlock(bool expandSelection);
23324ae1
FM
2895
2896 /**
8b9ef005
BP
2897 Moves the grid cursor down by some number of rows so that the previous
2898 bottom visible row becomes the top visible row.
2899 */
2900 bool MovePageDown();
3c4f71cc 2901
8b9ef005
BP
2902 /**
2903 Moves the grid cursor up by some number of rows so that the previous
2904 top visible row becomes the bottom visible row.
23324ae1 2905 */
8b9ef005 2906 bool MovePageUp();
23324ae1
FM
2907
2908 /**
caac7804 2909 Set the grid cursor to the specified cell.
08dd9b5a 2910
caac7804
BP
2911 The grid cursor indicates the current cell and can be moved by the user
2912 using the arrow keys or the mouse.
8b9ef005 2913
caac7804
BP
2914 Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
2915 if the event handler vetoes this event, the cursor is not moved.
8b9ef005 2916
caac7804
BP
2917 This function doesn't make the target call visible, use GoToCell() to
2918 do this.
23324ae1 2919 */
caac7804 2920 void SetGridCursor(int row, int col);
23324ae1 2921 /**
caac7804 2922 Set the grid cursor to the specified cell.
23324ae1 2923
caac7804
BP
2924 The grid cursor indicates the current cell and can be moved by the user
2925 using the arrow keys or the mouse.
bb778cae 2926
caac7804
BP
2927 Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
2928 if the event handler vetoes this event, the cursor is not moved.
8b9ef005 2929
caac7804
BP
2930 This function doesn't make the target call visible, use GoToCell() to
2931 do this.
23324ae1 2932 */
caac7804
BP
2933 void SetGridCursor(const wxGridCellCoords& coords);
2934
8b9ef005 2935 //@}
23324ae1 2936
8b9ef005 2937
caac7804
BP
2938 /**
2939 @name User Selection
2940 */
2941 //@{
8b9ef005 2942
caac7804
BP
2943 /**
2944 Deselects all cells that are currently selected.
23324ae1 2945 */
caac7804 2946 void ClearSelection();
23324ae1
FM
2947
2948 /**
caac7804 2949 Returns an array of individually selected cells.
08dd9b5a 2950
caac7804
BP
2951 Notice that this array does @em not contain all the selected cells in
2952 general as it doesn't include the cells selected as part of column, row
2953 or block selection. You must use this method, GetSelectedCols(),
2954 GetSelectedRows() and GetSelectionBlockTopLeft() and
2955 GetSelectionBlockBottomRight() methods to obtain the entire selection
2956 in general.
08dd9b5a 2957
caac7804
BP
2958 Please notice this behaviour is by design and is needed in order to
2959 support grids of arbitrary size (when an entire column is selected in
2960 a grid with a million of columns, we don't want to create an array with
2961 a million of entries in this function, instead it returns an empty
2962 array and GetSelectedCols() returns an array containing one element).
23324ae1 2963 */
caac7804 2964 wxGridCellCoordsArray GetSelectedCells() const;
23324ae1
FM
2965
2966 /**
caac7804 2967 Returns an array of selected columns.
08dd9b5a 2968
caac7804
BP
2969 Please notice that this method alone is not sufficient to find all the
2970 selected columns as it contains only the columns which were
2971 individually selected but not those being part of the block selection
2972 or being selected in virtue of all of their cells being selected
2973 individually, please see GetSelectedCells() for more details.
23324ae1 2974 */
caac7804 2975 wxArrayInt GetSelectedCols() const;
23324ae1
FM
2976
2977 /**
caac7804 2978 Returns an array of selected rows.
23324ae1 2979
caac7804
BP
2980 Please notice that this method alone is not sufficient to find all the
2981 selected rows as it contains only the rows which were individually
2982 selected but not those being part of the block selection or being
2983 selected in virtue of all of their cells being selected individually,
2984 please see GetSelectedCells() for more details.
23324ae1 2985 */
caac7804 2986 wxArrayInt GetSelectedRows() const;
23324ae1
FM
2987
2988 /**
caac7804 2989 Returns the colour used for drawing the selection background.
23324ae1 2990 */
caac7804 2991 wxColour GetSelectionBackground() const;
23324ae1 2992
8a3e536c 2993 /**
caac7804
BP
2994 Returns an array of the bottom right corners of blocks of selected
2995 cells.
8a3e536c 2996
caac7804
BP
2997 Please see GetSelectedCells() for more information about the selection
2998 representation in wxGrid.
23324ae1 2999
caac7804 3000 @see GetSelectionBlockTopLeft()
23324ae1 3001 */
caac7804 3002 wxGridCellCoordsArray GetSelectionBlockBottomRight() const;
8b9ef005 3003
8b9ef005 3004 /**
caac7804 3005 Returns an array of the top left corners of blocks of selected cells.
8b9ef005 3006
caac7804
BP
3007 Please see GetSelectedCells() for more information about the selection
3008 representation in wxGrid.
23324ae1 3009
caac7804 3010 @see GetSelectionBlockBottomRight()
23324ae1 3011 */
caac7804 3012 wxGridCellCoordsArray GetSelectionBlockTopLeft() const;
23324ae1
FM
3013
3014 /**
caac7804 3015 Returns the colour used for drawing the selection foreground.
23324ae1 3016 */
caac7804 3017 wxColour GetSelectionForeground() const;
23324ae1
FM
3018
3019 /**
caac7804 3020 Returns the current selection mode.
23324ae1 3021
caac7804 3022 @see SetSelectionMode().
23324ae1 3023 */
caac7804 3024 wxGridSelectionModes GetSelectionMode() const;
23324ae1
FM
3025
3026 /**
caac7804
BP
3027 Returns @true if the given cell is selected.
3028 */
3029 bool IsInSelection(int row, int col) const;
3030 /**
3031 Returns @true if the given cell is selected.
3032 */
3033 bool IsInSelection(const wxGridCellCoords& coords) const;
08dd9b5a 3034
caac7804
BP
3035 /**
3036 Returns @true if there are currently any selected cells, rows, columns
3037 or blocks.
3038 */
3039 bool IsSelection() const;
08dd9b5a 3040
caac7804
BP
3041 /**
3042 Selects all cells in the grid.
23324ae1 3043 */
caac7804 3044 void SelectAll();
23324ae1
FM
3045
3046 /**
caac7804 3047 Selects a rectangular block of cells.
8b9ef005 3048
caac7804
BP
3049 If @a addToSelected is @false then any existing selection will be
3050 deselected; if @true the column will be added to the existing
3051 selection.
23324ae1 3052 */
caac7804
BP
3053 void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
3054 bool addToSelected = false);
23324ae1 3055 /**
caac7804 3056 Selects a rectangular block of cells.
08dd9b5a 3057
caac7804
BP
3058 If @a addToSelected is @false then any existing selection will be
3059 deselected; if @true the column will be added to the existing
3060 selection.
23324ae1 3061 */
caac7804
BP
3062 void SelectBlock(const wxGridCellCoords& topLeft,
3063 const wxGridCellCoords& bottomRight,
3064 bool addToSelected = false);
23324ae1
FM
3065
3066 /**
caac7804 3067 Selects the specified column.
08dd9b5a 3068
caac7804
BP
3069 If @a addToSelected is @false then any existing selection will be
3070 deselected; if @true the column will be added to the existing
3071 selection.
3072
3073 This method won't select anything if the current selection mode is
3074 wxGridSelectRows.
23324ae1 3075 */
caac7804 3076 void SelectCol(int col, bool addToSelected = false);
23324ae1 3077
23324ae1 3078 /**
caac7804 3079 Selects the specified row.
8b9ef005 3080
caac7804
BP
3081 If @a addToSelected is @false then any existing selection will be
3082 deselected; if @true the row will be added to the existing selection.
3083
3084 This method won't select anything if the current selection mode is
3085 wxGridSelectColumns.
23324ae1 3086 */
caac7804 3087 void SelectRow(int row, bool addToSelected = false);
23324ae1
FM
3088
3089 /**
caac7804
BP
3090 Set the colour to be used for drawing the selection background.
3091 */
3092 void SetSelectionBackground(const wxColour& c);
08dd9b5a 3093
caac7804
BP
3094 /**
3095 Set the colour to be used for drawing the selection foreground.
23324ae1 3096 */
caac7804 3097 void SetSelectionForeground(const wxColour& c);
23324ae1
FM
3098
3099 /**
caac7804 3100 Set the selection behaviour of the grid.
8b9ef005 3101
caac7804
BP
3102 The existing selection is converted to conform to the new mode if
3103 possible and discarded otherwise (e.g. any individual selected cells
3104 are deselected if the new mode allows only the selection of the entire
3105 rows or columns).
23324ae1 3106 */
caac7804 3107 void SetSelectionMode(wxGridSelectionModes selmode);
23324ae1 3108
caac7804 3109 //@}
08dd9b5a 3110
8b9ef005 3111
caac7804
BP
3112 /**
3113 @name Scrolling
3114 */
3115 //@{
23324ae1 3116
23324ae1 3117 /**
caac7804
BP
3118 Returns the number of pixels per horizontal scroll increment.
3119
3120 The default is 15.
3121
3122 @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
23324ae1 3123 */
caac7804 3124 int GetScrollLineX() const;
23324ae1
FM
3125
3126 /**
caac7804 3127 Returns the number of pixels per vertical scroll increment.
08dd9b5a 3128
caac7804 3129 The default is 15.
8b9ef005 3130
caac7804 3131 @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
23324ae1 3132 */
caac7804 3133 int GetScrollLineY() const;
23324ae1
FM
3134
3135 /**
caac7804
BP
3136 Returns @true if a cell is either entirely or at least partially
3137 visible in the grid window.
08dd9b5a 3138
caac7804
BP
3139 By default, the cell must be entirely visible for this function to
3140 return @true but if @a wholeCellVisible is @false, the function returns
3141 @true even if the cell is only partially visible.
23324ae1 3142 */
caac7804 3143 bool IsVisible(int row, int col, bool wholeCellVisible = true) const;
23324ae1 3144 /**
caac7804
BP
3145 Returns @true if a cell is either entirely or at least partially
3146 visible in the grid window.
3147
3148 By default, the cell must be entirely visible for this function to
3149 return @true but if @a wholeCellVisible is @false, the function returns
3150 @true even if the cell is only partially visible.
23324ae1 3151 */
caac7804
BP
3152 bool IsVisible(const wxGridCellCoords& coords,
3153 bool wholeCellVisible = true) const;
23324ae1
FM
3154
3155 /**
caac7804
BP
3156 Brings the specified cell into the visible grid cell area with minimal
3157 scrolling.
23324ae1 3158
caac7804
BP
3159 Does nothing if the cell is already visible.
3160 */
3161 void MakeCellVisible(int row, int col);
23324ae1 3162 /**
caac7804
BP
3163 Brings the specified cell into the visible grid cell area with minimal
3164 scrolling.
3165
3166 Does nothing if the cell is already visible.
23324ae1 3167 */
caac7804 3168 void MakeCellVisible(const wxGridCellCoords& coords);
23324ae1
FM
3169
3170 /**
caac7804 3171 Sets the number of pixels per horizontal scroll increment.
08dd9b5a 3172
caac7804 3173 The default is 15.
8b9ef005 3174
caac7804 3175 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
23324ae1 3176 */
caac7804 3177 void SetScrollLineX(int x);
23324ae1
FM
3178
3179 /**
caac7804 3180 Sets the number of pixels per vertical scroll increment.
08dd9b5a 3181
caac7804 3182 The default is 15.
8b9ef005 3183
caac7804 3184 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
23324ae1 3185 */
caac7804 3186 void SetScrollLineY(int y);
23324ae1 3187
caac7804 3188 //@}
08dd9b5a 3189
23324ae1 3190
caac7804
BP
3191 /**
3192 @name Cell and Device Coordinate Translation
3193 */
3194 //@{
23324ae1
FM
3195
3196 /**
caac7804 3197 Convert grid cell coordinates to grid window pixel coordinates.
8b9ef005 3198
caac7804
BP
3199 This function returns the rectangle that encloses the block of cells
3200 limited by @a topLeft and @a bottomRight cell in device coords and
3201 clipped to the client size of the grid window.
8b9ef005 3202
caac7804 3203 @see CellToRect()
23324ae1 3204 */
caac7804
BP
3205 wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft,
3206 const wxGridCellCoords& bottomRight) const;
23324ae1
FM
3207
3208 /**
caac7804
BP
3209 Return the rectangle corresponding to the grid cell's size and position
3210 in logical coordinates.
08dd9b5a 3211
caac7804
BP
3212 @see BlockToDeviceRect()
3213 */
3214 wxRect CellToRect(int row, int col) const;
3215 /**
3216 Return the rectangle corresponding to the grid cell's size and position
3217 in logical coordinates.
08dd9b5a 3218
caac7804 3219 @see BlockToDeviceRect()
23324ae1 3220 */
882678eb 3221 wxRect CellToRect(const wxGridCellCoords& coords) const;
23324ae1 3222
23324ae1 3223 /**
caac7804
BP
3224 Returns the column at the given pixel position.
3225
3226 @param x
3227 The x position to evaluate.
3228 @param clipToMinMax
3229 If @true, rather than returning @c wxNOT_FOUND, it returns either
3230 the first or last column depending on whether @a x is too far to
3231 the left or right respectively.
3232 @return
3233 The column index or @c wxNOT_FOUND.
23324ae1 3234 */
caac7804 3235 int XToCol(int x, bool clipToMinMax = false) const;
23324ae1
FM
3236
3237 /**
caac7804
BP
3238 Returns the column whose right hand edge is close to the given logical
3239 @a x position.
3240
3241 If no column edge is near to this position @c wxNOT_FOUND is returned.
23324ae1 3242 */
caac7804 3243 int XToEdgeOfCol(int x) const;
23324ae1 3244
23324ae1 3245 /**
caac7804
BP
3246 Translates logical pixel coordinates to the grid cell coordinates.
3247
3248 Notice that this function expects logical coordinates on input so if
3249 you use this function in a mouse event handler you need to translate
3250 the mouse position, which is expressed in device coordinates, to
3251 logical ones.
3252
3253 @see XToCol(), YToRow()
3254 */
3255 wxGridCellCoords XYToCell(int x, int y) const;
3256 /**
3257 Translates logical pixel coordinates to the grid cell coordinates.
3258
3259 Notice that this function expects logical coordinates on input so if
3260 you use this function in a mouse event handler you need to translate
3261 the mouse position, which is expressed in device coordinates, to
3262 logical ones.
3263
3264 @see XToCol(), YToRow()
3265 */
3266 wxGridCellCoords XYToCell(const wxPoint& pos) const;
3267 // XYToCell(int, int, wxGridCellCoords&) overload is intentionally
3268 // undocumented, using it is ugly and non-const reference parameters are
3269 // not used in wxWidgets API
08dd9b5a 3270
8b9ef005 3271 /**
caac7804
BP
3272 Returns the row whose bottom edge is close to the given logical @a y
3273 position.
3274
3275 If no row edge is near to this position @c wxNOT_FOUND is returned.
23324ae1 3276 */
caac7804 3277 int YToEdgeOfRow(int y) const;
23324ae1
FM
3278
3279 /**
caac7804 3280 Returns the grid row that corresponds to the logical @a y coordinate.
08dd9b5a 3281
caac7804 3282 Returns @c wxNOT_FOUND if there is no row at the @a y position.
8b9ef005 3283 */
caac7804
BP
3284 int YToRow(int y, bool clipToMinMax = false) const;
3285
3286 //@}
3287
08dd9b5a 3288
8b9ef005 3289 /**
caac7804
BP
3290 @name Miscellaneous Functions
3291 */
3292 //@{
8b9ef005 3293
caac7804
BP
3294 /**
3295 Appends one or more new columns to the right of the grid.
3296
3297 The @a updateLabels argument is not used at present. If you are using a
3298 derived grid table class you will need to override
3299 wxGridTableBase::AppendCols(). See InsertCols() for further
3300 information.
3301
3302 @return @true on success or @false if appending columns failed.
23324ae1 3303 */
caac7804 3304 bool AppendCols(int numCols = 1, bool updateLabels = true);
23324ae1
FM
3305
3306 /**
caac7804 3307 Appends one or more new rows to the bottom of the grid.
08dd9b5a 3308
caac7804
BP
3309 The @a updateLabels argument is not used at present. If you are using a
3310 derived grid table class you will need to override
3311 wxGridTableBase::AppendRows(). See InsertRows() for further
3312 information.
23324ae1 3313
caac7804 3314 @return @true on success or @false if appending rows failed.
23324ae1 3315 */
caac7804 3316 bool AppendRows(int numRows = 1, bool updateLabels = true);
23324ae1 3317
23324ae1 3318 /**
caac7804
BP
3319 Return @true if the horizontal grid lines stop at the last column
3320 boundary or @false if they continue to the end of the window.
3c4f71cc 3321
caac7804
BP
3322 The default is to clip grid lines.
3323
3324 @see ClipHorzGridLines(), AreVertGridLinesClipped()
3325 */
3326 bool AreHorzGridLinesClipped() const;
23324ae1
FM
3327
3328 /**
caac7804
BP
3329 Return @true if the vertical grid lines stop at the last row
3330 boundary or @false if they continue to the end of the window.
8b9ef005 3331
caac7804
BP
3332 The default is to clip grid lines.
3333
3334 @see ClipVertGridLines(), AreHorzGridLinesClipped()
3335 */
3336 bool AreVertGridLinesClipped() const;
23324ae1
FM
3337
3338 /**
caac7804 3339 Increments the grid's batch count.
08dd9b5a 3340
caac7804
BP
3341 When the count is greater than zero repainting of the grid is
3342 suppressed. Each call to BeginBatch must be matched by a later call to
3343 EndBatch(). Code that does a lot of grid modification can be enclosed
3344 between BeginBatch() and EndBatch() calls to avoid screen flicker. The
3345 final EndBatch() call will cause the grid to be repainted.
3346
3347 Notice that you should use wxGridUpdateLocker which ensures that there
3348 is always a matching EndBatch() call for this BeginBatch() if possible
3349 instead of calling this method directly.
8b9ef005 3350 */
caac7804 3351 void BeginBatch();
08dd9b5a 3352
8b9ef005 3353 /**
caac7804 3354 Clears all data in the underlying grid table and repaints the grid.
8b9ef005 3355
caac7804
BP
3356 The table is not deleted by this function. If you are using a derived
3357 table class then you need to override wxGridTableBase::Clear() for this
3358 function to have any effect.
23324ae1 3359 */
caac7804 3360 void ClearGrid();
23324ae1
FM
3361
3362 /**
caac7804
BP
3363 Change whether the horizontal grid lines are clipped by the end of the
3364 last column.
8b9ef005 3365
caac7804
BP
3366 By default the grid lines are not drawn beyond the end of the last
3367 column but after calling this function with @a clip set to @false they
3368 will be drawn across the entire grid window.
3369
3370 @see AreHorzGridLinesClipped(), ClipVertGridLines()
3371 */
3372 void ClipHorzGridLines(bool clip);
23324ae1
FM
3373
3374 /**
caac7804
BP
3375 Change whether the vertical grid lines are clipped by the end of the
3376 last row.
08dd9b5a 3377
caac7804
BP
3378 By default the grid lines are not drawn beyond the end of the last
3379 row but after calling this function with @a clip set to @false they
3380 will be drawn across the entire grid window.
3381
3382 @see AreVertGridLinesClipped(), ClipHorzGridLines()
3383 */
3384 void ClipVertGridLines(bool clip);
08dd9b5a 3385
8b9ef005 3386 /**
caac7804
BP
3387 Deletes one or more columns from a grid starting at the specified
3388 position.
8b9ef005 3389
caac7804
BP
3390 The @a updateLabels argument is not used at present. If you are using a
3391 derived grid table class you will need to override
3392 wxGridTableBase::DeleteCols(). See InsertCols() for further
3393 information.
8b9ef005 3394
caac7804 3395 @return @true on success or @false if deleting columns failed.
23324ae1 3396 */
caac7804 3397 bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true);
23324ae1 3398
23324ae1 3399 /**
caac7804
BP
3400 Deletes one or more rows from a grid starting at the specified
3401 position.
8b9ef005 3402
caac7804
BP
3403 The @a updateLabels argument is not used at present. If you are using a
3404 derived grid table class you will need to override
3405 wxGridTableBase::DeleteRows(). See InsertRows() for further
3406 information.
8b9ef005 3407
caac7804 3408 @return @true on success or @false if appending rows failed.
23324ae1 3409 */
caac7804 3410 bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true);
23324ae1 3411
23324ae1 3412 /**
caac7804
BP
3413 Decrements the grid's batch count.
3414
3415 When the count is greater than zero repainting of the grid is
3416 suppressed. Each previous call to BeginBatch() must be matched by a
3417 later call to EndBatch(). Code that does a lot of grid modification can
3418 be enclosed between BeginBatch() and EndBatch() calls to avoid screen
3419 flicker. The final EndBatch() will cause the grid to be repainted.
3420
3421 @see wxGridUpdateLocker
8b9ef005 3422 */
caac7804 3423 void EndBatch();
08dd9b5a 3424
8b9ef005 3425 /**
caac7804 3426 Overridden wxWindow method.
8b9ef005 3427 */
caac7804 3428 virtual void Fit();
08dd9b5a 3429
8b9ef005 3430 /**
caac7804 3431 Causes immediate repainting of the grid.
8b9ef005 3432
caac7804 3433 Use this instead of the usual wxWindow::Refresh().
23324ae1 3434 */
caac7804 3435 void ForceRefresh();
23324ae1
FM
3436
3437 /**
caac7804
BP
3438 Returns the number of times that BeginBatch() has been called without
3439 (yet) matching calls to EndBatch(). While the grid's batch count is
3440 greater than zero the display will not be updated.
3441 */
3442 int GetBatchCount();
08dd9b5a 3443
caac7804
BP
3444 /**
3445 Returns the total number of grid columns.
8b9ef005 3446
caac7804 3447 This is the same as the number of columns in the underlying grid table.
23324ae1 3448 */
caac7804 3449 int GetNumberCols() const;
23324ae1
FM
3450
3451 /**
caac7804 3452 Returns the total number of grid rows.
08dd9b5a 3453
caac7804 3454 This is the same as the number of rows in the underlying grid table.
23324ae1 3455 */
caac7804 3456 int GetNumberRows() const;
23324ae1
FM
3457
3458 /**
caac7804
BP
3459 Returns the attribute for the given cell creating one if necessary.
3460
3461 If the cell already has an attribute, it is returned. Otherwise a new
3462 attribute is created, associated with the cell and returned. In any
3463 case the caller must call DecRef() on the returned pointer.
3464
3465 This function may only be called if CanHaveAttributes() returns @true.
8b9ef005 3466 */
caac7804 3467 wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
08dd9b5a 3468
8b9ef005 3469 /**
caac7804 3470 Returns a base pointer to the current table object.
08dd9b5a 3471
caac7804 3472 The returned pointer is still owned by the grid.
23324ae1 3473 */
caac7804 3474 wxGridTableBase *GetTable() const;
23324ae1
FM
3475
3476 /**
caac7804
BP
3477 Inserts one or more new columns into a grid with the first new column
3478 at the specified position.
08dd9b5a 3479
caac7804
BP
3480 Notice that inserting the columns in the grid requires grid table
3481 cooperation: when this method is called, grid object begins by
3482 requesting the underlying grid table to insert new columns. If this is
3483 successful the table notifies the grid and the grid updates the
3484 display. For a default grid (one where you have called CreateGrid())
3485 this process is automatic. If you are using a custom grid table
3486 (specified with SetTable()) then you must override
3487 wxGridTableBase::InsertCols() in your derived table class.
3488
3489 @param pos
3490 The position which the first newly inserted column will have.
3491 @param numCols
3492 The number of columns to insert.
3493 @param updateLabels
3494 Currently not used.
3495 @return
3496 @true if the columns were successfully inserted, @false if an error
3497 occurred (most likely the table couldn't be updated).
23324ae1 3498 */
caac7804 3499 bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true);
23324ae1
FM
3500
3501 /**
caac7804
BP
3502 Inserts one or more new rows into a grid with the first new row at the
3503 specified position.
8b9ef005 3504
caac7804
BP
3505 Notice that you must implement wxGridTableBase::InsertRows() if you use
3506 a grid with a custom table, please see InsertCols() for more
3507 information.
8b9ef005 3508
caac7804
BP
3509 @param pos
3510 The position which the first newly inserted row will have.
3511 @param numRows
3512 The number of rows to insert.
3513 @param updateLabels
3514 Currently not used.
3515 @return
3516 @true if the rows were successfully inserted, @false if an error
3517 occurred (most likely the table couldn't be updated).
3518 */
3519 bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true);
8b9ef005 3520
caac7804
BP
3521 /**
3522 Sets the cell attributes for all cells in the specified column.
08dd9b5a 3523
caac7804
BP
3524 For more information about controlling grid cell attributes see the
3525 wxGridCellAttr cell attribute class and the @ref overview_grid.
3526 */
3527 void SetColAttr(int col, wxGridCellAttr* attr);
23324ae1
FM
3528
3529 /**
caac7804 3530 Sets the extra margins used around the grid area.
08dd9b5a 3531
caac7804
BP
3532 A grid may occupy more space than needed for its data display and
3533 this function allows to set how big this extra space is
23324ae1 3534 */
caac7804 3535 void SetMargins(int extraWidth, int extraHeight);
23324ae1
FM
3536
3537 /**
caac7804 3538 Sets the cell attributes for all cells in the specified row.
08dd9b5a 3539
caac7804
BP
3540 The grid takes ownership of the attribute pointer.
3541
3542 See the wxGridCellAttr class for more information about controlling
3543 cell attributes.
23324ae1 3544 */
caac7804
BP
3545 void SetRowAttr(int row, wxGridCellAttr* attr);
3546
3547 //@}
23324ae1 3548
11393d29
VZ
3549
3550 /**
3551 @name Sorting support.
3552
3553 wxGrid doesn't provide any support for sorting the data but it does
3554 generate events allowing the user code to sort it and supports
3555 displaying the sort indicator in the column used for sorting.
3556
3557 To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT
3558 event (and not veto it) and resort the data displayed in the grid. The
3559 grid will automatically update the sorting indicator on the column
3560 which was clicked.
3561
3562 You can also call the functions in this section directly to update the
3563 sorting indicator. Once again, they don't do anything with the grid
3564 data, it remains your responsibility to actually sort it appropriately.
3565 */
3566 //@{
3567
3568 /**
3569 Return the column in which the sorting indicator is currently
3570 displayed.
3571
3572 Returns @c wxNOT_FOUND if sorting indicator is not currently displayed
3573 at all.
3574
3575 @see SetSortingColumn()
3576 */
3577 int GetSortingColumn() const;
3578
3579 /**
3580 Return @true if this column is currently used for sorting.
3581
3582 @see GetSortingColumn()
3583 */
3584 bool IsSortingBy(int col) const;
3585
3586 /**
3587 Return @true if the current sorting order is ascending or @false if it
3588 is descending.
3589
3590 It only makes sense to call this function if GetSortingColumn() returns
3591 a valid column index and not @c wxNOT_FOUND.
3592
3593 @see SetSortingColumn()
3594 */
3595 bool IsSortOrderAscending() const;
3596
3597 /**
3598 Set the column to display the sorting indicator in and its direction.
3599
3600 @param col
3601 The column to display the sorting indicator in or @c wxNOT_FOUND to
3602 remove any currently displayed sorting indicator.
3603 @param ascending
3604 If @true, display the ascending sort indicator, otherwise display
3605 the descending sort indicator.
3606
3607 @see GetSortingColumn(), IsSortOrderAscending()
3608 */
3609 void SetSortingColumn(int col, bool ascending = true);
3610
3611 /**
3612 Remove any currently shown sorting indicator.
3613
3614 This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND
3615 first argument.
3616 */
3617 void UnsetSortingColumn();
3618 //@}
3039ade9 3619
882678eb 3620
3039ade9
VZ
3621 /**
3622 @name Accessors for component windows.
3623
3624 Return the various child windows of wxGrid.
3625
3626 wxGrid is an empty parent window for 4 children representing the column
3627 labels window (top), the row labels window (left), the corner window
3628 (top left) and the main grid window. It may be necessary to use these
3629 individual windows and not the wxGrid window itself if you need to
3630 handle events for them (this can be done using wxEvtHandler::Connect()
3631 or wxWindow::PushEventHandler()) or do something else requiring the use
3632 of the correct window pointer. Notice that you should not, however,
3633 change these windows (e.g. reposition them or draw over them) because
3634 they are managed by wxGrid itself.
3635 */
3636 //@{
3637
3638 /**
3639 Return the main grid window containing the grid cells.
3640
3641 This window is always shown.
3642 */
3643 wxWindow *GetGridWindow() const;
3644
3645 /**
3646 Return the row labels window.
3647
3648 This window is not shown if the row labels were hidden using
3649 HideRowLabels().
3650 */
3651 wxWindow *GetGridRowLabelWindow() const;
3652
3653 /**
3654 Return the column labels window.
3655
3656 This window is not shown if the columns labels were hidden using
3657 HideColLabels().
3658
3659 Depending on whether UseNativeColHeader() was called or not this can be
3660 either a wxHeaderCtrl or a plain wxWindow. This function returns a valid
3661 window pointer in either case but in the former case you can also use
3662 GetGridColHeader() to access it if you need wxHeaderCtrl-specific
3663 functionality.
3664 */
600e986a 3665 wxWindow *GetGridColLabelWindow() const;
3039ade9
VZ
3666
3667 /**
3668 Return the window in the top left grid corner.
3669
3670 This window is shown only of both columns and row labels are shown and
3671 normally doesn't contain anything. Clicking on it is handled by wxGrid
3672 however and can be used to select the entire grid.
3673 */
3674 wxWindow *GetGridCornerLabelWindow() const;
3675
3676 /**
3677 Return the header control used for column labels display.
3678
3679 This function can only be called if UseNativeColHeader() had been
3680 called.
3681 */
3682 wxHeaderCtrl *GetGridColHeader() const;
3683
3684 //@}
882678eb
FM
3685
3686protected:
3687 /**
3688 Returns @true if this grid has support for cell attributes.
3689
3690 The grid supports attributes if it has the associated table which, in
3691 turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes()
3692 returns @true.
3693 */
3694 bool CanHaveAttributes() const;
3695
3696 /**
3697 Get the minimal width of the given column/row.
3698
3699 The value returned by this function may be different than that returned
3700 by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been
3701 called for this column.
3702 */
3703 int GetColMinimalWidth(int col) const;
3704
3705 /**
3706 Returns the coordinate of the right border specified column.
3707 */
3708 int GetColRight(int col) const;
3709
3710 /**
3711 Returns the coordinate of the left border specified column.
3712 */
3713 int GetColLeft(int col) const;
3714
3715 /**
3716 Returns the minimal size for the given column.
3717
3718 The value returned by this function may be different than that returned
3719 by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been
3720 called for this row.
3721 */
3722 int GetRowMinimalHeight(int col) const;
8b9ef005 3723};
23324ae1 3724
08dd9b5a 3725
23324ae1 3726
8b9ef005
BP
3727/**
3728 @class wxGridUpdateLocker
23324ae1 3729
8b9ef005
BP
3730 This small class can be used to prevent wxGrid from redrawing during its
3731 lifetime by calling wxGrid::BeginBatch() in its constructor and
3732 wxGrid::EndBatch() in its destructor. It is typically used in a function
3733 performing several operations with a grid which would otherwise result in
3734 flicker. For example:
23324ae1 3735
8b9ef005
BP
3736 @code
3737 void MyFrame::Foo()
3738 {
3739 m_grid = new wxGrid(this, ...);
23324ae1 3740
8b9ef005
BP
3741 wxGridUpdateLocker noUpdates(m_grid);
3742 m_grid-AppendColumn();
3743 // ... many other operations with m_grid ...
3744 m_grid-AppendRow();
08dd9b5a 3745
8b9ef005
BP
3746 // destructor called, grid refreshed
3747 }
3748 @endcode
08dd9b5a 3749
8b9ef005
BP
3750 Using this class is easier and safer than calling wxGrid::BeginBatch() and
3751 wxGrid::EndBatch() because you don't risk missing the call the latter (due
3752 to an exception for example).
23324ae1 3753
8b9ef005
BP
3754 @library{wxadv}
3755 @category{grid}
3756*/
3757class wxGridUpdateLocker
3758{
3759public:
23324ae1 3760 /**
8b9ef005
BP
3761 Creates an object preventing the updates of the specified @a grid. The
3762 parameter could be @NULL in which case nothing is done. If @a grid is
3763 non-@NULL then the grid must exist for longer than this
3764 wxGridUpdateLocker object itself.
08dd9b5a 3765
8b9ef005
BP
3766 The default constructor could be followed by a call to Create() to set
3767 the grid object later.
23324ae1 3768 */
8b9ef005 3769 wxGridUpdateLocker(wxGrid* grid = NULL);
23324ae1
FM
3770
3771 /**
8b9ef005
BP
3772 Destructor reenables updates for the grid this object is associated
3773 with.
23324ae1 3774 */
8b9ef005 3775 ~wxGridUpdateLocker();
23324ae1
FM
3776
3777 /**
8b9ef005
BP
3778 This method can be called if the object had been constructed using the
3779 default constructor. It must not be called more than once.
3780 */
3781 void Create(wxGrid* grid);
3782};
08dd9b5a 3783
08dd9b5a 3784
23324ae1 3785
8b9ef005
BP
3786/**
3787 @class wxGridEvent
08dd9b5a 3788
8b9ef005 3789 This event class contains information about various grid events.
8a3e536c 3790
2b1f9fa0
VZ
3791 Notice that all grid event table macros are available in two versions:
3792 @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the
3793 two is that the former doesn't allow to specify the grid window identifier
3794 and so takes a single parameter, the event handler, but is not suitable if
3795 there is more than one grid control in the window where the event table is
3796 used (as it would catch the events from all the grids). The version with @c
3797 CMD takes the id as first argument and the event handler as the second one
3798 and so can be used with multiple grids as well. Otherwise there are no
3799 difference between the two and only the versions without the id are
3800 documented below for brevity.
3801
8b9ef005 3802 @beginEventTable{wxGridEvent}
763163a8
VZ
3803 @event{EVT_GRID_CELL_CHANGING(func)}
3804 The user is about to change the data in a cell. The new cell value as
3805 string is available from GetString() event object method. This event
f8f31de6
FM
3806 can be vetoed if the change is not allowed.
3807 Processes a @c wxEVT_GRID_CELL_CHANGING event type.
763163a8
VZ
3808 @event{EVT_GRID_CELL_CHANGED(func)}
3809 The user changed the data in a cell. The old cell value as string is
3810 available from GetString() event object method. Notice that vetoing
3811 this event still works for backwards compatibility reasons but any new
3812 code should only veto EVT_GRID_CELL_CHANGING event and not this one.
3813 Processes a @c wxEVT_GRID_CELL_CHANGED event type.
8b9ef005
BP
3814 @event{EVT_GRID_CELL_LEFT_CLICK(func)}
3815 The user clicked a cell with the left mouse button. Processes a
3816 @c wxEVT_GRID_CELL_LEFT_CLICK event type.
3817 @event{EVT_GRID_CELL_LEFT_DCLICK(func)}
3818 The user double-clicked a cell with the left mouse button. Processes a
3819 @c wxEVT_GRID_CELL_LEFT_DCLICK event type.
3820 @event{EVT_GRID_CELL_RIGHT_CLICK(func)}
3821 The user clicked a cell with the right mouse button. Processes a
3822 @c wxEVT_GRID_CELL_RIGHT_CLICK event type.
3823 @event{EVT_GRID_CELL_RIGHT_DCLICK(func)}
3824 The user double-clicked a cell with the right mouse button. Processes a
3825 @c wxEVT_GRID_CELL_RIGHT_DCLICK event type.
3826 @event{EVT_GRID_EDITOR_HIDDEN(func)}
3827 The editor for a cell was hidden. Processes a
3828 @c wxEVT_GRID_EDITOR_HIDDEN event type.
3829 @event{EVT_GRID_EDITOR_SHOWN(func)}
3830 The editor for a cell was shown. Processes a
3831 @c wxEVT_GRID_EDITOR_SHOWN event type.
3832 @event{EVT_GRID_LABEL_LEFT_CLICK(func)}
3833 The user clicked a label with the left mouse button. Processes a
3834 @c wxEVT_GRID_LABEL_LEFT_CLICK event type.
3835 @event{EVT_GRID_LABEL_LEFT_DCLICK(func)}
3836 The user double-clicked a label with the left mouse button. Processes a
3837 @c wxEVT_GRID_LABEL_LEFT_DCLICK event type.
3838 @event{EVT_GRID_LABEL_RIGHT_CLICK(func)}
3839 The user clicked a label with the right mouse button. Processes a
3840 @c wxEVT_GRID_LABEL_RIGHT_CLICK event type.
3841 @event{EVT_GRID_LABEL_RIGHT_DCLICK(func)}
3842 The user double-clicked a label with the right mouse button. Processes
3843 a @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type.
3844 @event{EVT_GRID_SELECT_CELL(func)}
c6cc8b15
VZ
3845 The given cell was made current, either by user or by the program via a
3846 call to SetGridCursor() or GoToCell(). Processes a
8b9ef005 3847 @c wxEVT_GRID_SELECT_CELL event type.
cd68daf5
VZ
3848 @event{EVT_GRID_COL_MOVE(func)}
3849 The user tries to change the order of the columns in the grid by
3850 dragging the column specified by GetCol(). This event can be vetoed to
3851 either prevent the user from reordering the column change completely
3852 (but notice that if you don't want to allow it at all, you simply
3853 shouldn't call wxGrid::EnableDragColMove() in the first place), vetoed
3854 but handled in some way in the handler, e.g. by really moving the
3855 column to the new position at the associated table level, or allowed to
3856 proceed in which case wxGrid::SetColPos() is used to reorder the
3857 columns display order without affecting the use of the column indices
3858 otherwise.
3859 This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type.
11393d29
VZ
3860 @event{EVT_GRID_COL_SORT(func)}
3861 This event is generated when a column is clicked by the user and its
3862 name is explained by the fact that the custom reaction to a click on a
3863 column is to sort the grid contents by this column. However the grid
3864 itself has no special support for sorting and it's up to the handler of
3865 this event to update the associated table. But if the event is handled
3866 (and not vetoed) the grid supposes that the table was indeed resorted
3867 and updates the column to indicate the new sort order and refreshes
3868 itself.
11393d29 3869 This event macro corresponds to @c wxEVT_GRID_COL_SORT event type.
8b9ef005 3870 @endEventTable
8a3e536c 3871
8b9ef005 3872 @library{wxadv}
87638422 3873 @category{grid,events}
8b9ef005
BP
3874*/
3875class wxGridEvent : public wxNotifyEvent
3876{
3877public:
3878 /**
3879 Default constructor.
23324ae1 3880 */
8b9ef005 3881 wxGridEvent();
23324ae1 3882 /**
8b9ef005 3883 Constructor for initializing all event attributes.
23324ae1 3884 */
8b9ef005
BP
3885 wxGridEvent(int id, wxEventType type, wxObject* obj,
3886 int row = -1, int col = -1, int x = -1, int y = -1,
ccf39540 3887 bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
23324ae1
FM
3888
3889 /**
8b9ef005 3890 Returns @true if the Alt key was down at the time of the event.
23324ae1 3891 */
8b9ef005 3892 bool AltDown() const;
23324ae1
FM
3893
3894 /**
8b9ef005 3895 Returns @true if the Control key was down at the time of the event.
23324ae1 3896 */
8b9ef005 3897 bool ControlDown() const;
23324ae1
FM
3898
3899 /**
8b9ef005 3900 Column at which the event occurred.
23324ae1 3901 */
8b9ef005 3902 virtual int GetCol();
23324ae1
FM
3903
3904 /**
8b9ef005 3905 Position in pixels at which the event occurred.
23324ae1 3906 */
8b9ef005 3907 wxPoint GetPosition();
23324ae1
FM
3908
3909 /**
8b9ef005 3910 Row at which the event occurred.
23324ae1 3911 */
8b9ef005 3912 virtual int GetRow();
23324ae1
FM
3913
3914 /**
8b9ef005 3915 Returns @true if the Meta key was down at the time of the event.
23324ae1 3916 */
8b9ef005 3917 bool MetaDown() const;
23324ae1
FM
3918
3919 /**
8b9ef005
BP
3920 Returns @true if the user is selecting grid cells, or @false if
3921 deselecting.
23324ae1 3922 */
8b9ef005 3923 bool Selecting();
23324ae1
FM
3924
3925 /**
8b9ef005 3926 Returns @true if the Shift key was down at the time of the event.
23324ae1 3927 */
8b9ef005
BP
3928 bool ShiftDown() const;
3929};
23324ae1 3930
08dd9b5a 3931
8b9ef005
BP
3932
3933/**
3934 @class wxGridSizeEvent
3935
3936 This event class contains information about a row/column resize event.
3937
3938 @beginEventTable{wxGridSizeEvent}
8b9ef005 3939 @event{EVT_GRID_CMD_COL_SIZE(id, func)}
27bb2c8c
VZ
3940 The user resized a column, corresponds to @c wxEVT_GRID_COL_SIZE event
3941 type.
8b9ef005 3942 @event{EVT_GRID_CMD_ROW_SIZE(id, func)}
27bb2c8c
VZ
3943 The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event
3944 type.
3945 @event{EVT_GRID_COL_SIZE(func)}
3946 Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
3947 @event{EVT_GRID_ROW_SIZE(func)}
3948 Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id.
8b9ef005
BP
3949 @endEventTable
3950
3951 @library{wxadv}
87638422 3952 @category{grid,events}
8b9ef005
BP
3953*/
3954class wxGridSizeEvent : public wxNotifyEvent
3955{
3956public:
3957 /**
3958 Default constructor.
23324ae1 3959 */
8b9ef005 3960 wxGridSizeEvent();
23324ae1 3961 /**
8b9ef005 3962 Constructor for initializing all event attributes.
23324ae1 3963 */
8b9ef005
BP
3964 wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
3965 int rowOrCol = -1, int x = -1, int y = -1,
ccf39540 3966 const wxKeyboardState& kbd = wxKeyboardState());
23324ae1
FM
3967
3968 /**
8b9ef005 3969 Returns @true if the Alt key was down at the time of the event.
23324ae1 3970 */
8b9ef005 3971 bool AltDown() const;
23324ae1
FM
3972
3973 /**
8b9ef005 3974 Returns @true if the Control key was down at the time of the event.
23324ae1 3975 */
8b9ef005 3976 bool ControlDown() const;
23324ae1
FM
3977
3978 /**
8b9ef005 3979 Position in pixels at which the event occurred.
23324ae1 3980 */
8b9ef005 3981 wxPoint GetPosition();
23324ae1
FM
3982
3983 /**
8b9ef005 3984 Row or column at that was resized.
23324ae1 3985 */
8b9ef005 3986 int GetRowOrCol();
23324ae1
FM
3987
3988 /**
8b9ef005 3989 Returns @true if the Meta key was down at the time of the event.
23324ae1 3990 */
8b9ef005 3991 bool MetaDown() const;
23324ae1
FM
3992
3993 /**
8b9ef005 3994 Returns @true if the Shift key was down at the time of the event.
23324ae1 3995 */
8b9ef005
BP
3996 bool ShiftDown() const;
3997};
23324ae1 3998
3c4f71cc 3999
23324ae1 4000
8b9ef005
BP
4001/**
4002 @class wxGridRangeSelectEvent
08dd9b5a 4003
8b9ef005
BP
4004 @beginEventTable{wxGridRangeSelectEvent}
4005 @event{EVT_GRID_RANGE_SELECT(func)}
4006 The user selected a group of contiguous cells. Processes a
4007 @c wxEVT_GRID_RANGE_SELECT event type.
4008 @event{EVT_GRID_CMD_RANGE_SELECT(id, func)}
4009 The user selected a group of contiguous cells; variant taking a window
4010 identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type.
4011 @endEventTable
08dd9b5a 4012
8b9ef005 4013 @library{wxadv}
87638422 4014 @category{grid,events}
8b9ef005
BP
4015*/
4016class wxGridRangeSelectEvent : public wxNotifyEvent
4017{
4018public:
4019 /**
4020 Default constructor.
23324ae1 4021 */
8b9ef005 4022 wxGridRangeSelectEvent();
23324ae1 4023 /**
8b9ef005 4024 Constructor for initializing all event attributes.
23324ae1 4025 */
8b9ef005
BP
4026 wxGridRangeSelectEvent(int id, wxEventType type,
4027 wxObject* obj,
4028 const wxGridCellCoords& topLeft,
4029 const wxGridCellCoords& bottomRight,
ccf39540 4030 bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
23324ae1
FM
4031
4032 /**
8b9ef005 4033 Returns @true if the Alt key was down at the time of the event.
23324ae1 4034 */
8b9ef005 4035 bool AltDown() const;
23324ae1
FM
4036
4037 /**
8b9ef005 4038 Returns @true if the Control key was down at the time of the event.
23324ae1 4039 */
8b9ef005 4040 bool ControlDown() const;
23324ae1
FM
4041
4042 /**
8b9ef005 4043 Top left corner of the rectangular area that was (de)selected.
23324ae1 4044 */
8b9ef005 4045 wxGridCellCoords GetBottomRightCoords();
23324ae1 4046
8a3e536c 4047 /**
8b9ef005
BP
4048 Bottom row of the rectangular area that was (de)selected.
4049 */
4050 int GetBottomRow();
8a3e536c 4051
23324ae1 4052 /**
8b9ef005 4053 Left column of the rectangular area that was (de)selected.
23324ae1 4054 */
8b9ef005 4055 int GetLeftCol();
23324ae1
FM
4056
4057 /**
8b9ef005 4058 Right column of the rectangular area that was (de)selected.
23324ae1 4059 */
8b9ef005 4060 int GetRightCol();
5e6e278d 4061
5e6e278d 4062 /**
8b9ef005 4063 Top left corner of the rectangular area that was (de)selected.
5e6e278d 4064 */
8b9ef005 4065 wxGridCellCoords GetTopLeftCoords();
5e6e278d
FM
4066
4067 /**
8b9ef005 4068 Top row of the rectangular area that was (de)selected.
5e6e278d 4069 */
8b9ef005 4070 int GetTopRow();
5e6e278d
FM
4071
4072 /**
8b9ef005 4073 Returns @true if the Meta key was down at the time of the event.
5e6e278d 4074 */
8b9ef005 4075 bool MetaDown() const;
5e6e278d
FM
4076
4077 /**
8b9ef005 4078 Returns @true if the area was selected, @false otherwise.
5e6e278d 4079 */
8b9ef005 4080 bool Selecting();
5e6e278d
FM
4081
4082 /**
8b9ef005 4083 Returns @true if the Shift key was down at the time of the event.
5e6e278d 4084 */
8b9ef005 4085 bool ShiftDown() const;
23324ae1
FM
4086};
4087
4088
e54c96f1 4089
23324ae1 4090/**
8b9ef005 4091 @class wxGridEditorCreatedEvent
7c913512 4092
8b9ef005
BP
4093 @beginEventTable{wxGridEditorCreatedEvent}
4094 @event{EVT_GRID_EDITOR_CREATED(func)}
4095 The editor for a cell was created. Processes a
4096 @c wxEVT_GRID_EDITOR_CREATED event type.
4097 @event{EVT_GRID_CMD_EDITOR_CREATED(id, func)}
4098 The editor for a cell was created; variant taking a window identifier.
4099 Processes a @c wxEVT_GRID_EDITOR_CREATED event type.
4100 @endEventTable
7c913512 4101
23324ae1 4102 @library{wxadv}
87638422 4103 @category{grid,events}
23324ae1 4104*/
8b9ef005 4105class wxGridEditorCreatedEvent : public wxCommandEvent
23324ae1
FM
4106{
4107public:
4108 /**
4109 Default constructor.
4110 */
8b9ef005 4111 wxGridEditorCreatedEvent();
23324ae1 4112 /**
8b9ef005 4113 Constructor for initializing all event attributes.
23324ae1 4114 */
8b9ef005
BP
4115 wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj,
4116 int row, int col, wxControl* ctrl);
23324ae1
FM
4117
4118 /**
8b9ef005 4119 Returns the column at which the event occurred.
23324ae1 4120 */
8b9ef005 4121 int GetCol();
7c913512 4122
8b9ef005
BP
4123 /**
4124 Returns the edit control.
4125 */
4126 wxControl* GetControl();
7c913512 4127
8b9ef005
BP
4128 /**
4129 Returns the row at which the event occurred.
4130 */
4131 int GetRow();
7c913512 4132
23324ae1 4133 /**
8b9ef005 4134 Sets the column at which the event occurred.
23324ae1 4135 */
8b9ef005 4136 void SetCol(int col);
23324ae1
FM
4137
4138 /**
8b9ef005 4139 Sets the edit control.
23324ae1 4140 */
8b9ef005 4141 void SetControl(wxControl* ctrl);
23324ae1
FM
4142
4143 /**
8b9ef005 4144 Sets the row at which the event occurred.
23324ae1 4145 */
8b9ef005 4146 void SetRow(int row);
23324ae1 4147};
e54c96f1 4148