From: Bryan Petty Date: Mon, 24 Nov 2008 07:07:31 +0000 (+0000) Subject: Reviewed, and re-organized members of wxGrid, which now makes the interface header... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/caac7804114079a6ab0dcf1a6c15f9fd8340e4a0 Reviewed, and re-organized members of wxGrid, which now makes the interface header manual reviews finally finished. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 3d6f26a5f9..057ef18b7f 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -1008,51 +1008,54 @@ public: @class wxGrid wxGrid and its related classes are used for displaying and editing tabular - data. - They provide a rich set of features for display, editing, and interacting - with a variety of data sources. For simple applications, and to help you - get started, wxGrid is the only class you need to refer to directly. It - will set up default instances of the other classes and manage them for you. - For more complex applications you can derive your own classes for custom - grid views, grid data tables, cell editors and renderers. The @ref - overview_grid "wxGrid overview" has examples of simple and more complex applications, + data. They provide a rich set of features for display, editing, and + interacting with a variety of data sources. For simple applications, and to + help you get started, wxGrid is the only class you need to refer to + directly. It will set up default instances of the other classes and manage + them for you. For more complex applications you can derive your own classes + for custom grid views, grid data tables, cell editors and renderers. The + @ref overview_grid has examples of simple and more complex applications, explains the relationship between the various grid classes and has a summary of the keyboard shortcuts and mouse functions provided by wxGrid. - wxGrid has been greatly expanded and redesigned for wxWidgets 2.2 onwards. - The new grid classes are reasonably backward-compatible but there are some - exceptions. There are also easier ways of doing many things compared to the - previous implementation. - A wxGridTableBase class holds the actual data to be displayed by a wxGrid class. One or more wxGrid classes may act as a view for one table class. The default table class is called wxGridStringTable and holds an array of - strings. An instance of such a class is created by wxGrid::CreateGrid. + strings. An instance of such a class is created by CreateGrid(). wxGridCellRenderer is the abstract base class for rendereing contents in a cell. The following renderers are predefined: - - wxGridCellStringRenderer, - - wxGridCellBoolRenderer, - - wxGridCellFloatRenderer, - - wxGridCellNumberRenderer. + + - wxGridCellBoolRenderer + - wxGridCellFloatRenderer + - wxGridCellNumberRenderer + - wxGridCellStringRenderer + The look of a cell can be further defined using wxGridCellAttr. An object - of this type may be returned by wxGridTableBase::GetAttr. + of this type may be returned by wxGridTableBase::GetAttr(). wxGridCellEditor is the abstract base class for editing the value of a cell. The following editors are predefined: - - wxGridCellTextEditor - - wxGridCellBoolEditor - - wxGridCellChoiceEditor - - wxGridCellNumberEditor. + + - wxGridCellBoolEditor + - wxGridCellChoiceEditor + - wxGridCellFloatEditor + - wxGridCellNumberEditor + - wxGridCellTextEditor + + Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and + wxGridEditorCreatedEvent for the documentation of all event types you can + use with wxGrid. @library{wxadv} @category{grid} - @see @ref overview_grid "wxGrid overview" + @see @ref overview_grid, wxGridUpdateLocker */ class wxGrid : public wxScrolledWindow { public: + /** Different selection modes supported by the grid. */ @@ -1079,6 +1082,12 @@ public: wxGridSelectColumns }; + + /** + @name Constructors and Initialization + */ + //@{ + /** Default constructor. @@ -1086,20 +1095,27 @@ public: CreateGrid() or SetTable() to initialize the grid contents. */ wxGrid(); - /** Constructor creating the grid window. You must call either CreateGrid() or SetTable() to initialize the grid contents before using it. */ - wxGrid(wxWindow* parent, - wxWindowID id, + wxGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr); + /** + Destructor. + + This will also destroy the associated grid table unless you passed a + table object to the grid and specified that the grid should not take + ownership of the table (see SetTable()). + */ + virtual ~wxGrid(); + /** Creates the grid window for an object initialized using the default constructor. @@ -1107,427 +1123,482 @@ public: You must call either CreateGrid() or SetTable() to initialize the grid contents before using it. */ - bool Create(wxWindow* parent, - wxWindowID id, + bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr); /** - Destructor. + Creates a grid with the specified initial number of rows and columns. - This will also destroy the associated grid table unless you passed a - table object to the grid and specified that the grid should not take - ownership of the table (see wxGrid::SetTable). + Call this directly after the grid constructor. When you use this + function wxGrid will create and manage a simple table of string values + for you. All of the grid data will be stored in memory. + + For applications with more complex data types or relationships, or for + dealing with very large datasets, you should derive your own grid table + class and pass a table object to the grid with SetTable(). */ - virtual ~wxGrid(); + bool CreateGrid(int numRows, int numCols, + wxGridSelectionModes selmode = wxGridSelectCells); /** - Appends one or more new columns to the right of the grid. + Passes a pointer to a custom grid table to be used by the grid. - The @a updateLabels argument is not used at present. If you are using a - derived grid table class you will need to override - wxGridTableBase::AppendCols. See InsertCols() for further information. + This should be called after the grid constructor and before using the + grid object. If @a takeOwnership is set to @true then the table will be + deleted by the wxGrid destructor. - @return @true on success or @false if appending columns failed. + Use this function instead of CreateGrid() when your application + involves complex or non-string data or data sets that are too large to + fit wholly in memory. */ - bool AppendCols(int numCols = 1, bool updateLabels = true); + bool SetTable(wxGridTableBase* table, bool takeOwnership = false, + wxGridSelectionModes selmode = wxGridSelectCells); - /** - Appends one or more new rows to the bottom of the grid. + //@} - The @a updateLabels argument is not used at present. If you are using a - derived grid table class you will need to override - wxGridTableBase::AppendRows. See InsertRows() for further information. - @return @true on success or @false if appending rows failed. + /** + @name Grid Line Formatting + */ + //@{ + + /** + Turns the drawing of grid lines on or off. */ - bool AppendRows(int numRows = 1, bool updateLabels = true); + void EnableGridLines(bool enable = true); /** - Return @true if the horizontal grid lines stop at the last column - boundary or @false if they continue to the end of the window. + Returns the pen used for vertical grid lines. - The default is to clip grid lines. + This virtual function may be overridden in derived classes in order to + change the appearance of individual grid lines for the given column + @a col. - @see ClipHorzGridLines(), AreVertGridLinesClipped() - */ - bool AreHorzGridLinesClipped() const; + See GetRowGridLinePen() for an example. + */ + virtual wxPen GetColGridLinePen(int col); /** - Return @true if the vertical grid lines stop at the last row - boundary or @false if they continue to the end of the window. + Returns the pen used for grid lines. - The default is to clip grid lines. + This virtual function may be overridden in derived classes in order to + change the appearance of grid lines. Note that currently the pen width + must be 1. - @see ClipVertGridLines(), AreHorzGridLinesClipped() - */ - bool AreVertGridLinesClipped() const; + @see GetColGridLinePen(), GetRowGridLinePen() + */ + virtual wxPen GetDefaultGridLinePen(); /** - Automatically sets the height and width of all rows and columns to fit their - contents. + Returns the colour used for grid lines. + + @see GetDefaultGridLinePen() */ - void AutoSize(); + wxColour GetGridLineColour() const; /** - Automatically adjusts width of the column to fit its label. + Returns the pen used for horizontal grid lines. + + This virtual function may be overridden in derived classes in order to + change the appearance of individual grid line for the given @a row. + + Example: + @code + // in a grid displaying music notation, use a solid black pen between + // octaves (C0=row 127, C1=row 115 etc.) + wxPen MidiGrid::GetRowGridLinePen(int row) + { + if ( row % 12 == 7 ) + return wxPen(*wxBLACK, 1, wxSOLID); + else + return GetDefaultGridLinePen(); + } + @endcode */ - void AutoSizeColLabelSize(int col); + virtual wxPen GetRowGridLinePen(int row); /** - Automatically sizes the column to fit its contents. If setAsMin is @true the - calculated width will - also be set as the minimal width for the column. + Returns @true if drawing of grid lines is turned on, @false otherwise. */ - void AutoSizeColumn(int col, bool setAsMin = true); + bool GridLinesEnabled() const; /** - Automatically sizes all columns to fit their contents. If setAsMin is @true the - calculated widths will - also be set as the minimal widths for the columns. + Sets the colour used to draw grid lines. */ - void AutoSizeColumns(bool setAsMin = true); + void SetGridLineColour(const wxColour& colour); + + //@} + /** - Automatically sizes the row to fit its contents. If setAsMin is @true the - calculated height will - also be set as the minimal height for the row. - */ - void AutoSizeRow(int row, bool setAsMin = true); + @name Label Values and Formatting + */ + //@{ /** - Automatically adjusts height of the row to fit its label. + Sets the arguments to the current column label alignment values. + + Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE + or @c wxALIGN_RIGHT. + + Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or + @c wxALIGN_BOTTOM. */ - void AutoSizeRowLabelSize(int col); + void GetColLabelAlignment(int* horiz, int* vert) const; /** - Automatically sizes all rows to fit their contents. If setAsMin is @true the - calculated heights will - also be set as the minimal heights for the rows. + Returns the orientation of the column labels (either @c wxHORIZONTAL or + @c wxVERTICAL). */ - void AutoSizeRows(bool setAsMin = true); + int GetColLabelTextOrientation() const; /** - Increments the grid's batch count. - - When the count is greater than zero repainting of the grid is - suppressed. Each call to BeginBatch must be matched by a later call to - EndBatch(). Code that does a lot of grid modification can be enclosed - between BeginBatch and EndBatch calls to avoid screen flicker. The - final EndBatch will cause the grid to be repainted. + Returns the specified column label. - Notice that you should use wxGridUpdateLocker which ensures that there - is always a matching EndBatch() call for this BeginBatch() if possible - instead of calling this method directly. + The default grid table class provides column labels of the form + A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can + override wxGridTableBase::GetColLabelValue() to provide your own + labels. */ - void BeginBatch(); + wxString GetColLabelValue(int col) const; /** - Convert grid cell coordinates to grid window pixel coordinates. + Returns the colour used for the background of row and column labels. + */ + wxColour GetLabelBackgroundColour() const; - This function returns the rectangle that encloses the block of cells - limited by @a topLeft and @a bottomRight cell in device coords and - clipped to the client size of the grid window. + /** + Returns the font used for row and column labels. + */ + wxFont GetLabelFont() const; - @see CellToRect() + /** + Returns the colour used for row and column label text. */ - wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft, - const wxGridCellCoords& bottomRight) const; + wxColour GetLabelTextColour() const; /** - Returns @true if columns can be moved by dragging with the mouse. + Returns the alignment used for row labels. - Columns can be moved by dragging on their labels. + Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE + or @c wxALIGN_RIGHT. + + Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or + @c wxALIGN_BOTTOM. */ - bool CanDragColMove() const; + void GetRowLabelAlignment(int* horiz, int* vert) const; /** - Returns @true if columns can be resized by dragging with the mouse. + Returns the specified row label. - Columns can be resized by dragging the edges of their labels. If grid - line dragging is enabled they can also be resized by dragging the right - edge of the column in the grid cell area (see - wxGrid::EnableDragGridSize). + The default grid table class provides numeric row labels. If you are + using a custom grid table you can override + wxGridTableBase::GetRowLabelValue() to provide your own labels. */ - bool CanDragColSize() const; + wxString GetRowLabelValue(int row) const; /** - Return @true if the dragging of grid lines to resize rows and columns - is enabled or @false otherwise. + Hides the column labels by calling SetColLabelSize() with a size of 0. + Show labels again by calling that method with a width greater than 0. */ - bool CanDragGridSize() const; + void HideColLabels(); /** - Returns @true if rows can be resized by dragging with the mouse. + Hides the row labels by calling SetRowLabelSize() with a size of 0. - Rows can be resized by dragging the edges of their labels. If grid line - dragging is enabled they can also be resized by dragging the lower edge - of the row in the grid cell area (see wxGrid::EnableDragGridSize). + The labels can be shown again by calling SetRowLabelSize() with a width + greater than 0. */ - bool CanDragRowSize() const; + void HideRowLabels(); /** - Returns @true if the in-place edit control for the current grid cell - can be used and @false otherwise. + Sets the horizontal and vertical alignment of column label text. - This function always returns @false for the read-only cells. + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one + of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. */ - bool CanEnableCellControl() const; + void SetColLabelAlignment(int horiz, int vert); - //@{ /** - Return the rectangle corresponding to the grid cell's size and position - in logical coordinates. - - @see BlockToDeviceRect() + Sets the orientation of the column labels (either @c wxHORIZONTAL or + @c wxVERTICAL). */ - wxRect CellToRect(int row, int col) const; - const wxRect CellToRect(const wxGridCellCoords& coords) const; - - //@} + void SetColLabelTextOrientation(int textOrientation); /** - Clears all data in the underlying grid table and repaints the grid. + Set the value for the given column label. - The table is not deleted by this function. If you are using a derived - table class then you need to override wxGridTableBase::Clear() for this - function to have any effect. + If you are using a custom grid table you must override + wxGridTableBase::SetColLabelValue() for this to have any effect. */ - void ClearGrid(); + void SetColLabelValue(int col, const wxString& value); /** - Deselects all cells that are currently selected. + Sets the background colour for row and column labels. */ - void ClearSelection(); + void SetLabelBackgroundColour(const wxColour& colour); /** - Change whether the horizontal grid lines are clipped by the end of the - last column. - - By default the grid lines are not drawn beyond the end of the last - column but after calling this function with @a clip set to @false they - will be drawn across the entire grid window. - - @see AreHorzGridLinesClipped(), ClipVertGridLines() - */ - void ClipHorzGridLines(bool clip); + Sets the font for row and column labels. + */ + void SetLabelFont(const wxFont& font); /** - Change whether the vertical grid lines are clipped by the end of the - last row. - - By default the grid lines are not drawn beyond the end of the last - row but after calling this function with @a clip set to @false they - will be drawn across the entire grid window. - - @see AreVertzGridLinesClipped(), ClipHorzGridLines() - */ - void ClipVertzGridLines(bool clip); + Sets the colour for row and column label text. + */ + void SetLabelTextColour(const wxColour& colour); /** - Creates a grid with the specified initial number of rows and columns. + Sets the horizontal and vertical alignment of row label text. - Call this directly after the grid constructor. When you use this - function wxGrid will create and manage a simple table of string values - for you. All of the grid data will be stored in memory. - For applications with more complex data types or relationships, or for - dealing with very large datasets, you should derive your own grid table - class and pass a table object to the grid with SetTable(). + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one + of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. */ - bool CreateGrid(int numRows, int numCols, - wxGridSelectionModes selmode = wxGridSelectCells); + void SetRowLabelAlignment(int horiz, int vert); /** - Deletes one or more columns from a grid starting at the specified - position. - - The @a updateLabels argument is not used at present. If you are using a - derived grid table class you will need to override - wxGridTableBase::DeleteCols. See InsertCols() for further information. + Sets the value for the given row label. - @return @true on success or @false if deleting columns failed. + If you are using a derived grid table you must override + wxGridTableBase::SetRowLabelValue() for this to have any effect. */ - bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true); + void SetRowLabelValue(int row, const wxString& value); /** - Deletes one or more rows from a grid starting at the specified position. + Call this in order to make the column labels use a native look by using + wxRenderer::DrawHeaderButton() internally. - The @a updateLabels argument is not used at present. If you are using a - derived grid table class you will need to override - wxGridTableBase::DeleteRows. See InsertRows() for further information. - - @return @true on success or @false if appending rows failed. + There is no equivalent method for drawing row columns as there is not + native look for that. This option is useful when using wxGrid for + displaying tables and not as a spread-sheet. */ - bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true); + void SetUseNativeColLabels(bool native = true); - /** - Disables in-place editing of grid cells. + //@} - Equivalent to calling EnableCellEditControl(@false). - */ - void DisableCellEditControl(); /** - Disables column moving by dragging with the mouse. + @name Cell Formatting - Equivalent to passing @false to EnableDragColMove(). - */ - void DisableDragColMove(); + Note that wxGridCellAttr can be used alternatively to most of these + methods. See the "Attributes Management" of wxGridTableBase. + */ + //@{ /** - Disables column sizing by dragging with the mouse. + Sets the arguments to the horizontal and vertical text alignment values + for the grid cell at the specified location. - Equivalent to passing @false to EnableDragColSize(). + Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE + or @c wxALIGN_RIGHT. + + Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or + @c wxALIGN_BOTTOM. */ - void DisableDragColSize(); + void GetCellAlignment(int row, int col, int* horiz, int* vert) const; /** - Disable mouse dragging of grid lines to resize rows and columns. - - Equivalent to passing @false to EnableDragGridSize() + Returns the background colour of the cell at the specified location. */ - void DisableDragGridSize(); + wxColour GetCellBackgroundColour(int row, int col) const; /** - Disables row sizing by dragging with the mouse. + Returns the font for text in the grid cell at the specified location. + */ + wxFont GetCellFont(int row, int col) const; - Equivalent to passing @false to EnableDragRowSize(). + /** + Returns the text colour for the grid cell at the specified location. */ - void DisableDragRowSize(); + wxColour GetCellTextColour(int row, int col) const; /** - Enables or disables in-place editing of grid cell data. + Returns the default cell alignment. + + Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE + or @c wxALIGN_RIGHT. - The grid will issue either a wxEVT_GRID_EDITOR_SHOWN or - wxEVT_GRID_EDITOR_HIDDEN event. + Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or + @c wxALIGN_BOTTOM. + + @see SetDefaultCellAlignment() */ - void EnableCellEditControl(bool enable = true); + void GetDefaultCellAlignment(int* horiz, int* vert) const; /** - Enables or disables column moving by dragging with the mouse. + Returns the current default background colour for grid cells. */ - void EnableDragColMove(bool enable = true); + wxColour GetDefaultCellBackgroundColour() const; /** - Enables or disables column sizing by dragging with the mouse. + Returns the current default font for grid cell text. */ - void EnableDragColSize(bool enable = true); + wxFont GetDefaultCellFont() const; /** - Enables or disables row and column resizing by dragging gridlines with the - mouse. + Returns the current default colour for grid cell text. */ - void EnableDragGridSize(bool enable = true); + wxColour GetDefaultCellTextColour() const; /** - Enables or disables row sizing by dragging with the mouse. - */ - void EnableDragRowSize(bool enable = true); + Sets the horizontal and vertical alignment for grid cell text at the + specified location. + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. + + Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE + or @c wxALIGN_BOTTOM. + */ + void SetCellAlignment(int row, int col, int horiz, int vert); /** - Makes the grid globally editable or read-only. + Sets the horizontal and vertical alignment for grid cell text at the + specified location. - If the edit argument is @false this function sets the whole grid as - read-only. If the argument is @true the grid is set to the default - state where cells may be editable. In the default state you can set - single grid cells and whole rows and columns to be editable or - read-only via wxGridCellAttribute::SetReadOnly. For single cells you - can also use the shortcut function SetReadOnly(). + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. - For more information about controlling grid cell attributes see the - wxGridCellAttr cell attribute class and the - @ref overview_grid "wxGrid overview". + Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE + or @c wxALIGN_BOTTOM. */ - void EnableEditing(bool edit); + void SetCellAlignment(int align, int row, int col); /** - Turns the drawing of grid lines on or off. + Set the background colour for the given cell or all cells by default. */ - void EnableGridLines(bool enable = true); + void SetCellBackgroundColour(int row, int col, const wxColour& colour); /** - Decrements the grid's batch count. + Sets the font for text in the grid cell at the specified location. + */ + void SetCellFont(int row, int col, const wxFont& font); - When the count is greater than zero repainting of the grid is - suppressed. Each previous call to BeginBatch() must be matched by a - later call to EndBatch. Code that does a lot of grid modification can - be enclosed between BeginBatch and EndBatch calls to avoid screen - flicker. The final EndBatch will cause the grid to be repainted. + /** + Sets the text colour for the given cell. + */ + void SetCellTextColour(int row, int col, const wxColour& colour); + /** + Sets the text colour for the given cell. + */ + void SetCellTextColour(const wxColour& val, int row, int col); + /** + Sets the text colour for all cells by default. + */ + void SetCellTextColour(const wxColour& colour); - @see wxGridUpdateLocker + /** + Sets the default horizontal and vertical alignment for grid cell text. + + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one + of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. */ - void EndBatch(); + void SetDefaultCellAlignment(int horiz, int vert); /** - Overridden wxWindow method. + Sets the default background colour for grid cells. */ - virtual void Fit(); + void SetDefaultCellBackgroundColour(const wxColour& colour); /** - Causes immediate repainting of the grid. + Sets the default font to be used for grid cell text. + */ + void SetDefaultCellFont(const wxFont& font); - Use this instead of the usual wxWindow::Refresh. + /** + Sets the current default colour for grid cell text. */ - void ForceRefresh(); + void SetDefaultCellTextColour(const wxColour& colour); + + //@} + + + /** + @name Cell Values, Editors, and Renderers + + Note that wxGridCellAttr can be used alternatively to most of these + methods. See the "Attributes Management" of wxGridTableBase. + */ + //@{ /** - Returns the number of times that BeginBatch() has been called - without (yet) matching calls to EndBatch(). While - the grid's batch count is greater than zero the display will not be updated. + Returns @true if the in-place edit control for the current grid cell + can be used and @false otherwise. + + This function always returns @false for the read-only cells. */ - int GetBatchCount(); + bool CanEnableCellControl() const; /** - Sets the arguments to the horizontal and vertical text alignment values - for the grid cell at the specified location. + Disables in-place editing of grid cells. - Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE - or @c wxALIGN_RIGHT. + Equivalent to calling EnableCellEditControl(@false). + */ + void DisableCellEditControl(); - Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or - @c wxALIGN_BOTTOM. + /** + Enables or disables in-place editing of grid cell data. + + The grid will issue either a @c wxEVT_GRID_EDITOR_SHOWN or + @c wxEVT_GRID_EDITOR_HIDDEN event. */ - void GetCellAlignment(int row, int col, int* horiz, int* vert) const; + void EnableCellEditControl(bool enable = true); /** - Returns the background colour of the cell at the specified location. + Makes the grid globally editable or read-only. + + If the edit argument is @false this function sets the whole grid as + read-only. If the argument is @true the grid is set to the default + state where cells may be editable. In the default state you can set + single grid cells and whole rows and columns to be editable or + read-only via wxGridCellAttr::SetReadOnly(). For single cells you + can also use the shortcut function SetReadOnly(). + + For more information about controlling grid cell attributes see the + wxGridCellAttr class and the @ref overview_grid. */ - wxColour GetCellBackgroundColour(int row, int col) const; + void EnableEditing(bool edit); /** Returns a pointer to the editor for the cell at the specified location. - See wxGridCellEditor and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + See wxGridCellEditor and the @ref overview_grid for more information + about cell editors and renderers. The caller must call DecRef() on the returned pointer. */ wxGridCellEditor* GetCellEditor(int row, int col) const; - /** - Returns the font for text in the grid cell at the specified location. - */ - wxFont GetCellFont(int row, int col) const; - /** Returns a pointer to the renderer for the grid cell at the specified location. - See wxGridCellRenderer and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + See wxGridCellRenderer and the @ref overview_grid for more information + about cell editors and renderers. The caller must call DecRef() on the returned pointer. */ wxGridCellRenderer* GetCellRenderer(int row, int col) const; /** - Returns the text colour for the grid cell at the specified location. - */ - wxColour GetCellTextColour(int row, int col) const; + Returns the string contained in the cell at the specified location. - //@{ + For simple applications where a grid object automatically uses a + default grid table of string values you use this function together with + SetCellValue() to access cell values. For more complex applications + where you have derived your own grid table class that contains various + data types (e.g. numeric, boolean or user-defined custom types) then + you only use this function for those cells that contain string values. + + See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for + more information. + */ + wxString GetCellValue(int row, int col) const; /** Returns the string contained in the cell at the specified location. @@ -1538,591 +1609,682 @@ public: data types (e.g. numeric, boolean or user-defined custom types) then you only use this function for those cells that contain string values. - See wxGridTableBase::CanGetValueAs and the @ref overview_grid "wxGrid overview" - for more information. + See wxGridTableBase::CanGetValueAs() and the @ref overview_grid for + more information. */ - wxString GetCellValue(int row, int col) const; - const wxString GetCellValue(const wxGridCellCoords& coords) const; - //@} + const wxString GetCellValue(const wxGridCellCoords& coords) const; /** - Returns the column ID of the specified column position. + Returns a pointer to the current default grid cell editor. + + See wxGridCellEditor and the @ref overview_grid for more information + about cell editors and renderers. */ - int GetColAt(int colPos) const; + wxGridCellEditor* GetDefaultEditor() const; /** - Returns the pen used for vertical grid lines. + Returns the default editor for the specified cell. - This virtual function may be overridden in derived classes in order to - change the appearance of individual grid lines for the given column @e - col. + The base class version returns the editor appropriate for the current + cell type but this method may be overridden in the derived classes to + use custom editors for some cells by default. - See GetRowGridLinePen() for an example. - */ - virtual wxPen GetColGridLinePen(int col); + Notice that the same may be achieved in a usually simpler way by + associating a custom editor with the given cell or cells. + The caller must call DecRef() on the returned pointer. + */ + virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; /** - Sets the arguments to the current column label alignment values. + Returns the default editor for the specified cell. - Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE - or @c wxALIGN_RIGHT. + The base class version returns the editor appropriate for the current + cell type but this method may be overridden in the derived classes to + use custom editors for some cells by default. - Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or - @c wxALIGN_BOTTOM. - */ - void GetColLabelAlignment(int* horiz, int* vert) const; + Notice that the same may be achieved in a usually simpler way by + associating a custom editor with the given cell or cells. - /** - Returns the current height of the column labels. + The caller must call DecRef() on the returned pointer. */ - int GetColLabelSize() const; + wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const; /** - Returns the specified column label. + Returns the default editor for the cells containing values of the given + type. - The default grid table class provides column labels of the form - A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can - override wxGridTableBase::GetColLabelValue to provide your own labels. + The base class version returns the editor which was associated with the + specified @a typeName when it was registered RegisterDataType() but + this function may be overridden to return something different. This + allows to override an editor used for one of the standard types. + + The caller must call DecRef() on the returned pointer. */ - wxString GetColLabelValue(int col) const; + virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; /** - Returns the minimal width to which a column may be resized. + Returns a pointer to the current default grid cell renderer. - Use SetColMinimalAcceptableWidth() to change this value globally or - SetColMinimalWidth() to do it for individual columns. + See wxGridCellRenderer and the @ref overview_grid for more information + about cell editors and renderers. + + The caller must call DecRef() on the returned pointer. */ - int GetColMinimalAcceptableWidth() const; + wxGridCellRenderer* GetDefaultRenderer() const; /** - Returns the position of the specified column. + Returns the default renderer for the given cell. + + The base class version returns the renderer appropriate for the current + cell type but this method may be overridden in the derived classes to + use custom renderers for some cells by default. + + The caller must call DecRef() on the returned pointer. */ - int GetColPos(int colID) const; + virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; /** - Returns the width of the specified column. - */ - int GetColSize(int col) const; - - /** - Returns the default cell alignment. - - Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE - or @c wxALIGN_RIGHT. - - Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or - @c wxALIGN_BOTTOM. + Returns the default renderer for the cell containing values of the + given type. - @see SetDefaultCellAlignment() + @see GetDefaultEditorForType() */ - void GetDefaultCellAlignment(int* horiz, int* vert) const; + virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; /** - Returns the current default background colour for grid cells. + Hides the in-place cell edit control. */ - wxColour GetDefaultCellBackgroundColour() const; + void HideCellEditControl(); /** - Returns the current default font for grid cell text. + Returns @true if the in-place edit control is currently enabled. */ - wxFont GetDefaultCellFont() const; + bool IsCellEditControlEnabled() const; /** - Returns the current default colour for grid cell text. - */ - wxColour GetDefaultCellTextColour() const; + Returns @true if the current cell is read-only. - /** - Returns the default height for column labels. + @see SetReadOnly(), IsReadOnly() */ - int GetDefaultColLabelSize() const; + bool IsCurrentCellReadOnly() const; /** - Returns the current default width for grid columns. + Returns @false if the whole grid has been set as read-only or @true + otherwise. + + See EnableEditing() for more information about controlling the editing + status of grid cells. */ - int GetDefaultColSize() const; + bool IsEditable() const; /** - Returns a pointer to the current default grid cell editor. + Returns @true if the cell at the specified location can't be edited. - See wxGridCellEditor and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + @see SetReadOnly(), IsCurrentCellReadOnly() */ - wxGridCellEditor* GetDefaultEditor() const; + bool IsReadOnly(int row, int col) const; - //@{ /** - Returns the default editor for the specified cell. + Register a new data type. - The base class version returns the editor appropriate for the current - cell type but this method may be overridden in the derived classes to - use custom editors for some cells by default. + The data types allow to naturally associate specific renderers and + editors to the cells containing values of the given type. For example, + the grid automatically registers a data type with the name + @c wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and + wxGridCellTextEditor as its renderer and editor respectively -- this is + the data type used by all the cells of the default wxGridStringTable, + so this renderer and editor are used by default for all grid cells. - Notice that the same may be usually achieved in simpler way by - associating a custom editor with the given cell or cells. + However if a custom table returns @c wxGRID_VALUE_BOOL from its + wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and + wxGridCellBoolEditor are used for it because the grid also registers a + boolean data type with this name. - The caller must call DecRef() on the returned pointer. + And as this mechanism is completely generic, you may register your own + data types using your own custom renderers and editors. Just remember + that the table must identify a cell as being of the given type for them + to be used for this cell. + + @param typeName + Name of the new type. May be any string, but if the type name is + the same as the name of an already registered type, including one + of the standard ones (which are @c wxGRID_VALUE_STRING, @c + wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT + and @c wxGRID_VALUE_CHOICE), then the new registration information + replaces the previously used renderer and editor. + @param renderer + The renderer to use for the cells of this type. Its ownership is + taken by the grid, i.e. it will call DecRef() on this pointer when + it doesn't need it any longer. + @param editor + The editor to use for the cells of this type. Its ownership is also + taken by the grid. */ - virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; - wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const; - //@} + void RegisterDataType(const wxString& typeName, + wxGridCellRenderer* renderer, + wxGridCellEditor* editor); /** - Returns the default editor for the cells containing values of the given - type. - - The base class version returns the editor which was associated with the - specified @a typeName when it was registered RegisterDataType() but - this function may be overridden to return something different. This - allows to override an editor used for one of the standard types. + Sets the value of the current grid cell to the current in-place edit + control value. - The caller must call DecRef() on the returned pointer. + This is called automatically when the grid cursor moves from the + current cell to a new cell. It is also a good idea to call this + function when closing a grid since any edits to the final cell location + will not be saved otherwise. */ - virtual wxGridCellEditor * - GetDefaultEditorForType(const wxString& typeName) const; + void SaveEditControlValue(); /** - Returns the pen used for grid lines. + Sets the editor for the grid cell at the specified location. - This virtual function may be overridden in derived classes in order to - change the appearance of grid lines. Note that currently the pen width - must be 1. + The grid will take ownership of the pointer. - @see GetColGridLinePen(), GetRowGridLinePen() + See wxGridCellEditor and the @ref overview_grid for more information + about cell editors and renderers. */ - virtual wxPen GetDefaultGridLinePen(); + void SetCellEditor(int row, int col, wxGridCellEditor* editor); /** - Returns a pointer to the current default grid cell renderer. + Sets the renderer for the grid cell at the specified location. - See wxGridCellRenderer and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + The grid will take ownership of the pointer. - The caller must call DecRef() on the returned pointer. + See wxGridCellRenderer and the @ref overview_grid for more information + about cell editors and renderers. */ - wxGridCellRenderer* GetDefaultRenderer() const; + void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer); /** - Returns the default renderer for the given cell. + Sets the string value for the cell at the specified location. - The base class version returns the renderer appropriate for the current - cell type but this method may be overridden in the derived classes to - use custom renderers for some cells by default. + For simple applications where a grid object automatically uses a + default grid table of string values you use this function together with + GetCellValue() to access cell values. For more complex applications + where you have derived your own grid table class that contains various + data types (e.g. numeric, boolean or user-defined custom types) then + you only use this function for those cells that contain string values. - The caller must call DecRef() on the returned pointer. + See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for + more information. */ - virtual wxGridCellRenderer *GetDefaultRendererForCell(int row, int col) const; - + void SetCellValue(int row, int col, const wxString& s); /** - Returns the default renderer for the cell containing values of the - given type. + Sets the string value for the cell at the specified location. - @see GetDefaultEditorForType() - */ - virtual wxGridCellRenderer * - GetDefaultRendererForType(const wxString& typeName) const; + For simple applications where a grid object automatically uses a + default grid table of string values you use this function together with + GetCellValue() to access cell values. For more complex applications + where you have derived your own grid table class that contains various + data types (e.g. numeric, boolean or user-defined custom types) then + you only use this function for those cells that contain string values. - /** - Returns the default width for the row labels. + See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for + more information. */ - int GetDefaultRowLabelSize() const; - + void SetCellValue(const wxGridCellCoords& coords, const wxString& s); /** - Returns the current default height for grid rows. - */ - int GetDefaultRowSize() const; + @deprecated Please use SetCellValue(int,int,const wxString&) or + SetCellValue(const wxGridCellCoords&,const wxString&) + instead. - /** - Returns the current grid cell column position. - */ - int GetGridCursorCol() const; + Sets the string value for the cell at the specified location. - /** - Returns the current grid cell row position. + For simple applications where a grid object automatically uses a + default grid table of string values you use this function together with + GetCellValue() to access cell values. For more complex applications + where you have derived your own grid table class that contains various + data types (e.g. numeric, boolean or user-defined custom types) then + you only use this function for those cells that contain string values. + + See wxGridTableBase::CanSetValueAs() and the @ref overview_grid for + more information. */ - int GetGridCursorRow() const; + void SetCellValue(const wxString& val, int row, int col); /** - Returns the colour used for grid lines. + Sets the specified column to display boolean values. - @see GetDefaultGridLinePen() + @see SetColFormatCustom() */ - wxColour GetGridLineColour() const; + void SetColFormatBool(int col); /** - Returns the colour used for the background of row and column labels. - */ - wxColour GetLabelBackgroundColour() const; + Sets the specified column to display data in a custom format. - /** - Returns the font used for row and column labels. - */ - wxFont GetLabelFont() const; + This method provides an alternative to defining a custom grid table + which would return @a typeName from its GetTypeName() method for the + cells in this column: while it doesn't really change the type of the + cells in this column, it does associate the renderer and editor used + for the cells of the specified type with them. - /** - Returns the colour used for row and column label text. + See the @ref overview_grid for more information on working with custom + data types. */ - wxColour GetLabelTextColour() const; + void SetColFormatCustom(int col, const wxString& typeName); /** - Returns the total number of grid columns. + Sets the specified column to display floating point values with the + given width and precision. - This is the same as the number of columns in the underlying grid - table. + @see SetColFormatCustom() */ - int GetNumberCols() const; + void SetColFormatFloat(int col, int width = -1, int precision = -1); /** - Returns the total number of grid rows. + Sets the specified column to display integer values. - This is the same as the number of rows in the underlying grid table. + @see SetColFormatCustom() */ - int GetNumberRows() const; + void SetColFormatNumber(int col); /** - Returns the attribute for the given cell creating one if necessary. + Sets the default editor for grid cells. - If the cell already has an attribute, it is returned. Otherwise a new - attribute is created, associated with the cell and returned. In any - case the caller must call DecRef() on the returned pointer. + The grid will take ownership of the pointer. - This function may only be called if CanHaveAttributes() returns @true. + See wxGridCellEditor and the @ref overview_grid for more information + about cell editors and renderers. */ - wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; + void SetDefaultEditor(wxGridCellEditor* editor); /** - Returns the pen used for horizontal grid lines. + Sets the default renderer for grid cells. - This virtual function may be overridden in derived classes in order to - change the appearance of individual grid line for the given row @e row. + The grid will take ownership of the pointer. - Example: - @code - // in a grid displaying music notation, use a solid black pen between - // octaves (C0=row 127, C1=row 115 etc.) - wxPen MidiGrid::GetRowGridLinePen(int row) - { - if ( row % 12 == 7 ) - return wxPen(*wxBLACK, 1, wxSOLID); - else - return GetDefaultGridLinePen(); - } - @endcode + See wxGridCellRenderer and the @ref overview_grid for more information + about cell editors and renderers. */ - virtual wxPen GetRowGridLinePen(int row); + void SetDefaultRenderer(wxGridCellRenderer* renderer); /** - Returns the alignment used for row labels. - - Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE - or @c wxALIGN_RIGHT. + Makes the cell at the specified location read-only or editable. - Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or - @c wxALIGN_BOTTOM. + @see IsReadOnly() */ - void GetRowLabelAlignment(int* horiz, int* vert) const; + void SetReadOnly(int row, int col, bool isReadOnly = true); /** - Returns the current width of the row labels. + Displays the in-place cell edit control for the current cell. */ - int GetRowLabelSize() const; + void ShowCellEditControl(); - /** - Returns the specified row label. + //@} - The default grid table class provides numeric row labels. If you are - using a custom grid table you can override - wxGridTableBase::GetRowLabelValue to provide your own labels. - */ - wxString GetRowLabelValue(int row) const; /** - Returns the minimal size to which rows can be resized. - - Use SetRowMinimalAcceptableHeight() to change this value globally or - SetRowMinimalHeight() to do it for individual cells. + @name Column and Row Sizes + */ + //@{ - @see GetColMinimalAcceptableWidth() + /** + Automatically sets the height and width of all rows and columns to fit + their contents. */ - int GetRowMinimalAcceptableHeight() const; + void AutoSize(); /** - Returns the height of the specified row. + Automatically adjusts width of the column to fit its label. */ - int GetRowSize(int row) const; + void AutoSizeColLabelSize(int col); /** - Returns the number of pixels per horizontal scroll increment. - - The default is 15. - - @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY() - */ - int GetScrollLineX() const; + Automatically sizes the column to fit its contents. If @a setAsMin is + @true the calculated width will also be set as the minimal width for + the column. + */ + void AutoSizeColumn(int col, bool setAsMin = true); /** - Returns the number of pixels per vertical scroll increment. - - The default is 15. - - @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY() + Automatically sizes all columns to fit their contents. If @a setAsMin + is @true the calculated widths will also be set as the minimal widths + for the columns. */ - int GetScrollLineY() const; + void AutoSizeColumns(bool setAsMin = true); /** - Returns an array of individually selected cells. - - Notice that this array does @em not contain all the selected cells in - general as it doesn't include the cells selected as part of column, row - or block selection. You must use this method, GetSelectedCols(), - GetSelectedRows() and GetSelectionBlockTopLeft() and - GetSelectionBlockBottomRight() methods to obtain the entire selection - in general. - - Please notice this behaviour is by design and is needed in order to - support grids of arbitrary size (when an entire column is selected in - a grid with a million of columns, we don't want to create an array with - a million of entries in this function, instead it returns an empty - array and GetSelectedCols() returns an array containing one element). + Automatically sizes the row to fit its contents. If @a setAsMin is + @true the calculated height will also be set as the minimal height for + the row. */ - wxGridCellCoordsArray GetSelectedCells() const; + void AutoSizeRow(int row, bool setAsMin = true); /** - Returns an array of selected columns. - - Please notice that this method alone is not sufficient to find all the - selected columns as it contains only the columns which were - individually selected but not those being part of the block selection - or being selected in virtue of all of their cells being selected - individually, please see GetSelectedCells() for more details. + Automatically adjusts height of the row to fit its label. */ - wxArrayInt GetSelectedCols() const; + void AutoSizeRowLabelSize(int col); /** - Returns an array of selected rows. - - Please notice that this method alone is not sufficient to find all the - selected rows as it contains only the rows which were individually - selected but not those being part of the block selection or being - selected in virtue of all of their cells being selected individually, - please see GetSelectedCells() for more details. + Automatically sizes all rows to fit their contents. If @a setAsMin is + @true the calculated heights will also be set as the minimal heights + for the rows. */ - wxArrayInt GetSelectedRows() const; + void AutoSizeRows(bool setAsMin = true); /** - Access or update the selection fore/back colours + Returns the current height of the column labels. */ - wxColour GetSelectionBackground() const; + int GetColLabelSize() const; /** - Returns an array of the bottom right corners of blocks of selected - cells. + Returns the minimal width to which a column may be resized. - Please see GetSelectedCells() for more information about the selection - representation in wxGrid. + Use SetColMinimalAcceptableWidth() to change this value globally or + SetColMinimalWidth() to do it for individual columns. - @see GetSelectionBlockTopLeft() + @see GetRowMinimalAcceptableHeight() */ - wxGridCellCoordsArray GetSelectionBlockBottomRight() const; + int GetColMinimalAcceptableWidth() const; /** - Returns an array of the top left corners of blocks of selected cells. - - Please see GetSelectedCells() for more information about the selection - representation in wxGrid. - - @see GetSelectionBlockBottomRight() + Returns the width of the specified column. */ - wxGridCellCoordsArray GetSelectionBlockTopLeft() const; + int GetColSize(int col) const; /** - Returns the colour used for drawing the selection foreground. + Returns the default height for column labels. */ - wxColour GetSelectionForeground() const; + int GetDefaultColLabelSize() const; /** - Returns the current selection mode. - - @see SetSelectionMode(). + Returns the current default width for grid columns. */ - wxGridSelectionModes GetSelectionMode() const; + int GetDefaultColSize() const; /** - Returns a base pointer to the current table object. + Returns the default width for the row labels. + */ + int GetDefaultRowLabelSize() const; - The returned pointer is still owned by the grid. + /** + Returns the current default height for grid rows. */ - wxGridTableBase *GetTable() const; + int GetDefaultRowSize() const; - //@{ /** - Make the given cell current and ensure it is visible. + Returns the minimal size to which rows can be resized. - This method is equivalent to calling MakeCellVisible() and - SetGridCursor() and so, as with the latter, a wxEVT_GRID_SELECT_CELL - event is generated by it and the selected cell doesn't change if the - event is vetoed. - */ - void GoToCell(int row, int col); - void GoToCell(const wxGridCellCoords& coords); - //@} + Use SetRowMinimalAcceptableHeight() to change this value globally or + SetRowMinimalHeight() to do it for individual cells. - /** - Returns @true if drawing of grid lines is turned on, @false otherwise. + @see GetColMinimalAcceptableWidth() */ - bool GridLinesEnabled() const; + int GetRowMinimalAcceptableHeight() const; /** - Hides the in-place cell edit control. + Returns the current width of the row labels. */ - void HideCellEditControl(); + int GetRowLabelSize() const; /** - Hides the column labels by calling SetColLabelSize() - with a size of 0. Show labels again by calling that method with - a width greater than 0. + Returns the height of the specified row. */ - void HideColLabels(); + int GetRowSize(int row) const; /** - Hides the row labels by calling SetRowLabelSize() with a size of 0. + Sets the height of the column labels. - The labels can be shown again by calling SetRowLabelSize() with a width - greater than 0. + If @a height equals to @c wxGRID_AUTOSIZE then height is calculated + automatically so that no label is truncated. Note that this could be + slow for a large table. */ - void HideRowLabels(); + void SetColLabelSize(int height); /** - Inserts one or more new columns into a grid with the first new column - at the specified position. - - Notice that inserting the columns in the grid requires grid table - cooperation: when this method is called, grid object begins by - requesting the underlying grid table to insert new columns. If this is - successful the table notifies the grid and the grid updates the - display. For a default grid (one where you have called - wxGrid::CreateGrid) this process is automatic. If you are using a - custom grid table (specified with wxGrid::SetTable) then you must - override wxGridTableBase::InsertCols() in your derived table class. + Sets the minimal @a width to which the user can resize columns. - @param pos - The position which the first newly inserted column will have. - @param numCols - The number of columns to insert. - @param updateLabels - Currently not used. - @return - @true if the columns were successfully inserted, @false if an error - occurred (most likely the table couldn't be updated). + @see GetColMinimalAcceptableWidth() */ - bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true); + void SetColMinimalAcceptableWidth(int width); /** - Inserts one or more new rows into a grid with the first new row at the - specified position. + Sets the minimal @a width for the specified column @a col. - Notice that you must implement wxGridTableBase::InsertRows() if you use - a grid with a custom table, please see InsertCols() for more - information. + It is usually best to call this method during grid creation as calling + it later will not resize the column to the given minimal width even if + it is currently narrower than it. - @param pos - The position which the first newly inserted row will have. - @param numRows - The number of rows to insert. - @param updateLabels - Currently not used. - @return - @true if the rows were successfully inserted, @false if an error - occurred (most likely the table couldn't be updated). + @a width must be greater than the minimal acceptable column width as + returned by GetColMinimalAcceptableWidth(). */ - bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true); + void SetColMinimalWidth(int col, int width); /** - Returns @true if the in-place edit control is currently enabled. + 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. */ - bool IsCellEditControlEnabled() const; + void SetColSize(int col, int width); /** - Returns @true if the current cell is read-only. + Sets the default width for columns in the grid. - @see SetReadOnly(), IsReadOnly() + This will only affect columns subsequently added to the grid unless + @a resizeExistingCols is @true. + + If @a width is less than GetColMinimalAcceptableWidth(), then the + minimal acceptable width is used instead of it. */ - bool IsCurrentCellReadOnly() const; + void SetDefaultColSize(int width, bool resizeExistingCols = false); /** - Returns @false if the whole grid has been set as read-only or @true - otherwise. + Sets the default height for rows in the grid. - See EnableEditing() for more information about controlling the editing - status of grid cells. + This will only affect rows subsequently added to the grid unless + @a resizeExistingRows is @true. + + If @a height is less than GetRowMinimalAcceptableHeight(), then the + minimal acceptable heihgt is used instead of it. */ - bool IsEditable() const; + void SetDefaultRowSize(int height, bool resizeExistingRows = false); - //@{ /** - Is this cell currently selected? + Sets the width of the row labels. + + If @a width equals @c wxGRID_AUTOSIZE then width is calculated + automatically so that no label is truncated. Note that this could be + slow for a large table. */ - bool IsInSelection(int row, int col) const; - bool IsInSelection(const wxGridCellCoords& coords) const; - //@} + void SetRowLabelSize(int width); /** - Returns @true if the cell at the specified location can't be edited. + Sets the minimal row @a height used by default. - @see SetReadOnly(), IsCurrentCellReadOnly() + See SetColMinimalAcceptableWidth() for more information. */ - bool IsReadOnly(int row, int col) const; + void SetRowMinimalAcceptableHeight(int height); /** - Returns @true if there are currently any selected cells, rows, columns - or blocks. + Sets the minimal @a height for the specified @a row. + + See SetColMinimalWidth() for more information. */ - bool IsSelection() const; + void SetRowMinimalHeight(int row, int height); - //@{ /** - Returns @true if a cell is either wholly or at least partially visible - in the grid window. + Sets the height of the specified row. - By default, the cell must be entirely visible for this function to - return true but if @a wholeCellVisible is @false, the function returns - @true even if the cell is only partially visible. + See SetColSize() for more information. */ - bool IsVisible(int row, int col, bool wholeCellVisible = true) const; - bool IsVisible(const wxGridCellCoords& coords, - bool wholeCellVisible = true) const; + void SetRowSize(int row, int height); + //@} - //@{ + /** - Brings the specified cell into the visible grid cell area with minimal - scrolling. + @name User-Resizing and Dragging + */ + //@{ - Does nothing if the cell is already visible. + /** + Return @true if the dragging of cells is enabled or @false otherwise. */ - void MakeCellVisible(int row, int col); - void MakeCellVisible(const wxGridCellCoords& coords); - //@} + bool CanDragCell() const; /** - Moves the grid cursor down by one row. + Returns @true if columns can be moved by dragging with the mouse. - If a block of cells was previously selected it will expand if the - argument is @true or be cleared if the argument is @false. + Columns can be moved by dragging on their labels. */ - bool MoveCursorDown(bool expandSelection); + bool CanDragColMove() const; /** - Moves the grid cursor down in the current column such that it skips to - the beginning or end of a block of non-empty cells. + Returns @true if columns can be resized by dragging with the mouse. - If a block of cells was previously selected it will expand if the - argument is @true or be cleared if the argument is @false. + Columns can be resized by dragging the edges of their labels. If grid + line dragging is enabled they can also be resized by dragging the right + edge of the column in the grid cell area (see EnableDragGridSize()). */ - bool MoveCursorDownBlock(bool expandSelection); + bool CanDragColSize() const; /** - Moves the grid cursor left by one column. + Return @true if the dragging of grid lines to resize rows and columns + is enabled or @false otherwise. + */ + bool CanDragGridSize() const; + + /** + Returns @true if rows can be resized by dragging with the mouse. + + Rows can be resized by dragging the edges of their labels. If grid line + dragging is enabled they can also be resized by dragging the lower edge + of the row in the grid cell area (see EnableDragGridSize()). + */ + bool CanDragRowSize() const; + + /** + Disables column moving by dragging with the mouse. + + Equivalent to passing @false to EnableDragColMove(). + */ + void DisableDragColMove(); + + /** + Disables column sizing by dragging with the mouse. + + Equivalent to passing @false to EnableDragColSize(). + */ + void DisableDragColSize(); + + /** + Disable mouse dragging of grid lines to resize rows and columns. + + Equivalent to passing @false to EnableDragGridSize() + */ + void DisableDragGridSize(); + + /** + Disables row sizing by dragging with the mouse. + + Equivalent to passing @false to EnableDragRowSize(). + */ + void DisableDragRowSize(); + + /** + Enables or disables cell dragging with the mouse. + */ + void EnableDragCell(bool enable = true); + + /** + Enables or disables column moving by dragging with the mouse. + */ + void EnableDragColMove(bool enable = true); + + /** + Enables or disables column sizing by dragging with the mouse. + */ + void EnableDragColSize(bool enable = true); + + /** + Enables or disables row and column resizing by dragging gridlines with + the mouse. + */ + void EnableDragGridSize(bool enable = true); + + /** + Enables or disables row sizing by dragging with the mouse. + */ + void EnableDragRowSize(bool enable = true); + + /** + Returns the column ID of the specified column position. + */ + int GetColAt(int colPos) const; + + /** + Returns the position of the specified column. + */ + int GetColPos(int colID) const; + + /** + Sets the position of the specified column. + */ + void SetColPos(int colID, int newPos); + + //@} + + + /** + @name Cursor Movement + */ + //@{ + + /** + Returns the current grid cell column position. + */ + int GetGridCursorCol() const; + + /** + Returns the current grid cell row position. + */ + int GetGridCursorRow() const; + + /** + Make the given cell current and ensure it is visible. + + This method is equivalent to calling MakeCellVisible() and + SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL + event is generated by it and the selected cell doesn't change if the + event is vetoed. + */ + void GoToCell(int row, int col); + /** + Make the given cell current and ensure it is visible. + + This method is equivalent to calling MakeCellVisible() and + SetGridCursor() and so, as with the latter, a @c wxEVT_GRID_SELECT_CELL + event is generated by it and the selected cell doesn't change if the + event is vetoed. + */ + void GoToCell(const wxGridCellCoords& coords); + + /** + Moves the grid cursor down by one row. + + If a block of cells was previously selected it will expand if the + argument is @true or be cleared if the argument is @false. + */ + bool MoveCursorDown(bool expandSelection); + + /** + Moves the grid cursor down in the current column such that it skips to + the beginning or end of a block of non-empty cells. + + If a block of cells was previously selected it will expand if the + argument is @true or be cleared if the argument is @false. + */ + bool MoveCursorDownBlock(bool expandSelection); + + /** + Moves the grid cursor left by one column. If a block of cells was previously selected it will expand if the argument is @true or be cleared if the argument is @false. @@ -2185,586 +2347,645 @@ public: bool MovePageUp(); /** - Register a new data type. - - The data types allow to naturally associate specific renderers and - editors to the cells containing values of the given type. For example, - the grid automatically registers a data type with the name @c - wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and - wxGridCellTextEditor as its renderer and editor respectively -- this is - the data type used by all the cells of the default wxGridStringTable, - so this renderer and editor are used by default for all grid cells. + Set the grid cursor to the specified cell. - However if a custom table returns @c wxGRID_VALUE_BOOL from its - wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and - wxGridCellBoolEditor are used for it because the grid also registers a - boolean data type with this name. + The grid cursor indicates the current cell and can be moved by the user + using the arrow keys or the mouse. - And as this mechanism is completely generic, you may register your own - data types using your own custom renderers and editors. Just remember - that the table must identify a cell as being of the given type for them - to be used for this cell. + Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and + if the event handler vetoes this event, the cursor is not moved. - @param typeName - Name of the new type. May be any string, but if the type name is - the same as the name of an already registered type, including one - of the standard ones (which are @c wxGRID_VALUE_STRING, @c - wxGRID_VALUE_BOOL, @c wxGRID_VALUE_NUMBER, @c wxGRID_VALUE_FLOAT - and @c wxGRID_VALUE_CHOICE), then the new registration information - replaces the previously used renderer and editor. - @param renderer - The renderer to use for the cells of this type. Its ownership is - taken by the grid, i.e. it will call DecRef() on this pointer when - it doesn't need it any longer. - @param editor - The editor to use for the cells of this type. Its ownership is also - taken by the grid. + This function doesn't make the target call visible, use GoToCell() to + do this. */ - void RegisterDataType(const wxString& typeName, - wxGridCellRenderer* renderer, - wxGridCellEditor* editor); - + void SetGridCursor(int row, int col); /** - Sets the value of the current grid cell to the current in-place edit - control value. - - This is called automatically when the grid cursor moves from the - current cell to a new cell. It is also a good idea to call this - function when closing a grid since any edits to the final cell location - will not be saved otherwise. - */ - void SaveEditControlValue(); + Set the grid cursor to the specified cell. - /** - Selects all cells in the grid. - */ - void SelectAll(); + The grid cursor indicates the current cell and can be moved by the user + using the arrow keys or the mouse. - //@{ - /** - Selects a rectangular block of cells. + Calling this function generates a @c wxEVT_GRID_SELECT_CELL event and + if the event handler vetoes this event, the cursor is not moved. - If @a addToSelected is @false then any existing selection will be - deselected; if @true the column will be added to the existing - selection. + This function doesn't make the target call visible, use GoToCell() to + do this. */ - void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, - bool addToSelected = false); - void SelectBlock(const wxGridCellCoords& topLeft, - const wxGridCellCoords& bottomRight, - bool addToSelected = false); + void SetGridCursor(const wxGridCellCoords& coords); + //@} - /** - Selects the specified column. - If @a addToSelected is @false then any existing selection will be - deselected; if @true the column will be added to the existing - selection. + /** + @name User Selection + */ + //@{ - This method won't select anything if the current selection mode is - wxGridSelectRows. + /** + Deselects all cells that are currently selected. */ - void SelectCol(int col, bool addToSelected = false); + void ClearSelection(); /** - Selects the specified row. + Returns an array of individually selected cells. - If @a addToSelected is @false then any existing selection will be - deselected; if @true the row will be added to the existing selection. + Notice that this array does @em not contain all the selected cells in + general as it doesn't include the cells selected as part of column, row + or block selection. You must use this method, GetSelectedCols(), + GetSelectedRows() and GetSelectionBlockTopLeft() and + GetSelectionBlockBottomRight() methods to obtain the entire selection + in general. - This method won't select anything if the current selection mode is - wxGridSelectColumns. + Please notice this behaviour is by design and is needed in order to + support grids of arbitrary size (when an entire column is selected in + a grid with a million of columns, we don't want to create an array with + a million of entries in this function, instead it returns an empty + array and GetSelectedCols() returns an array containing one element). */ - void SelectRow(int row, bool addToSelected = false); + wxGridCellCoordsArray GetSelectedCells() const; - //@{ /** - Sets the horizontal and vertical alignment for grid cell text at the - specified location. - - Horizontal alignment should be one of @c wxALIGN_LEFT, @c - wxALIGN_CENTRE or @c wxALIGN_RIGHT. + Returns an array of selected columns. - Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE - or @c wxALIGN_BOTTOM. + Please notice that this method alone is not sufficient to find all the + selected columns as it contains only the columns which were + individually selected but not those being part of the block selection + or being selected in virtue of all of their cells being selected + individually, please see GetSelectedCells() for more details. */ - void SetCellAlignment(int row, int col, int horiz, int vert); - void SetCellAlignment(int align, int row, int col); - //@} + wxArrayInt GetSelectedCols() const; - //@{ /** - Set the background colour for the given cell or all cells by default. - */ - void SetCellBackgroundColour(int row, int col, const wxColour& colour); - //@} + Returns an array of selected rows. - /** - Sets the editor for the grid cell at the specified location. - - The grid will take ownership of the pointer. - - See wxGridCellEditor and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + Please notice that this method alone is not sufficient to find all the + selected rows as it contains only the rows which were individually + selected but not those being part of the block selection or being + selected in virtue of all of their cells being selected individually, + please see GetSelectedCells() for more details. */ - void SetCellEditor(int row, int col, wxGridCellEditor* editor); + wxArrayInt GetSelectedRows() const; /** - Sets the font for text in the grid cell at the specified location. + Returns the colour used for drawing the selection background. */ - void SetCellFont(int row, int col, const wxFont& font); + wxColour GetSelectionBackground() const; /** - Sets the renderer for the grid cell at the specified location. - - The grid will take ownership of the pointer. + Returns an array of the bottom right corners of blocks of selected + cells. - See wxGridCellRenderer and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. - */ - void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer); + Please see GetSelectedCells() for more information about the selection + representation in wxGrid. - //@{ - /** - Sets the text colour for the given cell or all cells by default. + @see GetSelectionBlockTopLeft() */ - void SetCellTextColour(int row, int col, const wxColour& colour); - void SetCellTextColour(const wxColour& val, int row, int col); - void SetCellTextColour(const wxColour& colour); - //@} + wxGridCellCoordsArray GetSelectionBlockBottomRight() const; - //@{ /** - Sets the string value for the cell at the specified location. + Returns an array of the top left corners of blocks of selected cells. - For simple applications where a grid object automatically uses a - default grid table of string values you use this function together with - GetCellValue() to access cell values. For more complex applications - where you have derived your own grid table class that contains various - data types (e.g. numeric, boolean or user-defined custom types) then - you only use this function for those cells that contain string values. - The last form is for backward compatibility only. + Please see GetSelectedCells() for more information about the selection + representation in wxGrid. - See wxGridTableBase::CanSetValueAs and the @ref overview_grid - "wxGrid overview" for more information. + @see GetSelectionBlockBottomRight() */ - void SetCellValue(int row, int col, const wxString& s); - void SetCellValue(const wxGridCellCoords& coords, const wxString& s); - void SetCellValue(const wxString& val, int row, int col); - //@} + wxGridCellCoordsArray GetSelectionBlockTopLeft() const; /** - Sets the cell attributes for all cells in the specified column. - - For more information about controlling grid cell attributes see the - wxGridCellAttr cell attribute class and the @ref overview_grid "wxGrid overview". + Returns the colour used for drawing the selection foreground. */ - void SetColAttr(int col, wxGridCellAttr* attr); + wxColour GetSelectionForeground() const; /** - Sets the specified column to display boolean values. + Returns the current selection mode. - @see SetColFormatCustom() + @see SetSelectionMode(). */ - void SetColFormatBool(int col); + wxGridSelectionModes GetSelectionMode() const; /** - Sets the specified column to display data in a custom format. + Returns @true if the given cell is selected. + */ + bool IsInSelection(int row, int col) const; + /** + Returns @true if the given cell is selected. + */ + bool IsInSelection(const wxGridCellCoords& coords) const; - This method provides an alternative to defining a custom grid table - which would return @a typeName from its GetTypeName() method for the - cells in this column: while it doesn't really change the type of the - cells in this column, it does associate the renderer and editor used - for the cells of the specified type with them. + /** + Returns @true if there are currently any selected cells, rows, columns + or blocks. + */ + bool IsSelection() const; - See the @ref overview_grid "wxGrid overview" for more - information on working with custom data types. + /** + Selects all cells in the grid. */ - void SetColFormatCustom(int col, const wxString& typeName); + void SelectAll(); /** - Sets the specified column to display floating point values with the - given width and precision. + Selects a rectangular block of cells. - @see SetColFormatCustom() + If @a addToSelected is @false then any existing selection will be + deselected; if @true the column will be added to the existing + selection. */ - void SetColFormatFloat(int col, int width = -1, int precision = -1); - + void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, + bool addToSelected = false); /** - Sets the specified column to display integer values. + Selects a rectangular block of cells. - @see SetColFormatCustom() + If @a addToSelected is @false then any existing selection will be + deselected; if @true the column will be added to the existing + selection. */ - void SetColFormatNumber(int col); + void SelectBlock(const wxGridCellCoords& topLeft, + const wxGridCellCoords& bottomRight, + bool addToSelected = false); /** - Sets the horizontal and vertical alignment of column label text. + Selects the specified column. - Horizontal alignment should be one of @c wxALIGN_LEFT, @c - wxALIGN_CENTRE or @c wxALIGN_RIGHT. - Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE - or @c wxALIGN_BOTTOM. + If @a addToSelected is @false then any existing selection will be + deselected; if @true the column will be added to the existing + selection. + + This method won't select anything if the current selection mode is + wxGridSelectRows. */ - void SetColLabelAlignment(int horiz, int vert); + void SelectCol(int col, bool addToSelected = false); /** - Sets the height of the column labels. + Selects the specified row. - If @a height equals to @c wxGRID_AUTOSIZE then height is calculated - automatically so that no label is truncated. Note that this could be - slow for a large table. + If @a addToSelected is @false then any existing selection will be + deselected; if @true the row will be added to the existing selection. + + This method won't select anything if the current selection mode is + wxGridSelectColumns. */ - void SetColLabelSize(int height); + void SelectRow(int row, bool addToSelected = false); /** - Set the value for the given column label. + Set the colour to be used for drawing the selection background. + */ + void SetSelectionBackground(const wxColour& c); - If you are using a custom grid table you must override - wxGridTableBase::SetColLabelValue for this to have any effect. + /** + Set the colour to be used for drawing the selection foreground. */ - void SetColLabelValue(int col, const wxString& value); + void SetSelectionForeground(const wxColour& c); /** - Sets the minimal width to which the user can resize columns. + Set the selection behaviour of the grid. - @see GetColMinimalAcceptableWidth() + The existing selection is converted to conform to the new mode if + possible and discarded otherwise (e.g. any individual selected cells + are deselected if the new mode allows only the selection of the entire + rows or columns). */ - void SetColMinimalAcceptableWidth(int width); + void SetSelectionMode(wxGridSelectionModes selmode); - /** - Sets the minimal width for the specified column. + //@} - It is usually best to call this method during grid creation as calling - it later will not resize the column to the given minimal width even if - it is currently narrower than it. - @a width must be greater than the minimal acceptable column width as - returned by GetColMinimalAcceptableWidth(). - */ - void SetColMinimalWidth(int col, int width); + /** + @name Scrolling + */ + //@{ /** - Sets the position of the specified column. + Returns the number of pixels per horizontal scroll increment. + + The default is 15. + + @see GetScrollLineY(), SetScrollLineX(), SetScrollLineY() */ - void SetColPos(int colID, int newPos); + int GetScrollLineX() const; /** - Sets the width of the specified column. + Returns the number of pixels per vertical scroll increment. - Notice that this function does not refresh the grid, you need to call - ForceRefresh() to make the changes take effect immediately. + The default is 15. - @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. + @see GetScrollLineX(), SetScrollLineX(), SetScrollLineY() */ - void SetColSize(int col, int width); + int GetScrollLineY() const; /** - Sets the default horizontal and vertical alignment for grid cell text. + Returns @true if a cell is either entirely or at least partially + visible in the grid window. - Horizontal alignment should be one of @c wxALIGN_LEFT, @c - wxALIGN_CENTRE or @c wxALIGN_RIGHT. - Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE - or @c wxALIGN_BOTTOM. + By default, the cell must be entirely visible for this function to + return @true but if @a wholeCellVisible is @false, the function returns + @true even if the cell is only partially visible. */ - void SetDefaultCellAlignment(int horiz, int vert); - + bool IsVisible(int row, int col, bool wholeCellVisible = true) const; /** - Sets the default background colour for grid cells. + Returns @true if a cell is either entirely or at least partially + visible in the grid window. + + By default, the cell must be entirely visible for this function to + return @true but if @a wholeCellVisible is @false, the function returns + @true even if the cell is only partially visible. */ - void SetDefaultCellBackgroundColour(const wxColour& colour); + bool IsVisible(const wxGridCellCoords& coords, + bool wholeCellVisible = true) const; /** - Sets the default font to be used for grid cell text. - */ - void SetDefaultCellFont(const wxFont& font); + Brings the specified cell into the visible grid cell area with minimal + scrolling. + Does nothing if the cell is already visible. + */ + void MakeCellVisible(int row, int col); /** - Sets the current default colour for grid cell text. + Brings the specified cell into the visible grid cell area with minimal + scrolling. + + Does nothing if the cell is already visible. */ - void SetDefaultCellTextColour(const wxColour& colour); + void MakeCellVisible(const wxGridCellCoords& coords); /** - Sets the default width for columns in the grid. + Sets the number of pixels per horizontal scroll increment. - This will only affect columns subsequently added to the grid unless - @a resizeExistingCols is @true. + The default is 15. - If @a width is less than GetColMinimalAcceptableWidth(), then the - minimal acceptable width is used instead of it. + @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY() */ - void SetDefaultColSize(int width, bool resizeExistingCols = false); + void SetScrollLineX(int x); /** - Sets the default editor for grid cells. + Sets the number of pixels per vertical scroll increment. - The grid will take ownership of the pointer. + The default is 15. - See wxGridCellEditor and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. + @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX() */ - void SetDefaultEditor(wxGridCellEditor* editor); + void SetScrollLineY(int y); - /** - Sets the default renderer for grid cells. + //@} - The grid will take ownership of the pointer. - See wxGridCellRenderer and the @ref overview_grid "wxGrid overview" - for more information about cell editors and renderers. - */ - void SetDefaultRenderer(wxGridCellRenderer* renderer); + /** + @name Cell and Device Coordinate Translation + */ + //@{ /** - Sets the default height for rows in the grid. + Convert grid cell coordinates to grid window pixel coordinates. - This will only affect rows subsequently added to the grid unless - @a resizeExistingRows is @true. + This function returns the rectangle that encloses the block of cells + limited by @a topLeft and @a bottomRight cell in device coords and + clipped to the client size of the grid window. - If @a height is less than GetRowMinimalAcceptableHeight(), then the - minimal acceptable heihgt is used instead of it. + @see CellToRect() */ - void SetDefaultRowSize(int height, bool resizeExistingRows = false); + wxRect BlockToDeviceRect(const wxGridCellCoords& topLeft, + const wxGridCellCoords& bottomRight) const; - //@{ /** - Set the grid cursor to the specified cell. - - The grid cursor indicates the current cell and can be moved by the user - using the arrow keys or the mouse. + Return the rectangle corresponding to the grid cell's size and position + in logical coordinates. - Calling this function generates a wxEVT_GRID_SELECT_CELL event and if - the event handler vetoes this event, the cursor is not moved. + @see BlockToDeviceRect() + */ + wxRect CellToRect(int row, int col) const; + /** + Return the rectangle corresponding to the grid cell's size and position + in logical coordinates. - This function doesn't make the target call visible, use GoToCell() to - do this. + @see BlockToDeviceRect() */ - void SetGridCursor(int row, int col); - void SetGridCursor(const wxGridCellCoords& coords); - //@} + const wxRect CellToRect(const wxGridCellCoords& coords) const; /** - Sets the colour used to draw grid lines. + Returns the column at the given pixel position. + + @param x + The x position to evaluate. + @param clipToMinMax + If @true, rather than returning @c wxNOT_FOUND, it returns either + the first or last column depending on whether @a x is too far to + the left or right respectively. + @return + The column index or @c wxNOT_FOUND. */ - void SetGridLineColour(const wxColour& colour); + int XToCol(int x, bool clipToMinMax = false) const; /** - Sets the background colour for row and column labels. + Returns the column whose right hand edge is close to the given logical + @a x position. + + If no column edge is near to this position @c wxNOT_FOUND is returned. */ - void SetLabelBackgroundColour(const wxColour& colour); + int XToEdgeOfCol(int x) const; /** - Sets the font for row and column labels. - */ - void SetLabelFont(const wxFont& font); + Translates logical pixel coordinates to the grid cell coordinates. + + Notice that this function expects logical coordinates on input so if + you use this function in a mouse event handler you need to translate + the mouse position, which is expressed in device coordinates, to + logical ones. + + @see XToCol(), YToRow() + */ + wxGridCellCoords XYToCell(int x, int y) const; + /** + Translates logical pixel coordinates to the grid cell coordinates. + + Notice that this function expects logical coordinates on input so if + you use this function in a mouse event handler you need to translate + the mouse position, which is expressed in device coordinates, to + logical ones. + + @see XToCol(), YToRow() + */ + wxGridCellCoords XYToCell(const wxPoint& pos) const; + // XYToCell(int, int, wxGridCellCoords&) overload is intentionally + // undocumented, using it is ugly and non-const reference parameters are + // not used in wxWidgets API /** - Sets the colour for row and column label text. + Returns the row whose bottom edge is close to the given logical @a y + position. + + If no row edge is near to this position @c wxNOT_FOUND is returned. */ - void SetLabelTextColour(const wxColour& colour); + int YToEdgeOfRow(int y) const; /** - Sets the extra margins used around the grid area. + Returns the grid row that corresponds to the logical @a y coordinate. - A grid may occupy more space than needed for its data display and - this function allows to set how big this extra space is + Returns @c wxNOT_FOUND if there is no row at the @a y position. */ - void SetMargins(int extraWidth, int extraHeight); + int YToRow(int y, bool clipToMinMax = false) const; + + //@} + /** - Makes the cell at the specified location read-only or editable. + @name Miscellaneous Functions + */ + //@{ - @see IsReadOnly() + /** + Appends one or more new columns to the right of the grid. + + The @a updateLabels argument is not used at present. If you are using a + derived grid table class you will need to override + wxGridTableBase::AppendCols(). See InsertCols() for further + information. + + @return @true on success or @false if appending columns failed. */ - void SetReadOnly(int row, int col, bool isReadOnly = true); + bool AppendCols(int numCols = 1, bool updateLabels = true); /** - Sets the cell attributes for all cells in the specified row. + Appends one or more new rows to the bottom of the grid. - The grid takes ownership of the attribute pointer. + The @a updateLabels argument is not used at present. If you are using a + derived grid table class you will need to override + wxGridTableBase::AppendRows(). See InsertRows() for further + information. - See the wxGridCellAttr class for more information about controlling - cell attributes. + @return @true on success or @false if appending rows failed. */ - void SetRowAttr(int row, wxGridCellAttr* attr); + bool AppendRows(int numRows = 1, bool updateLabels = true); /** - Sets the horizontal and vertical alignment of row label text. + Return @true if the horizontal grid lines stop at the last column + boundary or @false if they continue to the end of the window. - Horizontal alignment should be one of @c wxALIGN_LEFT, @c - wxALIGN_CENTRE or @c wxALIGN_RIGHT. - Vertical alignment should be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE - or @c wxALIGN_BOTTOM. - */ - void SetRowLabelAlignment(int horiz, int vert); + The default is to clip grid lines. + + @see ClipHorzGridLines(), AreVertGridLinesClipped() + */ + bool AreHorzGridLinesClipped() const; /** - Sets the width of the row labels. + Return @true if the vertical grid lines stop at the last row + boundary or @false if they continue to the end of the window. - If @a width equals @c wxGRID_AUTOSIZE then width is calculated - automatically so that no label is truncated. Note that this could be - slow for a large table. - */ - void SetRowLabelSize(int width); + The default is to clip grid lines. + + @see ClipVertGridLines(), AreHorzGridLinesClipped() + */ + bool AreVertGridLinesClipped() const; /** - Sets the value for the given row label. + Increments the grid's batch count. - If you are using a derived grid table you must override - wxGridTableBase::SetRowLabelValue for this to have any effect. + When the count is greater than zero repainting of the grid is + suppressed. Each call to BeginBatch must be matched by a later call to + EndBatch(). Code that does a lot of grid modification can be enclosed + between BeginBatch() and EndBatch() calls to avoid screen flicker. The + final EndBatch() call will cause the grid to be repainted. + + Notice that you should use wxGridUpdateLocker which ensures that there + is always a matching EndBatch() call for this BeginBatch() if possible + instead of calling this method directly. */ - void SetRowLabelValue(int row, const wxString& value); + void BeginBatch(); /** - Sets the minimal row height used by default. + Clears all data in the underlying grid table and repaints the grid. - See SetColMinimalAcceptableWidth() for more information. + The table is not deleted by this function. If you are using a derived + table class then you need to override wxGridTableBase::Clear() for this + function to have any effect. */ - void SetRowMinimalAcceptableHeight(int height); + void ClearGrid(); /** - Sets the minimal height for the specified row. + Change whether the horizontal grid lines are clipped by the end of the + last column. - See SetColMinimalWidth() for more information. - */ - void SetRowMinimalHeight(int row, int height); + By default the grid lines are not drawn beyond the end of the last + column but after calling this function with @a clip set to @false they + will be drawn across the entire grid window. + + @see AreHorzGridLinesClipped(), ClipVertGridLines() + */ + void ClipHorzGridLines(bool clip); /** - Sets the height of the specified row. + Change whether the vertical grid lines are clipped by the end of the + last row. - See SetColSize() for more information. - */ - void SetRowSize(int row, int height); + By default the grid lines are not drawn beyond the end of the last + row but after calling this function with @a clip set to @false they + will be drawn across the entire grid window. + + @see AreVertGridLinesClipped(), ClipHorzGridLines() + */ + void ClipVertGridLines(bool clip); /** - Sets the number of pixels per horizontal scroll increment. + Deletes one or more columns from a grid starting at the specified + position. - The default is 15. + The @a updateLabels argument is not used at present. If you are using a + derived grid table class you will need to override + wxGridTableBase::DeleteCols(). See InsertCols() for further + information. - @see GetScrollLineX(), GetScrollLineY(), SetScrollLineY() + @return @true on success or @false if deleting columns failed. */ - void SetScrollLineX(int x); + bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true); /** - Sets the number of pixels per vertical scroll increment. + Deletes one or more rows from a grid starting at the specified + position. - The default is 15. + The @a updateLabels argument is not used at present. If you are using a + derived grid table class you will need to override + wxGridTableBase::DeleteRows(). See InsertRows() for further + information. - @see GetScrollLineX(), GetScrollLineY(), SetScrollLineX() + @return @true on success or @false if appending rows failed. */ - void SetScrollLineY(int y); + bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true); /** - Set the colour to be used for drawing the selection background. + Decrements the grid's batch count. + + When the count is greater than zero repainting of the grid is + suppressed. Each previous call to BeginBatch() must be matched by a + later call to EndBatch(). Code that does a lot of grid modification can + be enclosed between BeginBatch() and EndBatch() calls to avoid screen + flicker. The final EndBatch() will cause the grid to be repainted. + + @see wxGridUpdateLocker */ - void SetSelectionBackground(const wxColour& c); + void EndBatch(); /** - Set the colour to be used for drawing the selection foreground. + Overridden wxWindow method. */ - void SetSelectionForeground(const wxColour& c); + virtual void Fit(); /** - Set the selection behaviour of the grid. + Causes immediate repainting of the grid. - The existing selection is converted to conform to the new mode if - possible and discarded otherwise (e.g. any individual selected cells - are deselected if the new mode allows only the selection of the entire - rows or columns). + Use this instead of the usual wxWindow::Refresh(). */ - void SetSelectionMode(wxGridSelectionModes selmode); + void ForceRefresh(); /** - Passes a pointer to a custom grid table to be used by the grid. + Returns the number of times that BeginBatch() has been called without + (yet) matching calls to EndBatch(). While the grid's batch count is + greater than zero the display will not be updated. + */ + int GetBatchCount(); - This should be called after the grid constructor and before using the - grid object. If @a takeOwnership is set to @true then the table will be - deleted by the wxGrid destructor. + /** + Returns the total number of grid columns. - Use this function instead of CreateGrid() when your application - involves complex or non-string data or data sets that are too large to - fit wholly in memory. + This is the same as the number of columns in the underlying grid table. */ - bool SetTable(wxGridTableBase* table, - bool takeOwnership = false, - wxGridSelectionModes selmode = wxGridSelectCells); + int GetNumberCols() const; /** - Call this in order to make the column labels use a native look by using - wxRenderer::DrawHeaderButton internally. + Returns the total number of grid rows. - There is no equivalent method for drawing row columns as there is not - native look for that. This option is useful when using wxGrid for - displaying tables and not as a spread-sheet. + This is the same as the number of rows in the underlying grid table. */ - void SetUseNativeColLabels(bool native = true); + int GetNumberRows() const; /** - Displays the in-place cell edit control for the current cell. + Returns the attribute for the given cell creating one if necessary. + + If the cell already has an attribute, it is returned. Otherwise a new + attribute is created, associated with the cell and returned. In any + case the caller must call DecRef() on the returned pointer. + + This function may only be called if CanHaveAttributes() returns @true. */ - void ShowCellEditControl(); + wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; /** - Returns the column at the given pixel position. + Returns a base pointer to the current table object. - @param x - The x position to evaluate. - @param clipToMinMax - If @true, rather than returning wxNOT_FOUND, it returns either the - first or last column depending on whether x is too far to the left - or right respectively. - @return - The column index or wxNOT_FOUND. + The returned pointer is still owned by the grid. */ - int XToCol(int x, bool clipToMinMax = false) const; + wxGridTableBase *GetTable() const; /** - Returns the column whose right hand edge is close to the given logical - x position. + Inserts one or more new columns into a grid with the first new column + at the specified position. - If no column edge is near to this position @c wxNOT_FOUND is returned. + Notice that inserting the columns in the grid requires grid table + cooperation: when this method is called, grid object begins by + requesting the underlying grid table to insert new columns. If this is + successful the table notifies the grid and the grid updates the + display. For a default grid (one where you have called CreateGrid()) + this process is automatic. If you are using a custom grid table + (specified with SetTable()) then you must override + wxGridTableBase::InsertCols() in your derived table class. + + @param pos + The position which the first newly inserted column will have. + @param numCols + The number of columns to insert. + @param updateLabels + Currently not used. + @return + @true if the columns were successfully inserted, @false if an error + occurred (most likely the table couldn't be updated). */ - int XToEdgeOfCol(int x) const; + bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true); - //@{ /** - Translates logical pixel coordinates to the grid cell coordinates. - - Notice that this function expects logical coordinates on input so if - you use this function in a mouse event handler you need to translate - the mouse position, which is expressed in device coordinates, to - logical ones. + Inserts one or more new rows into a grid with the first new row at the + specified position. - @see XToCol(), YToRow() - */ + Notice that you must implement wxGridTableBase::InsertRows() if you use + a grid with a custom table, please see InsertCols() for more + information. - // XYToCell(int, int, wxGridCellCoords&) overload is intentionally - // undocumented, using it is ugly and non-const reference parameters are - // not used in wxWidgets API + @param pos + The position which the first newly inserted row will have. + @param numRows + The number of rows to insert. + @param updateLabels + Currently not used. + @return + @true if the rows were successfully inserted, @false if an error + occurred (most likely the table couldn't be updated). + */ + bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true); - wxGridCellCoords XYToCell(int x, int y) const; - wxGridCellCoords XYToCell(const wxPoint& pos) const; + /** + Sets the cell attributes for all cells in the specified column. - //@} + For more information about controlling grid cell attributes see the + wxGridCellAttr cell attribute class and the @ref overview_grid. + */ + void SetColAttr(int col, wxGridCellAttr* attr); /** - Returns the row whose bottom edge is close to the given logical y - position. + Sets the extra margins used around the grid area. - If no row edge is near to this position @c wxNOT_FOUND is returned. + A grid may occupy more space than needed for its data display and + this function allows to set how big this extra space is */ - int YToEdgeOfRow(int y) const; + void SetMargins(int extraWidth, int extraHeight); /** - Returns the grid row that corresponds to the logical y coordinate. + Sets the cell attributes for all cells in the specified row. - Returns @c wxNOT_FOUND if there is no row at the y position. + The grid takes ownership of the attribute pointer. + + See the wxGridCellAttr class for more information about controlling + cell attributes. */ - int YToRow(int y, bool clipToMinMax = false) const; + void SetRowAttr(int row, wxGridCellAttr* attr); + + //@} protected: /**