]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/window.cpp
Removed duplicate file
[wxWidgets.git] / src / gtk1 / window.cpp
index 254545aa5bd8088fd6fa12ca17a8d3f5c558daa1..ff368baf68f3c84530e71d48828a7d8aeaede77d 100644 (file)
@@ -208,7 +208,6 @@ extern wxCursor   g_globalCursor;
 // inside it
 static wxWindowGTK  *g_captureWindow = (wxWindowGTK*) NULL;
 static bool g_captureWindowHasMouse = FALSE;
 // inside it
 static wxWindowGTK  *g_captureWindow = (wxWindowGTK*) NULL;
 static bool g_captureWindowHasMouse = FALSE;
-static wxWindowList g_capturedWindows;
 
 /* extern */ wxWindowGTK  *g_focusWindow = (wxWindowGTK*) NULL;
 
 
 /* extern */ wxWindowGTK  *g_focusWindow = (wxWindowGTK*) NULL;
 
@@ -217,6 +216,11 @@ static wxWindowList g_capturedWindows;
 // keeps its previous value
 static wxWindowGTK *g_focusWindowLast = (wxWindowGTK *)NULL;
 
 // 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
 // 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;
 }
 
     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
 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
 
     }
 #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 );
 
     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"
 //-----------------------------------------------------------------------------
 
 // "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
 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;
 
     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
     // 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
 
     }
 #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 );
 
     wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
     event.SetEventObject( win );
@@ -2475,11 +2507,12 @@ bool wxWindowGTK::Create( wxWindow *parent,
 
 wxWindowGTK::~wxWindowGTK()
 {
 
 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_focusWindow == this)
         g_focusWindow = NULL;
 
+    if (g_activeFrame == this)
+        g_activeFrame = NULL;
+
     m_isBeingDeleted = TRUE;
     m_hasVMT = FALSE;
 
     m_isBeingDeleted = TRUE;
     m_hasVMT = FALSE;
 
@@ -2799,6 +2832,18 @@ void wxWindowGTK::OnInternalIdle()
         wxTheApp->SetActive(activate, (wxWindow *)g_focusWindowLast);
     }
 
         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;
 
     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;
     }
     
         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
 }
 
 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))
     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);
             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) )
         {
     {
         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;
 }
 
     return TRUE;
 }
 
-static void wxDoCaptureMouse(wxWindowGTK *wnd)
+void wxWindowGTK::CaptureMouse()
 {
 {
+    wxCHECK_RET( m_widget != NULL, wxT("invalid window") );
+
     GdkWindow *window = (GdkWindow*) NULL;
     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
     else
-        window = wnd->GetConnectWidget()->window;
+        window = GetConnectWidget()->window;
 
     wxCHECK_RET( window, _T("CaptureMouse() failed") );
 
 
     wxCHECK_RET( window, _T("CaptureMouse() failed") );
 
-    wxCursor* cursor = &wnd->GetCursor();
+    wxCursor* cursor = & m_cursor;
     if (!cursor->Ok())
         cursor = wxSTANDARD_CURSOR;
 
     if (!cursor->Ok())
         cursor = wxSTANDARD_CURSOR;
 
@@ -3777,54 +3814,27 @@ static void wxDoCaptureMouse(wxWindowGTK *wnd)
                       (GdkWindow *) NULL,
                       cursor->GetCursor(),
                       (guint32)GDK_CURRENT_TIME );
                       (GdkWindow *) NULL,
                       cursor->GetCursor(),
                       (guint32)GDK_CURRENT_TIME );
-    g_captureWindow = wnd;
+    g_captureWindow = this;
     g_captureWindowHasMouse = TRUE;
     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;
     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
     else
-        window = wnd->GetConnectWidget()->window;
+        window = GetConnectWidget()->window;
 
     if (!window)
         return;
 
     gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME );
     g_captureWindow = (wxWindowGTK*) NULL;
 
     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 */
 }
 
 /* static */