]> git.saurik.com Git - wxWidgets.git/commitdiff
Change in wxWindow the access specifier of the wxEvtHandler event processing and...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 25 Jan 2009 11:58:39 +0000 (11:58 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 25 Jan 2009 11:58:39 +0000 (11:58 +0000)
from public to protected. Adapt wxWidgets code and wxWidgets samples to always use wxWindow::GetEventHandler()
when calling such functions on a wxWindow rather than directly using wxWindow::ProcessEvent, etc.
This enables correct event dispatching to the event handlers which have been pushed (with PushEventHandler) on the
windows.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58381 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

17 files changed:
include/wx/aui/tabmdi.h
include/wx/generic/mdig.h
include/wx/gtk/window.h
include/wx/propgrid/manager.h
include/wx/window.h
interface/wx/window.h
samples/except/except.cpp
samples/richtext/richtext.cpp
samples/stc/stctest.cpp
src/aui/auibar.cpp
src/aui/framemanager.cpp
src/common/choiccmn.cpp
src/common/combocmn.cpp
src/common/lboxcmn.cpp
src/html/helpwnd.cpp
src/unix/joystick.cpp
tests/events/propagation.cpp

index 2da0bdd809e8b516330ff09229c341a860880509..e4e7b8182cb56d9f1d0f579093b6cb08020ade2a 100644 (file)
@@ -61,7 +61,7 @@ public:
     void SetArtProvider(wxAuiTabArt* provider);
     wxAuiTabArt* GetArtProvider();
     wxAuiNotebook* GetNotebook() const;
-    
+
 #if wxUSE_MENUS
     wxMenu* GetWindowMenu() const { return m_pWindowMenu; }
     void SetWindowMenu(wxMenu* pMenu);
@@ -71,8 +71,6 @@ public:
 
     void SetChildMenuBar(wxAuiMDIChildFrame *pChild);
 
-    virtual bool ProcessEvent(wxEvent& event);
-
     wxAuiMDIChildFrame *GetActiveChild() const;
     void SetActiveChild(wxAuiMDIChildFrame* pChildFrame);
 
@@ -105,6 +103,8 @@ protected:
     void DoHandleMenu(wxCommandEvent &event);
 #endif // wxUSE_MENUS
 
+    virtual bool ProcessEvent(wxEvent& event);
+
     virtual void DoGetClientSize(int *width, int *height) const;
 
 private:
@@ -147,7 +147,7 @@ public:
 
     virtual void SetIcons(const wxIconBundle& icons);
     virtual const wxIconBundle& GetIcons() const;
-    
+
     virtual void SetIcon(const wxIcon& icon);
     virtual const wxIcon& GetIcon() const;
 
@@ -196,7 +196,7 @@ public:
 
     void SetMDIParentFrame(wxAuiMDIParentFrame* parent);
     wxAuiMDIParentFrame* GetMDIParentFrame() const;
-    
+
 protected:
     void Init();
     virtual void DoSetSize(int x, int y, int width, int height, int size_flags);
index d21366b3c5f0a3d83b3886192eebf676facda8f7..46708ed6fc459cdf74afb176cc12a4b105455e46 100644 (file)
@@ -78,8 +78,6 @@ public:
     virtual void SetMenuBar(wxMenuBar *pMenuBar);
 #endif // wxUSE_MENUS
 
-    virtual bool ProcessEvent(wxEvent& event);
-
     virtual wxGenericMDIClientWindow *OnCreateGenericClient();
 
 
@@ -112,6 +110,8 @@ private:
     void OnWindowMenu(wxCommandEvent& event);
 #endif // wxUSE_MENUS
 
+    virtual bool ProcessEvent(wxEvent& event);
+
     void OnClose(wxCloseEvent& event);
 
     // return the client window, may be NULL if we hadn't been created yet
index 4d30ba22565735d727c8ff4ab768755936d7d1e8..075a40cb7b6db59ee40c9be24cb35547f6b228a8 100644 (file)
@@ -166,7 +166,7 @@ public:
     // override this if some events should never be consumed by wxWidgets but
     // but have to be left for the native control
     //
-    // base version just does GetEventHandler()->ProcessEvent()
+    // base version just calls HandleWindowEvent()
     virtual bool GTKProcessEvent(wxEvent& event) const;
 
     // Map GTK widget direction of the given widget to/from wxLayoutDirection
@@ -178,7 +178,7 @@ public:
     // there is also the exception of wxMenuBar)
     virtual bool GTKNeedsParent() const { return !IsTopLevel(); }
 
-    // This is called when capture is taken from the window. It will 
+    // This is called when capture is taken from the window. It will
     // fire off capture lost events.
     void GTKReleaseMouseAndNotify();
 
@@ -256,7 +256,7 @@ public:
 
     // this widget will be queried for GTK's focus events
     GtkWidget           *m_focusWidget;
-    
+
     void GTKDisableFocusOutEvent();
     void GTKEnableFocusOutEvent();
 
index 58850722645814f0ba5acd283d8eec0218dcc997..c93c669420168e4f24c5b91c33c34909208ace2a 100644 (file)
@@ -634,7 +634,6 @@ public:
 
 #ifndef SWIG
 
-    virtual bool ProcessEvent( wxEvent& event );
     //
     // Event handlers
     //
@@ -707,6 +706,8 @@ protected:
     virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
 #endif*/
 
+    virtual bool ProcessEvent( wxEvent& event );
+
     /** Recalculates new positions for components, according to the
         given size.
     */
index 932ac84f3656181628fd4e54d0ac25be714b71d1..ec6a5644f98ec5ce7731ddfc8e5712a477516d9b 100644 (file)
@@ -817,6 +817,26 @@ public:
     virtual void SetNextHandler(wxEvtHandler *handler);
     virtual void SetPreviousHandler(wxEvtHandler *handler);
 
+protected:
+
+    // NOTE: we change the access specifier of the following wxEvtHandler functions
+    //       so that the user won't be able to call them directly.
+    //       Calling wxWindow::ProcessEvent in fact only works when there are NO
+    //       event handlers pushed on the window.
+    //       To ensure correct operation, instead of wxWindow::ProcessEvent
+    //       you must always call wxWindow::GetEventHandler()->ProcessEvent()
+    //       or HandleWindowEvent().
+    //       The same holds for all other wxEvtHandler functions.
+
+    wxEvtHandler::ProcessEvent;
+    wxEvtHandler::ProcessThreadEvent;
+    wxEvtHandler::SafelyProcessEvent;
+    wxEvtHandler::ProcessPendingEvents;
+    wxEvtHandler::AddPendingEvent;
+    wxEvtHandler::QueueEvent;
+
+public:
+
     // validators
     // ----------
 
index a77ebf36043818b4ffc674a01ca424f00a85b6ba..03eb0a689431d864c0852f2f6f97e04fe5acd64c 100644 (file)
@@ -3086,6 +3086,25 @@ protected:
         explanations of when you might want to do it.
      */
     void SendDestroyEvent();
+
+    //@{
+    /**
+        This function is public in wxEvtHandler but is protected in wxWindow because
+        for wxWindows you should always use this function on the pointer returned
+        by GetEventHandler() and not on the wxWindow object itself.
+
+        Note that it's still possible to call these functions directly on the
+        wxWindow object (e.g. downcasting it to wxEvtHandler) but doing that
+        will create subtle bugs when windows with event handlers pushed on them
+        are involved.
+    */
+    virtual bool ProcessEvent(wxEvent& event);
+    bool SafelyProcessEvent(wxEvent& event);
+    virtual void QueueEvent(wxEvent *event);
+    virtual void AddPendingEvent(const wxEvent& event);
+    void ProcessPendingEvents();
+    bool ProcessThreadEvent(const wxEvent& event);
+    //@}
 };
 
 
index 5e487845d55ecac6530c86c686a9ff9f26b52621..95502800c79324f26741cf6a53083758e778ecc8 100644 (file)
@@ -123,6 +123,8 @@ public:
     void OnHandleCrash(wxCommandEvent& event);
 #endif
 
+protected:
+
     // 1st-level exception handling: we overload ProcessEvent() to be able to
     // catch exceptions which occur in MyFrame methods here
     virtual bool ProcessEvent(wxEvent& event);
index c13f1829830e1a2721bc483b6527c0955f369e91..d41e8e90f95fefe130e6bb09fd615997dfb65ee2 100644 (file)
@@ -181,6 +181,8 @@ public:
     void OnPreview(wxCommandEvent& event);
     void OnPageSetup(wxCommandEvent& event);
 
+protected:
+
     // Forward command events to the current rich text control, if any
     bool ProcessEvent(wxEvent& event);
 
@@ -958,7 +960,7 @@ bool MyFrame::ProcessEvent(wxEvent& event)
             s_id = event.GetId();
 
             wxWindow* focusWin = wxFindFocusDescendant(this);
-            if (focusWin && focusWin->ProcessEvent(event))
+            if (focusWin && focusWin->GetEventHandler()->ProcessEvent(event))
             {
                 //s_command = NULL;
                 s_eventType = 0;
index 203cd15bbc65c26611a39d2f81abfa92cf643752..14db821fc551bba1faa0e622649fe8717a96ab5d 100644 (file)
@@ -457,7 +457,7 @@ void AppFrame::OnPrint (wxCommandEvent &WXUNUSED(event)) {
 
 // edit events
 void AppFrame::OnEdit (wxCommandEvent &event) {
-    if (m_edit) m_edit->ProcessEvent (event);
+    if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
 }
 
 // private functions
index aba30015078632ef8f8ee5d5b0179004d91976a4..8e03594c16837d853560d48ae0f18bfaa2a2d77f 100644 (file)
@@ -2260,7 +2260,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
             e.SetEventObject(this);
             e.SetToolId(-1);
             e.SetClickPoint(wxPoint(evt.GetX(), evt.GetY()));
-            bool processed = ProcessEvent(e);
+            bool processed = GetEventHandler()->ProcessEvent(e);
 
             if (processed)
             {
@@ -2297,7 +2297,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
                 {
                     wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, res);
                     e.SetEventObject(this);
-                    GetParent()->ProcessEvent(e);
+                    GetParent()->GetEventHandler()->ProcessEvent(e);
                 }
             }
 
@@ -2338,7 +2338,7 @@ void wxAuiToolBar::OnLeftDown(wxMouseEvent& evt)
 
         e.SetClickPoint(evt.GetPosition());
         e.SetItemRect(rect);
-        ProcessEvent(e);
+        GetEventHandler()->ProcessEvent(e);
         DoIdleUpdate();
     }
 }
@@ -2384,14 +2384,14 @@ void wxAuiToolBar::OnLeftUp(wxMouseEvent& evt)
 
                 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
                 e.SetEventObject(this);
-                ProcessEvent(e);
+                GetEventHandler()->ProcessEvent(e);
                 DoIdleUpdate();
             }
             else
             {
                 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED, m_action_item->id);
                 e.SetEventObject(this);
-                ProcessEvent(e);
+                GetEventHandler()->ProcessEvent(e);
                 DoIdleUpdate();
             }
         }
@@ -2454,7 +2454,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt)
             e.SetEventObject(this);
             e.SetToolId(m_action_item->id);
             e.SetClickPoint(m_action_pos);
-            ProcessEvent(e);
+            GetEventHandler()->ProcessEvent(e);
             DoIdleUpdate();
         }
     }
@@ -2465,7 +2465,7 @@ void wxAuiToolBar::OnRightUp(wxMouseEvent& evt)
         e.SetEventObject(this);
         e.SetToolId(-1);
         e.SetClickPoint(m_action_pos);
-        ProcessEvent(e);
+        GetEventHandler()->ProcessEvent(e);
         DoIdleUpdate();
     }
 
@@ -2525,7 +2525,7 @@ void wxAuiToolBar::OnMiddleUp(wxMouseEvent& evt)
             e.SetEventObject(this);
             e.SetToolId(m_action_item->id);
             e.SetClickPoint(m_action_pos);
-            ProcessEvent(e);
+            GetEventHandler()->ProcessEvent(e);
             DoIdleUpdate();
         }
     }
@@ -2550,7 +2550,7 @@ void wxAuiToolBar::OnMotion(wxMouseEvent& evt)
         wxAuiToolBarEvent e(wxEVT_COMMAND_AUITOOLBAR_BEGIN_DRAG, GetId());
         e.SetEventObject(this);
         e.SetToolId(m_action_item->id);
-        ProcessEvent(e);
+        GetEventHandler()->ProcessEvent(e);
         DoIdleUpdate();
         return;
     }
index 2c85e56551786f8b38996750c206af72c86ab6a4..05e6bbfb187f1168cf679eb7ecbee976de5d288a 100644 (file)
@@ -772,7 +772,7 @@ wxAuiManager* wxAuiManager::GetManager(wxWindow* window)
     wxAuiManagerEvent evt(wxEVT_AUI_FIND_MANAGER);
     evt.SetManager(NULL);
     evt.ResumePropagation(wxEVENT_PROPAGATE_MAX);
-    if (!window->ProcessEvent(evt))
+    if (!window->GetEventHandler()->ProcessEvent(evt))
         return NULL;
 
     return evt.GetManager();
@@ -933,7 +933,7 @@ void wxAuiManager::ProcessMgrEvent(wxAuiManagerEvent& event)
     // first, give the owner frame a chance to override
     if (m_frame)
     {
-        if (m_frame->ProcessEvent(event))
+        if (m_frame->GetEventHandler()->ProcessEvent(event))
             return;
     }
 
index 6685fda3cf9e13e653e918a904832e1f22dcc37f..64f8a92347e01da7d80b107e513fdde002f4ec48 100644 (file)
@@ -49,7 +49,7 @@ wxChoiceBase::~wxChoiceBase()
 void wxChoiceBase::Command(wxCommandEvent& event)
 {
     SetSelection(event.GetInt());
-    (void)ProcessEvent(event);
+    (void)GetEventHandler()->ProcessEvent(event);
 }
 
 #endif // wxUSE_CHOICE
index 89367d068b842d6da7e118bc1640dd2be119fe84..50449b2344ca0e4a1d1fe3642ac1e60d99b770f8 100644 (file)
@@ -461,7 +461,7 @@ void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event )
     wxWindowList children = m_combo->GetPopupWindow()->GetChildren();
     wxWindowList::iterator node = children.begin();
     wxWindow* child = (wxWindow*)*node;
-    child->AddPendingEvent(event);
+    child->GetEventHandler()->AddPendingEvent(event);
 }
 
 #if USES_WXDIALOG
@@ -1177,7 +1177,7 @@ bool wxComboCtrlBase::Enable(bool enable)
         m_btn->Enable(enable);
     if ( m_text )
         m_text->Enable(enable);
-        
+
     Refresh();
 
     return true;
@@ -1648,7 +1648,7 @@ void wxComboCtrlBase::OnKeyEvent(wxKeyEvent& event)
     if ( IsPopupShown() )
     {
         // pass it to the popped up control
-        GetPopupControl()->GetControl()->AddPendingEvent(event);
+        GetPopupControl()->GetControl()->GetEventHandler()->AddPendingEvent(event);
     }
     else // no popup
     {
index 9b114d7c1b56152b7ee95846548cf64106444c56..a9beae01cc920b6d8621a7be449755c9b6a99c12 100644 (file)
@@ -201,7 +201,7 @@ void wxListBoxBase::CalcAndSendEvent()
 void wxListBoxBase::Command(wxCommandEvent& event)
 {
     SetSelection(event.GetInt(), event.GetExtraLong() != 0);
-    (void)ProcessEvent(event);
+    (void)GetEventHandler()->ProcessEvent(event);
 }
 
 // ----------------------------------------------------------------------------
index e66a5be432295955a52c950e2b14225abed58e37..78b4719acf7fde873e5a08759a4736293b667eb6 100644 (file)
@@ -584,7 +584,7 @@ bool wxHtmlHelpWindow::Create(wxWindow* parent, wxWindowID id,
     // Reduce flicker by updating the splitter pane sizes before the
     // frame is shown
     wxSizeEvent sizeEvent(GetSize(), GetId());
-    ProcessEvent(sizeEvent);
+    GetEventHandler()->ProcessEvent(sizeEvent);
 
     if (m_Splitter)
         m_Splitter->UpdateSize();
index b96c009826e6503e0a03e26a397f18836c405b66..f9f2ba9d41dd2cafc77c695d0da5ed79d4816c7f 100644 (file)
@@ -102,7 +102,7 @@ void wxJoystickThread::SendEvent(wxEventType type, long ts, int change)
     jwx_event.SetEventObject(m_catchwin);
 
     if (m_catchwin)
-        m_catchwin->AddPendingEvent(jwx_event);
+        m_catchwin->GetEventHandler()->AddPendingEvent(jwx_event);
 }
 
 void* wxJoystickThread::Entry()
index e0918af3aa19729e287e29f395a6c9520cf4ffa9..e240dd6e17736d9b2459fbc4de307320ac73d215 100644 (file)
@@ -184,7 +184,7 @@ void EventPropagationTestCase::WindowWithoutHandler()
 
     TestWindow * const child = new TestWindow(parent, 'c');
 
-    child->ProcessEvent(event);
+    child->GetEventHandler()->ProcessEvent(event);
     CPPUNIT_ASSERT_EQUAL( "acpA", g_str );
 }