From 6086bcc8ba1d46f5079bf40a61c8411e4b66fe9f Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Mon, 9 Mar 2009 18:32:43 +0000 Subject: [PATCH] Allow wxPGMultiButton to work even if primary editor control was not created in wxPGEditor::CreateControls(); Clarified related samples and documentation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59450 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/editors.h | 2 ++ interface/wx/propgrid/editors.h | 13 +++++++------ samples/propgrid/propgrid.cpp | 16 ++++++++-------- src/propgrid/propgrid.cpp | 12 +++++++----- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/include/wx/propgrid/editors.h b/include/wx/propgrid/editors.h index fcb42d8bc7..dcc66671e5 100644 --- a/include/wx/propgrid/editors.h +++ b/include/wx/propgrid/editors.h @@ -534,6 +534,8 @@ public: protected: + void DoAddButton( wxWindow* button, const wxSize& sz ); + int GenId( int id ) const; wxArrayPtrVoid m_buttons; diff --git a/interface/wx/propgrid/editors.h b/interface/wx/propgrid/editors.h index be902a925b..29738a5c22 100644 --- a/interface/wx/propgrid/editors.h +++ b/interface/wx/propgrid/editors.h @@ -220,18 +220,19 @@ public: if ( event.GetId() == buttons->GetButtonId(0) ) { - // Do something when first button is pressed - return true; + // Do something when the first button is pressed + // Return true if the action modified the value in editor. + ... } if ( event.GetId() == buttons->GetButtonId(1) ) { - // Do something when second button is pressed - return true; + // Do something when the second button is pressed + ... } if ( event.GetId() == buttons->GetButtonId(2) ) { - // Do something when third button is pressed - return true; + // Do something when the third button is pressed + ... } } return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event); diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 56abbad6d2..07099777a8 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -134,21 +134,21 @@ bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid, if ( event.GetId() == buttons->GetButtonId(0) ) { - // Do something when first button is pressed + // Do something when the first button is pressed wxLogDebug("First button pressed"); - return true; + return false; // Return false since value did not change } if ( event.GetId() == buttons->GetButtonId(1) ) { - // Do something when second button is pressed - wxLogDebug("Second button pressed"); - return true; + // Do something when the second button is pressed + wxMessageBox("Second button pressed"); + return false; // Return false since value did not change } if ( event.GetId() == buttons->GetButtonId(2) ) { - // Do something when third button is pressed - wxLogDebug("Third button pressed"); - return true; + // Do something when the third button is pressed + wxMessageBox("Third button pressed"); + return false; // Return false since value did not change } } return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 842706e742..a9557f3461 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -2842,10 +2842,10 @@ void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) wxVariant pendingValue(selected->GetValueRef()); wxWindow* wnd = GetEditorControl(); + wxWindow* editorWnd = wxDynamicCast(event.GetEventObject(), wxWindow); int selFlags = 0; bool wasUnspecified = selected->IsValueUnspecified(); int usesAutoUnspecified = selected->UsesAutoUnspecified(); - bool valueIsPending = false; m_chgInfo_changedProperty = NULL; @@ -2891,17 +2891,19 @@ void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) if ( !buttonWasHandled ) { - if ( wnd ) + if ( wnd || m_wndEditor2 ) { // First call editor class' event handler. const wxPGEditor* editor = selected->GetEditorClass(); - if ( editor->OnEvent( this, selected, wnd, event ) ) + if ( editor->OnEvent( this, selected, editorWnd, event ) ) { // If changes, validate them if ( DoEditorValidate() ) { - if ( editor->GetValueFromControl( pendingValue, m_selected, wnd ) ) + if ( editor->GetValueFromControl( pendingValue, + m_selected, + wnd ) ) valueIsPending = true; } else @@ -2914,7 +2916,7 @@ void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) // Then the property's custom handler (must be always called, unless // validation failed). if ( !validationFailure ) - buttonWasHandled = selected->OnEvent( this, wnd, event ); + buttonWasHandled = selected->OnEvent( this, editorWnd, event ); } // SetValueInEvent(), as called in one of the functions referred above -- 2.45.2