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
This commit is contained in:
Václav Slavík
2007-05-25 12:20:25 +00:00
parent c821db16e6
commit 6954a1e2c9
5 changed files with 61 additions and 95 deletions

View 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();

View File

@@ -61,6 +61,8 @@ protected:
// common part of all ctors
void Init();
virtual void HandleFocusEvent(const wxDFBWindowEvent& event_);
protected:
wxString m_title;

View 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_);
}
// ---------------------------------------------------------------------------

View 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();
}
}
}

View 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;
}