* </refsect2>
*/
+#define AUTO_MNEMONICS_DELAY 300 /* ms */
+
typedef struct _GtkDeviceGrabInfo GtkDeviceGrabInfo;
struct _GtkWindowPrivate
guint16 configure_request_count;
+ guint auto_mnemonics_timeout_id;
+
/* The following flags are initially TRUE (before a window is mapped).
* They cause us to compute a configure request that involves
* default-only parameters. Once mapped, we set them to FALSE.
const gchar *tagname,
gpointer user_data);
-
-static void gtk_window_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size);
-static void gtk_window_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size);
-
static void ensure_state_flag_backdrop (GtkWidget *widget);
G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
widget_class->focus = gtk_window_focus;
widget_class->move_focus = gtk_window_move_focus;
widget_class->draw = gtk_window_draw;
- widget_class->get_preferred_width = gtk_window_get_preferred_width;
- widget_class->get_preferred_height = gtk_window_get_preferred_height;
widget_class->window_state_event = gtk_window_state_event;
widget_class->direction_changed = gtk_window_direction_changed;
widget_class->state_changed = gtk_window_state_changed;
static void
gtk_window_init (GtkWindow *window)
{
+ GtkStyleContext *context;
GtkWindowPrivate *priv;
window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
"notify::gtk-application-prefer-dark-theme",
G_CALLBACK (gtk_window_on_theme_variant_changed), window);
#endif
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (window));
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
}
static void
* unsets the default widget for a #GtkWindow about. When setting
* (rather than unsetting) the default widget it's generally easier to
* call gtk_widget_grab_focus() on the widget. Before making a widget
- * the default widget, you must set the #GTK_CAN_DEFAULT flag on the
- * widget you'd like to make the default using GTK_WIDGET_SET_FLAGS().
+ * the default widget, you must call gtk_widget_set_can_default() on the
+ * widget you'd like to make the default.
**/
void
gtk_window_set_default (GtkWindow *window,
gtk_application_add_window (priv->application, window);
}
+ /* don't use a normal cast: application may be NULL */
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "app", (GActionGroup *) application);
+
g_object_notify (G_OBJECT (window), "application");
}
}
* using this function, GTK+ will do its best to convince the window
* manager not to show a close button. Depending on the system, this
* function may not have any effect when called on a window that is
- * already visible, so you should call it before calling gtk_window_show().
+ * already visible, so you should call it before calling gtk_widget_show().
*
* On Windows, this function always works, since there's no window manager
* policy involved.
g_free (priv->startup_id);
+ if (priv->auto_mnemonics_timeout_id)
+ {
+ g_source_remove (priv->auto_mnemonics_timeout_id);
+ priv->auto_mnemonics_timeout_id = 0;
+ }
+
#ifdef GDK_WINDOWING_X11
g_signal_handlers_disconnect_by_func (gtk_settings_get_default (),
gtk_window_on_theme_variant_changed,
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = window->priv;
GtkContainer *container = GTK_CONTAINER (window);
+ GtkBitmask *empty;
gboolean need_resize;
gboolean is_plug;
need_resize = _gtk_widget_get_alloc_needed (widget) || !gtk_widget_get_realized (widget);
+ empty = _gtk_bitmask_new ();
_gtk_style_context_validate (gtk_widget_get_style_context (widget),
g_get_monotonic_time (),
- 0);
+ 0,
+ empty);
+ _gtk_bitmask_free (empty);
if (need_resize)
{
gtk_window_set_focus_visible (window, gtk_window_get_focus_visible (priv->transient_parent));
else
gtk_window_set_focus_visible (window, visible_focus == GTK_POLICY_ALWAYS);
-
- ensure_state_flag_backdrop (widget);
}
static gboolean
/*
* If we do need to resize, we do that by:
- * - filling in widget->allocation with the new size
* - setting configure_notify_received to TRUE
* for use in gtk_window_move_resize()
* - queueing a resize, leading to invocation of
priv->configure_notify_received = TRUE;
- allocation.width = event->width;
- allocation.height = event->height;
- gtk_widget_set_allocation (widget, &allocation);
-
gdk_window_invalidate_rect (gtk_widget_get_window (widget), NULL, FALSE); // XXX - What was this for again?
_gtk_container_queue_resize (GTK_CONTAINER (widget));
rect.width, rect.height);
set_grip_shape (window);
- gtk_widget_queue_resize (widget);
}
}
NULL, &mask);
if (window->priv->mnemonic_modifier == (mask & gtk_accelerator_get_default_mod_mask ()))
{
- gtk_window_set_mnemonics_visible (window, TRUE);
+ _gtk_window_set_auto_mnemonics_visible (window);
break;
}
}
}
}
-
-static void
-gtk_window_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- GtkWindow *window;
- GtkWidget *child;
- guint border_width;
-
- window = GTK_WINDOW (widget);
- child = gtk_bin_get_child (GTK_BIN (window));
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
- *minimum_size = border_width * 2;
- *natural_size = border_width * 2;
-
- if (child && gtk_widget_get_visible (child))
- {
- gint child_min, child_nat;
- gtk_widget_get_preferred_width (child, &child_min, &child_nat);
-
- *minimum_size += child_min;
- *natural_size += child_nat;
- }
-}
-
-static void
-gtk_window_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- GtkWindow *window;
- GtkWidget *child;
- guint border_width;
-
- window = GTK_WINDOW (widget);
- child = gtk_bin_get_child (GTK_BIN (window));
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
- *minimum_size = border_width * 2;
- *natural_size = border_width * 2;
-
- if (child && gtk_widget_get_visible (child))
- {
- gint child_min, child_nat;
- gtk_widget_get_preferred_height (child, &child_min, &child_nat);
-
- *minimum_size += child_min;
- *natural_size += child_nat;
- }
-}
-
-
/**
* _gtk_window_unset_focus_and_default:
* @window: a #GtkWindow
&new_geometry,
new_flags);
- gtk_widget_get_allocation (widget, &allocation);
+ allocation.x = 0;
+ allocation.y = 0;
+ allocation.width = gdk_window_get_width (gdk_window);
+ allocation.height = gdk_window_get_height (gdk_window);
/* handle resizing/moving and widget tree allocation
*/
if (!gtk_widget_get_app_paintable (widget) &&
gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
{
- gtk_style_context_save (context);
-
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND);
gtk_render_background (context, cr, 0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
-
- gtk_style_context_restore (context);
}
if (GTK_WIDGET_CLASS (gtk_window_parent_class)->draw)
gtk_cairo_transform_to_window (cr, widget, priv->grip_window);
gtk_window_get_resize_grip_area (GTK_WINDOW (widget), &rect);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BACKGROUND);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_GRIP);
gtk_style_context_set_junction_sides (context, get_grip_junction (widget));
gtk_render_handle (context, cr, 0, 0, rect.width, rect.height);
if (priv->resizable != resizable)
{
- priv->resizable = (resizable != FALSE);
+ priv->resizable = resizable;
update_grip_visibility (window);
* in-process, parented GtkPlug)
*
* Internal function used by #GtkPlug when it gets parented/unparented by a
- * #GtkSocket. This keeps the @window's #GTK_TOPLEVEL flag in sync with the
- * global list of toplevel windows.
+ * #GtkSocket. This keeps the @window's #GTK_WINDOW_TOPLEVEL flag in sync
+ * with the global list of toplevel windows.
*/
void
_gtk_window_set_is_toplevel (GtkWindow *window,
g_object_notify (G_OBJECT (window), "mnemonics-visible");
}
+ if (priv->auto_mnemonics_timeout_id)
+ {
+ g_source_remove (priv->auto_mnemonics_timeout_id);
+ priv->auto_mnemonics_timeout_id = 0;
+ }
+
priv->mnemonics_visible_set = TRUE;
}
+static gboolean
+set_auto_mnemonics_visible_cb (gpointer data)
+{
+ GtkWindow *window = data;
+
+ gtk_window_set_mnemonics_visible (window, TRUE);
+
+ window->priv->auto_mnemonics_timeout_id = 0;
+
+ return FALSE;
+}
+
+void
+_gtk_window_set_auto_mnemonics_visible (GtkWindow *window)
+{
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ if (window->priv->auto_mnemonics_timeout_id)
+ return;
+
+ window->priv->auto_mnemonics_timeout_id =
+ gdk_threads_add_timeout (AUTO_MNEMONICS_DELAY, set_auto_mnemonics_visible_cb, window);
+}
+
/**
* gtk_window_get_focus_visible:
* @window: a #GtkWindow
* @setting: the new value
*
* Tells GTK+ whether to drop its extra reference to the window
- * when gtk_window_destroy() is called.
+ * when gtk_widget_destroy() is called.
*
* This function is only exported for the benefit of language
* bindings which may need to keep the window alive until their