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