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