]> git.saurik.com Git - wxWidgets.git/commitdiff
got rid of wxEvtHandler::m_isWindow, use virtual functions (overridden in wxWindow...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Jun 2003 00:44:55 +0000 (00:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 26 Jun 2003 00:44:55 +0000 (00:44 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21418 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/event.h
include/wx/window.h
src/common/event.cpp
src/common/wincmn.cpp

index a177842ed588eb3c8fee6fabe2e20010f445acb9..a9549306501bb93a42b45c249fb4d1fe899791f6 100644 (file)
@@ -2094,6 +2094,22 @@ private:
     static const wxEventTableEntry sm_eventTableEntries[];
 
 protected:
+    // hooks for wxWindow used by ProcessEvent()
+    // -----------------------------------------
+
+    // this one is called before trying our own event table to allow plugging
+    // in the validators
+#if wxUSE_VALIDATORS
+    virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; }
+#endif // wxUSE_VALIDATORS
+
+    // this one is called after failing to find the event handle in our own
+    // table to give a chance to the other windows to process it
+    //
+    // base class implementation passes the event to wxTheApp
+    virtual bool TryParent(wxEvent& event);
+
+
     static const wxEventTable sm_eventTable;
 
     virtual const wxEventTable *GetEventTable() const;
@@ -2111,10 +2127,6 @@ protected:
 #  endif
 #endif
 
-    // optimization: instead of using costly IsKindOf() to decide whether we're
-    // a window (which is true in 99% of cases), use this flag
-    bool                m_isWindow;
-
     // Is event handler enabled?
     bool                m_enabled;
 
index 6b45c4a7b49cecc4f493187ad72e4ea17fc30611..646e088e221df3d01b4b2ec54eaf5b15716a40ae 100644 (file)
@@ -876,6 +876,13 @@ public:
 #endif // wxUSE_PALETTE
 
 protected:
+    // event handling specific to wxWindow
+#if wxUSE_VALIDATORS
+    virtual bool TryValidator(wxEvent& event);
+#endif // wxUSE_VALIDATORS
+    virtual bool TryParent(wxEvent& event);
+
+
 #if wxUSE_CONSTRAINTS
     // satisfy the constraints for the windows but don't set the window sizes
     void SatisfyConstraints();
index fe37d2fd0f1d8440ce8606af753246199e0213e2..60ebe589a74ca32f5f5508653088f7e43c90d225 100644 (file)
@@ -620,7 +620,6 @@ wxEvtHandler::wxEvtHandler()
     m_previousHandler = (wxEvtHandler *) NULL;
     m_enabled = TRUE;
     m_dynamicEvents = (wxList *) NULL;
-    m_isWindow = FALSE;
     m_pendingEvents = (wxList *) NULL;
 #if wxUSE_THREADS
 #  if !defined(__VISAGECPP__)
@@ -786,47 +785,25 @@ void wxEvtHandler::ProcessPendingEvents()
  * Event table stuff
  */
 
-bool wxEvtHandler::ProcessEvent(wxEvent& event)
+bool wxEvtHandler::TryParent(wxEvent& event)
 {
-#if wxUSE_GUI
-
-    // We have to use the actual window or processing events from
-    // wxWindowNative destructor won't work (we don't see the wxWindow class)
-#ifdef __WXDEBUG__
-    // check that our flag corresponds to reality
-    wxClassInfo* info = NULL;
-#ifdef __WXUNIVERSAL__
-#  if defined(__WXMSW__)
-    info = CLASSINFO(wxWindowMSW);
-#  elif defined(__WXGTK__)
-    info = CLASSINFO(wxWindowGTK);
-#  elif defined(__WXX11__)
-    info = CLASSINFO(wxWindowX11);
-#  elif defined(__WXMGL__)
-    info = CLASSINFO(wxWindowMGL);
-#  elif defined(__WXPM__)
-    info = CLASSINFO(wxWindowOS2);
-#  elif defined(__WXMAC__)
-    info = CLASSINFO(wxWindowMac);
-#  elif defined(__WXMOTIF__)
-    info = CLASSINFO(wxWindowMotif);
-#  endif
-#else
-    info = CLASSINFO(wxWindow);
-#endif
-
-    if ( m_isWindow != IsKindOf(info) )
+    if ( wxTheApp && (this != wxTheApp) )
     {
-        wxString msg = GetClassInfo()->GetClassName();
-        msg += _T(" should [not] be a window but it is [not]");
-
-        wxFAIL_MSG( msg );
+        // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
+        // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
+        // processed appropriately via SearchEventTable.
+        if ( event.GetEventType() != wxEVT_IDLE )
+        {
+            if ( wxTheApp->ProcessEvent(event) )
+                return TRUE;
+        }
     }
 
-#endif // __WXDEBUG__
-
-#endif // wxUSE_GUI
+    return FALSE;
+}
 
+bool wxEvtHandler::ProcessEvent(wxEvent& event)
+{
     // allow the application to hook into event processing
     if ( wxTheApp )
     {
@@ -844,52 +821,18 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
     // An event handler can be enabled or disabled
     if ( GetEvtHandlerEnabled() )
     {
-
-#if 0
-/*
-        What is this? When using GUI threads, a non main
-        threads can send an event and process it itself.
-        This breaks GTK's GUI threads, so please explain.
-*/
-
-        // Check whether we are in a child thread.
-        if ( !wxThread::IsMain() )
-          return ProcessThreadEvent(event);
-#endif
-
         // Handle per-instance dynamic event tables first
         if ( m_dynamicEvents && SearchDynamicEventTable(event) )
             return TRUE;
 
+#if wxUSE_VALIDATORS
+        if ( TryValidator(event) )
+            return TRUE;
+#endif // wxUSE_VALIDATORS
+
         // Then static per-class event tables
         const wxEventTable *table = GetEventTable();
 
-#if wxUSE_GUI && wxUSE_VALIDATORS
-        // Try the associated validator first, if this is a window.
-        // Problem: if the event handler of the window has been replaced,
-        // this wxEvtHandler may no longer be a window.
-        // Therefore validators won't be processed if the handler
-        // has been replaced with SetEventHandler.
-        // THIS CAN BE CURED if PushEventHandler is used instead of
-        // SetEventHandler, and then processing will be passed down the
-        // chain of event handlers.
-        if (m_isWindow)
-        {
-            wxWindow *win = (wxWindow *)this;
-
-            // Can only use the validator of the window which
-            // is receiving the event
-            if ( win == event.GetEventObject() )
-            {
-                wxValidator *validator = win->GetValidator();
-                if ( validator && validator->ProcessEvent(event) )
-                {
-                    return TRUE;
-                }
-            }
-        }
-#endif
-
         // Search upwards through the inheritance hierarchy
         while (table)
         {
@@ -906,43 +849,11 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
             return TRUE;
     }
 
-#if wxUSE_GUI
-    // Carry on up the parent-child hierarchy, but only if event is a command
-    // event: it wouldn't make sense for a parent to receive a child's size
-    // event, for example
-    if ( m_isWindow && event.IsCommandEvent() )
-    {
-        wxWindow *win = (wxWindow *)this;
-
-        // honour the requests to stop propagation at this window: this is
-        // used by the dialogs, for example, to prevent processing the events
-        // from the dialog controls in the parent frame which rarely, if ever,
-        // makes sense
-        if ( !(win->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
-        {
-            wxWindow *parent = win->GetParent();
-            if ( parent && !parent->IsBeingDeleted() )
-                return parent->GetEventHandler()->ProcessEvent(event);
-        }
-    }
-#endif // wxUSE_GUI
-
-    // Last try - application object.
-    if ( wxTheApp && (this != wxTheApp) )
-    {
-        // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
-        // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
-        // processed appropriately via SearchEventTable.
-        if ( event.GetEventType() != wxEVT_IDLE )
-        {
-            if ( wxTheApp->ProcessEvent(event) )
-                return TRUE;
-        }
-    }
-
-    return FALSE;
+    return TryParent(event);
 }
 
+#if wxUSE_BASE
+
 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
 {
     wxEventType eventType = event.GetEventType();
@@ -1135,6 +1046,8 @@ bool wxEvtHandler::OnClose()
 }
 #endif // WXWIN_COMPATIBILITY
 
+#endif // wxUSE_BASE
+
 #if wxUSE_GUI
 
 // Find a window with the focus, that is also a descendant of the given window.
index 5962b4b3532d460a4d03aed2e20aae60dcea8e6f..fe662701f14a8a3d1d33ff6b1c51a0cebd3ed711 100644 (file)
@@ -2101,6 +2101,52 @@ void wxWindowBase::SendDestroyEvent()
     GetEventHandler()->ProcessEvent(event);
 }
 
+// ----------------------------------------------------------------------------
+// event processing
+// ----------------------------------------------------------------------------
+
+#if wxUSE_VALIDATORS
+
+bool wxWindowBase::TryValidator(wxEvent& event)
+{
+    // Can only use the validator of the window which
+    // is receiving the event
+    if ( event.GetEventObject() == this )
+    {
+        wxValidator *validator = GetValidator();
+        if ( validator && validator->ProcessEvent(event) )
+        {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
+#endif // wxUSE_VALIDATORS
+
+bool wxWindowBase::TryParent(wxEvent& event)
+{
+    // Carry on up the parent-child hierarchy, but only if event is a command
+    // event: it wouldn't make sense for a parent to receive a child's size
+    // event, for example
+    if ( event.IsCommandEvent() )
+    {
+        // honour the requests to stop propagation at this window: this is
+        // used by the dialogs, for example, to prevent processing the events
+        // from the dialog controls in the parent frame which rarely, if ever,
+        // makes sense
+        if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
+        {
+            wxWindow *parent = GetParent();
+            if ( parent && !parent->IsBeingDeleted() )
+                return parent->GetEventHandler()->ProcessEvent(event);
+        }
+    }
+
+    return wxEvtHandler::TryParent(event);
+}
+
 // ----------------------------------------------------------------------------
 // global functions
 // ----------------------------------------------------------------------------