* 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;
};
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);
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));
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
{
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;
gboolean change_width,
gint width,
gboolean change_height,
- gint height)
+ gint height,
+ gboolean is_geometry)
{
GtkWindowGeometryInfo *info;
g_object_freeze_notify (G_OBJECT (window));
+ info->default_is_geometry = is_geometry != FALSE;
+
if (change_width)
{
if (width == 0)
* 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
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);
}
/**
/**
* 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
/* Check for mnemonics and accelerators
*/
if (!handled)
- handled = gtk_window_activate_key (window, event);
+ handled = _gtk_window_activate_key (window, event);
if (!handled)
{
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
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;
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;
}
gtk_window_real_set_focus (GtkWindow *window,
GtkWidget *focus)
{
- GdkEventFocus event;
gboolean def_flags = 0;
if (window->default_widget)
}
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;
}
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 &&
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
* 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.
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;
}
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,
{
struct {
GtkWindow *window;
- GtkWindowKeysForeach func;
+ GtkWindowKeysForeachFunc func;
gpointer func_data;
} *info = data;
(*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;
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;
}
}
-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;