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)
2251 GtkWindow *window = GTK_WINDOW (widget);
2252 GdkEventFocus fevent;
2254 /* It appears spurious focus in events can occur when
2255 * the window is hidden. So we'll just check to see if
2256 * the window is visible before actually handling the
2259 if (GTK_WIDGET_VISIBLE (widget))
2261 window->has_focus = TRUE;
2263 if (window->focus_widget &&
2264 window->focus_widget != widget &&
2265 !GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2267 fevent.type = GDK_FOCUS_CHANGE;
2268 fevent.window = window->focus_widget->window;
2271 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2279 gtk_window_focus_out_event (GtkWidget *widget,
2280 GdkEventFocus *event)
2282 GtkWindow *window = GTK_WINDOW (widget);
2283 GdkEventFocus fevent;
2285 window->has_focus = FALSE;
2287 if (window->focus_widget &&
2288 window->focus_widget != widget &&
2289 GTK_WIDGET_HAS_FOCUS (window->focus_widget))
2291 fevent.type = GDK_FOCUS_CHANGE;
2292 fevent.window = window->focus_widget->window;
2295 gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent);
2301 static GdkAtom atom_rcfiles = GDK_NONE;
2304 gtk_window_read_rcfiles (GtkWidget *widget,
2305 GdkEventClient *event)
2307 GList *embedded_windows;
2309 embedded_windows = gtk_object_get_data (GTK_OBJECT (widget), "gtk-embedded");
2310 if (embedded_windows)
2315 for(i = 0; i < 5; i++)
2317 sev.data_format = 32;
2318 sev.message_type = atom_rcfiles;
2320 while (embedded_windows)
2322 guint xid = GPOINTER_TO_UINT (embedded_windows->data);
2323 gdk_event_send_client_message ((GdkEvent *) &sev, xid);
2324 embedded_windows = embedded_windows->next;
2328 if (gtk_rc_reparse_all ())
2330 /* If the above returned true, some of our RC files are out
2331 * of date, so we need to reset all our widgets. Our other
2332 * toplevel windows will also get the message, but by
2333 * then, the RC file will up to date, so we have to tell
2334 * them now. Also, we have to invalidate cached icons in
2335 * icon sets so they get re-rendered.
2337 GList *list, *toplevels;
2339 _gtk_icon_set_invalidate_caches ();
2341 toplevels = gtk_window_list_toplevels ();
2342 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
2344 for (list = toplevels; list; list = list->next)
2346 gtk_widget_reset_rc_styles (list->data);
2347 gtk_widget_unref (list->data);
2349 g_list_free (toplevels);
2354 gtk_window_client_event (GtkWidget *widget,
2355 GdkEventClient *event)
2357 g_return_val_if_fail (widget != NULL, FALSE);
2358 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
2359 g_return_val_if_fail (event != NULL, FALSE);
2362 atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
2364 if(event->message_type == atom_rcfiles)
2365 gtk_window_read_rcfiles (widget, event);
2371 gtk_window_check_resize (GtkContainer *container)
2375 g_return_if_fail (container != NULL);
2376 g_return_if_fail (GTK_IS_WINDOW (container));
2378 window = GTK_WINDOW (container);
2380 if (GTK_WIDGET_VISIBLE (container))
2381 gtk_window_move_resize (window);
2385 gtk_window_focus (GtkContainer *container,
2386 GtkDirectionType direction)
2388 GtkBin *bin = GTK_BIN (container);
2389 GtkWindow *window = GTK_WINDOW (container);
2390 GtkWidget *old_focus_child = container->focus_child;
2393 /* We need a special implementation here to deal properly with wrapping
2394 * around in the tab chain without the danger of going into an
2397 if (old_focus_child)
2399 if (GTK_IS_CONTAINER (old_focus_child) &&
2400 GTK_WIDGET_DRAWABLE (old_focus_child) &&
2401 GTK_WIDGET_IS_SENSITIVE (old_focus_child) &&
2402 gtk_container_focus (GTK_CONTAINER (old_focus_child), direction))
2406 if (window->focus_widget)
2408 /* Wrapped off the end, clear the focus setting for the toplpevel */
2409 parent = window->focus_widget->parent;
2412 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
2413 parent = GTK_WIDGET (parent)->parent;
2416 gtk_window_set_focus (GTK_WINDOW (container), NULL);
2419 /* Now try to focus the first widget in the window */
2421 GTK_WIDGET_DRAWABLE (bin->child) &&
2422 GTK_WIDGET_IS_SENSITIVE (bin->child))
2424 if (GTK_IS_CONTAINER (bin->child))
2426 if (gtk_container_focus (GTK_CONTAINER (bin->child), direction))
2429 else if (GTK_WIDGET_CAN_FOCUS (bin->child))
2431 gtk_widget_grab_focus (bin->child);
2440 gtk_window_real_set_focus (GtkWindow *window,
2443 GdkEventFocus event;
2444 gboolean def_flags = 0;
2446 g_return_if_fail (window != NULL);
2447 g_return_if_fail (GTK_IS_WINDOW (window));
2449 if (window->default_widget)
2450 def_flags = GTK_WIDGET_HAS_DEFAULT (window->default_widget);
2452 if (window->focus_widget)
2454 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2455 (window->focus_widget != window->default_widget))
2457 GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2459 if (window->default_widget)
2460 GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2463 if (window->has_focus)
2465 event.type = GDK_FOCUS_CHANGE;
2466 event.window = window->focus_widget->window;
2469 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2473 window->focus_widget = focus;
2475 if (window->focus_widget)
2477 if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) &&
2478 (window->focus_widget != window->default_widget))
2480 if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget))
2481 GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT);
2483 if (window->default_widget)
2484 GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT);
2487 if (window->has_focus)
2489 event.type = GDK_FOCUS_CHANGE;
2490 event.window = window->focus_widget->window;
2493 gtk_widget_event (window->focus_widget, (GdkEvent*) &event);
2497 if (window->default_widget &&
2498 (def_flags != GTK_WIDGET_FLAGS (window->default_widget)))
2499 gtk_widget_queue_draw (window->default_widget);
2504 /*********************************
2505 * Functions related to resizing *
2506 *********************************/
2509 gtk_window_move_resize (GtkWindow *window)
2512 GtkContainer *container;
2513 GtkWindowGeometryInfo *info;
2514 GtkWindowLastGeometryInfo saved_last_info;
2515 GdkGeometry new_geometry;
2519 gint new_width, new_height;
2520 gboolean need_reposition;
2521 gboolean default_size_changed = FALSE;
2522 gboolean hints_changed = FALSE;
2523 gboolean may_shrink = window->auto_shrink;
2525 g_return_if_fail (GTK_WIDGET_REALIZED (window));
2527 widget = GTK_WIDGET (window);
2528 container = GTK_CONTAINER (widget);
2529 info = gtk_window_get_geometry_info (window, TRUE);
2530 saved_last_info = info->last;
2532 gtk_widget_size_request (widget, NULL);
2533 gtk_window_compute_default_size (window, &new_width, &new_height);
2535 if (info->last.width < 0 ||
2536 info->last.width != new_width ||
2537 info->last.height != new_height)
2539 default_size_changed = TRUE;
2540 may_shrink |= info->may_shrink;
2541 info->last.width = new_width;
2542 info->last.height = new_height;
2544 /* We need to force a reposition in this case
2546 if (window->position == GTK_WIN_POS_CENTER_ALWAYS)
2547 window->use_uposition = TRUE;
2549 info->may_shrink = FALSE;
2551 /* Compute new set of hints for the window
2553 gtk_window_compute_hints (window, &new_geometry, &new_flags);
2554 if (!gtk_window_compare_hints (&info->last.geometry, info->last.flags,
2555 &new_geometry, new_flags))
2557 hints_changed = TRUE;
2558 info->last.geometry = new_geometry;
2559 info->last.flags = new_flags;
2562 /* From the default size and the allocation, figure out the size
2563 * the window should be.
2565 if (!default_size_changed ||
2567 new_width <= widget->allocation.width &&
2568 new_height <= widget->allocation.height))
2570 new_width = widget->allocation.width;
2571 new_height = widget->allocation.height;
2574 /* constrain the window size to the specified geometry */
2575 gtk_window_constrain_size (window,
2576 &new_geometry, new_flags,
2577 new_width, new_height,
2578 &new_width, &new_height);
2580 /* compute new window position if a move is required
2582 need_reposition = gtk_window_compute_reposition (window, new_width, new_height, &x, &y);
2583 if (need_reposition && !(new_flags & GDK_HINT_POS))
2585 new_flags |= GDK_HINT_POS;
2586 hints_changed = TRUE;
2590 /* handle actual resizing:
2591 * - handle reallocations due to configure events
2592 * - figure whether we need to request a new window size
2593 * - handle simple resizes within our widget tree
2594 * - reposition window if neccessary
2596 width = widget->allocation.width;
2597 height = widget->allocation.height;
2599 if (window->handling_resize)
2601 GtkAllocation allocation;
2603 /* if we are just responding to a configure event, which
2604 * might be due to a resize by the window manager, the
2605 * user, or a response to a resizing request we made
2606 * earlier, we go ahead, allocate the new size and we're done
2607 * (see gtk_window_configure_event() for more details).
2610 window->handling_resize = FALSE;
2612 allocation = widget->allocation;
2614 gtk_widget_size_allocate (widget, &allocation);
2615 gtk_widget_queue_draw (widget);
2617 if ((default_size_changed || hints_changed) && (width != new_width || height != new_height))
2619 /* We could be here for two reasons
2620 * 1) We coincidentally got a resize while handling
2622 * 2) Our computation of default_size_changed was completely
2623 * screwed up, probably because one of our children
2624 * is changed requisition during size allocation).
2626 * For 1), we could just go ahead and ask for the
2627 * new size right now, but doing that for 2)
2628 * might well be fighting the user (and can even
2629 * trigger a loop). Since we really don't want to
2630 * do that, we requeue a resize in hopes that
2631 * by the time it gets handled, the child has seen
2632 * the light and is willing to go along with the
2633 * new size. (this happens for the zvt widget, since
2634 * the size_allocate() above will have stored the
2635 * requisition corresponding to the new size in the
2638 * This doesn't buy us anything for 1), but it shouldn't
2639 * hurt us too badly, since it is what would have
2640 * happened if we had gotten the configure event before
2641 * the new size had been set.
2644 if (need_reposition)
2647 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2649 gdk_window_move (GTK_WIDGET (window)->window, x, y);
2652 /* we have to preserve the values and flags that are used
2653 * for computation of default_size_changed and hints_changed
2655 info->last = saved_last_info;
2657 gtk_widget_queue_resize (widget);
2663 /* Now set hints if necessary
2666 gdk_window_set_geometry_hints (widget->window,
2670 if ((default_size_changed || hints_changed) &&
2671 (width != new_width || height != new_height))
2673 /* given that (width != new_width || height != new_height), we are in one
2674 * of the following situations:
2676 * default_size_changed
2677 * our requisition has changed and we need a different window size,
2678 * so we request it from the window manager.
2680 * !default_size_changed
2681 * the window manager wouldn't assign us the size we requested, in this
2682 * case we don't try to request a new size with every resize.
2684 * !default_size_changed && hints_changed
2685 * the window manager rejects our size, but we have just changed the
2686 * window manager hints, so there's a certain chance our request will
2687 * be honoured this time, so we try again.
2690 /* request a new window size */
2691 if (need_reposition)
2695 gdk_window_move_resize (window->frame,
2696 x - window->frame_left, y - window->frame_top,
2697 new_width + window->frame_left + window->frame_right,
2698 new_height + window->frame_top + window->frame_bottom);
2699 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2702 gdk_window_move_resize (GTK_WIDGET (window)->window, x, y, new_width, new_height);
2707 gdk_window_resize (window->frame,
2708 new_width + window->frame_left + window->frame_right,
2709 new_height + window->frame_top + window->frame_bottom);
2710 gdk_window_resize (GTK_WIDGET (window)->window, new_width, new_height);
2712 window->resize_count += 1;
2714 /* we are now awaiting the new configure event in response to our
2715 * resizing request. the configure event will cause a new resize
2716 * with ->handling_resize=TRUE.
2717 * until then, we want to
2718 * - discard expose events
2719 * - coalesce resizes for our children
2720 * - defer any window resizes until the configure event arrived
2721 * to achive this, we queue a resize for the window, but remove its
2722 * resizing handler, so resizing will not be handled from the next
2723 * idle handler but when the configure event arrives.
2725 * FIXME: we should also dequeue the pending redraws here, since
2726 * we handle those ourselves in ->handling_resize==TRUE.
2728 gtk_widget_queue_resize (GTK_WIDGET (container));
2729 if (container->resize_mode == GTK_RESIZE_QUEUE)
2730 gtk_container_dequeue_resize_handler (container);
2734 if (need_reposition)
2737 gdk_window_move (window->frame, x - window->frame_left, y - window->frame_top);
2739 gdk_window_move (widget->window, x, y);
2742 if (container->resize_widgets)
2743 gtk_container_resize_children (GTK_CONTAINER (window));
2747 /* Compare two sets of Geometry hints for equality.
2750 gtk_window_compare_hints (GdkGeometry *geometry_a,
2752 GdkGeometry *geometry_b,
2755 if (flags_a != flags_b)
2758 if ((flags_a & GDK_HINT_MIN_SIZE) &&
2759 (geometry_a->min_width != geometry_b->min_width ||
2760 geometry_a->min_height != geometry_b->min_height))
2763 if ((flags_a & GDK_HINT_MAX_SIZE) &&
2764 (geometry_a->max_width != geometry_b->max_width ||
2765 geometry_a->max_height != geometry_b->max_height))
2768 if ((flags_a & GDK_HINT_BASE_SIZE) &&
2769 (geometry_a->base_width != geometry_b->base_width ||
2770 geometry_a->base_height != geometry_b->base_height))
2773 if ((flags_a & GDK_HINT_ASPECT) &&
2774 (geometry_a->min_aspect != geometry_b->min_aspect ||
2775 geometry_a->max_aspect != geometry_b->max_aspect))
2778 if ((flags_a & GDK_HINT_RESIZE_INC) &&
2779 (geometry_a->width_inc != geometry_b->width_inc ||
2780 geometry_a->height_inc != geometry_b->height_inc))
2783 if ((flags_a & GDK_HINT_WIN_GRAVITY) &&
2784 geometry_a->win_gravity != geometry_b->win_gravity)
2790 /* Compute the default_size for a window. The result will
2791 * be stored in *width and *height. The default size is
2792 * the size the window should have when initially mapped.
2793 * This routine does not attempt to constrain the size
2794 * to obey the geometry hints - that must be done elsewhere.
2797 gtk_window_compute_default_size (GtkWindow *window,
2801 GtkRequisition requisition;
2802 GtkWindowGeometryInfo *info;
2804 gtk_widget_get_child_requisition (GTK_WIDGET (window), &requisition);
2805 *width = requisition.width;
2806 *height = requisition.height;
2808 info = gtk_window_get_geometry_info (window, FALSE);
2810 if (*width == 0 && *height == 0)
2819 *width = info->width > 0 ? info->width : *width;
2820 *height = info->height > 0 ? info->height : *height;
2825 _gtk_window_constrain_size (GtkWindow *window,
2831 GtkWindowGeometryInfo *info;
2833 g_return_if_fail (GTK_IS_WINDOW (window));
2835 info = window->geometry_info;
2838 GdkWindowHints flags = info->last.flags;
2839 GdkGeometry *geometry = &info->last.geometry;
2841 gtk_window_constrain_size (window,
2852 gtk_window_constrain_size (GtkWindow *window,
2853 GdkGeometry *geometry,
2860 gdk_window_constrain_size (geometry, flags, width, height,
2861 new_width, new_height);
2864 /* Compute the set of geometry hints and flags for a window
2865 * based on the application set geometry, and requisiition
2866 * of the window. gtk_widget_size_request() must have been
2870 gtk_window_compute_hints (GtkWindow *window,
2871 GdkGeometry *new_geometry,
2875 GtkWidgetAuxInfo *aux_info;
2877 gint extra_width = 0;
2878 gint extra_height = 0;
2879 GtkWindowGeometryInfo *geometry_info;
2880 GtkRequisition requisition;
2882 g_return_if_fail (GTK_IS_WINDOW (window));
2884 widget = GTK_WIDGET (window);
2886 gtk_widget_get_child_requisition (widget, &requisition);
2887 geometry_info = gtk_window_get_geometry_info (GTK_WINDOW (widget), FALSE);
2889 g_return_if_fail (geometry_info != NULL);
2891 *new_flags = geometry_info->mask;
2892 *new_geometry = geometry_info->geometry;
2894 if (geometry_info->widget)
2896 extra_width = widget->requisition.width - geometry_info->widget->requisition.width;
2897 extra_height = widget->requisition.height - geometry_info->widget->requisition.height;
2903 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
2904 if (aux_info && aux_info->x_set && aux_info->y_set)
2908 *new_flags |= GDK_HINT_POS;
2911 if (*new_flags & GDK_HINT_BASE_SIZE)
2913 new_geometry->base_width += extra_width;
2914 new_geometry->base_height += extra_height;
2916 else if (!(*new_flags & GDK_HINT_MIN_SIZE) &&
2917 (*new_flags & GDK_HINT_RESIZE_INC) &&
2918 ((extra_width != 0) || (extra_height != 0)))
2920 *new_flags |= GDK_HINT_BASE_SIZE;
2922 new_geometry->base_width = extra_width;
2923 new_geometry->base_height = extra_height;
2926 if (*new_flags & GDK_HINT_MIN_SIZE)
2928 if (new_geometry->min_width < 0)
2929 new_geometry->min_width = requisition.width;
2931 new_geometry->min_width += extra_width;
2933 if (new_geometry->min_height < 0)
2934 new_geometry->min_width = requisition.height;
2936 new_geometry->min_height += extra_height;
2938 else if (!window->allow_shrink)
2940 *new_flags |= GDK_HINT_MIN_SIZE;
2942 new_geometry->min_width = requisition.width;
2943 new_geometry->min_height = requisition.height;
2946 if (*new_flags & GDK_HINT_MAX_SIZE)
2948 if (new_geometry->max_width < 0)
2949 new_geometry->max_width = requisition.width;
2951 new_geometry->max_width += extra_width;
2953 if (new_geometry->max_height < 0)
2954 new_geometry->max_width = requisition.height;
2956 new_geometry->max_height += extra_height;
2958 else if (!window->allow_grow)
2960 *new_flags |= GDK_HINT_MAX_SIZE;
2962 new_geometry->max_width = requisition.width;
2963 new_geometry->max_height = requisition.height;
2966 *new_flags |= GDK_HINT_WIN_GRAVITY;
2967 new_geometry->win_gravity = window->gravity;
2970 /* Compute a new position for the window based on a new
2971 * size. *x and *y will be set to the new coordinates. Returns
2972 * TRUE if the window needs to be moved (and thus x and y got
2976 gtk_window_compute_reposition (GtkWindow *window,
2982 GtkWidget *widget = GTK_WIDGET (window);
2983 GtkWindowPosition pos;
2984 GtkWidget *parent_widget;
2985 gboolean needs_move = FALSE;
2987 parent_widget = (GtkWidget*) window->transient_parent;
2989 pos = window->position;
2990 if (pos == GTK_WIN_POS_CENTER_ON_PARENT &&
2991 (parent_widget == NULL ||
2992 !GTK_WIDGET_MAPPED (parent_widget)))
2993 pos = GTK_WIN_POS_NONE;
2997 case GTK_WIN_POS_CENTER:
2998 case GTK_WIN_POS_CENTER_ALWAYS:
2999 if (window->use_uposition)
3001 gint screen_width = gdk_screen_width ();
3002 gint screen_height = gdk_screen_height ();
3004 *x = (screen_width - new_width) / 2;
3005 *y = (screen_height - new_height) / 2;
3010 case GTK_WIN_POS_CENTER_ON_PARENT:
3011 if (window->use_uposition)
3014 gdk_window_get_origin (parent_widget->window,
3017 *x = ox + (parent_widget->allocation.width - new_width) / 2;
3018 *y = oy + (parent_widget->allocation.height - new_height) / 2;
3023 case GTK_WIN_POS_MOUSE:
3024 if (window->use_uposition)
3026 gint screen_width = gdk_screen_width ();
3027 gint screen_height = gdk_screen_height ();
3029 gdk_window_get_pointer (NULL, x, y, NULL);
3030 *x -= new_width / 2;
3031 *y -= new_height / 2;
3032 *x = CLAMP (*x, 0, screen_width - new_width);
3033 *y = CLAMP (*y, 0, screen_height - new_height);
3038 if (window->use_uposition)
3040 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3042 if (aux_info && aux_info->x_set && aux_info->y_set)
3054 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, TRUE);
3056 /* we handle necessary window positioning by hand here,
3057 * so we can coalesce the window movement with possible
3058 * resizes to get only one configure event.
3060 aux_info->x_set = TRUE;
3061 aux_info->y_set = TRUE;
3064 window->use_uposition = FALSE;
3070 /***********************
3071 * Redrawing functions *
3072 ***********************/
3075 gtk_window_paint (GtkWidget *widget,
3078 gtk_paint_flat_box (widget->style, widget->window, GTK_STATE_NORMAL,
3079 GTK_SHADOW_NONE, area, widget, "base", 0, 0, -1, -1);
3083 gtk_window_expose (GtkWidget *widget,
3084 GdkEventExpose *event)
3086 g_return_val_if_fail (widget != NULL, FALSE);
3087 g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE);
3088 g_return_val_if_fail (event != NULL, FALSE);
3090 if (!GTK_WIDGET_APP_PAINTABLE (widget))
3091 gtk_window_paint (widget, &event->area);
3093 if (GTK_WIDGET_CLASS (parent_class)->expose_event)
3094 return GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
3100 * gtk_window_set_has_frame:
3101 * @window: a #GtkWindow
3103 * If this function is called on a window before it is realized
3104 * or showed it will have a "frame" window around widget-window,
3105 * accessible in window->frame. Using the signal frame_event
3106 * you can recieve all events targeted at the frame.
3108 * This function is used by the linux-fb port to implement managed
3109 * windows, but it could concievably be used by X-programs that
3110 * want to do their own window decorations.
3113 gtk_window_set_has_frame (GtkWindow *window)
3115 g_return_if_fail (window != NULL);
3116 g_return_if_fail (GTK_IS_WINDOW (window));
3117 g_return_if_fail (!GTK_WIDGET_REALIZED (window));
3119 window->has_frame = TRUE;
3123 * gtk_window_set_frame_dimensions:
3124 * @window: a #GtkWindow that has a frame
3125 * @left: The width of the left border
3126 * @top: The height of the top border
3127 * @right: The width of the right border
3128 * @bottom: The height of the bottom border
3130 * For windows with frames (see #gtk_window_set_has_frame) this function
3131 * can be used to change the size of the frame border.
3134 gtk_window_set_frame_dimensions (GtkWindow *window,
3140 GtkWidget *widget = GTK_WIDGET (window);
3142 g_return_if_fail (window != NULL);
3143 g_return_if_fail (GTK_IS_WINDOW (window));
3145 if (window->frame_left == left &&
3146 window->frame_top == top &&
3147 window->frame_right == right &&
3148 window->frame_bottom == bottom)
3151 window->frame_left = left;
3152 window->frame_top = top;
3153 window->frame_right = right;
3154 window->frame_bottom = bottom;
3156 if (GTK_WIDGET_REALIZED (widget) && window->frame)
3158 gint width = widget->allocation.width + left + right;
3159 gint height = widget->allocation.height + top + bottom;
3160 gdk_window_resize (window->frame, width, height);
3161 gtk_decorated_window_move_resize_window (window,
3163 widget->allocation.width,
3164 widget->allocation.height);
3171 * gtk_window_present:
3172 * @window: a #GtkWindow
3174 * Presents a window to the user. This may mean raising the window
3175 * in the stacking order, deiconifying it, moving it to the current
3176 * desktop, and/or giving it the keyboard focus, possibly dependent
3177 * on the user's platform, window manager, and preferences.
3179 * If @window is hidden, this function calls gtk_widget_show()
3182 * This function should be used when the user tries to open a window
3183 * that's already open. Say for example the preferences dialog is
3184 * currently open, and the user chooses Preferences from the menu
3185 * a second time; use gtk_window_present() to move the already-open dialog
3186 * where the user can see it.
3190 gtk_window_present (GtkWindow *window)
3194 g_return_if_fail (GTK_IS_WINDOW (window));
3196 widget = GTK_WIDGET (window);
3198 if (GTK_WIDGET_VISIBLE (window))
3200 g_assert (widget->window != NULL);
3202 gdk_window_show (widget->window);
3204 /* note that gdk_window_focus() will also move the window to
3205 * the current desktop, for WM spec compliant window managers.
3207 gdk_window_focus (widget->window,
3208 gtk_get_current_event_time ());
3212 gtk_widget_show (widget);
3217 * gtk_window_iconify:
3218 * @window: a #GtkWindow
3220 * Asks to iconify @window. Note that you shouldn't assume the window
3221 * is definitely iconified afterward, because other entities (e.g. the
3222 * user or window manager) could deiconify it again, or there may not
3223 * be a window manager in which case iconification isn't possible,
3224 * etc. But normally the window will end up iconified. Just don't write
3225 * code that crashes if not.
3227 * It's permitted to call this function before showing a window,
3228 * in which case the window will be iconified before it ever appears
3231 * You can track iconification via the "window_state_event" signal
3236 gtk_window_iconify (GtkWindow *window)
3239 GdkWindow *toplevel;
3241 g_return_if_fail (GTK_IS_WINDOW (window));
3243 widget = GTK_WIDGET (window);
3245 window->iconify_initially = TRUE;
3248 toplevel = window->frame;
3250 toplevel = widget->window;
3252 if (toplevel != NULL)
3253 gdk_window_iconify (toplevel);
3257 * gtk_window_deiconify:
3258 * @window: a #GtkWindow
3260 * Asks to deiconify @window. Note that you shouldn't assume the
3261 * window is definitely deiconified afterward, because other entities
3262 * (e.g. the user or window manager) could iconify it again before
3263 * your code which assumes deiconification gets to run.
3265 * You can track iconification via the "window_state_event" signal
3269 gtk_window_deiconify (GtkWindow *window)
3272 GdkWindow *toplevel;
3274 g_return_if_fail (GTK_IS_WINDOW (window));
3276 widget = GTK_WIDGET (window);
3278 window->iconify_initially = FALSE;
3281 toplevel = window->frame;
3283 toplevel = widget->window;
3285 if (toplevel != NULL)
3286 gdk_window_deiconify (toplevel);
3291 * @window: a #GtkWindow
3293 * Asks to stick @window, which means that it will appear on all user
3294 * desktops. Note that you shouldn't assume the window is definitely
3295 * stuck afterward, because other entities (e.g. the user or window
3296 * manager) could unstick it again, and some window managers do not
3297 * support sticking windows. But normally the window will end up
3298 * stuck. Just don't write code that crashes if not.
3300 * It's permitted to call this function before showing a window.
3302 * You can track stickiness via the "window_state_event" signal
3307 gtk_window_stick (GtkWindow *window)
3310 GdkWindow *toplevel;
3312 g_return_if_fail (GTK_IS_WINDOW (window));
3314 widget = GTK_WIDGET (window);
3316 window->stick_initially = TRUE;
3319 toplevel = window->frame;
3321 toplevel = widget->window;
3323 if (toplevel != NULL)
3324 gdk_window_stick (toplevel);
3328 * gtk_window_unstick:
3329 * @window: a #GtkWindow
3331 * Asks to unstick @window, which means that it will appear on only
3332 * one of the user's desktops. Note that you shouldn't assume the
3333 * window is definitely unstuck afterward, because other entities
3334 * (e.g. the user or window manager) could stick it again. But
3335 * normally the window will end up stuck. Just don't write code that
3338 * You can track stickiness via the "window_state_event" signal
3343 gtk_window_unstick (GtkWindow *window)
3346 GdkWindow *toplevel;
3348 g_return_if_fail (GTK_IS_WINDOW (window));
3350 widget = GTK_WIDGET (window);
3352 window->stick_initially = FALSE;
3355 toplevel = window->frame;
3357 toplevel = widget->window;
3359 if (toplevel != NULL)
3360 gdk_window_unstick (toplevel);
3364 * gtk_window_maximize:
3365 * @window: a #GtkWindow
3367 * Asks to maximize @window, so that it becomes full-screen. Note that
3368 * you shouldn't assume the window is definitely maximized afterward,
3369 * because other entities (e.g. the user or window manager) could
3370 * unmaximize it again, and not all window managers support
3371 * maximization. But normally the window will end up maximized. Just
3372 * don't write code that crashes if not.
3374 * It's permitted to call this function before showing a window,
3375 * in which case the window will be maximized when it appears onscreen
3378 * You can track maximization via the "window_state_event" signal
3383 gtk_window_maximize (GtkWindow *window)
3386 GdkWindow *toplevel;
3388 g_return_if_fail (GTK_IS_WINDOW (window));
3390 widget = GTK_WIDGET (window);
3392 window->maximize_initially = TRUE;
3395 toplevel = window->frame;
3397 toplevel = widget->window;
3399 if (toplevel != NULL)
3400 gdk_window_maximize (toplevel);
3404 * gtk_window_unmaximize:
3405 * @window: a #GtkWindow
3407 * Asks to unmaximize @window. Note that you shouldn't assume the
3408 * window is definitely unmaximized afterward, because other entities
3409 * (e.g. the user or window manager) could maximize it again, and not
3410 * all window managers honor requests to unmaximize. But normally the
3411 * window will end up unmaximized. Just don't write code that crashes
3414 * You can track maximization via the "window_state_event" signal
3419 gtk_window_unmaximize (GtkWindow *window)
3422 GdkWindow *toplevel;
3424 g_return_if_fail (GTK_IS_WINDOW (window));
3426 widget = GTK_WIDGET (window);
3428 window->maximize_initially = FALSE;
3431 toplevel = window->frame;
3433 toplevel = widget->window;
3435 if (toplevel != NULL)
3436 gdk_window_unmaximize (toplevel);
3440 * gtk_window_set_resizeable:
3441 * @window: a #GtkWindow
3442 * @resizeable: %TRUE if the user can resize this window
3444 * Sets whether the user can resize a window. Windows are user resizeable
3448 gtk_window_set_resizeable (GtkWindow *window,
3449 gboolean resizeable)
3451 g_return_if_fail (GTK_IS_WINDOW (window));
3453 gtk_window_set_policy (window, FALSE, resizeable, FALSE);
3457 * gtk_window_get_resizeable:
3458 * @window: a #GtkWindow
3460 * Gets the value set by gtk_window_set_resizeable().
3462 * Return value: %TRUE if the user can resize the window
3465 gtk_window_get_resizeable (GtkWindow *window)
3467 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
3469 /* allow_grow is most likely to indicate the semantic concept we
3470 * mean by "resizeable" (and will be a reliable indicator if
3471 * set_policy() hasn't been called)
3473 return window->allow_grow;
3477 * gtk_window_set_gravity:
3478 * @window: a #GtkWindow
3479 * @gravity: window gravity
3481 * Window gravity defines the "reference point" to be used when
3482 * positioning or resizing a window. Calls to
3483 * gtk_widget_set_uposition() will position a different point on the
3484 * window depending on the window gravity. When the window changes size
3485 * the reference point determined by the window's gravity will stay in
3488 * See #GdkGravity for full details. To briefly summarize,
3489 * #GDK_GRAVITY_NORTH_WEST means that the reference point is the
3490 * northwest (top left) corner of the window
3491 * frame. #GDK_GRAVITY_SOUTH_EAST would be the bottom right corner of
3492 * the frame, and so on. If you want to position the window contents,
3493 * rather than the window manager's frame, #GDK_GRAVITY_STATIC moves
3494 * the reference point to the northwest corner of the #GtkWindow
3497 * The default window gravity is #GDK_GRAVITY_NORTH_WEST.
3501 gtk_window_set_gravity (GtkWindow *window,
3504 g_return_if_fail (GTK_IS_WINDOW (window));
3506 if (gravity != window->gravity)
3508 window->gravity = gravity;
3510 /* gtk_window_move_resize() will adapt gravity
3512 gtk_widget_queue_resize (GTK_WIDGET (window));
3517 * gtk_window_get_gravity:
3518 * @window: a #GtkWindow
3520 * Gets the value set by gtk_window_set_gravity().
3522 * Return value: window gravity
3525 gtk_window_get_gravity (GtkWindow *window)
3527 g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
3529 return window->gravity;
3533 * gtk_window_begin_resize_drag:
3534 * @window: a #GtkWindow
3535 * @button: mouse button that initiated the drag
3536 * @edge: position of the resize control
3537 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3538 * @root_y: Y position where the user clicked to initiate the drag
3539 * @timestamp: timestamp from the click event that initiated the drag
3541 * Starts resizing a window. This function is used if an application
3542 * has window resizing controls. When GDK can support it, the resize
3543 * will be done using the standard mechanism for the window manager or
3544 * windowing system. Otherwise, GDK will try to emulate window
3545 * resizing, potentially not all that well, depending on the windowing system.
3549 gtk_window_begin_resize_drag (GtkWindow *window,
3557 GdkWindow *toplevel;
3559 g_return_if_fail (GTK_IS_WINDOW (window));
3560 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3562 widget = GTK_WIDGET (window);
3565 toplevel = window->frame;
3567 toplevel = widget->window;
3569 gdk_window_begin_resize_drag (toplevel,
3577 * gtk_window_begin_move_drag:
3578 * @window: a #GtkWindow
3579 * @button: mouse button that initiated the drag
3580 * @root_x: X position where the user clicked to initiate the drag, in root window coordinates
3581 * @root_y: Y position where the user clicked to initiate the drag
3582 * @timestamp: timestamp from the click event that initiated the drag
3584 * Starts moving a window. This function is used if an application
3585 * has window movement grips. When GDK can support it, the window movement
3586 * will be done using the standard mechanism for the window manager or
3587 * windowing system. Otherwise, GDK will try to emulate window
3588 * movement, potentially not all that well, depending on the windowing system.
3592 gtk_window_begin_move_drag (GtkWindow *window,
3599 GdkWindow *toplevel;
3601 g_return_if_fail (GTK_IS_WINDOW (window));
3602 g_return_if_fail (GTK_WIDGET_VISIBLE (window));
3604 widget = GTK_WIDGET (window);
3607 toplevel = window->frame;
3609 toplevel = widget->window;
3611 gdk_window_begin_move_drag (toplevel,