]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toplevel.cpp
Disable wxUSE_ENH_METAFILE for wxGTK builds.
[wxWidgets.git] / src / gtk / toplevel.cpp
index b1188837b56ff9ab02872831735434b1f6d58bab..542cfc0cc5459cde0318babb33388ac937396821 100644 (file)
@@ -208,6 +208,37 @@ gboolean gtk_frame_focus_out_callback(GtkWidget * WXUNUSED(widget),
 }
 }
 
+// ----------------------------------------------------------------------------
+// "key_press_event"
+// ----------------------------------------------------------------------------
+
+extern "C" {
+static gboolean
+wxgtk_tlw_key_press_event(GtkWidget *widget, GdkEventKey *event)
+{
+    GtkWindow* const window = GTK_WINDOW(widget);
+
+    // By default GTK+ checks for the menu accelerators in this (top level)
+    // window first and then propagates the event to the currently focused
+    // child from where it bubbles up the window parent chain. In wxWidgets,
+    // however, we want the child window to have the event first but still
+    // handle it as an accelerator if it's not processed there, so we need to
+    // customize this by reversing the order of the steps done in the standard
+    // GTK+ gtk_window_key_press_event() handler.
+
+    if ( gtk_window_propagate_key_event(window, event) )
+        return TRUE;
+
+    if ( gtk_window_activate_key(window, event) )
+        return TRUE;
+
+    if (GTK_WIDGET_GET_CLASS(widget)->key_press_event(widget, event))
+        return TRUE;
+
+    return FALSE;
+}
+}
+
 //-----------------------------------------------------------------------------
 // "size_allocate" from m_wxwindow
 //-----------------------------------------------------------------------------
@@ -216,11 +247,12 @@ extern "C" {
 static void
 size_allocate(GtkWidget*, GtkAllocation* alloc, wxTopLevelWindowGTK* win)
 {
-    if (win->m_oldClientWidth  != alloc->width ||
-        win->m_oldClientHeight != alloc->height)
+    win->m_useCachedClientSize = true;
+    if (win->m_clientWidth  != alloc->width ||
+        win->m_clientHeight != alloc->height)
     {
-        win->m_oldClientWidth  = alloc->width;
-        win->m_oldClientHeight = alloc->height;
+        win->m_clientWidth  = alloc->width;
+        win->m_clientHeight = alloc->height;
 
         GtkAllocation a;
         gtk_widget_get_allocation(win->m_widget, &a);
@@ -343,7 +375,8 @@ gtk_frame_map_callback( GtkWidget*,
         // tlw that was "rolled up" with some WMs.
         // Queue a resize rather than sending size event directly to allow
         // children to be made visible first.
-        win->m_oldClientWidth = 0;
+        win->m_useCachedClientSize = false;
+        win->m_clientWidth = 0;
         gtk_widget_queue_resize(win->m_wxwindow);
     }
     // it is possible for m_isShown to be false here, see bug #9909
@@ -643,13 +676,10 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     g_signal_connect_after (m_widget, "focus_out_event",
                       G_CALLBACK (gtk_frame_focus_out_callback), this);
 
-    // GTK processes key events at the top level first, which handles for
-    // menu accelerators and shortcuts before passing the event on to the
-    // focus child window to begin propagation. We want to propagate
-    // first, so we connect gtk_window_propagate_key_event to
-    // key_press_event.
+    // We need to customize the default GTK+ logic for key processing to make
+    // it conforming to wxWidgets event processing order.
     g_signal_connect (m_widget, "key_press_event",
-                      G_CALLBACK (gtk_window_propagate_key_event), NULL);
+                      G_CALLBACK (wxgtk_tlw_key_press_event), NULL);
 
 #ifdef GDK_WINDOWING_X11
 #ifdef __WXGTK3__
@@ -1067,12 +1097,13 @@ void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int si
     if (m_width != oldSize.x || m_height != oldSize.y)
     {
         m_deferShowAllowed = true;
+        m_useCachedClientSize = false;
 
         int w, h;
         GTKDoGetSize(&w, &h);
         gtk_window_resize(GTK_WINDOW(m_widget), w, h);
 
-        GetClientSize(&m_oldClientWidth, &m_oldClientHeight);
+        DoGetClientSize(&m_clientWidth, &m_clientHeight);
         wxSizeEvent event(GetSize(), GetId());
         event.SetEventObject(this);
         HandleWindowEvent(event);
@@ -1102,6 +1133,8 @@ void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const
         if ( height )
             *height = 0;
     }
+    else if (m_useCachedClientSize)
+        base_type::DoGetClientSize(width, height);
     else
     {
         GTKDoGetSize(width, height);
@@ -1159,6 +1192,7 @@ void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize)
         GetCachedDecorSize() = decorSize;
     if (m_updateDecorSize && m_decorSize != decorSize)
     {
+        m_useCachedClientSize = false;
         const wxSize diff = decorSize - m_decorSize;
         m_decorSize = decorSize;
         bool resized = false;
@@ -1186,7 +1220,7 @@ void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize)
             m_height += diff.y;
             if (m_width  < 1) m_width  = 1;
             if (m_height < 1) m_height = 1;
-            m_oldClientWidth = 0;
+            m_clientWidth = 0;
             gtk_widget_queue_resize(m_wxwindow);
         }
     }
@@ -1194,7 +1228,7 @@ void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize)
     {
         // gtk_widget_show() was deferred, do it now
         m_deferShow = false;
-        GetClientSize(&m_oldClientWidth, &m_oldClientHeight);
+        DoGetClientSize(&m_clientWidth, &m_clientHeight);
         wxSizeEvent sizeEvent(GetSize(), GetId());
         sizeEvent.SetEventObject(this);
         HandleWindowEvent(sizeEvent);