1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gdk/gdkkeysyms.h"
32 #if defined (GDK_WINDOWING_X11)
34 #elif defined (GDK_WINDOWING_WIN32)
35 #include "win32/gdkwin32.h"
36 #elif defined (GDK_WINDOWING_NANOX)
37 #include "nanox/gdkprivate-nanox.h"
38 #elif defined (GDK_WINDOWING_FB)
39 #include "linux-fb/gdkfb.h"
42 #include "gtkprivate.h"
44 #include "gtksignal.h"
45 #include "gtkwindow.h"
46 #include "gtkwindow-decorate.h"
47 #include "gtkbindings.h"
49 #include "gtkiconfactory.h"
77 PROP_DESTROY_WITH_PARENT,
83 GdkGeometry geometry; /* Last set of geometry hints we set */
87 } GtkWindowLastGeometryInfo;
89 struct _GtkWindowGeometryInfo
91 /* Properties that the app has set on the window
93 GdkGeometry geometry; /* Geometry hints */
95 GtkWidget *widget; /* subwidget to which hints apply */
96 gint width; /* Default size */
98 guint may_shrink : 1; /* one-shot auto_shrink behaviour after set_default_size */
100 GtkWindowLastGeometryInfo last;
111 static void gtk_window_class_init (GtkWindowClass *klass);
112 static void gtk_window_init (GtkWindow *window);
113 static void gtk_window_dispose (GObject *object);
114 static void gtk_window_destroy (GtkObject *object);
115 static void gtk_window_finalize (GObject *object);
116 static void gtk_window_show (GtkWidget *widget);
117 static void gtk_window_hide (GtkWidget *widget);
118 static void gtk_window_map (GtkWidget *widget);
119 static void gtk_window_unmap (GtkWidget *widget);
120 static void gtk_window_realize (GtkWidget *widget);
121 static void gtk_window_unrealize (GtkWidget *widget);
122 static void gtk_window_size_request (GtkWidget *widget,
123 GtkRequisition *requisition);
124 static void gtk_window_size_allocate (GtkWidget *widget,
125 GtkAllocation *allocation);
126 static gint gtk_window_event (GtkWidget *widget,
128 static gboolean gtk_window_frame_event (GtkWidget *widget,
130 static gint gtk_window_configure_event (GtkWidget *widget,
131 GdkEventConfigure *event);
132 static gint gtk_window_key_press_event (GtkWidget *widget,
134 static gint gtk_window_key_release_event (GtkWidget *widget,
136 static gint gtk_window_enter_notify_event (GtkWidget *widget,
137 GdkEventCrossing *event);
138 static gint gtk_window_leave_notify_event (GtkWidget *widget,
139 GdkEventCrossing *event);
140 static gint gtk_window_focus_in_event (GtkWidget *widget,
141 GdkEventFocus *event);
142 static gint gtk_window_focus_out_event (GtkWidget *widget,
143 GdkEventFocus *event);
144 static gint gtk_window_client_event (GtkWidget *widget,
145 GdkEventClient *event);
146 static void gtk_window_check_resize (GtkContainer *container);
147 static gint gtk_window_focus (GtkWidget *widget,
148 GtkDirectionType direction);
149 static void gtk_window_real_set_focus (GtkWindow *window,
152 static void gtk_window_real_activate_default (GtkWindow *window);
153 static void gtk_window_real_activate_focus (GtkWindow *window);
154 static void gtk_window_move_focus (GtkWindow *window,
155 GtkDirectionType dir);
157 static void gtk_window_move_resize (GtkWindow *window);
158 static gboolean gtk_window_compare_hints (GdkGeometry *geometry_a,
160 GdkGeometry *geometry_b,
162 static void gtk_window_compute_default_size (GtkWindow *window,
165 static void gtk_window_constrain_size (GtkWindow *window,
166 GdkGeometry *geometry,
172 static void gtk_window_compute_hints (GtkWindow *window,
173 GdkGeometry *new_geometry,
175 static gint gtk_window_compute_reposition (GtkWindow *window,
181 static void gtk_window_read_rcfiles (GtkWidget *widget,
182 GdkEventClient *event);
183 static void gtk_window_paint (GtkWidget *widget,
185 static gint gtk_window_expose (GtkWidget *widget,
186 GdkEventExpose *event);
187 static void gtk_window_unset_transient_for (GtkWindow *window);
188 static void gtk_window_transient_parent_realized (GtkWidget *parent,
190 static void gtk_window_transient_parent_unrealized (GtkWidget *parent,
193 static GtkWindowGeometryInfo* gtk_window_get_geometry_info (GtkWindow *window,
197 static GSList *toplevel_list = NULL;
198 static GHashTable *mnemonic_hash_table = NULL;
199 static GtkBinClass *parent_class = NULL;
200 static guint window_signals[LAST_SIGNAL] = { 0 };
202 static void gtk_window_set_property (GObject *object,
206 static void gtk_window_get_property (GObject *object,
213 mnemonic_hash (gconstpointer key)
215 const GtkWindowMnemonic *k;
218 k = (GtkWindowMnemonic *)key;
220 h = (gulong) k->window;
221 h ^= k->keyval << 16;
222 h ^= k->keyval >> 16;
228 mnemonic_equal (gconstpointer a, gconstpointer b)
230 const GtkWindowMnemonic *ka;
231 const GtkWindowMnemonic *kb;
233 ka = (GtkWindowMnemonic *)a;
234 kb = (GtkWindowMnemonic *)b;
237 (ka->window == kb->window) &&
238 (ka->keyval == kb->keyval);
242 gtk_window_get_type (void)
244 static GtkType window_type = 0;
248 static const GtkTypeInfo window_info =
252 sizeof (GtkWindowClass),
253 (GtkClassInitFunc) gtk_window_class_init,
254 (GtkObjectInitFunc) gtk_window_init,
255 /* reserved_1 */ NULL,
256 /* reserved_2 */ NULL,
257 (GtkClassInitFunc) NULL,
260 window_type = gtk_type_unique (gtk_bin_get_type (), &window_info);
267 gtk_window_class_init (GtkWindowClass *klass)
269 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
270 GtkObjectClass *object_class;
271 GtkWidgetClass *widget_class;
272 GtkContainerClass *container_class;
273 GtkBindingSet *binding_set;
275 object_class = (GtkObjectClass*) klass;
276 widget_class = (GtkWidgetClass*) klass;
277 container_class = (GtkContainerClass*) klass;
279 parent_class = gtk_type_class (gtk_bin_get_type ());
281 gobject_class->dispose = gtk_window_dispose;
282 gobject_class->finalize = gtk_window_finalize;
284 gobject_class->set_property = gtk_window_set_property;
285 gobject_class->get_property = gtk_window_get_property;
287 object_class->destroy = gtk_window_destroy;
289 widget_class->show = gtk_window_show;
290 widget_class->hide = gtk_window_hide;
291 widget_class->map = gtk_window_map;
292 widget_class->unmap = gtk_window_unmap;
293 widget_class->realize = gtk_window_realize;
294 widget_class->unrealize = gtk_window_unrealize;
295 widget_class->size_request = gtk_window_size_request;
296 widget_class->size_allocate = gtk_window_size_allocate;
297 widget_class->configure_event = gtk_window_configure_event;
298 widget_class->key_press_event = gtk_window_key_press_event;
299 widget_class->key_release_event = gtk_window_key_release_event;
300 widget_class->enter_notify_event = gtk_window_enter_notify_event;
301 widget_class->leave_notify_event = gtk_window_leave_notify_event;
302 widget_class->focus_in_event = gtk_window_focus_in_event;
303 widget_class->focus_out_event = gtk_window_focus_out_event;
304 widget_class->client_event = gtk_window_client_event;
305 widget_class->focus = gtk_window_focus;
307 widget_class->expose_event = gtk_window_expose;
309 container_class->check_resize = gtk_window_check_resize;
311 klass->set_focus = gtk_window_real_set_focus;
312 klass->frame_event = gtk_window_frame_event;
314 klass->activate_default = gtk_window_real_activate_default;
315 klass->activate_focus = gtk_window_real_activate_focus;
316 klass->move_focus = gtk_window_move_focus;
319 g_object_class_install_property (gobject_class,
321 g_param_spec_enum ("type",
323 _("The type of the window"),
324 GTK_TYPE_WINDOW_TYPE,
326 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
329 g_object_class_install_property (gobject_class,
331 g_param_spec_string ("title",
333 _("The title of the window"),
337 g_object_class_install_property (gobject_class,
339 g_param_spec_boolean ("auto_shrink",
341 _("If TRUE, the window automatically shrinks to its size request anytime a resize occurs. Don't use this feature, it makes no sense."),
345 g_object_class_install_property (gobject_class,
347 g_param_spec_boolean ("allow_shrink",
349 _("If TRUE, the window has no mimimum size. Don't use this feature, it makes no sense."),
353 g_object_class_install_property (gobject_class,
355 g_param_spec_boolean ("allow_grow",
357 _("If TRUE, users can expand the window beyond its minimum size."),
361 g_object_class_install_property (gobject_class,
363 g_param_spec_boolean ("resizable",
365 _("If TRUE, users can resize the window."),
369 g_object_class_install_property (gobject_class,
371 g_param_spec_boolean ("modal",
373 _("If TRUE, the window is modal (other windows are not usable while this one is up)."),
377 g_object_class_install_property (gobject_class,
379 g_param_spec_enum ("window_position",
380 _("Window Position"),
381 _("The initial position of the window."),
382 GTK_TYPE_WINDOW_POSITION,
386 g_object_class_install_property (gobject_class,
388 g_param_spec_int ("default_width",
390 _("The default width of the window, or 0 to use the size request."),
396 g_object_class_install_property (gobject_class,
398 g_param_spec_int ("default_height",
400 _("The default height of the window, or 0 to use the size request."),
406 g_object_class_install_property (gobject_class,
407 PROP_DESTROY_WITH_PARENT,
408 g_param_spec_boolean ("destroy_with_parent",
409 _("Destroy with Parent"),
410 _("If this window should be destroyed when the parent is destroyed"),
414 /* Style props are set or not */
416 window_signals[SET_FOCUS] =
417 g_signal_new ("set_focus",
418 G_TYPE_FROM_CLASS (object_class),
420 G_STRUCT_OFFSET (GtkWindowClass, set_focus),
422 gtk_marshal_VOID__OBJECT,
426 window_signals[FRAME_EVENT] =
427 g_signal_new ("frame_event",
428 G_TYPE_FROM_CLASS(object_class),
430 G_STRUCT_OFFSET(GtkWindowClass, frame_event),
431 _gtk_boolean_handled_accumulator, NULL,
432 gtk_marshal_BOOLEAN__BOXED,
436 window_signals[ACTIVATE_FOCUS] =
437 g_signal_new ("activate_focus",
438 G_OBJECT_CLASS_TYPE (object_class),
439 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
440 GTK_SIGNAL_OFFSET (GtkWindowClass, activate_focus),
442 gtk_marshal_VOID__VOID,
446 window_signals[ACTIVATE_DEFAULT] =
447 g_signal_new ("activate_default",
448 G_OBJECT_CLASS_TYPE (object_class),
449 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
450 GTK_SIGNAL_OFFSET (GtkWindowClass, activate_default),
452 gtk_marshal_VOID__VOID,
456 window_signals[MOVE_FOCUS] =
457 g_signal_new ("move_focus",
458 G_OBJECT_CLASS_TYPE (object_class),
459 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
460 GTK_SIGNAL_OFFSET (GtkWindowClass, move_focus),
462 gtk_marshal_VOID__ENUM,
465 GTK_TYPE_DIRECTION_TYPE);
467 if (!mnemonic_hash_table)
468 mnemonic_hash_table = g_hash_table_new (mnemonic_hash,
475 binding_set = gtk_binding_set_by_class (klass);
477 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
478 "activate_focus", 0);
479 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
480 "activate_focus", 0);
482 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
483 "activate_default", 0);
485 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
486 "activate_default", 0);
488 gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
490 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_UP);
491 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
493 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_UP);
495 gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
497 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_DOWN);
498 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
500 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_DOWN);
502 gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
504 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_LEFT);
505 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0,
507 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_LEFT);
509 gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
511 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_RIGHT);
512 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0,
514 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_RIGHT);
516 gtk_binding_entry_add_signal (binding_set, GDK_Tab, 0,
518 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
519 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, 0,
521 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
522 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, 0,
524 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
526 gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_SHIFT_MASK,
528 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
529 gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_SHIFT_MASK,
531 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
532 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, GDK_SHIFT_MASK,
534 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
538 gtk_window_init (GtkWindow *window)
540 GTK_WIDGET_UNSET_FLAGS (window, GTK_NO_WINDOW);
541 GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
543 GTK_PRIVATE_SET_FLAG (window, GTK_ANCHORED);
545 gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
547 window->title = NULL;
548 window->wmclass_name = g_strdup (g_get_prgname ());
549 window->wmclass_class = g_strdup (gdk_progclass);
550 window->wm_role = NULL;
551 window->geometry_info = NULL;
552 window->type = GTK_WINDOW_TOPLEVEL;
553 window->focus_widget = NULL;
554 window->default_widget = NULL;
555 window->resize_count = 0;
556 window->allow_shrink = FALSE;
557 window->allow_grow = TRUE;
558 window->auto_shrink = FALSE;
559 window->handling_resize = FALSE;
560 window->position = GTK_WIN_POS_NONE;
561 window->use_uposition = TRUE;
562 window->modal = FALSE;
563 window->frame = NULL;
564 window->has_frame = FALSE;
565 window->frame_left = 0;
566 window->frame_right = 0;
567 window->frame_top = 0;
568 window->frame_bottom = 0;
569 window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
570 window->gravity = GDK_GRAVITY_NORTH_WEST;
571 window->decorated = TRUE;
572 window->mnemonic_modifier = GDK_MOD1_MASK;
574 gtk_widget_ref (GTK_WIDGET (window));
575 gtk_object_sink (GTK_OBJECT (window));
576 window->has_user_ref_count = TRUE;
577 toplevel_list = g_slist_prepend (toplevel_list, window);
579 gtk_decorated_window_init (window);
581 gtk_signal_connect (GTK_OBJECT (window),
583 GTK_SIGNAL_FUNC (gtk_window_event),
588 gtk_window_set_property (GObject *object,
595 window = GTK_WINDOW (object);
600 window->type = g_value_get_enum (value);
603 gtk_window_set_title (window, g_value_get_string (value));
605 case PROP_AUTO_SHRINK:
606 window->auto_shrink = g_value_get_boolean (value);
607 gtk_widget_queue_resize (GTK_WIDGET (window));
609 case PROP_ALLOW_SHRINK:
610 window->allow_shrink = g_value_get_boolean (value);
611 gtk_widget_queue_resize (GTK_WIDGET (window));
613 case PROP_ALLOW_GROW:
614 window->allow_grow = g_value_get_boolean (value);
615 gtk_widget_queue_resize (GTK_WIDGET (window));
616 g_object_notify (G_OBJECT (window), "resizable");
619 window->allow_grow = g_value_get_boolean (value);
620 gtk_widget_queue_resize (GTK_WIDGET (window));
621 g_object_notify (G_OBJECT (window), "allow_grow");
624 gtk_window_set_modal (window, g_value_get_boolean (value));
627 gtk_window_set_position (window, g_value_get_enum (value));
629 case PROP_DEFAULT_WIDTH:
630 gtk_window_set_default_size (window, g_value_get_int (value), -1);
632 case PROP_DEFAULT_HEIGHT:
633 gtk_window_set_default_size (window, -1, g_value_get_int (value));
635 case PROP_DESTROY_WITH_PARENT:
636 gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
644 gtk_window_get_property (GObject *object,
651 window = GTK_WINDOW (object);
655 GtkWindowGeometryInfo *info;
657 g_value_set_enum (value, window->type);
660 g_value_set_string (value, window->title);
662 case PROP_AUTO_SHRINK:
663 g_value_set_boolean (value, window->auto_shrink);
665 case PROP_ALLOW_SHRINK:
666 g_value_set_boolean (value, window->allow_shrink);
668 case PROP_ALLOW_GROW:
669 g_value_set_boolean (value, window->allow_grow);
672 g_value_set_boolean (value, window->allow_grow);
675 g_value_set_boolean (value, window->modal);
678 g_value_set_enum (value, window->position);
680 case PROP_DEFAULT_WIDTH:
681 info = gtk_window_get_geometry_info (window, FALSE);
683 g_value_set_int (value, 0);
685 g_value_set_int (value, info->width);
687 case PROP_DEFAULT_HEIGHT:
688 info = gtk_window_get_geometry_info (window, FALSE);
690 g_value_set_int (value, 0);
692 g_value_set_int (value, info->height);
694 case PROP_DESTROY_WITH_PARENT:
695 g_value_set_boolean (value, window->destroy_with_parent);
698 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
705 * @type: type of window
707 * Creates a new #GtkWindow, which is a toplevel window that can
708 * contain other widgets. Nearly always, the type of the window should
709 * be #GTK_WINDOW_TOPLEVEL. If you're implementing something like a
710 * popup menu from scratch (which is a bad idea, just use #GtkMenu),
711 * you might use #GTK_WINDOW_POPUP. #GTK_WINDOW_POPUP is not for
712 * dialogs, though in some other toolkits dialogs are called "popups."
713 * In GTK+, #GTK_WINDOW_POPUP means a pop-up menu or pop-up tooltip.
714 * Popup windows are not controlled by the window manager.
716 * If you simply want an undecorated window (no window borders), use
717 * gtk_window_set_decorated(), don't use #GTK_WINDOW_POPUP.
719 * Return value: a new #GtkWindow.
722 gtk_window_new (GtkWindowType type)
726 g_return_val_if_fail (type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP, NULL);
728 window = gtk_type_new (GTK_TYPE_WINDOW);
732 return GTK_WIDGET (window);
736 * gtk_window_set_title:
737 * @window: a #GtkWindow
738 * @title: title of the window
740 * Sets the title of the #GtkWindow. The title of a window will be displayed in
741 * its title bar; on the X Window System, the title bar is rendered by the
742 * window manager, so exactly how the title appears to users may vary according
743 * to a user's exact configuration. The title should help a user distinguish
744 * this window from other windows they may have open. A good title might
745 * include the application name and current document filename, for example.
749 gtk_window_set_title (GtkWindow *window,
752 g_return_if_fail (GTK_IS_WINDOW (window));
755 g_free (window->title);
756 window->title = g_strdup (title);
758 if (GTK_WIDGET_REALIZED (window))
760 gdk_window_set_title (GTK_WIDGET (window)->window, window->title);
762 gtk_decorated_window_set_title (window, title);
765 g_object_notify (G_OBJECT (window), "title");
769 * gtk_window_get_title:
770 * @window: a #GtkWindow
772 * Retrieves the title of the window. See gtk_window_set_title().
774 * Return value: the title of the window, or %NULL if none has
775 * been set explicitely. The returned string is owned by the widget
776 * and must not be modified or freed.
778 G_CONST_RETURN gchar *
779 gtk_window_get_title (GtkWindow *window)
781 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
783 return window->title;
787 * gtk_window_set_wmclass:
788 * @window: a #GtkWindow
789 * @wmclass_name: window name hint
790 * @wmclass_class: window class hint
792 * Don't use this function. It sets the X Window System "class" and
793 * "name" hints for a window. According to the ICCCM, you should
794 * always set these to the same value for all windows in an
795 * application, and GTK sets them to that value by default, so calling
796 * this function is sort of pointless. However, you may want to call
797 * gtk_window_set_role() on each window in your application, for the
798 * benefit of the session manager. Setting the role allows the window
799 * manager to restore window positions when loading a saved session.
803 gtk_window_set_wmclass (GtkWindow *window,
804 const gchar *wmclass_name,
805 const gchar *wmclass_class)
807 g_return_if_fail (GTK_IS_WINDOW (window));
809 g_free (window->wmclass_name);
810 window->wmclass_name = g_strdup (wmclass_name);
812 g_free (window->wmclass_class);
813 window->wmclass_class = g_strdup (wmclass_class);
815 if (GTK_WIDGET_REALIZED (window))
816 g_warning ("gtk_window_set_wmclass: shouldn't set wmclass after window is realized!\n");
820 * gtk_window_set_role:
821 * @window: a #GtkWindow
822 * @role: unique identifier for the window to be used when restoring a session
824 * In combination with the window title, the window role allows a
825 * window manager to identify "the same" window when an application is
826 * restarted. So for example you might set the "toolbox" role on your
827 * app's toolbox window, so that when the user restarts their session,
828 * the window manager can put the toolbox back in the same place.
830 * If a window already has a unique title, you don't need to set the
831 * role, since the WM can use the title to identify the window when
832 * restoring the session.
836 gtk_window_set_role (GtkWindow *window,
839 g_return_if_fail (GTK_IS_WINDOW (window));
841 if (role == window->wm_role)
844 g_free (window->wm_role);
845 window->wm_role = g_strdup (role);
847 if (GTK_WIDGET_REALIZED (window))
848 g_warning ("gtk_window_set_role(): shouldn't set role after window is realized!\n");
852 * gtk_window_get_role:
853 * @window: a #GtkWindow
855 * Returns the role of the window. See gtk_window_set_role() for
856 * further explanation.
858 * Return value: the role of the window if set, or %NULL. The
859 * returned is owned by the widget and must not be modified
862 G_CONST_RETURN gchar *
863 gtk_window_get_role (GtkWindow *window)
865 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
867 return window->wm_role;
871 * gtk_window_set_focus:
872 * @window: a #GtkWindow
873 * @focus: widget to be the new focus widget
875 * If @focus is not the current focus widget, and is focusable, emits
876 * the "set_focus" signal to set @focus as the focus widget for the
877 * window. This function is more or less GTK-internal; to focus an
878 * entry widget or the like, you should use gtk_widget_grab_focus()
879 * instead of this function.
883 gtk_window_set_focus (GtkWindow *window,
886 g_return_if_fail (GTK_IS_WINDOW (window));
889 g_return_if_fail (GTK_IS_WIDGET (focus));
890 g_return_if_fail (GTK_WIDGET_CAN_FOCUS (focus));
893 if ((window->focus_widget != focus) ||
894 (focus && !GTK_WIDGET_HAS_FOCUS (focus)))
895 gtk_signal_emit (GTK_OBJECT (window), window_signals[SET_FOCUS], focus);
899 * gtk_window_set_default:
900 * @window: a #GtkWindow
901 * @default_widget: widget to be the default
903 * The default widget is the widget that's activated when the user
904 * presses Enter in a dialog (for example). This function tells a
905 * #GtkWindow about the current default widget; it's really a GTK
906 * internal function and you shouldn't need it. Instead, to change the
907 * default widget, first set the #GTK_CAN_DEFAULT flag on the widget
908 * you'd like to make the default using GTK_WIDGET_SET_FLAGS(), then
909 * call gtk_widget_grab_default() to move the default.
913 gtk_window_set_default (GtkWindow *window,
914 GtkWidget *default_widget)
916 g_return_if_fail (GTK_IS_WINDOW (window));
919 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (default_widget));
921 if (window->default_widget != default_widget)
923 if (window->default_widget)
925 if (window->focus_widget != window->default_widget ||
926 !GTK_WIDGET_RECEIVES_DEFAULT (window->default_widget))
927 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
928 gtk_widget_queue_draw (window->default_widget);
931 window->default_widget = default_widget;
933 if (window->default_widget)
935 if (window->focus_widget == NULL ||
936 !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))
937 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
938 gtk_widget_queue_draw (window->default_widget);
944 gtk_window_set_policy (GtkWindow *window,
945 gboolean allow_shrink,
947 gboolean auto_shrink)
949 g_return_if_fail (GTK_IS_WINDOW (window));
951 window->allow_shrink = (allow_shrink != FALSE);
952 window->allow_grow = (allow_grow != FALSE);
953 window->auto_shrink = (auto_shrink != FALSE);
955 g_object_notify (G_OBJECT (window), "allow_shrink");
956 g_object_notify (G_OBJECT (window), "allow_grow");
957 g_object_notify (G_OBJECT (window), "resizable");
958 g_object_notify (G_OBJECT (window), "auto_shrink");
960 gtk_widget_queue_resize (GTK_WIDGET (window));
964 gtk_window_add_accel_group (GtkWindow *window,
965 GtkAccelGroup *accel_group)
967 g_return_if_fail (GTK_IS_WINDOW (window));
968 g_return_if_fail (accel_group != NULL);
970 gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
974 gtk_window_remove_accel_group (GtkWindow *window,
975 GtkAccelGroup *accel_group)
977 g_return_if_fail (GTK_IS_WINDOW (window));
978 g_return_if_fail (accel_group != NULL);
980 gtk_accel_group_detach (accel_group, GTK_OBJECT (window));
984 gtk_window_add_mnemonic (GtkWindow *window,
988 GtkWindowMnemonic key;
989 GtkWindowMnemonic *mnemonic;
991 g_return_if_fail (GTK_IS_WINDOW (window));
992 g_return_if_fail (GTK_IS_WIDGET (target));
996 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
1000 g_return_if_fail (g_slist_find (mnemonic->targets, target) == NULL);
1001 mnemonic->targets = g_slist_prepend (mnemonic->targets, target);
1005 mnemonic = g_new (GtkWindowMnemonic, 1);
1007 mnemonic->targets = g_slist_prepend (NULL, target);
1008 g_hash_table_insert (mnemonic_hash_table, mnemonic, mnemonic);
1013 gtk_window_remove_mnemonic (GtkWindow *window,
1017 GtkWindowMnemonic key;
1018 GtkWindowMnemonic *mnemonic;
1020 g_return_if_fail (GTK_IS_WINDOW (window));
1021 g_return_if_fail (GTK_IS_WIDGET (target));
1023 key.window = window;
1024 key.keyval = keyval;
1025 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
1027 g_return_if_fail (mnemonic && g_slist_find (mnemonic->targets, target) != NULL);
1029 mnemonic->targets = g_slist_remove (mnemonic->targets, target);
1030 if (mnemonic->targets == NULL)
1032 g_hash_table_remove (mnemonic_hash_table, mnemonic);
1038 gtk_window_mnemonic_activate (GtkWindow *window,
1040 GdkModifierType modifier)
1042 GtkWindowMnemonic key;
1043 GtkWindowMnemonic *mnemonic;
1045 GtkWidget *widget, *chosen_widget;
1046 gboolean overloaded;
1048 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1050 if (window->mnemonic_modifier != (modifier & gtk_accelerator_get_default_mod_mask ()))
1053 key.window = window;
1054 key.keyval = keyval;
1055 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
1061 chosen_widget = NULL;
1062 list = mnemonic->targets;
1065 widget = GTK_WIDGET (list->data);
1067 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
1068 GTK_WIDGET_MAPPED (widget))
1076 chosen_widget = widget;
1078 list = g_slist_next (list);
1083 /* For round robin we put the activated entry on
1084 * the end of the list after activation
1086 mnemonic->targets = g_slist_remove (mnemonic->targets, chosen_widget);
1087 mnemonic->targets = g_slist_append (mnemonic->targets, chosen_widget);
1089 return gtk_widget_mnemonic_activate (chosen_widget, overloaded);
1095 gtk_window_set_mnemonic_modifier (GtkWindow *window,
1096 GdkModifierType modifier)
1098 g_return_if_fail (GTK_IS_WINDOW (window));
1099 g_return_if_fail ((modifier & ~GDK_MODIFIER_MASK) == 0);
1101 window->mnemonic_modifier = modifier;
1105 * gtk_window_get_mnemonic_modifier:
1106 * @window: a #GtkWindow
1108 * Returns the mnemonic modifier for this window. See
1109 * gtk_window_set_mnemonic_modifier().
1111 * Return value: the modifier mask used to activate
1112 * mnemonics on this window.
1115 gtk_window_get_mnemonic_modifier (GtkWindow *window)
1117 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
1119 return window->mnemonic_modifier;
1123 gtk_window_set_position (GtkWindow *window,
1124 GtkWindowPosition position)
1126 g_return_if_fail (GTK_IS_WINDOW (window));
1128 window->position = position;
1130 g_object_notify (G_OBJECT (window), "window_position");
1134 gtk_window_activate_focus (GtkWindow *window)
1136 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1138 if (window->focus_widget)
1140 if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1141 gtk_widget_activate (window->focus_widget);
1149 gtk_window_activate_default (GtkWindow *window)
1151 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1153 if (window->default_widget && GTK_WIDGET_IS_SENSITIVE (window->default_widget) &&
1154 (!window->focus_widget || !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget)))
1156 gtk_widget_activate (window->default_widget);
1159 else if (window->focus_widget)
1161 if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1162 gtk_widget_activate (window->focus_widget);
1170 * gtk_window_set_modal:
1171 * @window: a #GtkWindow
1172 * @modal: whether the window is modal
1174 * Sets a window modal or non-modal. Modal windows prevent interaction
1175 * with other windows in the same application. To keep modal dialogs
1176 * on top of main application windows, use
1177 * gtk_window_set_transient_for() to make the dialog transient for the
1178 * parent; most window managers will then disallow lowering the dialog
1184 gtk_window_set_modal (GtkWindow *window,
1187 g_return_if_fail (GTK_IS_WINDOW (window));
1189 window->modal = modal != FALSE;
1191 /* adjust desired modality state */
1192 if (GTK_WIDGET_VISIBLE (window) && window->modal)
1193 gtk_grab_add (GTK_WIDGET (window));
1195 gtk_grab_remove (GTK_WIDGET (window));
1197 g_object_notify (G_OBJECT (window), "modal");
1201 * gtk_window_get_modal:
1202 * @window: a #GtkWindow
1204 * Returns whether the window is modal. See gtk_window_set_modal().
1206 * Return value: %TRUE if the window is set to be modal and
1207 * establishes a grab when shown
1210 gtk_window_get_modal (GtkWindow *window)
1212 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1214 return window->modal;
1218 * gtk_window_list_toplevels:
1220 * Returns a list of all existing toplevel windows. The widgets
1221 * in the list are not individually referenced. If you want
1222 * to iterate through the list and perform actions involving
1223 * callbacks that might destroy the widgets, you MUST call
1224 * g_list_foreach (result, (GFunc)g_object_ref, NULL) first, and
1225 * then unref all the widgets afterwards.
1227 * Return value: list of toplevel widgets
1230 gtk_window_list_toplevels (void)
1235 for (slist = toplevel_list; slist; slist = slist->next)
1236 list = g_list_prepend (list, slist->data);
1242 gtk_window_add_embedded_xid (GtkWindow *window, guint xid)
1244 GList *embedded_windows;
1246 g_return_if_fail (GTK_IS_WINDOW (window));
1248 embedded_windows = gtk_object_get_data (GTK_OBJECT (window), "gtk-embedded");
1249 if (embedded_windows)
1250 gtk_object_remove_no_notify_by_id (GTK_OBJECT (window),
1251 g_quark_from_static_string ("gtk-embedded"));
1252 embedded_windows = g_list_prepend (embedded_windows,
1253 GUINT_TO_POINTER (xid));
1255 gtk_object_set_data_full (GTK_OBJECT (window), "gtk-embedded",
1258 (GtkDestroyNotify) g_list_free : NULL);
1262 gtk_window_remove_embedded_xid (GtkWindow *window, guint xid)
1264 GList *embedded_windows;
1267 g_return_if_fail (GTK_IS_WINDOW (window));
1269 embedded_windows = gtk_object_get_data (GTK_OBJECT (window), "gtk-embedded");
1270 if (embedded_windows)
1271 gtk_object_remove_no_notify_by_id (GTK_OBJECT (window),
1272 g_quark_from_static_string ("gtk-embedded"));
1274 node = g_list_find (embedded_windows, GUINT_TO_POINTER (xid));
1277 embedded_windows = g_list_remove_link (embedded_windows, node);
1278 g_list_free_1 (node);
1281 gtk_object_set_data_full (GTK_OBJECT (window),
1282 "gtk-embedded", embedded_windows,
1284 (GtkDestroyNotify) g_list_free : NULL);
1288 _gtk_window_reposition (GtkWindow *window,
1292 GtkWindowGeometryInfo *info;
1294 g_return_if_fail (GTK_IS_WINDOW (window));
1296 /* keep this in sync with gtk_window_compute_reposition()
1298 if (GTK_WIDGET_REALIZED (window))
1300 info = gtk_window_get_geometry_info (window, TRUE);
1302 if (!(info->last.flags & GDK_HINT_POS))
1304 info->last.flags |= GDK_HINT_POS;
1305 gdk_window_set_geometry_hints (GTK_WIDGET (window)->window,
1306 &info->last.geometry,
1311 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
1313 gdk_window_move (GTK_WIDGET (window)->window, x, y);
1318 gtk_window_dispose (GObject *object)
1322 g_return_if_fail (GTK_IS_WINDOW (object));
1324 window = GTK_WINDOW (object);
1326 gtk_window_set_focus (window, NULL);
1327 gtk_window_set_default (window, NULL);
1329 G_OBJECT_CLASS (parent_class)->dispose (object);
1333 parent_destroyed_callback (GtkWindow *parent, GtkWindow *child)
1335 gtk_widget_destroy (GTK_WIDGET (child));
1339 connect_parent_destroyed (GtkWindow *window)
1341 if (window->transient_parent)
1343 gtk_signal_connect (GTK_OBJECT (window->transient_parent),
1345 GTK_SIGNAL_FUNC (parent_destroyed_callback),
1351 disconnect_parent_destroyed (GtkWindow *window)
1353 if (window->transient_parent)
1355 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1356 GTK_SIGNAL_FUNC (parent_destroyed_callback),
1362 gtk_window_transient_parent_realized (GtkWidget *parent,
1365 if (GTK_WIDGET_REALIZED (window))
1366 gdk_window_set_transient_for (window->window, parent->window);
1370 gtk_window_transient_parent_unrealized (GtkWidget *parent,
1373 if (GTK_WIDGET_REALIZED (window))
1374 gdk_property_delete (window->window,
1375 gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE));
1379 gtk_window_unset_transient_for (GtkWindow *window)
1381 if (window->transient_parent)
1383 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1384 GTK_SIGNAL_FUNC (gtk_window_transient_parent_realized),
1386 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1387 GTK_SIGNAL_FUNC (gtk_window_transient_parent_unrealized),
1389 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1390 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1391 &window->transient_parent);
1393 if (window->destroy_with_parent)
1394 disconnect_parent_destroyed (window);
1396 window->transient_parent = NULL;
1401 * gtk_window_set_transient_for:
1402 * @window: a #GtkWindow
1403 * @parent: parent window
1405 * Dialog windows should be set transient for the main application
1406 * window they were spawned from. This allows window managers to
1407 * e.g. keep the dialog on top of the main window, or center the
1408 * dialog over the main window. gtk_dialog_new_with_buttons() and
1409 * other convenience functions in GTK+ will sometimes call
1410 * gtk_window_set_transient_for() on your behalf.
1414 gtk_window_set_transient_for (GtkWindow *window,
1417 g_return_if_fail (GTK_IS_WINDOW (window));
1418 g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
1419 g_return_if_fail (window != parent);
1422 if (window->transient_parent)
1424 if (GTK_WIDGET_REALIZED (window) &&
1425 GTK_WIDGET_REALIZED (window->transient_parent) &&
1426 (!parent || !GTK_WIDGET_REALIZED (parent)))
1427 gtk_window_transient_parent_unrealized (GTK_WIDGET (window->transient_parent),
1428 GTK_WIDGET (window));
1430 gtk_window_unset_transient_for (window);
1433 window->transient_parent = parent;
1437 gtk_signal_connect (GTK_OBJECT (parent), "destroy",
1438 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1439 &window->transient_parent);
1440 gtk_signal_connect (GTK_OBJECT (parent), "realize",
1441 GTK_SIGNAL_FUNC (gtk_window_transient_parent_realized),
1443 gtk_signal_connect (GTK_OBJECT (parent), "unrealize",
1444 GTK_SIGNAL_FUNC (gtk_window_transient_parent_unrealized),
1447 if (window->destroy_with_parent)
1448 connect_parent_destroyed (window);
1450 if (GTK_WIDGET_REALIZED (window) &&
1451 GTK_WIDGET_REALIZED (parent))
1452 gtk_window_transient_parent_realized (GTK_WIDGET (parent),
1453 GTK_WIDGET (window));
1458 * gtk_window_get_transient_for:
1459 * @window: a #GtkWindow
1461 * Fetches the transient parent for this window. See
1462 * gtk_window_set_transient_for().
1464 * Return value: the transient parent for this window, or %NULL
1465 * if no transient parent has been set.
1468 gtk_window_get_transient_for (GtkWindow *window)
1470 g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
1472 return window->transient_parent;
1476 * gtk_window_set_type_hint:
1477 * @window: a #GtkWindow
1478 * @hint: the window type
1480 * By setting the type hint for the window, you allow the window
1481 * manager to decorate and handle the window in a way which is
1482 * suitable to the function of the window in your application.
1484 * This function should be called before the window becomes visible.
1486 * gtk_dialog_new_with_buttons() and other convenience functions in GTK+
1487 * will sometimes call gtk_window_set_type_hint() on your behalf.
1491 gtk_window_set_type_hint (GtkWindow *window,
1492 GdkWindowTypeHint hint)
1494 g_return_if_fail (GTK_IS_WINDOW (window));
1495 g_return_if_fail (!GTK_WIDGET_VISIBLE (window));
1496 window->type_hint = hint;
1500 * gtk_window_get_type_hint:
1501 * @window: a #GtkWindow
1503 * Gets the type hint for this window. See gtk_window_set_type_hint().
1505 * Return value: the type hint for @window.
1508 gtk_window_get_type_hint (GtkWindow *window)
1510 g_return_val_if_fail (GTK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
1512 return window->type_hint;
1516 * gtk_window_set_destroy_with_parent:
1517 * @window: a #GtkWindow
1518 * @setting: whether to destroy @window with its transient parent
1520 * If @setting is TRUE, then destroying the transient parent of @window
1521 * will also destroy @window itself. This is useful for dialogs that
1522 * shouldn't persist beyond the lifetime of the main window they're
1523 * associated with, for example.
1526 gtk_window_set_destroy_with_parent (GtkWindow *window,
1529 g_return_if_fail (GTK_IS_WINDOW (window));
1531 if (window->destroy_with_parent == (setting != FALSE))
1534 if (window->destroy_with_parent)
1536 disconnect_parent_destroyed (window);
1540 connect_parent_destroyed (window);
1543 window->destroy_with_parent = setting;
1545 g_object_notify (G_OBJECT (window), "destroy_with_parent");
1549 * gtk_window_get_destroy_with_parent:
1550 * @window: a #GtkWindow
1552 * Returns whether the window will be destroyed with its transient parent. See
1553 * gtk_window_set_destroy_with_parent ().
1555 * Return value: %TRUE if the window will be destroyed with its transient parent.
1558 gtk_window_get_destroy_with_parent (GtkWindow *window)
1560 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1562 return window->destroy_with_parent;
1565 static GtkWindowGeometryInfo*
1566 gtk_window_get_geometry_info (GtkWindow *window,
1569 GtkWindowGeometryInfo *info;
1571 info = window->geometry_info;
1572 if (!info && create)
1574 info = g_new0 (GtkWindowGeometryInfo, 1);
1578 info->last.width = -1;
1579 info->last.height = -1;
1580 info->widget = NULL;
1582 info->may_shrink = FALSE;
1583 window->geometry_info = info;
1590 * gtk_window_set_geometry_hints:
1591 * @window: a #GtkWindow
1592 * @geometry_widget: widget the geometry hints will be applied to
1593 * @geometry: struct containing geometry information
1594 * @geom_mask: mask indicating which struct fields should be paid attention to
1596 * This function sets up hints about how a window can be resized by
1597 * the user. You can set a minimum and maximum size; allowed resize
1598 * increments (e.g. for xterm, you can only resize by the size of a
1599 * character); aspect ratios; and more. See the #GdkGeometry struct.
1603 gtk_window_set_geometry_hints (GtkWindow *window,
1604 GtkWidget *geometry_widget,
1605 GdkGeometry *geometry,
1606 GdkWindowHints geom_mask)
1608 GtkWindowGeometryInfo *info;
1610 g_return_if_fail (window != NULL);
1612 info = gtk_window_get_geometry_info (window, TRUE);
1615 gtk_signal_disconnect_by_func (GTK_OBJECT (info->widget),
1616 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1619 info->widget = geometry_widget;
1621 gtk_signal_connect (GTK_OBJECT (geometry_widget), "destroy",
1622 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1626 info->geometry = *geometry;
1628 info->mask = geom_mask;
1630 gtk_widget_queue_resize (GTK_WIDGET (window));
1634 * gtk_window_set_decorated:
1635 * @window: a #GtkWindow
1636 * @setting: %TRUE to decorate the window
1638 * By default, windows are decorated with a title bar, resize
1639 * controls, etc. Some window managers allow GTK+ to disable these
1640 * decorations, creating a borderless window. If you set the decorated
1641 * property to %FALSE using this function, GTK+ will do its best to
1642 * convince the window manager not to decorate the window.
1646 gtk_window_set_decorated (GtkWindow *window,
1649 g_return_if_fail (GTK_IS_WINDOW (window));
1651 setting = setting != FALSE;
1653 if (setting == window->decorated)
1656 window->decorated = setting;
1658 if (GTK_WIDGET (window)->window)
1660 if (window->decorated)
1661 gdk_window_set_decorations (GTK_WIDGET (window)->window,
1664 gdk_window_set_decorations (GTK_WIDGET (window)->window,
1670 * gtk_window_get_decorated:
1671 * @window: a #GtkWindow
1673 * Returns whether the window has been set to have decorations
1674 * such as a title bar via gtk_window_set_decorated().
1676 * Return value: %TRUE if the window has been set to have decorations
1679 gtk_window_get_decorated (GtkWindow *window)
1681 g_return_val_if_fail (GTK_IS_WINDOW (window), TRUE);
1683 return window->decorated;
1687 * gtk_window_set_default_size:
1688 * @window: a #GtkWindow
1689 * @width: width in pixels, 0 to unset, or -1 to leave the width unchanged
1690 * @height: height in pixels, 0 to unset, or -1 to leave the height unchanged
1692 * Sets the default size of a window. If the window's "natural" size
1693 * (its size request) is larger than the default, the default will be
1694 * ignored. So the default size is a minimum initial size. Unlike
1695 * gtk_widget_set_usize(), which sets a size request for a widget and
1696 * thus would keep users from shrinking the window, this function only
1697 * sets the initial size, just as if the user had resized the window
1698 * themselves. Users can still shrink the window again as they
1699 * normally would. Setting a default size of 0 means to use the
1700 * "natural" default size (the size request of the window).
1702 * For more control over a window's initial size and how resizing works,
1703 * investigate gtk_window_set_geometry_hints().
1705 * A useful feature: if you set the "geometry widget" via
1706 * gtk_window_set_geometry_hints(), the default size specified by
1707 * gtk_window_set_default_size() will be the default size of that
1708 * widget, not of the entire window.
1712 gtk_window_set_default_size (GtkWindow *window,
1716 GtkWindowGeometryInfo *info;
1718 g_return_if_fail (GTK_IS_WINDOW (window));
1720 info = gtk_window_get_geometry_info (window, TRUE);
1722 g_object_freeze_notify (G_OBJECT (window));
1725 info->width = width;
1726 g_object_notify (G_OBJECT (window), "default_width");
1727 info->may_shrink = TRUE;
1731 info->height = height;
1732 g_object_notify (G_OBJECT (window), "default_height");
1733 info->may_shrink = TRUE;
1735 g_object_thaw_notify (G_OBJECT (window));
1737 gtk_widget_queue_resize (GTK_WIDGET (window));
1741 * gtk_window_get_default_size:
1742 * @window: a #GtkWindow
1743 * @width: location to store the default width, or %NULL
1744 * @height: location to store the default height, or %NULL
1746 * Gets the default size of the window. A value of 0 for the
1747 * width or height indicates that a default size has not
1748 * been explicitely set for that dimension, so the value
1749 * will be computed from the requisition of the window.
1752 gtk_window_get_default_size (GtkWindow *window,
1756 GtkWindowGeometryInfo *info;
1758 g_return_if_fail (GTK_IS_WINDOW (window));
1760 info = gtk_window_get_geometry_info (window, FALSE);
1763 *width = info ? info->width : 0;
1766 *height = info ? info->height : 0;
1770 gtk_window_destroy (GtkObject *object)
1774 g_return_if_fail (GTK_IS_WINDOW (object));
1776 window = GTK_WINDOW (object);
1778 if (window->transient_parent)
1779 gtk_window_set_transient_for (window, NULL);
1781 if (window->has_user_ref_count)
1783 window->has_user_ref_count = FALSE;
1784 gtk_widget_unref (GTK_WIDGET (window));
1788 gtk_window_group_remove_window (window->group, window);
1790 GTK_OBJECT_CLASS (parent_class)->destroy (object);
1794 gtk_window_mnemonic_hash_remove (gpointer key,
1798 GtkWindowMnemonic *mnemonic = key;
1799 GtkWindow *window = user;
1801 if (mnemonic->window == window)
1803 if (mnemonic->targets)
1805 gchar *name = gtk_accelerator_name (mnemonic->keyval, 0);
1807 g_warning ("mnemonic \"%s\" wasn't removed for widget (%p)",
1808 name, mnemonic->targets->data);
1811 g_slist_free (mnemonic->targets);
1820 gtk_window_finalize (GObject *object)
1824 g_return_if_fail (GTK_IS_WINDOW (object));
1826 window = GTK_WINDOW (object);
1828 toplevel_list = g_slist_remove (toplevel_list, window);
1830 g_free (window->title);
1831 g_free (window->wmclass_name);
1832 g_free (window->wmclass_class);
1833 g_free (window->wm_role);
1835 g_hash_table_foreach_remove (mnemonic_hash_table,
1836 gtk_window_mnemonic_hash_remove,
1838 if (window->geometry_info)
1840 if (window->geometry_info->widget)
1841 gtk_signal_disconnect_by_func (GTK_OBJECT (window->geometry_info->widget),
1842 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1843 &window->geometry_info->widget);
1844 g_free (window->geometry_info);
1847 G_OBJECT_CLASS (parent_class)->finalize (object);
1851 gtk_window_show (GtkWidget *widget)
1853 GtkWindow *window = GTK_WINDOW (widget);
1854 GtkContainer *container = GTK_CONTAINER (window);
1855 gboolean need_resize;
1857 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1859 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
1860 container->need_resize = FALSE;
1864 GtkWindowGeometryInfo *info = gtk_window_get_geometry_info (window, TRUE);
1865 GtkAllocation allocation = { 0, 0 };
1866 GdkGeometry new_geometry;
1867 guint width, height, new_flags;
1868 gboolean was_realized;
1870 /* determine default size to initially show the window with */
1871 gtk_widget_size_request (widget, NULL);
1872 gtk_window_compute_default_size (window, &width, &height);
1874 /* save away the last default size for later comparisions */
1875 info->last.width = width;
1876 info->last.height = height;
1878 /* constrain size to geometry */
1879 gtk_window_compute_hints (window, &new_geometry, &new_flags);
1880 gtk_window_constrain_size (window,
1881 &new_geometry, new_flags,
1885 /* and allocate the window */
1886 allocation.width = width;
1887 allocation.height = height;
1888 gtk_widget_size_allocate (widget, &allocation);
1890 was_realized = FALSE;
1891 if (!GTK_WIDGET_REALIZED (widget))
1893 gtk_widget_realize (widget);
1894 was_realized = TRUE;;
1897 /* Must be done after the windows are realized,
1898 * so that the decorations can be read
1900 gtk_decorated_window_calculate_frame_size (window);
1903 gdk_window_resize (widget->window, width, height);
1906 gtk_container_check_resize (container);
1908 gtk_widget_map (widget);
1911 gtk_grab_add (widget);
1915 gtk_window_hide (GtkWidget *widget)
1919 g_return_if_fail (GTK_IS_WINDOW (widget));
1921 window = GTK_WINDOW (widget);
1923 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1924 gtk_widget_unmap (widget);
1927 gtk_grab_remove (widget);
1931 gtk_window_map (GtkWidget *widget)
1934 GdkWindow *toplevel;
1936 g_return_if_fail (GTK_IS_WINDOW (widget));
1938 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1940 window = GTK_WINDOW (widget);
1942 if (window->bin.child &&
1943 GTK_WIDGET_VISIBLE (window->bin.child) &&
1944 !GTK_WIDGET_MAPPED (window->bin.child))
1945 gtk_widget_map (window->bin.child);
1948 toplevel = window->frame;
1950 toplevel = widget->window;
1952 if (window->maximize_initially)
1953 gdk_window_maximize (toplevel);
1955 gdk_window_unmaximize (toplevel);
1957 if (window->stick_initially)
1958 gdk_window_stick (toplevel);
1960 gdk_window_unstick (toplevel);
1962 if (window->iconify_initially)
1963 gdk_window_iconify (toplevel);
1965 gdk_window_deiconify (toplevel);
1967 gdk_window_show (widget->window);
1970 gdk_window_show (window->frame);
1974 gtk_window_unmap (GtkWidget *widget)
1978 g_return_if_fail (GTK_IS_WINDOW (widget));
1980 window = GTK_WINDOW (widget);
1982 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1984 gdk_window_withdraw (window->frame);
1986 gdk_window_withdraw (widget->window);
1988 window->use_uposition = TRUE;
1989 window->resize_count = 0;
1990 window->handling_resize = FALSE;
1995 gtk_window_realize (GtkWidget *widget)
1998 GdkWindow *parent_window;
1999 GdkWindowAttr attributes;
2000 gint attributes_mask;
2002 g_return_if_fail (GTK_IS_WINDOW (widget));
2004 window = GTK_WINDOW (widget);
2006 /* ensure widget tree is properly size allocated */
2007 if (widget->allocation.x == -1 &&
2008 widget->allocation.y == -1 &&
2009 widget->allocation.width == 1 &&
2010 widget->allocation.height == 1)
2012 GtkRequisition requisition;
2013 GtkAllocation allocation = { 0, 0, 200, 200 };
2015 gtk_widget_size_request (widget, &requisition);
2016 if (requisition.width || requisition.height)
2018 /* non-empty window */
2019 allocation.width = requisition.width;
2020 allocation.height = requisition.height;
2022 gtk_widget_size_allocate (widget, &allocation);
2024 gtk_container_queue_resize (GTK_CONTAINER (widget));
2026 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
2029 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
2031 switch (window->type)
2033 case GTK_WINDOW_TOPLEVEL:
2034 attributes.window_type = GDK_WINDOW_TOPLEVEL;
2036 case GTK_WINDOW_POPUP:
2037 attributes.window_type = GDK_WINDOW_TEMP;
2040 g_warning (G_STRLOC": Unknown window type %d!", window->type);
2044 attributes.title = window->title;
2045 attributes.wmclass_name = window->wmclass_name;
2046 attributes.wmclass_class = window->wmclass_class;
2047 attributes.wclass = GDK_INPUT_OUTPUT;
2048 attributes.visual = gtk_widget_get_visual (widget);
2049 attributes.colormap = gtk_widget_get_colormap (widget);
2051 if (window->has_frame)
2053 attributes.width = widget->allocation.width + window->frame_left + window->frame_right;
2054 attributes.height = widget->allocation.height + window->frame_top + window->frame_bottom;
2055 attributes.event_mask = (GDK_EXPOSURE_MASK |
2056 GDK_KEY_PRESS_MASK |
2057 GDK_ENTER_NOTIFY_MASK |
2058 GDK_LEAVE_NOTIFY_MASK |
2059 GDK_FOCUS_CHANGE_MASK |
2060 GDK_STRUCTURE_MASK |
2061 GDK_BUTTON_MOTION_MASK |
2062 GDK_POINTER_MOTION_HINT_MASK |
2063 GDK_BUTTON_PRESS_MASK |
2064 GDK_BUTTON_RELEASE_MASK);
2066 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
2068 window->frame = gdk_window_new (NULL, &attributes, attributes_mask);
2069 gdk_window_set_user_data (window->frame, widget);
2071 attributes.window_type = GDK_WINDOW_CHILD;
2072 attributes.x = window->frame_left;
2073 attributes.y = window->frame_right;
2075 attributes_mask = GDK_WA_X | GDK_WA_Y;
2077 parent_window = window->frame;
2081 attributes_mask = 0;
2082 parent_window = NULL;
2085 attributes.width = widget->allocation.width;
2086 attributes.height = widget->allocation.height;
2087 attributes.event_mask = gtk_widget_get_events (widget);
2088 attributes.event_mask |= (GDK_EXPOSURE_MASK |
2089 GDK_KEY_PRESS_MASK |
2090 GDK_ENTER_NOTIFY_MASK |
2091 GDK_LEAVE_NOTIFY_MASK |
2092 GDK_FOCUS_CHANGE_MASK |
2093 GDK_STRUCTURE_MASK);
2095 attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP;
2096 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
2097 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
2098 widget->window = gdk_window_new (parent_window, &attributes, attributes_mask);
2099 gdk_window_set_user_data (widget->window, window);
2101 widget->style = gtk_style_attach (widget->style, widget->window);
2102 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
2104 gtk_style_set_background (widget->style, window->frame, GTK_STATE_NORMAL);
2106 /* This is a bad hack to set the window background. */
2107 gtk_window_paint (widget, NULL);
2109 if (window->transient_parent &&
2110 GTK_WIDGET_REALIZED (window->transient_parent))
2111 gdk_window_set_transient_for (widget->window,
2112 GTK_WIDGET (window->transient_parent)->window);
2114 if (window->wm_role)
2115 gdk_window_set_role (widget->window, window->wm_role);
2117 if (!window->decorated)
2118 gdk_window_set_decorations (widget->window, 0);
2120 gdk_window_set_type_hint (widget->window, window->type_hint);
2122 /* transient_for must be set to allow the modal hint */
2123 if (window->transient_parent && window->modal)
2124 gdk_window_set_modal_hint (widget->window, TRUE);
2126 gdk_window_set_modal_hint (widget->window, FALSE);
2130 gtk_window_unrealize (GtkWidget *widget)
2134 g_return_if_fail (GTK_IS_WINDOW (widget));
2136 window = GTK_WINDOW (widget);
2140 gdk_window_set_user_data (window->frame, NULL);
2141 gdk_window_destroy (window->frame);
2142 window->frame = NULL;
2145 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
2149 gtk_window_size_request (GtkWidget *widget,
2150 GtkRequisition *requisition)
2155 g_return_if_fail (GTK_IS_WINDOW (widget));
2156 g_return_if_fail (requisition != NULL);
2158 window = GTK_WINDOW (widget);
2159 bin = GTK_BIN (window);
2161 requisition->width = GTK_CONTAINER (window)->border_width * 2;
2162 requisition->height = GTK_CONTAINER (window)->border_width * 2;
2164 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
2166 GtkRequisition child_requisition;
2168 gtk_widget_size_request (bin->child, &child_requisition);
2170 requisition->width += child_requisition.width;
2171 requisition->height += child_requisition.height;
2176 gtk_window_size_allocate (GtkWidget *widget,
2177 GtkAllocation *allocation)
2180 GtkAllocation child_allocation;
2182 g_return_if_fail (GTK_IS_WINDOW (widget));
2183 g_return_if_fail (allocation != NULL);
2185 window = GTK_WINDOW (widget);
2186 widget->allocation = *allocation;
2188 if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child))
2190 child_allocation.x = GTK_CONTAINER (window)->border_width;
2191 child_allocation.y = GTK_CONTAINER (window)->border_width;
2192 child_allocation.width =
2193 MAX (1, (gint)allocation->width - child_allocation.x * 2);
2194 child_allocation.height =
2195 MAX (1, (gint)allocation->height - child_allocation.y * 2);
2197 gtk_widget_size_allocate (window->bin.child, &child_allocation);
2200 if (GTK_WIDGET_REALIZED (widget) && window->frame)
2202 gdk_window_resize (window->frame,
2203 allocation->width + window->frame_left + window->frame_right,
2204 allocation->height + window->frame_top + window->frame_bottom);
2209 gtk_window_event (GtkWidget *widget, GdkEvent *event)
2212 gboolean return_val;
2215 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2216 g_return_val_if_fail (event != NULL, FALSE);
2218 window = GTK_WINDOW (widget);
2220 if (window->frame && (event->any.window == window->frame))
2222 if ((event->type != GDK_KEY_PRESS) &&
2223 (event->type != GDK_KEY_RELEASE) &&
2224 (event->type != GDK_FOCUS_CHANGE))
2226 gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "event");
2228 gtk_signal_emit (GTK_OBJECT (widget), window_signals[FRAME_EVENT], event, &return_val);
2233 g_object_unref (event->any.window);
2234 event->any.window = g_object_ref (widget->window);
2242 gtk_window_frame_event (GtkWidget *widget, GdkEvent *event)
2244 GdkEventConfigure *configure_event;
2245 GtkWindow *window = GTK_WINDOW (widget);
2248 switch (event->type)
2251 configure_event = (GdkEventConfigure *)event;
2253 /* Invalidate the decorations */
2256 rect.width = configure_event->width;
2257 rect.height = configure_event->height;
2259 gdk_window_invalidate_rect (window->frame, &rect, FALSE);
2261 /* Pass on the (modified) configure event */
2262 configure_event->width -= window->frame_left + window->frame_right;
2263 configure_event->height -= window->frame_top + window->frame_bottom;
2264 return gtk_window_configure_event (widget, configure_event);
2273 gtk_window_configure_event (GtkWidget *widget,
2274 GdkEventConfigure *event)
2278 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2279 g_return_val_if_fail (event != NULL, FALSE);
2281 window = GTK_WINDOW (widget);
2283 /* we got a configure event specifying the new window size and position,
2284 * in principle we have to distinguish 4 cases here:
2285 * 1) the size didn't change and resize_count == 0
2286 * -> the window was merely moved (sometimes not even that)
2287 * 2) the size didn't change and resize_count > 0
2288 * -> we requested a new size, but didn't get it
2289 * 3) the size changed and resize_count > 0
2290 * -> we asked for a new size and we got one
2291 * 4) the size changed and resize_count == 0
2292 * -> we got resized from outside the toolkit, and have to
2293 * accept that size since we don't want to fight neither the
2294 * window manager nor the user
2295 * in the three latter cases we have to reallocate the widget tree,
2296 * which happens in gtk_window_move_resize(), so we set a flag for
2297 * that function and assign the new size. if resize_count > 1,
2298 * we simply do nothing and wait for more configure events.
2301 if (window->resize_count > 0 ||
2302 widget->allocation.width != event->width ||
2303 widget->allocation.height != event->height)
2305 if (window->resize_count > 0)
2306 window->resize_count -= 1;
2308 if (window->resize_count == 0)
2310 window->handling_resize = TRUE;
2312 widget->allocation.width = event->width;
2313 widget->allocation.height = event->height;
2315 gtk_widget_queue_resize (widget);
2323 gtk_window_key_press_event (GtkWidget *widget,
2329 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2330 g_return_val_if_fail (event != NULL, FALSE);
2332 window = GTK_WINDOW (widget);
2336 if (window->focus_widget && window->focus_widget != widget &&
2337 GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
2338 handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
2341 handled = gtk_window_mnemonic_activate (window,
2346 handled = gtk_accel_groups_activate (GTK_OBJECT (window), event->keyval, event->state);
2348 /* Chain up, invokes binding set */
2349 if (!handled && GTK_WIDGET_CLASS (parent_class)->key_press_event)
2350 handled = GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
2357 gtk_window_real_activate_default (GtkWindow *window)
2359 gtk_window_activate_default (window);
2363 gtk_window_real_activate_focus (GtkWindow *window)
2365 gtk_window_activate_focus (window);
2369 gtk_window_move_focus (GtkWindow *window,
2370 GtkDirectionType dir)
2372 gtk_widget_child_focus (GTK_WIDGET (window), dir);
2374 if (!GTK_CONTAINER (window)->focus_child)
2375 gtk_window_set_focus (window, NULL);
2379 gtk_window_key_release_event (GtkWidget *widget,
2385 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2386 g_return_val_if_fail (event != NULL, FALSE);
2388 window = GTK_WINDOW (widget);
2390 if (window->focus_widget &&
2391 window->focus_widget != widget &&
2392 GTK_WIDGET_SENSITIVE (window->focus_widget))
2394 handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
2397 if (!handled && GTK_WIDGET_CLASS (parent_class)->key_release_event)
2398 handled = GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
2404 gtk_window_enter_notify_event (GtkWidget *widget,
2405 GdkEventCrossing *event)
2407 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2408 g_return_val_if_fail (event != NULL, FALSE);
2414 gtk_window_leave_notify_event (GtkWidget *widget,
2415 GdkEventCrossing *event)
2417 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2418 g_return_val_if_fail (event != NULL, FALSE);
2424 gtk_window_focus_in_event (GtkWidget *widget,
2425 GdkEventFocus *event)
2427 GtkWindow *window = GTK_WINDOW (widget);
2428 GdkEventFocus fevent;
2430 /* It appears spurious focus in events can occur when
2431 * the window is hidden. So we'll just check to see if
2432 * the window is visible before actually handling the
2435 if (GTK_WIDGET_VISIBLE (widget))
2437 window->has_focus = TRUE;
2439 if (window->focus_widget &&
2440 window->focus_widget != widget &&
2441 !GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2443 fevent.type = GDK_FOCUS_CHANGE;
2444 fevent.window = window->focus_widget->window;
2447 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2455 gtk_window_focus_out_event (GtkWidget *widget,
2456 GdkEventFocus *event)
2458 GtkWindow *window = GTK_WINDOW (widget);
2459 GdkEventFocus fevent;
2461 window->has_focus = FALSE;
2463 if (window->focus_widget &&
2464 window->focus_widget != widget &&
2465 GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2467 fevent.type = GDK_FOCUS_CHANGE;
2468 fevent.window = window->focus_widget->window;
2471 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2477 static GdkAtom atom_rcfiles = GDK_NONE;
2480 gtk_window_read_rcfiles (GtkWidget *widget,
2481 GdkEventClient *event)
2483 GList *embedded_windows;
2485 embedded_windows = gtk_object_get_data (GTK_OBJECT (widget), "gtk-embedded");
2486 if (embedded_windows)
2491 for (i = 0; i < 5; i++)
2493 sev.data_format = 32;
2494 sev.message_type = atom_rcfiles;
2496 while (embedded_windows)
2498 guint xid = GPOINTER_TO_UINT (embedded_windows->data);
2499 gdk_event_send_client_message ((GdkEvent *) &sev, xid);
2500 embedded_windows = embedded_windows->next;
2504 gtk_rc_reparse_all ();
2508 gtk_window_client_event (GtkWidget *widget,
2509 GdkEventClient *event)
2511 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2512 g_return_val_if_fail (event != NULL, FALSE);
2515 atom_rcfiles = gdk_atom_intern ("_GTK_READ_RCFILES", FALSE);
2517 if (event->message_type == atom_rcfiles)
2518 gtk_window_read_rcfiles (widget, event);
2524 gtk_window_check_resize (GtkContainer *container)
2528 g_return_if_fail (GTK_IS_WINDOW (container));
2530 window = GTK_WINDOW (container);
2532 if (GTK_WIDGET_VISIBLE (container))
2533 gtk_window_move_resize (window);
2537 gtk_window_focus (GtkWidget *widget,
2538 GtkDirectionType direction)
2542 GtkContainer *container;
2543 GtkWidget *old_focus_child;
2546 container = GTK_CONTAINER (widget);
2547 window = GTK_WINDOW (widget);
2548 bin = GTK_BIN (widget);
2550 old_focus_child = container->focus_child;
2552 /* We need a special implementation here to deal properly with wrapping
2553 * around in the tab chain without the danger of going into an
2556 if (old_focus_child)
2558 if (gtk_widget_child_focus (old_focus_child, direction))
2562 if (window->focus_widget)
2564 /* Wrapped off the end, clear the focus setting for the toplpevel */
2565 parent = window->focus_widget->parent;
2568 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
2569 parent = GTK_WIDGET (parent)->parent;
2572 gtk_window_set_focus (GTK_WINDOW (container), NULL);
2575 /* Now try to focus the first widget in the window */
2578 if (gtk_widget_child_focus (bin->child, direction))
2586 gtk_window_real_set_focus (GtkWindow *window,
2589 GdkEventFocus event;
2590 gboolean def_flags = 0;
2592 g_return_if_fail (GTK_IS_WINDOW (window));
2594 if (window->default_widget)
2595 def_flags = GTK_WIDGET_HAS_DEFAULT (window->default_widget);
2597 if (window->focus_widget)
2599 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2600 (window->focus_widget != window->default_widget))
2602 GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2604 if (window->default_widget)
2605 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2608 if (window->has_focus)
2610 event.type = GDK_FOCUS_CHANGE;
2611 event.window = window->focus_widget->window;
2614 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2618 window->focus_widget = focus;
2620 if (window->focus_widget)
2622 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2623 (window->focus_widget != window->default_widget))
2625 if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget))
2626 GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2628 if (window->default_widget)
2629 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2632 if (window->has_focus)
2634 event.type = GDK_FOCUS_CHANGE;
2635 event.window = window->focus_widget->window;
2638 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2642 if (window->default_widget &&
2643 (def_flags != GTK_WIDGET_FLAGS (window->default_widget)))
2644 gtk_widget_queue_draw (window->default_widget);
2649 /*********************************
2650 * Functions related to resizing *
2651 *********************************/
2654 gtk_window_move_resize (GtkWindow *window)
2657 GtkContainer *container;
2658 GtkWindowGeometryInfo *info;
2659 GtkWindowLastGeometryInfo saved_last_info;
2660 GdkGeometry new_geometry;
2664 gint new_width, new_height;
2665 gboolean need_reposition;
2666 gboolean default_size_changed = FALSE;
2667 gboolean hints_changed = FALSE;
2668 gboolean may_shrink = window->auto_shrink;
2670 g_return_if_fail (GTK_WIDGET_REALIZED (window));
2672 widget = GTK_WIDGET (window);
2673 container = GTK_CONTAINER (widget);
2674 info = gtk_window_get_geometry_info (window, TRUE);
2675 saved_last_info = info->last;
2677 gtk_widget_size_request (widget, NULL);
2678 gtk_window_compute_default_size (window, &new_width, &new_height);
2680 if (info->last.width < 0 ||
2681 info->last.width != new_width ||
2682 info->last.height != new_height)
2684 default_size_changed = TRUE;
2685 may_shrink |= info->may_shrink;
2686 info->last.width = new_width;
2687 info->last.height = new_height;
2689 /* We need to force a reposition in this case
2691 if (window->position == GTK_WIN_POS_CENTER_ALWAYS)
2692 window->use_uposition = TRUE;
2694 info->may_shrink = FALSE;
2696 /* Compute new set of hints for the window
2698 gtk_window_compute_hints (window, &new_geometry, &new_flags);
2699 if (!gtk_window_compare_hints (&info->last.geometry, info->last.flags,
2700 &new_geometry, new_flags))
2702 hints_changed = TRUE;
2703 info->last.geometry = new_geometry;
2704 info->last.flags = new_flags;
2707 /* From the default size and the allocation, figure out the size
2708 * the window should be.
2710 if (!default_size_changed ||
2712 new_width <= widget->allocation.width &&
2713 new_height <= widget->allocation.height))
2715 new_width = widget->allocation.width;
2716 new_height = widget->allocation.height;
2719 /* constrain the window size to the specified geometry */
2720 gtk_window_constrain_size (window,
2721 &new_geometry, new_flags,
2722 new_width, new_height,
2723 &new_width, &new_height);
2725 /* compute new window position if a move is required
2727 need_reposition = gtk_window_compute_reposition (window, new_width, new_height, &x, &y);
2728 if (need_reposition && !(new_flags & GDK_HINT_POS))
2730 new_flags |= GDK_HINT_POS;
2731 hints_changed = TRUE;
2735 /* handle actual resizing:
2736 * - handle reallocations due to configure events
2737 * - figure whether we need to request a new window size
2738 * - handle simple resizes within our widget tree
2739 * - reposition window if neccessary
2741 width = widget->allocation.width;
2742 height = widget->allocation.height;
2744 if (window->handling_resize)
2746 GtkAllocation allocation;
2748 /* if we are just responding to a configure event, which
2749 * might be due to a resize by the window manager, the
2750 * user, or a response to a resizing request we made
2751 * earlier, we go ahead, allocate the new size and we're done
2752 * (see gtk_window_configure_event() for more details).
2755 window->handling_resize = FALSE;
2757 allocation = widget->allocation;
2759 gtk_widget_size_allocate (widget, &allocation);
2760 gtk_widget_queue_draw (widget);
2762 if ((default_size_changed || hints_changed) && (width != new_width || height != new_height))
2764 /* We could be here for two reasons
2765 * 1) We coincidentally got a resize while handling
2767 * 2) Our computation of default_size_changed was completely
2768 * screwed up, probably because one of our children
2769 * is changed requisition during size allocation).
2771 * For 1), we could just go ahead and ask for the
2772 * new size right now, but doing that for 2)
2773 * might well be fighting the user (and can even
2774 * trigger a loop). Since we really don't want to
2775 * do that, we requeue a resize in hopes that
2776 * by the time it gets handled, the child has seen
2777 * the light and is willing to go along with the
2778 * new size. (this happens for the zvt widget, since
2779 * the size_allocate() above will have stored the
2780 * requisition corresponding to the new size in the
2783 * This doesn't buy us anything for 1), but it shouldn't
2784 * hurt us too badly, since it is what would have
2785 * happened if we had gotten the configure event before
2786 * the new size had been set.
2789 if (need_reposition)
2792 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2794 gdk_window_move (GTK_WIDGET (window)->window, x, y);
2797 /* we have to preserve the values and flags that are used
2798 * for computation of default_size_changed and hints_changed
2800 info->last = saved_last_info;
2802 gtk_widget_queue_resize (widget);
2808 /* Now set hints if necessary
2811 gdk_window_set_geometry_hints (widget->window,
2815 if ((default_size_changed || hints_changed) &&
2816 (width != new_width || height != new_height))
2818 /* given that (width != new_width || height != new_height), we are in one
2819 * of the following situations:
2821 * default_size_changed
2822 * our requisition has changed and we need a different window size,
2823 * so we request it from the window manager.
2825 * !default_size_changed
2826 * the window manager wouldn't assign us the size we requested, in this
2827 * case we don't try to request a new size with every resize.
2829 * !default_size_changed && hints_changed
2830 * the window manager rejects our size, but we have just changed the
2831 * window manager hints, so there's a certain chance our request will
2832 * be honoured this time, so we try again.
2835 /* request a new window size */
2836 if (need_reposition)
2840 gdk_window_move_resize (window->frame,
2841 x - window->frame_left, y - window->frame_top,
2842 new_width + window->frame_left + window->frame_right,
2843 new_height + window->frame_top + window->frame_bottom);
2844 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2847 gdk_window_move_resize (GTK_WIDGET (window)->window, x, y, new_width, new_height);
2852 gdk_window_resize (window->frame,
2853 new_width + window->frame_left + window->frame_right,
2854 new_height + window->frame_top + window->frame_bottom);
2855 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2857 window->resize_count += 1;
2859 /* we are now awaiting the new configure event in response to our
2860 * resizing request. the configure event will cause a new resize
2861 * with ->handling_resize=TRUE.
2862 * until then, we want to
2863 * - discard expose events
2864 * - coalesce resizes for our children
2865 * - defer any window resizes until the configure event arrived
2866 * to achive this, we queue a resize for the window, but remove its
2867 * resizing handler, so resizing will not be handled from the next
2868 * idle handler but when the configure event arrives.
2870 * FIXME: we should also dequeue the pending redraws here, since
2871 * we handle those ourselves in ->handling_resize==TRUE.
2873 gtk_widget_queue_resize (GTK_WIDGET (container));
2874 if (container->resize_mode == GTK_RESIZE_QUEUE)
2875 _gtk_container_dequeue_resize_handler (container);
2879 if (need_reposition)
2882 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2884 gdk_window_move (widget->window, x, y);
2887 if (container->resize_widgets)
2888 gtk_container_resize_children (GTK_CONTAINER (window));
2892 /* Compare two sets of Geometry hints for equality.
2895 gtk_window_compare_hints (GdkGeometry *geometry_a,
2897 GdkGeometry *geometry_b,
2900 if (flags_a != flags_b)
2903 if ((flags_a & GDK_HINT_MIN_SIZE) &&
2904 (geometry_a->min_width != geometry_b->min_width ||
2905 geometry_a->min_height != geometry_b->min_height))
2908 if ((flags_a & GDK_HINT_MAX_SIZE) &&
2909 (geometry_a->max_width != geometry_b->max_width ||
2910 geometry_a->max_height != geometry_b->max_height))
2913 if ((flags_a & GDK_HINT_BASE_SIZE) &&
2914 (geometry_a->base_width != geometry_b->base_width ||
2915 geometry_a->base_height != geometry_b->base_height))
2918 if ((flags_a & GDK_HINT_ASPECT) &&
2919 (geometry_a->min_aspect != geometry_b->min_aspect ||
2920 geometry_a->max_aspect != geometry_b->max_aspect))
2923 if ((flags_a & GDK_HINT_RESIZE_INC) &&
2924 (geometry_a->width_inc != geometry_b->width_inc ||
2925 geometry_a->height_inc != geometry_b->height_inc))
2928 if ((flags_a & GDK_HINT_WIN_GRAVITY) &&
2929 geometry_a->win_gravity != geometry_b->win_gravity)
2935 /* Compute the default_size for a window. The result will
2936 * be stored in *width and *height. The default size is
2937 * the size the window should have when initially mapped.
2938 * This routine does not attempt to constrain the size
2939 * to obey the geometry hints - that must be done elsewhere.
2942 gtk_window_compute_default_size (GtkWindow *window,
2946 GtkRequisition requisition;
2947 GtkWindowGeometryInfo *info;
2949 gtk_widget_get_child_requisition (GTK_WIDGET (window), &requisition);
2950 *width = requisition.width;
2951 *height = requisition.height;
2953 info = gtk_window_get_geometry_info (window, FALSE);
2955 if (*width == 0 && *height == 0)
2964 *width = info->width > 0 ? info->width : *width;
2965 *height = info->height > 0 ? info->height : *height;
2970 _gtk_window_constrain_size (GtkWindow *window,
2976 GtkWindowGeometryInfo *info;
2978 g_return_if_fail (GTK_IS_WINDOW (window));
2980 info = window->geometry_info;
2983 GdkWindowHints flags = info->last.flags;
2984 GdkGeometry *geometry = &info->last.geometry;
2986 gtk_window_constrain_size (window,
2997 gtk_window_constrain_size (GtkWindow *window,
2998 GdkGeometry *geometry,
3005 gdk_window_constrain_size (geometry, flags, width, height,
3006 new_width, new_height);
3009 /* Compute the set of geometry hints and flags for a window
3010 * based on the application set geometry, and requisiition
3011 * of the window. gtk_widget_size_request() must have been
3015 gtk_window_compute_hints (GtkWindow *window,
3016 GdkGeometry *new_geometry,
3020 GtkWidgetAuxInfo *aux_info;
3022 gint extra_width = 0;
3023 gint extra_height = 0;
3024 GtkWindowGeometryInfo *geometry_info;
3025 GtkRequisition requisition;
3027 g_return_if_fail (GTK_IS_WINDOW (window));
3029 widget = GTK_WIDGET (window);
3031 gtk_widget_get_child_requisition (widget, &requisition);
3032 geometry_info = gtk_window_get_geometry_info (GTK_WINDOW (widget), FALSE);
3034 g_return_if_fail (geometry_info != NULL);
3036 *new_flags = geometry_info->mask;
3037 *new_geometry = geometry_info->geometry;
3039 if (geometry_info->widget)
3041 extra_width = widget->requisition.width - geometry_info->widget->requisition.width;
3042 extra_height = widget->requisition.height - geometry_info->widget->requisition.height;
3048 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3049 if (aux_info && aux_info->x_set && aux_info->y_set)
3053 *new_flags |= GDK_HINT_POS;
3056 if (*new_flags & GDK_HINT_BASE_SIZE)
3058 new_geometry->base_width += extra_width;
3059 new_geometry->base_height += extra_height;
3061 else if (!(*new_flags & GDK_HINT_MIN_SIZE) &&
3062 (*new_flags & GDK_HINT_RESIZE_INC) &&
3063 ((extra_width != 0) || (extra_height != 0)))
3065 *new_flags |= GDK_HINT_BASE_SIZE;
3067 new_geometry->base_width = extra_width;
3068 new_geometry->base_height = extra_height;
3071 if (*new_flags & GDK_HINT_MIN_SIZE)
3073 if (new_geometry->min_width < 0)
3074 new_geometry->min_width = requisition.width;
3076 new_geometry->min_width += extra_width;
3078 if (new_geometry->min_height < 0)
3079 new_geometry->min_width = requisition.height;
3081 new_geometry->min_height += extra_height;
3083 else if (!window->allow_shrink)
3085 *new_flags |= GDK_HINT_MIN_SIZE;
3087 new_geometry->min_width = requisition.width;
3088 new_geometry->min_height = requisition.height;
3091 if (*new_flags & GDK_HINT_MAX_SIZE)
3093 if (new_geometry->max_width < 0)
3094 new_geometry->max_width = requisition.width;
3096 new_geometry->max_width += extra_width;
3098 if (new_geometry->max_height < 0)
3099 new_geometry->max_width = requisition.height;
3101 new_geometry->max_height += extra_height;
3103 else if (!window->allow_grow)
3105 *new_flags |= GDK_HINT_MAX_SIZE;
3107 new_geometry->max_width = requisition.width;
3108 new_geometry->max_height = requisition.height;
3111 *new_flags |= GDK_HINT_WIN_GRAVITY;
3112 new_geometry->win_gravity = window->gravity;
3115 /* Compute a new position for the window based on a new
3116 * size. *x and *y will be set to the new coordinates. Returns
3117 * TRUE if the window needs to be moved (and thus x and y got
3121 gtk_window_compute_reposition (GtkWindow *window,
3127 GtkWidget *widget = GTK_WIDGET (window);
3128 GtkWindowPosition pos;
3129 GtkWidget *parent_widget;
3130 gboolean needs_move = FALSE;
3132 parent_widget = (GtkWidget*) window->transient_parent;
3134 pos = window->position;
3135 if (pos == GTK_WIN_POS_CENTER_ON_PARENT &&
3136 (parent_widget == NULL ||
3137 !GTK_WIDGET_MAPPED (parent_widget)))
3138 pos = GTK_WIN_POS_NONE;
3142 case GTK_WIN_POS_CENTER:
3143 case GTK_WIN_POS_CENTER_ALWAYS:
3144 if (window->use_uposition)
3146 gint screen_width = gdk_screen_width ();
3147 gint screen_height = gdk_screen_height ();
3149 *x = (screen_width - new_width) / 2;
3150 *y = (screen_height - new_height) / 2;
3155 case GTK_WIN_POS_CENTER_ON_PARENT:
3156 if (window->use_uposition)
3159 gdk_window_get_origin (parent_widget->window,
3162 *x = ox + (parent_widget->allocation.width - new_width) / 2;
3163 *y = oy + (parent_widget->allocation.height - new_height) / 2;
3168 case GTK_WIN_POS_MOUSE:
3169 if (window->use_uposition)
3171 gint screen_width = gdk_screen_width ();
3172 gint screen_height = gdk_screen_height ();
3174 gdk_window_get_pointer (NULL, x, y, NULL);
3175 *x -= new_width / 2;
3176 *y -= new_height / 2;
3177 *x = CLAMP (*x, 0, screen_width - new_width);
3178 *y = CLAMP (*y, 0, screen_height - new_height);
3183 if (window->use_uposition)
3185 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3187 if (aux_info && aux_info->x_set && aux_info->y_set)
3199 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, TRUE);
3201 /* we handle necessary window positioning by hand here,
3202 * so we can coalesce the window movement with possible
3203 * resizes to get only one configure event.
3205 aux_info->x_set = TRUE;
3206 aux_info->y_set = TRUE;
3209 window->use_uposition = FALSE;
3215 /***********************
3216 * Redrawing functions *
3217 ***********************/
3220 gtk_window_paint (GtkWidget *widget,
3223 gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL,
3224 GTK_SHADOW_NONE, area, widget, "base", 0, 0, -1, -1);
3228 gtk_window_expose (GtkWidget *widget,
3229 GdkEventExpose *event)
3231 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
3232 g_return_val_if_fail (event != NULL, FALSE);
3234 if (!GTK_WIDGET_APP_PAINTABLE (widget))
3235 gtk_window_paint (widget, &event->area);
3237 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
3238 return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
3244 * gtk_window_set_has_frame:
3245 * @window: a #GtkWindow
3246 * @setting: a boolean
3248 * If this function is called on a window with setting of TRUE, before
3249 * it is realized or showed, it will have a "frame" window around
3250 * widget->window, accessible in window->frame. Using the signal
3251 * frame_event you can recieve all events targeted at the frame.
3253 * This function is used by the linux-fb port to implement managed
3254 * windows, but it could concievably be used by X-programs that
3255 * want to do their own window decorations.
3258 gtk_window_set_has_frame (GtkWindow *window,
3261 g_return_if_fail (GTK_IS_WINDOW (window));
3262 g_return_if_fail (!GTK_WIDGET_REALIZED (window));
3264 window->has_frame = setting != FALSE;
3268 * gtk_window_get_has_frame:
3269 * @window: a #GtkWindow
3271 * Returns whether the window has a frame window exterior to
3272 * widget->window. See gtk_window_set_has_frame ().
3274 * Return value: %TRUE if a frame has been added to the window
3275 * via gtk_widow_has_frame
3278 gtk_window_get_has_frame (GtkWindow *window)
3280 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
3282 return window->has_frame;
3286 * gtk_window_set_frame_dimensions:
3287 * @window: a #GtkWindow that has a frame
3288 * @left: The width of the left border
3289 * @top: The height of the top border
3290 * @right: The width of the right border
3291 * @bottom: The height of the bottom border
3293 * For windows with frames (see #gtk_window_set_has_frame) this function
3294 * can be used to change the size of the frame border.
3297 gtk_window_set_frame_dimensions (GtkWindow *window,
3303 GtkWidget *widget = GTK_WIDGET (window);
3305 g_return_if_fail (GTK_IS_WINDOW (window));
3307 if (window->frame_left == left &&
3308 window->frame_top == top &&
3309 window->frame_right == right &&
3310 window->frame_bottom == bottom)
3313 window->frame_left = left;
3314 window->frame_top = top;
3315 window->frame_right = right;
3316 window->frame_bottom = bottom;
3318 if (GTK_WIDGET_REALIZED (widget) && window->frame)
3320 gint width = widget->allocation.width + left + right;
3321 gint height = widget->allocation.height + top + bottom;
3322 gdk_window_resize (window->frame, width, height);
3323 gtk_decorated_window_move_resize_window (window,
3325 widget->allocation.width,
3326 widget->allocation.height);
3331 * gtk_window_present:
3332 * @window: a #GtkWindow
3334 * Presents a window to the user. This may mean raising the window
3335 * in the stacking order, deiconifying it, moving it to the current
3336 * desktop, and/or giving it the keyboard focus, possibly dependent
3337 * on the user's platform, window manager, and preferences.
3339 * If @window is hidden, this function calls gtk_widget_show()
3342 * This function should be used when the user tries to open a window
3343 * that's already open. Say for example the preferences dialog is
3344 * currently open, and the user chooses Preferences from the menu
3345 * a second time; use gtk_window_present() to move the already-open dialog
3346 * where the user can see it.
3350 gtk_window_present (GtkWindow *window)
3354 g_return_if_fail (GTK_IS_WINDOW (window));
3356 widget = GTK_WIDGET (window);
3358 if (GTK_WIDGET_VISIBLE (window))
3360 g_assert (widget->window != NULL);
3362 gdk_window_show (widget->window);
3364 /* note that gdk_window_focus() will also move the window to
3365 * the current desktop, for WM spec compliant window managers.
3367 gdk_window_focus (widget->window,
3368 gtk_get_current_event_time ());
3372 gtk_widget_show (widget);
3377 * gtk_window_iconify:
3378 * @window: a #GtkWindow
3380 * Asks to iconify (i.e. minimize) the specified @window. Note that you
3381 * shouldn't assume the window is definitely iconified afterward,
3382 * because other entities (e.g. the user or window manager) could
3383 * deiconify it again, or there may not be a window manager in which
3384 * case iconification isn't possible, etc. But normally the window
3385 * will end up iconified. Just don't write code that crashes if not.
3387 * It's permitted to call this function before showing a window,
3388 * in which case the window will be iconified before it ever appears
3391 * You can track iconification via the "window_state_event" signal
3396 gtk_window_iconify (GtkWindow *window)
3399 GdkWindow *toplevel;
3401 g_return_if_fail (GTK_IS_WINDOW (window));
3403 widget = GTK_WIDGET (window);
3405 window->iconify_initially = TRUE;
3408 toplevel = window->frame;
3410 toplevel = widget->window;
3412 if (toplevel != NULL)
3413 gdk_window_iconify (toplevel);
3417 * gtk_window_deiconify:
3418 * @window: a #GtkWindow
3420 * Asks to deiconify (i.e. unminimize) the specified @window. Note
3421 * that you shouldn't assume the window is definitely deiconified
3422 * afterward, because other entities (e.g. the user or window manager)
3423 * could iconify it again before your code which assumes
3424 * deiconification gets to run.
3426 * You can track iconification via the "window_state_event" signal
3430 gtk_window_deiconify (GtkWindow *window)
3433 GdkWindow *toplevel;
3435 g_return_if_fail (GTK_IS_WINDOW (window));
3437 widget = GTK_WIDGET (window);
3439 window->iconify_initially = FALSE;
3442 toplevel = window->frame;
3444 toplevel = widget->window;
3446 if (toplevel != NULL)
3447 gdk_window_deiconify (toplevel);
3452 * @window: a #GtkWindow
3454 * Asks to stick @window, which means that it will appear on all user
3455 * desktops. Note that you shouldn't assume the window is definitely
3456 * stuck afterward, because other entities (e.g. the user or window
3457 * manager) could unstick it again, and some window managers do not
3458 * support sticking windows. But normally the window will end up
3459 * stuck. Just don't write code that crashes if not.
3461 * It's permitted to call this function before showing a window.
3463 * You can track stickiness via the "window_state_event" signal
3468 gtk_window_stick (GtkWindow *window)
3471 GdkWindow *toplevel;
3473 g_return_if_fail (GTK_IS_WINDOW (window));
3475 widget = GTK_WIDGET (window);
3477 window->stick_initially = TRUE;
3480 toplevel = window->frame;
3482 toplevel = widget->window;
3484 if (toplevel != NULL)
3485 gdk_window_stick (toplevel);
3489 * gtk_window_unstick:
3490 * @window: a #GtkWindow
3492 * Asks to unstick @window, which means that it will appear on only
3493 * one of the user's desktops. Note that you shouldn't assume the
3494 * window is definitely unstuck afterward, because other entities
3495 * (e.g. the user or window manager) could stick it again. But
3496 * normally the window will end up stuck. Just don't write code that
3499 * You can track stickiness via the "window_state_event" signal
3504 gtk_window_unstick (GtkWindow *window)
3507 GdkWindow *toplevel;
3509 g_return_if_fail (GTK_IS_WINDOW (window));
3511 widget = GTK_WIDGET (window);
3513 window->stick_initially = FALSE;
3516 toplevel = window->frame;
3518 toplevel = widget->window;
3520 if (toplevel != NULL)
3521 gdk_window_unstick (toplevel);
3525 * gtk_window_maximize:
3526 * @window: a #GtkWindow
3528 * Asks to maximize @window, so that it becomes full-screen. Note that
3529 * you shouldn't assume the window is definitely maximized afterward,
3530 * because other entities (e.g. the user or window manager) could
3531 * unmaximize it again, and not all window managers support
3532 * maximization. But normally the window will end up maximized. Just
3533 * don't write code that crashes if not.
3535 * It's permitted to call this function before showing a window,
3536 * in which case the window will be maximized when it appears onscreen
3539 * You can track maximization via the "window_state_event" signal
3544 gtk_window_maximize (GtkWindow *window)
3547 GdkWindow *toplevel;
3549 g_return_if_fail (GTK_IS_WINDOW (window));
3551 widget = GTK_WIDGET (window);
3553 window->maximize_initially = TRUE;
3556 toplevel = window->frame;
3558 toplevel = widget->window;
3560 if (toplevel != NULL)
3561 gdk_window_maximize (toplevel);
3565 * gtk_window_unmaximize:
3566 * @window: a #GtkWindow
3568 * Asks to unmaximize @window. Note that you shouldn't assume the
3569 * window is definitely unmaximized afterward, because other entities
3570 * (e.g. the user or window manager) could maximize it again, and not
3571 * all window managers honor requests to unmaximize. But normally the
3572 * window will end up unmaximized. Just don't write code that crashes
3575 * You can track maximization via the "window_state_event" signal
3580 gtk_window_unmaximize (GtkWindow *window)
3583 GdkWindow *toplevel;
3585 g_return_if_fail (GTK_IS_WINDOW (window));
3587 widget = GTK_WIDGET (window);
3589 window->maximize_initially = FALSE;
3592 toplevel = window->frame;
3594 toplevel = widget->window;
3596 if (toplevel != NULL)
3597 gdk_window_unmaximize (toplevel);
3601 * gtk_window_set_resizable:
3602 * @window: a #GtkWindow
3603 * @resizable: %TRUE if the user can resize this window
3605 * Sets whether the user can resize a window. Windows are user resizable
3609 gtk_window_set_resizable (GtkWindow *window,
3612 g_return_if_fail (GTK_IS_WINDOW (window));
3614 gtk_window_set_policy (window, FALSE, resizable, FALSE);
3618 * gtk_window_get_resizable:
3619 * @window: a #GtkWindow
3621 * Gets the value set by gtk_window_set_resizable().
3623 * Return value: %TRUE if the user can resize the window
3626 gtk_window_get_resizable (GtkWindow *window)
3628 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
3630 /* allow_grow is most likely to indicate the semantic concept we
3631 * mean by "resizable" (and will be a reliable indicator if
3632 * set_policy() hasn't been called)
3634 return window->allow_grow;
3638 * gtk_window_set_gravity:
3639 * @window: a #GtkWindow
3640 * @gravity: window gravity
3642 * Window gravity defines the "reference point" to be used when
3643 * positioning or resizing a window. Calls to
3644 * gtk_widget_set_uposition() will position a different point on the
3645 * window depending on the window gravity. When the window changes size
3646 * the reference point determined by the window's gravity will stay in
3649 * See #GdkGravity for full details. To briefly summarize,
3650 * #GDK_GRAVITY_NORTH_WEST means that the reference point is the
3651 * northwest (top left) corner of the window
3652 * frame. #GDK_GRAVITY_SOUTH_EAST would be the bottom right corner of
3653 * the frame, and so on. If you want to position the window contents,
3654 * rather than the window manager's frame, #GDK_GRAVITY_STATIC moves
3655 * the reference point to the northwest corner of the #GtkWindow
3658 * The default window gravity is #GDK_GRAVITY_NORTH_WEST.
3662 gtk_window_set_gravity (GtkWindow *window,
3665 g_return_if_fail (GTK_IS_WINDOW (window));
3667 if (gravity != window->gravity)
3669 window->gravity = gravity;
3671 /* gtk_window_move_resize() will adapt gravity
3673 gtk_widget_queue_resize (GTK_WIDGET (window));
3678 * gtk_window_get_gravity:
3679 * @window: a #GtkWindow
3681 * Gets the value set by gtk_window_set_gravity().
3683 * Return value: window gravity
3686 gtk_window_get_gravity (GtkWindow *window)
3688 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
3690 return window->gravity;
3694 * gtk_window_begin_resize_drag:
3695 * @window: a #GtkWindow
3696 * @button: mouse button that initiated the drag
3697 * @edge: position of the resize control
3698 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3699 * @root_y: Y position where the user clicked to initiate the drag
3700 * @timestamp: timestamp from the click event that initiated the drag
3702 * Starts resizing a window. This function is used if an application
3703 * has window resizing controls. When GDK can support it, the resize
3704 * will be done using the standard mechanism for the window manager or
3705 * windowing system. Otherwise, GDK will try to emulate window
3706 * resizing, potentially not all that well, depending on the windowing system.
3710 gtk_window_begin_resize_drag (GtkWindow *window,
3718 GdkWindow *toplevel;
3720 g_return_if_fail (GTK_IS_WINDOW (window));
3721 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3723 widget = GTK_WIDGET (window);
3726 toplevel = window->frame;
3728 toplevel = widget->window;
3730 gdk_window_begin_resize_drag (toplevel,
3737 * gtk_window_get_frame_dimensions:
3738 * @window: a #GtkWindow
3739 * @left: location to store the width of the frame at the left, or %NULL
3740 * @top: location to store the height of the frame at the top, or %NULL
3741 * @right: location to store the width of the frame at the returns, or %NULL
3742 * @bottom: location to store the height of the frame at the bottom, or %NULL
3744 * Retrieves the dimensions of the frame window for this toplevel.
3745 * See gtk_window_set_has_frame(), gtk_window_set_frame_dimensions().
3748 gtk_window_get_frame_dimensions (GtkWindow *window,
3754 g_return_if_fail (GTK_IS_WINDOW (window));
3757 *left = window->frame_left;
3759 *top = window->frame_top;
3761 *top = window->frame_right;
3763 *top = window->frame_bottom;
3767 * gtk_window_begin_move_drag:
3768 * @window: a #GtkWindow
3769 * @button: mouse button that initiated the drag
3770 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3771 * @root_y: Y position where the user clicked to initiate the drag
3772 * @timestamp: timestamp from the click event that initiated the drag
3774 * Starts moving a window. This function is used if an application
3775 * has window movement grips. When GDK can support it, the window movement
3776 * will be done using the standard mechanism for the window manager or
3777 * windowing system. Otherwise, GDK will try to emulate window
3778 * movement, potentially not all that well, depending on the windowing system.
3782 gtk_window_begin_move_drag (GtkWindow *window,
3789 GdkWindow *toplevel;
3791 g_return_if_fail (GTK_IS_WINDOW (window));
3792 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3794 widget = GTK_WIDGET (window);
3797 toplevel = window->frame;
3799 toplevel = widget->window;
3801 gdk_window_begin_move_drag (toplevel,
3809 gtk_window_group_class_init (GtkWindowGroupClass *klass)
3814 gtk_window_group_get_type (void)
3816 static GtkType window_group_type = 0;
3818 if (!window_group_type)
3820 static const GTypeInfo window_group_info =
3822 sizeof (GtkWindowGroupClass),
3823 NULL, /* base_init */
3824 NULL, /* base_finalize */
3825 (GClassInitFunc) gtk_window_group_class_init,
3826 NULL, /* class_finalize */
3827 NULL, /* class_data */
3828 sizeof (GtkWindowGroup),
3829 16, /* n_preallocs */
3830 (GInstanceInitFunc) NULL,
3833 window_group_type = g_type_register_static (G_TYPE_OBJECT, "GtkWindowGroup", &window_group_info, 0);
3836 return window_group_type;
3840 * gtk_window_group_new:
3842 * Create a new #GtkWindowGroup object. Grabs added with
3843 * gtk_window_grab_add() only affect windows within the
3844 * same #GtkWindowGroup
3849 gtk_window_group_new (void)
3851 return g_object_new (GTK_TYPE_WINDOW_GROUP, NULL);
3855 window_group_cleanup_grabs (GtkWindowGroup *group,
3859 GSList *to_remove = NULL;
3861 tmp_list = group->grabs;
3864 if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
3865 to_remove = g_slist_prepend (to_remove, g_object_ref (tmp_list->data));
3866 tmp_list = tmp_list->next;
3871 gtk_grab_remove (to_remove->data);
3872 g_object_unref (to_remove->data);
3873 to_remove = g_slist_delete_link (to_remove, to_remove);
3878 * gtk_window_group_add_widget:
3879 * @window_group: a #GtkWindowGroup
3880 * @window: the #GtkWindow to add
3882 * Add a window to a #GtkWindowGroup.
3885 gtk_window_group_add_window (GtkWindowGroup *window_group,
3888 g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
3889 g_return_if_fail (GTK_IS_WINDOW (window));
3891 if (window->group != window_group)
3893 g_object_ref (window);
3894 g_object_ref (window_group);
3897 gtk_window_group_remove_window (window->group, window);
3899 window_group_cleanup_grabs (_gtk_window_get_group (NULL), window);
3901 window->group = window_group;
3903 g_object_unref (window);
3908 * gtk_window_group_remove_window:
3909 * @window_group: a #GtkWindowGroup
3910 * @window: the #GtkWindow to remove
3912 * Removes a window from a #GtkWindowGroup.
3915 gtk_window_group_remove_window (GtkWindowGroup *window_group,
3918 g_return_if_fail (GTK_IS_WINDOW_GROUP (window_group));
3919 g_return_if_fail (GTK_IS_WIDGET (window));
3920 g_return_if_fail (window->group == window_group);
3922 g_object_ref (window);
3924 window_group_cleanup_grabs (window_group, window);
3925 window->group = NULL;
3927 g_object_unref (G_OBJECT (window_group));
3928 g_object_unref (window);
3931 /* Return the group for the window or the default group
3934 _gtk_window_get_group (GtkWindow *window)
3936 if (window && window->group)
3937 return window->group;
3940 static GtkWindowGroup *default_group = NULL;
3943 default_group = gtk_window_group_new ();
3945 return default_group;