]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkwindow.c
Fix to properly take the default window into account by setting a flag and
[~andy/gtk] / gtk / gtkwindow.c
index a031e8bad34aa1d6900d95094d71bbdb3d4d0ffe..c1e006de622113845b342c1c1bf1fb7af60295fe 100644 (file)
@@ -118,6 +118,12 @@ struct _GtkWindowGeometryInfo
    * we sent the last configure request.
    */
   guint          position_constraints_changed : 1;
+
+  /* if true, default_width, height come from gtk_window_parse_geometry,
+   * and thus should be multiplied by the increments and affect the
+   * geometry widget only
+   */
+  guint          default_is_geometry : 1;
   
   GtkWindowLastGeometryInfo last;
 };
@@ -220,14 +226,13 @@ static void     gtk_window_set_default_size_internal (GtkWindow    *window,
                                                       gboolean      change_width,
                                                       gint          width,
                                                       gboolean      change_height,
-                                                      gint          height);
+                                                      gint          height,
+                                                     gboolean      is_geometry);
 
 static void     gtk_window_realize_icon               (GtkWindow    *window);
 static void     gtk_window_unrealize_icon             (GtkWindow    *window);
 
 static void        gtk_window_notify_keys_changed (GtkWindow   *window);
-static gboolean    gtk_window_activate_key        (GtkWindow   *window,
-                                                  GdkEventKey *event);
 static GtkKeyHash *gtk_window_get_key_hash        (GtkWindow   *window);
 static void        gtk_window_free_key_hash       (GtkWindow   *window);
 
@@ -677,12 +682,12 @@ gtk_window_set_property (GObject      *object,
     case PROP_DEFAULT_WIDTH:
       gtk_window_set_default_size_internal (window,
                                             TRUE, g_value_get_int (value),
-                                            FALSE, -1);
+                                            FALSE, -1, FALSE);
       break;
     case PROP_DEFAULT_HEIGHT:
       gtk_window_set_default_size_internal (window,
                                             FALSE, -1,
-                                            TRUE, g_value_get_int (value));
+                                            TRUE, g_value_get_int (value), FALSE);
       break;
     case PROP_DESTROY_WITH_PARENT:
       gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
@@ -1138,7 +1143,7 @@ gtk_window_add_mnemonic (GtkWindow *window,
   if (mnemonic)
     {
       g_return_if_fail (g_slist_find (mnemonic->targets, target) == NULL);
-      mnemonic->targets = g_slist_prepend (mnemonic->targets, target);
+      mnemonic->targets = g_slist_append (mnemonic->targets, target);
     }
   else
     {
@@ -1757,6 +1762,7 @@ gtk_window_get_geometry_info (GtkWindow *window,
       info->initial_x = 0;
       info->initial_y = 0;
       info->initial_pos_set = FALSE;
+      info->default_is_geometry = FALSE;
       info->position_constraints_changed = FALSE;
       info->last.configure_request.x = 0;
       info->last.configure_request.y = 0;
@@ -2342,7 +2348,8 @@ gtk_window_set_default_size_internal (GtkWindow    *window,
                                       gboolean      change_width,
                                       gint          width,
                                       gboolean      change_height,
-                                      gint          height)
+                                      gint          height,
+                                     gboolean      is_geometry)
 {
   GtkWindowGeometryInfo *info;
 
@@ -2353,6 +2360,8 @@ gtk_window_set_default_size_internal (GtkWindow    *window,
 
   g_object_freeze_notify (G_OBJECT (window));
 
+  info->default_is_geometry = is_geometry != FALSE;
+
   if (change_width)
     {
       if (width == 0)
@@ -2407,11 +2416,6 @@ gtk_window_set_default_size_internal (GtkWindow    *window,
  * For more control over a window's initial size and how resizing works,
  * investigate gtk_window_set_geometry_hints().
  *
- * A useful feature: if you set the "geometry widget" via
- * gtk_window_set_geometry_hints(), the default size specified by
- * gtk_window_set_default_size() will be the default size of that
- * widget, not of the entire window.
- *
  * For some uses, gtk_window_resize() is a more appropriate function.
  * gtk_window_resize() changes the current size of the window, rather
  * than the size to be used on initial display. gtk_window_resize() always
@@ -2433,7 +2437,7 @@ gtk_window_set_default_size (GtkWindow   *window,
   g_return_if_fail (width >= -1);
   g_return_if_fail (height >= -1);
 
-  gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height);
+  gtk_window_set_default_size_internal (window, TRUE, width, TRUE, height, FALSE);
 }
 
 /**
@@ -2469,8 +2473,8 @@ gtk_window_get_default_size (GtkWindow *window,
 /**
  * gtk_window_resize:
  * @window: a #GtkWindow
- * @width: width to resize the window to
- * @height: height to resize the window to
+ * @width: width in pixels to resize the window to
+ * @height: height in pixels to resize the window to
  *
  * Resizes the window as if the user had done so, obeying geometry
  * constraints. The default geometry constraint is that windows may
@@ -3534,7 +3538,7 @@ gtk_window_key_press_event (GtkWidget   *widget,
   /* Check for mnemonics and accelerators
    */
   if (!handled)
-    handled = gtk_window_activate_key (window, event);
+    handled = _gtk_window_activate_key (window, event);
 
   if (!handled)
     {
@@ -3629,12 +3633,35 @@ gtk_window_leave_notify_event (GtkWidget        *widget,
   return FALSE;
 }
 
+static void
+do_focus_change (GtkWidget *widget,
+                gboolean   in)
+{
+  GdkEventFocus fevent;
+
+  g_object_ref (widget);
+   
+ if (in)
+    GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
+  else
+    GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+
+  fevent.type = GDK_FOCUS_CHANGE;
+  fevent.window = widget->window;
+  fevent.in = in;
+  
+  gtk_widget_event (widget, (GdkEvent*) &fevent);
+  
+  g_object_notify (G_OBJECT (widget), "has_focus");
+
+  g_object_unref (widget);
+}
+
 static gint
 gtk_window_focus_in_event (GtkWidget     *widget,
                           GdkEventFocus *event)
 {
   GtkWindow *window = GTK_WINDOW (widget);
-  GdkEventFocus fevent;
 
   /* It appears spurious focus in events can occur when
    *  the window is hidden. So we'll just check to see if
@@ -3648,13 +3675,7 @@ gtk_window_focus_in_event (GtkWidget     *widget,
       if (window->focus_widget &&
          window->focus_widget != widget &&
          !GTK_WIDGET_HAS_FOCUS (window->focus_widget))
-       {
-         fevent.type = GDK_FOCUS_CHANGE;
-         fevent.window = window->focus_widget->window;
-         fevent.in = TRUE;
-
-         gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
-       }
+       do_focus_change (window->focus_widget, TRUE);   
     }
 
   return FALSE;
@@ -3665,20 +3686,13 @@ gtk_window_focus_out_event (GtkWidget     *widget,
                            GdkEventFocus *event)
 {
   GtkWindow *window = GTK_WINDOW (widget);
-  GdkEventFocus fevent;
 
   window->has_focus = FALSE;
   
   if (window->focus_widget &&
       window->focus_widget != widget &&
       GTK_WIDGET_HAS_FOCUS (window->focus_widget))
-    {
-      fevent.type = GDK_FOCUS_CHANGE;
-      fevent.window = window->focus_widget->window;
-      fevent.in = FALSE;
-
-      gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
-    }
+    do_focus_change (window->focus_widget, FALSE);
 
   return FALSE;
 }
@@ -3788,7 +3802,6 @@ static void
 gtk_window_real_set_focus (GtkWindow *window,
                           GtkWidget *focus)
 {
-  GdkEventFocus event;
   gboolean def_flags = 0;
 
   if (window->default_widget)
@@ -3806,13 +3819,7 @@ gtk_window_real_set_focus (GtkWindow *window,
         }
 
       if (window->has_focus)
-       {
-         event.type = GDK_FOCUS_CHANGE;
-         event.window = window->focus_widget->window;
-         event.in = FALSE;
-         
-         gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
-       }
+       do_focus_change (window->focus_widget, FALSE);
     }
   
   window->focus_widget = focus;
@@ -3830,13 +3837,7 @@ gtk_window_real_set_focus (GtkWindow *window,
        }
 
       if (window->has_focus)
-       {
-         event.type = GDK_FOCUS_CHANGE;
-         event.window = window->focus_widget->window;
-         event.in = TRUE;
-         
-         gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
-       }
+       do_focus_change (window->focus_widget, TRUE);
     }
   
   if (window->default_widget &&
@@ -3885,11 +3886,41 @@ gtk_window_compute_configure_request_size (GtkWindow *window,
 
        if (info)
          {
-           if (info->default_width > 0)
-             *width = info->default_width;
-           
-           if (info->default_height > 0)
-             *height = info->default_height;
+          gint base_width = 0;
+          gint base_height = 0;
+          gint width_inc = 1;
+          gint height_inc = 1;
+          
+          if (info->default_is_geometry &&
+              (info->default_width > 0 || info->default_height > 0))
+            {
+              GdkGeometry geometry;
+              guint flags;
+              
+              gtk_window_compute_hints (window, &geometry, &flags);
+
+              if (flags & GDK_HINT_BASE_SIZE)
+                {
+                  base_width = geometry.base_width;
+                  base_height = geometry.base_height;
+                }
+              else if (flags & GDK_HINT_MIN_SIZE)
+                {
+                  base_width = geometry.min_width;
+                  base_height = geometry.min_height;
+                }
+              if (flags & GDK_HINT_RESIZE_INC)
+                {
+                  width_inc = geometry.width_inc;
+                  height_inc = geometry.height_inc;
+                }
+            }
+            
+          if (info->default_width > 0)
+            *width = info->default_width * width_inc + base_width;
+          
+          if (info->default_height > 0)
+            *height = info->default_height * height_inc + base_height;
          }
     }
   else
@@ -4389,8 +4420,9 @@ gtk_window_move_resize (GtkWindow *window)
        * GTK_RESIZE_IMMEDIATE containers)
        */
       info->position_constraints_changed = FALSE;
-      window->need_default_position = FALSE;
       info->initial_pos_set = FALSE;
+      info->resize_width = -1;
+      info->resize_height = -1;
 
       /* for GTK_RESIZE_QUEUE toplevels, we are now awaiting a new
        * configure event in response to our resizing request.
@@ -5611,14 +5643,7 @@ gtk_window_parse_geometry (GtkWindow   *window,
   size_set = FALSE;
   if ((result & WidthValue) || (result & HeightValue))
     {
-      GtkWindowGeometryInfo *info;
-      info = gtk_window_get_geometry_info (window, FALSE);
-      if (info && info->mask & GDK_HINT_RESIZE_INC)
-        {
-          w *= info->geometry.width_inc;
-          h *= info->geometry.height_inc;
-        }
-      gtk_window_set_default_size (window, w, h);
+      gtk_window_set_default_size_internal (window, TRUE, w, TRUE, h, TRUE);
       size_set = TRUE;
     }
 
@@ -5680,12 +5705,6 @@ gtk_window_parse_geometry (GtkWindow   *window,
   return result != 0;
 }
 
-typedef void (*GtkWindowKeysForeach) (GtkWindow      *window,
-                                     guint           keyval,
-                                     GdkModifierType modifiers,
-                                     gboolean        is_mnemonic,
-                                     gpointer        data);
-
 static void
 gtk_window_mnemonic_hash_foreach (gpointer key,
                                  gpointer value,
@@ -5693,7 +5712,7 @@ gtk_window_mnemonic_hash_foreach (gpointer key,
 {
   struct {
     GtkWindow *window;
-    GtkWindowKeysForeach func;
+    GtkWindowKeysForeachFunc func;
     gpointer func_data;
   } *info = data;
 
@@ -5703,16 +5722,16 @@ gtk_window_mnemonic_hash_foreach (gpointer key,
     (*info->func) (info->window, mnemonic->keyval, info->window->mnemonic_modifier, TRUE, info->func_data);
 }
 
-static void
-gtk_window_keys_foreach (GtkWindow           *window,
-                        GtkWindowKeysForeach func,
-                        gpointer             func_data)
+void
+_gtk_window_keys_foreach (GtkWindow                *window,
+                         GtkWindowKeysForeachFunc func,
+                         gpointer                 func_data)
 {
   GSList *groups;
 
   struct {
     GtkWindow *window;
-    GtkWindowKeysForeach func;
+    GtkWindowKeysForeachFunc func;
     gpointer func_data;
   } info;
 
@@ -5795,7 +5814,7 @@ gtk_window_get_key_hash (GtkWindow *window)
     return key_hash;
   
   key_hash = _gtk_key_hash_new (gdk_keymap_get_default(), (GDestroyNotify)g_free);
-  gtk_window_keys_foreach (window, add_to_key_hash, key_hash);
+  _gtk_window_keys_foreach (window, add_to_key_hash, key_hash);
   g_object_set_data (G_OBJECT (window), "gtk-window-key-hash", key_hash);
 
   return key_hash;
@@ -5812,9 +5831,18 @@ gtk_window_free_key_hash (GtkWindow *window)
     }
 }
 
-static gboolean
-gtk_window_activate_key (GtkWindow   *window,
-                        GdkEventKey *event)
+/**
+ * _gtk_window_activate_key:
+ * @window: a #GtkWindow
+ * @event: a #GdkEventKey
+ * 
+ * Activates mnemonics and accelerators for this #GtKWindow
+ * 
+ * Return value: %TRUE if a mnemonic or accelerator was found and activated.
+ **/
+gboolean
+_gtk_window_activate_key (GtkWindow   *window,
+                         GdkEventKey *event)
 {
   GtkKeyHash *key_hash = g_object_get_data (G_OBJECT (window), "gtk-window-key-hash");
   GtkWindowKeyEntry *found_entry = NULL;