X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc1e14d62594e4d16ae9e5fa2dc5b46c2ac362ad..32bc74c0349f08401d2935d194df5118f552f45c:/src/gtk1/window.cpp diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 254545aa5b..ff368baf68 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -208,7 +208,6 @@ extern wxCursor g_globalCursor; // inside it static wxWindowGTK *g_captureWindow = (wxWindowGTK*) NULL; static bool g_captureWindowHasMouse = FALSE; -static wxWindowList g_capturedWindows; /* extern */ wxWindowGTK *g_focusWindow = (wxWindowGTK*) NULL; @@ -217,6 +216,11 @@ static wxWindowList g_capturedWindows; // keeps its previous value static wxWindowGTK *g_focusWindowLast = (wxWindowGTK *)NULL; +// the frame that is currently active (i.e. its child has focus). It is +// used to generate wxActivateEvents +static wxWindowGTK *g_activeFrame = (wxWindowGTK *)NULL; +static bool g_activeFrameLostFocus = FALSE; + // if we detect that the app has got/lost the focus, we set this variable to // either TRUE or FALSE and an activate event will be sent during the next // OnIdle() call and it is reset to -1: this value means that we shouldn't @@ -359,6 +363,16 @@ wxWindow *wxFindFocusedChild(wxWindowGTK *win) return (wxWindow *)NULL; } +// Returns toplevel grandparent of given window: +static wxWindowGTK* wxGetTopLevelParent(wxWindowGTK *win) +{ + wxWindowGTK *p = win; + while (p && !p->IsTopLevel()) + p = p->GetParent(); + return p; +} + + static void draw_frame( GtkWidget *widget, wxWindowGTK *win ) { // wxUniversal widgets draw the borders and scrollbars themselves @@ -1710,14 +1724,24 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, } #endif // wxUSE_CARET - if (win->IsTopLevel()) + + wxWindowGTK *active = wxGetTopLevelParent(win); + if ( active != g_activeFrame ) { - wxActivateEvent event( wxEVT_ACTIVATE, TRUE, win->GetId() ); - event.SetEventObject( win ); + if ( g_activeFrame ) + { + wxActivateEvent event(wxEVT_ACTIVATE, FALSE, g_activeFrame->GetId()); + event.SetEventObject(g_activeFrame); + g_activeFrame->GetEventHandler()->ProcessEvent(event); + } - // ignore return value - win->GetEventHandler()->ProcessEvent( event ); + g_activeFrame = active; + wxActivateEvent event(wxEVT_ACTIVATE, TRUE, g_activeFrame->GetId()); + event.SetEventObject(g_activeFrame); + g_activeFrame->GetEventHandler()->ProcessEvent(event); } + g_activeFrameLostFocus = FALSE; + wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); event.SetEventObject( win ); @@ -1736,6 +1760,8 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, // "focus_out_event" //----------------------------------------------------------------------------- +static GtkWidget *gs_widgetLastFocus = NULL; + static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindowGTK *win ) { DEBUG_MAIN_THREAD @@ -1746,6 +1772,18 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED if (!win->m_hasVMT) return FALSE; if (g_blockEventsOnDrag) return FALSE; + // VZ: this is really weird but GTK+ seems to call us from inside + // gtk_widget_grab_focus(), i.e. it first sends "focus_out" signal to + // this widget and then "focus_in". This is totally unexpected and + // completely breaks wxUniv code so ignore this dummy event (we can't + // be losing focus if we're about to acquire it!) + if ( widget == gs_widgetLastFocus ) + { + gs_widgetLastFocus = NULL; + + return FALSE; + } + // if the focus goes out of our app alltogether, OnIdle() will send // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset // g_sendActivateEvent to -1 @@ -1778,14 +1816,8 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED } #endif // wxUSE_CARET - if (win->IsTopLevel()) - { - wxActivateEvent event( wxEVT_ACTIVATE, FALSE, win->GetId() ); - event.SetEventObject( win ); - - // ignore return value - win->GetEventHandler()->ProcessEvent( event ); - } + wxASSERT_MSG( wxGetTopLevelParent(win) == g_activeFrame, wxT("unfocusing window that haven't gained focus properly") ) + g_activeFrameLostFocus = TRUE; wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); event.SetEventObject( win ); @@ -2475,11 +2507,12 @@ bool wxWindowGTK::Create( wxWindow *parent, wxWindowGTK::~wxWindowGTK() { - wxASSERT_MSG( g_capturedWindows.IndexOf(this) == wxNOT_FOUND, wxT("trying to destroy window that didn't release focus") ); - if (g_focusWindow == this) g_focusWindow = NULL; + if (g_activeFrame == this) + g_activeFrame = NULL; + m_isBeingDeleted = TRUE; m_hasVMT = FALSE; @@ -2799,6 +2832,18 @@ void wxWindowGTK::OnInternalIdle() wxTheApp->SetActive(activate, (wxWindow *)g_focusWindowLast); } + if ( g_activeFrameLostFocus ) + { + if ( g_activeFrame ) + { + wxActivateEvent event(wxEVT_ACTIVATE, FALSE, g_activeFrame->GetId()); + event.SetEventObject(g_activeFrame); + g_activeFrame->GetEventHandler()->ProcessEvent(event); + g_activeFrame = NULL; + } + g_activeFrameLostFocus = FALSE; + } + wxCursor cursor = m_cursor; if (g_globalCursor.Ok()) cursor = g_globalCursor; @@ -2992,20 +3037,8 @@ void wxWindowGTK::DoGetPosition( int *x, int *y ) const dy = pizza->yoffset; } - int nx = m_x - dx; - int ny = m_y - dy; - - if ( !IsTopLevel() && m_parent ) - { - // We may be faking the client origin. So a window that's really at (0, - // 30) may appear (to wxWin apps) to be at (0, 0). - wxPoint pt(m_parent->GetClientAreaOrigin()); - nx -= pt.x; - ny -= pt.y; - } - - if (x) (*x) = nx; - if (y) (*y) = ny; + if (x) (*x) = m_x - dx; + if (y) (*y) = m_y - dy; } void wxWindowGTK::DoClientToScreen( int *x, int *y ) const @@ -3168,11 +3201,13 @@ void wxWindowGTK::SetFocus() if (m_wxwindow) { if (!GTK_WIDGET_HAS_FOCUS (m_wxwindow)) + { + // see comment in gtk_window_focus_out_callback() + gs_widgetLastFocus = m_wxwindow; gtk_widget_grab_focus (m_wxwindow); - return; + } } - - if (m_widget) + else if (m_widget) { if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) ) { @@ -3754,17 +3789,19 @@ bool wxWindowGTK::SetFont( const wxFont &font ) return TRUE; } -static void wxDoCaptureMouse(wxWindowGTK *wnd) +void wxWindowGTK::CaptureMouse() { + wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); + GdkWindow *window = (GdkWindow*) NULL; - if (wnd->m_wxwindow) - window = GTK_PIZZA(wnd->m_wxwindow)->bin_window; + if (m_wxwindow) + window = GTK_PIZZA(m_wxwindow)->bin_window; else - window = wnd->GetConnectWidget()->window; + window = GetConnectWidget()->window; wxCHECK_RET( window, _T("CaptureMouse() failed") ); - wxCursor* cursor = &wnd->GetCursor(); + wxCursor* cursor = & m_cursor; if (!cursor->Ok()) cursor = wxSTANDARD_CURSOR; @@ -3777,54 +3814,27 @@ static void wxDoCaptureMouse(wxWindowGTK *wnd) (GdkWindow *) NULL, cursor->GetCursor(), (guint32)GDK_CURRENT_TIME ); - g_captureWindow = wnd; + g_captureWindow = this; g_captureWindowHasMouse = TRUE; - wxLogDebug("captured %p", wnd); } -static void wxDoReleaseMouse(wxWindowGTK *wnd) +void wxWindowGTK::ReleaseMouse() { - wxLogDebug("trying to release %p", wnd); + wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); + wxCHECK_RET( g_captureWindow, wxT("can't release mouse - not captured") ); GdkWindow *window = (GdkWindow*) NULL; - if (wnd->m_wxwindow) - window = GTK_PIZZA(wnd->m_wxwindow)->bin_window; + if (m_wxwindow) + window = GTK_PIZZA(m_wxwindow)->bin_window; else - window = wnd->GetConnectWidget()->window; + window = GetConnectWidget()->window; if (!window) return; gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); g_captureWindow = (wxWindowGTK*) NULL; - wxLogDebug("released %p", wnd); -} - -void wxWindowGTK::CaptureMouse() -{ - wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); - - wxLogDebug("CAPTURE %p", this); - wxWindowList::Node *last = g_capturedWindows.GetLast(); - if (last) - wxDoReleaseMouse(last->GetData()); - - g_capturedWindows.Append(this); - wxDoCaptureMouse(this); -} - -void wxWindowGTK::ReleaseMouse() -{ - wxCHECK_RET( m_widget != NULL, wxT("invalid window") ); - - wxLogDebug("RELEASE %p", this); - wxDoReleaseMouse(this); - g_capturedWindows.DeleteObject(this); - - wxWindowList::Node *last = g_capturedWindows.GetLast(); - if (last) - wxDoCaptureMouse(last->GetData()); } /* static */