]> git.saurik.com Git - wxWidgets.git/blobdiff - interface/wx/grid.h
added wxHeaderCtrl::ResetColumnsOrder() function; use it from wxGrid
[wxWidgets.git] / interface / wx / grid.h
index 057ef18b7f11dd8aae7ce7dc274a0359c806e093..9072c1992c1200cb1b40ea8b0c5d50847fd84322 100644 (file)
@@ -673,9 +673,14 @@ public:
     //@{
 
     /**
-        Must be overridden to implement testing for empty cells.
+        May be overridden to implement testing for empty cells.
+
+        This method is used by the grid to test if the given cell is not used
+        and so whether a neighbouring cell may overflow into it. By default it
+        only returns true if the value of the given cell, as returned by
+        GetValue(), is empty.
      */
-    virtual bool IsEmptyCell(int row, int col) = 0;
+    virtual bool IsEmptyCell(int row, int col);
 
     /**
         Same as IsEmptyCell() but taking wxGridCellCoords.
@@ -1376,9 +1381,36 @@ public:
         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.
+
+        @see UseNativeHeader()
     */
     void SetUseNativeColLabels(bool native = true);
 
+    /**
+        Enable the use of native header window for column labels.
+
+        If this function is called with @true argument, a wxHeaderCtrl is used
+        instead to display the column labels instead of drawing them in wxGrid
+        code itself. This has the advantage of making the grid look and feel
+        perfectly the same as native applications (using SetUseNativeColLabels()
+        the grid can be made to look more natively but it still doesn't feel
+        natively, notably the column resizing and dragging still works slightly
+        differently as it is implemented in wxWidgets itself) but results in
+        different behaviour for column and row headers, for which there is no
+        equivalent function, and, most importantly, is unsuitable for grids
+        with huge numbers of columns as wxHeaderCtrl doesn't support virtual
+        mode. Because of this, by default the grid does not use the native
+        header control but you should call this function to enable it if you
+        are using the grid to display tabular data and don't have thousands of
+        columns in it.
+
+        Also note that currently @c wxEVT_GRID_LABEL_LEFT_DCLICK and @c
+        wxEVT_GRID_LABEL_RIGHT_DCLICK events are not generated for the column
+        labels if the native columns header is used (but this limitation could
+        possibly be lifted in the future).
+     */
+    void UseNativeColHeader(bool native = true);
+
     //@}
 
 
@@ -2053,17 +2085,33 @@ public:
     /**
         Sets the width of the specified column.
 
-        Notice that this function does not refresh the grid, you need to call
-        ForceRefresh() to make the changes take effect immediately.
-
         @param col
             The column index.
         @param width
-            The new column width in pixels or a negative value to fit the
-            column width to its label width.
+            The new column width in pixels, 0 to hide the column or -1 to fit
+            the column width to its label width.
     */
     void SetColSize(int col, int width);
 
+    /**
+        Hides the specified column.
+
+        To show the column later you need to call SetColSize() with non-0
+        width or ShowCol().
+
+        @param col
+            The column index.
+     */
+    void HideCol(int col);
+
+    /**
+        Shows the previously hidden column by resizing it to non-0 size.
+
+        @see HideCol(), SetColSize()
+     */
+    void ShowCol(int col);
+
+
     /**
         Sets the default width for columns in the grid.
 
@@ -2116,6 +2164,24 @@ public:
     */
     void SetRowSize(int row, int height);
 
+    /**
+        Hides the specified row.
+
+        To show the row later you need to call SetRowSize() with non-0
+        width or ShowRow().
+
+        @param col
+            The row index.
+     */
+    void HideRow(int col);
+
+    /**
+        Shows the previously hidden row by resizing it to non-0 size.
+
+        @see HideRow(), SetRowSize()
+     */
+    void ShowRow(int col);
+
     //@}
 
 
@@ -2229,6 +2295,11 @@ public:
     */
     void SetColPos(int colID, int newPos);
 
+    /**
+        Resets the position of the columns to the default.
+     */
+    void ResetColPos();
+
     //@}
 
 
@@ -3024,6 +3095,77 @@ protected:
         called for this row.
     */
     int GetRowMinimalHeight(int col) const;
+
+
+    /**
+        @name Sorting support.
+
+        wxGrid doesn't provide any support for sorting the data but it does
+        generate events allowing the user code to sort it and supports
+        displaying the sort indicator in the column used for sorting.
+
+        To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT
+        event (and not veto it) and resort the data displayed in the grid. The
+        grid will automatically update the sorting indicator on the column
+        which was clicked.
+
+        You can also call the functions in this section directly to update the
+        sorting indicator. Once again, they don't do anything with the grid
+        data, it remains your responsibility to actually sort it appropriately.
+     */
+    //@{
+
+    /**
+        Return the column in which the sorting indicator is currently
+        displayed.
+
+        Returns @c wxNOT_FOUND if sorting indicator is not currently displayed
+        at all.
+
+        @see SetSortingColumn()
+     */
+    int GetSortingColumn() const;
+
+    /**
+        Return @true if this column is currently used for sorting.
+
+        @see GetSortingColumn()
+     */
+    bool IsSortingBy(int col) const;
+
+    /**
+        Return @true if the current sorting order is ascending or @false if it
+        is descending.
+
+        It only makes sense to call this function if GetSortingColumn() returns
+        a valid column index and not @c wxNOT_FOUND.
+
+        @see SetSortingColumn()
+     */
+    bool IsSortOrderAscending() const;
+
+    /**
+        Set the column to display the sorting indicator in and its direction.
+
+        @param col
+            The column to display the sorting indicator in or @c wxNOT_FOUND to
+            remove any currently displayed sorting indicator.
+        @param ascending
+            If @true, display the ascending sort indicator, otherwise display
+            the descending sort indicator.
+
+        @see GetSortingColumn(), IsSortOrderAscending()
+     */
+    void SetSortingColumn(int col, bool ascending = true);
+
+    /**
+        Remove any currently shown sorting indicator.
+
+        This is equivalent to calling SetSortingColumn() with @c wxNOT_FOUND
+        first argument.
+     */
+    void UnsetSortingColumn();
+    //@}
 };
 
 
@@ -3092,6 +3234,17 @@ public:
 
     This event class contains information about various grid events.
 
+    Notice that all grid event table macros are available in two versions:
+    @c EVT_GRID_XXX and @c EVT_GRID_CMD_XXX. The only difference between the
+    two is that the former doesn't allow to specify the grid window identifier
+    and so takes a single parameter, the event handler, but is not suitable if
+    there is more than one grid control in the window where the event table is
+    used (as it would catch the events from all the grids). The version with @c
+    CMD takes the id as first argument and the event handler as the second one
+    and so can be used with multiple grids as well. Otherwise there are no
+    difference between the two and only the versions without the id are
+    documented below for brevity.
+
     @beginEventTable{wxGridEvent}
     @event{EVT_GRID_CELL_CHANGE(func)}
         The user changed the data in a cell. Processes a
@@ -3129,50 +3282,30 @@ public:
     @event{EVT_GRID_SELECT_CELL(func)}
         The user moved to, and selected a cell. Processes a
         @c wxEVT_GRID_SELECT_CELL event type.
-    @event{EVT_GRID_CMD_CELL_CHANGE(id, func)}
-        The user changed the data in a cell; variant taking a window
-        identifier. Processes a @c wxEVT_GRID_CELL_CHANGE event type.
-    @event{EVT_GRID_CMD_CELL_LEFT_CLICK(id, func)}
-        The user clicked a cell with the left mouse button; variant taking a
-        window identifier. Processes a @c wxEVT_GRID_CELL_LEFT_CLICK event
-        type.
-    @event{EVT_GRID_CMD_CELL_LEFT_DCLICK(id, func)}
-        The user double-clicked a cell with the left mouse button; variant
-        taking a window identifier. Processes a @c wxEVT_GRID_CELL_LEFT_DCLICK
-        event type.
-    @event{EVT_GRID_CMD_CELL_RIGHT_CLICK(id, func)}
-        The user clicked a cell with the right mouse button; variant taking a
-        window identifier. Processes a @c wxEVT_GRID_CELL_RIGHT_CLICK event
-        type.
-    @event{EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, func)}
-        The user double-clicked a cell with the right mouse button; variant
-        taking a window identifier. Processes a @c wxEVT_GRID_CELL_RIGHT_DCLICK
-        event type.
-    @event{EVT_GRID_CMD_EDITOR_HIDDEN(id, func)}
-        The editor for a cell was hidden; variant taking a window identifier.
-        Processes a @c wxEVT_GRID_EDITOR_HIDDEN event type.
-    @event{EVT_GRID_CMD_EDITOR_SHOWN(id, func)}
-        The editor for a cell was shown; variant taking a window identifier.
-        Processes a @c wxEVT_GRID_EDITOR_SHOWN event type.
-    @event{EVT_GRID_CMD_LABEL_LEFT_CLICK(id, func)}
-        The user clicked a label with the left mouse button; variant taking a
-        window identifier. Processes a @c wxEVT_GRID_LABEL_LEFT_CLICK event
-        type.
-    @event{EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, func)}
-        The user double-clicked a label with the left mouse button; variant
-        taking a window identifier. Processes a @c wxEVT_GRID_LABEL_LEFT_DCLICK
-        event type.
-    @event{EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, func)}
-        The user clicked a label with the right mouse button; variant taking a
-        window identifier. Processes a @c wxEVT_GRID_LABEL_RIGHT_CLICK event
-        type.
-    @event{EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, func)}
-        The user double-clicked a label with the right mouse button; variant
-        taking a window identifier. Processes a
-        @c wxEVT_GRID_LABEL_RIGHT_DCLICK event type.
-    @event{EVT_GRID_CMD_SELECT_CELL(id, func)}
-        The user moved to, and selected a cell; variant taking a window
-        identifier. Processes a @c wxEVT_GRID_SELECT_CELL event type.
+    @event{EVT_GRID_COL_MOVE(func)}
+        The user tries to change the order of the columns in the grid by
+        dragging the column specified by GetCol(). This event can be vetoed to
+        either prevent the user from reordering the column change completely
+        (but notice that if you don't want to allow it at all, you simply
+        shouldn't call wxGrid::EnableDragColMove() in the first place), vetoed
+        but handled in some way in the handler, e.g. by really moving the
+        column to the new position at the associated table level, or allowed to
+        proceed in which case wxGrid::SetColPos() is used to reorder the
+        columns display order without affecting the use of the column indices
+        otherwise.
+
+        This event macro corresponds to @c wxEVT_GRID_COL_MOVE event type.
+    @event{EVT_GRID_COL_SORT(func)}
+        This event is generated when a column is clicked by the user and its
+        name is explained by the fact that the custom reaction to a click on a
+        column is to sort the grid contents by this column. However the grid
+        itself has no special support for sorting and it's up to the handler of
+        this event to update the associated table. But if the event is handled
+        (and not vetoed) the grid supposes that the table was indeed resorted
+        and updates the column to indicate the new sort order and refreshes
+        itself.
+
+        This event macro corresponds to @c wxEVT_GRID_COL_SORT event type.
     @endEventTable
 
     @library{wxadv}