]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxGridUpdateLocker helper class wrapping Begin/EndBatch() calls in a more conve...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 15 Mar 2007 17:25:15 +0000 (17:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 15 Mar 2007 17:25:15 +0000 (17:25 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44833 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/classes.tex
docs/latex/wx/grid.tex
docs/latex/wx/gupdlock.tex [new file with mode: 0644]
include/wx/generic/grid.h
samples/grid/griddemo.cpp
src/common/dbgrid.cpp
src/generic/grid.cpp

index 0dc9025a390dacc3b30d9217ca5fdb1633e2aae8..0ea04eb93fac7a3369f6d5494a1210400eedf4ef 100644 (file)
@@ -39,6 +39,7 @@ All:
 - Fixed crashes in helpview when opening a file.
 - Added wxMutex::LockTimeout() (Aleksandr Napylov)
 - Set locale to the default in all ports, not just wxGTK
 - Fixed crashes in helpview when opening a file.
 - Added wxMutex::LockTimeout() (Aleksandr Napylov)
 - Set locale to the default in all ports, not just wxGTK
+- Added wxGridUpdateLocker helper class (Evgeniy Tarassov)
 
 wxGTK:
 
 
 wxGTK:
 
index 50f5926823e8c2bb005164514f208fceb8b33c89..5046e4ceaac21cdbf0096b86340cb1c73c173f44 100644 (file)
 \input gridrend.tex
 \input gridtbl.tex
 \input gridsizr.tex
 \input gridrend.tex
 \input gridtbl.tex
 \input gridsizr.tex
+\input gupdlock.tex
 \input hashmap.tex
 \input hashset.tex
 \input hash.tex
 \input hashmap.tex
 \input hashset.tex
 \input hash.tex
index 0231c365d0ab95b2ea1d125068dc1d7e28d1548a..62b640cda8ac26a368bed656257a6562e53685af 100644 (file)
@@ -253,6 +253,10 @@ the grid is suppressed. Each call to BeginBatch must be matched by a later call
 modification can be enclosed between BeginBatch and EndBatch calls to avoid
 screen flicker. The final EndBatch will cause the grid to be repainted.
 
 modification can be enclosed between BeginBatch and EndBatch calls to avoid
 screen flicker. The final EndBatch will cause the grid to be repainted.
 
+\wxheading{See also}
+
+\helpref{wxGridUpdateLocker}{wxgridupdatelocker}
+
 
 
 \membersection{wxGrid::BlockToDeviceRect}\label{wxgridblocktodevicerect}
 
 
 \membersection{wxGrid::BlockToDeviceRect}\label{wxgridblocktodevicerect}
@@ -514,6 +518,10 @@ 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.
 
 BeginBatch and EndBatch calls to avoid screen flicker. The final EndBatch will
 cause the grid to be repainted.
 
+\wxheading{See also}
+
+\helpref{wxGridUpdateLocker}{wxgridupdatelocker}
+
 
 
 \membersection{wxGrid::Fit}\label{wxgridfit}
 
 
 \membersection{wxGrid::Fit}\label{wxgridfit}
diff --git a/docs/latex/wx/gupdlock.tex b/docs/latex/wx/gupdlock.tex
new file mode 100644 (file)
index 0000000..f0c6a3c
--- /dev/null
@@ -0,0 +1,81 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Name:        gupdlock.tex
+%% Purpose:     wxGridUpdateLocker documentation
+%% Author:      Evgeniy Tarassov
+%% Created:     2007-03-15
+%% RCS-ID:      $Id$
+%% Copyright:   (c) 2007 TT-Solutions SARL
+%% License:     wxWindows license
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\section{\class{wxGridUpdateLocker}}\label{wxgridupdatelocker}
+
+This small class can be used to prevent \helpref{wxGrid}{wxgrid} from redrawing
+during its lifetime by calling \helpref{wxGrid::BeginBatch}{wxgridbeginbatch}
+in its constructor and \helpref{wxGrid::EndBatch}{wxgridendbatch} in its
+destructor. It is typically used in a function performing several operations
+with a grid which would otherwise result in flicker. For example:
+
+{\small
+\begin{verbatim}
+    void MyFrame::Foo()
+    {
+        m_grid = new wxGrid(this, ...);
+
+        wxGridUpdateLocker noUpdates(m_grid);
+        m_grid->AppendColumn();
+        ... many other operations with m_grid...
+        m_grid->AppendRow();
+
+        // destructor called, grid refreshed
+    }
+\end{verbatim}
+}
+
+Using this class is easier and safer than calling 
+\helpref{BeginBatch}{wxgridbeginbatch} and \helpref{EndBatch}{wxgridendbatch}
+because you don't risk not to call the latter (due to an exception for example).
+
+\wxheading{Derived from}
+
+None.
+
+\wxheading{Include files}
+
+<wx/grid.h>
+
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+
+\membersection{wxGridUpdateLocker::wxGridUpdateLocker}\label{wxgridupdatelockerctor}
+
+\func{}{wxGridUpdateLocker}{\param{wxGrid *}{grid = \NULL}}
+
+Creates an object preventing the updates of the specified \arg{grid}. The
+parameter could be \NULL in which case nothing is done. If \arg{grid} is
+non-\NULL then the grid must exist for longer than wxGridUpdateLocker object
+itself.
+
+The default constructor could be followed by a call to 
+\helpref{wxGridUpdateLocker::Create}{wxgridupdatelockercreate} to set the
+grid object later.
+
+
+
+\membersection{wxGridUpdateLocker::\destruct{wxGridUpdateLocker}}\label{wxgridupdatelockerdtor}
+
+\func{}{\destruct{wxGridUpdateLocker}}{\void}
+
+Destructor reenables updates for the grid this object is associated with.
+
+
+
+\membersection{wxGridUpdateLocker::Create}\label{wxgridupdatelockercreate}
+
+\func{void}{Create}{\param{wxGrid* }{grid}}
+
+This method can be called if the object had been constructed using the default
+constructor. It must not be called more than once.
+
+
index 4229751aa1a95e9dc2e43d79a0fea528b6d23668..2d04e59b6c649215b638a8228c3360825e3d9f9b 100644 (file)
@@ -2007,6 +2007,47 @@ protected:
 };
 
 
 };
 
 
+// ----------------------------------------------------------------------------
+// wxGridUpdateLocker prevents updates to a grid during its lifetime
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_ADV wxGridUpdateLocker
+{
+public:
+    // if the pointer is NULL, Create() can be called later
+    wxGridUpdateLocker(wxGrid *grid = NULL)
+    {
+        Init(grid);
+    }
+
+    // can be called if ctor was used with a NULL pointer, must not be called
+    // more than once
+    void Create(wxGrid *grid)
+    {
+        wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") );
+
+        Init(grid);
+    }
+
+    ~wxGridUpdateLocker()
+    {
+        if ( m_grid )
+            m_grid->EndBatch();
+    }
+
+private:
+    void Init(wxGrid *grid)
+    {
+        m_grid = grid;
+        if ( m_grid )
+            m_grid->BeginBatch();
+    }
+
+    wxGrid *m_grid;
+
+    DECLARE_NO_COPY_CLASS(wxGridUpdateLocker)
+};
+
 // ----------------------------------------------------------------------------
 // Grid event class and event types
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Grid event class and event types
 // ----------------------------------------------------------------------------
index 387fb57614446342c6b282f5ab21f7f4b76b13a5..85867844affc194157a7dd15d6c726cfc8b14923 100644 (file)
@@ -668,7 +668,7 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
 {
     if ( grid->IsSelection() )
     {
 {
     if ( grid->IsSelection() )
     {
-        grid->BeginBatch();
+        wxGridUpdateLocker locker(grid);
         for ( int n = 0; n < grid->GetNumberRows(); )
         {
             if ( grid->IsInSelection( n , 0 ) )
         for ( int n = 0; n < grid->GetNumberRows(); )
         {
             if ( grid->IsInSelection( n , 0 ) )
@@ -676,7 +676,6 @@ void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
             else
                 n++;
         }
             else
                 n++;
         }
-        grid->EndBatch();
     }
 }
 
     }
 }
 
@@ -685,7 +684,7 @@ void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
 {
     if ( grid->IsSelection() )
     {
 {
     if ( grid->IsSelection() )
     {
-        grid->BeginBatch();
+        wxGridUpdateLocker locker(grid);
         for ( int n = 0; n < grid->GetNumberCols(); )
         {
             if ( grid->IsInSelection( 0 , n ) )
         for ( int n = 0; n < grid->GetNumberCols(); )
         {
             if ( grid->IsInSelection( 0 , n ) )
@@ -693,7 +692,6 @@ void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
             else
                 n++;
         }
             else
                 n++;
         }
-        grid->EndBatch();
     }
 }
 
     }
 }
 
index d8b13172a32ee901937d026df42ef5706f91d04b..634be020d86bc7e42dddf0a28f3732e90493a27e 100644 (file)
@@ -203,11 +203,12 @@ bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwners
 {
     wxDbGridCellAttrProvider *provider;
 
 {
     wxDbGridCellAttrProvider *provider;
 
+    wxGridUpdateLocker locker(GetView());
+
     //Remove Information from grid about old data
     if (GetView())
     {
         wxGrid *grid = GetView();
     //Remove Information from grid about old data
     if (GetView())
     {
         wxGrid *grid = GetView();
-        grid->BeginBatch();
         grid->ClearSelection();
         if (grid->IsCellEditControlEnabled())
         {
         grid->ClearSelection();
         if (grid->IsCellEditControlEnabled())
         {
@@ -250,7 +251,6 @@ bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwners
         wxGrid * grid = GetView();
         wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rowtotal);
         grid->ProcessTableMessage(msg);
         wxGrid * grid = GetView();
         wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rowtotal);
         grid->ProcessTableMessage(msg);
-        grid->EndBatch();
     }
     m_dbowner = takeOwnership;
     m_rowmodified = false;
     }
     m_dbowner = takeOwnership;
     m_rowmodified = false;
index 20121718e06a36efa51c00ea8bb6e62e6392a460..e8ef3ce6dd19d05d60bdd23454cef36621d26f3d 100644 (file)
@@ -10595,8 +10595,9 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
 {
     int width = m_rowLabelWidth;
 
 {
     int width = m_rowLabelWidth;
 
-    if ( !calcOnly )
-        BeginBatch();
+    wxGridUpdateLocker locker;
+    if(!calcOnly)
+        locker.Create(this);
 
     for ( int col = 0; col < m_numCols; col++ )
     {
 
     for ( int col = 0; col < m_numCols; col++ )
     {
@@ -10606,9 +10607,6 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin)
         width += GetColWidth(col);
     }
 
         width += GetColWidth(col);
     }
 
-    if ( !calcOnly )
-        EndBatch();
-
     return width;
 }
 
     return width;
 }
 
@@ -10616,8 +10614,9 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
 {
     int height = m_colLabelHeight;
 
 {
     int height = m_colLabelHeight;
 
-    if ( !calcOnly )
-        BeginBatch();
+    wxGridUpdateLocker locker;
+    if(!calcOnly)
+        locker.Create(this);
 
     for ( int row = 0; row < m_numRows; row++ )
     {
 
     for ( int row = 0; row < m_numRows; row++ )
     {
@@ -10627,15 +10626,12 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin)
         height += GetRowHeight(row);
     }
 
         height += GetRowHeight(row);
     }
 
-    if ( !calcOnly )
-        EndBatch();
-
     return height;
 }
 
 void wxGrid::AutoSize()
 {
     return height;
 }
 
 void wxGrid::AutoSize()
 {
-    BeginBatch();
+    wxGridUpdateLocker locker(this);
 
     // we need to round up the size of the scrollable area to a multiple of
     // scroll step to ensure that we don't get the scrollbars when we're sized
 
     // we need to round up the size of the scrollable area to a multiple of
     // scroll step to ensure that we don't get the scrollbars when we're sized
@@ -10701,8 +10697,6 @@ void wxGrid::AutoSize()
     // client size but also leave space for (not needed any more) scrollbars
     SetScrollbars(0, 0, 0, 0, 0, 0, true);
     SetClientSize(sizeFit.x + m_rowLabelWidth, sizeFit.y + m_colLabelHeight);
     // client size but also leave space for (not needed any more) scrollbars
     SetScrollbars(0, 0, 0, 0, 0, 0, true);
     SetClientSize(sizeFit.x + m_rowLabelWidth, sizeFit.y + m_colLabelHeight);
-
-    EndBatch();
 }
 
 void wxGrid::AutoSizeRowLabelSize( int row )
 }
 
 void wxGrid::AutoSizeRowLabelSize( int row )