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