From e9cc4973ff92bb1067f9bdb5dafa5cfb5a6b516e Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sat, 15 Nov 2008 10:34:36 +0000 Subject: [PATCH] Fixed various NULL reference issues. Also cleaned up wxPGComboBox code overall a bit. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56782 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/propgrid.h | 8 +++++-- include/wx/propgrid/propgriddefs.h | 1 - include/wx/propgrid/propgridiface.h | 5 +++- src/propgrid/editors.cpp | 36 ++++++++++++++++++----------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 1dd48d53d4..a35360ccce 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -27,6 +27,7 @@ extern WXDLLIMPEXP_DATA_PROPGRID(const char) wxPropertyGridNameStr[]; #endif +class wxPGComboBox; // ----------------------------------------------------------------------- // Global variables @@ -1219,8 +1220,11 @@ public: void IncFrozen() { m_frozen++; } void DecFrozen() { m_frozen--; } - void OnComboItemPaint( wxPGCustomComboControl* pCb,int item,wxDC& dc, - wxRect& rect,int flags ); + void OnComboItemPaint( const wxPGComboBox* pCb, + int item, + wxDC* pDc, + wxRect& rect, + int flags ); /** Standardized double-to-string conversion. */ diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index d72a787095..02e4fc0f2d 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -266,7 +266,6 @@ class wxPropertyGrid; class wxPropertyGridEvent; class wxPropertyGridManager; class wxPGOwnerDrawnComboBox; -class wxPGCustomComboControl; class wxPGEditorDialogAdapter; class wxPGValidationInfo; diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index e12f9248f3..a2139e45e9 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -363,7 +363,10 @@ public: */ const wxPGAttributeStorage& GetPropertyAttributes( wxPGPropArg id ) const { - wxPG_PROP_ARG_CALL_PROLOG_RETVAL(*((const wxPGAttributeStorage*)NULL)); + // If 'id' refers to invalid property, then we will return dummy + // attributes (ie. root property's attributes, which contents should + // should always be empty and of no consequence). + wxPG_PROP_ARG_CALL_PROLOG_RETVAL(m_pState->DoGetRoot()->GetAttributes()); return p->GetAttributes(); } diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index fb60bdaa5f..0f63021c56 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -528,31 +528,37 @@ public: name ) ) return false; - m_dclickProcessor = new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() ); + m_dclickProcessor = new + wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() ); PushEventHandler(m_dclickProcessor); return true; } - virtual void OnDrawItem( wxDC& dc, const wxRect& rect, int item, int flags ) const + virtual void OnDrawItem( wxDC& dc, + const wxRect& rect, + int item, + int flags ) const { wxPropertyGrid* pg = GetGrid(); - pg->OnComboItemPaint((wxPGCustomComboControl*)this,item,dc,(wxRect&)rect,flags); + pg->OnComboItemPaint( this, item, &dc, (wxRect&)rect, flags ); } + virtual wxCoord OnMeasureItem( size_t item ) const { wxPropertyGrid* pg = GetGrid(); wxRect rect; rect.x = -1; rect.width = 0; - pg->OnComboItemPaint((wxPGCustomComboControl*)this,item,*((wxDC*)NULL),rect,0); + pg->OnComboItemPaint( this, item, NULL, rect, 0 ); return rect.height; } wxPropertyGrid* GetGrid() const { - wxPropertyGrid* pg = wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid); + wxPropertyGrid* pg = wxDynamicCast(GetParent()->GetParent(), + wxPropertyGrid); wxASSERT(pg); return pg; } @@ -563,15 +569,17 @@ public: wxRect rect; rect.x = -1; rect.width = -1; - pg->OnComboItemPaint((wxPGCustomComboControl*)this,item,*((wxDC*)NULL),rect,0); + pg->OnComboItemPaint( this, item, NULL, rect, 0 ); return rect.width; } - virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust), int WXUNUSED(textCtrlYAdjust) ) + virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust), + int WXUNUSED(textCtrlYAdjust) ) { wxPropertyGrid* pg = GetGrid(); wxOwnerDrawnComboBox::PositionTextCtrl( - wxPG_TEXTCTRLXADJUST - (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1, + wxPG_TEXTCTRLXADJUST - + (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1, pg->GetSpacingY() + 2 ); } @@ -582,14 +590,12 @@ private: }; -void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl* pCc, +void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb, int item, - wxDC& dc, + wxDC* pDc, wxRect& rect, int flags ) { - wxPGComboBox* pCb = (wxPGComboBox*)pCc; - // Sanity check wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid)) ); @@ -669,13 +675,14 @@ void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl* pCc, if ( (flags & wxODCB_PAINTING_CONTROL) ) paintdata.m_choiceItem = -1; - if ( &dc ) - dc.SetBrush(*wxWHITE_BRUSH); + if ( pDc ) + pDc->SetBrush(*wxWHITE_BRUSH); if ( rect.x >= 0 ) { // // DrawItem call + wxDC& dc = *pDc; wxPoint pt(rect.x + wxPG_CONTROL_MARGIN - wxPG_CHOICEXADJUST - 1, rect.y + 1); @@ -760,6 +767,7 @@ void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl* pCc, { // // MeasureItem call + wxDC& dc = *pDc; p->OnCustomPaint( dc, rect, paintdata ); rect.height = paintdata.m_drawnHeight + 2; -- 2.45.2