gtkwindow.c 241 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Elliot Lee's avatar
Elliot Lee committed
2 3 4
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27
#include "config.h"
Elliot Lee's avatar
Elliot Lee committed
28
#include <string.h>
29 30
#include <stdlib.h>
#include <errno.h>
Elliot Lee's avatar
Elliot Lee committed
31 32 33
#include <limits.h>
#include "gdk/gdk.h"
#include "gdk/gdkkeysyms.h"
34

35 36
#include "gtkintl.h"

37
#include "gtkprivate.h"
38
#include "gtkrc.h"
Elliot Lee's avatar
Elliot Lee committed
39
#include "gtkwindow.h"
40
#include "gtkwindow-decorate.h"
Tim Janik's avatar
Tim Janik committed
41
#include "gtkbindings.h"
42
#include "gtkkeyhash.h"
43
#include "gtkmain.h"
44
#include "gtkmnemonichash.h"
45
#include "gtkiconfactory.h"
46
#include "gtkicontheme.h"
47
#include "gtkmarshalers.h"
48
#include "gtkplug.h"
49
#include "gtkbuildable.h"
50
#include "gtkalias.h"
Elliot Lee's avatar
Elliot Lee committed
51

52 53 54 55
#ifdef GDK_WINDOWING_X11
#include "x11/gdkx.h"
#endif

Elliot Lee's avatar
Elliot Lee committed
56
enum {
57
  SET_FOCUS,
58
  FRAME_EVENT,
59 60
  ACTIVATE_FOCUS,
  ACTIVATE_DEFAULT,
61
  KEYS_CHANGED,
Elliot Lee's avatar
Elliot Lee committed
62 63
  LAST_SIGNAL
};
64

65
enum {
66 67 68 69 70
  PROP_0,

  /* Construct */
  PROP_TYPE,

Havoc Pennington's avatar
Havoc Pennington committed
71
  /* Normal Props */
72
  PROP_TITLE,
73
  PROP_ROLE,
74 75
  PROP_ALLOW_SHRINK,
  PROP_ALLOW_GROW,
76
  PROP_RESIZABLE,
77 78 79 80 81
  PROP_MODAL,
  PROP_WIN_POS,
  PROP_DEFAULT_WIDTH,
  PROP_DEFAULT_HEIGHT,
  PROP_DESTROY_WITH_PARENT,
Havoc Pennington's avatar
Havoc Pennington committed
82
  PROP_ICON,
83
  PROP_ICON_NAME,
84
  PROP_SCREEN,
85 86 87
  PROP_TYPE_HINT,
  PROP_SKIP_TASKBAR_HINT,
  PROP_SKIP_PAGER_HINT,
88
  PROP_URGENCY_HINT,
89
  PROP_ACCEPT_FOCUS,
90
  PROP_FOCUS_ON_MAP,
91
  PROP_DECORATED,
92
  PROP_DELETABLE,
93
  PROP_GRAVITY,
Alexander Larsson's avatar
Alexander Larsson committed
94
  PROP_TRANSIENT_FOR,
95
  PROP_OPACITY,
96
  
97 98 99
  /* Readonly properties */
  PROP_IS_ACTIVE,
  PROP_HAS_TOPLEVEL_FOCUS,
Havoc Pennington's avatar
Havoc Pennington committed
100
  
101 102 103
  /* Writeonly properties */
  PROP_STARTUP_ID,
  
104
  LAST_ARG
105
};
Elliot Lee's avatar
Elliot Lee committed
106

Havoc Pennington's avatar
Havoc Pennington committed
107 108 109 110 111
typedef struct
{
  GList     *icon_list;
  GdkPixmap *icon_pixmap;
  GdkPixmap *icon_mask;
112
  gchar     *icon_name;
Havoc Pennington's avatar
Havoc Pennington committed
113 114 115
  guint      realized : 1;
  guint      using_default_icon : 1;
  guint      using_parent_icon : 1;
116
  guint      using_themed_icon : 1;
Havoc Pennington's avatar
Havoc Pennington committed
117 118
} GtkWindowIconInfo;

119
typedef struct {
120 121
  GdkGeometry    geometry; /* Last set of geometry hints we set */
  GdkWindowHints flags;
Havoc Pennington's avatar
Havoc Pennington committed
122
  GdkRectangle   configure_request;
123 124
} GtkWindowLastGeometryInfo;

125 126
struct _GtkWindowGeometryInfo
{
127 128 129 130 131
  /* Properties that the app has set on the window
   */
  GdkGeometry    geometry;	/* Geometry hints */
  GdkWindowHints mask;
  GtkWidget     *widget;	/* subwidget to which hints apply */
Havoc Pennington's avatar
Havoc Pennington committed
132 133 134 135 136
  /* from last gtk_window_resize () - if > 0, indicates that
   * we should resize to this size.
   */
  gint           resize_width;  
  gint           resize_height;
137

Havoc Pennington's avatar
Havoc Pennington committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
  /* From last gtk_window_move () prior to mapping -
   * only used if initial_pos_set
   */
  gint           initial_x;
  gint           initial_y;
  
  /* Default size - used only the FIRST time we map a window,
   * only if > 0.
   */
  gint           default_width; 
  gint           default_height;
  /* whether to use initial_x, initial_y */
  guint          initial_pos_set : 1;
  /* CENTER_ALWAYS or other position constraint changed since
   * we sent the last configure request.
   */
  guint          position_constraints_changed : 1;
155 156 157 158 159 160

  /* if true, default_width, height come from gtk_window_parse_geometry,
   * and thus should be multiplied by the increments and affect the
   * geometry widget only
   */
  guint          default_is_geometry : 1;
Havoc Pennington's avatar
Havoc Pennington committed
161
  
162
  GtkWindowLastGeometryInfo last;
163
};
164

165 166
#define GTK_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_WINDOW, GtkWindowPrivate))

167 168 169 170
typedef struct _GtkWindowPrivate GtkWindowPrivate;

struct _GtkWindowPrivate
{
171 172
  GtkMnemonicHash *mnemonic_hash;
  
173 174
  guint above_initially : 1;
  guint below_initially : 1;
175 176 177
  guint fullscreen_initially : 1;
  guint skips_taskbar : 1;
  guint skips_pager : 1;
178
  guint urgent : 1;
179
  guint accept_focus : 1;
180
  guint focus_on_map : 1;
181
  guint deletable : 1;
182
  guint transient_parent_group : 1;
183 184

  guint reset_type_hint : 1;
185
  guint opacity_set : 1;
186
  guint builder_visible : 1;
187

188
  GdkWindowTypeHint type_hint;
189

190 191
  gdouble opacity;

192
  gchar *startup_id;
193
};
194

Tim Janik's avatar
Tim Janik committed
195
static void gtk_window_dispose            (GObject           *object);
196
static void gtk_window_destroy            (GtkObject         *object);
197
static void gtk_window_finalize           (GObject           *object);
Elliot Lee's avatar
Elliot Lee committed
198 199 200 201 202
static void gtk_window_show               (GtkWidget         *widget);
static void gtk_window_hide               (GtkWidget         *widget);
static void gtk_window_map                (GtkWidget         *widget);
static void gtk_window_unmap              (GtkWidget         *widget);
static void gtk_window_realize            (GtkWidget         *widget);
203
static void gtk_window_unrealize          (GtkWidget         *widget);
Elliot Lee's avatar
Elliot Lee committed
204 205 206 207
static void gtk_window_size_request       (GtkWidget         *widget,
					   GtkRequisition    *requisition);
static void gtk_window_size_allocate      (GtkWidget         *widget,
					   GtkAllocation     *allocation);
208 209
static gint gtk_window_event              (GtkWidget *widget,
					   GdkEvent *event);
210 211
static gboolean gtk_window_map_event      (GtkWidget         *widget,
                                           GdkEventAny       *event);
212
static gboolean gtk_window_frame_event    (GtkWindow *window,
213
					   GdkEvent *event);
Elliot Lee's avatar
Elliot Lee committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
static gint gtk_window_configure_event    (GtkWidget         *widget,
					   GdkEventConfigure *event);
static gint gtk_window_key_press_event    (GtkWidget         *widget,
					   GdkEventKey       *event);
static gint gtk_window_key_release_event  (GtkWidget         *widget,
					   GdkEventKey       *event);
static gint gtk_window_enter_notify_event (GtkWidget         *widget,
					   GdkEventCrossing  *event);
static gint gtk_window_leave_notify_event (GtkWidget         *widget,
					   GdkEventCrossing  *event);
static gint gtk_window_focus_in_event     (GtkWidget         *widget,
					   GdkEventFocus     *event);
static gint gtk_window_focus_out_event    (GtkWidget         *widget,
					   GdkEventFocus     *event);
static gint gtk_window_client_event	  (GtkWidget	     *widget,
229
					   GdkEventClient    *event);
230
static void gtk_window_check_resize       (GtkContainer      *container);
231
static gint gtk_window_focus              (GtkWidget        *widget,
232
				           GtkDirectionType  direction);
233
static void gtk_window_real_set_focus     (GtkWindow         *window,
234
					   GtkWidget         *focus);
235

236 237 238 239
static void gtk_window_real_activate_default (GtkWindow         *window);
static void gtk_window_real_activate_focus   (GtkWindow         *window);
static void gtk_window_move_focus            (GtkWindow         *window,
                                              GtkDirectionType   dir);
240
static void gtk_window_keys_changed          (GtkWindow         *window);
241 242 243 244
static void gtk_window_paint                 (GtkWidget         *widget,
					      GdkRectangle      *area);
static gint gtk_window_expose                (GtkWidget         *widget,
					      GdkEventExpose    *event);
245 246 247 248 249 250
static void gtk_window_unset_transient_for         (GtkWindow  *window);
static void gtk_window_transient_parent_realized   (GtkWidget  *parent,
						    GtkWidget  *window);
static void gtk_window_transient_parent_unrealized (GtkWidget  *parent,
						    GtkWidget  *window);

251 252
static GdkScreen *gtk_window_check_screen (GtkWindow *window);

Havoc Pennington's avatar
Havoc Pennington committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
static GtkWindowGeometryInfo* gtk_window_get_geometry_info         (GtkWindow    *window,
                                                                    gboolean      create);

static void     gtk_window_move_resize               (GtkWindow    *window);
static gboolean gtk_window_compare_hints             (GdkGeometry  *geometry_a,
                                                      guint         flags_a,
                                                      GdkGeometry  *geometry_b,
                                                      guint         flags_b);
static void     gtk_window_constrain_size            (GtkWindow    *window,
                                                      GdkGeometry  *geometry,
                                                      guint         flags,
                                                      gint          width,
                                                      gint          height,
                                                      gint         *new_width,
                                                      gint         *new_height);
static void     gtk_window_constrain_position        (GtkWindow    *window,
                                                      gint          new_width,
                                                      gint          new_height,
                                                      gint         *x,
                                                      gint         *y);
static void     gtk_window_compute_hints             (GtkWindow    *window,
                                                      GdkGeometry  *new_geometry,
                                                      guint        *new_flags);
static void     gtk_window_compute_configure_request (GtkWindow    *window,
                                                      GdkRectangle *request,
                                                      GdkGeometry  *geometry,
                                                      guint        *flags);

static void     gtk_window_set_default_size_internal (GtkWindow    *window,
                                                      gboolean      change_width,
                                                      gint          width,
                                                      gboolean      change_height,
285 286
                                                      gint          height,
						      gboolean      is_geometry);
Elliot Lee's avatar
Elliot Lee committed
287

288 289 290 291
static void     update_themed_icon                    (GtkIconTheme *theme,
				                       GtkWindow    *window);
static GList   *icon_list_from_theme                  (GtkWidget    *widget,
						       const gchar  *name);
Havoc Pennington's avatar
Havoc Pennington committed
292 293
static void     gtk_window_realize_icon               (GtkWindow    *window);
static void     gtk_window_unrealize_icon             (GtkWindow    *window);
294 295 296 297

static void        gtk_window_notify_keys_changed (GtkWindow   *window);
static GtkKeyHash *gtk_window_get_key_hash        (GtkWindow   *window);
static void        gtk_window_free_key_hash       (GtkWindow   *window);
298 299
static void	   gtk_window_on_composited_changed (GdkScreen *screen,
						     GtkWindow *window);
300

301 302
static GSList      *toplevel_list = NULL;
static guint        window_signals[LAST_SIGNAL] = { 0 };
Havoc Pennington's avatar
Havoc Pennington committed
303
static GList       *default_icon_list = NULL;
304
static gchar       *default_icon_name = NULL;
305
static guint        default_icon_serial = 0;
306 307
static gboolean     disable_startup_notification = FALSE;
static gboolean     sent_startup_notification = FALSE;
Elliot Lee's avatar
Elliot Lee committed
308

309 310 311 312
static GQuark       quark_gtk_embedded = 0;
static GQuark       quark_gtk_window_key_hash = 0;
static GQuark       quark_gtk_window_default_icon_pixmap = 0;
static GQuark       quark_gtk_window_icon_info = 0;
313
static GQuark       quark_gtk_buildable_accels = 0;
314

315 316
static GtkBuildableIface *parent_buildable_iface;

317 318 319 320 321 322 323 324
static void gtk_window_set_property (GObject         *object,
				     guint            prop_id,
				     const GValue    *value,
				     GParamSpec      *pspec);
static void gtk_window_get_property (GObject         *object,
				     guint            prop_id,
				     GValue          *value,
				     GParamSpec      *pspec);
Elliot Lee's avatar
Elliot Lee committed
325

326 327
/* GtkBuildable */
static void gtk_window_buildable_interface_init  (GtkBuildableIface *iface);
328 329 330 331
static void gtk_window_buildable_set_buildable_property (GtkBuildable        *buildable,
							 GtkBuilder          *builder,
							 const gchar         *name,
							 const GValue        *value);
332 333
static void gtk_window_buildable_parser_finished (GtkBuildable     *buildable,
						  GtkBuilder       *builder);
334 335 336 337 338 339 340 341 342 343 344
static gboolean gtk_window_buildable_custom_tag_start (GtkBuildable  *buildable,
						       GtkBuilder    *builder,
						       GObject       *child,
						       const gchar   *tagname,
						       GMarkupParser *parser,
						       gpointer      *data);
static void gtk_window_buildable_custom_finished (GtkBuildable  *buildable,
						      GtkBuilder    *builder,
						      GObject       *child,
						      const gchar   *tagname,
						      gpointer       user_data);
345

346

347 348 349
G_DEFINE_TYPE_WITH_CODE (GtkWindow, gtk_window, GTK_TYPE_BIN,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
						gtk_window_buildable_interface_init))
Elliot Lee's avatar
Elliot Lee committed
350

351 352 353 354 355 356
static void
add_tab_bindings (GtkBindingSet    *binding_set,
		  GdkModifierType   modifiers,
		  GtkDirectionType  direction)
{
  gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
357
                                "move-focus", 1,
358 359
                                GTK_TYPE_DIRECTION_TYPE, direction);
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
360
                                "move-focus", 1,
361 362 363
                                GTK_TYPE_DIRECTION_TYPE, direction);
}

364 365 366 367 368 369 370 371
static void
add_arrow_bindings (GtkBindingSet    *binding_set,
		    guint             keysym,
		    GtkDirectionType  direction)
{
  guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
  
  gtk_binding_entry_add_signal (binding_set, keysym, 0,
372
                                "move-focus", 1,
373 374
                                GTK_TYPE_DIRECTION_TYPE, direction);
  gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
375
                                "move-focus", 1,
376 377
                                GTK_TYPE_DIRECTION_TYPE, direction);
  gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
378
                                "move-focus", 1,
379 380
                                GTK_TYPE_DIRECTION_TYPE, direction);
  gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
381
                                "move-focus", 1,
382 383 384
                                GTK_TYPE_DIRECTION_TYPE, direction);
}

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
static guint32
extract_time_from_startup_id (const gchar* startup_id)
{
  gchar *timestr = g_strrstr (startup_id, "_TIME");
  guint32 retval = GDK_CURRENT_TIME;

  if (timestr)
    {
      gchar *end;
      guint32 timestamp; 
    
      /* Skip past the "_TIME" part */
      timestr += 5;
    
      timestamp = strtoul (timestr, &end, 0);
      if (end != timestr && errno == 0)
        retval = timestamp;
    }

  return retval;
}

static gboolean
startup_id_is_fake (const gchar* startup_id)
{
  return strncmp (startup_id, "_TIME", 5) == 0;
}
412

Elliot Lee's avatar
Elliot Lee committed
413 414 415
static void
gtk_window_class_init (GtkWindowClass *klass)
{
416
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
Elliot Lee's avatar
Elliot Lee committed
417 418 419
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;
420 421
  GtkBindingSet *binding_set;
  
Elliot Lee's avatar
Elliot Lee committed
422 423 424
  object_class = (GtkObjectClass*) klass;
  widget_class = (GtkWidgetClass*) klass;
  container_class = (GtkContainerClass*) klass;
425
  
426 427 428 429
  quark_gtk_embedded = g_quark_from_static_string ("gtk-embedded");
  quark_gtk_window_key_hash = g_quark_from_static_string ("gtk-window-key-hash");
  quark_gtk_window_default_icon_pixmap = g_quark_from_static_string ("gtk-window-default-icon-pixmap");
  quark_gtk_window_icon_info = g_quark_from_static_string ("gtk-window-icon-info");
430
  quark_gtk_buildable_accels = g_quark_from_static_string ("gtk-window-buildable-accels");
431

Tim Janik's avatar
Tim Janik committed
432
  gobject_class->dispose = gtk_window_dispose;
433 434
  gobject_class->finalize = gtk_window_finalize;

435 436 437
  gobject_class->set_property = gtk_window_set_property;
  gobject_class->get_property = gtk_window_get_property;
  
438
  object_class->destroy = gtk_window_destroy;
Elliot Lee's avatar
Elliot Lee committed
439 440 441 442

  widget_class->show = gtk_window_show;
  widget_class->hide = gtk_window_hide;
  widget_class->map = gtk_window_map;
443
  widget_class->map_event = gtk_window_map_event;
Elliot Lee's avatar
Elliot Lee committed
444 445
  widget_class->unmap = gtk_window_unmap;
  widget_class->realize = gtk_window_realize;
446
  widget_class->unrealize = gtk_window_unrealize;
Elliot Lee's avatar
Elliot Lee committed
447 448 449 450 451 452 453 454 455 456
  widget_class->size_request = gtk_window_size_request;
  widget_class->size_allocate = gtk_window_size_allocate;
  widget_class->configure_event = gtk_window_configure_event;
  widget_class->key_press_event = gtk_window_key_press_event;
  widget_class->key_release_event = gtk_window_key_release_event;
  widget_class->enter_notify_event = gtk_window_enter_notify_event;
  widget_class->leave_notify_event = gtk_window_leave_notify_event;
  widget_class->focus_in_event = gtk_window_focus_in_event;
  widget_class->focus_out_event = gtk_window_focus_out_event;
  widget_class->client_event = gtk_window_client_event;
457
  widget_class->focus = gtk_window_focus;
458
  
459 460
  widget_class->expose_event = gtk_window_expose;
   
461
  container_class->check_resize = gtk_window_check_resize;
Elliot Lee's avatar
Elliot Lee committed
462

463
  klass->set_focus = gtk_window_real_set_focus;
464
  klass->frame_event = gtk_window_frame_event;
465

466 467 468
  klass->activate_default = gtk_window_real_activate_default;
  klass->activate_focus = gtk_window_real_activate_focus;
  klass->move_focus = gtk_window_move_focus;
469
  klass->keys_changed = gtk_window_keys_changed;
470
  
471 472
  g_type_class_add_private (gobject_class, sizeof (GtkWindowPrivate));
  
473 474 475 476
  /* Construct */
  g_object_class_install_property (gobject_class,
                                   PROP_TYPE,
                                   g_param_spec_enum ("type",
477 478
						      P_("Window Type"),
						      P_("The type of the window"),
479 480
						      GTK_TYPE_WINDOW_TYPE,
						      GTK_WINDOW_TOPLEVEL,
481
						      GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
Havoc Pennington's avatar
Havoc Pennington committed
482
  /* Regular Props */
483 484 485
  g_object_class_install_property (gobject_class,
                                   PROP_TITLE,
                                   g_param_spec_string ("title",
486 487
                                                        P_("Window Title"),
                                                        P_("The title of the window"),
488
                                                        NULL,
489
                                                        GTK_PARAM_READWRITE));
490

491 492 493
  g_object_class_install_property (gobject_class,
                                   PROP_ROLE,
                                   g_param_spec_string ("role",
494 495
							P_("Window Role"),
							P_("Unique identifier for the window to be used when restoring a session"),
496
							NULL,
497
							GTK_PARAM_READWRITE));
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
							
  /**
   * GtkWindow:startup-id:
   *
   * The :startup-id is a write-only property for setting window's
   * startup notification identifier. See gtk_window_set_startup_id()
   * for more details.
   *
   * Since: 2.12
   */							
  g_object_class_install_property (gobject_class,
                                   PROP_ROLE,
                                   g_param_spec_string ("startup-id",
							P_("Startup ID"),
							P_("Unique startup identifier for the window used by startup-notification"),
							NULL,
							GTK_PARAM_WRITABLE));
515

516 517
  g_object_class_install_property (gobject_class,
                                   PROP_ALLOW_SHRINK,
Matthias Clasen's avatar
x  
Matthias Clasen committed
518
                                   g_param_spec_boolean ("allow-shrink",
519
							 P_("Allow Shrink"),
520
							 /* xgettext:no-c-format */
521
							 P_("If TRUE, the window has no mimimum size. Setting this to TRUE is 99% of the time a bad idea"),
522
							 FALSE,
523
							 GTK_PARAM_READWRITE));
524 525 526

  g_object_class_install_property (gobject_class,
                                   PROP_ALLOW_GROW,
Matthias Clasen's avatar
x  
Matthias Clasen committed
527
                                   g_param_spec_boolean ("allow-grow",
528 529
							 P_("Allow Grow"),
							 P_("If TRUE, users can expand the window beyond its minimum size"),
530
							 TRUE,
531
							 GTK_PARAM_READWRITE));
532

533 534 535
  g_object_class_install_property (gobject_class,
                                   PROP_RESIZABLE,
                                   g_param_spec_boolean ("resizable",
536 537
							 P_("Resizable"),
							 P_("If TRUE, users can resize the window"),
538
							 TRUE,
539
							 GTK_PARAM_READWRITE));
540
  
541 542 543
  g_object_class_install_property (gobject_class,
                                   PROP_MODAL,
                                   g_param_spec_boolean ("modal",
544 545
							 P_("Modal"),
							 P_("If TRUE, the window is modal (other windows are not usable while this one is up)"),
546
							 FALSE,
547
							 GTK_PARAM_READWRITE));
548 549 550

  g_object_class_install_property (gobject_class,
                                   PROP_WIN_POS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
551
                                   g_param_spec_enum ("window-position",
552 553
						      P_("Window Position"),
						      P_("The initial position of the window"),
554 555
						      GTK_TYPE_WINDOW_POSITION,
						      GTK_WIN_POS_NONE,
556
						      GTK_PARAM_READWRITE));
557 558 559
 
  g_object_class_install_property (gobject_class,
                                   PROP_DEFAULT_WIDTH,
Matthias Clasen's avatar
x  
Matthias Clasen committed
560
                                   g_param_spec_int ("default-width",
561 562
						     P_("Default Width"),
						     P_("The default width of the window, used when initially showing the window"),
Havoc Pennington's avatar
Havoc Pennington committed
563
						     -1,
564
						     G_MAXINT,
Havoc Pennington's avatar
Havoc Pennington committed
565
						     -1,
566
						     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
567
  
568 569
  g_object_class_install_property (gobject_class,
                                   PROP_DEFAULT_HEIGHT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
570
                                   g_param_spec_int ("default-height",
571 572
						     P_("Default Height"),
						     P_("The default height of the window, used when initially showing the window"),
Havoc Pennington's avatar
Havoc Pennington committed
573
						     -1,
574
						     G_MAXINT,
Havoc Pennington's avatar
Havoc Pennington committed
575
						     -1,
576
						     GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
577
  
578 579
  g_object_class_install_property (gobject_class,
                                   PROP_DESTROY_WITH_PARENT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
580
                                   g_param_spec_boolean ("destroy-with-parent",
581 582
							 P_("Destroy with Parent"),
							 P_("If this window should be destroyed when the parent is destroyed"),
583
                                                         FALSE,
584
							 GTK_PARAM_READWRITE));
585

Havoc Pennington's avatar
Havoc Pennington committed
586 587 588
  g_object_class_install_property (gobject_class,
                                   PROP_ICON,
                                   g_param_spec_object ("icon",
589 590
                                                        P_("Icon"),
                                                        P_("Icon for this window"),
Havoc Pennington's avatar
Havoc Pennington committed
591
                                                        GDK_TYPE_PIXBUF,
592
                                                        GTK_PARAM_READWRITE));
Havoc Pennington's avatar
Havoc Pennington committed
593
  
594 595 596 597 598 599 600 601 602 603
  /**
   * GtkWindow:icon-name:
   *
   * The :icon-name property specifies the name of the themed icon to
   * use as the window icon. See #GtkIconTheme for more details.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
                                   PROP_ICON_NAME,
Matthias Clasen's avatar
x  
Matthias Clasen committed
604
                                   g_param_spec_string ("icon-name",
605 606 607
                                                        P_("Icon Name"),
                                                        P_("Name of the themed icon for this window"),
							NULL,
608
                                                        GTK_PARAM_READWRITE));
609
  
610 611 612
  g_object_class_install_property (gobject_class,
				   PROP_SCREEN,
				   g_param_spec_object ("screen",
613 614
 							P_("Screen"),
 							P_("The screen where this window will be displayed"),
615
							GDK_TYPE_SCREEN,
616
 							GTK_PARAM_READWRITE));
617

618 619
  g_object_class_install_property (gobject_class,
                                   PROP_IS_ACTIVE,
Matthias Clasen's avatar
x  
Matthias Clasen committed
620
                                   g_param_spec_boolean ("is-active",
621 622
							 P_("Is Active"),
							 P_("Whether the toplevel is the current active window"),
623
							 FALSE,
624
							 GTK_PARAM_READABLE));
625 626 627
  
  g_object_class_install_property (gobject_class,
                                   PROP_HAS_TOPLEVEL_FOCUS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
628
                                   g_param_spec_boolean ("has-toplevel-focus",
629 630
							 P_("Focus in Toplevel"),
							 P_("Whether the input focus is within this GtkWindow"),
631
							 FALSE,
632
							 GTK_PARAM_READABLE));
633 634 635

  g_object_class_install_property (gobject_class,
				   PROP_TYPE_HINT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
636
				   g_param_spec_enum ("type-hint",
637 638
                                                      P_("Type hint"),
                                                      P_("Hint to help the desktop environment understand what kind of window this is and how to treat it."),
639 640
                                                      GDK_TYPE_WINDOW_TYPE_HINT,
                                                      GDK_WINDOW_TYPE_HINT_NORMAL,
641
                                                      GTK_PARAM_READWRITE));
642 643 644

  g_object_class_install_property (gobject_class,
				   PROP_SKIP_TASKBAR_HINT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
645
				   g_param_spec_boolean ("skip-taskbar-hint",
646 647
                                                         P_("Skip taskbar"),
                                                         P_("TRUE if the window should not be in the task bar."),
648
                                                         FALSE,
649
                                                         GTK_PARAM_READWRITE));
650 651 652

  g_object_class_install_property (gobject_class,
				   PROP_SKIP_PAGER_HINT,
Matthias Clasen's avatar
x  
Matthias Clasen committed
653
				   g_param_spec_boolean ("skip-pager-hint",
654 655
                                                         P_("Skip pager"),
                                                         P_("TRUE if the window should not be in the pager."),
656
                                                         FALSE,
657
                                                         GTK_PARAM_READWRITE));  
658

659 660 661 662 663 664 665 666
  g_object_class_install_property (gobject_class,
				   PROP_URGENCY_HINT,
				   g_param_spec_boolean ("urgency-hint",
                                                         P_("Urgent"),
                                                         P_("TRUE if the window should be brought to the user's attention."),
                                                         FALSE,
                                                         GTK_PARAM_READWRITE));  

667 668 669 670 671 672 673 674 675
  /**
   * GtkWindow:accept-focus-hint:
   *
   * Whether the window should receive the input focus.
   *
   * Since: 2.4
   */
  g_object_class_install_property (gobject_class,
				   PROP_ACCEPT_FOCUS,
Matthias Clasen's avatar
x  
Matthias Clasen committed
676
				   g_param_spec_boolean ("accept-focus",
677 678
                                                         P_("Accept focus"),
                                                         P_("TRUE if the window should receive the input focus."),
679
                                                         TRUE,
680
                                                         GTK_PARAM_READWRITE));  
681

682 683 684 685 686 687 688 689 690
  /**
   * GtkWindow:focus-on-map-hint:
   *
   * Whether the window should receive the input focus when mapped.
   *
   * Since: 2.6
   */
  g_object_class_install_property (gobject_class,
				   PROP_FOCUS_ON_MAP,
Matthias Clasen's avatar
x  
Matthias Clasen committed
691
				   g_param_spec_boolean ("focus-on-map",
692 693 694
                                                         P_("Focus on map"),
                                                         P_("TRUE if the window should receive the input focus when mapped."),
                                                         TRUE,
695
                                                         GTK_PARAM_READWRITE));  
696

697 698 699 700 701 702 703 704 705 706
  /**
   * GtkWindow:decorated:
   *
   * Whether the window should be decorated by the window manager.
   *
   * Since: 2.4
   */
  g_object_class_install_property (gobject_class,
                                   PROP_DECORATED,
                                   g_param_spec_boolean ("decorated",
707 708
							 P_("Decorated"),
							 P_("Whether the window should be decorated by the window manager"),
709
							 TRUE,
710
							 GTK_PARAM_READWRITE));
711

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
  /**
   * GtkWindow:deletable:
   *
   * Whether the window frame should have a close button.
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
                                   PROP_DELETABLE,
                                   g_param_spec_boolean ("deletable",
							 P_("Deletable"),
							 P_("Whether the window frame should have a close button"),
							 TRUE,
							 GTK_PARAM_READWRITE));


728 729 730 731 732 733 734 735 736 737 738
  /**
   * GtkWindow:gravity:
   *
   * The window gravity of the window. See gtk_window_move() and #GdkGravity for
   * more details about window gravity.
   *
   * Since: 2.4
   */
  g_object_class_install_property (gobject_class,
                                   PROP_GRAVITY,
                                   g_param_spec_enum ("gravity",
739 740
						      P_("Gravity"),
						      P_("The window gravity of the window"),
741 742
						      GDK_TYPE_GRAVITY,
						      GDK_GRAVITY_NORTH_WEST,
743
						      GTK_PARAM_READWRITE));
744

Alexander Larsson's avatar
Alexander Larsson committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760

  /**
   * GtkWindow:transient-for:
   *
   * The transient parent of the window. See gtk_window_set_transient_for() for
   * more details about transient windows.
   *
   * Since: 2.10
   */
  g_object_class_install_property (gobject_class,
				   PROP_TRANSIENT_FOR,
				   g_param_spec_object ("transient-for",
							P_("Transient for Window"),
							P_("The transient parent of the dialog"),
							GTK_TYPE_WINDOW,
							GTK_PARAM_READWRITE| G_PARAM_CONSTRUCT));
Matthias Clasen's avatar
Matthias Clasen committed
761

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
  /**
   * GtkWindow:opacity:
   *
   * The requested opacity of the window. See gtk_window_set_opacity() for
   * more details about window opacity.
   *
   * Since: 2.12
   */
  g_object_class_install_property (gobject_class,
				   PROP_OPACITY,
				   g_param_spec_double ("opacity",
							P_("Opacity for Window"),
							P_("The opacity of the window, from 0 to 1"),
							0.0,
							1.0,
							1.0,
							GTK_PARAM_READWRITE));
Alexander Larsson's avatar
Alexander Larsson committed
779

780
  window_signals[SET_FOCUS] =
781
    g_signal_new (I_("set-focus"),
Manish Singh's avatar
Manish Singh committed
782
                  G_TYPE_FROM_CLASS (gobject_class),
783 784 785
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkWindowClass, set_focus),
                  NULL, NULL,
786
                  _gtk_marshal_VOID__OBJECT,
787 788
                  G_TYPE_NONE, 1,
                  GTK_TYPE_WIDGET);
789 790
  
  window_signals[FRAME_EVENT] =
791
    g_signal_new (I_("frame-event"),
Manish Singh's avatar
Manish Singh committed
792
                  G_TYPE_FROM_CLASS (gobject_class),
793 794 795
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET(GtkWindowClass, frame_event),
                  _gtk_boolean_handled_accumulator, NULL,
796
                  _gtk_marshal_BOOLEAN__BOXED,
797 798
                  G_TYPE_BOOLEAN, 1,
                  GDK_TYPE_EVENT);
799

Matthias Clasen's avatar
Matthias Clasen committed
800 801 802 803 804 805 806 807 808
  /**
   * GtkWindow::activate-focus:
   * @window: the window which received the signal
   *
   * The ::activate-default signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user activates the currently
   * focused widget of @window.
   */
809
  window_signals[ACTIVATE_FOCUS] =
810
    g_signal_new (I_("activate-focus"),
Manish Singh's avatar
Manish Singh committed
811
                  G_TYPE_FROM_CLASS (gobject_class),
812
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
Manish Singh's avatar
Manish Singh committed
813
                  G_STRUCT_OFFSET (GtkWindowClass, activate_focus),
814
                  NULL, NULL,
815
                  _gtk_marshal_VOID__VOID,
816 817
                  G_TYPE_NONE,
                  0);
818

Matthias Clasen's avatar
Matthias Clasen committed
819 820 821 822 823 824 825 826 827
  /**
   * GtkWindow::activate-default:
   * @window: the window which received the signal
   *
   * The ::activate-default signal is a
   * <link linkend="keybinding-signals">keybinding signal</link>
   * which gets emitted when the user activates the default widget
   * of @window.
   */
828
  window_signals[ACTIVATE_DEFAULT] =
829
    g_signal_new (I_("activate-default"),
Manish Singh's avatar
Manish Singh committed
830
                  G_TYPE_FROM_CLASS (gobject_class),
831
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
Manish Singh's avatar
Manish Singh committed
832
                  G_STRUCT_OFFSET (GtkWindowClass, activate_default),
833
                  NULL, NULL,
834
                  _gtk_marshal_VOID__VOID,
835 836
                  G_TYPE_NONE,
                  0);
837

Matthias Clasen's avatar
Matthias Clasen committed
838 839 840 841 842 843 844
  /**
   * GtkWindow::keys-changed:
   * @window: the window which received the signal
   *
   * The ::keys-changed signal gets emitted when the set of accelerators
   * or mnemonics that are associated with @window changes.
   */
845
  window_signals[KEYS_CHANGED] =
846
    g_signal_new (I_("keys-changed"),
Manish Singh's avatar
Manish Singh committed
847
                  G_TYPE_FROM_CLASS (gobject_class),
848
                  G_SIGNAL_RUN_FIRST,
Manish Singh's avatar
Manish Singh committed
849
                  G_STRUCT_OFFSET (GtkWindowClass, keys_changed),
850
                  NULL, NULL,
Manish Singh's avatar
Manish Singh committed
851
                  _gtk_marshal_VOID__VOID,
852 853
                  G_TYPE_NONE,
                  0);
854 855 856 857 858 859 860 861

  /*
   * Key bindings
   */

  binding_set = gtk_binding_set_by_class (klass);

  gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
862
                                "activate-focus", 0);
863
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
864
                                "activate-focus", 0);
865
  
866
  gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
867
                                "activate-default", 0);
868
  gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
869
                                "activate-default", 0);
870
  gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
871
                                "activate-default", 0);
872

873 874 875 876
  add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
  add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
  add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
  add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
877

878 879 880 881
  add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
  add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
  add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
  add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
Elliot Lee's avatar
Elliot Lee committed
882 883 884 885 886
}

static void
gtk_window_init (GtkWindow *window)
{
887
  GdkColormap *colormap;
888
  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
889
  
Elliot Lee's avatar
Elliot Lee committed
890
  GTK_WIDGET_UNSET_FLAGS (window, GTK_NO_WINDOW);
891
  GTK_WIDGET_SET_FLAGS (window, GTK_TOPLEVEL);
Elliot Lee's avatar
Elliot Lee committed
892

Owen Taylor's avatar
Owen Taylor committed
893 894
  GTK_PRIVATE_SET_FLAG (window, GTK_ANCHORED);

895 896
  gtk_container_set_resize_mode (GTK_CONTAINER (window), GTK_RESIZE_QUEUE);

Elliot Lee's avatar
Elliot Lee committed
897
  window->title = NULL;
898
  window->wmclass_name = g_strdup (g_get_prgname ());
899
  window->wmclass_class = g_strdup (gdk_get_program_class ());
900 901
  window->wm_role = NULL;
  window->geometry_info = NULL;
Elliot Lee's avatar
Elliot Lee committed
902 903 904
  window->type = GTK_WINDOW_TOPLEVEL;
  window->focus_widget = NULL;
  window->default_widget = NULL;
Havoc Pennington's avatar
Havoc Pennington committed
905
  window->configure_request_count = 0;
Elliot Lee's avatar
Elliot Lee committed
906 907
  window->allow_shrink = FALSE;
  window->allow_grow = TRUE;
Havoc Pennington's avatar
Havoc Pennington committed
908
  window->configure_notify_received = FALSE;
Elliot Lee's avatar
Elliot Lee committed
909
  window->position = GTK_WIN_POS_NONE;
Havoc Pennington's avatar
Havoc Pennington committed
910 911
  window->need_default_size = TRUE;
  window->need_default_position = TRUE;
912
  window->modal = FALSE;
913 914 915 916 917 918
  window->frame = NULL;
  window->has_frame = FALSE;
  window->frame_left = 0;
  window->frame_right = 0;
  window->frame_top = 0;
  window->frame_bottom = 0;
919
  window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
920
  window->gravity = GDK_GRAVITY_NORTH_WEST;
921
  window->decorated = TRUE;
922
  window->mnemonic_modifier = GDK_MOD1_MASK;
Owen Taylor's avatar
Owen Taylor committed
923
  window->screen = gdk_screen_get_default ();
924 925

  priv->accept_focus = TRUE;
926
  priv->focus_on_map = TRUE;
927
  priv->deletable = TRUE;
928
  priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
929
  priv->opacity = 1.0;
930
  priv->startup_id = NULL;
931

932 933 934 935
  colormap = _gtk_widget_peek_colormap ();
  if (colormap)
    gtk_widget_set_colormap (GTK_WIDGET (window), colormap);
  
936
  g_object_ref_sink (window);
937 938
  window->has_user_ref_count = TRUE;
  toplevel_list = g_slist_prepend (toplevel_list, window);
939 940 941

  gtk_decorated_window_init (window);

942
  g_signal_connect (window->screen, "composited-changed",
943
		    G_CALLBACK (gtk_window_on_composited_changed), window);
Elliot Lee's avatar
Elliot Lee committed
944 945 946
}

static void
947 948 949 950
gtk_window_set_property (GObject      *object,
			 guint         prop_id,
			 const GValue *value,
			 GParamSpec   *pspec)
Elliot Lee's avatar
Elliot Lee committed
951
{
952
  GtkWindow  *window;
Havoc Pennington's avatar
Havoc Pennington committed
953
  
954 955
  window = GTK_WINDOW (object);

956
  switch (prop_id)
Elliot Lee's avatar
Elliot Lee committed
957
    {
958 959
    case PROP_TYPE:
      window->type = g_value_get_enum (value);
960
      break;
961 962
    case PROP_TITLE:
      gtk_window_set_title (window, g_value_get_string (value));
963
      break;
964 965 966
    case PROP_ROLE:
      gtk_window_set_role (window, g_value_get_string (value));
      break;
967 968 969
    case PROP_STARTUP_ID:
      gtk_window_set_startup_id (window, g_value_get_string (value));
      break; 
970 971
    case PROP_ALLOW_SHRINK:
      window->allow_shrink = g_value_get_boolean (value);
972
      gtk_widget_queue_resize (GTK_WIDGET (window));
973
      break;
974 975
    case PROP_ALLOW_GROW:
      window->allow_grow = g_value_get_boolean (value);
976
      gtk_widget_queue_resize (GTK_WIDGET (window));
977 978 979 980 981
      g_object_notify (G_OBJECT (window), "resizable");
      break;
    case PROP_RESIZABLE:
      window->allow_grow = g_value_get_boolean (value);
      gtk_widget_queue_resize (GTK_WIDGET (window));
982
      g_object_notify (G_OBJECT (window), "allow-grow");
983
      break;
984 985
    case PROP_MODAL:
      gtk_window_set_modal (window, g_value_get_boolean (value));
986
      break;
987 988
    case PROP_WIN_POS:
      gtk_window_set_position (window, g_value_get_enum (value));
989
      break;
990
    case PROP_DEFAULT_WIDTH:
Havoc Pennington's avatar
Havoc Pennington committed
991 992
      gtk_window_set_default_size_internal (window,
                                            TRUE, g_value_get_int (value),
993
                                            FALSE, -1, FALSE);
994
      break;
995
    case PROP_DEFAULT_HEIGHT:
Havoc Pennington's avatar
Havoc Pennington committed
996 997
      gtk_window_set_default_size_internal (window,
                                            FALSE, -1,
998
                                            TRUE, g_value_get_int (value), FALSE);
999
      break;
1000 1001
    case PROP_DESTROY_WITH_PARENT:
      gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
1002
      break;
Havoc Pennington's avatar
Havoc Pennington committed
1003 1004 1005 1006
    case PROP_ICON:
      gtk_window_set_icon (window,
                           g_value_get_object (value));
      break;
1007 1008 1009
    case PROP_ICON_NAME:
      gtk_window_set_icon_name (window, g_value_get_string (value));
      break;
1010 1011 1012
    case PROP_SCREEN:
      gtk_window_set_screen (window, g_value_get_object (value));
      break;
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
    case PROP_TYPE_HINT:
      gtk_window_set_type_hint (window,
                                g_value_get_enum (value));
      break;
    case PROP_SKIP_TASKBAR_HINT:
      gtk_window_set_skip_taskbar_hint (window,
                                        g_value_get_boolean (value));
      break;
    case PROP_SKIP_PAGER_HINT:
      gtk_window_set_skip_pager_hint (window,
                                      g_value_get_boolean (value));
      break;
1025 1026 1027 1028
    case PROP_URGENCY_HINT:
      gtk_window_set_urgency_hint (window,
				   g_value_get_boolean (value));
      break;
1029 1030 1031 1032
    case PROP_ACCEPT_FOCUS:
      gtk_window_set_accept_focus (window,
				   g_value_get_boolean (value));
      break;
1033 1034 1035 1036
    case PROP_FOCUS_ON_MAP:
      gtk_window_set_focus_on_map (window,
				   g_value_get_boolean (value));
      break;
1037 1038 1039
    case PROP_DECORATED:
      gtk_window_set_decorated (window, g_value_get_boolean (value));
      break;
1040 1041 1042
    case PROP_DELETABLE:
      gtk_window_set_deletable (window, g_value_get_boolean (value));
      break;
1043 1044 1045
    case PROP_GRAVITY:
      gtk_window_set_gravity (window, g_value_get_enum (value));
      break;
Alexander Larsson's avatar
Alexander Larsson committed
1046 1047 1048
    case PROP_TRANSIENT_FOR:
      gtk_window_set_transient_for (window, g_value_get_object (value));
      break;
1049 1050 1051
    case PROP_OPACITY:
      gtk_window_set_opacity (window, g_value_get_double (value));
      break;
Tim Janik's avatar
Tim Janik committed
1052
    default:
1053
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Tim Janik's avatar
Tim Janik committed
1054
      break;
Elliot Lee's avatar
Elliot Lee committed
1055 1056 1057
    }
}

1058
static void
1059 1060 1061 1062
gtk_window_get_property (GObject      *object,
			 guint         prop_id,
			 GValue       *value,
			 GParamSpec   *pspec)
1063
{
1064
  GtkWindow  *window;
1065
  GtkWindowPrivate *priv;
1066 1067

  window = GTK_WINDOW (object);
1068 1069
  priv = GTK_WINDOW_GET_PRIVATE (window);
  
1070
  switch (prop_id)
1071
    {
1072
      GtkWindowGeometryInfo *info;
1073 1074
    case PROP_TYPE:
      g_value_set_enum (value, window->type);
1075
      break;
1076 1077 1078
    case PROP_ROLE:
      g_value_set_string (value, window->wm_role);
      break;
1079 1080
    case PROP_TITLE:
      g_value_set_string (value, window->title);
1081
      break;
1082 1083
    case PROP_ALLOW_SHRINK:
      g_value_set_boolean (value, window->allow_shrink);
1084
      break;
1085 1086
    case PROP_ALLOW_GROW:
      g_value_set_boolean (value, window->allow_grow);
1087
      break;
1088 1089 1090
    case PROP_RESIZABLE:
      g_value_set_boolean (value, window->allow_grow);
      break;
1091 1092
    case PROP_MODAL:
      g_value_set_boolean (value, window->modal);
1093
      break;
1094 1095
    case PROP_WIN_POS:
      g_value_set_enum (value, window->position);
1096
      break;
1097
    case PROP_DEFAULT_WIDTH:
1098 1099
      info = gtk_window_get_geometry_info (window, FALSE);
      if (!info)
Havoc Pennington's avatar
Havoc Pennington committed
1100
	g_value_set_int (value, -1);
1101
      else
Havoc Pennington's avatar
Havoc Pennington committed
1102
	g_value_set_int (value, info->default_width);
1103
      break;
1104
    case PROP_DEFAULT_HEIGHT:
1105 1106
      info = gtk_window_get_geometry_info (window, FALSE);
      if (!info)
Havoc Pennington's avatar
Havoc Pennington committed
1107
	g_value_set_int (value, -1);
1108
      else
Havoc Pennington's avatar
Havoc Pennington committed
1109
	g_value_set_int (value, info->default_height);
1110
      break;
1111 1112
    case PROP_DESTROY_WITH_PARENT:
      g_value_set_boolean (value, window->destroy_with_parent);
1113
      break;
Havoc Pennington's avatar
Havoc Pennington committed
1114
    case PROP_ICON:
1115
      g_value_set_object (value, gtk_window_get_icon (window));
Havoc Pennington's avatar
Havoc Pennington committed
1116
      break;
1117 1118 1119
    case PROP_ICON_NAME:
      g_value_set_string (value, gtk_window_get_icon_name (window));
      break;
1120 1121 1122
    case PROP_SCREEN:
      g_value_set_object (value, window->screen);
      break;
1123 1124 1125 1126 1127 1128
    case PROP_IS_ACTIVE:
      g_value_set_boolean (value, window->is_active);
      break;
    case PROP_HAS_TOPLEVEL_FOCUS:
      g_value_set_boolean (value, window->has_toplevel_focus);
      break;
1129
    case PROP_TYPE_HINT:
1130
      g_value_set_enum (value, priv->type_hint);
1131 1132 1133 1134 1135 1136 1137 1138 1139
      break;
    case PROP_SKIP_TASKBAR_HINT:
      g_value_set_boolean (value,
                           gtk_window_get_skip_taskbar_hint (window));
      break;
    case PROP_SKIP_PAGER_HINT:
      g_value_set_boolean (value,
                           gtk_window_get_skip_pager_hint (window));
      break;
1140 1141 1142 1143
    case PROP_URGENCY_HINT:
      g_value_set_boolean (value,
                           gtk_window_get_urgency_hint (window));
      break;
1144 1145 1146 1147
    case PROP_ACCEPT_FOCUS:
      g_value_set_boolean (value,
                           gtk_window_get_accept_focus (window));
      break;
1148 1149 1150 1151
    case PROP_FOCUS_ON_MAP:
      g_value_set_boolean (value,
                           gtk_window_get_focus_on_map (window));
      break;
1152 1153 1154
    case PROP_DECORATED:
      g_value_set_boolean (value, gtk_window_get_decorated (window));
      break;
1155 1156 1157
    case PROP_DELETABLE:
      g_value_set_boolean (value, gtk_window_get_deletable (window));
      break;
1158 1159 1160
    case PROP_GRAVITY:
      g_value_set_enum (value, gtk_window_get_gravity (window));
      break;
Alexander Larsson's avatar
Alexander Larsson committed
1161 1162 1163
    case PROP_TRANSIENT_FOR:
      g_value_set_object (value, gtk_window_get_transient_for (window));
      break;
1164 1165 1166
    case PROP_OPACITY:
      g_value_set_double (value, gtk_window_get_opacity (window));
      break;
1167
    default:
1168
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1169 1170 1171 1172
      break;
    }
}

1173 1174 1175 1176
static void
gtk_window_buildable_interface_init (GtkBuildableIface *iface)
{
  parent_buildable_iface = g_type_interface_peek_parent (iface);
1177
  iface->set_buildable_property = gtk_window_buildable_set_buildable_property;
1178
  iface->parser_finished = gtk_window_buildable_parser_finished;
1179 1180
  iface->custom_tag_start = gtk_window_buildable_custom_tag_start;
  iface->custom_finished = gtk_window_buildable_custom_finished;
1181 1182 1183
}

static void
1184 1185 1186 1187
gtk_window_buildable_set_buildable_property (GtkBuildable        *buildable,
					     GtkBuilder          *builder,
					     const gchar         *name,
					     const GValue        *value)
1188 1189 1190 1191 1192 1193
{
  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);

  if (strcmp (name, "visible") == 0 && g_value_get_boolean (value))
    priv->builder_visible = TRUE;
  else
1194
    parent_buildable_iface->set_buildable_property (buildable, builder, name, value);
1195 1196 1197 1198 1199 1200 1201
}

static void
gtk_window_buildable_parser_finished (GtkBuildable *buildable,
				      GtkBuilder   *builder)
{
  GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (buildable);