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 )