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