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"
76 PROP_DESTROY_WITH_PARENT,
82 GdkGeometry geometry; /* Last set of geometry hints we set */
86 } GtkWindowLastGeometryInfo;
88 struct _GtkWindowGeometryInfo
90 /* Properties that the app has set on the window
92 GdkGeometry geometry; /* Geometry hints */
94 GtkWidget *widget; /* subwidget to which hints apply */
95 gint width; /* Default size */
97 guint may_shrink : 1; /* one-shot auto_shrink behaviour after set_default_size */
99 GtkWindowLastGeometryInfo last;
110 static void gtk_window_class_init (GtkWindowClass *klass);
111 static void gtk_window_init (GtkWindow *window);
112 static void gtk_window_shutdown (GObject *object);
113 static void gtk_window_destroy (GtkObject *object);
114 static void gtk_window_finalize (GObject *object);
115 static void gtk_window_show (GtkWidget *widget);
116 static void gtk_window_hide (GtkWidget *widget);
117 static void gtk_window_map (GtkWidget *widget);
118 static void gtk_window_unmap (GtkWidget *widget);
119 static void gtk_window_realize (GtkWidget *widget);
120 static void gtk_window_unrealize (GtkWidget *widget);
121 static void gtk_window_size_request (GtkWidget *widget,
122 GtkRequisition *requisition);
123 static void gtk_window_size_allocate (GtkWidget *widget,
124 GtkAllocation *allocation);
125 static gint gtk_window_event (GtkWidget *widget,
127 static gboolean gtk_window_frame_event (GtkWidget *widget,
129 static gint gtk_window_configure_event (GtkWidget *widget,
130 GdkEventConfigure *event);
131 static gint gtk_window_key_press_event (GtkWidget *widget,
133 static gint gtk_window_key_release_event (GtkWidget *widget,
135 static gint gtk_window_enter_notify_event (GtkWidget *widget,
136 GdkEventCrossing *event);
137 static gint gtk_window_leave_notify_event (GtkWidget *widget,
138 GdkEventCrossing *event);
139 static gint gtk_window_focus_in_event (GtkWidget *widget,
140 GdkEventFocus *event);
141 static gint gtk_window_focus_out_event (GtkWidget *widget,
142 GdkEventFocus *event);
143 static gint gtk_window_client_event (GtkWidget *widget,
144 GdkEventClient *event);
145 static void gtk_window_check_resize (GtkContainer *container);
146 static gint gtk_window_focus (GtkContainer *container,
147 GtkDirectionType direction);
148 static void gtk_window_real_set_focus (GtkWindow *window,
151 static void gtk_window_real_activate_default (GtkWindow *window);
152 static void gtk_window_real_activate_focus (GtkWindow *window);
153 static void gtk_window_move_focus (GtkWindow *window,
154 GtkDirectionType dir);
156 static void gtk_window_move_resize (GtkWindow *window);
157 static gboolean gtk_window_compare_hints (GdkGeometry *geometry_a,
159 GdkGeometry *geometry_b,
161 static void gtk_window_compute_default_size (GtkWindow *window,
164 static void gtk_window_constrain_size (GtkWindow *window,
165 GdkGeometry *geometry,
171 static void gtk_window_compute_hints (GtkWindow *window,
172 GdkGeometry *new_geometry,
174 static gint gtk_window_compute_reposition (GtkWindow *window,
180 static void gtk_window_read_rcfiles (GtkWidget *widget,
181 GdkEventClient *event);
182 static void gtk_window_paint (GtkWidget *widget,
184 static gint gtk_window_expose (GtkWidget *widget,
185 GdkEventExpose *event);
186 static void gtk_window_unset_transient_for (GtkWindow *window);
187 static void gtk_window_transient_parent_realized (GtkWidget *parent,
189 static void gtk_window_transient_parent_unrealized (GtkWidget *parent,
192 static GtkWindowGeometryInfo* gtk_window_get_geometry_info (GtkWindow *window,
196 static GSList *toplevel_list = NULL;
197 static GHashTable *mnemonic_hash_table = NULL;
198 static GtkBinClass *parent_class = NULL;
199 static guint window_signals[LAST_SIGNAL] = { 0 };
201 static void gtk_window_set_property (GObject *object,
205 static void gtk_window_get_property (GObject *object,
212 mnemonic_hash (gconstpointer key)
214 const GtkWindowMnemonic *k;
217 k = (GtkWindowMnemonic *)key;
219 h = (gulong) k->window;
220 h ^= k->keyval << 16;
221 h ^= k->keyval >> 16;
227 mnemonic_equal (gconstpointer a, gconstpointer b)
229 const GtkWindowMnemonic *ka;
230 const GtkWindowMnemonic *kb;
232 ka = (GtkWindowMnemonic *)a;
233 kb = (GtkWindowMnemonic *)b;
236 (ka->window == kb->window) &&
237 (ka->keyval == kb->keyval);
241 gtk_window_get_type (void)
243 static GtkType window_type = 0;
247 static const GtkTypeInfo window_info =
251 sizeof (GtkWindowClass),
252 (GtkClassInitFunc) gtk_window_class_init,
253 (GtkObjectInitFunc) gtk_window_init,
254 /* reserved_1 */ NULL,
255 /* reserved_2 */ NULL,
256 (GtkClassInitFunc) NULL,
259 window_type = gtk_type_unique (gtk_bin_get_type (), &window_info);
266 gtk_window_class_init (GtkWindowClass *klass)
268 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
269 GtkObjectClass *object_class;
270 GtkWidgetClass *widget_class;
271 GtkContainerClass *container_class;
272 GtkBindingSet *binding_set;
274 object_class = (GtkObjectClass*) klass;
275 widget_class = (GtkWidgetClass*) klass;
276 container_class = (GtkContainerClass*) klass;
278 parent_class = gtk_type_class (gtk_bin_get_type ());
280 gobject_class->shutdown = gtk_window_shutdown;
281 gobject_class->finalize = gtk_window_finalize;
283 gobject_class->set_property = gtk_window_set_property;
284 gobject_class->get_property = gtk_window_get_property;
286 object_class->destroy = gtk_window_destroy;
288 widget_class->show = gtk_window_show;
289 widget_class->hide = gtk_window_hide;
290 widget_class->map = gtk_window_map;
291 widget_class->unmap = gtk_window_unmap;
292 widget_class->realize = gtk_window_realize;
293 widget_class->unrealize = gtk_window_unrealize;
294 widget_class->size_request = gtk_window_size_request;
295 widget_class->size_allocate = gtk_window_size_allocate;
296 widget_class->configure_event = gtk_window_configure_event;
297 widget_class->key_press_event = gtk_window_key_press_event;
298 widget_class->key_release_event = gtk_window_key_release_event;
299 widget_class->enter_notify_event = gtk_window_enter_notify_event;
300 widget_class->leave_notify_event = gtk_window_leave_notify_event;
301 widget_class->focus_in_event = gtk_window_focus_in_event;
302 widget_class->focus_out_event = gtk_window_focus_out_event;
303 widget_class->client_event = gtk_window_client_event;
305 widget_class->expose_event = gtk_window_expose;
307 container_class->check_resize = gtk_window_check_resize;
308 container_class->focus = gtk_window_focus;
310 klass->set_focus = gtk_window_real_set_focus;
311 klass->frame_event = gtk_window_frame_event;
313 klass->activate_default = gtk_window_real_activate_default;
314 klass->activate_focus = gtk_window_real_activate_focus;
315 klass->move_focus = gtk_window_move_focus;
318 g_object_class_install_property (gobject_class,
320 g_param_spec_enum ("type",
322 _("The type of the window"),
323 GTK_TYPE_WINDOW_TYPE,
325 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
328 g_object_class_install_property (gobject_class,
330 g_param_spec_string ("title",
332 _("The title of the window"),
336 g_object_class_install_property (gobject_class,
338 g_param_spec_boolean ("auto_shrink",
340 _("If TRUE, the window automatically shrinks to its size request anytime a resize occurs. Don't use this feature, it makes no sense."),
344 g_object_class_install_property (gobject_class,
346 g_param_spec_boolean ("allow_shrink",
348 _("If TRUE, the window has no mimimum size. Don't use this feature, it makes no sense."),
352 g_object_class_install_property (gobject_class,
354 g_param_spec_boolean ("allow_grow",
356 _("If TRUE, users can expand the window beyond its minimum size."),
360 g_object_class_install_property (gobject_class,
362 g_param_spec_boolean ("modal",
364 _("If TRUE, the window is modal (other windows are not usable while this one is up)."),
368 g_object_class_install_property (gobject_class,
370 g_param_spec_enum ("window_position",
371 _("Window Position"),
372 _("The initial position of the window."),
373 GTK_TYPE_WINDOW_POSITION,
377 g_object_class_install_property (gobject_class,
379 g_param_spec_int ("default_width",
381 _("The default width of the window, or 0 to use the size request."),
387 g_object_class_install_property (gobject_class,
389 g_param_spec_int ("default_height",
391 _("The default height of the windo, or 0 to use the size request."),
397 g_object_class_install_property (gobject_class,
398 PROP_DESTROY_WITH_PARENT,
399 g_param_spec_boolean ("destroy_with_parent",
400 _("Destroy with Parent"),
401 _("If this window should be destroyed when the parent is destroyed,"),
405 /* Style props are set or not */
407 window_signals[SET_FOCUS] =
408 g_signal_newc ("set_focus",
409 G_TYPE_FROM_CLASS (object_class),
411 G_STRUCT_OFFSET (GtkWindowClass, set_focus),
413 gtk_marshal_VOID__OBJECT,
417 window_signals[FRAME_EVENT] =
418 g_signal_newc ("frame_event",
419 G_TYPE_FROM_CLASS(object_class),
421 G_STRUCT_OFFSET(GtkWindowClass, frame_event),
422 _gtk_boolean_handled_accumulator, NULL,
423 gtk_marshal_BOOLEAN__BOXED,
427 window_signals[ACTIVATE_FOCUS] =
428 g_signal_newc ("activate_focus",
429 G_OBJECT_CLASS_TYPE (object_class),
430 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
431 GTK_SIGNAL_OFFSET (GtkWindowClass, activate_focus),
433 gtk_marshal_VOID__VOID,
437 window_signals[ACTIVATE_DEFAULT] =
438 g_signal_newc ("activate_default",
439 G_OBJECT_CLASS_TYPE (object_class),
440 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
441 GTK_SIGNAL_OFFSET (GtkWindowClass, activate_default),
443 gtk_marshal_VOID__VOID,
447 window_signals[MOVE_FOCUS] =
448 g_signal_newc ("move_focus",
449 G_OBJECT_CLASS_TYPE (object_class),
450 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
451 GTK_SIGNAL_OFFSET (GtkWindowClass, move_focus),
453 gtk_marshal_VOID__ENUM,
456 GTK_TYPE_DIRECTION_TYPE);
458 if (!mnemonic_hash_table)
459 mnemonic_hash_table = g_hash_table_new (mnemonic_hash,
466 binding_set = gtk_binding_set_by_class (klass);
468 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
469 "activate_focus", 0);
471 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
472 "activate_default", 0);
474 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
475 "activate_default", 0);
477 gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
479 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_UP);
480 gtk_binding_entry_add_signal (binding_set, GDK_KP_Up, 0,
482 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_UP);
484 gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
486 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_DOWN);
487 gtk_binding_entry_add_signal (binding_set, GDK_KP_Down, 0,
489 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_DOWN);
491 gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
493 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_LEFT);
494 gtk_binding_entry_add_signal (binding_set, GDK_KP_Left, 0,
496 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_LEFT);
498 gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
500 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_RIGHT);
501 gtk_binding_entry_add_signal (binding_set, GDK_KP_Right, 0,
503 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_RIGHT);
505 gtk_binding_entry_add_signal (binding_set, GDK_Tab, 0,
507 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
508 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, 0,
510 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
512 gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_SHIFT_MASK,
514 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
515 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Left_Tab, GDK_SHIFT_MASK,
517 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
521 gtk_window_init (GtkWindow *window)
523 GTK_WIDGET_UNSET_FLAGS (window, GTK_NO_WINDOW);
524 GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
526 GTK_PRIVATE_SET_FLAG (window, GTK_ANCHORED);
528 gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);
530 window->title = NULL;
531 window->wmclass_name = g_strdup (g_get_prgname ());
532 window->wmclass_class = g_strdup (gdk_progclass);
533 window->wm_role = NULL;
534 window->geometry_info = NULL;
535 window->type = GTK_WINDOW_TOPLEVEL;
536 window->focus_widget = NULL;
537 window->default_widget = NULL;
538 window->resize_count = 0;
539 window->allow_shrink = FALSE;
540 window->allow_grow = TRUE;
541 window->auto_shrink = FALSE;
542 window->handling_resize = FALSE;
543 window->position = GTK_WIN_POS_NONE;
544 window->use_uposition = TRUE;
545 window->modal = FALSE;
546 window->frame = NULL;
547 window->has_frame = FALSE;
548 window->frame_left = 0;
549 window->frame_right = 0;
550 window->frame_top = 0;
551 window->frame_bottom = 0;
552 window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
553 window->gravity = GDK_GRAVITY_NORTH_WEST;
554 window->decorated = TRUE;
555 window->mnemonic_modifier = GDK_MOD1_MASK;
557 gtk_widget_ref (GTK_WIDGET (window));
558 gtk_object_sink (GTK_OBJECT (window));
559 window->has_user_ref_count = TRUE;
560 toplevel_list = g_slist_prepend (toplevel_list, window);
562 gtk_decorated_window_init (window);
564 gtk_signal_connect (GTK_OBJECT (window),
566 GTK_SIGNAL_FUNC (gtk_window_event),
571 gtk_window_set_property (GObject *object,
578 window = GTK_WINDOW (object);
583 window->type = g_value_get_enum (value);
586 gtk_window_set_title (window, g_value_get_string (value));
588 case PROP_AUTO_SHRINK:
589 window->auto_shrink = g_value_get_boolean (value);
590 gtk_widget_queue_resize (GTK_WIDGET (window));
592 case PROP_ALLOW_SHRINK:
593 window->allow_shrink = g_value_get_boolean (value);
594 gtk_widget_queue_resize (GTK_WIDGET (window));
596 case PROP_ALLOW_GROW:
597 window->allow_grow = g_value_get_boolean (value);
598 gtk_widget_queue_resize (GTK_WIDGET (window));
601 gtk_window_set_modal (window, g_value_get_boolean (value));
604 gtk_window_set_position (window, g_value_get_enum (value));
606 case PROP_DEFAULT_WIDTH:
607 gtk_window_set_default_size (window, g_value_get_int (value), -1);
609 case PROP_DEFAULT_HEIGHT:
610 gtk_window_set_default_size (window, -1, g_value_get_int (value));
612 case PROP_DESTROY_WITH_PARENT:
613 gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
621 gtk_window_get_property (GObject *object,
628 window = GTK_WINDOW (object);
632 GtkWindowGeometryInfo *info;
634 g_value_set_enum (value, window->type);
637 g_value_set_string (value, window->title);
639 case PROP_AUTO_SHRINK:
640 g_value_set_boolean (value, window->auto_shrink);
642 case PROP_ALLOW_SHRINK:
643 g_value_set_boolean (value, window->allow_shrink);
645 case PROP_ALLOW_GROW:
646 g_value_set_boolean (value, window->allow_grow);
649 g_value_set_boolean (value, window->modal);
652 g_value_set_enum (value, window->position);
654 case PROP_DEFAULT_WIDTH:
655 info = gtk_window_get_geometry_info (window, FALSE);
657 g_value_set_int (value, 0);
659 g_value_set_int (value, info->width);
661 case PROP_DEFAULT_HEIGHT:
662 info = gtk_window_get_geometry_info (window, FALSE);
664 g_value_set_int (value, 0);
666 g_value_set_int (value, info->height);
668 case PROP_DESTROY_WITH_PARENT:
669 g_value_set_boolean (value, window->destroy_with_parent);
672 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
679 * @type: type of window
681 * Creates a new #GtkWindow, which is a toplevel window that can
682 * contain other widgets. Nearly always, the type of the window should
683 * be #GTK_WINDOW_TOPLEVEL. If you're implementing something like a
684 * popup menu from scratch (which is a bad idea, just use #GtkMenu),
685 * you might use #GTK_WINDOW_POPUP. #GTK_WINDOW_POPUP is not for
686 * dialogs, though in some other toolkits dialogs are called "popups."
687 * In GTK+, #GTK_WINDOW_POPUP means a pop-up menu or pop-up tooltip.
688 * Popup windows are not controlled by the window manager.
690 * If you simply want an undecorated window (no window borders), use
691 * gtk_window_set_decorated(), don't use #GTK_WINDOW_POPUP.
693 * Return value: a new #GtkWindow.
696 gtk_window_new (GtkWindowType type)
700 g_return_val_if_fail (type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP, NULL);
702 window = gtk_type_new (GTK_TYPE_WINDOW);
706 return GTK_WIDGET (window);
710 * gtk_window_set_title:
711 * @window: a #GtkWindow
712 * @title: title of the window
714 * Sets the title of the #GtkWindow. The title of a window will be displayed in
715 * its title bar; on the X Window System, the title bar is rendered by the
716 * window manager, so exactly how the title appears to users may vary according
717 * to a user's exact configuration. The title should help a user distinguish
718 * this window from other windows they may have open. A good title might
719 * include the application name and current document filename, for example.
723 gtk_window_set_title (GtkWindow *window,
726 g_return_if_fail (window != NULL);
727 g_return_if_fail (GTK_IS_WINDOW (window));
730 g_free (window->title);
731 window->title = g_strdup (title);
733 if (GTK_WIDGET_REALIZED (window))
735 gdk_window_set_title (GTK_WIDGET (window)->window, window->title);
737 gtk_decorated_window_set_title (window, title);
740 g_object_notify (G_OBJECT (window), "title");
744 * gtk_window_set_wmclass:
745 * @window: a #GtkWindow
746 * @wmclass_name: window name hint
747 * @wmclass_class: window class hint
749 * Don't use this function. It sets the X Window System "class" and
750 * "name" hints for a window. According to the ICCCM, you should
751 * always set these to the same value for all windows in an
752 * application, and GTK sets them to that value by default, so calling
753 * this function is sort of pointless. However, you may want to call
754 * gtk_window_set_role() on each window in your application, for the
755 * benefit of the session manager. Setting the role allows the window
756 * manager to restore window positions when loading a saved session.
760 gtk_window_set_wmclass (GtkWindow *window,
761 const gchar *wmclass_name,
762 const gchar *wmclass_class)
764 g_return_if_fail (window != NULL);
765 g_return_if_fail (GTK_IS_WINDOW (window));
767 g_free (window->wmclass_name);
768 window->wmclass_name = g_strdup (wmclass_name);
770 g_free (window->wmclass_class);
771 window->wmclass_class = g_strdup (wmclass_class);
773 if (GTK_WIDGET_REALIZED (window))
774 g_warning ("gtk_window_set_wmclass: shouldn't set wmclass after window is realized!\n");
778 * gtk_window_set_role:
779 * @window: a #GtkWindow
780 * @role: unique identifier for the window to be used when restoring a session
782 * In combination with the window title, the window role allows a
783 * window manager to identify "the same" window when an application is
784 * restarted. So for example you might set the "toolbox" role on your
785 * app's toolbox window, so that when the user restarts their session,
786 * the window manager can put the toolbox back in the same place.
788 * If a window already has a unique title, you don't need to set the
789 * role, since the WM can use the title to identify the window when
790 * restoring the session.
794 gtk_window_set_role (GtkWindow *window,
797 g_return_if_fail (GTK_IS_WINDOW (window));
799 if (role == window->wm_role)
802 g_free (window->wm_role);
803 window->wm_role = g_strdup (role);
805 if (GTK_WIDGET_REALIZED (window))
806 g_warning ("gtk_window_set_role(): shouldn't set role after window is realized!\n");
810 * gtk_window_set_focus:
811 * @window: a #GtkWindow
812 * @focus: widget to be the new focus widget
814 * If @focus is not the current focus widget, and is focusable, emits
815 * the "set_focus" signal to set @focus as the focus widget for the
816 * window. This function is more or less GTK-internal; to focus an
817 * entry widget or the like, you should use gtk_widget_grab_focus()
818 * instead of this function.
822 gtk_window_set_focus (GtkWindow *window,
825 g_return_if_fail (window != NULL);
826 g_return_if_fail (GTK_IS_WINDOW (window));
829 g_return_if_fail (GTK_IS_WIDGET (focus));
830 g_return_if_fail (GTK_WIDGET_CAN_FOCUS (focus));
833 if ((window->focus_widget != focus) ||
834 (focus && !GTK_WIDGET_HAS_FOCUS (focus)))
835 gtk_signal_emit (GTK_OBJECT (window), window_signals[SET_FOCUS], focus);
839 * gtk_window_set_default:
840 * @window: a #GtkWindow
841 * @default_widget: widget to be the default
843 * The default widget is the widget that's activated when the user
844 * presses Enter in a dialog (for example). This function tells a
845 * #GtkWindow about the current default widget; it's really a GTK
846 * internal function and you shouldn't need it. Instead, to change the
847 * default widget, first set the #GTK_CAN_DEFAULT flag on the widget
848 * you'd like to make the default using GTK_WIDGET_SET_FLAGS(), then
849 * call gtk_widget_grab_default() to move the default.
853 gtk_window_set_default (GtkWindow *window,
854 GtkWidget *default_widget)
856 g_return_if_fail (window != NULL);
857 g_return_if_fail (GTK_IS_WINDOW (window));
860 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (default_widget));
862 if (window->default_widget != default_widget)
864 if (window->default_widget)
866 if (window->focus_widget != window->default_widget ||
867 !GTK_WIDGET_RECEIVES_DEFAULT (window->default_widget))
868 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
869 gtk_widget_queue_draw (window->default_widget);
872 window->default_widget = default_widget;
874 if (window->default_widget)
876 if (window->focus_widget == NULL ||
877 !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))
878 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
879 gtk_widget_queue_draw (window->default_widget);
885 gtk_window_set_policy (GtkWindow *window,
886 gboolean allow_shrink,
888 gboolean auto_shrink)
890 g_return_if_fail (window != NULL);
891 g_return_if_fail (GTK_IS_WINDOW (window));
893 window->allow_shrink = (allow_shrink != FALSE);
894 window->allow_grow = (allow_grow != FALSE);
895 window->auto_shrink = (auto_shrink != FALSE);
897 g_object_notify (G_OBJECT (window), "allow_shrink");
898 g_object_notify (G_OBJECT (window), "allow_grow");
899 g_object_notify (G_OBJECT (window), "auto_shrink");
901 gtk_widget_queue_resize (GTK_WIDGET (window));
905 gtk_window_add_accel_group (GtkWindow *window,
906 GtkAccelGroup *accel_group)
908 g_return_if_fail (window != NULL);
909 g_return_if_fail (GTK_IS_WINDOW (window));
910 g_return_if_fail (accel_group != NULL);
912 gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
916 gtk_window_remove_accel_group (GtkWindow *window,
917 GtkAccelGroup *accel_group)
919 g_return_if_fail (window != NULL);
920 g_return_if_fail (GTK_IS_WINDOW (window));
921 g_return_if_fail (accel_group != NULL);
923 gtk_accel_group_detach (accel_group, GTK_OBJECT (window));
927 gtk_window_add_mnemonic (GtkWindow *window,
931 GtkWindowMnemonic key;
932 GtkWindowMnemonic *mnemonic;
934 g_return_if_fail (GTK_IS_WINDOW (window));
935 g_return_if_fail (GTK_IS_WIDGET (target));
939 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
943 g_return_if_fail (g_slist_find (mnemonic->targets, target) == NULL);
944 mnemonic->targets = g_slist_prepend (mnemonic->targets, target);
948 mnemonic = g_new (GtkWindowMnemonic, 1);
950 mnemonic->targets = g_slist_prepend (NULL, target);
951 g_hash_table_insert (mnemonic_hash_table, mnemonic, mnemonic);
956 gtk_window_remove_mnemonic (GtkWindow *window,
960 GtkWindowMnemonic key;
961 GtkWindowMnemonic *mnemonic;
963 g_return_if_fail (GTK_IS_WINDOW (window));
964 g_return_if_fail (GTK_IS_WIDGET (target));
968 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
970 g_return_if_fail (mnemonic && g_slist_find (mnemonic->targets, target) != NULL);
972 mnemonic->targets = g_slist_remove (mnemonic->targets, target);
973 if (mnemonic->targets == NULL)
975 g_hash_table_remove (mnemonic_hash_table, mnemonic);
981 gtk_window_mnemonic_activate (GtkWindow *window,
983 GdkModifierType modifier)
985 GtkWindowMnemonic key;
986 GtkWindowMnemonic *mnemonic;
988 GtkWidget *widget, *chosen_widget;
991 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
993 if (window->mnemonic_modifier != (modifier & gtk_accelerator_get_default_mod_mask ()))
998 mnemonic = g_hash_table_lookup (mnemonic_hash_table, &key);
1004 chosen_widget = NULL;
1005 list = mnemonic->targets;
1008 widget = GTK_WIDGET (list->data);
1010 if (GTK_WIDGET_IS_SENSITIVE (widget) &&
1011 GTK_WIDGET_MAPPED (widget))
1019 chosen_widget = widget;
1021 list = g_slist_next (list);
1026 /* For round robin we put the activated entry on
1027 * the end of the list after activation
1029 mnemonic->targets = g_slist_remove (mnemonic->targets, chosen_widget);
1030 mnemonic->targets = g_slist_append (mnemonic->targets, chosen_widget);
1032 return gtk_widget_mnemonic_activate (chosen_widget, overloaded);
1038 gtk_window_set_mnemonic_modifier (GtkWindow *window,
1039 GdkModifierType modifier)
1041 g_return_if_fail (GTK_IS_WINDOW (window));
1042 g_return_if_fail ((modifier & ~GDK_MODIFIER_MASK) == 0);
1044 window->mnemonic_modifier = modifier;
1048 gtk_window_set_position (GtkWindow *window,
1049 GtkWindowPosition position)
1051 g_return_if_fail (GTK_IS_WINDOW (window));
1053 window->position = position;
1055 g_object_notify (G_OBJECT (window), "window_position");
1059 gtk_window_activate_focus (GtkWindow *window)
1061 g_return_val_if_fail (window != NULL, FALSE);
1062 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1064 if (window->focus_widget)
1066 if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1067 gtk_widget_activate (window->focus_widget);
1075 gtk_window_activate_default (GtkWindow *window)
1077 g_return_val_if_fail (window != NULL, FALSE);
1078 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1080 if (window->default_widget && GTK_WIDGET_IS_SENSITIVE (window->default_widget) &&
1081 (!window->focus_widget || !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget)))
1083 gtk_widget_activate (window->default_widget);
1086 else if (window->focus_widget)
1088 if (GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
1089 gtk_widget_activate (window->focus_widget);
1097 * gtk_window_set_modal:
1098 * @window: a #GtkWindow
1099 * @modal: whether the window is modal
1101 * Sets a window modal or non-modal. Modal windows prevent interaction
1102 * with other windows in the same application. To keep modal dialogs
1103 * on top of main application windows, use
1104 * gtk_window_set_transient_for() to make the dialog transient for the
1105 * parent; most window managers will then disallow lowering the dialog
1111 gtk_window_set_modal (GtkWindow *window,
1114 g_return_if_fail (window != NULL);
1115 g_return_if_fail (GTK_IS_WINDOW (window));
1117 window->modal = modal != FALSE;
1119 /* adjust desired modality state */
1120 if (GTK_WIDGET_VISIBLE (window) && window->modal)
1121 gtk_grab_add (GTK_WIDGET (window));
1123 gtk_grab_remove (GTK_WIDGET (window));
1125 g_object_notify (G_OBJECT (window), "modal");
1129 * gtk_window_list_toplevels:
1131 * Returns a list of all existing toplevel windows. The widgets
1132 * in the list are not individually referenced. If you want
1133 * to iterate through the list and perform actions involving
1134 * callbacks that might destroy the widgets, you MUST call
1135 * g_list_foreach (result, (GFunc)g_object_ref, NULL) first, and
1136 * then unref all the widgets afterwards.
1138 * Return value: list of toplevel widgets
1141 gtk_window_list_toplevels (void)
1146 for (slist = toplevel_list; slist; slist = slist->next)
1147 list = g_list_prepend (list, slist->data);
1153 gtk_window_add_embedded_xid (GtkWindow *window, guint xid)
1155 GList *embedded_windows;
1157 g_return_if_fail (window != NULL);
1158 g_return_if_fail (GTK_IS_WINDOW (window));
1160 embedded_windows = gtk_object_get_data (GTK_OBJECT (window), "gtk-embedded");
1161 if (embedded_windows)
1162 gtk_object_remove_no_notify_by_id (GTK_OBJECT (window),
1163 g_quark_from_static_string ("gtk-embedded"));
1164 embedded_windows = g_list_prepend (embedded_windows,
1165 GUINT_TO_POINTER (xid));
1167 gtk_object_set_data_full (GTK_OBJECT (window), "gtk-embedded",
1170 (GtkDestroyNotify) g_list_free : NULL);
1174 gtk_window_remove_embedded_xid (GtkWindow *window, guint xid)
1176 GList *embedded_windows;
1179 g_return_if_fail (window != NULL);
1180 g_return_if_fail (GTK_IS_WINDOW (window));
1182 embedded_windows = gtk_object_get_data (GTK_OBJECT (window), "gtk-embedded");
1183 if (embedded_windows)
1184 gtk_object_remove_no_notify_by_id (GTK_OBJECT (window),
1185 g_quark_from_static_string ("gtk-embedded"));
1187 node = g_list_find (embedded_windows, GUINT_TO_POINTER (xid));
1190 embedded_windows = g_list_remove_link (embedded_windows, node);
1191 g_list_free_1 (node);
1194 gtk_object_set_data_full (GTK_OBJECT (window),
1195 "gtk-embedded", embedded_windows,
1197 (GtkDestroyNotify) g_list_free : NULL);
1201 _gtk_window_reposition (GtkWindow *window,
1205 GtkWindowGeometryInfo *info;
1207 g_return_if_fail (window != NULL);
1208 g_return_if_fail (GTK_IS_WINDOW (window));
1210 /* keep this in sync with gtk_window_compute_reposition()
1212 if (GTK_WIDGET_REALIZED (window))
1214 info = gtk_window_get_geometry_info (window, TRUE);
1216 if (!(info->last.flags & GDK_HINT_POS))
1218 info->last.flags |= GDK_HINT_POS;
1219 gdk_window_set_geometry_hints (GTK_WIDGET (window)->window,
1220 &info->last.geometry,
1225 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
1227 gdk_window_move (GTK_WIDGET (window)->window, x, y);
1232 gtk_window_shutdown (GObject *object)
1236 g_return_if_fail (GTK_IS_WINDOW (object));
1238 window = GTK_WINDOW (object);
1240 gtk_window_set_focus (window, NULL);
1241 gtk_window_set_default (window, NULL);
1243 G_OBJECT_CLASS (parent_class)->shutdown (object);
1247 parent_destroyed_callback (GtkWindow *parent, GtkWindow *child)
1249 gtk_widget_destroy (GTK_WIDGET (child));
1253 connect_parent_destroyed (GtkWindow *window)
1255 if (window->transient_parent)
1257 gtk_signal_connect (GTK_OBJECT (window->transient_parent),
1259 GTK_SIGNAL_FUNC (parent_destroyed_callback),
1265 disconnect_parent_destroyed (GtkWindow *window)
1267 if (window->transient_parent)
1269 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1270 GTK_SIGNAL_FUNC (parent_destroyed_callback),
1276 gtk_window_transient_parent_realized (GtkWidget *parent,
1279 if (GTK_WIDGET_REALIZED (window))
1280 gdk_window_set_transient_for (window->window, parent->window);
1284 gtk_window_transient_parent_unrealized (GtkWidget *parent,
1287 if (GTK_WIDGET_REALIZED (window))
1288 gdk_property_delete (window->window,
1289 gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE));
1293 gtk_window_unset_transient_for (GtkWindow *window)
1295 if (window->transient_parent)
1297 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1298 GTK_SIGNAL_FUNC (gtk_window_transient_parent_realized),
1300 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1301 GTK_SIGNAL_FUNC (gtk_window_transient_parent_unrealized),
1303 gtk_signal_disconnect_by_func (GTK_OBJECT (window->transient_parent),
1304 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1305 &window->transient_parent);
1307 if (window->destroy_with_parent)
1308 disconnect_parent_destroyed (window);
1310 window->transient_parent = NULL;
1315 * gtk_window_set_transient_for:
1316 * @window: a #GtkWindow
1317 * @parent: parent window
1319 * Dialog windows should be set transient for the main application
1320 * window they were spawned from. This allows window managers to
1321 * e.g. keep the dialog on top of the main window, or center the
1322 * dialog over the main window. gtk_dialog_new_with_buttons() and
1323 * other convenience functions in GTK+ will sometimes call
1324 * gtk_window_set_transient_for() on your behalf.
1328 gtk_window_set_transient_for (GtkWindow *window,
1331 g_return_if_fail (GTK_IS_WINDOW (window));
1332 g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
1333 g_return_if_fail (window != parent);
1336 if (window->transient_parent)
1338 if (GTK_WIDGET_REALIZED (window) &&
1339 GTK_WIDGET_REALIZED (window->transient_parent) &&
1340 (!parent || !GTK_WIDGET_REALIZED (parent)))
1341 gtk_window_transient_parent_unrealized (GTK_WIDGET (window->transient_parent),
1342 GTK_WIDGET (window));
1344 gtk_window_unset_transient_for (window);
1347 window->transient_parent = parent;
1351 gtk_signal_connect (GTK_OBJECT (parent), "destroy",
1352 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1353 &window->transient_parent);
1354 gtk_signal_connect (GTK_OBJECT (parent), "realize",
1355 GTK_SIGNAL_FUNC (gtk_window_transient_parent_realized),
1357 gtk_signal_connect (GTK_OBJECT (parent), "unrealize",
1358 GTK_SIGNAL_FUNC (gtk_window_transient_parent_unrealized),
1361 if (window->destroy_with_parent)
1362 connect_parent_destroyed (window);
1364 if (GTK_WIDGET_REALIZED (window) &&
1365 GTK_WIDGET_REALIZED (parent))
1366 gtk_window_transient_parent_realized (GTK_WIDGET (parent),
1367 GTK_WIDGET (window));
1372 * gtk_window_set_type_hint:
1373 * @window: a #GtkWindow
1374 * @hint: the window type
1376 * By setting the type hint for the window, you allow the window
1377 * manager to decorate and handle the window in a way which is
1378 * suitable to the function of the window in your application.
1380 * This function should be called before the window becomes visible.
1382 * gtk_dialog_new_with_buttons() and other convenience functions in GTK+
1383 * will sometimes call gtk_window_set_type_hint() on your behalf.
1387 gtk_window_set_type_hint (GtkWindow *window,
1388 GdkWindowTypeHint hint)
1390 g_return_if_fail (GTK_IS_WINDOW (window));
1391 g_return_if_fail (!GTK_WIDGET_VISIBLE (window));
1392 window->type_hint = hint;
1396 * gtk_window_set_destroy_with_parent:
1397 * @window: a #GtkWindow
1398 * @setting: whether to destroy @window with its transient parent
1400 * If @setting is TRUE, then destroying the transient parent of @window
1401 * will also destroy @window itself. This is useful for dialogs that
1402 * shouldn't persist beyond the lifetime of the main window they're
1403 * associated with, for example.
1406 gtk_window_set_destroy_with_parent (GtkWindow *window,
1409 g_return_if_fail (GTK_IS_WINDOW (window));
1411 if (window->destroy_with_parent == (setting != FALSE))
1414 if (window->destroy_with_parent)
1416 disconnect_parent_destroyed (window);
1420 connect_parent_destroyed (window);
1423 window->destroy_with_parent = setting;
1425 g_object_notify (G_OBJECT (window), "destroy_with_parent");
1428 static GtkWindowGeometryInfo*
1429 gtk_window_get_geometry_info (GtkWindow *window,
1432 GtkWindowGeometryInfo *info;
1434 info = window->geometry_info;
1435 if (!info && create)
1437 info = g_new0 (GtkWindowGeometryInfo, 1);
1441 info->last.width = -1;
1442 info->last.height = -1;
1443 info->widget = NULL;
1445 info->may_shrink = FALSE;
1446 window->geometry_info = info;
1453 * gtk_window_set_geometry_hints:
1454 * @window: a #GdkWindow
1455 * @geometry_widget: widget the geometry hints will be applied to
1456 * @geometry: struct containing geometry information
1457 * @geom_mask: mask indicating which struct fields should be paid attention to
1459 * This function sets up hints about how a window can be resized by
1460 * the user. You can set a minimum and maximum size; allowed resize
1461 * increments (e.g. for xterm, you can only resize by the size of a
1462 * character); aspect ratios; and more. See the #GdkGeometry struct.
1466 gtk_window_set_geometry_hints (GtkWindow *window,
1467 GtkWidget *geometry_widget,
1468 GdkGeometry *geometry,
1469 GdkWindowHints geom_mask)
1471 GtkWindowGeometryInfo *info;
1473 g_return_if_fail (window != NULL);
1475 info = gtk_window_get_geometry_info (window, TRUE);
1478 gtk_signal_disconnect_by_func (GTK_OBJECT (info->widget),
1479 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1482 info->widget = geometry_widget;
1484 gtk_signal_connect (GTK_OBJECT (geometry_widget), "destroy",
1485 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1489 info->geometry = *geometry;
1491 info->mask = geom_mask;
1493 gtk_widget_queue_resize (GTK_WIDGET (window));
1497 * gtk_window_set_decorated:
1498 * @window: a #GtkWindow
1499 * @setting: %TRUE to decorate the window
1501 * By default, windows are decorated with a title bar, resize
1502 * controls, etc. Some window managers allow GTK+ to disable these
1503 * decorations, creating a borderless window. If you set the decorated
1504 * property to %FALSE using this function, GTK+ will do its best to
1505 * convince the window manager not to decorate the window.
1509 gtk_window_set_decorated (GtkWindow *window,
1512 g_return_if_fail (GTK_IS_WINDOW (window));
1514 setting = setting != FALSE;
1516 if (setting == window->decorated)
1519 if (GTK_WIDGET (window)->window)
1521 if (window->decorated)
1522 gdk_window_set_decorations (GTK_WIDGET (window)->window,
1525 gdk_window_set_decorations (GTK_WIDGET (window)->window,
1531 * gtk_window_set_default_size:
1532 * @window: a #GtkWindow
1533 * @width: width in pixels, 0 to unset, or -1 to leave the width unchanged
1534 * @height: height in pixels, 0 to unset, or -1 to leave the height unchanged
1536 * Sets the default size of a window. If the window's "natural" size
1537 * (its size request) is larger than the default, the default will be
1538 * ignored. So the default size is a minimum initial size. Unlike
1539 * gtk_widget_set_usize(), which sets a size request for a widget and
1540 * thus would keep users from shrinking the window, this function only
1541 * sets the initial size, just as if the user had resized the window
1542 * themselves. Users can still shrink the window again as they
1543 * normally would. Setting a default size of 0 means to use the
1544 * "natural" default size (the size request of the window).
1546 * For more control over a window's initial size and how resizing works,
1547 * investigate gtk_window_set_geometry_hints().
1549 * A useful feature: if you set the "geometry widget" via
1550 * gtk_window_set_geometry_hints(), the default size specified by
1551 * gtk_window_set_default_size() will be the default size of that
1552 * widget, not of the entire window.
1556 gtk_window_set_default_size (GtkWindow *window,
1560 GtkWindowGeometryInfo *info;
1562 g_return_if_fail (GTK_IS_WINDOW (window));
1564 info = gtk_window_get_geometry_info (window, TRUE);
1566 g_object_freeze_notify (G_OBJECT (window));
1569 info->width = width;
1570 g_object_notify (G_OBJECT (window), "default_width");
1571 info->may_shrink = TRUE;
1575 info->height = height;
1576 g_object_notify (G_OBJECT (window), "default_height");
1577 info->may_shrink = TRUE;
1579 g_object_thaw_notify (G_OBJECT (window));
1581 gtk_widget_queue_resize (GTK_WIDGET (window));
1585 gtk_window_destroy (GtkObject *object)
1589 g_return_if_fail (GTK_IS_WINDOW (object));
1591 window = GTK_WINDOW (object);
1593 if (window->transient_parent)
1594 gtk_window_set_transient_for (window, NULL);
1596 if (window->has_user_ref_count)
1598 window->has_user_ref_count = FALSE;
1599 gtk_widget_unref (GTK_WIDGET (window));
1602 GTK_OBJECT_CLASS (parent_class)->destroy (object);
1606 gtk_window_mnemonic_hash_remove (gpointer key,
1610 GtkWindowMnemonic *mnemonic = key;
1611 GtkWindow *window = user;
1613 if (mnemonic->window == window)
1615 if (mnemonic->targets)
1617 gchar *name = gtk_accelerator_name (mnemonic->keyval, 0);
1619 g_warning ("mnemonic \"%s\" wasn't removed for widget (%p)",
1620 name, mnemonic->targets->data);
1623 g_slist_free (mnemonic->targets);
1632 gtk_window_finalize (GObject *object)
1636 g_return_if_fail (GTK_IS_WINDOW (object));
1638 window = GTK_WINDOW (object);
1640 toplevel_list = g_slist_remove (toplevel_list, window);
1642 g_free (window->title);
1643 g_free (window->wmclass_name);
1644 g_free (window->wmclass_class);
1645 g_free (window->wm_role);
1647 g_hash_table_foreach_remove (mnemonic_hash_table,
1648 gtk_window_mnemonic_hash_remove,
1650 if (window->geometry_info)
1652 if (window->geometry_info->widget)
1653 gtk_signal_disconnect_by_func (GTK_OBJECT (window->geometry_info->widget),
1654 GTK_SIGNAL_FUNC (gtk_widget_destroyed),
1655 &window->geometry_info->widget);
1656 g_free (window->geometry_info);
1659 G_OBJECT_CLASS (parent_class)->finalize (object);
1663 gtk_window_show (GtkWidget *widget)
1665 GtkWindow *window = GTK_WINDOW (widget);
1666 GtkContainer *container = GTK_CONTAINER (window);
1667 gboolean need_resize;
1669 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1671 need_resize = container->need_resize || !GTK_WIDGET_REALIZED (widget);
1672 container->need_resize = FALSE;
1676 GtkWindowGeometryInfo *info = gtk_window_get_geometry_info (window, TRUE);
1677 GtkAllocation allocation = { 0, 0 };
1678 GdkGeometry new_geometry;
1679 guint width, height, new_flags;
1680 gboolean was_realized;
1682 /* determine default size to initially show the window with */
1683 gtk_widget_size_request (widget, NULL);
1684 gtk_window_compute_default_size (window, &width, &height);
1686 /* save away the last default size for later comparisions */
1687 info->last.width = width;
1688 info->last.height = height;
1690 /* constrain size to geometry */
1691 gtk_window_compute_hints (window, &new_geometry, &new_flags);
1692 gtk_window_constrain_size (window,
1693 &new_geometry, new_flags,
1697 /* and allocate the window */
1698 allocation.width = width;
1699 allocation.height = height;
1700 gtk_widget_size_allocate (widget, &allocation);
1702 was_realized = FALSE;
1703 if (!GTK_WIDGET_REALIZED (widget))
1705 gtk_widget_realize (widget);
1706 was_realized = TRUE;;
1709 /* Must be done after the windows are realized,
1710 * so that the decorations can be read
1712 gtk_decorated_window_calculate_frame_size (window);
1715 gdk_window_resize (widget->window, width, height);
1718 gtk_container_check_resize (container);
1720 gtk_widget_map (widget);
1723 gtk_grab_add (widget);
1727 gtk_window_hide (GtkWidget *widget)
1731 g_return_if_fail (widget != NULL);
1732 g_return_if_fail (GTK_IS_WINDOW (widget));
1734 window = GTK_WINDOW (widget);
1736 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1737 gtk_widget_unmap (widget);
1740 gtk_grab_remove (widget);
1744 gtk_window_map (GtkWidget *widget)
1747 GdkWindow *toplevel;
1749 g_return_if_fail (widget != NULL);
1750 g_return_if_fail (GTK_IS_WINDOW (widget));
1752 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1754 window = GTK_WINDOW (widget);
1756 if (window->bin.child &&
1757 GTK_WIDGET_VISIBLE (window->bin.child) &&
1758 !GTK_WIDGET_MAPPED (window->bin.child))
1759 gtk_widget_map (window->bin.child);
1762 toplevel = window->frame;
1764 toplevel = widget->window;
1766 if (window->maximize_initially)
1767 gdk_window_maximize (toplevel);
1769 gdk_window_unmaximize (toplevel);
1771 if (window->stick_initially)
1772 gdk_window_stick (toplevel);
1774 gdk_window_unstick (toplevel);
1776 if (window->iconify_initially)
1777 gdk_window_iconify (toplevel);
1779 gdk_window_deiconify (toplevel);
1781 gdk_window_show (widget->window);
1784 gdk_window_show (window->frame);
1788 gtk_window_unmap (GtkWidget *widget)
1792 g_return_if_fail (widget != NULL);
1793 g_return_if_fail (GTK_IS_WINDOW (widget));
1795 window = GTK_WINDOW (widget);
1797 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1799 gdk_window_withdraw (window->frame);
1801 gdk_window_withdraw (widget->window);
1803 window->use_uposition = TRUE;
1804 window->resize_count = 0;
1805 window->handling_resize = FALSE;
1810 gtk_window_realize (GtkWidget *widget)
1813 GdkWindow *parent_window;
1814 GdkWindowAttr attributes;
1815 gint attributes_mask;
1817 g_return_if_fail (GTK_IS_WINDOW (widget));
1819 window = GTK_WINDOW (widget);
1821 /* ensure widget tree is properly size allocated */
1822 if (widget->allocation.x == -1 &&
1823 widget->allocation.y == -1 &&
1824 widget->allocation.width == 1 &&
1825 widget->allocation.height == 1)
1827 GtkRequisition requisition;
1828 GtkAllocation allocation = { 0, 0, 200, 200 };
1830 gtk_widget_size_request (widget, &requisition);
1831 if (requisition.width || requisition.height)
1833 /* non-empty window */
1834 allocation.width = requisition.width;
1835 allocation.height = requisition.height;
1837 gtk_widget_size_allocate (widget, &allocation);
1839 gtk_container_queue_resize (GTK_CONTAINER (widget));
1841 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
1844 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1846 switch (window->type)
1848 case GTK_WINDOW_TOPLEVEL:
1849 attributes.window_type = GDK_WINDOW_TOPLEVEL;
1851 case GTK_WINDOW_POPUP:
1852 attributes.window_type = GDK_WINDOW_TEMP;
1855 g_warning (G_STRLOC": Unknown window type %d!", window->type);
1859 attributes.title = window->title;
1860 attributes.wmclass_name = window->wmclass_name;
1861 attributes.wmclass_class = window->wmclass_class;
1862 attributes.wclass = GDK_INPUT_OUTPUT;
1863 attributes.visual = gtk_widget_get_visual (widget);
1864 attributes.colormap = gtk_widget_get_colormap (widget);
1866 if (window->has_frame)
1868 attributes.width = widget->allocation.width + window->frame_left + window->frame_right;
1869 attributes.height = widget->allocation.height + window->frame_top + window->frame_bottom;
1870 attributes.event_mask = (GDK_EXPOSURE_MASK |
1871 GDK_KEY_PRESS_MASK |
1872 GDK_ENTER_NOTIFY_MASK |
1873 GDK_LEAVE_NOTIFY_MASK |
1874 GDK_FOCUS_CHANGE_MASK |
1875 GDK_STRUCTURE_MASK |
1876 GDK_BUTTON_MOTION_MASK |
1877 GDK_POINTER_MOTION_HINT_MASK |
1878 GDK_BUTTON_PRESS_MASK |
1879 GDK_BUTTON_RELEASE_MASK);
1881 attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
1883 window->frame = gdk_window_new (NULL, &attributes, attributes_mask);
1884 gdk_window_set_user_data (window->frame, widget);
1886 attributes.window_type = GDK_WINDOW_CHILD;
1887 attributes.x = window->frame_left;
1888 attributes.y = window->frame_right;
1890 attributes_mask = GDK_WA_X | GDK_WA_Y;
1892 parent_window = window->frame;
1896 attributes_mask = 0;
1897 parent_window = NULL;
1900 attributes.width = widget->allocation.width;
1901 attributes.height = widget->allocation.height;
1902 attributes.event_mask = gtk_widget_get_events (widget);
1903 attributes.event_mask |= (GDK_EXPOSURE_MASK |
1904 GDK_KEY_PRESS_MASK |
1905 GDK_ENTER_NOTIFY_MASK |
1906 GDK_LEAVE_NOTIFY_MASK |
1907 GDK_FOCUS_CHANGE_MASK |
1908 GDK_STRUCTURE_MASK);
1910 attributes_mask |= GDK_WA_VISUAL | GDK_WA_COLORMAP;
1911 attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
1912 attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
1913 widget->window = gdk_window_new (parent_window, &attributes, attributes_mask);
1914 gdk_window_set_user_data (widget->window, window);
1916 widget->style = gtk_style_attach (widget->style, widget->window);
1917 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
1919 gtk_style_set_background (widget->style, window->frame, GTK_STATE_NORMAL);
1921 /* This is a bad hack to set the window background. */
1922 gtk_window_paint (widget, NULL);
1924 if (window->transient_parent &&
1925 GTK_WIDGET_REALIZED (window->transient_parent))
1926 gdk_window_set_transient_for (widget->window,
1927 GTK_WIDGET (window->transient_parent)->window);
1929 if (window->wm_role)
1930 gdk_window_set_role (widget->window, window->wm_role);
1932 if (!window->decorated)
1933 gdk_window_set_decorations (widget->window, 0);
1935 gdk_window_set_type_hint (widget->window, window->type_hint);
1937 /* transient_for must be set to allow the modal hint */
1938 if (window->transient_parent && window->modal)
1939 gdk_window_set_modal_hint (widget->window, TRUE);
1941 gdk_window_set_modal_hint (widget->window, FALSE);
1945 gtk_window_unrealize (GtkWidget *widget)
1949 g_return_if_fail (widget != NULL);
1950 g_return_if_fail (GTK_IS_WINDOW (widget));
1952 window = GTK_WINDOW (widget);
1956 gdk_window_set_user_data (window->frame, NULL);
1957 gdk_window_destroy (window->frame);
1958 window->frame = NULL;
1961 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1965 gtk_window_size_request (GtkWidget *widget,
1966 GtkRequisition *requisition)
1971 g_return_if_fail (widget != NULL);
1972 g_return_if_fail (GTK_IS_WINDOW (widget));
1973 g_return_if_fail (requisition != NULL);
1975 window = GTK_WINDOW (widget);
1976 bin = GTK_BIN (window);
1978 requisition->width = GTK_CONTAINER (window)->border_width * 2;
1979 requisition->height = GTK_CONTAINER (window)->border_width * 2;
1981 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1983 GtkRequisition child_requisition;
1985 gtk_widget_size_request (bin->child, &child_requisition);
1987 requisition->width += child_requisition.width;
1988 requisition->height += child_requisition.height;
1993 gtk_window_size_allocate (GtkWidget *widget,
1994 GtkAllocation *allocation)
1997 GtkAllocation child_allocation;
1999 g_return_if_fail (widget != NULL);
2000 g_return_if_fail (GTK_IS_WINDOW (widget));
2001 g_return_if_fail (allocation != NULL);
2003 window = GTK_WINDOW (widget);
2004 widget->allocation = *allocation;
2006 if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child))
2008 child_allocation.x = GTK_CONTAINER (window)->border_width;
2009 child_allocation.y = GTK_CONTAINER (window)->border_width;
2010 child_allocation.width =
2011 MAX (1, (gint)allocation->width - child_allocation.x * 2);
2012 child_allocation.height =
2013 MAX (1, (gint)allocation->height - child_allocation.y * 2);
2015 gtk_widget_size_allocate (window->bin.child, &child_allocation);
2018 if (GTK_WIDGET_REALIZED (widget) && window->frame)
2020 gdk_window_resize (window->frame,
2021 allocation->width + window->frame_left + window->frame_right,
2022 allocation->height + window->frame_top + window->frame_bottom);
2027 gtk_window_event (GtkWidget *widget, GdkEvent *event)
2030 gboolean return_val;
2033 g_return_val_if_fail (widget != NULL, FALSE);
2034 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2035 g_return_val_if_fail (event != NULL, FALSE);
2037 window = GTK_WINDOW (widget);
2039 if (window->frame && (event->any.window == window->frame))
2041 if ((event->type != GDK_KEY_PRESS) &&
2042 (event->type != GDK_KEY_RELEASE) &&
2043 (event->type != GDK_FOCUS_CHANGE))
2045 gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "event");
2047 gtk_signal_emit (GTK_OBJECT (widget), window_signals[FRAME_EVENT], event, &return_val);
2052 g_object_unref (event->any.window);
2053 event->any.window = g_object_ref (widget->window);
2061 gtk_window_frame_event (GtkWidget *widget, GdkEvent *event)
2063 GdkEventConfigure *configure_event;
2064 GtkWindow *window = GTK_WINDOW (widget);
2067 switch (event->type)
2070 configure_event = (GdkEventConfigure *)event;
2072 /* Invalidate the decorations */
2075 rect.width = configure_event->width;
2076 rect.height = configure_event->height;
2078 gdk_window_invalidate_rect (window->frame, &rect, FALSE);
2080 /* Pass on the (modified) configure event */
2081 configure_event->width -= window->frame_left + window->frame_right;
2082 configure_event->height -= window->frame_top + window->frame_bottom;
2083 return gtk_window_configure_event (widget, configure_event);
2092 gtk_window_configure_event (GtkWidget *widget,
2093 GdkEventConfigure *event)
2097 g_return_val_if_fail (widget != NULL, FALSE);
2098 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2099 g_return_val_if_fail (event != NULL, FALSE);
2101 window = GTK_WINDOW (widget);
2103 /* we got a configure event specifying the new window size and position,
2104 * in principle we have to distinguish 4 cases here:
2105 * 1) the size didn't change and resize_count == 0
2106 * -> the window was merely moved (sometimes not even that)
2107 * 2) the size didn't change and resize_count > 0
2108 * -> we requested a new size, but didn't get it
2109 * 3) the size changed and resize_count > 0
2110 * -> we asked for a new size and we got one
2111 * 4) the size changed and resize_count == 0
2112 * -> we got resized from outside the toolkit, and have to
2113 * accept that size since we don't want to fight neither the
2114 * window manager nor the user
2115 * in the three latter cases we have to reallocate the widget tree,
2116 * which happens in gtk_window_move_resize(), so we set a flag for
2117 * that function and assign the new size. if resize_count > 1,
2118 * we simply do nothing and wait for more configure events.
2121 if (window->resize_count > 0 ||
2122 widget->allocation.width != event->width ||
2123 widget->allocation.height != event->height)
2125 if (window->resize_count > 0)
2126 window->resize_count -= 1;
2128 if (window->resize_count == 0)
2130 window->handling_resize = TRUE;
2132 widget->allocation.width = event->width;
2133 widget->allocation.height = event->height;
2135 gtk_widget_queue_resize (widget);
2143 gtk_window_key_press_event (GtkWidget *widget,
2149 g_return_val_if_fail (widget != NULL, FALSE);
2150 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2151 g_return_val_if_fail (event != NULL, FALSE);
2153 window = GTK_WINDOW (widget);
2157 if (window->focus_widget && window->focus_widget != widget &&
2158 GTK_WIDGET_IS_SENSITIVE (window->focus_widget))
2159 handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
2162 handled = gtk_window_mnemonic_activate (window,
2167 handled = gtk_accel_groups_activate (GTK_OBJECT (window), event->keyval, event->state);
2169 /* Chain up, invokes binding set */
2170 if (!handled && GTK_WIDGET_CLASS (parent_class)->key_press_event)
2171 handled = GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event);
2178 gtk_window_real_activate_default (GtkWindow *window)
2180 gtk_window_activate_default (window);
2184 gtk_window_real_activate_focus (GtkWindow *window)
2186 gtk_window_activate_focus (window);
2190 gtk_window_move_focus (GtkWindow *window,
2191 GtkDirectionType dir)
2193 gtk_container_focus (GTK_CONTAINER (window), dir);
2195 if (!GTK_CONTAINER (window)->focus_child)
2196 gtk_window_set_focus (window, NULL);
2200 gtk_window_key_release_event (GtkWidget *widget,
2206 g_return_val_if_fail (widget != NULL, FALSE);
2207 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2208 g_return_val_if_fail (event != NULL, FALSE);
2210 window = GTK_WINDOW (widget);
2212 if (window->focus_widget &&
2213 window->focus_widget != widget &&
2214 GTK_WIDGET_SENSITIVE (window->focus_widget))
2216 handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
2219 if (!handled && GTK_WIDGET_CLASS (parent_class)->key_release_event)
2220 handled = GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event);
2226 gtk_window_enter_notify_event (GtkWidget *widget,
2227 GdkEventCrossing *event)
2229 g_return_val_if_fail (widget != NULL, FALSE);
2230 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2231 g_return_val_if_fail (event != NULL, FALSE);
2237 gtk_window_leave_notify_event (GtkWidget *widget,
2238 GdkEventCrossing *event)
2240 g_return_val_if_fail (widget != NULL, FALSE);
2241 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2242 g_return_val_if_fail (event != NULL, FALSE);
2248 gtk_window_focus_in_event (GtkWidget *widget,
2249 GdkEventFocus *event)
2252 GdkEventFocus fevent;
2254 g_return_val_if_fail (widget != NULL, FALSE);
2255 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2256 g_return_val_if_fail (event != NULL, FALSE);
2258 /* It appears spurious focus in events can occur when
2259 * the window is hidden. So we'll just check to see if
2260 * the window is visible before actually handling the
2263 if (GTK_WIDGET_VISIBLE (widget))
2265 window = GTK_WINDOW (widget);
2266 if (window->focus_widget &&
2267 window->focus_widget != widget &&
2268 !GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2270 fevent.type = GDK_FOCUS_CHANGE;
2271 fevent.window = window->focus_widget->window;
2274 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2282 gtk_window_focus_out_event (GtkWidget *widget,
2283 GdkEventFocus *event)
2286 GdkEventFocus fevent;
2288 g_return_val_if_fail (widget != NULL, FALSE);
2289 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2290 g_return_val_if_fail (event != NULL, FALSE);
2292 window = GTK_WINDOW (widget);
2293 if (window->focus_widget &&
2294 window->focus_widget != widget &&
2295 GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2297 fevent.type = GDK_FOCUS_CHANGE;
2298 fevent.window = window->focus_widget->window;
2301 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2307 static GdkAtom atom_rcfiles = GDK_NONE;
2310 gtk_window_read_rcfiles (GtkWidget *widget,
2311 GdkEventClient *event)
2313 GList *embedded_windows;
2315 embedded_windows = gtk_object_get_data (GTK_OBJECT (widget), "gtk-embedded");
2316 if (embedded_windows)
2321 for(i = 0; i < 5; i++)
2323 sev.data_format = 32;
2324 sev.message_type = atom_rcfiles;
2326 while (embedded_windows)
2328 guint xid = GPOINTER_TO_UINT (embedded_windows->data);
2329 gdk_event_send_client_message ((GdkEvent *) &sev, xid);
2330 embedded_windows = embedded_windows->next;
2334 if (gtk_rc_reparse_all ())
2336 /* If the above returned true, some of our RC files are out
2337 * of date, so we need to reset all our widgets. Our other
2338 * toplevel windows will also get the message, but by
2339 * then, the RC file will up to date, so we have to tell
2340 * them now. Also, we have to invalidate cached icons in
2341 * icon sets so they get re-rendered.
2343 GList *list, *toplevels;
2345 _gtk_icon_set_invalidate_caches ();
2347 toplevels = gtk_window_list_toplevels ();
2348 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
2350 for (list = toplevels; list; list = list->next)
2352 gtk_widget_reset_rc_styles (list->data);
2353 gtk_widget_unref (list->data);
2355 g_list_free (toplevels);
2360 gtk_window_client_event (GtkWidget *widget,
2361 GdkEventClient *event)
2363 g_return_val_if_fail (widget != NULL, FALSE);
2364 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2365 g_return_val_if_fail (event != NULL, FALSE);
2368 atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
2370 if(event->message_type == atom_rcfiles)
2371 gtk_window_read_rcfiles (widget, event);
2377 gtk_window_check_resize (GtkContainer *container)
2381 g_return_if_fail (container != NULL);
2382 g_return_if_fail (GTK_IS_WINDOW (container));
2384 window = GTK_WINDOW (container);
2386 if (GTK_WIDGET_VISIBLE (container))
2387 gtk_window_move_resize (window);
2391 gtk_window_focus (GtkContainer *container,
2392 GtkDirectionType direction)
2394 GtkBin *bin = GTK_BIN (container);
2395 GtkWindow *window = GTK_WINDOW (container);
2396 GtkWidget *old_focus_child = container->focus_child;
2399 /* We need a special implementation here to deal properly with wrapping
2400 * around in the tab chain without the danger of going into an
2403 if (old_focus_child)
2405 if (GTK_IS_CONTAINER (old_focus_child) &&
2406 GTK_WIDGET_DRAWABLE (old_focus_child) &&
2407 GTK_WIDGET_IS_SENSITIVE (old_focus_child) &&
2408 gtk_container_focus (GTK_CONTAINER (old_focus_child), direction))
2412 if (window->focus_widget)
2414 /* Wrapped off the end, clear the focus setting for the toplpevel */
2415 parent = window->focus_widget->parent;
2418 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
2419 parent = GTK_WIDGET (parent)->parent;
2422 gtk_window_set_focus (GTK_WINDOW (container), NULL);
2425 /* Now try to focus the first widget in the window */
2426 if (GTK_WIDGET_DRAWABLE (bin->child) &&
2427 GTK_WIDGET_IS_SENSITIVE (bin->child))
2429 if (GTK_IS_CONTAINER (bin->child))
2431 if (gtk_container_focus (GTK_CONTAINER (bin->child), direction))
2434 else if (GTK_WIDGET_CAN_FOCUS (bin->child))
2436 gtk_widget_grab_focus (bin->child);
2445 gtk_window_real_set_focus (GtkWindow *window,
2448 GdkEventFocus event;
2449 gboolean def_flags = 0;
2451 g_return_if_fail (window != NULL);
2452 g_return_if_fail (GTK_IS_WINDOW (window));
2454 if (window->default_widget)
2455 def_flags = GTK_WIDGET_HAS_DEFAULT (window->default_widget);
2457 if (window->focus_widget)
2459 event.type = GDK_FOCUS_CHANGE;
2460 event.window = window->focus_widget->window;
2463 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2464 (window->focus_widget != window->default_widget))
2466 GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2467 /* if any widget had the default set there should be
2468 a default_widget, but might not so this is a sanity
2470 if (window->default_widget)
2471 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2474 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2477 window->focus_widget = focus;
2479 if (window->focus_widget)
2481 event.type = GDK_FOCUS_CHANGE;
2482 event.window = window->focus_widget->window;
2485 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2486 (window->focus_widget != window->default_widget))
2488 if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget))
2489 GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2491 if (window->default_widget)
2492 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2495 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2498 if (window->default_widget &&
2499 (def_flags != GTK_WIDGET_FLAGS (window->default_widget)))
2500 gtk_widget_queue_draw (window->default_widget);
2505 /*********************************
2506 * Functions related to resizing *
2507 *********************************/
2510 gtk_window_move_resize (GtkWindow *window)
2513 GtkContainer *container;
2514 GtkWindowGeometryInfo *info;
2515 GtkWindowLastGeometryInfo saved_last_info;
2516 GdkGeometry new_geometry;
2520 gint new_width, new_height;
2521 gboolean need_reposition;
2522 gboolean default_size_changed = FALSE;
2523 gboolean hints_changed = FALSE;
2524 gboolean may_shrink = window->auto_shrink;
2526 g_return_if_fail (GTK_WIDGET_REALIZED (window));
2528 widget = GTK_WIDGET (window);
2529 container = GTK_CONTAINER (widget);
2530 info = gtk_window_get_geometry_info (window, TRUE);
2531 saved_last_info = info->last;
2533 gtk_widget_size_request (widget, NULL);
2534 gtk_window_compute_default_size (window, &new_width, &new_height);
2536 if (info->last.width < 0 ||
2537 info->last.width != new_width ||
2538 info->last.height != new_height)
2540 default_size_changed = TRUE;
2541 may_shrink |= info->may_shrink;
2542 info->last.width = new_width;
2543 info->last.height = new_height;
2545 /* We need to force a reposition in this case
2547 if (window->position == GTK_WIN_POS_CENTER_ALWAYS)
2548 window->use_uposition = TRUE;
2550 info->may_shrink = FALSE;
2552 /* Compute new set of hints for the window
2554 gtk_window_compute_hints (window, &new_geometry, &new_flags);
2555 if (!gtk_window_compare_hints (&info->last.geometry, info->last.flags,
2556 &new_geometry, new_flags))
2558 hints_changed = TRUE;
2559 info->last.geometry = new_geometry;
2560 info->last.flags = new_flags;
2563 /* From the default size and the allocation, figure out the size
2564 * the window should be.
2566 if (!default_size_changed ||
2568 new_width <= widget->allocation.width &&
2569 new_height <= widget->allocation.height))
2571 new_width = widget->allocation.width;
2572 new_height = widget->allocation.height;
2575 /* constrain the window size to the specified geometry */
2576 gtk_window_constrain_size (window,
2577 &new_geometry, new_flags,
2578 new_width, new_height,
2579 &new_width, &new_height);
2581 /* compute new window position if a move is required
2583 need_reposition = gtk_window_compute_reposition (window, new_width, new_height, &x, &y);
2584 if (need_reposition && !(new_flags & GDK_HINT_POS))
2586 new_flags |= GDK_HINT_POS;
2587 hints_changed = TRUE;
2591 /* handle actual resizing:
2592 * - handle reallocations due to configure events
2593 * - figure whether we need to request a new window size
2594 * - handle simple resizes within our widget tree
2595 * - reposition window if neccessary
2597 width = widget->allocation.width;
2598 height = widget->allocation.height;
2600 if (window->handling_resize)
2602 GtkAllocation allocation;
2604 /* if we are just responding to a configure event, which
2605 * might be due to a resize by the window manager, the
2606 * user, or a response to a resizing request we made
2607 * earlier, we go ahead, allocate the new size and we're done
2608 * (see gtk_window_configure_event() for more details).
2611 window->handling_resize = FALSE;
2613 allocation = widget->allocation;
2615 gtk_widget_size_allocate (widget, &allocation);
2616 gtk_widget_queue_draw (widget);
2618 if ((default_size_changed || hints_changed) && (width != new_width || height != new_height))
2620 /* We could be here for two reasons
2621 * 1) We coincidentally got a resize while handling
2623 * 2) Our computation of default_size_changed was completely
2624 * screwed up, probably because one of our children
2625 * is changed requisition during size allocation).
2627 * For 1), we could just go ahead and ask for the
2628 * new size right now, but doing that for 2)
2629 * might well be fighting the user (and can even
2630 * trigger a loop). Since we really don't want to
2631 * do that, we requeue a resize in hopes that
2632 * by the time it gets handled, the child has seen
2633 * the light and is willing to go along with the
2634 * new size. (this happens for the zvt widget, since
2635 * the size_allocate() above will have stored the
2636 * requisition corresponding to the new size in the
2639 * This doesn't buy us anything for 1), but it shouldn't
2640 * hurt us too badly, since it is what would have
2641 * happened if we had gotten the configure event before
2642 * the new size had been set.
2645 if (need_reposition)
2648 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2650 gdk_window_move (GTK_WIDGET (window)->window, x, y);
2653 /* we have to preserve the values and flags that are used
2654 * for computation of default_size_changed and hints_changed
2656 info->last = saved_last_info;
2658 gtk_widget_queue_resize (widget);
2664 /* Now set hints if necessary
2667 gdk_window_set_geometry_hints (widget->window,
2671 if ((default_size_changed || hints_changed) &&
2672 (width != new_width || height != new_height))
2674 /* given that (width != new_width || height != new_height), we are in one
2675 * of the following situations:
2677 * default_size_changed
2678 * our requisition has changed and we need a different window size,
2679 * so we request it from the window manager.
2681 * !default_size_changed
2682 * the window manager wouldn't assign us the size we requested, in this
2683 * case we don't try to request a new size with every resize.
2685 * !default_size_changed && hints_changed
2686 * the window manager rejects our size, but we have just changed the
2687 * window manager hints, so there's a certain chance our request will
2688 * be honoured this time, so we try again.
2691 /* request a new window size */
2692 if (need_reposition)
2696 gdk_window_move_resize (window->frame,
2697 x - window->frame_left, y - window->frame_top,
2698 new_width + window->frame_left + window->frame_right,
2699 new_height + window->frame_top + window->frame_bottom);
2700 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2703 gdk_window_move_resize (GTK_WIDGET (window)->window, x, y, new_width, new_height);
2708 gdk_window_resize (window->frame,
2709 new_width + window->frame_left + window->frame_right,
2710 new_height + window->frame_top + window->frame_bottom);
2711 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2713 window->resize_count += 1;
2715 /* we are now awaiting the new configure event in response to our
2716 * resizing request. the configure event will cause a new resize
2717 * with ->handling_resize=TRUE.
2718 * until then, we want to
2719 * - discard expose events
2720 * - coalesce resizes for our children
2721 * - defer any window resizes until the configure event arrived
2722 * to achive this, we queue a resize for the window, but remove its
2723 * resizing handler, so resizing will not be handled from the next
2724 * idle handler but when the configure event arrives.
2726 * FIXME: we should also dequeue the pending redraws here, since
2727 * we handle those ourselves in ->handling_resize==TRUE.
2729 gtk_widget_queue_resize (GTK_WIDGET (container));
2730 if (container->resize_mode == GTK_RESIZE_QUEUE)
2731 gtk_container_dequeue_resize_handler (container);
2735 if (need_reposition)
2738 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2740 gdk_window_move (widget->window, x, y);
2743 if (container->resize_widgets)
2744 gtk_container_resize_children (GTK_CONTAINER (window));
2748 /* Compare two sets of Geometry hints for equality.
2751 gtk_window_compare_hints (GdkGeometry *geometry_a,
2753 GdkGeometry *geometry_b,
2756 if (flags_a != flags_b)
2759 if ((flags_a & GDK_HINT_MIN_SIZE) &&
2760 (geometry_a->min_width != geometry_b->min_width ||
2761 geometry_a->min_height != geometry_b->min_height))
2764 if ((flags_a & GDK_HINT_MAX_SIZE) &&
2765 (geometry_a->max_width != geometry_b->max_width ||
2766 geometry_a->max_height != geometry_b->max_height))
2769 if ((flags_a & GDK_HINT_BASE_SIZE) &&
2770 (geometry_a->base_width != geometry_b->base_width ||
2771 geometry_a->base_height != geometry_b->base_height))
2774 if ((flags_a & GDK_HINT_ASPECT) &&
2775 (geometry_a->min_aspect != geometry_b->min_aspect ||
2776 geometry_a->max_aspect != geometry_b->max_aspect))
2779 if ((flags_a & GDK_HINT_RESIZE_INC) &&
2780 (geometry_a->width_inc != geometry_b->width_inc ||
2781 geometry_a->height_inc != geometry_b->height_inc))
2784 if ((flags_a & GDK_HINT_WIN_GRAVITY) &&
2785 geometry_a->win_gravity != geometry_b->win_gravity)
2791 /* Compute the default_size for a window. The result will
2792 * be stored in *width and *height. The default size is
2793 * the size the window should have when initially mapped.
2794 * This routine does not attempt to constrain the size
2795 * to obey the geometry hints - that must be done elsewhere.
2798 gtk_window_compute_default_size (GtkWindow *window,
2802 GtkRequisition requisition;
2803 GtkWindowGeometryInfo *info;
2805 gtk_widget_get_child_requisition (GTK_WIDGET (window), &requisition);
2806 *width = requisition.width;
2807 *height = requisition.height;
2809 info = gtk_window_get_geometry_info (window, FALSE);
2811 if (*width == 0 && *height == 0)
2820 *width = info->width > 0 ? info->width : *width;
2821 *height = info->height > 0 ? info->height : *height;
2826 _gtk_window_constrain_size (GtkWindow *window,
2832 GtkWindowGeometryInfo *info;
2834 g_return_if_fail (GTK_IS_WINDOW (window));
2836 info = window->geometry_info;
2839 GdkWindowHints flags = info->last.flags;
2840 GdkGeometry *geometry = &info->last.geometry;
2842 gtk_window_constrain_size (window,
2853 gtk_window_constrain_size (GtkWindow *window,
2854 GdkGeometry *geometry,
2861 gdk_window_constrain_size (geometry, flags, width, height,
2862 new_width, new_height);
2865 /* Compute the set of geometry hints and flags for a window
2866 * based on the application set geometry, and requisiition
2867 * of the window. gtk_widget_size_request() must have been
2871 gtk_window_compute_hints (GtkWindow *window,
2872 GdkGeometry *new_geometry,
2876 GtkWidgetAuxInfo *aux_info;
2878 gint extra_width = 0;
2879 gint extra_height = 0;
2880 GtkWindowGeometryInfo *geometry_info;
2881 GtkRequisition requisition;
2883 g_return_if_fail (GTK_IS_WINDOW (window));
2885 widget = GTK_WIDGET (window);
2887 gtk_widget_get_child_requisition (widget, &requisition);
2888 geometry_info = gtk_window_get_geometry_info (GTK_WINDOW (widget), FALSE);
2890 g_return_if_fail (geometry_info != NULL);
2892 *new_flags = geometry_info->mask;
2893 *new_geometry = geometry_info->geometry;
2895 if (geometry_info->widget)
2897 extra_width = widget->requisition.width - geometry_info->widget->requisition.width;
2898 extra_height = widget->requisition.height - geometry_info->widget->requisition.height;
2904 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
2905 if (aux_info && aux_info->x_set && aux_info->y_set)
2909 *new_flags |= GDK_HINT_POS;
2912 if (*new_flags & GDK_HINT_BASE_SIZE)
2914 new_geometry->base_width += extra_width;
2915 new_geometry->base_height += extra_height;
2917 else if (!(*new_flags & GDK_HINT_MIN_SIZE) &&
2918 (*new_flags & GDK_HINT_RESIZE_INC) &&
2919 ((extra_width != 0) || (extra_height != 0)))
2921 *new_flags |= GDK_HINT_BASE_SIZE;
2923 new_geometry->base_width = extra_width;
2924 new_geometry->base_height = extra_height;
2927 if (*new_flags & GDK_HINT_MIN_SIZE)
2929 if (new_geometry->min_width < 0)
2930 new_geometry->min_width = requisition.width;
2932 new_geometry->min_width += extra_width;
2934 if (new_geometry->min_height < 0)
2935 new_geometry->min_width = requisition.height;
2937 new_geometry->min_height += extra_height;
2939 else if (!window->allow_shrink)
2941 *new_flags |= GDK_HINT_MIN_SIZE;
2943 new_geometry->min_width = requisition.width;
2944 new_geometry->min_height = requisition.height;
2947 if (*new_flags & GDK_HINT_MAX_SIZE)
2949 if (new_geometry->max_width < 0)
2950 new_geometry->max_width = requisition.width;
2952 new_geometry->max_width += extra_width;
2954 if (new_geometry->max_height < 0)
2955 new_geometry->max_width = requisition.height;
2957 new_geometry->max_height += extra_height;
2959 else if (!window->allow_grow)
2961 *new_flags |= GDK_HINT_MAX_SIZE;
2963 new_geometry->max_width = requisition.width;
2964 new_geometry->max_height = requisition.height;
2967 *new_flags |= GDK_HINT_WIN_GRAVITY;
2968 new_geometry->win_gravity = window->gravity;
2971 /* Compute a new position for the window based on a new
2972 * size. *x and *y will be set to the new coordinates. Returns
2973 * TRUE if the window needs to be moved (and thus x and y got
2977 gtk_window_compute_reposition (GtkWindow *window,
2983 GtkWidget *widget = GTK_WIDGET (window);
2984 GtkWindowPosition pos;
2985 GtkWidget *parent_widget;
2986 gboolean needs_move = FALSE;
2988 parent_widget = (GtkWidget*) window->transient_parent;
2990 pos = window->position;
2991 if (pos == GTK_WIN_POS_CENTER_ON_PARENT &&
2992 (parent_widget == NULL ||
2993 !GTK_WIDGET_MAPPED (parent_widget)))
2994 pos = GTK_WIN_POS_NONE;
2998 case GTK_WIN_POS_CENTER:
2999 case GTK_WIN_POS_CENTER_ALWAYS:
3000 if (window->use_uposition)
3002 gint screen_width = gdk_screen_width ();
3003 gint screen_height = gdk_screen_height ();
3005 *x = (screen_width - new_width) / 2;
3006 *y = (screen_height - new_height) / 2;
3011 case GTK_WIN_POS_CENTER_ON_PARENT:
3012 if (window->use_uposition)
3015 gdk_window_get_origin (parent_widget->window,
3018 *x = ox + (parent_widget->allocation.width - new_width) / 2;
3019 *y = oy + (parent_widget->allocation.height - new_height) / 2;
3024 case GTK_WIN_POS_MOUSE:
3025 if (window->use_uposition)
3027 gint screen_width = gdk_screen_width ();
3028 gint screen_height = gdk_screen_height ();
3030 gdk_window_get_pointer (NULL, x, y, NULL);
3031 *x -= new_width / 2;
3032 *y -= new_height / 2;
3033 *x = CLAMP (*x, 0, screen_width - new_width);
3034 *y = CLAMP (*y, 0, screen_height - new_height);
3039 if (window->use_uposition)
3041 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3043 if (aux_info && aux_info->x_set && aux_info->y_set)
3055 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, TRUE);
3057 /* we handle necessary window positioning by hand here,
3058 * so we can coalesce the window movement with possible
3059 * resizes to get only one configure event.
3061 aux_info->x_set = TRUE;
3062 aux_info->y_set = TRUE;
3065 window->use_uposition = FALSE;
3071 /***********************
3072 * Redrawing functions *
3073 ***********************/
3076 gtk_window_paint (GtkWidget *widget,
3079 gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL,
3080 GTK_SHADOW_NONE, area, widget, "base", 0, 0, -1, -1);
3084 gtk_window_expose (GtkWidget *widget,
3085 GdkEventExpose *event)
3087 g_return_val_if_fail (widget != NULL, FALSE);
3088 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
3089 g_return_val_if_fail (event != NULL, FALSE);
3091 if (!GTK_WIDGET_APP_PAINTABLE (widget))
3092 gtk_window_paint (widget, &event->area);
3094 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
3095 return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
3101 * gtk_window_set_has_frame:
3102 * @window: a #GtkWindow
3104 * If this function is called on a window before it is realized
3105 * or showed it will have a "frame" window around widget-window,
3106 * accessible in window->frame. Using the signal frame_event
3107 * you can recieve all events targeted at the frame.
3109 * This function is used by the linux-fb port to implement managed
3110 * windows, but it could concievably be used by X-programs that
3111 * want to do their own window decorations.
3114 gtk_window_set_has_frame (GtkWindow *window)
3116 g_return_if_fail (window != NULL);
3117 g_return_if_fail (GTK_IS_WINDOW (window));
3118 g_return_if_fail (!GTK_WIDGET_REALIZED (window));
3120 window->has_frame = TRUE;
3124 * gtk_window_set_frame_dimensions:
3125 * @window: a #GtkWindow that has a frame
3126 * @left: The width of the left border
3127 * @top: The height of the top border
3128 * @right: The width of the right border
3129 * @bottom: The height of the bottom border
3131 * For windows with frames (see #gtk_window_set_has_frame) this function
3132 * can be used to change the size of the frame border.
3135 gtk_window_set_frame_dimensions (GtkWindow *window,
3141 GtkWidget *widget = GTK_WIDGET (window);
3143 g_return_if_fail (window != NULL);
3144 g_return_if_fail (GTK_IS_WINDOW (window));
3146 if (window->frame_left == left &&
3147 window->frame_top == top &&
3148 window->frame_right == right &&
3149 window->frame_bottom == bottom)
3152 window->frame_left = left;
3153 window->frame_top = top;
3154 window->frame_right = right;
3155 window->frame_bottom = bottom;
3157 if (GTK_WIDGET_REALIZED (widget) && window->frame)
3159 gint width = widget->allocation.width + left + right;
3160 gint height = widget->allocation.height + top + bottom;
3161 gdk_window_resize (window->frame, width, height);
3162 gtk_decorated_window_move_resize_window (window,
3164 widget->allocation.width,
3165 widget->allocation.height);
3172 * gtk_window_present:
3173 * @window: a #GtkWindow
3175 * Presents a window to the user. This may mean raising the window
3176 * in the stacking order, deiconifying it, moving it to the current
3177 * desktop, and/or giving it the keyboard focus, possibly dependent
3178 * on the user's platform, window manager, and preferences.
3180 * If @window is hidden, this function calls gtk_widget_show()
3183 * This function should be used when the user tries to open a window
3184 * that's already open. Say for example the preferences dialog is
3185 * currently open, and the user chooses Preferences from the menu
3186 * a second time; use gtk_window_present() to move the already-open dialog
3187 * where the user can see it.
3191 gtk_window_present (GtkWindow *window)
3195 g_return_if_fail (GTK_IS_WINDOW (window));
3197 widget = GTK_WIDGET (window);
3199 if (GTK_WIDGET_VISIBLE (window))
3201 g_assert (widget->window != NULL);
3203 gdk_window_show (widget->window);
3205 /* note that gdk_window_focus() will also move the window to
3206 * the current desktop, for WM spec compliant window managers.
3208 gdk_window_focus (widget->window,
3209 gtk_get_current_event_time ());
3213 gtk_widget_show (widget);
3218 * gtk_window_iconify:
3219 * @window: a #GtkWindow
3221 * Asks to iconify @window. Note that you shouldn't assume the window
3222 * is definitely iconified afterward, because other entities (e.g. the
3223 * user or window manager) could deiconify it again, or there may not
3224 * be a window manager in which case iconification isn't possible,
3225 * etc. But normally the window will end up iconified. Just don't write
3226 * code that crashes if not.
3228 * It's permitted to call this function before showing a window,
3229 * in which case the window will be iconified before it ever appears
3232 * You can track iconification via the "window_state_event" signal
3237 gtk_window_iconify (GtkWindow *window)
3240 GdkWindow *toplevel;
3242 g_return_if_fail (GTK_IS_WINDOW (window));
3244 widget = GTK_WIDGET (window);
3246 window->iconify_initially = TRUE;
3249 toplevel = window->frame;
3251 toplevel = widget->window;
3253 if (toplevel != NULL)
3254 gdk_window_iconify (toplevel);
3258 * gtk_window_deiconify:
3259 * @window: a #GtkWindow
3261 * Asks to deiconify @window. Note that you shouldn't assume the
3262 * window is definitely deiconified afterward, because other entities
3263 * (e.g. the user or window manager) could iconify it again before
3264 * your code which assumes deiconification gets to run.
3266 * You can track iconification via the "window_state_event" signal
3270 gtk_window_deiconify (GtkWindow *window)
3273 GdkWindow *toplevel;
3275 g_return_if_fail (GTK_IS_WINDOW (window));
3277 widget = GTK_WIDGET (window);
3279 window->iconify_initially = FALSE;
3282 toplevel = window->frame;
3284 toplevel = widget->window;
3286 if (toplevel != NULL)
3287 gdk_window_deiconify (toplevel);
3292 * @window: a #GtkWindow
3294 * Asks to stick @window, which means that it will appear on all user
3295 * desktops. Note that you shouldn't assume the window is definitely
3296 * stuck afterward, because other entities (e.g. the user or window
3297 * manager) could unstick it again, and some window managers do not
3298 * support sticking windows. But normally the window will end up
3299 * stuck. Just don't write code that crashes if not.
3301 * It's permitted to call this function before showing a window.
3303 * You can track stickiness via the "window_state_event" signal
3308 gtk_window_stick (GtkWindow *window)
3311 GdkWindow *toplevel;
3313 g_return_if_fail (GTK_IS_WINDOW (window));
3315 widget = GTK_WIDGET (window);
3317 window->stick_initially = TRUE;
3320 toplevel = window->frame;
3322 toplevel = widget->window;
3324 if (toplevel != NULL)
3325 gdk_window_stick (toplevel);
3329 * gtk_window_unstick:
3330 * @window: a #GtkWindow
3332 * Asks to unstick @window, which means that it will appear on only
3333 * one of the user's desktops. Note that you shouldn't assume the
3334 * window is definitely unstuck afterward, because other entities
3335 * (e.g. the user or window manager) could stick it again. But
3336 * normally the window will end up stuck. Just don't write code that
3339 * You can track stickiness via the "window_state_event" signal
3344 gtk_window_unstick (GtkWindow *window)
3347 GdkWindow *toplevel;
3349 g_return_if_fail (GTK_IS_WINDOW (window));
3351 widget = GTK_WIDGET (window);
3353 window->stick_initially = FALSE;
3356 toplevel = window->frame;
3358 toplevel = widget->window;
3360 if (toplevel != NULL)
3361 gdk_window_unstick (toplevel);
3365 * gtk_window_maximize:
3366 * @window: a #GtkWindow
3368 * Asks to maximize @window, so that it becomes full-screen. Note that
3369 * you shouldn't assume the window is definitely maximized afterward,
3370 * because other entities (e.g. the user or window manager) could
3371 * unmaximize it again, and not all window managers support
3372 * maximization. But normally the window will end up maximized. Just
3373 * don't write code that crashes if not.
3375 * It's permitted to call this function before showing a window,
3376 * in which case the window will be maximized when it appears onscreen
3379 * You can track maximization via the "window_state_event" signal
3384 gtk_window_maximize (GtkWindow *window)
3387 GdkWindow *toplevel;
3389 g_return_if_fail (GTK_IS_WINDOW (window));
3391 widget = GTK_WIDGET (window);
3393 window->maximize_initially = TRUE;
3396 toplevel = window->frame;
3398 toplevel = widget->window;
3400 if (toplevel != NULL)
3401 gdk_window_maximize (toplevel);
3405 * gtk_window_unmaximize:
3406 * @window: a #GtkWindow
3408 * Asks to unmaximize @window. Note that you shouldn't assume the
3409 * window is definitely unmaximized afterward, because other entities
3410 * (e.g. the user or window manager) could maximize it again, and not
3411 * all window managers honor requests to unmaximize. But normally the
3412 * window will end up unmaximized. Just don't write code that crashes
3415 * You can track maximization via the "window_state_event" signal
3420 gtk_window_unmaximize (GtkWindow *window)
3423 GdkWindow *toplevel;
3425 g_return_if_fail (GTK_IS_WINDOW (window));
3427 widget = GTK_WIDGET (window);
3429 window->maximize_initially = FALSE;
3432 toplevel = window->frame;
3434 toplevel = widget->window;
3436 if (toplevel != NULL)
3437 gdk_window_unmaximize (toplevel);
3441 * gtk_window_set_resizeable:
3442 * @window: a #GtkWindow
3443 * @resizeable: %TRUE if the user can resize this window
3445 * Sets whether the user can resize a window. Windows are user resizeable
3449 gtk_window_set_resizeable (GtkWindow *window,
3450 gboolean resizeable)
3452 g_return_if_fail (GTK_IS_WINDOW (window));
3454 gtk_window_set_policy (window, FALSE, resizeable, FALSE);
3458 * gtk_window_get_resizeable:
3459 * @window: a #GtkWindow
3461 * Gets the value set by gtk_window_set_resizeable().
3463 * Return value: %TRUE if the user can resize the window
3466 gtk_window_get_resizeable (GtkWindow *window)
3468 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
3470 /* allow_grow is most likely to indicate the semantic concept we
3471 * mean by "resizeable" (and will be a reliable indicator if
3472 * set_policy() hasn't been called)
3474 return window->allow_grow;
3478 * gtk_window_set_gravity:
3479 * @window: a #GtkWindow
3480 * @gravity: window gravity
3482 * Window gravity defines the "reference point" to be used when
3483 * positioning or resizing a window. Calls to
3484 * gtk_widget_set_uposition() will position a different point on the
3485 * window depending on the window gravity. When the window changes size
3486 * the reference point determined by the window's gravity will stay in
3489 * See #GdkGravity for full details. To briefly summarize,
3490 * #GDK_GRAVITY_NORTH_WEST means that the reference point is the
3491 * northwest (top left) corner of the window
3492 * frame. #GDK_GRAVITY_SOUTH_EAST would be the bottom right corner of
3493 * the frame, and so on. If you want to position the window contents,
3494 * rather than the window manager's frame, #GDK_GRAVITY_STATIC moves
3495 * the reference point to the northwest corner of the #GtkWindow
3498 * The default window gravity is #GDK_GRAVITY_NORTH_WEST.
3502 gtk_window_set_gravity (GtkWindow *window,
3505 g_return_if_fail (GTK_IS_WINDOW (window));
3507 if (gravity != window->gravity)
3509 window->gravity = gravity;
3511 /* gtk_window_move_resize() will adapt gravity
3513 gtk_widget_queue_resize (GTK_WIDGET (window));
3518 * gtk_window_get_gravity:
3519 * @window: a #GtkWindow
3521 * Gets the value set by gtk_window_set_gravity().
3523 * Return value: window gravity
3526 gtk_window_get_gravity (GtkWindow *window)
3528 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
3530 return window->gravity;
3534 * gtk_window_begin_resize_drag:
3535 * @window: a #GtkWindow
3536 * @button: mouse button that initiated the drag
3537 * @edge: position of the resize control
3538 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3539 * @root_y: Y position where the user clicked to initiate the drag
3540 * @timestamp: timestamp from the click event that initiated the drag
3542 * Starts resizing a window. This function is used if an application
3543 * has window resizing controls. When GDK can support it, the resize
3544 * will be done using the standard mechanism for the window manager or
3545 * windowing system. Otherwise, GDK will try to emulate window
3546 * resizing, potentially not all that well, depending on the windowing system.
3550 gtk_window_begin_resize_drag (GtkWindow *window,
3558 GdkWindow *toplevel;
3560 g_return_if_fail (GTK_IS_WINDOW (window));
3561 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3563 widget = GTK_WIDGET (window);
3566 toplevel = window->frame;
3568 toplevel = widget->window;
3570 gdk_window_begin_resize_drag (toplevel,
3578 * gtk_window_begin_move_drag:
3579 * @window: a #GtkWindow
3580 * @button: mouse button that initiated the drag
3581 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3582 * @root_y: Y position where the user clicked to initiate the drag
3583 * @timestamp: timestamp from the click event that initiated the drag
3585 * Starts moving a window. This function is used if an application
3586 * has window movement grips. When GDK can support it, the window movement
3587 * will be done using the standard mechanism for the window manager or
3588 * windowing system. Otherwise, GDK will try to emulate window
3589 * movement, potentially not all that well, depending on the windowing system.
3593 gtk_window_begin_move_drag (GtkWindow *window,
3600 GdkWindow *toplevel;
3602 g_return_if_fail (GTK_IS_WINDOW (window));
3603 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3605 widget = GTK_WIDGET (window);
3608 toplevel = window->frame;
3610 toplevel = widget->window;
3612 gdk_window_begin_move_drag (toplevel,