]> git.saurik.com Git - wxWidgets.git/commitdiff
Eliminate need to call Connect() in wxPGEditor::CreateControls()
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 23 Nov 2008 11:00:40 +0000 (11:00 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 23 Nov 2008 11:00:40 +0000 (11:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/editors.h
include/wx/propgrid/propgrid.h
interface/wx/propgrid/editors.h
interface/wx/propgrid/propgrid.h
src/propgrid/advprops.cpp
src/propgrid/editors.cpp
src/propgrid/propgrid.cpp

index 54bcdda98a92bc4c863458523f39501df78bb186..96298e2cc5f7445e344b2605e3b23383d6791164 100644 (file)
@@ -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,
index cd239f59591aee258792243fc53550702cc99401..650bacbb4165abe0ddd721391aa706a922b6111c 100644 (file)
@@ -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:
index fbbe8a5f20b502f80a2421ea77d105192f47f173..be902a925befebfe223d7fd99b1c7ac801822e41 100644 (file)
@@ -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,
index de580e638431f9bf0ad61c642f80a2cd2815950e..253c252f637e77b7082c702c1b8231ddc2b9cd98 100644 (file)
@@ -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.
     */
index da83df34dca1cce69c1d6738f944872b525772d7..b33a39eb2a60858770f3f20cda34500d97d1e685 100644 (file)
@@ -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();
index 0f63021c567b7b721db9cb458fd15b16c1ec66b1..ae1d0c79b2a04b6a4ac90aead76b5b346673b5ee 100644 (file)
@@ -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; i<GetCount(); i++ )
-    {
-        wxWindowID id = GetButtonId(i);
-        propGrid->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED,
-            wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
-    }
 }
 
 int wxPGMultiButton::GenId( int id ) const
index f0987ea966b66877fca09ba77222f0d117777127..cbc0bd7ad6029cdc0184cd61df72f1ad458d56a1 100644 (file)
@@ -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;