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