]> git.saurik.com Git - wxWidgets.git/commitdiff
Initializing more variables in wxGrid::Create()
authorMichael Bedward <mbedward@ozemail.com.au>
Wed, 9 Feb 2000 05:04:21 +0000 (05:04 +0000)
committerMichael Bedward <mbedward@ozemail.com.au>
Wed, 9 Feb 2000 05:04:21 +0000 (05:04 +0000)
Minor fixes for crashes under wxMotif when setting attributes before
the grid has been first painted.

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

include/wx/generic/grid.h
src/generic/grid.cpp

index 61912549dc979a4e2a2763b319e77d95f90c1ef6..b97ba5933efcf02b273f7a22c13309cc4d4b9cee 100644 (file)
@@ -449,7 +449,7 @@ public:
 
     void DrawGridCellArea( wxDC& dc );
     void DrawCellBorder( wxDC& dc, const wxGridCellCoords& );
-    void DrawAllGridLines( wxDC& dc, const wxRegion & reg = wxRegion() );
+    void DrawAllGridLines( wxDC& dc, const wxRegion & reg );
     void DrawCell( wxDC& dc, const wxGridCellCoords& );
     void DrawCellBackground( wxDC& dc, const wxGridCellCoords& );
     void DrawCellValue( wxDC& dc, const wxGridCellCoords& );
@@ -859,6 +859,7 @@ public:
 
 protected:
     bool m_created;
+    bool m_displayed;
 
     wxGridWindow             *m_gridWin;
     wxGridRowLabelWindow     *m_rowLabelWin;
index a999ea3e08a6717f7f331a6dacd0caf4e4ddf0b5..82eef22b3b40ede78a487310c32eb56a0ba4ff68 100644 (file)
@@ -940,6 +940,16 @@ wxGrid::~wxGrid()
 
 void wxGrid::Create()
 {
+    m_created = FALSE;    // set to TRUE by CreateGrid
+    m_displayed = FALSE;  // set to TRUE by OnPaint
+
+    m_table        = (wxGridTableBase *) NULL;
+    m_cellEditCtrl = (wxWindow *) NULL;
+
+    m_numRows = 0;
+    m_numCols = 0;
+    m_currentCellCoords = wxGridNoCellCoords;
+    
     int colLblH = WXGRID_DEFAULT_COL_LABEL_HEIGHT;
     int rowLblW = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
 
@@ -1119,6 +1129,10 @@ void wxGrid::Init()
 
 void wxGrid::CalcDimensions()
 {
+    // This avoids a crash in SetScrollbars
+    //
+    if ( !m_displayed ) return;
+    
     int cw, ch;
     GetClientSize( &cw, &ch );
 
@@ -2381,6 +2395,8 @@ void wxGrid::OnPaint( wxPaintEvent& WXUNUSED(event) )
         SetEditControlValue();
         ShowCellEditControl();
     }
+
+    m_displayed = TRUE;
 }
 
 
@@ -2540,10 +2556,8 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
         return;
     }
 
-    wxClientDC dc( m_gridWin );
-    PrepareDC( dc );
-
-    if ( m_currentCellCoords != wxGridNoCellCoords )
+    if ( m_displayed  &&
+         m_currentCellCoords != wxGridNoCellCoords )
     {
         HideCellEditControl();
         SaveEditControlValue();
@@ -2552,13 +2566,17 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
     m_currentCellCoords = coords;
 
     SetEditControlValue();
-    ShowCellEditControl();
 
-    if ( IsSelection() )
+    if ( m_displayed )
     {
-        wxRect r( SelectionToDeviceRect() );
-        ClearSelection();
-        if ( !GetBatchCount() ) m_gridWin->Refresh( FALSE, &r );
+        ShowCellEditControl();
+
+        if ( IsSelection() )
+        {
+            wxRect r( SelectionToDeviceRect() );
+            ClearSelection();
+            if ( !GetBatchCount() ) m_gridWin->Refresh( FALSE, &r );
+        }
     }
 }