/**
Fetch the value from the table and prepare the edit control to begin
- editing. Sets the focus to the edit control.
+ editing.
+
+ This function should save the original value of the grid cell at the
+ given @a row and @a col and show the control allowing the user to
+ change it.
+
+ @see EndEdit()
*/
virtual void BeginEdit(int row, int col, wxGrid* grid) = 0;
virtual void Destroy();
/**
- Complete the editing of the current cell. If necessary, the control may
- be destroyed.
+ End editing the cell.
- @return @true if the value has changed.
+ This function must check if the current value of the editing control is
+ valid and different from the original value (available as @a oldval in
+ its string form and possibly saved internally using its real type by
+ BeginEdit()). If it isn't, it just returns @false, otherwise it fills
+ @a newval with the representation of the new value in the string form,
+ if necessary saves it using its real type internally, and returns @true.
+
+ If the user-defined wxEVT_GRID_CELL_CHANGING event handler doesn't veto
+ this change, ApplyEdit() will be called next.
*/
- virtual bool EndEdit(int row, int col, wxGrid* grid) = 0;
+ virtual bool EndEdit(const wxString& oldval, wxString* newval) = 0;
+
+ /**
+ Effectively save the changes in the grid.
+
+ This function should save the value of the control in the grid. It is
+ called only after EndEdit() returns @true.
+ */
+ virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0;
/**
Some types of controls on some platforms may need some help with the
an empty string otherwise.
*/
static void UseStringValues(const wxString& valueTrue = "1",
- const wxString& valueFalse = wxEmptyString) const;
+ const wxString& valueFalse = wxEmptyString);
};
/**
/**
Default constructor.
*/
- wxGridCellAttr();
+ wxGridCellAttr(wxGridCellAttr* attrDefault = NULL);
/**
Constructor specifying some of the often used attributes.
*/
- wxGridCellFloatEditor
- wxGridCellNumberEditor
- wxGridCellTextEditor
-
+
Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and
wxGridEditorCreatedEvent for the documentation of all event types you can
use with wxGrid.
See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for
more information.
*/
- const wxString GetCellValue(const wxGridCellCoords& coords) const;
+ wxString GetCellValue(const wxGridCellCoords& coords) const;
/**
Returns a pointer to the current default grid cell editor.
*/
int GetColSize(int col) const;
+ /**
+ Returns @true if the specified column is not currently hidden.
+ */
+ bool IsColShown(int col) const;
+
/**
Returns the default height for column labels.
*/
*/
int GetRowSize(int row) const;
+ /**
+ Returns @true if the specified row is not currently hidden.
+ */
+ bool IsRowShown(int row) const;
+
/**
Sets the height of the column labels.
/**
Sets the width of the specified column.
- Notice that this function does not refresh the grid, you need to call
- ForceRefresh() to make the changes take effect immediately.
-
@param col
The column index.
@param width
- The new column width in pixels or a negative value to fit the
- column width to its label width.
+ The new column width in pixels, 0 to hide the column or -1 to fit
+ the column width to its label width.
*/
void SetColSize(int col, int width);
+ /**
+ Hides the specified column.
+
+ To show the column later you need to call SetColSize() with non-0
+ width or ShowCol().
+
+ @param col
+ The column index.
+ */
+ void HideCol(int col);
+
+ /**
+ Shows the previously hidden column by resizing it to non-0 size.
+
+ @see HideCol(), SetColSize()
+ */
+ void ShowCol(int col);
+
+
/**
Sets the default width for columns in the grid.
*/
void SetRowSize(int row, int height);
+ /**
+ Hides the specified row.
+
+ To show the row later you need to call SetRowSize() with non-0
+ width or ShowRow().
+
+ @param col
+ The row index.
+ */
+ void HideRow(int col);
+
+ /**
+ Shows the previously hidden row by resizing it to non-0 size.
+
+ @see HideRow(), SetRowSize()
+ */
+ void ShowRow(int col);
+
//@}
*/
void SetColPos(int colID, int newPos);
+ /**
+ Sets the positions of all columns at once.
+
+ This method takes an array containing the indices of the columns in
+ their display order, i.e. uses the same convention as
+ wxHeaderCtrl::SetColumnsOrder().
+ */
+ void SetColumnsOrder(const wxArrayInt& order);
+
+ /**
+ Resets the position of the columns to the default.
+ */
+ void ResetColPos();
+
//@}
/**
@name Cursor Movement
- */
+ */
//@{
/**
@see BlockToDeviceRect()
*/
- const wxRect CellToRect(const wxGridCellCoords& coords) const;
+ wxRect CellToRect(const wxGridCellCoords& coords) const;
/**
Returns the column at the given pixel position.
//@}
+
+ /**
+ @name Sorting support.
+
+ wxGrid doesn't provide any support for sorting the data but it does
+ generate events allowing the user code to sort it and supports
+ displaying the sort indicator in the column used for sorting.
+
+ To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT
+ event (and not veto it) and resort the data displayed in the grid. The
+ grid will automatically update the sorting indicator on the column
+ which was clicked.
+
+ You can also call the functions in this section directly to update the
+ sorting indicator. Once again, they don't do anything with the grid
+ data, it remains your responsibility to actually sort it appropriately.
+ */
+ //@{
+
+ /**
+ Return the column in which the sorting indicator is currently
+ displayed.
+
+ Returns @c wxNOT_FOUND if sorting indicator is not currently displayed
+ at all.
+
+ @see SetSortingColumn()
+ */
+ int GetSortingColumn() const;
+
+ /**
+ Return @true if this column is currently used for sorting.
+
+ @see GetSortingColumn()
+ */
+ bool IsSortingBy(int col) const;
+
+ /**
+ Return @true if the current sorting order is ascending or @false if it
+ is descending.
+
+ It only makes sense to call this function if GetSortingColumn() returns
+ a valid column index and not @c wxNOT_FOUND.
+
+ @see SetSortingColumn()
+ */
+ bool IsSortOrderAscending() const;
+
+ /**
+ Set the column to display the sorting indicator in and its direction.
+
+ @param col
+ The column to display the sorting indicator in or @c wxNOT_FOUND to
+ remove any currently displayed sorting indicator.
+ @param ascending
+ If @true, display the ascending sort indicator, otherwise display
+ the descending sort indicator.
+
+ @see GetSortingColumn(), IsSortOrderAscending()
+ */
+ void SetSortingColumn(int col, bool ascending = true);
+
+ /**
+ Remove any currently shown sorting indicator.
+
+ This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND
+ first argument.
+ */
+ void UnsetSortingColumn();
+ //@}
+
+
+ /**
+ @name Accessors for component windows.
+
+ Return the various child windows of wxGrid.
+
+ wxGrid is an empty parent window for 4 children representing the column
+ labels window (top), the row labels window (left), the corner window
+ (top left) and the main grid window. It may be necessary to use these
+ individual windows and not the wxGrid window itself if you need to
+ handle events for them (this can be done using wxEvtHandler::Connect()
+ or wxWindow::PushEventHandler()) or do something else requiring the use
+ of the correct window pointer. Notice that you should not, however,
+ change these windows (e.g. reposition them or draw over them) because
+ they are managed by wxGrid itself.
+ */
+ //@{
+
+ /**
+ Return the main grid window containing the grid cells.
+
+ This window is always shown.
+ */
+ wxWindow *GetGridWindow() const;
+
+ /**
+ Return the row labels window.
+
+ This window is not shown if the row labels were hidden using
+ HideRowLabels().
+ */
+ wxWindow *GetGridRowLabelWindow() const;
+
+ /**
+ Return the column labels window.
+
+ This window is not shown if the columns labels were hidden using
+ HideColLabels().
+
+ Depending on whether UseNativeColHeader() was called or not this can be
+ either a wxHeaderCtrl or a plain wxWindow. This function returns a valid
+ window pointer in either case but in the former case you can also use
+ GetGridColHeader() to access it if you need wxHeaderCtrl-specific
+ functionality.
+ */
+ wxWindow *GetGridColLabelWindow() const;
+
+ /**
+ Return the window in the top left grid corner.
+
+ This window is shown only of both columns and row labels are shown and
+ normally doesn't contain anything. Clicking on it is handled by wxGrid
+ however and can be used to select the entire grid.
+ */
+ wxWindow *GetGridCornerLabelWindow() const;
+
+ /**
+ Return the header control used for column labels display.
+
+ This function can only be called if UseNativeColHeader() had been
+ called.
+ */
+ wxHeaderCtrl *GetGridColHeader() const;
+
+ //@}
+
protected:
/**
Returns @true if this grid has support for cell attributes.
This event class contains information about various grid events.
+ Notice that all grid event table macros are available in two versions:
+ @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the
+ two is that the former doesn't allow to specify the grid window identifier
+ and so takes a single parameter, the event handler, but is not suitable if
+ there is more than one grid control in the window where the event table is
+ used (as it would catch the events from all the grids). The version with @c
+ CMD takes the id as first argument and the event handler as the second one
+ and so can be used with multiple grids as well. Otherwise there are no
+ difference between the two and only the versions without the id are
+ documented below for brevity.
+
@beginEventTable{wxGridEvent}
- @event{EVT_GRID_CELL_CHANGE(func)}
- The user changed the data in a cell. Processes a
- @c wxEVT_GRID_CELL_CHANGE event type.
+ @event{EVT_GRID_CELL_CHANGING(func)}
+ The user is about to change the data in a cell. The new cell value as
+ string is available from GetString() event object method. This event
+ can be vetoed if the change is not allowed.
+ Processes a @c wxEVT_GRID_CELL_CHANGING event type.
+ @event{EVT_GRID_CELL_CHANGED(func)}
+ The user changed the data in a cell. The old cell value as string is
+ available from GetString() event object method. Notice that vetoing
+ this event still works for backwards compatibility reasons but any new
+ code should only veto EVT_GRID_CELL_CHANGING event and not this one.
+ Processes a @c wxEVT_GRID_CELL_CHANGED event type.
@event{EVT_GRID_CELL_LEFT_CLICK(func)}
The user clicked a cell with the left mouse button. Processes a
@c wxEVT_GRID_CELL_LEFT_CLICK event type.
columns display order without affecting the use of the column indices
otherwise.
This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type.
- @event{EVT_GRID_CMD_CELL_CHANGE(id, func)}
- The user changed the data in a cell; variant taking a window
- identifier. Processes a @c wxEVT_GRID_CELL_CHANGE event type.
- @event{EVT_GRID_CMD_CELL_LEFT_CLICK(id, func)}
- The user clicked a cell with the left mouse button; variant taking a
- window identifier. Processes a @c wxEVT_GRID_CELL_LEFT_CLICK event
- type.
- @event{EVT_GRID_CMD_CELL_LEFT_DCLICK(id, func)}
- The user double-clicked a cell with the left mouse button; variant
- taking a window identifier. Processes a @c wxEVT_GRID_CELL_LEFT_DCLICK
- event type.
- @event{EVT_GRID_CMD_CELL_RIGHT_CLICK(id, func)}
- The user clicked a cell with the right mouse button; variant taking a
- window identifier. Processes a @c wxEVT_GRID_CELL_RIGHT_CLICK event
- type.
- @event{EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, func)}
- The user double-clicked a cell with the right mouse button; variant
- taking a window identifier. Processes a @c wxEVT_GRID_CELL_RIGHT_DCLICK
- event type.
- @event{EVT_GRID_CMD_EDITOR_HIDDEN(id, func)}
- The editor for a cell was hidden; variant taking a window identifier.
- Processes a @c wxEVT_GRID_EDITOR_HIDDEN event type.
- @event{EVT_GRID_CMD_EDITOR_SHOWN(id, func)}
- The editor for a cell was shown; variant taking a window identifier.
- Processes a @c wxEVT_GRID_EDITOR_SHOWN event type.
- @event{EVT_GRID_CMD_LABEL_LEFT_CLICK(id, func)}
- The user clicked a label with the left mouse button; variant taking a
- window identifier. Processes a @c wxEVT_GRID_LABEL_LEFT_CLICK event
- type.
- @event{EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, func)}
- The user double-clicked a label with the left mouse button; variant
- taking a window identifier. Processes a @c wxEVT_GRID_LABEL_LEFT_DCLICK
- event type.
- @event{EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, func)}
- The user clicked a label with the right mouse button; variant taking a
- window identifier. Processes a @c wxEVT_GRID_LABEL_RIGHT_CLICK event
- type.
- @event{EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, func)}
- The user double-clicked a label with the right mouse button; variant
- taking a window identifier. Processes a
- @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type.
- @event{EVT_GRID_CMD_SELECT_CELL(id, func)}
- The user moved to, and selected a cell; variant taking a window
- identifier. Processes a @c wxEVT_GRID_SELECT_CELL event type.
+ @event{EVT_GRID_COL_SORT(func)}
+ This event is generated when a column is clicked by the user and its
+ name is explained by the fact that the custom reaction to a click on a
+ column is to sort the grid contents by this column. However the grid
+ itself has no special support for sorting and it's up to the handler of
+ this event to update the associated table. But if the event is handled
+ (and not vetoed) the grid supposes that the table was indeed resorted
+ and updates the column to indicate the new sort order and refreshes
+ itself.
+ This event macro corresponds to @c wxEVT_GRID_COL_SORT event type.
@endEventTable
@library{wxadv}
- @category{grid}
+ @category{grid,events}
*/
class wxGridEvent : public wxNotifyEvent
{
*/
wxGridEvent(int id, wxEventType type, wxObject* obj,
int row = -1, int col = -1, int x = -1, int y = -1,
- bool sel = true, bool control = false, bool shift = false,
- bool alt = false, bool meta = false);
+ bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
/**
Returns @true if the Alt key was down at the time of the event.
@endEventTable
@library{wxadv}
- @category{grid}
+ @category{grid,events}
*/
class wxGridSizeEvent : public wxNotifyEvent
{
*/
wxGridSizeEvent(int id, wxEventType type, wxObject* obj,
int rowOrCol = -1, int x = -1, int y = -1,
- bool control = false, bool shift = false,
- bool alt = false, bool meta = false);
+ const wxKeyboardState& kbd = wxKeyboardState());
/**
Returns @true if the Alt key was down at the time of the event.
@endEventTable
@library{wxadv}
- @category{grid}
+ @category{grid,events}
*/
class wxGridRangeSelectEvent : public wxNotifyEvent
{
wxObject* obj,
const wxGridCellCoords& topLeft,
const wxGridCellCoords& bottomRight,
- bool sel = true, bool control = false,
- bool shift = false, bool alt = false,
- bool meta = false);
+ bool sel = true, const wxKeyboardState& kbd = wxKeyboardState());
/**
Returns @true if the Alt key was down at the time of the event.
@endEventTable
@library{wxadv}
- @category{grid}
+ @category{grid,events}
*/
class wxGridEditorCreatedEvent : public wxCommandEvent
{