]> git.saurik.com Git - wxWidgets.git/commitdiff
implemented wxActivateEvent and restoring focus after a TLW that owned it was destroyed
authorVáclav Slavík <vslavik@fastmail.fm>
Fri, 25 May 2007 12:20:25 +0000 (12:20 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Fri, 25 May 2007 12:20:25 +0000 (12:20 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dfb/nonownedwnd.h
include/wx/dfb/toplevel.h
src/dfb/nonownedwnd.cpp
src/dfb/toplevel.cpp
src/dfb/window.cpp

index 96d2ebbf88ba0e38ba62bb015a593776269cfc12..f657eb236f0e8079e3695534d814be77a4d70de2 100644 (file)
@@ -88,6 +88,10 @@ protected:
     // wxWindows as in wx
     void SetDfbFocus();
 
+    // overriden in wxTopLevelWindowDFB, there's no common handling for wxTLW
+    // and wxPopupWindow to be done here
+    virtual void HandleFocusEvent(const wxDFBWindowEvent& WXUNUSED(event_)) {}
+
 private:
     // do queued painting in idle time
     void HandleQueuedPaintRequests();
index fce0970d7e5d3fbc1bf47df479dbb7afdc6f2899..983320ffe25ca1e97d304b0d91e8fa96096ff24a 100644 (file)
@@ -61,6 +61,8 @@ protected:
     // common part of all ctors
     void Init();
 
+    virtual void HandleFocusEvent(const wxDFBWindowEvent& event_);
+
 protected:
     wxString      m_title;
 
index 886f918b0c336ab20851b5507fe893703e46df06..35e8d3fd741200f9c5daad0429cce96c70f17c4a 100644 (file)
@@ -243,20 +243,7 @@ bool wxNonOwnedWindow::Show(bool show)
     m_dfbwin->SetOpacity(show ? m_opacity : 0);
 
     if ( show )
-    {
-        wxWindow *focused = wxWindow::FindFocus();
-        if ( focused && focused->GetTLW() == this )
-        {
-            SetDfbFocus();
-        }
-        else if ( CanAcceptFocus() )
-        {
-            // FIXME: we should probably always call SetDfbFocus instead
-            // and call SetFocus() from wxActivateEvent/DWET_GOTFOCUS
-            // handler
-            SetFocus();
-        }
-    }
+        SetDfbFocus();
 
     return true;
 }
@@ -403,42 +390,41 @@ void wxNonOwnedWindow::HandleDFBWindowEvent(const wxDFBWindowEvent& event_)
     }
 
     wxNonOwnedWindow *tlw = gs_dfbWindowsMap[event.window_id];
-    wxWindow *recipient = NULL;
-    void (wxWindow::*handlerFunc)(const wxDFBWindowEvent&) = NULL;
 
     switch ( event.type )
     {
         case DWET_KEYDOWN:
         case DWET_KEYUP:
         {
-            recipient = wxWindow::FindFocus();
-            handlerFunc = &wxWindowDFB::HandleKeyEvent;
+            wxWindow *recipient = wxWindow::FindFocus();
+            if ( !recipient )
+            {
+                wxLogTrace(TRACE_EVENTS,
+                           _T("ignoring event: no recipient window"));
+                return;
+            }
+
+            wxCHECK_RET( recipient && recipient->GetTLW() == tlw,
+                         _T("event recipient not in TLW which received the event") );
+
+            recipient->HandleKeyEvent(event_);
             break;
         }
 
+        case DWET_GOTFOCUS:
+        case DWET_LOSTFOCUS:
+            tlw->HandleFocusEvent(event_);
+            break;
+
         case DWET_NONE:
         case DWET_ALL:
-        {
             wxFAIL_MSG( _T("invalid event type") );
             break;
-        }
 
         default:
             // we're not interested in them here
             break;
     }
-
-    if ( !recipient )
-    {
-        wxLogTrace(TRACE_EVENTS, _T("ignoring event: no recipient window"));
-        return;
-    }
-
-    wxCHECK_RET( recipient && recipient->GetTLW() == tlw,
-                 _T("event recipient not in TLW which received the event") );
-
-    // process the event:
-    (recipient->*handlerFunc)(event_);
 }
 
 // ---------------------------------------------------------------------------
index cf667df95ddccd3f85d99e5f8b1155991f7caa42..c8c36de1f16acb34b47c367a6207059f23719d06 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "wx/dfb/private.h"
 
+#define TRACE_EVENTS _T("events")
+
 // ============================================================================
 // wxTopLevelWindowDFB
 // ============================================================================
@@ -166,3 +168,38 @@ bool wxTopLevelWindowDFB::IsIconized() const
 {
     return false;
 }
+
+// ----------------------------------------------------------------------------
+// focus handling
+// ----------------------------------------------------------------------------
+
+void wxTopLevelWindowDFB::HandleFocusEvent(const wxDFBWindowEvent& event_)
+{
+    const DFBWindowEvent& dfbevent = event_;
+    const bool activate = (dfbevent.type == DWET_GOTFOCUS);
+
+    wxLogTrace(TRACE_EVENTS,
+               _T("toplevel window %p ('%s') %s focus"),
+               this, GetName(),
+               activate ? _T("got") : _T("lost"));
+
+    wxActivateEvent event(wxEVT_ACTIVATE, activate, GetId());
+    event.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(event);
+
+    // if a frame that doesn't have wx focus inside it just got focus, we
+    // need to set focus to it (or its child):
+    if ( activate )
+    {
+        wxWindow *focused = wxWindow::FindFocus();
+        if ( !focused || focused->GetTLW() != this )
+        {
+            wxLogTrace(TRACE_EVENTS,
+                       _T("setting wx focus to toplevel window %p ('%s')"),
+                       this, GetName());
+
+            if ( CanAcceptFocus() )
+                SetFocus();
+        }
+    }
+}
index c115e67ab9d9b49e78933bf2f31414ed07b0a400..d07170da05b7f7b99bb69234121d0c7e1ec6e879 100644 (file)
@@ -94,25 +94,6 @@ wxWindowDFB::~wxWindowDFB()
     if ( gs_mouseCapture == this )
         ReleaseMouse();
 
-#warning "FIXME: what to do with gs_activeFrame here and elsewhere?"
-#if 0
-    if (gs_activeFrame == this)
-    {
-        gs_activeFrame = NULL;
-        // activate next frame in Z-order:
-        if ( m_wnd->prev )
-        {
-            wxWindowDFB *win = (wxWindowDFB*)m_wnd->prev->userData;
-            win->SetFocus();
-        }
-        else if ( m_wnd->next )
-        {
-            wxWindowDFB *win = (wxWindowDFB*)m_wnd->next->userData;
-            win->SetFocus();
-        }
-    }
-#endif
-
     if ( gs_focusedWindow == this )
         DFBKillFocus();
 
@@ -221,26 +202,6 @@ void wxWindowDFB::SetFocus()
     //       are hidden; when the TLW becomes visible, it will set the focus
     //       to use from wxTLW::Show()
 
-    #warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS"
-    #warning "FIXME: keep this or not? not, think multiapp core"
-#if 0
-    wxWindowDFB *active = wxGetTopLevelParent((wxWindow*)this);
-    if ( !(m_windowStyle & wxPOPUP_WINDOW) && active != gs_activeFrame )
-    {
-        if ( gs_activeFrame )
-        {
-            wxActivateEvent event(wxEVT_ACTIVATE, false, gs_activeFrame->GetId());
-            event.SetEventObject(gs_activeFrame);
-            gs_activeFrame->GetEventHandler()->ProcessEvent(event);
-        }
-
-        gs_activeFrame = active;
-        wxActivateEvent event(wxEVT_ACTIVATE, true, gs_activeFrame->GetId());
-        event.SetEventObject(gs_activeFrame);
-        gs_activeFrame->GetEventHandler()->ProcessEvent(event);
-    }
-#endif
-
     // notify the parent keeping track of focus for the kbd navigation
     // purposes that we got it
     wxChildFocusEvent eventFocus((wxWindow*)this);
@@ -301,30 +262,6 @@ bool wxWindowDFB::Show(bool show)
     // parent area at the place of this window (if hiding):
     DoRefreshWindow();
 
-#warning "FIXME: all of this must be implemented for DFB"
-#if 0
-    DFB_wmShowWindow(m_wnd, show);
-
-    if (!show && gs_activeFrame == this)
-    {
-        // activate next frame in Z-order:
-        if ( m_wnd->prev )
-        {
-            wxWindowDFB *win = (wxWindowDFB*)m_wnd->prev->userData;
-            win->SetFocus();
-        }
-        else if ( m_wnd->next )
-        {
-            wxWindowDFB *win = (wxWindowDFB*)m_wnd->next->userData;
-            win->SetFocus();
-        }
-        else
-        {
-            gs_activeFrame = NULL;
-        }
-    }
-#endif
-
     return true;
 }