From de2f5898c4679eb3b4b9f6be91f0e3bbac5d27f8 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 9 Dec 2014 17:07:59 +0000 Subject: [PATCH] Reconnect wxPropertyGridManager event handlers when wxPG id is changing. Because some event handlers are bound to the particular id's they need to be reconnected when wxPG id is the subject of change. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78259 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/manager.h | 2 ++ src/propgrid/manager.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/wx/propgrid/manager.h b/include/wx/propgrid/manager.h index 8b933cbe8d..4d886f3fb6 100644 --- a/include/wx/propgrid/manager.h +++ b/include/wx/propgrid/manager.h @@ -750,6 +750,8 @@ protected: virtual bool SetEditableStateItem( const wxString& name, wxVariant value ) wxOVERRIDE; virtual wxVariant GetEditableStateItem( const wxString& name ) const wxOVERRIDE; + // Reconnect propgrid event handlers. + void ReconnectEventHandlers(wxWindowID oldId, wxWindowID newId); private: DECLARE_EVENT_TABLE() }; diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index 696a200ba8..c93e43bfad 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -584,13 +584,7 @@ void wxPropertyGridManager::Init2( int style ) // Connect to property grid onselect event. // NB: Even if wxID_ANY is used, this doesn't connect properly in wxPython // (see wxPropertyGridManager::ProcessEvent). - Connect(m_pPropGrid->GetId(), - wxEVT_PG_SELECTED, - wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect)); - - Connect(m_pPropGrid->GetId(), - wxEVT_PG_COL_DRAGGING, - wxPropertyGridEventHandler(wxPropertyGridManager::OnPGColDrag)); + ReconnectEventHandlers(wxID_NONE, m_pPropGrid->GetId()); // Optional initial controls. m_width = -12345; @@ -630,7 +624,8 @@ void wxPropertyGridManager::SetId( wxWindowID winid ) { wxWindow::SetId(winid); - // TODO: Reconnect propgrid event handler(s). + // Reconnect propgrid event handlers. + ReconnectEventHandlers(m_pPropGrid->GetId(), winid); m_pPropGrid->SetId(winid); } @@ -1906,6 +1901,27 @@ void wxPropertyGridManager::SetPageSplitterLeft(int page, bool subProps) } } +void wxPropertyGridManager::ReconnectEventHandlers(wxWindowID oldId, wxWindowID newId) +{ + wxASSERT( oldId != newId ); + + if (oldId != wxID_NONE) + { + Disconnect(oldId, wxEVT_PG_SELECTED, + wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect)); + Disconnect(oldId, wxEVT_PG_COL_DRAGGING, + wxPropertyGridEventHandler(wxPropertyGridManager::OnPGColDrag)); + } + + if (newId != wxID_NONE) + { + Connect(newId, wxEVT_PG_SELECTED, + wxPropertyGridEventHandler(wxPropertyGridManager::OnPropertyGridSelect)); + Connect(newId, wxEVT_PG_COL_DRAGGING, + wxPropertyGridEventHandler(wxPropertyGridManager::OnPGColDrag)); + } +} + // ----------------------------------------------------------------------- void wxPropertyGridManager::OnPropertyGridSelect( wxPropertyGridEvent& event )