]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow hiding/showing already hidden/shown wxGrid rows/columns.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 12 Jan 2013 03:09:12 +0000 (03:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 12 Jan 2013 03:09:12 +0000 (03:09 +0000)
Don't assert if an already hidden/shown row/column is being hidden/shown again
but simply don't do anything. This is more convenient because the code outside
wxGrid has no efficient way to only hide a row/column if it's currently shown.

Closes #14960.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73366 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/grid.h
samples/grid/griddemo.cpp
samples/grid/griddemo.h
src/generic/grid.cpp

index a614af5b0ec65f9eecfed5c5220a12c106443237..0b15c437fbdd09c3bea6ef86976f375ba5499a63 100644 (file)
@@ -2988,8 +2988,7 @@ public:
         To show the column later you need to call SetColSize() with non-0
         width or ShowCol() to restore the previous column width.
 
-        Notice that this method shouldn't be called if the column is already
-        hidden.
+        If the column is already hidden, this method doesn't do anything.
 
         @param col
             The column index.
@@ -3002,8 +3001,7 @@ public:
         The column is shown again with the same width that it had before
         HideCol() call.
 
-        Notice that this method shouldn't be called if the column is not
-        currently hidden.
+        If the column is currently shown, this method doesn't do anything.
 
         @see HideCol(), SetColSize()
      */
@@ -3073,6 +3071,8 @@ public:
         To show the row later you need to call SetRowSize() with non-0
         width or ShowRow() to restore its original height.
 
+        If the row is already hidden, this method doesn't do anything.
+
         @param col
             The row index.
      */
@@ -3084,6 +3084,8 @@ public:
         The row is shown again with the same height that it had before
         HideRow() call.
 
+        If the row is currently shown, this method doesn't do anything.
+
         @see HideRow(), SetRowSize()
      */
     void ShowRow(int col);
index 35dcee999ac8921d2758a873bf7fb64b57741af3..f10c12a51c52d8a8a7ecec5d22e103e02a29bfd8 100644 (file)
@@ -211,6 +211,11 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
     EVT_MENU( ID_SIZE_LABELS_ROW, GridFrame::AutoSizeLabelsRow )
     EVT_MENU( ID_SIZE_GRID, GridFrame::AutoSizeTable )
 
+    EVT_MENU( ID_HIDECOL, GridFrame::HideCol )
+    EVT_MENU( ID_SHOWCOL, GridFrame::ShowCol )
+    EVT_MENU( ID_HIDEROW, GridFrame::HideRow )
+    EVT_MENU( ID_SHOWROW, GridFrame::ShowRow )
+
     EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth)
     EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth)
 
@@ -293,7 +298,10 @@ GridFrame::GridFrame()
     viewMenu->AppendCheckItem(ID_AUTOSIZECOLS, "&Auto-size cols");
     viewMenu->AppendCheckItem(ID_CELLOVERFLOW, "&Overflow cells");
     viewMenu->AppendCheckItem(ID_RESIZECELL, "&Resize cell (7,1)");
-
+    viewMenu->Append(ID_HIDECOL, "&Hide column A");
+    viewMenu->Append(ID_SHOWCOL, "&Show column A");
+    viewMenu->Append(ID_HIDEROW, "&Hide row 2");
+    viewMenu->Append(ID_SHOWROW, "&Show row 2");
     wxMenu *rowLabelMenu = new wxMenu;
 
     viewMenu->Append( ID_ROWLABELALIGN, wxT("R&ow label alignment"),
@@ -2309,3 +2317,23 @@ void GridFrame::OnRenderPaint( wxPaintEvent& event )
              m_gridBitmap.GetHeight(),
              &memDc, 0, 0 );
 }
+
+void GridFrame::HideCol( wxCommandEvent& WXUNUSED(event) )
+{
+    grid->HideCol(0);
+}
+
+void GridFrame::ShowCol( wxCommandEvent& WXUNUSED(event) )
+{
+    grid->ShowCol(0);
+}
+
+void GridFrame::HideRow( wxCommandEvent& WXUNUSED(event) )
+{
+    grid->HideRow(1);
+}
+
+void GridFrame::ShowRow( wxCommandEvent& WXUNUSED(event) )
+{
+    grid->ShowRow(1);
+}
index 88056141949637a69a0f97c8c95d911adc18441b..1303018c97aa20475a10f7d8f847a2bf2067c74c 100644 (file)
@@ -88,6 +88,12 @@ class GridFrame : public wxFrame
     void AutoSizeLabelsRow(wxCommandEvent& event);
     void AutoSizeTable(wxCommandEvent& event);
 
+    void HideCol(wxCommandEvent& event);
+    void ShowCol(wxCommandEvent& event);
+    void HideRow(wxCommandEvent& event);
+    void ShowRow(wxCommandEvent& event);
+
+
     void OnLabelLeftClick( wxGridEvent& );
     void OnCellLeftClick( wxGridEvent& );
     void OnRowSize( wxGridSizeEvent& );
@@ -131,6 +137,10 @@ public:
         ID_TOGGLEGRIDLINES,
         ID_AUTOSIZECOLS,
         ID_CELLOVERFLOW,
+        ID_HIDECOL,
+        ID_SHOWCOL,
+        ID_HIDEROW,
+        ID_SHOWROW,
         ID_RESIZECELL,
         ID_SETLABELCOLOUR,
         ID_SETLABELTEXTCOLOUR,
index 6e276fe316a79e83aaa687a1b9bb39b158426541..499e600b19851c3c856c0fba70ad6032055b3717 100644 (file)
@@ -8106,8 +8106,11 @@ int UpdateRowOrColSize(int& sizeCurrent, int sizeNew)
         // We're showing back a previously hidden row/column.
         wxASSERT_MSG( sizeNew == -1, wxS("New size must be positive or -1.") );
 
-        wxASSERT_MSG( sizeCurrent < 0, wxS("May only show back if hidden.") );
+        // If it's already visible, simply do nothing.
+        if ( sizeCurrent >= 0 )
+            return 0;
 
+        // Otherwise show it by restoring its old size.
         sizeCurrent = -sizeCurrent;
 
         // This is positive which is correct.
@@ -8116,8 +8119,13 @@ int UpdateRowOrColSize(int& sizeCurrent, int sizeNew)
     else if ( sizeNew == 0 )
     {
         // We're hiding a row/column.
-        wxASSERT_MSG( sizeCurrent > 0, wxS("Can't hide if already hidden.") );
 
+        // If it's already hidden, simply do nothing.
+        if ( sizeCurrent <= 0 )
+            return 0;
+
+        // Otherwise hide it and also remember the shown size to be able to
+        // restore it later.
         sizeCurrent = -sizeCurrent;
 
         // This is negative which is correct.