From b0996c3da00677389854e5afbcef499e7aa1654b Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 23 Nov 2008 11:00:40 +0000 Subject: [PATCH] Eliminate need to call Connect() in wxPGEditor::CreateControls() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/editors.h | 15 ++------ include/wx/propgrid/propgrid.h | 24 +++--------- interface/wx/propgrid/editors.h | 15 ++------ interface/wx/propgrid/propgrid.h | 16 -------- src/propgrid/advprops.cpp | 21 +--------- src/propgrid/editors.cpp | 42 ++------------------ src/propgrid/propgrid.cpp | 66 +++++++++++++++++++------------- 7 files changed, 57 insertions(+), 142 deletions(-) diff --git a/include/wx/propgrid/editors.h b/include/wx/propgrid/editors.h index 54bcdda98a..96298e2cc5 100644 --- a/include/wx/propgrid/editors.h +++ b/include/wx/propgrid/editors.h @@ -114,17 +114,10 @@ public: @remarks - Primary control shall use id wxPG_SUBID1, and secondary (button) control shall use wxPG_SUBID2. - - Implementation shoud connect all necessary events to the - wxPropertyGrid::OnCustomEditorEvent. For Example: - @code - // Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor - // control to the OnEvent. - control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED, - wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid); - @endcode - OnCustomEditorEvent will then forward events, first to - wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent(). + - Unlike in previous version of wxPropertyGrid, it is no longer + necessary to call wxEvtHandler::Connect() for interesting editor + events. Instead, all events from control are now automatically + forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent(). */ virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid, wxPGProperty* property, diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index cd239f5959..650bacbb41 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -495,8 +495,8 @@ enum wxPG_KEYBOARD_ACTIONS #define wxPG_MAN_FL_PAGE_INSERTED 0x02000000 // Active editor control is abnormally large #define wxPG_FL_ABNORMAL_EDITOR 0x04000000 -// Recursion guard for OnCustomEditorEvent -#define wxPG_FL_IN_ONCUSTOMEDITOREVENT 0x08000000 +// Recursion guard for HandleCustomEditorEvent +#define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x08000000 #define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000 // Editor control width should not change on resize #define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000 @@ -1179,6 +1179,9 @@ public: return m_wndEditor2; } + // Events from editor controls are forward to this function + void HandleCustomEditorEvent( wxEvent &event ); + #ifndef SWIG /** @@ -1196,22 +1199,6 @@ public: // Mostly useful for page switching. void SwitchState( wxPropertyGridPageState* pNewState ); - /** - When creating custom property editors, connect required editor events to - this function. For instance: - - @code - control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid); - @endcode - - @remarks You should never need to call this function directly! - - @see wxPGEditor::CreateControls(), wxEvtHandler::Connect() - */ - void OnCustomEditorEvent( wxEvent &event ); - long GetInternalFlags() const { return m_iFlags; } bool HasInternalFlag( long flag ) const { return (m_iFlags & flag) ? true : false; } @@ -1327,7 +1314,6 @@ public: */ bool UnfocusEditor(); - virtual bool ProcessEvent(wxEvent& event); virtual void SetWindowStyleFlag( long style ); protected: diff --git a/interface/wx/propgrid/editors.h b/interface/wx/propgrid/editors.h index fbbe8a5f20..be902a925b 100644 --- a/interface/wx/propgrid/editors.h +++ b/interface/wx/propgrid/editors.h @@ -70,17 +70,10 @@ public: @remarks - Primary control shall use id wxPG_SUBID1, and secondary (button) control shall use wxPG_SUBID2. - - Implementation shoud connect all necessary events to the - wxPropertyGrid::OnCustomEditorEvent(). For example: - @code - control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid); - @endcode - OnCustomEditorEvent will then forward events, first to - wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent(). - - @see wxPropertyGrid::OnCustomEditorEvent(), wxEvtHandler::Connect() + - Unlike in previous version of wxPropertyGrid, it is no longer + necessary to call wxEvtHandler::Connect() for interesting editor + events. Instead, all events from control are now automatically + forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent(). */ virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property, diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index de580e6384..253c252f63 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -658,22 +658,6 @@ public: */ bool IsFrozen() const; - /** - When creating custom property editors, connect required editor events to - this function. For instance: - - @code - control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid); - @endcode - - @remarks You should never need to call this function directly! - - @see wxPGEditor::CreateControls(), wxEvtHandler::Connect() - */ - void OnCustomEditorEvent( wxEvent &event ); - /** Redraws given property. */ diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index da83df34dc..b33a39eb2a 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -137,24 +137,12 @@ wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxP wnd2->SetRange( INT_MIN, INT_MAX ); wnd2->SetValue( 0 ); - wxWindowID id = wnd2->GetId(); - wnd2->Connect( id, wxEVT_SCROLL_LINEUP, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid ); - wnd2->Connect( id, wxEVT_SCROLL_LINEDOWN, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid ); - // Let's add validator to make sure only numbers can be entered wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString); wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary; wnd1->SetValidator(validator); - wnd1->Connect( wnd1->GetId(), wxEVT_KEY_DOWN, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid ); - return wxPGWindowList(wnd1, wnd2); } @@ -334,13 +322,6 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri useSz, prop->GetDatePickerStyle() | wxNO_BORDER); - // Connect all required events to grid's OnCustomEditorEvent - // (all relevenat wxTextCtrl, wxComboBox and wxButton events are - // already connected) - ctrl->Connect( wxPG_SUBID1, wxEVT_DATE_CHANGED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent), - NULL, propgrid ); - #ifdef __WXMSW__ ctrl->Show(); #endif @@ -1026,7 +1007,7 @@ bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const wxASSERT( propgrid ); // Must only occur when user triggers event - if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT) ) + if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT) ) return res; wxColourPropertyValue val = GetVal(); diff --git a/src/propgrid/editors.cpp b/src/propgrid/editors.cpp index 0f63021c56..ae1d0c79b2 100644 --- a/src/propgrid/editors.cpp +++ b/src/propgrid/editors.cpp @@ -877,15 +877,6 @@ wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid, else cb->SetSelection( -1 ); - // Connect event handling - wxWindowID id = cb->GetId(); - propGrid->Connect(id, wxEVT_COMMAND_COMBOBOX_SELECTED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - propGrid->Connect(id, wxEVT_COMMAND_TEXT_UPDATED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - propGrid->Connect(id, wxEVT_COMMAND_TEXT_ENTER, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - #ifdef __WXMSW__ cb->Show(); #endif @@ -1298,7 +1289,7 @@ void wxSimpleCheckBox::SetValue( int value ) wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent(); wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) ); - propGrid->OnCustomEditorEvent(evt); + propGrid->HandleCustomEditorEvent(evt); } @@ -1401,14 +1392,6 @@ wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid, cb->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); - cb->Connect( wxPG_SUBID1, wxEVT_LEFT_DOWN, - (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) - &wxPropertyGrid::OnCustomEditorEvent, NULL, propGrid ); - - cb->Connect( wxPG_SUBID1, wxEVT_LEFT_DCLICK, - (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) - &wxPropertyGrid::OnCustomEditorEvent, NULL, propGrid ); - if ( property->GetChoiceSelection() > 0 && !property->IsValueUnspecified() ) cb->m_state = 1; @@ -1711,13 +1694,6 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos, if ( maxLen > 0 ) tc->SetMaxLength( maxLen ); - // Connect event handling - id = ed->GetId(); - this->Connect(id, wxEVT_COMMAND_TEXT_UPDATED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - this->Connect(id, wxEVT_COMMAND_TEXT_ENTER, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - return (wxWindow*) ed; } @@ -1779,11 +1755,6 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize if ( selected->HasFlag(wxPG_PROP_READONLY) ) but->Disable(); - // Connect event handling - id = but->GetId(); - this->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - return but; } @@ -1881,17 +1852,10 @@ wxPGMultiButton::wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz ) SetBackgroundColour(pg->GetCellBackgroundColour()); } -void wxPGMultiButton::Finalize( wxPropertyGrid* propGrid, const wxPoint& pos ) +void wxPGMultiButton::Finalize( wxPropertyGrid* WXUNUSED(propGrid), + const wxPoint& pos ) { Move( pos.x + m_fullEditorSize.x - m_buttonsWidth, pos.y ); - - // Connect event handling - for ( unsigned int i=0; iConnect(id, wxEVT_COMMAND_BUTTON_CLICKED, - wxEventHandler(wxPropertyGrid::OnCustomEditorEvent)); - } } int wxPGMultiButton::GenId( int id ) const diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index f0987ea966..cbc0bd7ad6 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -2388,7 +2388,7 @@ bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags ) // Don't do this if already processing editor event. It might // induce recursive dialogs and crap like that. - if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT ) + if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT ) { if ( m_inDoPropertyChanged ) return true; @@ -2879,27 +2879,7 @@ bool wxPropertyGrid::DoEditorValidate() // ----------------------------------------------------------------------- -bool wxPropertyGrid::ProcessEvent(wxEvent& event) -{ - wxWindow* wnd = (wxWindow*) event.GetEventObject(); - if ( wnd && wnd->IsKindOf(CLASSINFO(wxWindow)) ) - { - wxWindow* parent = wnd->GetParent(); - - if ( parent && - (parent == m_canvas || - parent->GetParent() == m_canvas) ) - { - OnCustomEditorEvent(event); - return true; - } - } - return wxPanel::ProcessEvent(event); -} - -// ----------------------------------------------------------------------- - -void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event ) +void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) { wxPGProperty* selected = m_selected; @@ -2908,7 +2888,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event ) if ( !selected ) return; - if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT ) + if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT ) return; wxVariant pendingValue(selected->GetValueRef()); @@ -2938,7 +2918,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event ) m_prevTcValue = newTcValue; } - SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT); + SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT); bool validationFailure = false; bool buttonWasHandled = false; @@ -3038,7 +3018,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event ) } } - ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT); + ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT); } // ----------------------------------------------------------------------- @@ -3163,9 +3143,37 @@ void wxPropertyGrid::CustomSetCursor( int type, bool override ) } // ----------------------------------------------------------------------- -// wxPropertyGrid property selection +// wxPropertyGrid property selection, editor creation // ----------------------------------------------------------------------- +// +// This class forwards events from property editor controls to wxPropertyGrid. +class wxPropertyGridEditorEventForwarder : public wxEvtHandler +{ +public: + wxPropertyGridEditorEventForwarder( wxPropertyGrid* propGrid ) + : wxEvtHandler(), m_propGrid(propGrid) + { + } + + virtual ~wxPropertyGridEditorEventForwarder() + { + } + +private: + bool ProcessEvent( wxEvent& event ) + { + // Always skip + event.Skip(); + + m_propGrid->HandleCustomEditorEvent(event); + + return wxEvtHandler::ProcessEvent(event); + } + + wxPropertyGrid* m_propGrid; +}; + // Setups event handling for child control void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd ) { @@ -3193,6 +3201,10 @@ void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd ) NULL, this); } + wxPropertyGridEditorEventForwarder* forwarder; + forwarder = new wxPropertyGridEditorEventForwarder(this); + argWnd->PushEventHandler(forwarder); + argWnd->Connect(id, wxEVT_KEY_DOWN, wxCharEventHandler(wxPropertyGrid::OnChildKeyDown), NULL, this); @@ -3222,6 +3234,7 @@ void wxPropertyGrid::FreeEditors() // Do not free editors immediately if processing events if ( m_wndEditor2 ) { + m_wndEditor2->PopEventHandler(true); m_wndEditor2->Hide(); wxPendingDelete.Append( m_wndEditor2 ); m_wndEditor2 = (wxWindow*) NULL; @@ -3229,6 +3242,7 @@ void wxPropertyGrid::FreeEditors() if ( m_wndEditor ) { + m_wndEditor->PopEventHandler(true); m_wndEditor->Hide(); wxPendingDelete.Append( m_wndEditor ); m_wndEditor = (wxWindow*) NULL; -- 2.45.2