check whether the grid is fully created in Refresh() (fixes a crash under Mac); refactored members initialization into a new InitVars() method to avoid duplication and ensure that they're always initialized (slightly modified patch 1901366)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52122 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-02-26 17:17:28 +00:00
parent 8d788b830c
commit f954984155
2 changed files with 25 additions and 16 deletions

View File

@@ -1090,9 +1090,9 @@ WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray,
class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow
{ {
public: public:
wxGrid() ; wxGrid();
wxGrid( wxWindow *parent, wxGrid( wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@@ -1645,6 +1645,7 @@ public:
: wxScrolledWindow( parent, wxID_ANY, wxPoint(x,y), wxSize(w,h), : wxScrolledWindow( parent, wxID_ANY, wxPoint(x,y), wxSize(w,h),
(style|wxWANTS_CHARS), name ) (style|wxWANTS_CHARS), name )
{ {
InitVars();
Create(); Create();
} }
@@ -1989,6 +1990,7 @@ protected:
void Create(); void Create();
void Init(); void Init();
void InitVars();
void CalcDimensions(); void CalcDimensions();
void CalcWindowSizes(); void CalcWindowSizes();
bool Redimension( wxGridTableMessage& ); bool Redimension( wxGridTableMessage& );

View File

@@ -4131,12 +4131,7 @@ END_EVENT_TABLE()
wxGrid::wxGrid() wxGrid::wxGrid()
{ {
// in order to make sure that a size event is not InitVars();
// trigerred in a unfinished state
m_cornerLabelWin = NULL;
m_rowLabelWin = NULL;
m_colLabelWin = NULL;
m_gridWin = NULL;
} }
wxGrid::wxGrid( wxWindow *parent, wxGrid::wxGrid( wxWindow *parent,
@@ -4146,6 +4141,7 @@ wxGrid::wxGrid( wxWindow *parent,
long style, long style,
const wxString& name ) const wxString& name )
{ {
InitVars();
Create(parent, id, pos, size, style, name); Create(parent, id, pos, size, style, name);
} }
@@ -4203,15 +4199,8 @@ wxGrid::~wxGrid()
void wxGrid::Create() void wxGrid::Create()
{ {
// set to true by CreateGrid
m_created = false;
// create the type registry // create the type registry
m_typeRegistry = new wxGridTypeRegistry; m_typeRegistry = new wxGridTypeRegistry;
m_selection = NULL;
m_table = (wxGridTableBase *) NULL;
m_ownTable = false;
m_cellEditCtrlEnabled = false; m_cellEditCtrlEnabled = false;
@@ -4405,6 +4394,24 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership,
return m_created; return m_created;
} }
void wxGrid::InitVars()
{
m_created = false;
m_cornerLabelWin = NULL;
m_rowLabelWin = NULL;
m_colLabelWin = NULL;
m_gridWin = NULL;
m_table = NULL;
m_ownTable = false;
m_selection = NULL;
m_defaultCellAttr = NULL;
m_typeRegistry = NULL;
m_winCapture = NULL;
}
void wxGrid::Init() void wxGrid::Init()
{ {
m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH; m_rowLabelWidth = WXGRID_DEFAULT_ROW_LABEL_WIDTH;
@@ -6818,7 +6825,7 @@ void wxGrid::Refresh(bool eraseb, const wxRect* rect)
{ {
// Don't do anything if between Begin/EndBatch... // Don't do anything if between Begin/EndBatch...
// EndBatch() will do all this on the last nested one anyway. // EndBatch() will do all this on the last nested one anyway.
if (! GetBatchCount()) if ( m_created && !GetBatchCount() )
{ {
// Refresh to get correct scrolled position: // Refresh to get correct scrolled position:
wxScrolledWindow::Refresh(eraseb, rect); wxScrolledWindow::Refresh(eraseb, rect);