From: Václav Slavík Date: Fri, 25 May 2007 12:20:25 +0000 (+0000) Subject: implemented wxActivateEvent and restoring focus after a TLW that owned it was destroyed X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6954a1e2c983321297c11050d380485a8f3c724d?ds=inline implemented wxActivateEvent and restoring focus after a TLW that owned it was destroyed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46207 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dfb/nonownedwnd.h b/include/wx/dfb/nonownedwnd.h index 96d2ebbf88..f657eb236f 100644 --- a/include/wx/dfb/nonownedwnd.h +++ b/include/wx/dfb/nonownedwnd.h @@ -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(); diff --git a/include/wx/dfb/toplevel.h b/include/wx/dfb/toplevel.h index fce0970d7e..983320ffe2 100644 --- a/include/wx/dfb/toplevel.h +++ b/include/wx/dfb/toplevel.h @@ -61,6 +61,8 @@ protected: // common part of all ctors void Init(); + virtual void HandleFocusEvent(const wxDFBWindowEvent& event_); + protected: wxString m_title; diff --git a/src/dfb/nonownedwnd.cpp b/src/dfb/nonownedwnd.cpp index 886f918b0c..35e8d3fd74 100644 --- a/src/dfb/nonownedwnd.cpp +++ b/src/dfb/nonownedwnd.cpp @@ -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_); } // --------------------------------------------------------------------------- diff --git a/src/dfb/toplevel.cpp b/src/dfb/toplevel.cpp index cf667df95d..c8c36de1f1 100644 --- a/src/dfb/toplevel.cpp +++ b/src/dfb/toplevel.cpp @@ -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(); + } + } +} diff --git a/src/dfb/window.cpp b/src/dfb/window.cpp index c115e67ab9..d07170da05 100644 --- a/src/dfb/window.cpp +++ b/src/dfb/window.cpp @@ -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; }