1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGrid and related classes
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxGridCellRenderer
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.
21 @see wxGridCellAutoWrapStringRenderer, wxGridCellBoolRenderer,
22 wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
23 wxGridCellFloatRenderer, wxGridCellNumberRenderer,
24 wxGridCellStringRenderer
26 class wxGridCellRenderer
30 This function must be implemented in derived classes to return a copy
33 virtual wxGridCellRenderer
* Clone() const = 0;
36 Draw the given cell on the provided DC inside the given rectangle using
37 the style specified by the attribute and the default or selected state
38 corresponding to the isSelected value.
40 This pure virtual function has a default implementation which will
41 prepare the DC using the given attribute: it will draw the rectangle
42 with the background colour from attr and set the text colour and font.
44 virtual void Draw(wxGrid
& grid
, wxGridCellAttr
& attr
, wxDC
& dc
,
45 const wxRect
& rect
, int row
, int col
,
49 Get the preferred size of the cell for its contents.
51 virtual wxSize
GetBestSize(wxGrid
& grid
, wxGridCellAttr
& attr
, wxDC
& dc
,
52 int row
, int col
) = 0;
56 @class wxGridCellAutoWrapStringRenderer
58 This class may be used to format string data in a cell. The too
59 long lines are wrapped to be shown entirely at word boundaries.
64 @see wxGridCellRenderer, wxGridCellBoolRenderer,
65 wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
66 wxGridCellFloatRenderer, wxGridCellNumberRenderer,
67 wxGridCellStringRenderer
70 class wxGridCellAutoWrapStringRenderer
: public wxGridCellStringRenderer
76 wxGridCellAutoWrapStringRenderer();
81 @class wxGridCellBoolRenderer
83 This class may be used to format boolean data in a cell.
88 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
89 wxGridCellDateTimeRenderer, wxGridCellEnumRenderer,
90 wxGridCellFloatRenderer, wxGridCellNumberRenderer,
91 wxGridCellStringRenderer
93 class wxGridCellBoolRenderer
: public wxGridCellRenderer
99 wxGridCellBoolRenderer();
103 @class wxGridCellDateTimeRenderer
105 This class may be used to format a date/time data in a cell.
106 The class wxDateTime is used internally to display the local date/time
107 or to parse the string date entered in the cell thanks to the defined format.
112 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
113 wxGridCellBoolRenderer, wxGridCellEnumRenderer,
114 wxGridCellFloatRenderer, wxGridCellNumberRenderer,
115 wxGridCellStringRenderer
117 class wxGridCellDateTimeRenderer
: public wxGridCellStringRenderer
121 Date/time renderer constructor.
124 strptime()-like format string used the parse the output date/time.
126 strptime()-like format string used to parse the string entered in the cell.
128 wxGridCellDateTimeRenderer(const wxString
& outformat
= wxDefaultDateTimeFormat
,
129 const wxString
& informat
= wxDefaultDateTimeFormat
);
133 Sets the strptime()-like format string which will be used to parse
137 strptime()-like format string used to parse the date/time.
139 virtual void SetParameters(const wxString
& params
);
143 @class wxGridCellEnumRenderer
145 This class may be used to render in a cell a number as a textual
148 The corresponding text strings are specified as comma-separated items in
149 the string passed to this renderer ctor or SetParameters() method. For
150 example, if this string is @c "John,Fred,Bob" the cell will be rendered as
151 "John", "Fred" or "Bob" if its contents is 0, 1 or 2 respectively.
156 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
157 wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
158 wxGridCellFloatRenderer, wxGridCellNumberRenderer,
159 wxGridCellStringRenderer
161 class wxGridCellEnumRenderer
: public wxGridCellStringRenderer
168 Comma separated string parameters "item1[,item2[...,itemN]]".
170 wxGridCellEnumRenderer( const wxString
& choices
= wxEmptyString
);
173 Sets the comma separated string content of the enum.
176 Comma separated string parameters "item1[,item2[...,itemN]]".
178 virtual void SetParameters(const wxString
& params
);
182 @class wxGridCellFloatRenderer
184 This class may be used to format floating point data in a cell.
189 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
190 wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
191 wxGridCellEnumRenderer, wxGridCellNumberRenderer,
192 wxGridCellStringRenderer
194 class wxGridCellFloatRenderer
: public wxGridCellStringRenderer
198 Float cell renderer ctor.
201 Minimum number of characters to be shown.
203 Number of digits after the decimal dot.
205 wxGridCellFloatRenderer(int width
= -1, int precision
= -1);
208 Returns the precision.
210 int GetPrecision() const;
215 int GetWidth() const;
218 Parameters string format is "width[,precision]".
220 virtual void SetParameters(const wxString
& params
);
225 void SetPrecision(int precision
);
230 void SetWidth(int width
);
234 @class wxGridCellNumberRenderer
236 This class may be used to format integer data in a cell.
241 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
242 wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
243 wxGridCellEnumRenderer, wxGridCellFloatRenderer,
244 wxGridCellStringRenderer
246 class wxGridCellNumberRenderer
: public wxGridCellStringRenderer
252 wxGridCellNumberRenderer();
256 @class wxGridCellStringRenderer
258 This class may be used to format string data in a cell; it is the default
264 @see wxGridCellRenderer, wxGridCellAutoWrapStringRenderer,
265 wxGridCellBoolRenderer, wxGridCellDateTimeRenderer,
266 wxGridCellEnumRenderer, wxGridCellFloatRenderer,
267 wxGridCellNumberRenderer
269 class wxGridCellStringRenderer
: public wxGridCellRenderer
275 wxGridCellStringRenderer();
280 @class wxGridCellEditor
282 This class is responsible for providing and manipulating the in-place edit
283 controls for the grid. Instances of wxGridCellEditor (actually, instances
284 of derived classes since it is an abstract class) can be associated with
285 the cell attributes for individual cells, rows, columns, or even for the
291 @see wxGridCellAutoWrapStringEditor, wxGridCellBoolEditor,
292 wxGridCellChoiceEditor, wxGridCellEnumEditor,
293 wxGridCellFloatEditor, wxGridCellNumberEditor,
296 class wxGridCellEditor
305 Fetch the value from the table and prepare the edit control to begin
308 This function should save the original value of the grid cell at the
309 given @a row and @a col and show the control allowing the user to
314 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
) = 0;
317 Create a new object which is the copy of this one.
319 virtual wxGridCellEditor
* Clone() const = 0;
322 Creates the actual edit control.
324 virtual void Create(wxWindow
* parent
, wxWindowID id
,
325 wxEvtHandler
* evtHandler
) = 0;
330 virtual void Destroy();
333 End editing the cell.
335 This function must check if the current value of the editing control is
336 valid and different from the original value (available as @a oldval in
337 its string form and possibly saved internally using its real type by
338 BeginEdit()). If it isn't, it just returns @false, otherwise it must do
340 # Save the new value internally so that ApplyEdit() could apply it.
341 # Fill @a newval (which is never @NULL) with the string
342 representation of the new value.
345 Notice that it must @em not modify the grid as the change could still
348 If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
349 this change, ApplyEdit() will be called next.
351 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
352 const wxString
& oldval
, wxString
* newval
) = 0;
355 Effectively save the changes in the grid.
357 This function should save the value of the control in the grid. It is
358 called only after EndEdit() returns @true.
360 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
) = 0;
363 Some types of controls on some platforms may need some help with the
366 virtual void HandleReturn(wxKeyEvent
& event
);
369 Returns @true if the edit control has been created.
374 Draws the part of the cell not occupied by the control: the base class
375 version just fills it with background colour from the attribute.
377 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
* attr
);
380 Reset the value in the control back to its starting value.
382 virtual void Reset() = 0;
385 Size and position the edit control.
387 virtual void SetSize(const wxRect
& rect
);
390 Show or hide the edit control, use the specified attributes to set
391 colours/fonts for it.
393 virtual void Show(bool show
, wxGridCellAttr
* attr
= NULL
);
396 If the editor is enabled by clicking on the cell, this method will be
399 virtual void StartingClick();
402 If the editor is enabled by pressing keys on the grid, this will be
403 called to let the editor do something about that first key if desired.
405 virtual void StartingKey(wxKeyEvent
& event
);
410 The destructor is private because only DecRef() can delete us.
412 virtual ~wxGridCellEditor();
416 @class wxGridCellAutoWrapStringEditor
418 Grid cell editor for wrappable string/text data.
423 @see wxGridCellEditor, wxGridCellBoolEditor, wxGridCellChoiceEditor,
424 wxGridCellEnumEditor, wxGridCellFloatEditor,
425 wxGridCellNumberEditor, wxGridCellTextEditor
427 class wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
430 wxGridCellAutoWrapStringEditor();
434 @class wxGridCellBoolEditor
436 Grid cell editor for boolean data.
441 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
442 wxGridCellChoiceEditor, wxGridCellEnumEditor,
443 wxGridCellFloatEditor, wxGridCellNumberEditor,
446 class wxGridCellBoolEditor
: public wxGridCellEditor
452 wxGridCellBoolEditor();
455 Returns @true if the given @a value is equal to the string
456 representation of the truth value we currently use (see
459 static bool IsTrueValue(const wxString
& value
);
462 This method allows you to customize the values returned by GetValue()
463 for the cell using this editor. By default, the default values of the
464 arguments are used, i.e. @c "1" is returned if the cell is checked and
465 an empty string otherwise.
467 static void UseStringValues(const wxString
& valueTrue
= "1",
468 const wxString
& valueFalse
= wxEmptyString
);
472 @class wxGridCellChoiceEditor
474 Grid cell editor for string data providing the user a choice from a list of
480 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
481 wxGridCellBoolEditor, wxGridCellEnumEditor,
482 wxGridCellFloatEditor, wxGridCellNumberEditor,
485 class wxGridCellChoiceEditor
: public wxGridCellEditor
489 Choice cell renderer ctor.
492 Number of strings from which the user can choose.
494 An array of strings from which the user can choose.
496 If allowOthers is @true, the user can type a string not in choices
499 wxGridCellChoiceEditor(size_t count
= 0,
500 const wxString choices
[] = NULL
,
501 bool allowOthers
= false);
504 Choice cell renderer ctor.
507 An array of strings from which the user can choose.
509 If allowOthers is @true, the user can type a string not in choices
512 wxGridCellChoiceEditor(const wxArrayString
& choices
,
513 bool allowOthers
= false);
516 Parameters string format is "item1[,item2[...,itemN]]"
518 virtual void SetParameters(const wxString
& params
);
522 @class wxGridCellEnumEditor
524 Grid cell editor which displays an enum number as a textual equivalent
525 (eg. data in cell is 0,1,2 ... n the cell could be displayed as
526 "John","Fred"..."Bob" in the combo choice box).
531 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
532 wxGridCellBoolEditor, wxGridCellChoiceEditor,
533 wxGridCellTextEditor, wxGridCellFloatEditor,
534 wxGridCellNumberEditor
536 class wxGridCellEnumEditor
: public wxGridCellChoiceEditor
540 Enum cell editor ctor.
543 Comma separated choice parameters "item1[,item2[...,itemN]]".
545 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
549 @class wxGridCellTextEditor
551 Grid cell editor for string/text data.
556 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
557 wxGridCellBoolEditor, wxGridCellChoiceEditor,
558 wxGridCellEnumEditor, wxGridCellFloatEditor,
559 wxGridCellNumberEditor
561 class wxGridCellTextEditor
: public wxGridCellEditor
567 wxGridCellTextEditor();
570 The parameters string format is "n" where n is a number representing
573 virtual void SetParameters(const wxString
& params
);
577 @class wxGridCellFloatEditor
579 The editor for floating point numbers data.
584 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
585 wxGridCellBoolEditor, wxGridCellChoiceEditor,
586 wxGridCellEnumEditor, wxGridCellNumberEditor,
589 class wxGridCellFloatEditor
: public wxGridCellTextEditor
593 Float cell editor ctor.
596 Minimum number of characters to be shown.
598 Number of digits after the decimal dot.
600 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
603 Parameters string format is "width,precision"
605 virtual void SetParameters(const wxString
& params
);
609 @class wxGridCellNumberEditor
611 Grid cell editor for numeric integer data.
616 @see wxGridCellEditor, wxGridCellAutoWrapStringEditor,
617 wxGridCellBoolEditor, wxGridCellChoiceEditor,
618 wxGridCellEnumEditor, wxGridCellFloatEditor,
621 class wxGridCellNumberEditor
: public wxGridCellTextEditor
625 Allows you to specify the range for acceptable data. Values equal to
626 -1 for both @a min and @a max indicate that no range checking should be
629 wxGridCellNumberEditor(int min
= -1, int max
= -1);
633 Parameters string format is "min,max".
635 virtual void SetParameters(const wxString
& params
);
640 If the return value is @true, the editor uses a wxSpinCtrl to get user
641 input, otherwise it uses a wxTextCtrl.
643 bool HasRange() const;
646 String representation of the value.
648 wxString
GetString() const;
654 @class wxGridCellAttr
656 This class can be used to alter the cells' appearance in the grid by
657 changing their attributes from the defaults. An object of this class may be
658 returned by wxGridTableBase::GetAttr().
667 Kind of the attribute to retrieve.
669 @see wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr()
673 /// Return the combined effective attribute for the cell.
676 /// Return the attribute explicitly set for this cell.
679 /// Return the attribute set for this cells row.
682 /// Return the attribute set for this cells column.
689 wxGridCellAttr(wxGridCellAttr
* attrDefault
= NULL
);
691 Constructor specifying some of the often used attributes.
693 wxGridCellAttr(const wxColour
& colText
, const wxColour
& colBack
,
694 const wxFont
& font
, int hAlign
, int vAlign
);
697 Creates a new copy of this object.
699 wxGridCellAttr
* Clone() const;
702 This class is reference counted: it is created with ref count of 1, so
703 calling DecRef() once will delete it. Calling IncRef() allows to lock
704 it until the matching DecRef() is called.
709 Get the alignment to use for the cell with the given attribute.
711 If this attribute doesn't specify any alignment, the default attribute
712 alignment is used (which can be changed using
713 wxGrid::SetDefaultCellAlignment() but is left and top by default).
715 Notice that @a hAlign and @a vAlign values are always overwritten by
716 this function, use GetNonDefaultAlignment() if this is not desirable.
719 Horizontal alignment is returned here if this argument is non-@NULL.
720 It is one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
722 Vertical alignment is returned here if this argument is non-@NULL.
723 It is one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
725 void GetAlignment(int* hAlign
, int* vAlign
) const;
728 Returns the background colour.
730 const wxColour
& GetBackgroundColour() const;
733 Returns the cell editor.
735 wxGridCellEditor
* GetEditor(const wxGrid
* grid
, int row
, int col
) const;
740 const wxFont
& GetFont() const;
743 Get the alignment defined by this attribute.
745 Unlike GetAlignment() this function only modifies @a hAlign and @a
746 vAlign if this attribute does define a non-default alignment. This
747 means that they must be initialized before calling this function and
748 that their values will be preserved unchanged if they are different
749 from wxALIGN_INVALID.
751 For example, the following fragment can be used to use the cell
752 alignment if one is defined but right-align its contents by default
753 (instead of left-aligning it by default) while still using the default
756 int hAlign = wxALIGN_RIGHT,
757 vAlign = wxALIGN_INVALID;
758 attr.GetNonDefaultAlignment(&hAlign, &vAlign);
763 void GetNonDefaultAlignment(int *hAlign
, int *vAlign
) const;
766 Returns the cell renderer.
768 wxGridCellRenderer
* GetRenderer(const wxGrid
* grid
, int row
, int col
) const;
771 Returns the text colour.
773 const wxColour
& GetTextColour() const;
776 Returns @true if this attribute has a valid alignment set.
778 bool HasAlignment() const;
781 Returns @true if this attribute has a valid background colour set.
783 bool HasBackgroundColour() const;
786 Returns @true if this attribute has a valid cell editor set.
788 bool HasEditor() const;
791 Returns @true if this attribute has a valid font set.
793 bool HasFont() const;
796 Returns @true if this attribute has a valid cell renderer set.
798 bool HasRenderer() const;
801 Returns @true if this attribute has a valid text colour set.
803 bool HasTextColour() const;
806 This class is reference counted: it is created with ref count of 1, so
807 calling DecRef() once will delete it. Calling IncRef() allows to lock
808 it until the matching DecRef() is called.
813 Returns @true if this cell is set as read-only.
815 bool IsReadOnly() const;
818 Sets the alignment. @a hAlign can be one of @c wxALIGN_LEFT,
819 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT and @a vAlign can be one of
820 @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
822 void SetAlignment(int hAlign
, int vAlign
);
825 Sets the background colour.
827 void SetBackgroundColour(const wxColour
& colBack
);
830 @todo Needs documentation.
832 void SetDefAttr(wxGridCellAttr
* defAttr
);
835 Sets the editor to be used with the cells with this attribute.
837 void SetEditor(wxGridCellEditor
* editor
);
842 void SetFont(const wxFont
& font
);
845 Sets the cell as read-only.
847 void SetReadOnly(bool isReadOnly
= true);
850 Sets the renderer to be used for cells with this attribute. Takes
851 ownership of the pointer.
853 void SetRenderer(wxGridCellRenderer
* renderer
);
856 Sets the text colour.
858 void SetTextColour(const wxColour
& colText
);
862 Base class for corner window renderer.
864 This is the simplest of all header renderers and only has a single
867 @see wxGridCellAttrProvider::GetCornerRenderer()
871 class wxGridCornerHeaderRenderer
875 Called by the grid to draw the corner window border.
877 This method is responsible for drawing the border inside the given @a
878 rect and adjusting the rectangle size to correspond to the area inside
879 the border, i.e. usually call wxRect::Deflate() to account for the
883 The grid whose corner window is being drawn.
885 The device context to use for drawing.
887 Input/output parameter which contains the border rectangle on input
888 and should be updated to contain the area inside the border on
891 virtual void DrawBorder(const wxGrid
& grid
,
893 wxRect
& rect
) const = 0;
896 Common base class for row and column headers renderers.
898 @see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer
902 class wxGridHeaderLabelsRenderer
: public wxGridCornerHeaderRenderer
906 Called by the grid to draw the specified label.
908 Notice that the base class DrawBorder() method is called before this
911 The default implementation uses wxGrid::GetLabelTextColour() and
912 wxGrid::GetLabelFont() to draw the label.
914 virtual void DrawLabel(const wxGrid
& grid
,
916 const wxString
& value
,
920 int textOrientation
) const;
924 Base class for row headers renderer.
926 This is the same as wxGridHeaderLabelsRenderer currently but we still use a
927 separate class for it to distinguish it from wxGridColumnHeaderRenderer.
929 @see wxGridRowHeaderRendererDefault
931 @see wxGridCellAttrProvider::GetRowHeaderRenderer()
935 class wxGridRowHeaderRenderer
: public wxGridHeaderLabelsRenderer
940 Base class for column headers renderer.
942 This is the same as wxGridHeaderLabelsRenderer currently but we still use a
943 separate class for it to distinguish it from wxGridRowHeaderRenderer.
945 @see wxGridColumnHeaderRendererDefault
947 @see wxGridCellAttrProvider::GetColumnHeaderRenderer()
951 class wxGridColumnHeaderRenderer
: public wxGridHeaderLabelsRenderer
956 Default row header renderer.
958 You may derive from this class if you need to only override one of its
959 methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the
960 default implementation for the other one.
962 @see wxGridColumnHeaderRendererDefault
966 class wxGridRowHeaderRendererDefault
: public wxGridRowHeaderRenderer
969 /// Implement border drawing for the row labels.
970 virtual void DrawBorder(const wxGrid
& grid
,
976 Default column header renderer.
978 @see wxGridRowHeaderRendererDefault
982 class wxGridColumnHeaderRendererDefault
: public wxGridColumnHeaderRenderer
985 /// Implement border drawing for the column labels.
986 virtual void DrawBorder(const wxGrid
& grid
,
992 Default corner window renderer.
994 @see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault
998 class wxGridCornerHeaderRendererDefault
: public wxGridCornerHeaderRenderer
1001 /// Implement border drawing for the corner window.
1002 virtual void DrawBorder(const wxGrid
& grid
,
1004 wxRect
& rect
) const;
1008 Class providing attributes to be used for the grid cells.
1010 This class both defines an interface which grid cell attributes providers
1011 should implement -- and which can be implemented differently in derived
1012 classes -- and a default implementation of this interface which is often
1013 good enough to be used without modification, especially with not very large
1014 grids for which the efficiency of attributes storage hardly matters (see
1015 the discussion below).
1017 An object of this class can be associated with a wxGrid using
1018 wxGridTableBase::SetAttrProvider() but it's not necessary to call it if you
1019 intend to use the default provider as it is used by wxGridTableBase by
1022 Notice that while attributes provided by this class can be set for
1023 individual cells using SetAttr() or the entire rows or columns using
1024 SetRowAttr() and SetColAttr() they are always retrieved using GetAttr()
1028 The default implementation of this class stores the attributes passed to
1029 its SetAttr(), SetRowAttr() and SetColAttr() in a straightforward way. A
1030 derived class may use its knowledge about how the attributes are used in
1031 your program to implement it much more efficiently: for example, using a
1032 special background colour for all even-numbered rows can be implemented by
1033 simply returning the same attribute from GetAttr() if the row number is
1034 even instead of having to store N/2 row attributes where N is the total
1035 number of rows in the grid.
1037 Notice that objects of this class can't be copied.
1039 class wxGridCellAttrProvider
: public wxClientDataContainer
1042 /// Trivial default constructor.
1043 wxGridCellAttrProvider();
1045 /// Destructor releases any attributes held by this class.
1046 virtual ~wxGridCellAttrProvider();
1049 Get the attribute to use for the specified cell.
1051 If wxGridCellAttr::Any is used as @a kind value, this function combines
1052 the attributes set for this cell using SetAttr() and those for its row
1053 or column (set with SetRowAttr() or SetColAttr() respectively), with
1054 the cell attribute having the highest precedence.
1056 Notice that the caller must call DecRef() on the returned pointer if it
1060 The row of the cell.
1062 The column of the cell.
1064 The kind of the attribute to return.
1066 The attribute to use which should be DecRef()'d by caller or @NULL
1067 if no attributes are defined for this cell.
1069 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
1070 wxGridCellAttr::wxAttrKind kind
) const;
1075 All these functions take ownership of the attribute passed to them,
1076 i.e. will call DecRef() on it themselves later and so it should not be
1077 destroyed by the caller. And the attribute can be @NULL to reset a
1078 previously set value.
1082 /// Set attribute for the specified cell.
1083 virtual void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
1085 /// Set attribute for the specified row.
1086 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
1088 /// Set attribute for the specified column.
1089 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
1094 Getting header renderers.
1096 These functions return the renderers for the given row or column header
1097 label and the corner window. Unlike cell attributes, these objects are
1098 not reference counted and are never @NULL so they are returned by
1099 reference and not pointer and DecRef() shouldn't (and can't) be called
1102 All these functions were added in wxWidgets 2.9.1.
1107 Return the renderer used for drawing column headers.
1109 By default wxGridColumnHeaderRendererDefault is returned.
1111 @see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader()
1115 virtual const wxGridColumnHeaderRenderer
& GetColumnHeaderRenderer(int col
);
1118 Return the renderer used for drawing row headers.
1120 By default wxGridRowHeaderRendererDefault is returned.
1124 virtual const wxGridRowHeaderRenderer
& GetRowHeaderRenderer(int row
);
1127 Return the renderer used for drawing the corner window.
1129 By default wxGridCornerHeaderRendererDefault is returned.
1133 virtual const wxGridCornerHeaderRenderer
& GetCornerRenderer();
1140 @class wxGridTableBase
1142 The almost abstract base class for grid tables.
1144 A grid table is responsible for storing the grid data and, indirectly, grid
1145 cell attributes. The data can be stored in the way most convenient for the
1146 application but has to be provided in string form to wxGrid. It is also
1147 possible to provide cells values in other formats if appropriate, e.g. as
1150 This base class is not quite abstract as it implements a trivial strategy
1151 for storing the attributes by forwarding it to wxGridCellAttrProvider and
1152 also provides stubs for some other functions. However it does have a number
1153 of pure virtual methods which must be implemented in the derived classes.
1155 @see wxGridStringTable
1160 class wxGridTableBase
: public wxObject
1164 Default constructor.
1169 Destructor frees the attribute provider if it was created.
1171 virtual ~wxGridTableBase();
1174 Must be overridden to return the number of rows in the table.
1176 For backwards compatibility reasons, this method is not const.
1177 Use GetRowsCount() instead of it in const methods of derived table
1180 virtual int GetNumberRows() = 0;
1183 Must be overridden to return the number of columns in the table.
1185 For backwards compatibility reasons, this method is not const.
1186 Use GetColsCount() instead of it in const methods of derived table
1189 virtual int GetNumberCols() = 0;
1192 Return the number of rows in the table.
1194 This method is not virtual and is only provided as a convenience for
1195 the derived classes which can't call GetNumberRows() without a
1196 @c const_cast from their const methods.
1198 int GetRowsCount() const;
1201 Return the number of columns in the table.
1203 This method is not virtual and is only provided as a convenience for
1204 the derived classes which can't call GetNumberCols() without a
1205 @c const_cast from their const methods.
1207 int GetColsCount() const;
1211 @name Table Cell Accessors
1216 May be overridden to implement testing for empty cells.
1218 This method is used by the grid to test if the given cell is not used
1219 and so whether a neighbouring cell may overflow into it. By default it
1220 only returns true if the value of the given cell, as returned by
1221 GetValue(), is empty.
1223 virtual bool IsEmptyCell(int row
, int col
);
1226 Same as IsEmptyCell() but taking wxGridCellCoords.
1228 Notice that this method is not virtual, only IsEmptyCell() should be
1231 bool IsEmpty(const wxGridCellCoords
& coords
);
1234 Must be overridden to implement accessing the table values as text.
1236 virtual wxString
GetValue(int row
, int col
) = 0;
1239 Must be overridden to implement setting the table values as text.
1241 virtual void SetValue(int row
, int col
, const wxString
& value
) = 0;
1244 Returns the type of the value in the given cell.
1246 By default all cells are strings and this method returns
1247 @c wxGRID_VALUE_STRING.
1249 virtual wxString
GetTypeName(int row
, int col
);
1252 Returns true if the value of the given cell can be accessed as if it
1253 were of the specified type.
1255 By default the cells can only be accessed as strings. Note that a cell
1256 could be accessible in different ways, e.g. a numeric cell may return
1257 @true for @c wxGRID_VALUE_NUMBER but also for @c wxGRID_VALUE_STRING
1258 indicating that the value can be coerced to a string form.
1260 virtual bool CanGetValueAs(int row
, int col
, const wxString
& typeName
);
1263 Returns true if the value of the given cell can be set as if it were of
1266 @see CanGetValueAs()
1268 virtual bool CanSetValueAs(int row
, int col
, const wxString
& typeName
);
1271 Returns the value of the given cell as a long.
1273 This should only be called if CanGetValueAs() returns @true when called
1274 with @c wxGRID_VALUE_NUMBER argument. Default implementation always
1277 virtual long GetValueAsLong(int row
, int col
);
1280 Returns the value of the given cell as a double.
1282 This should only be called if CanGetValueAs() returns @true when called
1283 with @c wxGRID_VALUE_FLOAT argument. Default implementation always
1286 virtual double GetValueAsDouble(int row
, int col
);
1289 Returns the value of the given cell as a boolean.
1291 This should only be called if CanGetValueAs() returns @true when called
1292 with @c wxGRID_VALUE_BOOL argument. Default implementation always
1295 virtual bool GetValueAsBool(int row
, int col
);
1298 Returns the value of the given cell as a user-defined type.
1300 This should only be called if CanGetValueAs() returns @true when called
1301 with @a typeName. Default implementation always return @NULL.
1303 virtual void *GetValueAsCustom(int row
, int col
, const wxString
& typeName
);
1306 Sets the value of the given cell as a long.
1308 This should only be called if CanSetValueAs() returns @true when called
1309 with @c wxGRID_VALUE_NUMBER argument. Default implementation doesn't do
1312 virtual void SetValueAsLong(int row
, int col
, long value
);
1315 Sets the value of the given cell as a double.
1317 This should only be called if CanSetValueAs() returns @true when called
1318 with @c wxGRID_VALUE_FLOAT argument. Default implementation doesn't do
1321 virtual void SetValueAsDouble(int row
, int col
, double value
);
1324 Sets the value of the given cell as a boolean.
1326 This should only be called if CanSetValueAs() returns @true when called
1327 with @c wxGRID_VALUE_BOOL argument. Default implementation doesn't do
1330 virtual void SetValueAsBool( int row
, int col
, bool value
);
1333 Sets the value of the given cell as a user-defined type.
1335 This should only be called if CanSetValueAs() returns @true when called
1336 with @a typeName. Default implementation doesn't do anything.
1338 virtual void SetValueAsCustom(int row
, int col
, const wxString
& typeName
,
1345 Called by the grid when the table is associated with it.
1347 The default implementation stores the pointer and returns it from its
1348 GetView() and so only makes sense if the table cannot be associated
1349 with more than one grid at a time.
1351 virtual void SetView(wxGrid
*grid
);
1354 Returns the last grid passed to SetView().
1356 virtual wxGrid
*GetView() const;
1360 @name Table Structure Modifiers
1362 Notice that none of these functions are pure virtual as they don't have
1363 to be implemented if the table structure is never modified after
1364 creation, i.e. neither rows nor columns are never added or deleted but
1365 that you do need to implement them if they are called, i.e. if your
1366 code either calls them directly or uses the matching wxGrid methods, as
1367 by default they simply do nothing which is definitely inappropriate.
1372 Clear the table contents.
1374 This method is used by wxGrid::ClearGrid().
1376 virtual void Clear();
1379 Insert additional rows into the table.
1382 The position of the first new row.
1384 The number of rows to insert.
1386 virtual bool InsertRows(size_t pos
= 0, size_t numRows
= 1);
1389 Append additional rows at the end of the table.
1391 This method is provided in addition to InsertRows() as some data models
1392 may only support appending rows to them but not inserting them at
1393 arbitrary locations. In such case you may implement this method only
1394 and leave InsertRows() unimplemented.
1397 The number of rows to add.
1399 virtual bool AppendRows(size_t numRows
= 1);
1402 Delete rows from the table.
1405 The first row to delete.
1407 The number of rows to delete.
1409 virtual bool DeleteRows(size_t pos
= 0, size_t numRows
= 1);
1412 Exactly the same as InsertRows() but for columns.
1414 virtual bool InsertCols(size_t pos
= 0, size_t numCols
= 1);
1417 Exactly the same as AppendRows() but for columns.
1419 virtual bool AppendCols(size_t numCols
= 1);
1422 Exactly the same as DeleteRows() but for columns.
1424 virtual bool DeleteCols(size_t pos
= 0, size_t numCols
= 1);
1429 @name Table Row and Column Labels
1431 By default the numbers are used for labeling rows and Latin letters for
1432 labeling columns. If the table has more than 26 columns, the pairs of
1433 letters are used starting from the 27-th one and so on, i.e. the
1434 sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ,
1440 Return the label of the specified row.
1442 virtual wxString
GetRowLabelValue(int row
);
1445 Return the label of the specified column.
1447 virtual wxString
GetColLabelValue(int col
);
1450 Set the given label for the specified row.
1452 The default version does nothing, i.e. the label is not stored. You
1453 must override this method in your derived class if you wish
1454 wxGrid::SetRowLabelValue() to work.
1456 virtual void SetRowLabelValue(int row
, const wxString
& label
);
1459 Exactly the same as SetRowLabelValue() but for columns.
1461 virtual void SetColLabelValue(int col
, const wxString
& label
);
1467 @name Attributes Management
1469 By default the attributes management is delegated to
1470 wxGridCellAttrProvider class. You may override the methods in this
1471 section to handle the attributes directly if, for example, they can be
1472 computed from the cell values.
1477 Associate this attributes provider with the table.
1479 The table takes ownership of @a attrProvider pointer and will delete it
1480 when it doesn't need it any more. The pointer can be @NULL, however
1481 this won't disable attributes management in the table but will just
1482 result in a default attributes being recreated the next time any of the
1483 other functions in this section is called. To completely disable the
1484 attributes support, should this be needed, you need to override
1485 CanHaveAttributes() to return @false.
1487 void SetAttrProvider(wxGridCellAttrProvider
*attrProvider
);
1490 Returns the attribute provider currently being used.
1492 This function may return @NULL if the attribute provider hasn't been
1493 neither associated with this table by SetAttrProvider() nor created on
1494 demand by any other methods.
1496 wxGridCellAttrProvider
*GetAttrProvider() const;
1499 Return the attribute for the given cell.
1501 By default this function is simply forwarded to
1502 wxGridCellAttrProvider::GetAttr() but it may be overridden to handle
1503 attributes directly in the table.
1505 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
1506 wxGridCellAttr::wxAttrKind kind
);
1509 Set attribute of the specified cell.
1511 By default this function is simply forwarded to
1512 wxGridCellAttrProvider::SetAttr().
1514 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1516 virtual void SetAttr(wxGridCellAttr
* attr
, int row
, int col
);
1519 Set attribute of the specified row.
1521 By default this function is simply forwarded to
1522 wxGridCellAttrProvider::SetRowAttr().
1524 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1526 virtual void SetRowAttr(wxGridCellAttr
*attr
, int row
);
1529 Set attribute of the specified column.
1531 By default this function is simply forwarded to
1532 wxGridCellAttrProvider::SetColAttr().
1534 The table takes ownership of @a attr, i.e. will call DecRef() on it.
1536 virtual void SetColAttr(wxGridCellAttr
*attr
, int col
);
1541 Returns true if this table supports attributes or false otherwise.
1543 By default, the table automatically creates a wxGridCellAttrProvider
1544 when this function is called if it had no attribute provider before and
1547 virtual bool CanHaveAttributes();
1551 @class wxGridSizesInfo
1553 wxGridSizesInfo stores information about sizes of all wxGrid rows or
1556 It assumes that most of the rows or columns (which are both called elements
1557 here as the difference between them doesn't matter at this class level)
1558 have the default size and so stores it separately. And it uses a wxHashMap
1559 to store the sizes of all elements which have the non-default size.
1561 This structure is particularly useful for serializing the sizes of all
1562 wxGrid elements at once.
1567 struct wxGridSizesInfo
1570 Default constructor.
1572 m_sizeDefault and m_customSizes must be initialized later.
1579 This constructor is used by wxGrid::GetRowSizes() and GetColSizes()
1580 methods. User code will usually use the default constructor instead.
1583 The default element size.
1585 Array containing the sizes of @em all elements, including those
1586 which have the default size.
1588 wxGridSizesInfo(int defSize
, const wxArrayInt
& allSizes
);
1591 Get the element size.
1594 The index of the element.
1596 The size for this element, using m_customSizes if @a pos is in it
1597 or m_sizeDefault otherwise.
1599 int GetSize(unsigned pos
) const;
1606 Map with element indices as keys and their sizes as values.
1608 This map only contains the elements with non-default size.
1610 wxUnsignedToIntHashMap m_customSizes
;
1617 wxGrid and its related classes are used for displaying and editing tabular
1618 data. They provide a rich set of features for display, editing, and
1619 interacting with a variety of data sources. For simple applications, and to
1620 help you get started, wxGrid is the only class you need to refer to
1621 directly. It will set up default instances of the other classes and manage
1622 them for you. For more complex applications you can derive your own classes
1623 for custom grid views, grid data tables, cell editors and renderers. The
1624 @ref overview_grid has examples of simple and more complex applications,
1625 explains the relationship between the various grid classes and has a
1626 summary of the keyboard shortcuts and mouse functions provided by wxGrid.
1628 A wxGridTableBase class holds the actual data to be displayed by a wxGrid
1629 class. One or more wxGrid classes may act as a view for one table class.
1630 The default table class is called wxGridStringTable and holds an array of
1631 strings. An instance of such a class is created by CreateGrid().
1633 wxGridCellRenderer is the abstract base class for rendereing contents in a
1634 cell. The following renderers are predefined:
1636 - wxGridCellBoolRenderer
1637 - wxGridCellFloatRenderer
1638 - wxGridCellNumberRenderer
1639 - wxGridCellStringRenderer
1641 The look of a cell can be further defined using wxGridCellAttr. An object
1642 of this type may be returned by wxGridTableBase::GetAttr().
1644 wxGridCellEditor is the abstract base class for editing the value of a
1645 cell. The following editors are predefined:
1647 - wxGridCellBoolEditor
1648 - wxGridCellChoiceEditor
1649 - wxGridCellFloatEditor
1650 - wxGridCellNumberEditor
1651 - wxGridCellTextEditor
1653 Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and
1654 wxGridEditorCreatedEvent for the documentation of all event types you can
1660 @see @ref overview_grid, wxGridUpdateLocker
1662 class wxGrid
: public wxScrolledWindow
1667 Different selection modes supported by the grid.
1669 enum wxGridSelectionModes
1672 The default selection mode allowing selection of the individual
1673 cells as well as of the entire rows and columns.
1678 The selection mode allowing the selection of the entire rows only.
1680 The user won't be able to select any cells or columns in this mode.
1685 The selection mode allowing the selection of the entire columns only.
1687 The user won't be able to select any cells or rows in this mode.
1693 Return values for GetCellSize().
1699 /// This cell is inside a span covered by another cell.
1700 CellSpan_Inside
= -1,
1702 /// This is a normal, non-spanning cell.
1705 /// This cell spans several physical wxGrid cells.
1710 @name Constructors and Initialization
1715 Default constructor.
1717 You must call Create() to really create the grid window and also call
1718 CreateGrid() or SetTable() to initialize the grid contents.
1722 Constructor creating the grid window.
1724 You must call either CreateGrid() or SetTable() to initialize the grid
1725 contents before using it.
1727 wxGrid(wxWindow
* parent
, wxWindowID id
,
1728 const wxPoint
& pos
= wxDefaultPosition
,
1729 const wxSize
& size
= wxDefaultSize
,
1730 long style
= wxWANTS_CHARS
,
1731 const wxString
& name
= wxGridNameStr
);
1736 This will also destroy the associated grid table unless you passed a
1737 table object to the grid and specified that the grid should not take
1738 ownership of the table (see SetTable()).
1743 Creates the grid window for an object initialized using the default
1746 You must call either CreateGrid() or SetTable() to initialize the grid
1747 contents before using it.
1749 bool Create(wxWindow
* parent
, wxWindowID id
,
1750 const wxPoint
& pos
= wxDefaultPosition
,
1751 const wxSize
& size
= wxDefaultSize
,
1752 long style
= wxWANTS_CHARS
,
1753 const wxString
& name
= wxGridNameStr
);
1756 Creates a grid with the specified initial number of rows and columns.
1758 Call this directly after the grid constructor. When you use this
1759 function wxGrid will create and manage a simple table of string values
1760 for you. All of the grid data will be stored in memory.
1762 For applications with more complex data types or relationships, or for
1763 dealing with very large datasets, you should derive your own grid table
1764 class and pass a table object to the grid with SetTable().
1766 bool CreateGrid(int numRows
, int numCols
,
1767 wxGridSelectionModes selmode
= wxGridSelectCells
);
1770 Passes a pointer to a custom grid table to be used by the grid.
1772 This should be called after the grid constructor and before using the
1773 grid object. If @a takeOwnership is set to @true then the table will be
1774 deleted by the wxGrid destructor.
1776 Use this function instead of CreateGrid() when your application
1777 involves complex or non-string data or data sets that are too large to
1778 fit wholly in memory.
1780 bool SetTable(wxGridTableBase
* table
, bool takeOwnership
= false,
1781 wxGridSelectionModes selmode
= wxGridSelectCells
);
1787 @name Grid Line Formatting
1792 Turns the drawing of grid lines on or off.
1794 void EnableGridLines(bool enable
= true);
1797 Returns the pen used for vertical grid lines.
1799 This virtual function may be overridden in derived classes in order to
1800 change the appearance of individual grid lines for the given column
1803 See GetRowGridLinePen() for an example.
1805 virtual wxPen
GetColGridLinePen(int col
);
1808 Returns the pen used for grid lines.
1810 This virtual function may be overridden in derived classes in order to
1811 change the appearance of grid lines. Note that currently the pen width
1814 @see GetColGridLinePen(), GetRowGridLinePen()
1816 virtual wxPen
GetDefaultGridLinePen();
1819 Returns the colour used for grid lines.
1821 @see GetDefaultGridLinePen()
1823 wxColour
GetGridLineColour() const;
1826 Returns the pen used for horizontal grid lines.
1828 This virtual function may be overridden in derived classes in order to
1829 change the appearance of individual grid line for the given @a row.
1833 // in a grid displaying music notation, use a solid black pen between
1834 // octaves (C0=row 127, C1=row 115 etc.)
1835 wxPen MidiGrid::GetRowGridLinePen(int row)
1837 if ( row % 12 == 7 )
1838 return wxPen(*wxBLACK, 1, wxSOLID);
1840 return GetDefaultGridLinePen();
1844 virtual wxPen
GetRowGridLinePen(int row
);
1847 Returns @true if drawing of grid lines is turned on, @false otherwise.
1849 bool GridLinesEnabled() const;
1852 Sets the colour used to draw grid lines.
1854 void SetGridLineColour(const wxColour
& colour
);
1860 @name Label Values and Formatting
1865 Sets the arguments to the current column label alignment values.
1867 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1868 or @c wxALIGN_RIGHT.
1870 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1873 void GetColLabelAlignment(int* horiz
, int* vert
) const;
1876 Returns the orientation of the column labels (either @c wxHORIZONTAL or
1879 int GetColLabelTextOrientation() const;
1882 Returns the specified column label.
1884 The default grid table class provides column labels of the form
1885 A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can
1886 override wxGridTableBase::GetColLabelValue() to provide your own
1889 wxString
GetColLabelValue(int col
) const;
1892 Returns the colour used for the background of row and column labels.
1894 wxColour
GetLabelBackgroundColour() const;
1897 Returns the font used for row and column labels.
1899 wxFont
GetLabelFont() const;
1902 Returns the colour used for row and column label text.
1904 wxColour
GetLabelTextColour() const;
1907 Returns the alignment used for row labels.
1909 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
1910 or @c wxALIGN_RIGHT.
1912 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
1915 void GetRowLabelAlignment(int* horiz
, int* vert
) const;
1918 Returns the specified row label.
1920 The default grid table class provides numeric row labels. If you are
1921 using a custom grid table you can override
1922 wxGridTableBase::GetRowLabelValue() to provide your own labels.
1924 wxString
GetRowLabelValue(int row
) const;
1927 Hides the column labels by calling SetColLabelSize() with a size of 0.
1928 Show labels again by calling that method with a width greater than 0.
1930 void HideColLabels();
1933 Hides the row labels by calling SetRowLabelSize() with a size of 0.
1935 The labels can be shown again by calling SetRowLabelSize() with a width
1938 void HideRowLabels();
1941 Sets the horizontal and vertical alignment of column label text.
1943 Horizontal alignment should be one of @c wxALIGN_LEFT,
1944 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
1945 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
1947 void SetColLabelAlignment(int horiz
, int vert
);
1950 Sets the orientation of the column labels (either @c wxHORIZONTAL or
1953 void SetColLabelTextOrientation(int textOrientation
);
1956 Set the value for the given column label.
1958 If you are using a custom grid table you must override
1959 wxGridTableBase::SetColLabelValue() for this to have any effect.
1961 void SetColLabelValue(int col
, const wxString
& value
);
1964 Sets the background colour for row and column labels.
1966 void SetLabelBackgroundColour(const wxColour
& colour
);
1969 Sets the font for row and column labels.
1971 void SetLabelFont(const wxFont
& font
);
1974 Sets the colour for row and column label text.
1976 void SetLabelTextColour(const wxColour
& colour
);
1979 Sets the horizontal and vertical alignment of row label text.
1981 Horizontal alignment should be one of @c wxALIGN_LEFT,
1982 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
1983 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
1985 void SetRowLabelAlignment(int horiz
, int vert
);
1988 Sets the value for the given row label.
1990 If you are using a derived grid table you must override
1991 wxGridTableBase::SetRowLabelValue() for this to have any effect.
1993 void SetRowLabelValue(int row
, const wxString
& value
);
1996 Call this in order to make the column labels use a native look by using
1997 wxRendererNative::DrawHeaderButton() internally.
1999 There is no equivalent method for drawing row columns as there is not
2000 native look for that. This option is useful when using wxGrid for
2001 displaying tables and not as a spread-sheet.
2003 @see UseNativeColHeader()
2005 void SetUseNativeColLabels(bool native
= true);
2008 Enable the use of native header window for column labels.
2010 If this function is called with @true argument, a wxHeaderCtrl is used
2011 instead to display the column labels instead of drawing them in wxGrid
2012 code itself. This has the advantage of making the grid look and feel
2013 perfectly the same as native applications (using SetUseNativeColLabels()
2014 the grid can be made to look more natively but it still doesn't feel
2015 natively, notably the column resizing and dragging still works slightly
2016 differently as it is implemented in wxWidgets itself) but results in
2017 different behaviour for column and row headers, for which there is no
2018 equivalent function, and, most importantly, is unsuitable for grids
2019 with huge numbers of columns as wxHeaderCtrl doesn't support virtual
2020 mode. Because of this, by default the grid does not use the native
2021 header control but you should call this function to enable it if you
2022 are using the grid to display tabular data and don't have thousands of
2025 Another difference between the default behaviour and the native header
2026 behaviour is that the latter provides the user with a context menu
2027 (which appears on right clicking the header) allowing to rearrange the
2028 grid columns if CanDragColMove() returns @true. If you want to prevent
2029 this from happening for some reason, you need to define a handler for
2030 @c wxEVT_GRID_LABEL_RIGHT_CLICK event which simply does nothing (in
2031 particular doesn't skip the event) as this will prevent the default
2032 right click handling from working.
2034 Also note that currently @c wxEVT_GRID_LABEL_RIGHT_DCLICK event is not
2035 generated for the column labels if the native columns header is used
2036 (but this limitation could possibly be lifted in the future).
2038 void UseNativeColHeader(bool native
= true);
2044 @name Cell Formatting
2046 Note that wxGridCellAttr can be used alternatively to most of these
2047 methods. See the "Attributes Management" of wxGridTableBase.
2052 Sets the arguments to the horizontal and vertical text alignment values
2053 for the grid cell at the specified location.
2055 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
2056 or @c wxALIGN_RIGHT.
2058 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
2061 void GetCellAlignment(int row
, int col
, int* horiz
, int* vert
) const;
2064 Returns the background colour of the cell at the specified location.
2066 wxColour
GetCellBackgroundColour(int row
, int col
) const;
2069 Returns the font for text in the grid cell at the specified location.
2071 wxFont
GetCellFont(int row
, int col
) const;
2074 Returns the text colour for the grid cell at the specified location.
2076 wxColour
GetCellTextColour(int row
, int col
) const;
2079 Returns the default cell alignment.
2081 Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE
2082 or @c wxALIGN_RIGHT.
2084 Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or
2087 @see SetDefaultCellAlignment()
2089 void GetDefaultCellAlignment(int* horiz
, int* vert
) const;
2092 Returns the current default background colour for grid cells.
2094 wxColour
GetDefaultCellBackgroundColour() const;
2097 Returns the current default font for grid cell text.
2099 wxFont
GetDefaultCellFont() const;
2102 Returns the current default colour for grid cell text.
2104 wxColour
GetDefaultCellTextColour() const;
2107 Sets the horizontal and vertical alignment for grid cell text at the
2110 Horizontal alignment should be one of @c wxALIGN_LEFT,
2111 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2113 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2114 or @c wxALIGN_BOTTOM.
2116 void SetCellAlignment(int row
, int col
, int horiz
, int vert
);
2118 Sets the horizontal and vertical alignment for grid cell text at the
2121 Horizontal alignment should be one of @c wxALIGN_LEFT,
2122 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT.
2124 Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE
2125 or @c wxALIGN_BOTTOM.
2127 void SetCellAlignment(int align
, int row
, int col
);
2130 Set the background colour for the given cell or all cells by default.
2132 void SetCellBackgroundColour(int row
, int col
, const wxColour
& colour
);
2135 Sets the font for text in the grid cell at the specified location.
2137 void SetCellFont(int row
, int col
, const wxFont
& font
);
2140 Sets the text colour for the given cell.
2142 void SetCellTextColour(int row
, int col
, const wxColour
& colour
);
2144 Sets the text colour for the given cell.
2146 void SetCellTextColour(const wxColour
& val
, int row
, int col
);
2148 Sets the text colour for all cells by default.
2150 void SetCellTextColour(const wxColour
& colour
);
2153 Sets the default horizontal and vertical alignment for grid cell text.
2155 Horizontal alignment should be one of @c wxALIGN_LEFT,
2156 @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one
2157 of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM.
2159 void SetDefaultCellAlignment(int horiz
, int vert
);
2162 Sets the default background colour for grid cells.
2164 void SetDefaultCellBackgroundColour(const wxColour
& colour
);
2167 Sets the default font to be used for grid cell text.
2169 void SetDefaultCellFont(const wxFont
& font
);
2172 Sets the current default colour for grid cell text.
2174 void SetDefaultCellTextColour(const wxColour
& colour
);
2180 @name Cell Values, Editors, and Renderers
2182 Note that wxGridCellAttr can be used alternatively to most of these
2183 methods. See the "Attributes Management" of wxGridTableBase.
2188 Returns @true if the in-place edit control for the current grid cell
2189 can be used and @false otherwise.
2191 This function always returns @false for the read-only cells.
2193 bool CanEnableCellControl() const;
2196 Disables in-place editing of grid cells.
2198 Equivalent to calling EnableCellEditControl(@false).
2200 void DisableCellEditControl();
2203 Enables or disables in-place editing of grid cell data.
2205 The grid will issue either a @c wxEVT_GRID_EDITOR_SHOWN or
2206 @c wxEVT_GRID_EDITOR_HIDDEN event.
2208 void EnableCellEditControl(bool enable
= true);
2211 Makes the grid globally editable or read-only.
2213 If the edit argument is @false this function sets the whole grid as
2214 read-only. If the argument is @true the grid is set to the default
2215 state where cells may be editable. In the default state you can set
2216 single grid cells and whole rows and columns to be editable or
2217 read-only via wxGridCellAttr::SetReadOnly(). For single cells you
2218 can also use the shortcut function SetReadOnly().
2220 For more information about controlling grid cell attributes see the
2221 wxGridCellAttr class and the @ref overview_grid.
2223 void EnableEditing(bool edit
);
2226 Returns a pointer to the editor for the cell at the specified location.
2228 See wxGridCellEditor and the @ref overview_grid for more information
2229 about cell editors and renderers.
2231 The caller must call DecRef() on the returned pointer.
2233 wxGridCellEditor
* GetCellEditor(int row
, int col
) const;
2236 Returns a pointer to the renderer for the grid cell at the specified
2239 See wxGridCellRenderer and the @ref overview_grid for more information
2240 about cell editors and renderers.
2242 The caller must call DecRef() on the returned pointer.
2244 wxGridCellRenderer
* GetCellRenderer(int row
, int col
) const;
2247 Returns the string contained in the cell at the specified location.
2249 For simple applications where a grid object automatically uses a
2250 default grid table of string values you use this function together with
2251 SetCellValue() to access cell values. For more complex applications
2252 where you have derived your own grid table class that contains various
2253 data types (e.g. numeric, boolean or user-defined custom types) then
2254 you only use this function for those cells that contain string values.
2256 See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
2259 wxString
GetCellValue(int row
, int col
) const;
2261 Returns the string contained in the cell at the specified location.
2263 For simple applications where a grid object automatically uses a
2264 default grid table of string values you use this function together with
2265 SetCellValue() to access cell values. For more complex applications
2266 where you have derived your own grid table class that contains various
2267 data types (e.g. numeric, boolean or user-defined custom types) then
2268 you only use this function for those cells that contain string values.
2270 See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
2273 wxString
GetCellValue(const wxGridCellCoords
& coords
) const;
2276 Returns a pointer to the current default grid cell editor.
2278 See wxGridCellEditor and the @ref overview_grid for more information
2279 about cell editors and renderers.
2281 wxGridCellEditor
* GetDefaultEditor() const;
2284 Returns the default editor for the specified cell.
2286 The base class version returns the editor appropriate for the current
2287 cell type but this method may be overridden in the derived classes to
2288 use custom editors for some cells by default.
2290 Notice that the same may be achieved in a usually simpler way by
2291 associating a custom editor with the given cell or cells.
2293 The caller must call DecRef() on the returned pointer.
2295 virtual wxGridCellEditor
* GetDefaultEditorForCell(int row
, int col
) const;
2297 Returns the default editor for the specified cell.
2299 The base class version returns the editor appropriate for the current
2300 cell type but this method may be overridden in the derived classes to
2301 use custom editors for some cells by default.
2303 Notice that the same may be achieved in a usually simpler way by
2304 associating a custom editor with the given cell or cells.
2306 The caller must call DecRef() on the returned pointer.
2308 wxGridCellEditor
* GetDefaultEditorForCell(const wxGridCellCoords
& c
) const;
2311 Returns the default editor for the cells containing values of the given
2314 The base class version returns the editor which was associated with the
2315 specified @a typeName when it was registered RegisterDataType() but
2316 this function may be overridden to return something different. This
2317 allows to override an editor used for one of the standard types.
2319 The caller must call DecRef() on the returned pointer.
2321 virtual wxGridCellEditor
* GetDefaultEditorForType(const wxString
& typeName
) const;
2324 Returns a pointer to the current default grid cell renderer.
2326 See wxGridCellRenderer and the @ref overview_grid for more information
2327 about cell editors and renderers.
2329 The caller must call DecRef() on the returned pointer.
2331 wxGridCellRenderer
* GetDefaultRenderer() const;
2334 Returns the default renderer for the given cell.
2336 The base class version returns the renderer appropriate for the current
2337 cell type but this method may be overridden in the derived classes to
2338 use custom renderers for some cells by default.
2340 The caller must call DecRef() on the returned pointer.
2342 virtual wxGridCellRenderer
* GetDefaultRendererForCell(int row
, int col
) const;
2345 Returns the default renderer for the cell containing values of the
2348 @see GetDefaultEditorForType()
2350 virtual wxGridCellRenderer
* GetDefaultRendererForType(const wxString
& typeName
) const;
2353 Hides the in-place cell edit control.
2355 void HideCellEditControl();
2358 Returns @true if the in-place edit control is currently enabled.
2360 bool IsCellEditControlEnabled() const;
2363 Returns @true if the current cell is read-only.
2365 @see SetReadOnly(), IsReadOnly()
2367 bool IsCurrentCellReadOnly() const;
2370 Returns @false if the whole grid has been set as read-only or @true
2373 See EnableEditing() for more information about controlling the editing
2374 status of grid cells.
2376 bool IsEditable() const;
2379 Returns @true if the cell at the specified location can't be edited.
2381 @see SetReadOnly(), IsCurrentCellReadOnly()
2383 bool IsReadOnly(int row
, int col
) const;
2386 Register a new data type.
2388 The data types allow to naturally associate specific renderers and
2389 editors to the cells containing values of the given type. For example,
2390 the grid automatically registers a data type with the name
2391 @c wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and
2392 wxGridCellTextEditor as its renderer and editor respectively -- this is
2393 the data type used by all the cells of the default wxGridStringTable,
2394 so this renderer and editor are used by default for all grid cells.
2396 However if a custom table returns @c wxGRID_VALUE_BOOL from its
2397 wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and
2398 wxGridCellBoolEditor are used for it because the grid also registers a
2399 boolean data type with this name.
2401 And as this mechanism is completely generic, you may register your own
2402 data types using your own custom renderers and editors. Just remember
2403 that the table must identify a cell as being of the given type for them
2404 to be used for this cell.
2407 Name of the new type. May be any string, but if the type name is
2408 the same as the name of an already registered type, including one
2409 of the standard ones (which are @c wxGRID_VALUE_STRING, @c
2410 wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT
2411 and @c wxGRID_VALUE_CHOICE), then the new registration information
2412 replaces the previously used renderer and editor.
2414 The renderer to use for the cells of this type. Its ownership is
2415 taken by the grid, i.e. it will call DecRef() on this pointer when
2416 it doesn't need it any longer.
2418 The editor to use for the cells of this type. Its ownership is also
2421 void RegisterDataType(const wxString
& typeName
,
2422 wxGridCellRenderer
* renderer
,
2423 wxGridCellEditor
* editor
);
2426 Sets the value of the current grid cell to the current in-place edit
2429 This is called automatically when the grid cursor moves from the
2430 current cell to a new cell. It is also a good idea to call this
2431 function when closing a grid since any edits to the final cell location
2432 will not be saved otherwise.
2434 void SaveEditControlValue();
2437 Sets the editor for the grid cell at the specified location.
2439 The grid will take ownership of the pointer.
2441 See wxGridCellEditor and the @ref overview_grid for more information
2442 about cell editors and renderers.
2444 void SetCellEditor(int row
, int col
, wxGridCellEditor
* editor
);
2447 Sets the renderer for the grid cell at the specified location.
2449 The grid will take ownership of the pointer.
2451 See wxGridCellRenderer and the @ref overview_grid for more information
2452 about cell editors and renderers.
2454 void SetCellRenderer(int row
, int col
, wxGridCellRenderer
* renderer
);
2457 Sets the string value for the cell at the specified location.
2459 For simple applications where a grid object automatically uses a
2460 default grid table of string values you use this function together with
2461 GetCellValue() to access cell values. For more complex applications
2462 where you have derived your own grid table class that contains various
2463 data types (e.g. numeric, boolean or user-defined custom types) then
2464 you only use this function for those cells that contain string values.
2466 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2469 void SetCellValue(int row
, int col
, const wxString
& s
);
2471 Sets the string value for the cell at the specified location.
2473 For simple applications where a grid object automatically uses a
2474 default grid table of string values you use this function together with
2475 GetCellValue() to access cell values. For more complex applications
2476 where you have derived your own grid table class that contains various
2477 data types (e.g. numeric, boolean or user-defined custom types) then
2478 you only use this function for those cells that contain string values.
2480 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2483 void SetCellValue(const wxGridCellCoords
& coords
, const wxString
& s
);
2485 @deprecated Please use SetCellValue(int,int,const wxString&) or
2486 SetCellValue(const wxGridCellCoords&,const wxString&)
2489 Sets the string value for the cell at the specified location.
2491 For simple applications where a grid object automatically uses a
2492 default grid table of string values you use this function together with
2493 GetCellValue() to access cell values. For more complex applications
2494 where you have derived your own grid table class that contains various
2495 data types (e.g. numeric, boolean or user-defined custom types) then
2496 you only use this function for those cells that contain string values.
2498 See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for
2501 void SetCellValue(const wxString
& val
, int row
, int col
);
2504 Sets the specified column to display boolean values.
2506 @see SetColFormatCustom()
2508 void SetColFormatBool(int col
);
2511 Sets the specified column to display data in a custom format.
2513 This method provides an alternative to defining a custom grid table
2514 which would return @a typeName from its GetTypeName() method for the
2515 cells in this column: while it doesn't really change the type of the
2516 cells in this column, it does associate the renderer and editor used
2517 for the cells of the specified type with them.
2519 See the @ref overview_grid for more information on working with custom
2522 void SetColFormatCustom(int col
, const wxString
& typeName
);
2525 Sets the specified column to display floating point values with the
2526 given width and precision.
2528 @see SetColFormatCustom()
2530 void SetColFormatFloat(int col
, int width
= -1, int precision
= -1);
2533 Sets the specified column to display integer values.
2535 @see SetColFormatCustom()
2537 void SetColFormatNumber(int col
);
2540 Sets the default editor for grid cells.
2542 The grid will take ownership of the pointer.
2544 See wxGridCellEditor and the @ref overview_grid for more information
2545 about cell editors and renderers.
2547 void SetDefaultEditor(wxGridCellEditor
* editor
);
2550 Sets the default renderer for grid cells.
2552 The grid will take ownership of the pointer.
2554 See wxGridCellRenderer and the @ref overview_grid for more information
2555 about cell editors and renderers.
2557 void SetDefaultRenderer(wxGridCellRenderer
* renderer
);
2560 Makes the cell at the specified location read-only or editable.
2564 void SetReadOnly(int row
, int col
, bool isReadOnly
= true);
2567 Displays the in-place cell edit control for the current cell.
2569 void ShowCellEditControl();
2575 @name Column and Row Sizes
2577 @see @ref overview_grid_resizing
2582 Automatically sets the height and width of all rows and columns to fit
2588 Automatically adjusts width of the column to fit its label.
2590 void AutoSizeColLabelSize(int col
);
2593 Automatically sizes the column to fit its contents. If @a setAsMin is
2594 @true the calculated width will also be set as the minimal width for
2597 void AutoSizeColumn(int col
, bool setAsMin
= true);
2600 Automatically sizes all columns to fit their contents. If @a setAsMin
2601 is @true the calculated widths will also be set as the minimal widths
2604 void AutoSizeColumns(bool setAsMin
= true);
2607 Automatically sizes the row to fit its contents. If @a setAsMin is
2608 @true the calculated height will also be set as the minimal height for
2611 void AutoSizeRow(int row
, bool setAsMin
= true);
2614 Automatically adjusts height of the row to fit its label.
2616 void AutoSizeRowLabelSize(int col
);
2619 Automatically sizes all rows to fit their contents. If @a setAsMin is
2620 @true the calculated heights will also be set as the minimal heights
2623 void AutoSizeRows(bool setAsMin
= true);
2626 Returns the current height of the column labels.
2628 int GetColLabelSize() const;
2631 Returns the minimal width to which a column may be resized.
2633 Use SetColMinimalAcceptableWidth() to change this value globally or
2634 SetColMinimalWidth() to do it for individual columns.
2636 @see GetRowMinimalAcceptableHeight()
2638 int GetColMinimalAcceptableWidth() const;
2641 Returns the width of the specified column.
2643 int GetColSize(int col
) const;
2646 Returns @true if the specified column is not currently hidden.
2648 bool IsColShown(int col
) const;
2651 Returns the default height for column labels.
2653 int GetDefaultColLabelSize() const;
2656 Returns the current default width for grid columns.
2658 int GetDefaultColSize() const;
2661 Returns the default width for the row labels.
2663 int GetDefaultRowLabelSize() const;
2666 Returns the current default height for grid rows.
2668 int GetDefaultRowSize() const;
2671 Returns the minimal size to which rows can be resized.
2673 Use SetRowMinimalAcceptableHeight() to change this value globally or
2674 SetRowMinimalHeight() to do it for individual cells.
2676 @see GetColMinimalAcceptableWidth()
2678 int GetRowMinimalAcceptableHeight() const;
2681 Returns the current width of the row labels.
2683 int GetRowLabelSize() const;
2686 Returns the height of the specified row.
2688 int GetRowSize(int row
) const;
2691 Returns @true if the specified row is not currently hidden.
2693 bool IsRowShown(int row
) const;
2696 Sets the height of the column labels.
2698 If @a height equals to @c wxGRID_AUTOSIZE then height is calculated
2699 automatically so that no label is truncated. Note that this could be
2700 slow for a large table.
2702 void SetColLabelSize(int height
);
2705 Sets the minimal @a width to which the user can resize columns.
2707 @see GetColMinimalAcceptableWidth()
2709 void SetColMinimalAcceptableWidth(int width
);
2712 Sets the minimal @a width for the specified column @a col.
2714 It is usually best to call this method during grid creation as calling
2715 it later will not resize the column to the given minimal width even if
2716 it is currently narrower than it.
2718 @a width must be greater than the minimal acceptable column width as
2719 returned by GetColMinimalAcceptableWidth().
2721 void SetColMinimalWidth(int col
, int width
);
2724 Sets the width of the specified column.
2729 The new column width in pixels, 0 to hide the column or -1 to fit
2730 the column width to its label width.
2732 void SetColSize(int col
, int width
);
2735 Hides the specified column.
2737 To show the column later you need to call SetColSize() with non-0
2743 void HideCol(int col
);
2746 Shows the previously hidden column by resizing it to non-0 size.
2748 @see HideCol(), SetColSize()
2750 void ShowCol(int col
);
2754 Sets the default width for columns in the grid.
2756 This will only affect columns subsequently added to the grid unless
2757 @a resizeExistingCols is @true.
2759 If @a width is less than GetColMinimalAcceptableWidth(), then the
2760 minimal acceptable width is used instead of it.
2762 void SetDefaultColSize(int width
, bool resizeExistingCols
= false);
2765 Sets the default height for rows in the grid.
2767 This will only affect rows subsequently added to the grid unless
2768 @a resizeExistingRows is @true.
2770 If @a height is less than GetRowMinimalAcceptableHeight(), then the
2771 minimal acceptable heihgt is used instead of it.
2773 void SetDefaultRowSize(int height
, bool resizeExistingRows
= false);
2776 Sets the width of the row labels.
2778 If @a width equals @c wxGRID_AUTOSIZE then width is calculated
2779 automatically so that no label is truncated. Note that this could be
2780 slow for a large table.
2782 void SetRowLabelSize(int width
);
2785 Sets the minimal row @a height used by default.
2787 See SetColMinimalAcceptableWidth() for more information.
2789 void SetRowMinimalAcceptableHeight(int height
);
2792 Sets the minimal @a height for the specified @a row.
2794 See SetColMinimalWidth() for more information.
2796 void SetRowMinimalHeight(int row
, int height
);
2799 Sets the height of the specified row.
2801 See SetColSize() for more information.
2803 void SetRowSize(int row
, int height
);
2806 Hides the specified row.
2808 To show the row later you need to call SetRowSize() with non-0
2814 void HideRow(int col
);
2817 Shows the previously hidden row by resizing it to non-0 size.
2819 @see HideRow(), SetRowSize()
2821 void ShowRow(int col
);
2824 Get size information for all columns at once.
2826 This method is useful when the information about all column widths
2827 needs to be saved. The widths can be later restored using
2830 @sa wxGridSizesInfo, GetRowSizes()
2832 wxGridSizesInfo
GetColSizes() const;
2835 Get size information for all row at once.
2837 @sa wxGridSizesInfo, GetColSizes()
2839 wxGridSizesInfo
GetRowSizes() const;
2842 Restore all columns sizes.
2844 This is usually called with wxGridSizesInfo object previously returned
2849 void SetColSizes(const wxGridSizesInfo
& sizeInfo
);
2852 Restore all rows sizes.
2856 void SetRowSizes(const wxGridSizesInfo
& sizeInfo
);
2859 Set the size of the cell.
2861 Specifying a value of more than 1 in @a num_rows or @a num_cols will
2862 make the cell at (@a row, @a col) span the block of the specified size,
2863 covering the other cells which would be normally shown in it. Passing 1
2864 for both arguments resets the cell to normal appearance.
2869 The row of the cell.
2871 The column of the cell.
2873 Number of rows to be occupied by this cell, must be >= 1.
2875 Number of columns to be occupied by this cell, must be >= 1.
2877 void SetCellSize(int row
, int col
, int num_rows
, int num_cols
);
2880 Get the size of the cell in number of cells covered by it.
2882 For normal cells, the function fills both @a num_rows and @a num_cols
2883 with 1 and returns CellSpan_None. For cells which span multiple cells, i.e.
2884 for which SetCellSize() had been called, the returned values are the
2885 same ones as were passed to SetCellSize() call and the function return
2886 value is CellSpan_Main.
2888 More unexpectedly, perhaps, the returned values may be @em negative for
2889 the cells which are inside a span covered by a cell occupying multiple
2890 rows or columns. They correspond to the offset of the main cell of the
2891 span from the cell passed to this functions and the function returns
2892 CellSpan_Inside value to indicate this.
2894 As an example, consider a 3*3 grid with the cell (1, 1) (the one in the
2895 middle) having a span of 2 rows and 2 columns, i.e. the grid looks like
2905 Then the function returns 2 and 2 in @a num_rows and @a num_cols for
2906 the cell (1, 1) itself and -1 and -1 for the cell (2, 2) as well as -1
2907 and 0 for the cell (2, 1).
2910 The row of the cell.
2912 The column of the cell.
2914 Pointer to variable receiving the number of rows, must not be @NULL.
2916 Pointer to variable receiving the number of columns, must not be
2919 The kind of this cell span (the return value is new in wxWidgets
2920 2.9.1, this function was void in previous wxWidgets versions).
2922 CellSpan
GetCellSize( int row
, int col
, int *num_rows
, int *num_cols
) const;
2925 Get the number of rows and columns allocated for this cell.
2927 This overload doesn't return a CellSpan value but the values returned
2928 may still be negative, see GetCellSize(int, int, int *, int *) for
2931 wxSize
GetCellSize(const wxGridCellCoords
& coords
);
2937 @name User-Resizing and Dragging
2939 Functions controlling various interactive mouse operations.
2941 By default, columns and rows can be resized by dragging the edges of
2942 their labels (this can be disabled using DisableDragColSize() and
2943 DisableDragRowSize() methods). And if grid line dragging is enabled with
2944 EnableDragGridSize() they can also be resized by dragging the right or
2945 bottom edge of the grid cells.
2947 Columns can also be moved to interactively change their order but this
2948 needs to be explicitly enabled with EnableDragColMove().
2953 Return @true if the dragging of cells is enabled or @false otherwise.
2955 bool CanDragCell() const;
2958 Returns @true if columns can be moved by dragging with the mouse.
2960 Columns can be moved by dragging on their labels.
2962 bool CanDragColMove() const;
2965 Returns @true if the given column can be resized by dragging with the
2968 This function returns @true if resizing the columns interactively is
2969 globally enabled, i.e. if DisableDragColSize() hadn't been called, and
2970 if this column wasn't explicitly marked as non-resizable with
2973 bool CanDragColSize(int col
) const;
2976 Return @true if the dragging of grid lines to resize rows and columns
2977 is enabled or @false otherwise.
2979 bool CanDragGridSize() const;
2982 Returns @true if the given row can be resized by dragging with the
2985 This is the same as CanDragColSize() but for rows.
2987 bool CanDragRowSize(int row
) const;
2990 Disable interactive resizing of the specified column.
2992 This method allows to disable resizing of an individual column in a
2993 grid where the columns are otherwise resizable (which is the case by
2996 Notice that currently there is no way to make some columns resizable in
2997 a grid where columns can't be resized by default as there doesn't seem
2998 to be any need for this in practice. There is also no way to make the
2999 column marked as fixed using this method resizeable again because it is
3000 supposed that fixed columns are used for static parts of the grid and
3001 so should remain fixed during the entire grid lifetime.
3003 Also notice that disabling interactive column resizing will not prevent
3004 the program from changing the column size.
3006 @see EnableDragColSize()
3008 void DisableColResize(int col
);
3011 Disable interactive resizing of the specified row.
3013 This is the same as DisableColResize() but for rows.
3015 @see EnableDragRowSize()
3017 void DisableRowResize(int row
);
3020 Disables column moving by dragging with the mouse.
3022 Equivalent to passing @false to EnableDragColMove().
3024 void DisableDragColMove();
3027 Disables column sizing by dragging with the mouse.
3029 Equivalent to passing @false to EnableDragColSize().
3031 void DisableDragColSize();
3034 Disable mouse dragging of grid lines to resize rows and columns.
3036 Equivalent to passing @false to EnableDragGridSize()
3038 void DisableDragGridSize();
3041 Disables row sizing by dragging with the mouse.
3043 Equivalent to passing @false to EnableDragRowSize().
3045 void DisableDragRowSize();
3048 Enables or disables cell dragging with the mouse.
3050 void EnableDragCell(bool enable
= true);
3053 Enables or disables column moving by dragging with the mouse.
3055 void EnableDragColMove(bool enable
= true);
3058 Enables or disables column sizing by dragging with the mouse.
3060 @see DisableColResize()
3062 void EnableDragColSize(bool enable
= true);
3065 Enables or disables row and column resizing by dragging gridlines with
3068 void EnableDragGridSize(bool enable
= true);
3071 Enables or disables row sizing by dragging with the mouse.
3073 @see DisableRowResize()
3075 void EnableDragRowSize(bool enable
= true);
3078 Returns the column ID of the specified column position.
3080 int GetColAt(int colPos
) const;
3083 Returns the position of the specified column.
3085 int GetColPos(int colID
) const;
3088 Sets the position of the specified column.
3090 void SetColPos(int colID
, int newPos
);
3093 Sets the positions of all columns at once.
3095 This method takes an array containing the indices of the columns in
3096 their display order, i.e. uses the same convention as
3097 wxHeaderCtrl::SetColumnsOrder().
3099 void SetColumnsOrder(const wxArrayInt
& order
);
3102 Resets the position of the columns to the default.
3110 @name Cursor Movement
3115 Returns the current grid cell column position.
3117 int GetGridCursorCol() const;
3120 Returns the current grid cell row position.
3122 int GetGridCursorRow() const;
3125 Make the given cell current and ensure it is visible.
3127 This method is equivalent to calling MakeCellVisible() and
3128 SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
3129 event is generated by it and the selected cell doesn't change if the
3132 void GoToCell(int row
, int col
);
3134 Make the given cell current and ensure it is visible.
3136 This method is equivalent to calling MakeCellVisible() and
3137 SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL
3138 event is generated by it and the selected cell doesn't change if the
3141 void GoToCell(const wxGridCellCoords
& coords
);
3144 Moves the grid cursor down by one row.
3146 If a block of cells was previously selected it will expand if the
3147 argument is @true or be cleared if the argument is @false.
3149 bool MoveCursorDown(bool expandSelection
);
3152 Moves the grid cursor down in the current column such that it skips to
3153 the beginning or end of a block of non-empty cells.
3155 If a block of cells was previously selected it will expand if the
3156 argument is @true or be cleared if the argument is @false.
3158 bool MoveCursorDownBlock(bool expandSelection
);
3161 Moves the grid cursor left by one column.
3163 If a block of cells was previously selected it will expand if the
3164 argument is @true or be cleared if the argument is @false.
3166 bool MoveCursorLeft(bool expandSelection
);
3169 Moves the grid cursor left in the current row such that it skips to the
3170 beginning or end of a block of non-empty cells.
3172 If a block of cells was previously selected it will expand if the
3173 argument is @true or be cleared if the argument is @false.
3175 bool MoveCursorLeftBlock(bool expandSelection
);
3178 Moves the grid cursor right by one column.
3180 If a block of cells was previously selected it will expand if the
3181 argument is @true or be cleared if the argument is @false.
3183 bool MoveCursorRight(bool expandSelection
);
3186 Moves the grid cursor right in the current row such that it skips to
3187 the beginning or end of a block of non-empty cells.
3189 If a block of cells was previously selected it will expand if the
3190 argument is @true or be cleared if the argument is @false.
3192 bool MoveCursorRightBlock(bool expandSelection
);
3195 Moves the grid cursor up by one row.
3197 If a block of cells was previously selected it will expand if the
3198 argument is @true or be cleared if the argument is @false.
3200 bool MoveCursorUp(bool expandSelection
);
3203 Moves the grid cursor up in the current column such that it skips to
3204 the beginning or end of a block of non-empty cells.
3206 If a block of cells was previously selected it will expand if the
3207 argument is @true or be cleared if the argument is @false.
3209 bool MoveCursorUpBlock(bool expandSelection
);
3212 Moves the grid cursor down by some number of rows so that the previous
3213 bottom visible row becomes the top visible row.
3215 bool MovePageDown();
3218 Moves the grid cursor up by some number of rows so that the previous
3219 top visible row becomes the bottom visible row.
3224 Set the grid cursor to the specified cell.
3226 The grid cursor indicates the current cell and can be moved by the user
3227 using the arrow keys or the mouse.
3229 Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
3230 if the event handler vetoes this event, the cursor is not moved.
3232 This function doesn't make the target call visible, use GoToCell() to
3235 void SetGridCursor(int row
, int col
);
3237 Set the grid cursor to the specified cell.
3239 The grid cursor indicates the current cell and can be moved by the user
3240 using the arrow keys or the mouse.
3242 Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and
3243 if the event handler vetoes this event, the cursor is not moved.
3245 This function doesn't make the target call visible, use GoToCell() to
3248 void SetGridCursor(const wxGridCellCoords
& coords
);
3254 @name User Selection
3259 Deselects all cells that are currently selected.
3261 void ClearSelection();
3264 Returns an array of individually selected cells.
3266 Notice that this array does @em not contain all the selected cells in
3267 general as it doesn't include the cells selected as part of column, row
3268 or block selection. You must use this method, GetSelectedCols(),
3269 GetSelectedRows() and GetSelectionBlockTopLeft() and
3270 GetSelectionBlockBottomRight() methods to obtain the entire selection
3273 Please notice this behaviour is by design and is needed in order to
3274 support grids of arbitrary size (when an entire column is selected in
3275 a grid with a million of columns, we don't want to create an array with
3276 a million of entries in this function, instead it returns an empty
3277 array and GetSelectedCols() returns an array containing one element).
3279 wxGridCellCoordsArray
GetSelectedCells() const;
3282 Returns an array of selected columns.
3284 Please notice that this method alone is not sufficient to find all the
3285 selected columns as it contains only the columns which were
3286 individually selected but not those being part of the block selection
3287 or being selected in virtue of all of their cells being selected
3288 individually, please see GetSelectedCells() for more details.
3290 wxArrayInt
GetSelectedCols() const;
3293 Returns an array of selected rows.
3295 Please notice that this method alone is not sufficient to find all the
3296 selected rows as it contains only the rows which were individually
3297 selected but not those being part of the block selection or being
3298 selected in virtue of all of their cells being selected individually,
3299 please see GetSelectedCells() for more details.
3301 wxArrayInt
GetSelectedRows() const;
3304 Returns the colour used for drawing the selection background.
3306 wxColour
GetSelectionBackground() const;
3309 Returns an array of the bottom right corners of blocks of selected
3312 Please see GetSelectedCells() for more information about the selection
3313 representation in wxGrid.
3315 @see GetSelectionBlockTopLeft()
3317 wxGridCellCoordsArray
GetSelectionBlockBottomRight() const;
3320 Returns an array of the top left corners of blocks of selected cells.
3322 Please see GetSelectedCells() for more information about the selection
3323 representation in wxGrid.
3325 @see GetSelectionBlockBottomRight()
3327 wxGridCellCoordsArray
GetSelectionBlockTopLeft() const;
3330 Returns the colour used for drawing the selection foreground.
3332 wxColour
GetSelectionForeground() const;
3335 Returns the current selection mode.
3337 @see SetSelectionMode().
3339 wxGridSelectionModes
GetSelectionMode() const;
3342 Returns @true if the given cell is selected.
3344 bool IsInSelection(int row
, int col
) const;
3346 Returns @true if the given cell is selected.
3348 bool IsInSelection(const wxGridCellCoords
& coords
) const;
3351 Returns @true if there are currently any selected cells, rows, columns
3354 bool IsSelection() const;
3357 Selects all cells in the grid.
3362 Selects a rectangular block of cells.
3364 If @a addToSelected is @false then any existing selection will be
3365 deselected; if @true the column will be added to the existing
3368 void SelectBlock(int topRow
, int leftCol
, int bottomRow
, int rightCol
,
3369 bool addToSelected
= false);
3371 Selects a rectangular block of cells.
3373 If @a addToSelected is @false then any existing selection will be
3374 deselected; if @true the column will be added to the existing
3377 void SelectBlock(const wxGridCellCoords
& topLeft
,
3378 const wxGridCellCoords
& bottomRight
,
3379 bool addToSelected
= false);
3382 Selects the specified column.
3384 If @a addToSelected is @false then any existing selection will be
3385 deselected; if @true the column will be added to the existing
3388 This method won't select anything if the current selection mode is
3391 void SelectCol(int col
, bool addToSelected
= false);
3394 Selects the specified row.
3396 If @a addToSelected is @false then any existing selection will be
3397 deselected; if @true the row will be added to the existing selection.
3399 This method won't select anything if the current selection mode is
3400 wxGridSelectColumns.
3402 void SelectRow(int row
, bool addToSelected
= false);
3405 Set the colour to be used for drawing the selection background.
3407 void SetSelectionBackground(const wxColour
& c
);
3410 Set the colour to be used for drawing the selection foreground.
3412 void SetSelectionForeground(const wxColour
& c
);
3415 Set the selection behaviour of the grid.
3417 The existing selection is converted to conform to the new mode if
3418 possible and discarded otherwise (e.g. any individual selected cells
3419 are deselected if the new mode allows only the selection of the entire
3422 void SetSelectionMode(wxGridSelectionModes selmode
);
3433 Returns the number of pixels per horizontal scroll increment.
3437 @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
3439 int GetScrollLineX() const;
3442 Returns the number of pixels per vertical scroll increment.
3446 @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
3448 int GetScrollLineY() const;
3451 Returns @true if a cell is either entirely or at least partially
3452 visible in the grid window.
3454 By default, the cell must be entirely visible for this function to
3455 return @true but if @a wholeCellVisible is @false, the function returns
3456 @true even if the cell is only partially visible.
3458 bool IsVisible(int row
, int col
, bool wholeCellVisible
= true) const;
3460 Returns @true if a cell is either entirely or at least partially
3461 visible in the grid window.
3463 By default, the cell must be entirely visible for this function to
3464 return @true but if @a wholeCellVisible is @false, the function returns
3465 @true even if the cell is only partially visible.
3467 bool IsVisible(const wxGridCellCoords
& coords
,
3468 bool wholeCellVisible
= true) const;
3471 Brings the specified cell into the visible grid cell area with minimal
3474 Does nothing if the cell is already visible.
3476 void MakeCellVisible(int row
, int col
);
3478 Brings the specified cell into the visible grid cell area with minimal
3481 Does nothing if the cell is already visible.
3483 void MakeCellVisible(const wxGridCellCoords
& coords
);
3486 Sets the number of pixels per horizontal scroll increment.
3490 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
3492 void SetScrollLineX(int x
);
3495 Sets the number of pixels per vertical scroll increment.
3499 @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
3501 void SetScrollLineY(int y
);
3507 @name Cell and Device Coordinate Translation
3512 Convert grid cell coordinates to grid window pixel coordinates.
3514 This function returns the rectangle that encloses the block of cells
3515 limited by @a topLeft and @a bottomRight cell in device coords and
3516 clipped to the client size of the grid window.
3520 wxRect
BlockToDeviceRect(const wxGridCellCoords
& topLeft
,
3521 const wxGridCellCoords
& bottomRight
) const;
3524 Return the rectangle corresponding to the grid cell's size and position
3525 in logical coordinates.
3527 @see BlockToDeviceRect()
3529 wxRect
CellToRect(int row
, int col
) const;
3531 Return the rectangle corresponding to the grid cell's size and position
3532 in logical coordinates.
3534 @see BlockToDeviceRect()
3536 wxRect
CellToRect(const wxGridCellCoords
& coords
) const;
3539 Returns the column at the given pixel position.
3542 The x position to evaluate.
3544 If @true, rather than returning @c wxNOT_FOUND, it returns either
3545 the first or last column depending on whether @a x is too far to
3546 the left or right respectively.
3548 The column index or @c wxNOT_FOUND.
3550 int XToCol(int x
, bool clipToMinMax
= false) const;
3553 Returns the column whose right hand edge is close to the given logical
3556 If no column edge is near to this position @c wxNOT_FOUND is returned.
3558 int XToEdgeOfCol(int x
) const;
3561 Translates logical pixel coordinates to the grid cell coordinates.
3563 Notice that this function expects logical coordinates on input so if
3564 you use this function in a mouse event handler you need to translate
3565 the mouse position, which is expressed in device coordinates, to
3568 @see XToCol(), YToRow()
3570 wxGridCellCoords
XYToCell(int x
, int y
) const;
3572 Translates logical pixel coordinates to the grid cell coordinates.
3574 Notice that this function expects logical coordinates on input so if
3575 you use this function in a mouse event handler you need to translate
3576 the mouse position, which is expressed in device coordinates, to
3579 @see XToCol(), YToRow()
3581 wxGridCellCoords
XYToCell(const wxPoint
& pos
) const;
3582 // XYToCell(int, int, wxGridCellCoords&) overload is intentionally
3583 // undocumented, using it is ugly and non-const reference parameters are
3584 // not used in wxWidgets API
3587 Returns the row whose bottom edge is close to the given logical @a y
3590 If no row edge is near to this position @c wxNOT_FOUND is returned.
3592 int YToEdgeOfRow(int y
) const;
3595 Returns the grid row that corresponds to the logical @a y coordinate.
3597 Returns @c wxNOT_FOUND if there is no row at the @a y position.
3599 int YToRow(int y
, bool clipToMinMax
= false) const;
3605 @name Miscellaneous Functions
3610 Appends one or more new columns to the right of the grid.
3612 The @a updateLabels argument is not used at present. If you are using a
3613 derived grid table class you will need to override
3614 wxGridTableBase::AppendCols(). See InsertCols() for further
3617 @return @true on success or @false if appending columns failed.
3619 bool AppendCols(int numCols
= 1, bool updateLabels
= true);
3622 Appends one or more new rows to the bottom of the grid.
3624 The @a updateLabels argument is not used at present. If you are using a
3625 derived grid table class you will need to override
3626 wxGridTableBase::AppendRows(). See InsertRows() for further
3629 @return @true on success or @false if appending rows failed.
3631 bool AppendRows(int numRows
= 1, bool updateLabels
= true);
3634 Return @true if the horizontal grid lines stop at the last column
3635 boundary or @false if they continue to the end of the window.
3637 The default is to clip grid lines.
3639 @see ClipHorzGridLines(), AreVertGridLinesClipped()
3641 bool AreHorzGridLinesClipped() const;
3644 Return @true if the vertical grid lines stop at the last row
3645 boundary or @false if they continue to the end of the window.
3647 The default is to clip grid lines.
3649 @see ClipVertGridLines(), AreHorzGridLinesClipped()
3651 bool AreVertGridLinesClipped() const;
3654 Increments the grid's batch count.
3656 When the count is greater than zero repainting of the grid is
3657 suppressed. Each call to BeginBatch must be matched by a later call to
3658 EndBatch(). Code that does a lot of grid modification can be enclosed
3659 between BeginBatch() and EndBatch() calls to avoid screen flicker. The
3660 final EndBatch() call will cause the grid to be repainted.
3662 Notice that you should use wxGridUpdateLocker which ensures that there
3663 is always a matching EndBatch() call for this BeginBatch() if possible
3664 instead of calling this method directly.
3669 Clears all data in the underlying grid table and repaints the grid.
3671 The table is not deleted by this function. If you are using a derived
3672 table class then you need to override wxGridTableBase::Clear() for this
3673 function to have any effect.
3678 Change whether the horizontal grid lines are clipped by the end of the
3681 By default the grid lines are not drawn beyond the end of the last
3682 column but after calling this function with @a clip set to @false they
3683 will be drawn across the entire grid window.
3685 @see AreHorzGridLinesClipped(), ClipVertGridLines()
3687 void ClipHorzGridLines(bool clip
);
3690 Change whether the vertical grid lines are clipped by the end of the
3693 By default the grid lines are not drawn beyond the end of the last
3694 row but after calling this function with @a clip set to @false they
3695 will be drawn across the entire grid window.
3697 @see AreVertGridLinesClipped(), ClipHorzGridLines()
3699 void ClipVertGridLines(bool clip
);
3702 Deletes one or more columns from a grid starting at the specified
3705 The @a updateLabels argument is not used at present. If you are using a
3706 derived grid table class you will need to override
3707 wxGridTableBase::DeleteCols(). See InsertCols() for further
3710 @return @true on success or @false if deleting columns failed.
3712 bool DeleteCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true);
3715 Deletes one or more rows from a grid starting at the specified
3718 The @a updateLabels argument is not used at present. If you are using a
3719 derived grid table class you will need to override
3720 wxGridTableBase::DeleteRows(). See InsertRows() for further
3723 @return @true on success or @false if appending rows failed.
3725 bool DeleteRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true);
3728 Decrements the grid's batch count.
3730 When the count is greater than zero repainting of the grid is
3731 suppressed. Each previous call to BeginBatch() must be matched by a
3732 later call to EndBatch(). Code that does a lot of grid modification can
3733 be enclosed between BeginBatch() and EndBatch() calls to avoid screen
3734 flicker. The final EndBatch() will cause the grid to be repainted.
3736 @see wxGridUpdateLocker
3741 Overridden wxWindow method.
3746 Causes immediate repainting of the grid.
3748 Use this instead of the usual wxWindow::Refresh().
3750 void ForceRefresh();
3753 Returns the number of times that BeginBatch() has been called without
3754 (yet) matching calls to EndBatch(). While the grid's batch count is
3755 greater than zero the display will not be updated.
3757 int GetBatchCount();
3760 Returns the total number of grid columns.
3762 This is the same as the number of columns in the underlying grid table.
3764 int GetNumberCols() const;
3767 Returns the total number of grid rows.
3769 This is the same as the number of rows in the underlying grid table.
3771 int GetNumberRows() const;
3774 Returns the attribute for the given cell creating one if necessary.
3776 If the cell already has an attribute, it is returned. Otherwise a new
3777 attribute is created, associated with the cell and returned. In any
3778 case the caller must call DecRef() on the returned pointer.
3780 This function may only be called if CanHaveAttributes() returns @true.
3782 wxGridCellAttr
*GetOrCreateCellAttr(int row
, int col
) const;
3785 Returns a base pointer to the current table object.
3787 The returned pointer is still owned by the grid.
3789 wxGridTableBase
*GetTable() const;
3792 Inserts one or more new columns into a grid with the first new column
3793 at the specified position.
3795 Notice that inserting the columns in the grid requires grid table
3796 cooperation: when this method is called, grid object begins by
3797 requesting the underlying grid table to insert new columns. If this is
3798 successful the table notifies the grid and the grid updates the
3799 display. For a default grid (one where you have called CreateGrid())
3800 this process is automatic. If you are using a custom grid table
3801 (specified with SetTable()) then you must override
3802 wxGridTableBase::InsertCols() in your derived table class.
3805 The position which the first newly inserted column will have.
3807 The number of columns to insert.
3811 @true if the columns were successfully inserted, @false if an error
3812 occurred (most likely the table couldn't be updated).
3814 bool InsertCols(int pos
= 0, int numCols
= 1, bool updateLabels
= true);
3817 Inserts one or more new rows into a grid with the first new row at the
3820 Notice that you must implement wxGridTableBase::InsertRows() if you use
3821 a grid with a custom table, please see InsertCols() for more
3825 The position which the first newly inserted row will have.
3827 The number of rows to insert.
3831 @true if the rows were successfully inserted, @false if an error
3832 occurred (most likely the table couldn't be updated).
3834 bool InsertRows(int pos
= 0, int numRows
= 1, bool updateLabels
= true);
3837 Sets the cell attributes for all cells in the specified column.
3839 For more information about controlling grid cell attributes see the
3840 wxGridCellAttr cell attribute class and the @ref overview_grid.
3842 void SetColAttr(int col
, wxGridCellAttr
* attr
);
3845 Sets the extra margins used around the grid area.
3847 A grid may occupy more space than needed for its data display and
3848 this function allows to set how big this extra space is
3850 void SetMargins(int extraWidth
, int extraHeight
);
3853 Sets the cell attributes for all cells in the specified row.
3855 The grid takes ownership of the attribute pointer.
3857 See the wxGridCellAttr class for more information about controlling
3860 void SetRowAttr(int row
, wxGridCellAttr
* attr
);
3866 @name Sorting support.
3868 wxGrid doesn't provide any support for sorting the data but it does
3869 generate events allowing the user code to sort it and supports
3870 displaying the sort indicator in the column used for sorting.
3872 To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT
3873 event (and not veto it) and resort the data displayed in the grid. The
3874 grid will automatically update the sorting indicator on the column
3877 You can also call the functions in this section directly to update the
3878 sorting indicator. Once again, they don't do anything with the grid
3879 data, it remains your responsibility to actually sort it appropriately.
3884 Return the column in which the sorting indicator is currently
3887 Returns @c wxNOT_FOUND if sorting indicator is not currently displayed
3890 @see SetSortingColumn()
3892 int GetSortingColumn() const;
3895 Return @true if this column is currently used for sorting.
3897 @see GetSortingColumn()
3899 bool IsSortingBy(int col
) const;
3902 Return @true if the current sorting order is ascending or @false if it
3905 It only makes sense to call this function if GetSortingColumn() returns
3906 a valid column index and not @c wxNOT_FOUND.
3908 @see SetSortingColumn()
3910 bool IsSortOrderAscending() const;
3913 Set the column to display the sorting indicator in and its direction.
3916 The column to display the sorting indicator in or @c wxNOT_FOUND to
3917 remove any currently displayed sorting indicator.
3919 If @true, display the ascending sort indicator, otherwise display
3920 the descending sort indicator.
3922 @see GetSortingColumn(), IsSortOrderAscending()
3924 void SetSortingColumn(int col
, bool ascending
= true);
3927 Remove any currently shown sorting indicator.
3929 This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND
3932 void UnsetSortingColumn();
3937 @name Accessors for component windows.
3939 Return the various child windows of wxGrid.
3941 wxGrid is an empty parent window for 4 children representing the column
3942 labels window (top), the row labels window (left), the corner window
3943 (top left) and the main grid window. It may be necessary to use these
3944 individual windows and not the wxGrid window itself if you need to
3945 handle events for them (this can be done using wxEvtHandler::Connect()
3946 or wxWindow::PushEventHandler()) or do something else requiring the use
3947 of the correct window pointer. Notice that you should not, however,
3948 change these windows (e.g. reposition them or draw over them) because
3949 they are managed by wxGrid itself.
3954 Return the main grid window containing the grid cells.
3956 This window is always shown.
3958 wxWindow
*GetGridWindow() const;
3961 Return the row labels window.
3963 This window is not shown if the row labels were hidden using
3966 wxWindow
*GetGridRowLabelWindow() const;
3969 Return the column labels window.
3971 This window is not shown if the columns labels were hidden using
3974 Depending on whether UseNativeColHeader() was called or not this can be
3975 either a wxHeaderCtrl or a plain wxWindow. This function returns a valid
3976 window pointer in either case but in the former case you can also use
3977 GetGridColHeader() to access it if you need wxHeaderCtrl-specific
3980 wxWindow
*GetGridColLabelWindow() const;
3983 Return the window in the top left grid corner.
3985 This window is shown only of both columns and row labels are shown and
3986 normally doesn't contain anything. Clicking on it is handled by wxGrid
3987 however and can be used to select the entire grid.
3989 wxWindow
*GetGridCornerLabelWindow() const;
3992 Return the header control used for column labels display.
3994 This function can only be called if UseNativeColHeader() had been
3997 wxHeaderCtrl
*GetGridColHeader() const;
4003 Returns @true if this grid has support for cell attributes.
4005 The grid supports attributes if it has the associated table which, in
4006 turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes()
4009 bool CanHaveAttributes() const;
4012 Get the minimal width of the given column/row.
4014 The value returned by this function may be different than that returned
4015 by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been
4016 called for this column.
4018 int GetColMinimalWidth(int col
) const;
4021 Returns the coordinate of the right border specified column.
4023 int GetColRight(int col
) const;
4026 Returns the coordinate of the left border specified column.
4028 int GetColLeft(int col
) const;
4031 Returns the minimal size for the given column.
4033 The value returned by this function may be different than that returned
4034 by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been
4035 called for this row.
4037 int GetRowMinimalHeight(int col
) const;
4043 @class wxGridUpdateLocker
4045 This small class can be used to prevent wxGrid from redrawing during its
4046 lifetime by calling wxGrid::BeginBatch() in its constructor and
4047 wxGrid::EndBatch() in its destructor. It is typically used in a function
4048 performing several operations with a grid which would otherwise result in
4049 flicker. For example:
4054 m_grid = new wxGrid(this, ...);
4056 wxGridUpdateLocker noUpdates(m_grid);
4057 m_grid-AppendColumn();
4058 // ... many other operations with m_grid ...
4061 // destructor called, grid refreshed
4065 Using this class is easier and safer than calling wxGrid::BeginBatch() and
4066 wxGrid::EndBatch() because you don't risk missing the call the latter (due
4067 to an exception for example).
4072 class wxGridUpdateLocker
4076 Creates an object preventing the updates of the specified @a grid. The
4077 parameter could be @NULL in which case nothing is done. If @a grid is
4078 non-@NULL then the grid must exist for longer than this
4079 wxGridUpdateLocker object itself.
4081 The default constructor could be followed by a call to Create() to set
4082 the grid object later.
4084 wxGridUpdateLocker(wxGrid
* grid
= NULL
);
4087 Destructor reenables updates for the grid this object is associated
4090 ~wxGridUpdateLocker();
4093 This method can be called if the object had been constructed using the
4094 default constructor. It must not be called more than once.
4096 void Create(wxGrid
* grid
);
4104 This event class contains information about various grid events.
4106 Notice that all grid event table macros are available in two versions:
4107 @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the
4108 two is that the former doesn't allow to specify the grid window identifier
4109 and so takes a single parameter, the event handler, but is not suitable if
4110 there is more than one grid control in the window where the event table is
4111 used (as it would catch the events from all the grids). The version with @c
4112 CMD takes the id as first argument and the event handler as the second one
4113 and so can be used with multiple grids as well. Otherwise there are no
4114 difference between the two and only the versions without the id are
4115 documented below for brevity.
4117 @beginEventTable{wxGridEvent}
4118 @event{EVT_GRID_CELL_CHANGING(func)}
4119 The user is about to change the data in a cell. The new cell value as
4120 string is available from GetString() event object method. This event
4121 can be vetoed if the change is not allowed.
4122 Processes a @c wxEVT_GRID_CELL_CHANGING event type.
4123 @event{EVT_GRID_CELL_CHANGED(func)}
4124 The user changed the data in a cell. The old cell value as string is
4125 available from GetString() event object method. Notice that vetoing
4126 this event still works for backwards compatibility reasons but any new
4127 code should only veto EVT_GRID_CELL_CHANGING event and not this one.
4128 Processes a @c wxEVT_GRID_CELL_CHANGED event type.
4129 @event{EVT_GRID_CELL_LEFT_CLICK(func)}
4130 The user clicked a cell with the left mouse button. Processes a
4131 @c wxEVT_GRID_CELL_LEFT_CLICK event type.
4132 @event{EVT_GRID_CELL_LEFT_DCLICK(func)}
4133 The user double-clicked a cell with the left mouse button. Processes a
4134 @c wxEVT_GRID_CELL_LEFT_DCLICK event type.
4135 @event{EVT_GRID_CELL_RIGHT_CLICK(func)}
4136 The user clicked a cell with the right mouse button. Processes a
4137 @c wxEVT_GRID_CELL_RIGHT_CLICK event type.
4138 @event{EVT_GRID_CELL_RIGHT_DCLICK(func)}
4139 The user double-clicked a cell with the right mouse button. Processes a
4140 @c wxEVT_GRID_CELL_RIGHT_DCLICK event type.
4141 @event{EVT_GRID_EDITOR_HIDDEN(func)}
4142 The editor for a cell was hidden. Processes a
4143 @c wxEVT_GRID_EDITOR_HIDDEN event type.
4144 @event{EVT_GRID_EDITOR_SHOWN(func)}
4145 The editor for a cell was shown. Processes a
4146 @c wxEVT_GRID_EDITOR_SHOWN event type.
4147 @event{EVT_GRID_LABEL_LEFT_CLICK(func)}
4148 The user clicked a label with the left mouse button. Processes a
4149 @c wxEVT_GRID_LABEL_LEFT_CLICK event type.
4150 @event{EVT_GRID_LABEL_LEFT_DCLICK(func)}
4151 The user double-clicked a label with the left mouse button. Processes a
4152 @c wxEVT_GRID_LABEL_LEFT_DCLICK event type.
4153 @event{EVT_GRID_LABEL_RIGHT_CLICK(func)}
4154 The user clicked a label with the right mouse button. Processes a
4155 @c wxEVT_GRID_LABEL_RIGHT_CLICK event type.
4156 @event{EVT_GRID_LABEL_RIGHT_DCLICK(func)}
4157 The user double-clicked a label with the right mouse button. Processes
4158 a @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type.
4159 @event{EVT_GRID_SELECT_CELL(func)}
4160 The given cell was made current, either by user or by the program via a
4161 call to SetGridCursor() or GoToCell(). Processes a
4162 @c wxEVT_GRID_SELECT_CELL event type.
4163 @event{EVT_GRID_COL_MOVE(func)}
4164 The user tries to change the order of the columns in the grid by
4165 dragging the column specified by GetCol(). This event can be vetoed to
4166 either prevent the user from reordering the column change completely
4167 (but notice that if you don't want to allow it at all, you simply
4168 shouldn't call wxGrid::EnableDragColMove() in the first place), vetoed
4169 but handled in some way in the handler, e.g. by really moving the
4170 column to the new position at the associated table level, or allowed to
4171 proceed in which case wxGrid::SetColPos() is used to reorder the
4172 columns display order without affecting the use of the column indices
4174 This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type.
4175 @event{EVT_GRID_COL_SORT(func)}
4176 This event is generated when a column is clicked by the user and its
4177 name is explained by the fact that the custom reaction to a click on a
4178 column is to sort the grid contents by this column. However the grid
4179 itself has no special support for sorting and it's up to the handler of
4180 this event to update the associated table. But if the event is handled
4181 (and not vetoed) the grid supposes that the table was indeed resorted
4182 and updates the column to indicate the new sort order and refreshes
4184 This event macro corresponds to @c wxEVT_GRID_COL_SORT event type.
4188 @category{grid,events}
4190 class wxGridEvent
: public wxNotifyEvent
4194 Default constructor.
4198 Constructor for initializing all event attributes.
4200 wxGridEvent(int id
, wxEventType type
, wxObject
* obj
,
4201 int row
= -1, int col
= -1, int x
= -1, int y
= -1,
4202 bool sel
= true, const wxKeyboardState
& kbd
= wxKeyboardState());
4205 Returns @true if the Alt key was down at the time of the event.
4207 bool AltDown() const;
4210 Returns @true if the Control key was down at the time of the event.
4212 bool ControlDown() const;
4215 Column at which the event occurred.
4217 virtual int GetCol();
4220 Position in pixels at which the event occurred.
4222 wxPoint
GetPosition();
4225 Row at which the event occurred.
4227 virtual int GetRow();
4230 Returns @true if the Meta key was down at the time of the event.
4232 bool MetaDown() const;
4235 Returns @true if the user is selecting grid cells, or @false if
4241 Returns @true if the Shift key was down at the time of the event.
4243 bool ShiftDown() const;
4249 @class wxGridSizeEvent
4251 This event class contains information about a row/column resize event.
4253 @beginEventTable{wxGridSizeEvent}
4254 @event{EVT_GRID_CMD_COL_SIZE(id, func)}
4255 The user resized a column, corresponds to @c wxEVT_GRID_COL_SIZE event
4257 @event{EVT_GRID_CMD_ROW_SIZE(id, func)}
4258 The user resized a row, corresponds to @c wxEVT_GRID_ROW_SIZE event
4260 @event{EVT_GRID_COL_SIZE(func)}
4261 Same as EVT_GRID_CMD_COL_SIZE() but uses `wxID_ANY` id.
4262 @event{EVT_GRID_ROW_SIZE(func)}
4263 Same as EVT_GRID_CMD_ROW_SIZE() but uses `wxID_ANY` id.
4267 @category{grid,events}
4269 class wxGridSizeEvent
: public wxNotifyEvent
4273 Default constructor.
4277 Constructor for initializing all event attributes.
4279 wxGridSizeEvent(int id
, wxEventType type
, wxObject
* obj
,
4280 int rowOrCol
= -1, int x
= -1, int y
= -1,
4281 const wxKeyboardState
& kbd
= wxKeyboardState());
4284 Returns @true if the Alt key was down at the time of the event.
4286 bool AltDown() const;
4289 Returns @true if the Control key was down at the time of the event.
4291 bool ControlDown() const;
4294 Position in pixels at which the event occurred.
4296 wxPoint
GetPosition();
4299 Row or column at that was resized.
4304 Returns @true if the Meta key was down at the time of the event.
4306 bool MetaDown() const;
4309 Returns @true if the Shift key was down at the time of the event.
4311 bool ShiftDown() const;
4317 @class wxGridRangeSelectEvent
4319 @beginEventTable{wxGridRangeSelectEvent}
4320 @event{EVT_GRID_RANGE_SELECT(func)}
4321 The user selected a group of contiguous cells. Processes a
4322 @c wxEVT_GRID_RANGE_SELECT event type.
4323 @event{EVT_GRID_CMD_RANGE_SELECT(id, func)}
4324 The user selected a group of contiguous cells; variant taking a window
4325 identifier. Processes a @c wxEVT_GRID_RANGE_SELECT event type.
4329 @category{grid,events}
4331 class wxGridRangeSelectEvent
: public wxNotifyEvent
4335 Default constructor.
4337 wxGridRangeSelectEvent();
4339 Constructor for initializing all event attributes.
4341 wxGridRangeSelectEvent(int id
, wxEventType type
,
4343 const wxGridCellCoords
& topLeft
,
4344 const wxGridCellCoords
& bottomRight
,
4345 bool sel
= true, const wxKeyboardState
& kbd
= wxKeyboardState());
4348 Returns @true if the Alt key was down at the time of the event.
4350 bool AltDown() const;
4353 Returns @true if the Control key was down at the time of the event.
4355 bool ControlDown() const;
4358 Top left corner of the rectangular area that was (de)selected.
4360 wxGridCellCoords
GetBottomRightCoords();
4363 Bottom row of the rectangular area that was (de)selected.
4368 Left column of the rectangular area that was (de)selected.
4373 Right column of the rectangular area that was (de)selected.
4378 Top left corner of the rectangular area that was (de)selected.
4380 wxGridCellCoords
GetTopLeftCoords();
4383 Top row of the rectangular area that was (de)selected.
4388 Returns @true if the Meta key was down at the time of the event.
4390 bool MetaDown() const;
4393 Returns @true if the area was selected, @false otherwise.
4398 Returns @true if the Shift key was down at the time of the event.
4400 bool ShiftDown() const;
4406 @class wxGridEditorCreatedEvent
4408 @beginEventTable{wxGridEditorCreatedEvent}
4409 @event{EVT_GRID_EDITOR_CREATED(func)}
4410 The editor for a cell was created. Processes a
4411 @c wxEVT_GRID_EDITOR_CREATED event type.
4412 @event{EVT_GRID_CMD_EDITOR_CREATED(id, func)}
4413 The editor for a cell was created; variant taking a window identifier.
4414 Processes a @c wxEVT_GRID_EDITOR_CREATED event type.
4418 @category{grid,events}
4420 class wxGridEditorCreatedEvent
: public wxCommandEvent
4424 Default constructor.
4426 wxGridEditorCreatedEvent();
4428 Constructor for initializing all event attributes.
4430 wxGridEditorCreatedEvent(int id
, wxEventType type
, wxObject
* obj
,
4431 int row
, int col
, wxControl
* ctrl
);
4434 Returns the column at which the event occurred.
4439 Returns the edit control.
4441 wxControl
* GetControl();
4444 Returns the row at which the event occurred.
4449 Sets the column at which the event occurred.
4451 void SetCol(int col
);
4454 Sets the edit control.
4456 void SetControl(wxControl
* ctrl
);
4459 Sets the row at which the event occurred.
4461 void SetRow(int row
);