]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
7a727433d87f6e1b1d6bd6539bb3833c2f4d507a
[~andy/gtk] / gtk / gtkwidget.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include <config.h>
28 #include <stdarg.h>
29 #include <string.h>
30 #include <locale.h>
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
35 #include "gtkintl.h"
36 #include "gtkmain.h"
37 #include "gtkmarshalers.h"
38 #include "gtkrc.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
46 #include "gdk/gdk.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltips.h"
53 #include "gtkinvisible.h"
54 #include "gtkalias.h"
55
56 #define WIDGET_CLASS(w)  GTK_WIDGET_GET_CLASS (w)
57 #define INIT_PATH_SIZE  (512)
58
59
60 enum {
61   SHOW,
62   HIDE,
63   MAP,
64   UNMAP,
65   REALIZE,
66   UNREALIZE,
67   SIZE_REQUEST,
68   SIZE_ALLOCATE,
69   STATE_CHANGED,
70   PARENT_SET,
71   HIERARCHY_CHANGED,
72   STYLE_SET,
73   DIRECTION_CHANGED,
74   GRAB_NOTIFY,
75   CHILD_NOTIFY,
76   MNEMONIC_ACTIVATE,
77   GRAB_FOCUS,
78   FOCUS,
79   EVENT,
80   EVENT_AFTER,
81   BUTTON_PRESS_EVENT,
82   BUTTON_RELEASE_EVENT,
83   SCROLL_EVENT,
84   MOTION_NOTIFY_EVENT,
85   DELETE_EVENT,
86   DESTROY_EVENT,
87   EXPOSE_EVENT,
88   KEY_PRESS_EVENT,
89   KEY_RELEASE_EVENT,
90   ENTER_NOTIFY_EVENT,
91   LEAVE_NOTIFY_EVENT,
92   CONFIGURE_EVENT,
93   FOCUS_IN_EVENT,
94   FOCUS_OUT_EVENT,
95   MAP_EVENT,
96   UNMAP_EVENT,
97   PROPERTY_NOTIFY_EVENT,
98   SELECTION_CLEAR_EVENT,
99   SELECTION_REQUEST_EVENT,
100   SELECTION_NOTIFY_EVENT,
101   SELECTION_GET,
102   SELECTION_RECEIVED,
103   PROXIMITY_IN_EVENT,
104   PROXIMITY_OUT_EVENT,
105   DRAG_BEGIN,
106   DRAG_END,
107   DRAG_DATA_DELETE,
108   DRAG_LEAVE,
109   DRAG_MOTION,
110   DRAG_DROP,
111   DRAG_DATA_GET,
112   DRAG_DATA_RECEIVED,
113   CLIENT_EVENT,
114   NO_EXPOSE_EVENT,
115   VISIBILITY_NOTIFY_EVENT,
116   WINDOW_STATE_EVENT,
117   POPUP_MENU,
118   SHOW_HELP,
119   ACCEL_CLOSURES_CHANGED,
120   SCREEN_CHANGED,
121   CAN_ACTIVATE_ACCEL,
122   GRAB_BROKEN,
123   COMPOSITED_CHANGED,
124   KEYNAV_FAILED,
125   DRAG_FAILED,
126   LAST_SIGNAL
127 };
128
129 enum {
130   PROP_0,
131   PROP_NAME,
132   PROP_PARENT,
133   PROP_WIDTH_REQUEST,
134   PROP_HEIGHT_REQUEST,
135   PROP_VISIBLE,
136   PROP_SENSITIVE,
137   PROP_APP_PAINTABLE,
138   PROP_CAN_FOCUS,
139   PROP_HAS_FOCUS,
140   PROP_IS_FOCUS,
141   PROP_CAN_DEFAULT,
142   PROP_HAS_DEFAULT,
143   PROP_RECEIVES_DEFAULT,
144   PROP_COMPOSITE_CHILD,
145   PROP_STYLE,
146   PROP_EVENTS,
147   PROP_EXTENSION_EVENTS,
148   PROP_NO_SHOW_ALL
149 };
150
151 typedef struct  _GtkStateData    GtkStateData;
152
153 struct _GtkStateData
154 {
155   GtkStateType  state;
156   guint         state_restoration : 1;
157   guint         parent_sensitive : 1;
158   guint         use_forall : 1;
159 };
160
161
162 /* --- prototypes --- */
163 static void     gtk_widget_class_init           (GtkWidgetClass     *klass);
164 static void     gtk_widget_base_class_finalize  (GtkWidgetClass     *klass);
165 static void     gtk_widget_init                 (GtkWidget          *widget);
166 static void     gtk_widget_set_property          (GObject           *object,
167                                                   guint              prop_id,
168                                                   const GValue      *value,
169                                                   GParamSpec        *pspec);
170 static void     gtk_widget_get_property          (GObject           *object,
171                                                   guint              prop_id,
172                                                   GValue            *value,
173                                                   GParamSpec        *pspec);
174 static void     gtk_widget_dispose               (GObject           *object);
175 static void     gtk_widget_real_destroy          (GtkObject         *object);
176 static void     gtk_widget_finalize              (GObject           *object);
177 static void     gtk_widget_real_show             (GtkWidget         *widget);
178 static void     gtk_widget_real_hide             (GtkWidget         *widget);
179 static void     gtk_widget_real_map              (GtkWidget         *widget);
180 static void     gtk_widget_real_unmap            (GtkWidget         *widget);
181 static void     gtk_widget_real_realize          (GtkWidget         *widget);
182 static void     gtk_widget_real_unrealize        (GtkWidget         *widget);
183 static void     gtk_widget_real_size_request     (GtkWidget         *widget,
184                                                   GtkRequisition    *requisition);
185 static void     gtk_widget_real_size_allocate    (GtkWidget         *widget,
186                                                   GtkAllocation     *allocation);
187 static void     gtk_widget_style_set             (GtkWidget         *widget,
188                                                   GtkStyle          *previous_style);
189 static void     gtk_widget_direction_changed     (GtkWidget         *widget,
190                                                   GtkTextDirection   previous_direction);
191
192 static void     gtk_widget_real_grab_focus       (GtkWidget         *focus_widget);
193 static gboolean gtk_widget_real_show_help        (GtkWidget         *widget,
194                                                   GtkWidgetHelpType  help_type);
195
196 static void     gtk_widget_dispatch_child_properties_changed    (GtkWidget        *object,
197                                                                  guint             n_pspecs,
198                                                                  GParamSpec      **pspecs);
199 static gboolean         gtk_widget_real_key_press_event         (GtkWidget        *widget,
200                                                                  GdkEventKey      *event);
201 static gboolean         gtk_widget_real_key_release_event       (GtkWidget        *widget,
202                                                                  GdkEventKey      *event);
203 static gboolean         gtk_widget_real_focus_in_event           (GtkWidget       *widget,
204                                                                   GdkEventFocus   *event);
205 static gboolean         gtk_widget_real_focus_out_event         (GtkWidget        *widget,
206                                                                  GdkEventFocus    *event);
207 static gboolean         gtk_widget_real_focus                   (GtkWidget        *widget,
208                                                                  GtkDirectionType  direction);
209 static gboolean         gtk_widget_real_keynav_failed           (GtkWidget        *widget,
210                                                                  GtkDirectionType  direction);
211 static PangoContext*    gtk_widget_peek_pango_context           (GtkWidget        *widget);
212 static void             gtk_widget_update_pango_context         (GtkWidget        *widget);
213 static void             gtk_widget_propagate_state              (GtkWidget        *widget,
214                                                                  GtkStateData     *data);
215 static void             gtk_widget_reset_rc_style               (GtkWidget        *widget);
216 static void             gtk_widget_set_style_internal           (GtkWidget        *widget,
217                                                                  GtkStyle         *style,
218                                                                  gboolean          initial_emission);
219 static gint             gtk_widget_event_internal               (GtkWidget        *widget,
220                                                                  GdkEvent         *event);
221 static gboolean         gtk_widget_real_mnemonic_activate       (GtkWidget        *widget,
222                                                                  gboolean          group_cycling);
223 static void             gtk_widget_aux_info_destroy             (GtkWidgetAuxInfo *aux_info);
224 static AtkObject*       gtk_widget_real_get_accessible          (GtkWidget        *widget);
225 static void             gtk_widget_accessible_interface_init    (AtkImplementorIface *iface);
226 static AtkObject*       gtk_widget_ref_accessible               (AtkImplementor *implementor);
227 static void             gtk_widget_invalidate_widget_windows    (GtkWidget        *widget,
228                                                                  GdkRegion        *region);
229 static GdkScreen *      gtk_widget_get_screen_unchecked         (GtkWidget        *widget);
230 static void             gtk_widget_queue_shallow_draw           (GtkWidget        *widget);
231 static gboolean         gtk_widget_real_can_activate_accel      (GtkWidget *widget,
232                                                                  guint      signal_id);
233      
234 static void gtk_widget_set_usize_internal (GtkWidget *widget,
235                                            gint       width,
236                                            gint       height);
237 static void gtk_widget_get_draw_rectangle (GtkWidget    *widget,
238                                            GdkRectangle *rect);
239
240
241 /* --- variables --- */
242 static gpointer         gtk_widget_parent_class = NULL;
243 static guint            widget_signals[LAST_SIGNAL] = { 0 };
244 static GtkStyle        *gtk_default_style = NULL;
245 static GSList          *colormap_stack = NULL;
246 static guint            composite_child_stack = 0;
247 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
248 static GParamSpecPool  *style_property_spec_pool = NULL;
249
250 static GQuark           quark_property_parser = 0;
251 static GQuark           quark_aux_info = 0;
252 static GQuark           quark_accel_path = 0;
253 static GQuark           quark_accel_closures = 0;
254 static GQuark           quark_event_mask = 0;
255 static GQuark           quark_extension_event_mode = 0;
256 static GQuark           quark_parent_window = 0;
257 static GQuark           quark_shape_info = 0;
258 static GQuark           quark_input_shape_info = 0;
259 static GQuark           quark_colormap = 0;
260 static GQuark           quark_pango_context = 0;
261 static GQuark           quark_rc_style = 0;
262 static GQuark           quark_accessible_object = 0;
263 static GQuark           quark_mnemonic_labels = 0;
264 GParamSpecPool         *_gtk_widget_child_property_pool = NULL;
265 GObjectNotifyContext   *_gtk_widget_child_property_notify_context = NULL;
266
267 /* --- functions --- */
268 GType
269 gtk_widget_get_type (void)
270 {
271   static GType widget_type = 0;
272
273   if (G_UNLIKELY (widget_type == 0))
274     {
275       const GTypeInfo widget_info =
276       {
277         sizeof (GtkWidgetClass),
278         NULL,           /* base_init */
279         (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
280         (GClassInitFunc) gtk_widget_class_init,
281         NULL,           /* class_finalize */
282         NULL,           /* class_init */
283         sizeof (GtkWidget),
284         0,              /* n_preallocs */
285         (GInstanceInitFunc) gtk_widget_init,
286         NULL,           /* value_table */
287       };
288
289       const GInterfaceInfo accessibility_info =
290       {
291         (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
292         (GInterfaceFinalizeFunc) NULL,
293         NULL /* interface data */
294       };
295
296       widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
297                                            &widget_info, G_TYPE_FLAG_ABSTRACT);
298
299       g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
300                                    &accessibility_info) ;
301
302     }
303
304   return widget_type;
305 }
306
307 static void
308 child_property_notify_dispatcher (GObject     *object,
309                                   guint        n_pspecs,
310                                   GParamSpec **pspecs)
311 {
312   GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
313 }
314
315 static void
316 gtk_widget_class_init (GtkWidgetClass *klass)
317 {
318   static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
319   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
320   GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
321   GtkBindingSet *binding_set;
322
323   gtk_widget_parent_class = g_type_class_peek_parent (klass);
324
325   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
326   quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
327   quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
328   quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
329   quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
330   quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
331   quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
332   quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
333   quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
334   quark_colormap = g_quark_from_static_string ("gtk-colormap");
335   quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
336   quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
337   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
338   quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
339
340   style_property_spec_pool = g_param_spec_pool_new (FALSE);
341   _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
342   cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
343   cpn_context.dispatcher = child_property_notify_dispatcher;
344   _gtk_widget_child_property_notify_context = &cpn_context;
345
346   gobject_class->dispose = gtk_widget_dispose;
347   gobject_class->finalize = gtk_widget_finalize;
348   gobject_class->set_property = gtk_widget_set_property;
349   gobject_class->get_property = gtk_widget_get_property;
350
351   object_class->destroy = gtk_widget_real_destroy;
352   
353   klass->activate_signal = 0;
354   klass->set_scroll_adjustments_signal = 0;
355   klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
356   klass->show = gtk_widget_real_show;
357   klass->show_all = gtk_widget_show;
358   klass->hide = gtk_widget_real_hide;
359   klass->hide_all = gtk_widget_hide;
360   klass->map = gtk_widget_real_map;
361   klass->unmap = gtk_widget_real_unmap;
362   klass->realize = gtk_widget_real_realize;
363   klass->unrealize = gtk_widget_real_unrealize;
364   klass->size_request = gtk_widget_real_size_request;
365   klass->size_allocate = gtk_widget_real_size_allocate;
366   klass->state_changed = NULL;
367   klass->parent_set = NULL;
368   klass->hierarchy_changed = NULL;
369   klass->style_set = gtk_widget_style_set;
370   klass->direction_changed = gtk_widget_direction_changed;
371   klass->grab_notify = NULL;
372   klass->child_notify = NULL;
373   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
374   klass->grab_focus = gtk_widget_real_grab_focus;
375   klass->focus = gtk_widget_real_focus;
376   klass->event = NULL;
377   klass->button_press_event = NULL;
378   klass->button_release_event = NULL;
379   klass->motion_notify_event = NULL;
380   klass->delete_event = NULL;
381   klass->destroy_event = NULL;
382   klass->expose_event = NULL;
383   klass->key_press_event = gtk_widget_real_key_press_event;
384   klass->key_release_event = gtk_widget_real_key_release_event;
385   klass->enter_notify_event = NULL;
386   klass->leave_notify_event = NULL;
387   klass->configure_event = NULL;
388   klass->focus_in_event = gtk_widget_real_focus_in_event;
389   klass->focus_out_event = gtk_widget_real_focus_out_event;
390   klass->map_event = NULL;
391   klass->unmap_event = NULL;
392   klass->window_state_event = NULL;
393   klass->property_notify_event = _gtk_selection_property_notify;
394   klass->selection_clear_event = gtk_selection_clear;
395   klass->selection_request_event = _gtk_selection_request;
396   klass->selection_notify_event = _gtk_selection_notify;
397   klass->selection_received = NULL;
398   klass->proximity_in_event = NULL;
399   klass->proximity_out_event = NULL;
400   klass->drag_begin = NULL;
401   klass->drag_end = NULL;
402   klass->drag_data_delete = NULL;
403   klass->drag_leave = NULL;
404   klass->drag_motion = NULL;
405   klass->drag_drop = NULL;
406   klass->drag_data_received = NULL;
407   klass->screen_changed = NULL;
408   klass->can_activate_accel = gtk_widget_real_can_activate_accel;
409   klass->grab_broken_event = NULL;
410
411   klass->show_help = gtk_widget_real_show_help;
412   
413   /* Accessibility support */
414   klass->get_accessible = gtk_widget_real_get_accessible;
415
416   klass->no_expose_event = NULL;
417
418   g_object_class_install_property (gobject_class,
419                                    PROP_NAME,
420                                    g_param_spec_string ("name",
421                                                         P_("Widget name"),
422                                                         P_("The name of the widget"),
423                                                         NULL,
424                                                         GTK_PARAM_READWRITE));
425   g_object_class_install_property (gobject_class,
426                                    PROP_PARENT,
427                                    g_param_spec_object ("parent",
428                                                         P_("Parent widget"), 
429                                                         P_("The parent widget of this widget. Must be a Container widget"),
430                                                         GTK_TYPE_CONTAINER,
431                                                         GTK_PARAM_READWRITE));
432
433   g_object_class_install_property (gobject_class,
434                                    PROP_WIDTH_REQUEST,
435                                    g_param_spec_int ("width-request",
436                                                      P_("Width request"),
437                                                      P_("Override for width request of the widget, or -1 if natural request should be used"),
438                                                      -1,
439                                                      G_MAXINT,
440                                                      -1,
441                                                      GTK_PARAM_READWRITE));
442   g_object_class_install_property (gobject_class,
443                                    PROP_HEIGHT_REQUEST,
444                                    g_param_spec_int ("height-request",
445                                                      P_("Height request"),
446                                                      P_("Override for height request of the widget, or -1 if natural request should be used"),
447                                                      -1,
448                                                      G_MAXINT,
449                                                      -1,
450                                                      GTK_PARAM_READWRITE));
451   g_object_class_install_property (gobject_class,
452                                    PROP_VISIBLE,
453                                    g_param_spec_boolean ("visible",
454                                                          P_("Visible"),
455                                                          P_("Whether the widget is visible"),
456                                                          FALSE,
457                                                          GTK_PARAM_READWRITE));
458   g_object_class_install_property (gobject_class,
459                                    PROP_SENSITIVE,
460                                    g_param_spec_boolean ("sensitive",
461                                                          P_("Sensitive"),
462                                                          P_("Whether the widget responds to input"),
463                                                          TRUE,
464                                                          GTK_PARAM_READWRITE));
465   g_object_class_install_property (gobject_class,
466                                    PROP_APP_PAINTABLE,
467                                    g_param_spec_boolean ("app-paintable",
468                                                          P_("Application paintable"),
469                                                          P_("Whether the application will paint directly on the widget"),
470                                                          FALSE,
471                                                          GTK_PARAM_READWRITE));
472   g_object_class_install_property (gobject_class,
473                                    PROP_CAN_FOCUS,
474                                    g_param_spec_boolean ("can-focus",
475                                                          P_("Can focus"),
476                                                          P_("Whether the widget can accept the input focus"),
477                                                          FALSE,
478                                                          GTK_PARAM_READWRITE));
479   g_object_class_install_property (gobject_class,
480                                    PROP_HAS_FOCUS,
481                                    g_param_spec_boolean ("has-focus",
482                                                          P_("Has focus"),
483                                                          P_("Whether the widget has the input focus"),
484                                                          FALSE,
485                                                          GTK_PARAM_READWRITE));
486   g_object_class_install_property (gobject_class,
487                                    PROP_IS_FOCUS,
488                                    g_param_spec_boolean ("is-focus",
489                                                          P_("Is focus"),
490                                                          P_("Whether the widget is the focus widget within the toplevel"),
491                                                          FALSE,
492                                                          GTK_PARAM_READWRITE));
493   g_object_class_install_property (gobject_class,
494                                    PROP_CAN_DEFAULT,
495                                    g_param_spec_boolean ("can-default",
496                                                          P_("Can default"),
497                                                          P_("Whether the widget can be the default widget"),
498                                                          FALSE,
499                                                          GTK_PARAM_READWRITE));
500   g_object_class_install_property (gobject_class,
501                                    PROP_HAS_DEFAULT,
502                                    g_param_spec_boolean ("has-default",
503                                                          P_("Has default"),
504                                                          P_("Whether the widget is the default widget"),
505                                                          FALSE,
506                                                          GTK_PARAM_READWRITE));
507   g_object_class_install_property (gobject_class,
508                                    PROP_RECEIVES_DEFAULT,
509                                    g_param_spec_boolean ("receives-default",
510                                                          P_("Receives default"),
511                                                          P_("If TRUE, the widget will receive the default action when it is focused"),
512                                                          FALSE,
513                                                          GTK_PARAM_READWRITE));
514   g_object_class_install_property (gobject_class,
515                                    PROP_COMPOSITE_CHILD,
516                                    g_param_spec_boolean ("composite-child",
517                                                          P_("Composite child"),
518                                                          P_("Whether the widget is part of a composite widget"),
519                                                          FALSE,
520                                                          GTK_PARAM_READABLE));
521   g_object_class_install_property (gobject_class,
522                                    PROP_STYLE,
523                                    g_param_spec_object ("style",
524                                                         P_("Style"),
525                                                         P_("The style of the widget, which contains information about how it will look (colors etc)"),
526                                                         GTK_TYPE_STYLE,
527                                                         GTK_PARAM_READWRITE));
528   g_object_class_install_property (gobject_class,
529                                    PROP_EVENTS,
530                                    g_param_spec_flags ("events",
531                                                        P_("Events"),
532                                                        P_("The event mask that decides what kind of GdkEvents this widget gets"),
533                                                        GDK_TYPE_EVENT_MASK,
534                                                        GDK_STRUCTURE_MASK,
535                                                        GTK_PARAM_READWRITE));
536   g_object_class_install_property (gobject_class,
537                                    PROP_EXTENSION_EVENTS,
538                                    g_param_spec_enum ("extension-events",
539                                                       P_("Extension events"),
540                                                       P_("The mask that decides what kind of extension events this widget gets"),
541                                                       GDK_TYPE_EXTENSION_MODE,
542                                                       GDK_EXTENSION_EVENTS_NONE,
543                                                       GTK_PARAM_READWRITE));
544   g_object_class_install_property (gobject_class,
545                                    PROP_NO_SHOW_ALL,
546                                    g_param_spec_boolean ("no-show-all",
547                                                          P_("No show all"),
548                                                          P_("Whether gtk_widget_show_all() should not affect this widget"),
549                                                          FALSE,
550                                                          GTK_PARAM_READWRITE));
551   widget_signals[SHOW] =
552     g_signal_new (I_("show"),
553                   G_TYPE_FROM_CLASS (gobject_class),
554                   G_SIGNAL_RUN_FIRST,
555                   G_STRUCT_OFFSET (GtkWidgetClass, show),
556                   NULL, NULL,
557                   _gtk_marshal_VOID__VOID,
558                   G_TYPE_NONE, 0);
559   widget_signals[HIDE] =
560     g_signal_new (I_("hide"),
561                   G_TYPE_FROM_CLASS (gobject_class),
562                   G_SIGNAL_RUN_FIRST,
563                   G_STRUCT_OFFSET (GtkWidgetClass, hide),
564                   NULL, NULL,
565                   _gtk_marshal_VOID__VOID,
566                   G_TYPE_NONE, 0);
567   widget_signals[MAP] =
568     g_signal_new (I_("map"),
569                   G_TYPE_FROM_CLASS (gobject_class),
570                   G_SIGNAL_RUN_FIRST,
571                   G_STRUCT_OFFSET (GtkWidgetClass, map),
572                   NULL, NULL,
573                   _gtk_marshal_VOID__VOID,
574                   G_TYPE_NONE, 0);
575   widget_signals[UNMAP] =
576     g_signal_new (I_("unmap"),
577                   G_TYPE_FROM_CLASS (gobject_class),
578                   G_SIGNAL_RUN_FIRST,
579                   G_STRUCT_OFFSET (GtkWidgetClass, unmap),
580                   NULL, NULL,
581                   _gtk_marshal_VOID__VOID,
582                   G_TYPE_NONE, 0);
583   widget_signals[REALIZE] =
584     g_signal_new (I_("realize"),
585                   G_TYPE_FROM_CLASS (gobject_class),
586                   G_SIGNAL_RUN_FIRST,
587                   G_STRUCT_OFFSET (GtkWidgetClass, realize),
588                   NULL, NULL,
589                   _gtk_marshal_VOID__VOID,
590                   G_TYPE_NONE, 0);
591   widget_signals[UNREALIZE] =
592     g_signal_new (I_("unrealize"),
593                   G_TYPE_FROM_CLASS (gobject_class),
594                   G_SIGNAL_RUN_LAST,
595                   G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
596                   NULL, NULL,
597                   _gtk_marshal_VOID__VOID,
598                   G_TYPE_NONE, 0);
599   widget_signals[SIZE_REQUEST] =
600     g_signal_new (I_("size_request"),
601                   G_TYPE_FROM_CLASS (gobject_class),
602                   G_SIGNAL_RUN_FIRST,
603                   G_STRUCT_OFFSET (GtkWidgetClass, size_request),
604                   NULL, NULL,
605                   _gtk_marshal_VOID__BOXED,
606                   G_TYPE_NONE, 1,
607                   GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
608   widget_signals[SIZE_ALLOCATE] = 
609     g_signal_new (I_("size_allocate"),
610                   G_TYPE_FROM_CLASS (gobject_class),
611                   G_SIGNAL_RUN_FIRST,
612                   G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
613                   NULL, NULL,
614                   _gtk_marshal_VOID__BOXED,
615                   G_TYPE_NONE, 1,
616                   GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
617   widget_signals[STATE_CHANGED] =
618     g_signal_new (I_("state_changed"),
619                   G_TYPE_FROM_CLASS (gobject_class),
620                   G_SIGNAL_RUN_FIRST,
621                   G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
622                   NULL, NULL,
623                   _gtk_marshal_VOID__ENUM,
624                   G_TYPE_NONE, 1,
625                   GTK_TYPE_STATE_TYPE);
626
627   /**
628    * GtkWidget::parent-set:
629    * @widget: the object on which the signal is emitted
630    * @old_parent: the previous parent, or %NULL if the widget 
631    *   just got its initial parent.
632    *
633    * The parent-set signal is emitted when a new parent has been set 
634    * on a widget. 
635    */
636   widget_signals[PARENT_SET] =
637     g_signal_new (I_("parent_set"),
638                   G_TYPE_FROM_CLASS (gobject_class),
639                   G_SIGNAL_RUN_FIRST,
640                   G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
641                   NULL, NULL,
642                   _gtk_marshal_VOID__OBJECT,
643                   G_TYPE_NONE, 1,
644                   GTK_TYPE_WIDGET);
645   widget_signals[HIERARCHY_CHANGED] =
646     g_signal_new (I_("hierarchy_changed"),
647                   G_TYPE_FROM_CLASS (gobject_class),
648                   G_SIGNAL_RUN_LAST,
649                   G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
650                   NULL, NULL,
651                   _gtk_marshal_VOID__OBJECT,
652                   G_TYPE_NONE, 1,
653                   GTK_TYPE_WIDGET);
654   /**
655    * GtkWidget::style-set:
656    * @widget: the object on which the signal is emitted
657    * @previous_style: the previous style, or %NULL if the widget 
658    *   just got its initial style 
659    *
660    * The style-set signal is emitted when a new style has been set 
661    * on a widget. Note that style-modifying functions like 
662    * gtk_widget_modify_base() also cause this signal to be emitted.
663    */
664   widget_signals[STYLE_SET] =
665     g_signal_new (I_("style_set"),
666                   G_TYPE_FROM_CLASS (gobject_class),
667                   G_SIGNAL_RUN_FIRST,
668                   G_STRUCT_OFFSET (GtkWidgetClass, style_set),
669                   NULL, NULL,
670                   _gtk_marshal_VOID__OBJECT,
671                   G_TYPE_NONE, 1,
672                   GTK_TYPE_STYLE);
673   widget_signals[DIRECTION_CHANGED] =
674     g_signal_new (I_("direction_changed"),
675                   G_TYPE_FROM_CLASS (gobject_class),
676                   G_SIGNAL_RUN_FIRST,
677                   G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
678                   NULL, NULL,
679                   _gtk_marshal_VOID__ENUM,
680                   G_TYPE_NONE, 1,
681                   GTK_TYPE_TEXT_DIRECTION);
682
683   /**
684    * GtkWidget::grab-notify:
685    * @widget: the object which received the signal
686    * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
687    *               if it becomes unshadowed
688    *
689    * The ::grab-notify signal is emitted when a widget becomes
690    * shadowed by a GTK+ grab (not a pointer or keyboard grab) on 
691    * another widget, or when it becomes unshadowed due to a grab 
692    * being removed.
693    * 
694    * A widget is shadowed by a gtk_grab_add() when the topmost 
695    * grab widget in the grab stack of its window group is not 
696    * its ancestor.
697    */
698   widget_signals[GRAB_NOTIFY] =
699     g_signal_new (I_("grab_notify"),
700                   G_TYPE_FROM_CLASS (gobject_class),
701                   G_SIGNAL_RUN_FIRST,
702                   G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
703                   NULL, NULL,
704                   _gtk_marshal_VOID__BOOLEAN,
705                   G_TYPE_NONE, 1,
706                   G_TYPE_BOOLEAN);
707
708 /**
709  * GtkWidget::child-notify:
710  * @widget: the object which received the signal.
711  * @pspec: the #GParamSpec of the changed child property.
712  *
713  * The ::child-notify signal is emitted for each child property that has 
714  * changed on an object. The signal's detail holds the property name. 
715  */
716   widget_signals[CHILD_NOTIFY] =
717     g_signal_new (I_("child_notify"),
718                    G_TYPE_FROM_CLASS (gobject_class),
719                    G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
720                    G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
721                    NULL, NULL,
722                    g_cclosure_marshal_VOID__PARAM,
723                    G_TYPE_NONE, 1,
724                    G_TYPE_PARAM);
725   widget_signals[MNEMONIC_ACTIVATE] =
726     g_signal_new (I_("mnemonic_activate"),
727                   G_TYPE_FROM_CLASS (gobject_class),
728                   G_SIGNAL_RUN_LAST,
729                   G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
730                   _gtk_boolean_handled_accumulator, NULL,
731                   _gtk_marshal_BOOLEAN__BOOLEAN,
732                   G_TYPE_BOOLEAN, 1,
733                   G_TYPE_BOOLEAN);
734   widget_signals[GRAB_FOCUS] =
735     g_signal_new (I_("grab_focus"),
736                   G_TYPE_FROM_CLASS (gobject_class),
737                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
738                   G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
739                   NULL, NULL,
740                   _gtk_marshal_VOID__VOID,
741                   G_TYPE_NONE, 0);
742   widget_signals[FOCUS] =
743     g_signal_new (I_("focus"),
744                   G_TYPE_FROM_CLASS (object_class),
745                   G_SIGNAL_RUN_LAST,
746                   G_STRUCT_OFFSET (GtkWidgetClass, focus),
747                   _gtk_boolean_handled_accumulator, NULL,
748                   _gtk_marshal_BOOLEAN__ENUM,
749                   G_TYPE_BOOLEAN, 1,
750                   GTK_TYPE_DIRECTION_TYPE);
751   widget_signals[EVENT] =
752     g_signal_new (I_("event"),
753                   G_TYPE_FROM_CLASS (gobject_class),
754                   G_SIGNAL_RUN_LAST,
755                   G_STRUCT_OFFSET (GtkWidgetClass, event),
756                   _gtk_boolean_handled_accumulator, NULL,
757                   _gtk_marshal_BOOLEAN__BOXED,
758                   G_TYPE_BOOLEAN, 1,
759                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
760   widget_signals[EVENT_AFTER] =
761     g_signal_new (I_("event_after"),
762                   G_TYPE_FROM_CLASS (gobject_class),
763                   0,
764                   0,
765                   NULL, NULL,
766                   _gtk_marshal_VOID__BOXED,
767                   G_TYPE_NONE, 1,
768                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
769   widget_signals[BUTTON_PRESS_EVENT] =
770     g_signal_new (I_("button_press_event"),
771                   G_TYPE_FROM_CLASS (gobject_class),
772                   G_SIGNAL_RUN_LAST,
773                   G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
774                   _gtk_boolean_handled_accumulator, NULL,
775                   _gtk_marshal_BOOLEAN__BOXED,
776                   G_TYPE_BOOLEAN, 1,
777                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
778   widget_signals[BUTTON_RELEASE_EVENT] =
779     g_signal_new (I_("button_release_event"),
780                   G_TYPE_FROM_CLASS (gobject_class),
781                   G_SIGNAL_RUN_LAST,
782                   G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
783                   _gtk_boolean_handled_accumulator, NULL,
784                   _gtk_marshal_BOOLEAN__BOXED,
785                   G_TYPE_BOOLEAN, 1,
786                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
787   widget_signals[SCROLL_EVENT] =
788     g_signal_new (I_("scroll_event"),
789                   G_TYPE_FROM_CLASS (gobject_class),
790                   G_SIGNAL_RUN_LAST,
791                   G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
792                   _gtk_boolean_handled_accumulator, NULL,
793                   _gtk_marshal_BOOLEAN__BOXED,
794                   G_TYPE_BOOLEAN, 1,
795                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
796   widget_signals[MOTION_NOTIFY_EVENT] =
797     g_signal_new (I_("motion_notify_event"),
798                   G_TYPE_FROM_CLASS (gobject_class),
799                   G_SIGNAL_RUN_LAST,
800                   G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
801                   _gtk_boolean_handled_accumulator, NULL,
802                   _gtk_marshal_BOOLEAN__BOXED,
803                   G_TYPE_BOOLEAN, 1,
804                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
805   widget_signals[COMPOSITED_CHANGED] =
806     g_signal_new (I_("composited_changed"),
807                   G_TYPE_FROM_CLASS (gobject_class),
808                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
809                   G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
810                   NULL, NULL,
811                   _gtk_marshal_VOID__VOID,
812                   G_TYPE_NONE, 0);
813
814   /**
815    * GtkWidget::keynav-failed:
816    * @widget: the object which received the signal.
817    * @direction: the direction of movement
818    *
819    * See gtk_widget_keynav_failed() for details.
820    *
821    * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
822    *          if the emitting widget should try to handle the keyboard
823    *          navigation attempt in its parent container(s).
824    *
825    * Since: 2.12
826    **/
827   widget_signals[KEYNAV_FAILED] =
828     _gtk_binding_signal_new (I_("keynav-failed"),
829                              G_TYPE_FROM_CLASS (gobject_class),
830                              G_SIGNAL_RUN_LAST,
831                              G_CALLBACK (gtk_widget_real_keynav_failed),
832                              _gtk_boolean_handled_accumulator, NULL,
833                              _gtk_marshal_BOOLEAN__ENUM,
834                              G_TYPE_BOOLEAN, 1,
835                              GTK_TYPE_DIRECTION_TYPE);
836
837 /**
838  * GtkWidget::delete-event:
839  * @widget: the object which received the signal.
840  * @event: the event which triggered this signal
841  *
842  * The ::delete-event signal is emitted if a user requests that
843  * a toplevel window is closed. The default handler for this signal
844  * destroys the window. Connecting gtk_widget_hide_on_delete() to
845  * this signal will cause the window to be hidden instead, so that
846  * it can later be shown again without reconstructing it.
847  *
848  * Returns: %TRUE to stop other handlers from being invoked for the event. 
849  *   %FALSE to propagate the event further.
850  */
851   widget_signals[DELETE_EVENT] =
852     g_signal_new (I_("delete_event"),
853                   G_TYPE_FROM_CLASS (gobject_class),
854                   G_SIGNAL_RUN_LAST,
855                   G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
856                   _gtk_boolean_handled_accumulator, NULL,
857                   _gtk_marshal_BOOLEAN__BOXED,
858                   G_TYPE_BOOLEAN, 1,
859                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
860
861 /**
862  * GtkWidget::destroy-event:
863  * @widget: the object which received the signal.
864  * @event: the event which triggered this signal
865  *
866  * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
867  * You rarely get this signal, because most widgets disconnect themselves 
868  * from their window before they destroy it, so no widget owns the 
869  * window at destroy time.
870  * 
871  * Returns: %TRUE to stop other handlers from being invoked for the event. 
872  *   %FALSE to propagate the event further.
873  */
874   widget_signals[DESTROY_EVENT] =
875     g_signal_new (I_("destroy_event"),
876                   G_TYPE_FROM_CLASS (gobject_class),
877                   G_SIGNAL_RUN_LAST,
878                   G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
879                   _gtk_boolean_handled_accumulator, NULL,
880                   _gtk_marshal_BOOLEAN__BOXED,
881                   G_TYPE_BOOLEAN, 1,
882                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
883   widget_signals[EXPOSE_EVENT] =
884     g_signal_new (I_("expose_event"),
885                   G_TYPE_FROM_CLASS (gobject_class),
886                   G_SIGNAL_RUN_LAST,
887                   G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
888                   _gtk_boolean_handled_accumulator, NULL,
889                   _gtk_marshal_BOOLEAN__BOXED,
890                   G_TYPE_BOOLEAN, 1,
891                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
892   widget_signals[KEY_PRESS_EVENT] =
893     g_signal_new (I_("key_press_event"),
894                   G_TYPE_FROM_CLASS (gobject_class),
895                   G_SIGNAL_RUN_LAST,
896                   G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
897                   _gtk_boolean_handled_accumulator, NULL,
898                   _gtk_marshal_BOOLEAN__BOXED,
899                   G_TYPE_BOOLEAN, 1,
900                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
901   widget_signals[KEY_RELEASE_EVENT] =
902     g_signal_new (I_("key_release_event"),
903                   G_TYPE_FROM_CLASS (gobject_class),
904                   G_SIGNAL_RUN_LAST,
905                   G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
906                   _gtk_boolean_handled_accumulator, NULL,
907                   _gtk_marshal_BOOLEAN__BOXED,
908                   G_TYPE_BOOLEAN, 1,
909                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
910   widget_signals[ENTER_NOTIFY_EVENT] =
911     g_signal_new (I_("enter_notify_event"),
912                   G_TYPE_FROM_CLASS (gobject_class),
913                   G_SIGNAL_RUN_LAST,
914                   G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
915                   _gtk_boolean_handled_accumulator, NULL,
916                   _gtk_marshal_BOOLEAN__BOXED,
917                   G_TYPE_BOOLEAN, 1,
918                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
919   widget_signals[LEAVE_NOTIFY_EVENT] =
920     g_signal_new (I_("leave_notify_event"),
921                   G_TYPE_FROM_CLASS (gobject_class),
922                   G_SIGNAL_RUN_LAST,
923                   G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
924                   _gtk_boolean_handled_accumulator, NULL,
925                   _gtk_marshal_BOOLEAN__BOXED,
926                   G_TYPE_BOOLEAN, 1,
927                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
928   widget_signals[CONFIGURE_EVENT] =
929     g_signal_new (I_("configure_event"),
930                   G_TYPE_FROM_CLASS (gobject_class),
931                   G_SIGNAL_RUN_LAST,
932                   G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
933                   _gtk_boolean_handled_accumulator, NULL,
934                   _gtk_marshal_BOOLEAN__BOXED,
935                   G_TYPE_BOOLEAN, 1,
936                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
937   widget_signals[FOCUS_IN_EVENT] =
938     g_signal_new (I_("focus_in_event"),
939                   G_TYPE_FROM_CLASS (gobject_class),
940                   G_SIGNAL_RUN_LAST,
941                   G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
942                   _gtk_boolean_handled_accumulator, NULL,
943                   _gtk_marshal_BOOLEAN__BOXED,
944                   G_TYPE_BOOLEAN, 1,
945                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
946   widget_signals[FOCUS_OUT_EVENT] =
947     g_signal_new (I_("focus_out_event"),
948                   G_TYPE_FROM_CLASS (gobject_class),
949                   G_SIGNAL_RUN_LAST,
950                   G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
951                   _gtk_boolean_handled_accumulator, NULL,
952                   _gtk_marshal_BOOLEAN__BOXED,
953                   G_TYPE_BOOLEAN, 1,
954                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
955   widget_signals[MAP_EVENT] =
956     g_signal_new (I_("map_event"),
957                   G_TYPE_FROM_CLASS (gobject_class),
958                   G_SIGNAL_RUN_LAST,
959                   G_STRUCT_OFFSET (GtkWidgetClass, map_event),
960                   _gtk_boolean_handled_accumulator, NULL,
961                   _gtk_marshal_BOOLEAN__BOXED,
962                   G_TYPE_BOOLEAN, 1,
963                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
964   widget_signals[UNMAP_EVENT] =
965     g_signal_new (I_("unmap_event"),
966                   G_TYPE_FROM_CLASS (gobject_class),
967                   G_SIGNAL_RUN_LAST,
968                   G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
969                   _gtk_boolean_handled_accumulator, NULL,
970                   _gtk_marshal_BOOLEAN__BOXED,
971                   G_TYPE_BOOLEAN, 1,
972                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
973   widget_signals[PROPERTY_NOTIFY_EVENT] =
974     g_signal_new (I_("property_notify_event"),
975                   G_TYPE_FROM_CLASS (gobject_class),
976                   G_SIGNAL_RUN_LAST,
977                   G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
978                   _gtk_boolean_handled_accumulator, NULL,
979                   _gtk_marshal_BOOLEAN__BOXED,
980                   G_TYPE_BOOLEAN, 1,
981                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
982   widget_signals[SELECTION_CLEAR_EVENT] =
983     g_signal_new (I_("selection_clear_event"),
984                   G_TYPE_FROM_CLASS (gobject_class),
985                   G_SIGNAL_RUN_LAST,
986                   G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
987                   _gtk_boolean_handled_accumulator, NULL,
988                   _gtk_marshal_BOOLEAN__BOXED,
989                   G_TYPE_BOOLEAN, 1,
990                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
991   widget_signals[SELECTION_REQUEST_EVENT] =
992     g_signal_new (I_("selection_request_event"),
993                   G_TYPE_FROM_CLASS (gobject_class),
994                   G_SIGNAL_RUN_LAST,
995                   G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
996                   _gtk_boolean_handled_accumulator, NULL,
997                   _gtk_marshal_BOOLEAN__BOXED,
998                   G_TYPE_BOOLEAN, 1,
999                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1000   widget_signals[SELECTION_NOTIFY_EVENT] =
1001     g_signal_new (I_("selection_notify_event"),
1002                   G_TYPE_FROM_CLASS (gobject_class),
1003                   G_SIGNAL_RUN_LAST,
1004                   G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1005                   _gtk_boolean_handled_accumulator, NULL,
1006                   _gtk_marshal_BOOLEAN__BOXED,
1007                   G_TYPE_BOOLEAN, 1,
1008                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1009   widget_signals[SELECTION_RECEIVED] =
1010     g_signal_new (I_("selection_received"),
1011                   G_TYPE_FROM_CLASS (gobject_class),
1012                   G_SIGNAL_RUN_LAST,
1013                   G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1014                   NULL, NULL,
1015                   _gtk_marshal_VOID__BOXED_UINT,
1016                   G_TYPE_NONE, 2,
1017                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1018                   G_TYPE_UINT);
1019   widget_signals[SELECTION_GET] =
1020     g_signal_new (I_("selection_get"),
1021                   G_TYPE_FROM_CLASS (gobject_class),
1022                   G_SIGNAL_RUN_LAST,
1023                   G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1024                   NULL, NULL,
1025                   _gtk_marshal_VOID__BOXED_UINT_UINT,
1026                   G_TYPE_NONE, 3,
1027                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1028                   G_TYPE_UINT,
1029                   G_TYPE_UINT);
1030   widget_signals[PROXIMITY_IN_EVENT] =
1031     g_signal_new (I_("proximity_in_event"),
1032                   G_TYPE_FROM_CLASS (gobject_class),
1033                   G_SIGNAL_RUN_LAST,
1034                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1035                   _gtk_boolean_handled_accumulator, NULL,
1036                   _gtk_marshal_BOOLEAN__BOXED,
1037                   G_TYPE_BOOLEAN, 1,
1038                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1039   widget_signals[PROXIMITY_OUT_EVENT] =
1040     g_signal_new (I_("proximity_out_event"),
1041                   G_TYPE_FROM_CLASS (gobject_class),
1042                   G_SIGNAL_RUN_LAST,
1043                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1044                   _gtk_boolean_handled_accumulator, NULL,
1045                   _gtk_marshal_BOOLEAN__BOXED,
1046                   G_TYPE_BOOLEAN, 1,
1047                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1048
1049   /**
1050    * GtkWidget::drag-leave:
1051    * @widget: the object which received the signal.
1052    * @drag_context: the drag context
1053    * @time: the timestamp of the motion event
1054    *
1055    * The ::drag-leave signal is emitted on the drop site when the cursor 
1056    * leaves the widget. A typical reason to connect to this signal is to 
1057    * undo things done in ::drag-motion, e.g. undo highlighting with 
1058    * gtk_drag_unhighlight()
1059    */
1060   widget_signals[DRAG_LEAVE] =
1061     g_signal_new (I_("drag_leave"),
1062                   G_TYPE_FROM_CLASS (gobject_class),
1063                   G_SIGNAL_RUN_LAST,
1064                   G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1065                   NULL, NULL,
1066                   _gtk_marshal_VOID__OBJECT_UINT,
1067                   G_TYPE_NONE, 2,
1068                   GDK_TYPE_DRAG_CONTEXT,
1069                   G_TYPE_UINT);
1070
1071   /**
1072    * GtkWidget::drag-begin:
1073    * @widget: the object which received the signal.
1074    * @drag_context: the drag context
1075    *
1076    * The ::drag-begin signal is emitted on the drag source when a drag is started. 
1077    * A typical reason to connect to this signal is to set up a custom drag icon with
1078    * gtk_drag_source_set_icon().
1079    */
1080   widget_signals[DRAG_BEGIN] =
1081     g_signal_new (I_("drag_begin"),
1082                   G_TYPE_FROM_CLASS (gobject_class),
1083                   G_SIGNAL_RUN_LAST,
1084                   G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1085                   NULL, NULL,
1086                   _gtk_marshal_VOID__OBJECT,
1087                   G_TYPE_NONE, 1,
1088                   GDK_TYPE_DRAG_CONTEXT);
1089
1090   /**
1091    * GtkWidget::drag-end:
1092    * @widget: the object which received the signal.
1093    * @drag_context: the drag context
1094    *
1095    * The ::drag-end signal is emitted on the drag source when a drag is finished. 
1096    * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1097    */
1098   widget_signals[DRAG_END] =
1099     g_signal_new (I_("drag_end"),
1100                   G_TYPE_FROM_CLASS (gobject_class),
1101                   G_SIGNAL_RUN_LAST,
1102                   G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1103                   NULL, NULL,
1104                   _gtk_marshal_VOID__OBJECT,
1105                   G_TYPE_NONE, 1,
1106                   GDK_TYPE_DRAG_CONTEXT);
1107
1108   /**
1109    * GtkWidget::drag-data-delete:
1110    * @widget: the object which received the signal.
1111    * @drag_context: the drag context
1112    *
1113    * The ::drag-data-delete signal is emitted on the drag source when a drag 
1114    * with the action %GDK_ACTION_MOVE is successfully completed. The signal 
1115    * handler is responsible for deleting the data that has been dropped. What 
1116    * "delete" means, depends on the context of the drag operation. 
1117    */
1118   widget_signals[DRAG_DATA_DELETE] =
1119     g_signal_new (I_("drag_data_delete"),
1120                   G_TYPE_FROM_CLASS (gobject_class),
1121                   G_SIGNAL_RUN_LAST,
1122                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1123                   NULL, NULL,
1124                   _gtk_marshal_VOID__OBJECT,
1125                   G_TYPE_NONE, 1,
1126                   GDK_TYPE_DRAG_CONTEXT);
1127
1128   /**
1129    * GtkWidget::drag-failed:
1130    * @widget: the object which received the signal.
1131    * @drag_context: the drag context.
1132    * @result: the result of the drag operation.
1133    *
1134    * The ::drag-failed signal is emitted on the drag source when a drag has
1135    * failed. The signal handler may hook custom code to handle a failed DND
1136    * operation based on the type of error, it returns %TRUE is the failure has
1137    * been already handled (not showing the default "drag operation failed"
1138    * animation), otherwise it returns %FALSE.
1139    *
1140    * Return value: %TRUE if the failed drag operation has been already handled.
1141    *
1142    * Since: 2.12
1143    */
1144   widget_signals[DRAG_FAILED] =
1145     g_signal_new (I_("drag_failed"),
1146                   G_TYPE_FROM_CLASS (gobject_class),
1147                   G_SIGNAL_RUN_LAST,
1148                   0, _gtk_boolean_handled_accumulator, NULL,
1149                   _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1150                   G_TYPE_BOOLEAN, 2,
1151                   GDK_TYPE_DRAG_CONTEXT,
1152                   GTK_TYPE_DRAG_RESULT);
1153
1154   /**
1155    * GtkWidget::drag-motion:
1156    * @widget: the object which received the signal.
1157    * @drag_context: the drag context
1158    * @x: the x coordinate of the current cursor position
1159    * @y: the y coordinate of the current cursor position
1160    * @time: the timestamp of the motion event
1161    * @returns: whether the cursor position is in a drop zone
1162    *
1163    * The ::drag-motion signal is emitted on the drop site when the user 
1164    * moves the cursor over the widget during a drag. The signal handler 
1165    * must determine whether the cursor position is in a drop zone or not. 
1166    * If it is not in a drop zone, it returns %FALSE and no further processing 
1167    * is necessary. Otherwise, the handler returns %TRUE. In this case, the 
1168    * handler is responsible for providing the necessary information for 
1169    * displaying feedback to the user, by calling gdk_drag_status(). If the 
1170    * decision whether the drop will be accepted or rejected can't be made
1171    * based solely on the cursor position and the type of the data, the handler 
1172    * may inspect the dragged data by calling gtk_drag_get_data() and defer the 
1173    * gdk_drag_status() call to the ::drag-data-received handler. 
1174    *
1175    * Note that there is no ::drag-enter signal. The drag receiver has to keep 
1176    * track of whether he has received any ::drag-motion signals since the last 
1177    * ::drag-leave and if not, treat the ::drag-motion signal as an "enter" signal. 
1178    * Upon an "enter", the handler will typically highlight the drop site with 
1179    * gtk_drag_highlight().
1180    *
1181    * <informalexample><programlisting> 
1182    * static void
1183    * drag_motion (GtkWidget *widget,
1184    *              GdkDragContext *context,
1185    *              gint x,
1186    *              gint y,
1187    *              guint time)
1188    * {
1189    *   GdkAtom target;
1190    *  
1191    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1192    *  
1193    *   if (!private_data->drag_highlight) 
1194    *    {
1195    *      private_data->drag_highlight = 1;
1196    *      gtk_drag_highlight (widget);
1197    *    }
1198    *  
1199    *   target = gtk_drag_dest_find_target (widget, context, NULL);
1200    *   if (target == GDK_NONE)
1201    *     gdk_drag_status (context, 0, time);
1202    *   else 
1203    *    {
1204    *      private_data->pending_status = context->suggested_action;
1205    *      gtk_drag_get_data (widget, context, target, time);
1206    *    }
1207    *  
1208    *   return TRUE;
1209    * }
1210    *   
1211    * static void
1212    * drag_data_received (GtkWidget        *widget,
1213    *                     GdkDragContext   *context,
1214    *                     gint              x,
1215    *                     gint              y,
1216    *                     GtkSelectionData *selection_data,
1217    *                     guint             info,
1218    *                     guint             time)
1219    * {
1220    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1221    *   
1222    *   if (private_data->suggested_action) 
1223    *    {
1224    *      private_data->suggested_action = 0;
1225    *      
1226    *     /<!-- -->* We are getting this data due to a request in drag_motion,
1227    *      * rather than due to a request in drag_drop, so we are just
1228    *      * supposed to call gdk_drag_status(<!-- -->), not actually paste in 
1229    *      * the data.
1230    *      *<!-- -->/
1231    *      str = gtk_selection_data_get_text (selection_data);
1232    *      if (!data_is_acceptable (str)) 
1233    *        gdk_drag_status (context, 0, time);
1234    *      else
1235    *        gdk_drag_status (context, private_data->suggested_action, time);
1236    *    }
1237    *   else
1238    *    {
1239    *      /<!-- -->* accept the drop *<!-- -->/
1240    *    }
1241    * }
1242    * </programlisting></informalexample>
1243    */
1244   widget_signals[DRAG_MOTION] =
1245     g_signal_new (I_("drag_motion"),
1246                   G_TYPE_FROM_CLASS (gobject_class),
1247                   G_SIGNAL_RUN_LAST,
1248                   G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1249                   _gtk_boolean_handled_accumulator, NULL,
1250                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1251                   G_TYPE_BOOLEAN, 4,
1252                   GDK_TYPE_DRAG_CONTEXT,
1253                   G_TYPE_INT,
1254                   G_TYPE_INT,
1255                   G_TYPE_UINT);
1256
1257   /**
1258    * GtkWidget::drag-drop:
1259    * @widget: the object which received the signal.
1260    * @drag_context: the drag context
1261    * @x: the x coordinate of the current cursor position
1262    * @y: the y coordinate of the current cursor position
1263    * @time: the timestamp of the motion event
1264    * @returns: whether the cursor position is in a drop zone
1265    *
1266    * The ::drag-drop signal is emitted on the drop site when the user drops the 
1267    * data onto the widget. The signal handler must determine whether the cursor 
1268    * position is in a drop zone or not. If it is not in a drop zone, it returns 
1269    * %FALSE and no further processing is necessary. Otherwise, the handler returns 
1270    * %TRUE. In this case, the handler must ensure that gtk_drag_finish() is called 
1271    * to let the source know that the drop is done. The call to gtk_drag_finish() 
1272    * can be done either directly or in a ::drag-data-received handler which gets 
1273    * triggered by calling gtk_drag_get_data() to receive the data for one or more 
1274    * of the supported targets.
1275    */
1276   widget_signals[DRAG_DROP] =
1277     g_signal_new (I_("drag_drop"),
1278                   G_TYPE_FROM_CLASS (gobject_class),
1279                   G_SIGNAL_RUN_LAST,
1280                   G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1281                   _gtk_boolean_handled_accumulator, NULL,
1282                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1283                   G_TYPE_BOOLEAN, 4,
1284                   GDK_TYPE_DRAG_CONTEXT,
1285                   G_TYPE_INT,
1286                   G_TYPE_INT,
1287                   G_TYPE_UINT);
1288
1289   /** 
1290    * GtkWidget::drag-data-get:
1291    * @widget: the object which received the signal.
1292    * @drag_context: the drag context
1293    * @data: the #GtkSelectionData to be filled with the dragged data
1294    * @info: the info that has been registered with the target in the #GtkTargetList.
1295    * @time: the timestamp at which the data was requested
1296    *
1297    * The ::drag-data-get signal is emitted on the drag source when the drop site 
1298    * requests the data which is dragged. It is the responsibility of the signal 
1299    * handler to fill @data with the data in the format which is indicated by @info. 
1300    * See gtk_selection_data_set() and gtk_selection_data_set_text().
1301    */
1302   widget_signals[DRAG_DATA_GET] =
1303     g_signal_new (I_("drag_data_get"),
1304                   G_TYPE_FROM_CLASS (gobject_class),
1305                   G_SIGNAL_RUN_LAST,
1306                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1307                   NULL, NULL,
1308                   _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1309                   G_TYPE_NONE, 4,
1310                   GDK_TYPE_DRAG_CONTEXT,
1311                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1312                   G_TYPE_UINT,
1313                   G_TYPE_UINT);
1314
1315 /**
1316  * GtkWidget::drag-data-received:
1317  * @widget: the object which received the signal.
1318  * @drag_context: the drag context
1319  * @x: where the drop happened
1320  * @y: where the drop happened
1321  * @data: the received data
1322  * @info: the info that has been registered with the target in the #GtkTargetList.
1323  * @time: the timestamp at which the data was received
1324  *
1325  * The ::drag-data-received signal is emitted on the drop site when the dragged 
1326  * data has been received. If the data was received in order to determine whether 
1327  * the drop will be accepted, the handler is expected to call gdk_drag_status() 
1328  * and <emphasis>not</emphasis> finish the drag. If the data was received in 
1329  * response to a ::drag-drop signal (and this is the last target to be received), 
1330  * the handler for this signal is expected to process the received data and then 
1331  * call gtk_drag_finish(), setting the @success parameter depending on whether 
1332  * the data was processed successfully. 
1333  * 
1334  * The handler may inspect and modify @drag_context->action before calling 
1335  * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the following 
1336  * example:
1337  * <informalexample><programlisting>
1338  * void  
1339  * drag_data_received (GtkWidget          *widget,
1340  *                     GdkDragContext     *drag_context,
1341  *                     gint                x,
1342  *                     gint                y,
1343  *                     GtkSelectionData   *data,
1344  *                     guint               info,
1345  *                     guint               time)
1346  * {
1347  *   if ((data->length >= 0) && (data->format == 8))
1348  *     {
1349  *       if (drag_context->action == GDK_ACTION_ASK) 
1350  *         {
1351  *           GtkWidget *dialog;
1352  *           gint response;
1353  *           
1354  *           dialog = gtk_message_dialog_new (NULL,
1355  *                                            GTK_DIALOG_MODAL | 
1356  *                                            GTK_DIALOG_DESTROY_WITH_PARENT,
1357  *                                            GTK_MESSAGE_INFO,
1358  *                                            GTK_BUTTONS_YES_NO,
1359  *                                            "Move the data ?\n");
1360  *           response = gtk_dialog_run (GTK_DIALOG (dialog));
1361  *           gtk_widget_destroy (dialog);
1362  *             
1363  *           if (response == GTK_RESPONSE_YES)
1364  *             drag_context->action = GDK_ACTION_MOVE;
1365  *           else
1366  *             drag_context->action = GDK_ACTION_COPY;
1367  *          }
1368  *          
1369  *       gtk_drag_finish (drag_context, TRUE, FALSE, time);
1370  *       return;
1371  *     }
1372  *       
1373  *    gtk_drag_finish (drag_context, FALSE, FALSE, time);
1374  *  }
1375  * </programlisting></informalexample>
1376  */
1377   widget_signals[DRAG_DATA_RECEIVED] =
1378     g_signal_new (I_("drag_data_received"),
1379                   G_TYPE_FROM_CLASS (gobject_class),
1380                   G_SIGNAL_RUN_LAST,
1381                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1382                   NULL, NULL,
1383                   _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1384                   G_TYPE_NONE, 6,
1385                   GDK_TYPE_DRAG_CONTEXT,
1386                   G_TYPE_INT,
1387                   G_TYPE_INT,
1388                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1389                   G_TYPE_UINT,
1390                   G_TYPE_UINT);
1391   widget_signals[VISIBILITY_NOTIFY_EVENT] =
1392     g_signal_new (I_("visibility_notify_event"),
1393                   G_TYPE_FROM_CLASS (gobject_class),
1394                   G_SIGNAL_RUN_LAST,
1395                   G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1396                   _gtk_boolean_handled_accumulator, NULL,
1397                   _gtk_marshal_BOOLEAN__BOXED,
1398                   G_TYPE_BOOLEAN, 1,
1399                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1400   widget_signals[CLIENT_EVENT] =
1401     g_signal_new (I_("client_event"),
1402                   G_TYPE_FROM_CLASS (gobject_class),
1403                   G_SIGNAL_RUN_LAST,
1404                   G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1405                   _gtk_boolean_handled_accumulator, NULL,
1406                   _gtk_marshal_BOOLEAN__BOXED,
1407                   G_TYPE_BOOLEAN, 1,
1408                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1409   widget_signals[NO_EXPOSE_EVENT] =
1410     g_signal_new (I_("no_expose_event"),
1411                   G_TYPE_FROM_CLASS (gobject_class),
1412                   G_SIGNAL_RUN_LAST,
1413                   G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1414                   _gtk_boolean_handled_accumulator, NULL,
1415                   _gtk_marshal_BOOLEAN__BOXED,
1416                   G_TYPE_BOOLEAN, 1,
1417                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1418   widget_signals[WINDOW_STATE_EVENT] =
1419     g_signal_new (I_("window_state_event"),
1420                   G_TYPE_FROM_CLASS (gobject_class),
1421                   G_SIGNAL_RUN_LAST,
1422                   G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1423                   _gtk_boolean_handled_accumulator, NULL,
1424                   _gtk_marshal_BOOLEAN__BOXED,
1425                   G_TYPE_BOOLEAN, 1,
1426                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1427   /**
1428    * GtkWidget::grab-broken-event:
1429    * @widget: the object which received the signal
1430    * @event: the #GdkEventGrabBroken event
1431    *
1432    * Emitted when a pointer or keyboard grab on a window belonging 
1433    * to @widget gets broken. 
1434    * 
1435    * On X11, this happens when the grab window becomes unviewable 
1436    * (i.e. it or one of its ancestors is unmapped), or if the same 
1437    * application grabs the pointer or keyboard again.
1438    *
1439    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1440    *   %FALSE to propagate the event further.
1441    *
1442    * Since: 2.8
1443    */
1444   widget_signals[GRAB_BROKEN] =
1445     g_signal_new (I_("grab_broken_event"),
1446                   G_TYPE_FROM_CLASS (gobject_class),
1447                   G_SIGNAL_RUN_LAST,
1448                   G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
1449                   _gtk_boolean_handled_accumulator, NULL,
1450                   _gtk_marshal_BOOLEAN__BOXED,
1451                   G_TYPE_BOOLEAN, 1,
1452                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1453 /**
1454  * GtkWidget::popup-menu
1455  * @widget: the object which received the signal
1456  * @returns: TRUE if a menu was activated
1457  *
1458  * This signal gets emitted whenever a widget should pop up a context-sensitive
1459  * menu.  This usually happens through the standard key binding mechanism; by
1460  * pressing a certain key while a widget is focused, the user can cause the
1461  * widget to pop up a menu.  For example, the #GtkEntry widget creates a menu
1462  * with clipboard commands.  See <xref linkend="checklist-popup-menu"/> for an
1463  * example of how to use this signal.
1464  */
1465   widget_signals[POPUP_MENU] =
1466     g_signal_new (I_("popup_menu"),
1467                   G_TYPE_FROM_CLASS (gobject_class),
1468                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1469                   G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1470                   _gtk_boolean_handled_accumulator, NULL,
1471                   _gtk_marshal_BOOLEAN__VOID,
1472                   G_TYPE_BOOLEAN, 0);
1473   widget_signals[SHOW_HELP] =
1474     g_signal_new (I_("show_help"),
1475                   G_TYPE_FROM_CLASS (gobject_class),
1476                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1477                   G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1478                   _gtk_boolean_handled_accumulator, NULL,
1479                   _gtk_marshal_BOOLEAN__ENUM,
1480                   G_TYPE_BOOLEAN, 1,
1481                   GTK_TYPE_WIDGET_HELP_TYPE);
1482   widget_signals[ACCEL_CLOSURES_CHANGED] =
1483     g_signal_new (I_("accel_closures_changed"),
1484                   G_TYPE_FROM_CLASS (gobject_class),
1485                   0,
1486                   0,
1487                   NULL, NULL,
1488                   _gtk_marshal_NONE__NONE,
1489                   G_TYPE_NONE, 0);
1490   widget_signals[SCREEN_CHANGED] =
1491     g_signal_new (I_("screen_changed"),
1492                   G_TYPE_FROM_CLASS (gobject_class),
1493                   G_SIGNAL_RUN_LAST,
1494                   G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1495                   NULL, NULL,
1496                   _gtk_marshal_VOID__OBJECT,
1497                   G_TYPE_NONE, 1,
1498                   GDK_TYPE_SCREEN);
1499 /**
1500  * GtkWidget::can-activate-accel:
1501  * @widget: the object which received the signal
1502  * @signal_id: the ID of a signal installed on @widget
1503  * @returns: %TRUE if the signal can be activated.
1504  *
1505  * Determines whether an accelerator that activates the signal
1506  * identified by @signal_id can currently be activated.
1507  * This signal is present to allow applications and derived
1508  * widgets to override the default #GtkWidget handling
1509  * for determining whether an accelerator can be activated.
1510  */
1511   widget_signals[CAN_ACTIVATE_ACCEL] =
1512      g_signal_new (I_("can_activate_accel"),
1513                   G_TYPE_FROM_CLASS (gobject_class),
1514                   G_SIGNAL_RUN_LAST,
1515                   G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1516                   _gtk_boolean_handled_accumulator, NULL,
1517                   _gtk_marshal_BOOLEAN__UINT,
1518                   G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1519
1520   binding_set = gtk_binding_set_by_class (klass);
1521   gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1522                                 "popup_menu", 0);
1523   gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1524                                 "popup_menu", 0);  
1525
1526   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1527                                 "show_help", 1,
1528                                 GTK_TYPE_WIDGET_HELP_TYPE,
1529                                 GTK_WIDGET_HELP_TOOLTIP);
1530   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1531                                 "show_help", 1,
1532                                 GTK_TYPE_WIDGET_HELP_TYPE,
1533                                 GTK_WIDGET_HELP_TOOLTIP);
1534   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1535                                 "show_help", 1,
1536                                 GTK_TYPE_WIDGET_HELP_TYPE,
1537                                 GTK_WIDGET_HELP_WHATS_THIS);  
1538   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1539                                 "show_help", 1,
1540                                 GTK_TYPE_WIDGET_HELP_TYPE,
1541                                 GTK_WIDGET_HELP_WHATS_THIS);
1542
1543   gtk_widget_class_install_style_property (klass,
1544                                            g_param_spec_boolean ("interior-focus",
1545                                                                  P_("Interior Focus"),
1546                                                                  P_("Whether to draw the focus indicator inside widgets"),
1547                                                                  TRUE,
1548                                                                  GTK_PARAM_READABLE));
1549
1550   gtk_widget_class_install_style_property (klass,
1551                                            g_param_spec_int ("focus-line-width",
1552                                                              P_("Focus linewidth"),
1553                                                              P_("Width, in pixels, of the focus indicator line"),
1554                                                              0, G_MAXINT, 1,
1555                                                              GTK_PARAM_READABLE));
1556
1557   gtk_widget_class_install_style_property (klass,
1558                                            g_param_spec_string ("focus-line-pattern",
1559                                                                 P_("Focus line dash pattern"),
1560                                                                 P_("Dash pattern used to draw the focus indicator"),
1561                                                                 "\1\1",
1562                                                                 GTK_PARAM_READABLE));
1563   gtk_widget_class_install_style_property (klass,
1564                                            g_param_spec_int ("focus-padding",
1565                                                              P_("Focus padding"),
1566                                                              P_("Width, in pixels, between focus indicator and the widget 'box'"),
1567                                                              0, G_MAXINT, 1,
1568                                                              GTK_PARAM_READABLE));
1569   gtk_widget_class_install_style_property (klass,
1570                                            g_param_spec_boxed ("cursor-color",
1571                                                                P_("Cursor color"),
1572                                                                P_("Color with which to draw insertion cursor"),
1573                                                                GDK_TYPE_COLOR,
1574                                                                GTK_PARAM_READABLE));
1575   gtk_widget_class_install_style_property (klass,
1576                                            g_param_spec_boxed ("secondary-cursor-color",
1577                                                                P_("Secondary cursor color"),
1578                                                                P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1579                                                                GDK_TYPE_COLOR,
1580                                                                GTK_PARAM_READABLE));
1581   gtk_widget_class_install_style_property (klass,
1582                                            g_param_spec_float ("cursor-aspect-ratio",
1583                                                                P_("Cursor line aspect ratio"),
1584                                                                P_("Aspect ratio with which to draw insertion cursor"),
1585                                                                0.0, 1.0, 0.04,
1586                                                                GTK_PARAM_READABLE));
1587
1588 /**
1589  * GtkWidget:draw-border:
1590  *
1591  * The "draw-border" property defines the size of areas outside 
1592  * the widget's allocation to draw.
1593  *
1594  * Since: 2.8
1595  */
1596   gtk_widget_class_install_style_property (klass,
1597                                            g_param_spec_boxed ("draw-border",
1598                                                                P_("Draw Border"),
1599                                                                P_("Size of areas outside the widget's allocation to draw"),
1600                                                                GTK_TYPE_BORDER,
1601                                                                GTK_PARAM_READABLE));
1602
1603 /**
1604  * GtkWidget:link-color:
1605  *
1606  * The "link-color" property defines the color of unvisited links.
1607  *
1608  * Since: 2.10
1609  */
1610   gtk_widget_class_install_style_property (klass,
1611                                            g_param_spec_boxed ("link-color",
1612                                                                P_("Unvisited Link Color"),
1613                                                                P_("Color of unvisited links"),
1614                                                                GDK_TYPE_COLOR,
1615                                                                GTK_PARAM_READABLE));
1616
1617 /**
1618  * GtkWidget:visited-link-color:
1619  *
1620  * The "visited-link-color" property defines the color of visited links.
1621  *
1622  * Since: 2.10
1623  */
1624   gtk_widget_class_install_style_property (klass,
1625                                            g_param_spec_boxed ("visited-link-color",
1626                                                                P_("Visited Link Color"),
1627                                                                P_("Color of visited links"),
1628                                                                GDK_TYPE_COLOR,
1629                                                                GTK_PARAM_READABLE));
1630
1631 /**
1632  * GtkWidget:wide-separators:
1633  *
1634  * The "wide-separators" property defines whether separators have 
1635  * configurable width and should be drawn using a box instead of a line.
1636  *
1637  * Since: 2.10
1638  */
1639   gtk_widget_class_install_style_property (klass,
1640                                            g_param_spec_boolean ("wide-separators",
1641                                                                  P_("Wide Separators"),
1642                                                                  P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
1643                                                                  FALSE,
1644                                                                  GTK_PARAM_READABLE));
1645
1646 /**
1647  * GtkWidget:separator-width:
1648  *
1649  * The "separator-width" property defines the width of separators.
1650  * This property only takes effect if "wide-separators" is %TRUE.
1651  *
1652  * Since: 2.10
1653  */
1654   gtk_widget_class_install_style_property (klass,
1655                                            g_param_spec_int ("separator-width",
1656                                                              P_("Separator Width"),
1657                                                              P_("The width of separators if wide-separators is TRUE"),
1658                                                              0, G_MAXINT, 0,
1659                                                              GTK_PARAM_READABLE));
1660
1661 /**
1662  * GtkWidget:separator-height:
1663  *
1664  * The "separator-height" property defines the height of separators.
1665  * This property only takes effect if "wide-separators" is %TRUE.
1666  *
1667  * Since: 2.10
1668  */
1669   gtk_widget_class_install_style_property (klass,
1670                                            g_param_spec_int ("separator-height",
1671                                                              P_("Separator Height"),
1672                                                              P_("The height of separators if \"wide-separators\" is TRUE"),
1673                                                              0, G_MAXINT, 0,
1674                                                              GTK_PARAM_READABLE));
1675
1676 /**
1677  * GtkWidget:scroll-arrow-hlength:
1678  *
1679  * The "scroll-arrow-hlength" property defines the length of 
1680  * horizontal scroll arrows.
1681  *
1682  * Since: 2.10
1683  */
1684   gtk_widget_class_install_style_property (klass,
1685                                            g_param_spec_int ("scroll-arrow-hlength",
1686                                                              P_("Horizontal Scroll Arrow Length"),
1687                                                              P_("The length of horizontal scroll arrows"),
1688                                                              1, G_MAXINT, 16,
1689                                                              GTK_PARAM_READABLE));
1690
1691 /**
1692  * GtkWidget:scroll-arrow-vlength:
1693  *
1694  * The "scroll-arrow-vlength" property defines the length of 
1695  * vertical scroll arrows.
1696  *
1697  * Since: 2.10
1698  */
1699   gtk_widget_class_install_style_property (klass,
1700                                            g_param_spec_int ("scroll-arrow-vlength",
1701                                                              P_("Vertical Scroll Arrow Length"),
1702                                                              P_("The length of vertical scroll arrows"),
1703                                                              1, G_MAXINT, 16,
1704                                                              GTK_PARAM_READABLE));
1705 }
1706
1707 static void
1708 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
1709 {
1710   GList *list, *node;
1711
1712   list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
1713   for (node = list; node; node = node->next)
1714     {
1715       GParamSpec *pspec = node->data;
1716
1717       g_param_spec_pool_remove (style_property_spec_pool, pspec);
1718       g_param_spec_unref (pspec);
1719     }
1720   g_list_free (list);
1721 }
1722
1723 static void
1724 gtk_widget_set_property (GObject         *object,
1725                          guint            prop_id,
1726                          const GValue    *value,
1727                          GParamSpec      *pspec)
1728 {
1729   GtkWidget *widget = GTK_WIDGET (object);
1730
1731   switch (prop_id)
1732     {
1733       guint32 saved_flags;
1734       
1735     case PROP_NAME:
1736       gtk_widget_set_name (widget, g_value_get_string (value));
1737       break;
1738     case PROP_PARENT:
1739       gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1740       break;
1741     case PROP_WIDTH_REQUEST:
1742       gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1743       break;
1744     case PROP_HEIGHT_REQUEST:
1745       gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1746       break;
1747     case PROP_VISIBLE:
1748       if (g_value_get_boolean (value))
1749         gtk_widget_show (widget);
1750       else
1751         gtk_widget_hide (widget);
1752       break;
1753     case PROP_SENSITIVE:
1754       gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1755       break;
1756     case PROP_APP_PAINTABLE:
1757       gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1758       break;
1759     case PROP_CAN_FOCUS:
1760       saved_flags = GTK_WIDGET_FLAGS (widget);
1761       if (g_value_get_boolean (value))
1762         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1763       else
1764         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1765       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1766         gtk_widget_queue_resize (widget);
1767       break;
1768     case PROP_HAS_FOCUS:
1769       if (g_value_get_boolean (value))
1770         gtk_widget_grab_focus (widget);
1771       break;
1772     case PROP_IS_FOCUS:
1773       if (g_value_get_boolean (value))
1774         gtk_widget_grab_focus (widget);
1775       break;
1776     case PROP_CAN_DEFAULT:
1777       saved_flags = GTK_WIDGET_FLAGS (widget);
1778       if (g_value_get_boolean (value))
1779         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1780       else
1781         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1782       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1783         gtk_widget_queue_resize (widget);
1784       break;
1785     case PROP_HAS_DEFAULT:
1786       if (g_value_get_boolean (value))
1787         gtk_widget_grab_default (widget);
1788       break;
1789     case PROP_RECEIVES_DEFAULT:
1790       if (g_value_get_boolean (value))
1791         GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1792       else
1793         GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1794       break;
1795     case PROP_STYLE:
1796       gtk_widget_set_style (widget, g_value_get_object (value));
1797       break;
1798     case PROP_EVENTS:
1799       if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1800         gtk_widget_set_events (widget, g_value_get_flags (value));
1801       break;
1802     case PROP_EXTENSION_EVENTS:
1803       gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1804       break;
1805     case PROP_NO_SHOW_ALL:
1806       gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1807       break;
1808     default:
1809       break;
1810     }
1811 }
1812
1813 static void
1814 gtk_widget_get_property (GObject         *object,
1815                          guint            prop_id,
1816                          GValue          *value,
1817                          GParamSpec      *pspec)
1818 {
1819   GtkWidget *widget = GTK_WIDGET (object);
1820   
1821   switch (prop_id)
1822     {
1823       gint *eventp;
1824       GdkExtensionMode *modep;
1825
1826     case PROP_NAME:
1827       if (widget->name)
1828         g_value_set_string (value, widget->name);
1829       else
1830         g_value_set_string (value, "");
1831       break;
1832     case PROP_PARENT:
1833       if (widget->parent)
1834         g_value_set_object (value, widget->parent);
1835       else
1836         g_value_set_object (value, NULL);
1837       break;
1838     case PROP_WIDTH_REQUEST:
1839       {
1840         int w;
1841         gtk_widget_get_size_request (widget, &w, NULL);
1842         g_value_set_int (value, w);
1843       }
1844       break;
1845     case PROP_HEIGHT_REQUEST:
1846       {
1847         int h;
1848         gtk_widget_get_size_request (widget, NULL, &h);
1849         g_value_set_int (value, h);
1850       }
1851       break;
1852     case PROP_VISIBLE:
1853       g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1854       break;
1855     case PROP_SENSITIVE:
1856       g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1857       break;
1858     case PROP_APP_PAINTABLE:
1859       g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1860       break;
1861     case PROP_CAN_FOCUS:
1862       g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1863       break;
1864     case PROP_HAS_FOCUS:
1865       g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1866       break;
1867     case PROP_IS_FOCUS:
1868       g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1869       break;
1870     case PROP_CAN_DEFAULT:
1871       g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1872       break;
1873     case PROP_HAS_DEFAULT:
1874       g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1875       break;
1876     case PROP_RECEIVES_DEFAULT:
1877       g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1878       break;
1879     case PROP_COMPOSITE_CHILD:
1880       g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1881       break;
1882     case PROP_STYLE:
1883       g_value_set_object (value, gtk_widget_get_style (widget));
1884       break;
1885     case PROP_EVENTS:
1886       eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1887       if (!eventp)
1888         g_value_set_flags (value, 0);
1889       else
1890         g_value_set_flags (value, *eventp);
1891       break;
1892     case PROP_EXTENSION_EVENTS:
1893       modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1894       if (!modep)
1895         g_value_set_enum (value, 0);
1896       else
1897         g_value_set_enum (value, (GdkExtensionMode) *modep);
1898       break;
1899     case PROP_NO_SHOW_ALL:
1900       g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1901       break;
1902     default:
1903       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1904       break;
1905     }
1906 }
1907
1908 static void
1909 gtk_widget_init (GtkWidget *widget)
1910 {
1911   GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1912   widget->state = GTK_STATE_NORMAL;
1913   widget->saved_state = GTK_STATE_NORMAL;
1914   widget->name = NULL;
1915   widget->requisition.width = 0;
1916   widget->requisition.height = 0;
1917   widget->allocation.x = -1;
1918   widget->allocation.y = -1;
1919   widget->allocation.width = 1;
1920   widget->allocation.height = 1;
1921   widget->window = NULL;
1922   widget->parent = NULL;
1923
1924   GTK_WIDGET_SET_FLAGS (widget,
1925                         GTK_SENSITIVE |
1926                         GTK_PARENT_SENSITIVE |
1927                         (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1928                         GTK_DOUBLE_BUFFERED);
1929
1930   GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1931   GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1932   GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1933
1934   widget->style = gtk_widget_get_default_style ();
1935   g_object_ref (widget->style);
1936 }
1937
1938
1939 static void
1940 gtk_widget_dispatch_child_properties_changed (GtkWidget   *widget,
1941                                               guint        n_pspecs,
1942                                               GParamSpec **pspecs)
1943 {
1944   GtkWidget *container = widget->parent;
1945   guint i;
1946
1947   for (i = 0; widget->parent == container && i < n_pspecs; i++)
1948     g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1949 }
1950
1951 /**
1952  * gtk_widget_freeze_child_notify:
1953  * @widget: a #GtkWidget
1954  * 
1955  * Stops emission of "child-notify" signals on @widget. The signals are
1956  * queued until gtk_widget_thaw_child_notify() is called on @widget. 
1957  *
1958  * This is the analogue of g_object_freeze_notify() for child properties.
1959  **/
1960 void
1961 gtk_widget_freeze_child_notify (GtkWidget *widget)
1962 {
1963   g_return_if_fail (GTK_IS_WIDGET (widget));
1964
1965   if (!G_OBJECT (widget)->ref_count)
1966     return;
1967
1968   g_object_ref (widget);
1969   g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1970   g_object_unref (widget);
1971 }
1972
1973 /**
1974  * gtk_widget_child_notify:
1975  * @widget: a #GtkWidget
1976  * @child_property: the name of a child property installed on the 
1977  *                  class of @widget<!-- -->'s parent.
1978  * 
1979  * Emits a "child-notify" signal for the 
1980  * <link linkend="child-properties">child property</link> @child_property 
1981  * on @widget.
1982  *
1983  * This is the analogue of g_object_notify() for child properties.
1984  **/
1985 void
1986 gtk_widget_child_notify (GtkWidget    *widget,
1987                          const gchar  *child_property)
1988 {
1989   GParamSpec *pspec;
1990
1991   g_return_if_fail (GTK_IS_WIDGET (widget));
1992   g_return_if_fail (child_property != NULL);
1993   if (!G_OBJECT (widget)->ref_count || !widget->parent)
1994     return;
1995
1996   g_object_ref (widget);
1997   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1998                                     child_property,
1999                                     G_OBJECT_TYPE (widget->parent),
2000                                     TRUE);
2001   if (!pspec)
2002     g_warning ("%s: container class `%s' has no child property named `%s'",
2003                G_STRLOC,
2004                G_OBJECT_TYPE_NAME (widget->parent),
2005                child_property);
2006   else
2007     {
2008       GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2009
2010       g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2011       g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2012     }
2013   g_object_unref (widget);
2014 }
2015
2016 /**
2017  * gtk_widget_thaw_child_notify:
2018  * @widget: a #GtkWidget
2019  *
2020  * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2021  * This causes all queued "child-notify" signals on @widget to be emitted.
2022  */ 
2023 void
2024 gtk_widget_thaw_child_notify (GtkWidget *widget)
2025 {
2026   GObjectNotifyQueue *nqueue;
2027
2028   g_return_if_fail (GTK_IS_WIDGET (widget));
2029
2030   if (!G_OBJECT (widget)->ref_count)
2031     return;
2032
2033   g_object_ref (widget);
2034   nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2035   if (!nqueue || !nqueue->freeze_count)
2036     g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2037                G_OBJECT_TYPE_NAME (widget), widget);
2038   else
2039     g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2040   g_object_unref (widget);
2041 }
2042
2043
2044 /**
2045  * gtk_widget_new:
2046  * @type: type ID of the widget to create
2047  * @first_property_name: name of first property to set
2048  * @Varargs: value of first property, followed by more properties, %NULL-terminated
2049  * 
2050  * This is a convenience function for creating a widget and setting
2051  * its properties in one go. For example you might write:
2052  * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2053  * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2054  * g_object_new(), but returns a widget so you don't have to
2055  * cast the object yourself.
2056  * 
2057  * Return value: a new #GtkWidget of type @widget_type
2058  **/
2059 GtkWidget*
2060 gtk_widget_new (GType        type,
2061                 const gchar *first_property_name,
2062                 ...)
2063 {
2064   GtkWidget *widget;
2065   va_list var_args;
2066   
2067   g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2068   
2069   va_start (var_args, first_property_name);
2070   widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2071   va_end (var_args);
2072
2073   return widget;
2074 }
2075
2076 /**
2077  * gtk_widget_set:
2078  * @widget: a #GtkWidget
2079  * @first_property_name: name of first property to set
2080  * @Varargs: value of first property, followed by more properties, %NULL-terminated
2081  * 
2082  * Like g_object_set() - there's no reason to use this instead of
2083  * g_object_set().
2084  **/
2085 void
2086 gtk_widget_set (GtkWidget   *widget,
2087                 const gchar *first_property_name,
2088                 ...)
2089 {
2090   va_list var_args;
2091
2092   g_return_if_fail (GTK_IS_WIDGET (widget));
2093
2094   va_start (var_args, first_property_name);
2095   g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2096   va_end (var_args);
2097 }
2098
2099 static inline void         
2100 gtk_widget_queue_draw_child (GtkWidget *widget)
2101 {
2102   GtkWidget *parent;
2103
2104   parent = widget->parent;
2105   if (parent && GTK_WIDGET_DRAWABLE (parent))
2106     gtk_widget_queue_draw_area (parent,
2107                                 widget->allocation.x,
2108                                 widget->allocation.y,
2109                                 widget->allocation.width,
2110                                 widget->allocation.height);
2111 }
2112
2113 /**
2114  * gtk_widget_unparent:
2115  * @widget: a #GtkWidget
2116  * 
2117  * This function is only for use in widget implementations.
2118  * Should be called by implementations of the remove method
2119  * on #GtkContainer, to dissociate a child from the container.
2120  **/
2121 void
2122 gtk_widget_unparent (GtkWidget *widget)
2123 {
2124   GObjectNotifyQueue *nqueue;
2125   GtkWidget *toplevel;
2126   GtkWidget *old_parent;
2127   
2128   g_return_if_fail (GTK_IS_WIDGET (widget));
2129   if (widget->parent == NULL)
2130     return;
2131   
2132   /* keep this function in sync with gtk_menu_detach()
2133    */
2134
2135   g_object_freeze_notify (G_OBJECT (widget));
2136   nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2137
2138   toplevel = gtk_widget_get_toplevel (widget);
2139   if (GTK_WIDGET_TOPLEVEL (toplevel))
2140     _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2141
2142   if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2143     gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2144
2145   /* If we are unanchoring the child, we save around the toplevel
2146    * to emit hierarchy changed
2147    */
2148   if (GTK_WIDGET_ANCHORED (widget->parent))
2149     g_object_ref (toplevel);
2150   else
2151     toplevel = NULL;
2152
2153   gtk_widget_queue_draw_child (widget);
2154
2155   /* Reset the width and height here, to force reallocation if we
2156    * get added back to a new parent. This won't work if our new
2157    * allocation is smaller than 1x1 and we actually want a size of 1x1...
2158    * (would 0x0 be OK here?)
2159    */
2160   widget->allocation.width = 1;
2161   widget->allocation.height = 1;
2162   
2163   if (GTK_WIDGET_REALIZED (widget)) 
2164     {
2165       if (GTK_WIDGET_IN_REPARENT (widget))
2166         gtk_widget_unmap (widget);
2167       else
2168         gtk_widget_unrealize (widget);
2169     }
2170
2171   /* Removing a widget from a container restores the child visible
2172    * flag to the default state, so it doesn't affect the child
2173    * in the next parent.
2174    */
2175   GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2176     
2177   old_parent = widget->parent;
2178   widget->parent = NULL;
2179   gtk_widget_set_parent_window (widget, NULL);
2180   g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2181   if (toplevel)
2182     {
2183       _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2184       g_object_unref (toplevel);
2185     }
2186       
2187   g_object_notify (G_OBJECT (widget), "parent");
2188   g_object_thaw_notify (G_OBJECT (widget));
2189   if (!widget->parent)
2190     g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2191   g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2192   g_object_unref (widget);
2193 }
2194
2195 /**
2196  * gtk_widget_destroy:
2197  * @widget: a #GtkWidget
2198  *
2199  * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2200  * you don't have to cast the widget to #GtkObject. When a widget is
2201  * destroyed, it will break any references it holds to other objects.
2202  * If the widget is inside a container, the widget will be removed
2203  * from the container. If the widget is a toplevel (derived from
2204  * #GtkWindow), it will be removed from the list of toplevels, and the
2205  * reference GTK+ holds to it will be removed. Removing a
2206  * widget from its container or the list of toplevels results in the
2207  * widget being finalized, unless you've added additional references
2208  * to the widget with g_object_ref().
2209  *
2210  * In most cases, only toplevel widgets (windows) require explicit
2211  * destruction, because when you destroy a toplevel its children will
2212  * be destroyed as well.
2213  * 
2214  **/
2215 void
2216 gtk_widget_destroy (GtkWidget *widget)
2217 {
2218   g_return_if_fail (GTK_IS_WIDGET (widget));
2219
2220   gtk_object_destroy ((GtkObject*) widget);
2221 }
2222
2223 /**
2224  * gtk_widget_destroyed:
2225  * @widget: a #GtkWidget
2226  * @widget_pointer: address of a variable that contains @widget
2227  *
2228  * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2229  * %NULL.  It's intended to be used as a callback connected to the
2230  * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2231  * as a signal handler, and pass the address of your widget variable
2232  * as user data. Then when the widget is destroyed, the variable will
2233  * be set to %NULL. Useful for example to avoid multiple copies
2234  * of the same dialog.
2235  * 
2236  **/
2237 void
2238 gtk_widget_destroyed (GtkWidget      *widget,
2239                       GtkWidget      **widget_pointer)
2240 {
2241   /* Don't make any assumptions about the
2242    *  value of widget!
2243    *  Even check widget_pointer.
2244    */
2245   if (widget_pointer)
2246     *widget_pointer = NULL;
2247 }
2248
2249 /**
2250  * gtk_widget_show:
2251  * @widget: a #GtkWidget
2252  * 
2253  * Flags a widget to be displayed. Any widget that isn't shown will
2254  * not appear on the screen. If you want to show all the widgets in a
2255  * container, it's easier to call gtk_widget_show_all() on the
2256  * container, instead of individually showing the widgets.
2257  *
2258  * Remember that you have to show the containers containing a widget,
2259  * in addition to the widget itself, before it will appear onscreen.
2260  *
2261  * When a toplevel container is shown, it is immediately realized and
2262  * mapped; other shown widgets are realized and mapped when their
2263  * toplevel container is realized and mapped.
2264  * 
2265  **/
2266 void
2267 gtk_widget_show (GtkWidget *widget)
2268 {
2269   g_return_if_fail (GTK_IS_WIDGET (widget));
2270
2271   if (!GTK_WIDGET_VISIBLE (widget))
2272     {
2273       g_object_ref (widget);
2274       if (!GTK_WIDGET_TOPLEVEL (widget))
2275         gtk_widget_queue_resize (widget);
2276       g_signal_emit (widget, widget_signals[SHOW], 0);
2277       g_object_notify (G_OBJECT (widget), "visible");
2278       g_object_unref (widget);
2279     }
2280 }
2281
2282 static void
2283 gtk_widget_real_show (GtkWidget *widget)
2284 {
2285   if (!GTK_WIDGET_VISIBLE (widget))
2286     {
2287       GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2288
2289       if (widget->parent &&
2290           GTK_WIDGET_MAPPED (widget->parent) &&
2291           GTK_WIDGET_CHILD_VISIBLE (widget) &&
2292           !GTK_WIDGET_MAPPED (widget))
2293         gtk_widget_map (widget);
2294     }
2295 }
2296
2297 static void
2298 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2299 {
2300   *flag = TRUE;
2301   g_signal_handlers_disconnect_by_func (widget,
2302                                         gtk_widget_show_map_callback, 
2303                                         flag);
2304 }
2305
2306 /**
2307  * gtk_widget_show_now:
2308  * @widget: a #GtkWidget
2309  * 
2310  * Shows a widget. If the widget is an unmapped toplevel widget
2311  * (i.e. a #GtkWindow that has not yet been shown), enter the main
2312  * loop and wait for the window to actually be mapped. Be careful;
2313  * because the main loop is running, anything can happen during
2314  * this function.
2315  **/
2316 void
2317 gtk_widget_show_now (GtkWidget *widget)
2318 {
2319   gint flag = FALSE;
2320   
2321   g_return_if_fail (GTK_IS_WIDGET (widget));
2322
2323   /* make sure we will get event */
2324   if (!GTK_WIDGET_MAPPED (widget) &&
2325       GTK_WIDGET_TOPLEVEL (widget))
2326     {
2327       gtk_widget_show (widget);
2328
2329       g_signal_connect (widget, "map_event",
2330                         G_CALLBACK (gtk_widget_show_map_callback), 
2331                         &flag);
2332
2333       while (!flag)
2334         gtk_main_iteration ();
2335     }
2336   else
2337     gtk_widget_show (widget);
2338 }
2339
2340 /**
2341  * gtk_widget_hide:
2342  * @widget: a #GtkWidget
2343  * 
2344  * Reverses the effects of gtk_widget_show(), causing the widget to be
2345  * hidden (invisible to the user).
2346  **/
2347 void
2348 gtk_widget_hide (GtkWidget *widget)
2349 {
2350   g_return_if_fail (GTK_IS_WIDGET (widget));
2351   
2352   if (GTK_WIDGET_VISIBLE (widget))
2353     {
2354       GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2355       
2356       g_object_ref (widget);
2357       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2358         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2359
2360       g_signal_emit (widget, widget_signals[HIDE], 0);
2361       if (!GTK_WIDGET_TOPLEVEL (widget))
2362         gtk_widget_queue_resize (widget);
2363       g_object_notify (G_OBJECT (widget), "visible");
2364       g_object_unref (widget);
2365     }
2366 }
2367
2368 static void
2369 gtk_widget_real_hide (GtkWidget *widget)
2370 {
2371   if (GTK_WIDGET_VISIBLE (widget))
2372     {
2373       GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2374       
2375       if (GTK_WIDGET_MAPPED (widget))
2376         gtk_widget_unmap (widget);
2377     }
2378 }
2379
2380 /**
2381  * gtk_widget_hide_on_delete:
2382  * @widget: a #GtkWidget
2383  * 
2384  * Utility function; intended to be connected to the "delete_event"
2385  * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2386  * argument, then returns %TRUE. If connected to "delete_event", the
2387  * result is that clicking the close button for a window (on the
2388  * window frame, top right corner usually) will hide but not destroy
2389  * the window. By default, GTK+ destroys windows when "delete_event"
2390  * is received.
2391  * 
2392  * Return value: %TRUE
2393  **/
2394 gboolean
2395 gtk_widget_hide_on_delete (GtkWidget      *widget)
2396 {
2397   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2398   
2399   gtk_widget_hide (widget);
2400   
2401   return TRUE;
2402 }
2403
2404 /**
2405  * gtk_widget_show_all:
2406  * @widget: a #GtkWidget
2407  * 
2408  * Recursively shows a widget, and any child widgets (if the widget is
2409  * a container).
2410  **/
2411 void
2412 gtk_widget_show_all (GtkWidget *widget)
2413 {
2414   GtkWidgetClass *class;
2415
2416   g_return_if_fail (GTK_IS_WIDGET (widget));
2417
2418   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2419     return;
2420
2421   class = GTK_WIDGET_GET_CLASS (widget);
2422
2423   if (class->show_all)
2424     class->show_all (widget);
2425 }
2426
2427 /**
2428  * gtk_widget_hide_all:
2429  * @widget: a #GtkWidget
2430  * 
2431  * Recursively hides a widget and any child widgets.
2432  **/
2433 void
2434 gtk_widget_hide_all (GtkWidget *widget)
2435 {
2436   GtkWidgetClass *class;
2437
2438   g_return_if_fail (GTK_IS_WIDGET (widget));
2439
2440   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2441     return;
2442
2443   class = GTK_WIDGET_GET_CLASS (widget);
2444
2445   if (class->hide_all)
2446     class->hide_all (widget);
2447 }
2448
2449 /**
2450  * gtk_widget_map:
2451  * @widget: a #GtkWidget
2452  * 
2453  * This function is only for use in widget implementations. Causes
2454  * a widget to be mapped if it isn't already.
2455  * 
2456  **/
2457 void
2458 gtk_widget_map (GtkWidget *widget)
2459 {
2460   g_return_if_fail (GTK_IS_WIDGET (widget));
2461   g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2462   g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2463   
2464   if (!GTK_WIDGET_MAPPED (widget))
2465     {
2466       if (!GTK_WIDGET_REALIZED (widget))
2467         gtk_widget_realize (widget);
2468
2469       g_signal_emit (widget, widget_signals[MAP], 0);
2470
2471       if (GTK_WIDGET_NO_WINDOW (widget))
2472         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2473     }
2474 }
2475
2476 /**
2477  * gtk_widget_unmap:
2478  * @widget: a #GtkWidget
2479  *
2480  * This function is only for use in widget implementations. Causes
2481  * a widget to be unmapped if it's currently mapped.
2482  * 
2483  **/
2484 void
2485 gtk_widget_unmap (GtkWidget *widget)
2486 {
2487   g_return_if_fail (GTK_IS_WIDGET (widget));
2488   
2489   if (GTK_WIDGET_MAPPED (widget))
2490     {
2491       if (GTK_WIDGET_NO_WINDOW (widget))
2492         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2493       g_signal_emit (widget, widget_signals[UNMAP], 0);
2494     }
2495 }
2496
2497 /**
2498  * gtk_widget_realize:
2499  * @widget: a #GtkWidget
2500  * 
2501  * Creates the GDK (windowing system) resources associated with a
2502  * widget.  For example, @widget->window will be created when a widget
2503  * is realized.  Normally realization happens implicitly; if you show
2504  * a widget and all its parent containers, then the widget will be
2505  * realized and mapped automatically.
2506  * 
2507  * Realizing a widget requires all
2508  * the widget's parent widgets to be realized; calling
2509  * gtk_widget_realize() realizes the widget's parents in addition to
2510  * @widget itself. If a widget is not yet inside a toplevel window
2511  * when you realize it, bad things will happen.
2512  *
2513  * This function is primarily used in widget implementations, and
2514  * isn't very useful otherwise. Many times when you think you might
2515  * need it, a better approach is to connect to a signal that will be
2516  * called after the widget is realized automatically, such as
2517  * "expose_event". Or simply g_signal_connect_after() to the
2518  * "realize" signal.
2519  *  
2520  **/
2521 void
2522 gtk_widget_realize (GtkWidget *widget)
2523 {
2524   gint events;
2525   GdkExtensionMode mode;
2526   GtkWidgetShapeInfo *shape_info;
2527   
2528   g_return_if_fail (GTK_IS_WIDGET (widget));
2529   g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2530                     GTK_IS_INVISIBLE (widget));
2531   
2532   if (!GTK_WIDGET_REALIZED (widget))
2533     {
2534       /*
2535         if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2536           g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2537       */
2538
2539       if (widget->parent == NULL &&
2540           !GTK_WIDGET_TOPLEVEL (widget))
2541         g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2542                    "inside a toplevel window is not going to work very well. "
2543                    "Widgets must be inside a toplevel container before realizing them.");
2544       
2545       if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2546         gtk_widget_realize (widget->parent);
2547
2548       gtk_widget_ensure_style (widget);
2549       
2550       g_signal_emit (widget, widget_signals[REALIZE], 0);
2551       
2552       if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2553         {
2554           shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2555           gdk_window_shape_combine_mask (widget->window,
2556                                          shape_info->shape_mask,
2557                                          shape_info->offset_x,
2558                                          shape_info->offset_y);
2559         }
2560       
2561       shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
2562       if (shape_info)
2563         gdk_window_input_shape_combine_mask (widget->window,
2564                                              shape_info->shape_mask,
2565                                              shape_info->offset_x,
2566                                              shape_info->offset_y);
2567
2568       if (!GTK_WIDGET_NO_WINDOW (widget))
2569         {
2570           mode = gtk_widget_get_extension_events (widget);
2571           if (mode != GDK_EXTENSION_EVENTS_NONE)
2572             {
2573               events = gtk_widget_get_events (widget);
2574               gdk_input_set_extension_events (widget->window, events, mode);
2575             }
2576         }
2577       
2578     }
2579 }
2580
2581 /**
2582  * gtk_widget_unrealize:
2583  * @widget: a #GtkWidget
2584  *
2585  * This function is only useful in widget implementations.
2586  * Causes a widget to be unrealized (frees all GDK resources
2587  * associated with the widget, such as @widget->window).
2588  * 
2589  **/
2590 void
2591 gtk_widget_unrealize (GtkWidget *widget)
2592 {
2593   g_return_if_fail (GTK_IS_WIDGET (widget));
2594
2595   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2596     gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
2597
2598   if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
2599     gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
2600
2601   if (GTK_WIDGET_REALIZED (widget))
2602     {
2603       g_object_ref (widget);
2604       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2605       GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2606       g_object_unref (widget);
2607     }
2608 }
2609
2610 /*****************************************
2611  * Draw queueing.
2612  *****************************************/
2613
2614 /**
2615  * gtk_widget_queue_draw_area:
2616  * @widget: a #GtkWidget
2617  * @x: x coordinate of upper-left corner of rectangle to redraw
2618  * @y: y coordinate of upper-left corner of rectangle to redraw
2619  * @width: width of region to draw
2620  * @height: height of region to draw
2621  *
2622  * Invalidates the rectangular area of @widget defined by @x, @y,
2623  * @width and @height by calling gdk_window_invalidate_rect() on the
2624  * widget's window and all its child windows.  Once the main loop
2625  * becomes idle (after the current batch of events has been processed,
2626  * roughly), the window will receive expose events for the union of
2627  * all regions that have been invalidated.
2628  *
2629  * Normally you would only use this function in widget
2630  * implementations. You might also use it, or
2631  * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2632  * #GtkDrawingArea or some portion thereof.
2633  *
2634  * Frequently you can just call gdk_window_invalidate_rect() or
2635  * gdk_window_invalidate_region() instead of this function. Those
2636  * functions will invalidate only a single window, instead of the
2637  * widget and all its children.
2638  *
2639  * The advantage of adding to the invalidated region compared to
2640  * simply drawing immediately is efficiency; using an invalid region
2641  * ensures that you only have to redraw one time.
2642  * 
2643  **/
2644 void       
2645 gtk_widget_queue_draw_area (GtkWidget *widget,
2646                             gint       x,
2647                             gint       y,
2648                             gint       width,
2649                             gint       height)
2650 {
2651   GdkRectangle invalid_rect;
2652   GtkWidget *w;
2653   
2654   g_return_if_fail (GTK_IS_WIDGET (widget));
2655
2656   if (!GTK_WIDGET_REALIZED (widget))
2657     return;
2658   
2659   /* Just return if the widget or one of its ancestors isn't mapped */
2660   for (w = widget; w != NULL; w = w->parent)
2661     if (!GTK_WIDGET_MAPPED (w))
2662       return;
2663
2664   /* Find the correct widget */
2665
2666   if (!GTK_WIDGET_NO_WINDOW (widget))
2667     {
2668       if (widget->parent)
2669         {
2670           /* Translate widget relative to window-relative */
2671
2672           gint wx, wy, wwidth, wheight;
2673           
2674           gdk_window_get_position (widget->window, &wx, &wy);
2675           x -= wx - widget->allocation.x;
2676           y -= wy - widget->allocation.y;
2677           
2678           gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2679
2680           if (x + width <= 0 || y + height <= 0 ||
2681               x >= wwidth || y >= wheight)
2682             return;
2683           
2684           if (x < 0)
2685             {
2686               width += x;  x = 0;
2687             }
2688           if (y < 0)
2689             {
2690               height += y; y = 0;
2691             }
2692           if (x + width > wwidth)
2693             width = wwidth - x;
2694           if (y + height > wheight)
2695             height = wheight - y;
2696         }
2697     }
2698
2699   invalid_rect.x = x;
2700   invalid_rect.y = y;
2701   invalid_rect.width = width;
2702   invalid_rect.height = height;
2703   
2704   gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2705 }
2706
2707 static void
2708 widget_add_child_draw_rectangle (GtkWidget    *widget,
2709                                  GdkRectangle *rect)
2710 {
2711   GdkRectangle child_rect;
2712   
2713   if (!GTK_WIDGET_MAPPED (widget) ||
2714       widget->window != widget->parent->window)
2715     return;
2716
2717   gtk_widget_get_draw_rectangle (widget, &child_rect);
2718   gdk_rectangle_union (rect, &child_rect, rect);
2719 }
2720
2721 static void
2722 gtk_widget_get_draw_rectangle (GtkWidget    *widget,
2723                                GdkRectangle *rect)
2724 {
2725   if (GTK_WIDGET_NO_WINDOW (widget))
2726     {
2727       GtkBorder *draw_border = NULL;
2728
2729       *rect = widget->allocation;
2730
2731       gtk_widget_style_get (widget, 
2732                             "draw-border", &draw_border,
2733                             NULL);
2734       if (draw_border)
2735         {
2736           rect->x -= draw_border->top;
2737           rect->y -= draw_border->left;
2738           rect->width += draw_border->left + draw_border->right;
2739           rect->height += draw_border->top + draw_border->bottom;
2740
2741           gtk_border_free (draw_border);
2742         }
2743
2744       if (GTK_IS_CONTAINER (widget))
2745         gtk_container_forall (GTK_CONTAINER (widget),
2746                               (GtkCallback)widget_add_child_draw_rectangle,
2747                               rect);
2748     }
2749   else
2750     {
2751       rect->x = 0;
2752       rect->y = 0;
2753       rect->width = widget->allocation.width;
2754       rect->height = widget->allocation.height;
2755     }
2756 }
2757
2758 /**
2759  * gtk_widget_queue_draw:
2760  * @widget: a #GtkWidget
2761  *
2762  * Equivalent to calling gtk_widget_queue_draw_area() for the
2763  * entire area of a widget.
2764  * 
2765  **/
2766 void       
2767 gtk_widget_queue_draw (GtkWidget *widget)
2768 {
2769   GdkRectangle rect;
2770   
2771   g_return_if_fail (GTK_IS_WIDGET (widget));
2772
2773   gtk_widget_get_draw_rectangle (widget, &rect);
2774
2775   gtk_widget_queue_draw_area (widget,
2776                               rect.x, rect.y,
2777                               rect.width, rect.height);
2778 }
2779
2780 /* Invalidates the given area (allocation-relative-coordinates)
2781  * in all of the widget's windows
2782  */
2783 /**
2784  * gtk_widget_queue_clear_area:
2785  * @widget: a #GtkWidget
2786  * @x: x coordinate of upper-left corner of rectangle to redraw
2787  * @y: y coordinate of upper-left corner of rectangle to redraw
2788  * @width: width of region to draw
2789  * @height: height of region to draw
2790  * 
2791  * This function is no longer different from
2792  * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2793  * gtk_widget_queue_draw_area(). Originally
2794  * gtk_widget_queue_clear_area() would force a redraw of the
2795  * background for %GTK_NO_WINDOW widgets, and
2796  * gtk_widget_queue_draw_area() would not. Now both functions ensure
2797  * the background will be redrawn.
2798  * 
2799  * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2800  **/
2801 void       
2802 gtk_widget_queue_clear_area (GtkWidget *widget,
2803                              gint       x,
2804                              gint       y,
2805                              gint       width,
2806                              gint       height)
2807 {
2808   g_return_if_fail (GTK_IS_WIDGET (widget));
2809
2810   gtk_widget_queue_draw_area (widget, x, y, width, height);
2811 }
2812
2813 /**
2814  * gtk_widget_queue_clear:
2815  * @widget: a #GtkWidget
2816  * 
2817  * This function does the same as gtk_widget_queue_draw().
2818  *
2819  * @Deprecated: Use gtk_widget_queue_draw() instead.
2820  **/
2821 void       
2822 gtk_widget_queue_clear (GtkWidget *widget)
2823 {
2824   g_return_if_fail (GTK_IS_WIDGET (widget));
2825
2826   gtk_widget_queue_draw (widget);
2827 }
2828
2829 /**
2830  * gtk_widget_queue_resize:
2831  * @widget: a #GtkWidget
2832  *
2833  * This function is only for use in widget implementations.
2834  * Flags a widget to have its size renegotiated; should
2835  * be called when a widget for some reason has a new size request.
2836  * For example, when you change the text in a #GtkLabel, #GtkLabel
2837  * queues a resize to ensure there's enough space for the new text.
2838  **/
2839 void
2840 gtk_widget_queue_resize (GtkWidget *widget)
2841 {
2842   g_return_if_fail (GTK_IS_WIDGET (widget));
2843
2844   if (GTK_WIDGET_REALIZED (widget))
2845     gtk_widget_queue_shallow_draw (widget);
2846       
2847   _gtk_size_group_queue_resize (widget);
2848 }
2849
2850 /**
2851  * gtk_widget_queue_resize_no_redraw:
2852  * @widget: a #GtkWidget
2853  *
2854  * This function works like gtk_widget_queue_resize(), except that the
2855  * widget is not invalidated.
2856  *
2857  * Since: 2.4
2858  **/
2859 void
2860 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2861 {
2862   g_return_if_fail (GTK_IS_WIDGET (widget));
2863
2864   _gtk_size_group_queue_resize (widget);
2865 }
2866
2867 /**
2868  * gtk_widget_draw:
2869  * @widget: a #GtkWidget
2870  * @area: area to draw
2871  *
2872  * In GTK+ 1.2, this function would immediately render the
2873  * region @area of a widget, by invoking the virtual draw method of a
2874  * widget. In GTK+ 2.0, the draw method is gone, and instead
2875  * gtk_widget_draw() simply invalidates the specified region of the
2876  * widget, then updates the invalid region of the widget immediately.
2877  * Usually you don't want to update the region immediately for
2878  * performance reasons, so in general gtk_widget_queue_draw_area() is
2879  * a better choice if you want to draw a region of a widget.
2880  * 
2881  **/
2882 void
2883 gtk_widget_draw (GtkWidget    *widget,
2884                  GdkRectangle *area)
2885 {
2886   g_return_if_fail (GTK_IS_WIDGET (widget));
2887
2888   if (GTK_WIDGET_DRAWABLE (widget))
2889     {
2890       if (area)
2891         gtk_widget_queue_draw_area (widget,
2892                                     area->x, area->y,
2893                                     area->width, area->height);
2894       else
2895         gtk_widget_queue_draw (widget);
2896
2897       gdk_window_process_updates (widget->window, TRUE);
2898     }
2899 }
2900
2901 /**
2902  * gtk_widget_size_request:
2903  * @widget: a #GtkWidget
2904  * @requisition: a #GtkRequisition to be filled in
2905  * 
2906  * This function is typically used when implementing a #GtkContainer
2907  * subclass.  Obtains the preferred size of a widget. The container
2908  * uses this information to arrange its child widgets and decide what
2909  * size allocations to give them with gtk_widget_size_allocate().
2910  *
2911  * You can also call this function from an application, with some
2912  * caveats. Most notably, getting a size request requires the widget
2913  * to be associated with a screen, because font information may be
2914  * needed. Multihead-aware applications should keep this in mind.
2915  *
2916  * Also remember that the size request is not necessarily the size
2917  * a widget will actually be allocated.
2918  *
2919  * See also gtk_widget_get_child_requisition().
2920  **/
2921 void
2922 gtk_widget_size_request (GtkWidget      *widget,
2923                          GtkRequisition *requisition)
2924 {
2925   g_return_if_fail (GTK_IS_WIDGET (widget));
2926
2927 #ifdef G_ENABLE_DEBUG
2928   if (requisition == &widget->requisition)
2929     g_warning ("gtk_widget_size_request() called on child widget with request equal\n to widget->requisition. gtk_widget_set_usize() may not work properly.");
2930 #endif /* G_ENABLE_DEBUG */
2931
2932   _gtk_size_group_compute_requisition (widget, requisition);
2933 }
2934
2935 /**
2936  * gtk_widget_get_child_requisition:
2937  * @widget: a #GtkWidget
2938  * @requisition: a #GtkRequisition to be filled in
2939  * 
2940  * This function is only for use in widget implementations. Obtains
2941  * @widget->requisition, unless someone has forced a particular
2942  * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2943  * case it returns that geometry instead of the widget's requisition.
2944  *
2945  * This function differs from gtk_widget_size_request() in that
2946  * it retrieves the last size request value from @widget->requisition,
2947  * while gtk_widget_size_request() actually calls the "size_request" method
2948  * on @widget to compute the size request and fill in @widget->requisition,
2949  * and only then returns @widget->requisition.
2950  *
2951  * Because this function does not call the "size_request" method, it
2952  * can only be used when you know that @widget->requisition is
2953  * up-to-date, that is, gtk_widget_size_request() has been called
2954  * since the last time a resize was queued. In general, only container
2955  * implementations have this information; applications should use
2956  * gtk_widget_size_request().
2957  **/
2958 void
2959 gtk_widget_get_child_requisition (GtkWidget      *widget,
2960                                   GtkRequisition *requisition)
2961 {
2962   _gtk_size_group_get_child_requisition (widget, requisition);
2963 }
2964
2965 static gboolean
2966 invalidate_predicate (GdkWindow *window,
2967                       gpointer   data)
2968 {
2969   gpointer user_data;
2970
2971   gdk_window_get_user_data (window, &user_data);
2972
2973   return (user_data == data);
2974 }
2975
2976 /* Invalidate @region in widget->window and all children
2977  * of widget->window owned by widget. @region is in the
2978  * same coordinates as widget->allocation and will be
2979  * modified by this call.
2980  */
2981 static void
2982 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2983                                       GdkRegion *region)
2984 {
2985   if (!GTK_WIDGET_REALIZED (widget))
2986     return;
2987   
2988   if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2989     {
2990       int x, y;
2991       
2992       gdk_window_get_position (widget->window, &x, &y);
2993       gdk_region_offset (region, -x, -y);
2994     }
2995
2996   gdk_window_invalidate_maybe_recurse (widget->window, region,
2997                                        invalidate_predicate, widget);
2998 }
2999
3000 /**
3001  * gtk_widget_queue_shallow_draw:
3002  * @widget: a #GtkWidget
3003  *
3004  * Like gtk_widget_queue_draw(), but only windows owned
3005  * by @widget are invalidated.
3006  **/
3007 static void
3008 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3009 {
3010   GdkRectangle rect;
3011   GdkRegion *region;
3012   
3013   if (!GTK_WIDGET_REALIZED (widget))
3014     return;
3015
3016   gtk_widget_get_draw_rectangle (widget, &rect);
3017
3018   /* get_draw_rectangle() gives us window coordinates, we
3019    * need to convert to the coordinates that widget->allocation
3020    * is in.
3021    */
3022   if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3023     {
3024       int wx, wy;
3025       
3026       gdk_window_get_position (widget->window, &wx, &wy);
3027       
3028       rect.x += wx;
3029       rect.y += wy;
3030     }
3031   
3032   region = gdk_region_rectangle (&rect);
3033   gtk_widget_invalidate_widget_windows (widget, region);
3034   gdk_region_destroy (region);
3035 }
3036
3037 /**
3038  * gtk_widget_size_allocate:
3039  * @widget: a #GtkWidget
3040  * @allocation: position and size to be allocated to @widget
3041  *
3042  * This function is only used by #GtkContainer subclasses, to assign a size
3043  * and position to their child widgets. 
3044  * 
3045  **/
3046 void
3047 gtk_widget_size_allocate (GtkWidget     *widget,
3048                           GtkAllocation *allocation)
3049 {
3050   GtkWidgetAuxInfo *aux_info;
3051   GdkRectangle real_allocation;
3052   GdkRectangle old_allocation;
3053   gboolean alloc_needed;
3054   gboolean size_changed;
3055   gboolean position_changed;
3056   
3057   g_return_if_fail (GTK_IS_WIDGET (widget));
3058  
3059 #ifdef G_ENABLE_DEBUG
3060   if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3061     {
3062       gint depth;
3063       GtkWidget *parent;
3064       const gchar *name;
3065
3066       depth = 0;
3067       parent = widget;
3068       while (parent)
3069         {
3070           depth++;
3071           parent = gtk_widget_get_parent (parent);
3072         }
3073       
3074       name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3075       g_print ("gtk_widget_size_allocate: %*s%s %d %d\n", 
3076                2 * depth, " ", name, 
3077                allocation->width, allocation->height);
3078     }
3079 #endif /* G_ENABLE_DEBUG */
3080  
3081   alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3082   if (!GTK_WIDGET_REQUEST_NEEDED (widget))      /* Preserve request/allocate ordering */
3083     GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3084
3085   old_allocation = widget->allocation;
3086   real_allocation = *allocation;
3087   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3088   
3089   if (aux_info)
3090     {
3091       if (aux_info->x_set)
3092         real_allocation.x = aux_info->x;
3093       if (aux_info->y_set)
3094         real_allocation.y = aux_info->y;
3095     }
3096
3097   if (real_allocation.width < 0 || real_allocation.height < 0)
3098     {
3099       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3100                  real_allocation.width,
3101                  real_allocation.height);
3102     }
3103   
3104   real_allocation.width = MAX (real_allocation.width, 1);
3105   real_allocation.height = MAX (real_allocation.height, 1);
3106
3107   size_changed = (old_allocation.width != real_allocation.width ||
3108                   old_allocation.height != real_allocation.height);
3109   position_changed = (old_allocation.x != real_allocation.x ||
3110                       old_allocation.y != real_allocation.y);
3111
3112   if (!alloc_needed && !size_changed && !position_changed)
3113     return;
3114   
3115   g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3116
3117   if (GTK_WIDGET_MAPPED (widget))
3118     {
3119       if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3120         {
3121           /* Invalidate union(old_allaction,widget->allocation) in widget->window
3122            */
3123           GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3124           gdk_region_union_with_rect (invalidate, &old_allocation);
3125
3126           gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3127           gdk_region_destroy (invalidate);
3128         }
3129       
3130       if (size_changed)
3131         {
3132           if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3133             {
3134               /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3135                */
3136               GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3137               gdk_region_union_with_rect (invalidate, &old_allocation);
3138
3139               gtk_widget_invalidate_widget_windows (widget, invalidate);
3140               gdk_region_destroy (invalidate);
3141             }
3142         }
3143     }
3144
3145   if ((size_changed || position_changed) && widget->parent &&
3146       GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3147     {
3148       GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3149       gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3150       gdk_region_destroy (invalidate);
3151     }
3152 }
3153
3154 /**
3155  * gtk_widget_common_ancestor:
3156  * @widget_a: a #GtkWidget
3157  * @widget_b: a #GtkWidget
3158  * 
3159  * Find the common ancestor of @widget_a and @widget_b that
3160  * is closest to the two widgets.
3161  * 
3162  * Return value: the closest common ancestor of @widget_a and
3163  *   @widget_b or %NULL if @widget_a and @widget_b do not
3164  *   share a common ancestor.
3165  **/
3166 static GtkWidget *
3167 gtk_widget_common_ancestor (GtkWidget *widget_a,
3168                             GtkWidget *widget_b)
3169 {
3170   GtkWidget *parent_a;
3171   GtkWidget *parent_b;
3172   gint depth_a = 0;
3173   gint depth_b = 0;
3174
3175   parent_a = widget_a;
3176   while (parent_a->parent)
3177     {
3178       parent_a = parent_a->parent;
3179       depth_a++;
3180     }
3181
3182   parent_b = widget_b;
3183   while (parent_b->parent)
3184     {
3185       parent_b = parent_b->parent;
3186       depth_b++;
3187     }
3188
3189   if (parent_a != parent_b)
3190     return NULL;
3191
3192   while (depth_a > depth_b)
3193     {
3194       widget_a = widget_a->parent;
3195       depth_a--;
3196     }
3197
3198   while (depth_b > depth_a)
3199     {
3200       widget_b = widget_b->parent;
3201       depth_b--;
3202     }
3203
3204   while (widget_a != widget_b)
3205     {
3206       widget_a = widget_a->parent;
3207       widget_b = widget_b->parent;
3208     }
3209
3210   return widget_a;
3211 }
3212
3213 /**
3214  * gtk_widget_translate_coordinates:
3215  * @src_widget:  a #GtkWidget
3216  * @dest_widget: a #GtkWidget
3217  * @src_x: X position relative to @src_widget
3218  * @src_y: Y position relative to @src_widget
3219  * @dest_x: location to store X position relative to @dest_widget
3220  * @dest_y: location to store Y position relative to @dest_widget
3221  * 
3222  * Translate coordinates relative to @src_widget's allocation to coordinates
3223  * relative to @dest_widget's allocations. In order to perform this
3224  * operation, both widgets must be realized, and must share a common
3225  * toplevel.
3226  * 
3227  * Return value: %FALSE if either widget was not realized, or there
3228  *   was no common ancestor. In this case, nothing is stored in
3229  *   *@dest_x and *@dest_y. Otherwise %TRUE.
3230  **/
3231 gboolean
3232 gtk_widget_translate_coordinates (GtkWidget  *src_widget,
3233                                   GtkWidget  *dest_widget,
3234                                   gint        src_x,
3235                                   gint        src_y,
3236                                   gint       *dest_x,
3237                                   gint       *dest_y)
3238 {
3239   GtkWidget *ancestor;
3240   GdkWindow *window;
3241
3242   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3243   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3244
3245   ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3246   if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3247     return FALSE;
3248
3249   /* Translate from allocation relative to window relative */
3250   if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3251     {
3252       gint wx, wy;
3253       gdk_window_get_position (src_widget->window, &wx, &wy);
3254
3255       src_x -= wx - src_widget->allocation.x;
3256       src_y -= wy - src_widget->allocation.y;
3257     }
3258   else
3259     {
3260       src_x += src_widget->allocation.x;
3261       src_y += src_widget->allocation.y;
3262     }
3263
3264   /* Translate to the common ancestor */
3265   window = src_widget->window;
3266   while (window != ancestor->window)
3267     {
3268       gint dx, dy;
3269       
3270       gdk_window_get_position (window, &dx, &dy);
3271       
3272       src_x += dx;
3273       src_y += dy;
3274       
3275       window = gdk_window_get_parent (window);
3276
3277       if (!window)              /* Handle GtkHandleBox */
3278         return FALSE;
3279     }
3280
3281   /* And back */
3282   window = dest_widget->window;
3283   while (window != ancestor->window)
3284     {
3285       gint dx, dy;
3286       
3287       gdk_window_get_position (window, &dx, &dy);
3288       
3289       src_x -= dx;
3290       src_y -= dy;
3291       
3292       window = gdk_window_get_parent (window);
3293       
3294       if (!window)              /* Handle GtkHandleBox */
3295         return FALSE;
3296     }
3297
3298   /* Translate from window relative to allocation relative */
3299   if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
3300     {
3301       gint wx, wy;
3302       gdk_window_get_position (dest_widget->window, &wx, &wy);
3303
3304       src_x += wx - dest_widget->allocation.x;
3305       src_y += wy - dest_widget->allocation.y;
3306     }
3307   else
3308     {
3309       src_x -= dest_widget->allocation.x;
3310       src_y -= dest_widget->allocation.y;
3311     }
3312
3313   if (dest_x)
3314     *dest_x = src_x;
3315   if (dest_y)
3316     *dest_y = src_y;
3317
3318   return TRUE;
3319 }
3320
3321 static void
3322 gtk_widget_real_size_allocate (GtkWidget     *widget,
3323                                GtkAllocation *allocation)
3324 {
3325   widget->allocation = *allocation;
3326   
3327   if (GTK_WIDGET_REALIZED (widget) &&
3328       !GTK_WIDGET_NO_WINDOW (widget))
3329      {
3330         gdk_window_move_resize (widget->window,
3331                                 allocation->x, allocation->y,
3332                                 allocation->width, allocation->height);
3333      }
3334 }
3335
3336 static gboolean
3337 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3338                                     guint      signal_id)
3339 {
3340   /* widgets must be onscreen for accels to take effect */
3341   return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3342 }
3343
3344 /**
3345  * gtk_widget_can_activate_accel:
3346  * @widget: a #GtkWidget
3347  * @signal_id: the ID of a signal installed on @widget
3348  * 
3349  * Determines whether an accelerator that activates the signal
3350  * identified by @signal_id can currently be activated.
3351  * This is done by emitting the GtkWidget::can-activate-accel
3352  * signal on @widget; if the signal isn't overridden by a
3353  * handler or in a derived widget, then the default check is
3354  * that the widget must be sensitive, and the widget and all
3355  * its ancestors mapped.
3356  *
3357  * Return value: %TRUE if the accelerator can be activated.
3358  *
3359  * Since: 2.4
3360  **/
3361 gboolean
3362 gtk_widget_can_activate_accel (GtkWidget *widget,
3363                                guint      signal_id)
3364 {
3365   gboolean can_activate = FALSE;
3366   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3367   g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3368   return can_activate;
3369 }
3370
3371 typedef struct {
3372   GClosure   closure;
3373   guint      signal_id;
3374 } AccelClosure;
3375
3376 static void
3377 closure_accel_activate (GClosure     *closure,
3378                         GValue       *return_value,
3379                         guint         n_param_values,
3380                         const GValue *param_values,
3381                         gpointer      invocation_hint,
3382                         gpointer      marshal_data)
3383 {
3384   AccelClosure *aclosure = (AccelClosure*) closure;
3385   gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3386
3387   if (can_activate)
3388     g_signal_emit (closure->data, aclosure->signal_id, 0);
3389
3390   /* whether accelerator was handled */
3391   g_value_set_boolean (return_value, can_activate);
3392 }
3393
3394 static void
3395 closures_destroy (gpointer data)
3396 {
3397   GSList *slist, *closures = data;
3398
3399   for (slist = closures; slist; slist = slist->next)
3400     {
3401       g_closure_invalidate (slist->data);
3402       g_closure_unref (slist->data);
3403     }
3404   g_slist_free (closures);
3405 }
3406
3407 static GClosure*
3408 widget_new_accel_closure (GtkWidget *widget,
3409                           guint      signal_id)
3410 {
3411   AccelClosure *aclosure;
3412   GClosure *closure = NULL;
3413   GSList *slist, *closures;
3414
3415   closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3416   for (slist = closures; slist; slist = slist->next)
3417     if (!gtk_accel_group_from_accel_closure (slist->data))
3418       {
3419         /* reuse this closure */
3420         closure = slist->data;
3421         break;
3422       }
3423   if (!closure)
3424     {
3425       closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3426       closures = g_slist_prepend (closures, g_closure_ref (closure));
3427       g_closure_sink (closure);
3428       g_closure_set_marshal (closure, closure_accel_activate);
3429     }
3430   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3431   
3432   aclosure = (AccelClosure*) closure;
3433   g_assert (closure->data == widget);
3434   g_assert (closure->marshal == closure_accel_activate);
3435   aclosure->signal_id = signal_id;
3436
3437   return closure;
3438 }
3439
3440 /**
3441  * gtk_widget_add_accelerator
3442  * @widget:       widget to install an accelerator on
3443  * @accel_signal: widget signal to emit on accelerator activation
3444  * @accel_group:  accel group for this widget, added to its toplevel
3445  * @accel_key:    GDK keyval of the accelerator
3446  * @accel_mods:   modifier key combination of the accelerator
3447  * @accel_flags:  flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3448  *
3449  * Installs an accelerator for this @widget in @accel_group that causes
3450  * @accel_signal to be emitted if the accelerator is activated.
3451  * The @accel_group needs to be added to the widget's toplevel via
3452  * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3453  * Accelerators added through this function are not user changeable during
3454  * runtime. If you want to support accelerators that can be changed by the
3455  * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3456  * gtk_menu_item_set_accel_path() instead.
3457  */
3458 void
3459 gtk_widget_add_accelerator (GtkWidget      *widget,
3460                             const gchar    *accel_signal,
3461                             GtkAccelGroup  *accel_group,
3462                             guint           accel_key,
3463                             GdkModifierType accel_mods,
3464                             GtkAccelFlags   accel_flags)
3465 {
3466   GClosure *closure;
3467   GSignalQuery query;
3468
3469   g_return_if_fail (GTK_IS_WIDGET (widget));
3470   g_return_if_fail (accel_signal != NULL);
3471   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3472
3473   g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3474   if (!query.signal_id ||
3475       !(query.signal_flags & G_SIGNAL_ACTION) ||
3476       query.return_type != G_TYPE_NONE ||
3477       query.n_params)
3478     {
3479       /* hmm, should be elaborate enough */
3480       g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3481                  G_OBJECT_TYPE_NAME (widget), accel_signal);
3482       return;
3483     }
3484
3485   closure = widget_new_accel_closure (widget, query.signal_id);
3486
3487   g_object_ref (widget);
3488
3489   /* install the accelerator. since we don't map this onto an accel_path,
3490    * the accelerator will automatically be locked.
3491    */
3492   gtk_accel_group_connect (accel_group,
3493                            accel_key,
3494                            accel_mods,
3495                            accel_flags | GTK_ACCEL_LOCKED,
3496                            closure);
3497
3498   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3499
3500   g_object_unref (widget);
3501 }
3502
3503 /**
3504  * gtk_widget_remove_accelerator:
3505  * @widget:       widget to install an accelerator on
3506  * @accel_group:  accel group for this widget
3507  * @accel_key:    GDK keyval of the accelerator
3508  * @accel_mods:   modifier key combination of the accelerator
3509  * @returns:      whether an accelerator was installed and could be removed
3510  *
3511  * Removes an accelerator from @widget, previously installed with
3512  * gtk_widget_add_accelerator().
3513  */
3514 gboolean
3515 gtk_widget_remove_accelerator (GtkWidget      *widget,
3516                                GtkAccelGroup  *accel_group,
3517                                guint           accel_key,
3518                                GdkModifierType accel_mods)
3519 {
3520   GtkAccelGroupEntry *ag_entry;
3521   GList *slist, *clist;
3522   guint n;
3523   
3524   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3525   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3526
3527   ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3528   clist = gtk_widget_list_accel_closures (widget);
3529   for (slist = clist; slist; slist = slist->next)
3530     {
3531       guint i;
3532
3533       for (i = 0; i < n; i++)
3534         if (slist->data == (gpointer) ag_entry[i].closure)
3535           {
3536             gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3537
3538             g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3539
3540             g_list_free (clist);
3541
3542             return is_removed;
3543           }
3544     }
3545   g_list_free (clist);
3546
3547   g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3548              accel_key, accel_mods, accel_group,
3549              G_OBJECT_TYPE_NAME (widget), widget);
3550
3551   return FALSE;
3552 }
3553
3554 /**
3555  * gtk_widget_list_accel_closures
3556  * @widget:  widget to list accelerator closures for
3557  * @returns: a newly allocated #GList of closures
3558  *
3559  * Lists the closures used by @widget for accelerator group connections
3560  * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3561  * The closures can be used to monitor accelerator changes on @widget,
3562  * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a 
3563  * closure which can be found out with gtk_accel_group_from_accel_closure().
3564  */
3565 GList*
3566 gtk_widget_list_accel_closures (GtkWidget *widget)
3567 {
3568   GSList *slist;
3569   GList *clist = NULL;
3570
3571   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3572
3573   for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3574     if (gtk_accel_group_from_accel_closure (slist->data))
3575       clist = g_list_prepend (clist, slist->data);
3576   return clist;
3577 }
3578
3579 typedef struct {
3580   GQuark         path_quark;
3581   GtkAccelGroup *accel_group;
3582   GClosure      *closure;
3583 } AccelPath;
3584
3585 static void
3586 destroy_accel_path (gpointer data)
3587 {
3588   AccelPath *apath = data;
3589
3590   gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3591
3592   /* closures_destroy takes care of unrefing the closure */
3593   g_object_unref (apath->accel_group);
3594   
3595   g_slice_free (AccelPath, apath);
3596 }
3597
3598
3599 /**
3600  * gtk_widget_set_accel_path:
3601  * @widget: a #GtkWidget
3602  * @accel_path: path used to look up the accelerator
3603  * @accel_group: a #GtkAccelGroup.
3604  * 
3605  * Given an accelerator group, @accel_group, and an accelerator path,
3606  * @accel_path, sets up an accelerator in @accel_group so whenever the
3607  * key binding that is defined for @accel_path is pressed, @widget
3608  * will be activated.  This removes any accelerators (for any
3609  * accelerator group) installed by previous calls to
3610  * gtk_widget_set_accel_path(). Associating accelerators with
3611  * paths allows them to be modified by the user and the modifications
3612  * to be saved for future use. (See gtk_accel_map_save().)
3613  *
3614  * This function is a low level function that would most likely
3615  * be used by a menu creation system like #GtkItemFactory. If you
3616  * use #GtkItemFactory, setting up accelerator paths will be done
3617  * automatically.
3618  *
3619  * Even when you you aren't using #GtkItemFactory, if you only want to
3620  * set up accelerators on menu items gtk_menu_item_set_accel_path()
3621  * provides a somewhat more convenient interface.
3622  **/
3623 void
3624 gtk_widget_set_accel_path (GtkWidget     *widget,
3625                            const gchar   *accel_path,
3626                            GtkAccelGroup *accel_group)
3627 {
3628   AccelPath *apath;
3629
3630   g_return_if_fail (GTK_IS_WIDGET (widget));
3631   g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3632
3633   if (accel_path)
3634     {
3635       g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3636       g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3637
3638       gtk_accel_map_add_entry (accel_path, 0, 0);
3639       apath = g_slice_new (AccelPath);
3640       apath->accel_group = g_object_ref (accel_group);
3641       apath->path_quark = g_quark_from_string (accel_path);
3642       apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
3643     }
3644   else
3645     apath = NULL;
3646
3647   /* also removes possible old settings */
3648   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3649
3650   if (apath)
3651     gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3652
3653   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3654 }
3655
3656 const gchar*
3657 _gtk_widget_get_accel_path (GtkWidget *widget,
3658                             gboolean  *locked)
3659 {
3660   AccelPath *apath;
3661
3662   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3663
3664   apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3665   if (locked)
3666     *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3667   return apath ? g_quark_to_string (apath->path_quark) : NULL;
3668 }
3669
3670 gboolean
3671 gtk_widget_mnemonic_activate (GtkWidget *widget,
3672                               gboolean   group_cycling)
3673 {
3674   gboolean handled;
3675   
3676   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3677
3678   group_cycling = group_cycling != FALSE;
3679   if (!GTK_WIDGET_IS_SENSITIVE (widget))
3680     handled = TRUE;
3681   else
3682     g_signal_emit (widget,
3683                    widget_signals[MNEMONIC_ACTIVATE],
3684                    0,
3685                    group_cycling,
3686                    &handled);
3687   return handled;
3688 }
3689
3690 static gboolean
3691 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3692                                    gboolean   group_cycling)
3693 {
3694   if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3695     gtk_widget_activate (widget);
3696   else if (GTK_WIDGET_CAN_FOCUS (widget))
3697     gtk_widget_grab_focus (widget);
3698   else
3699     {
3700       g_warning ("widget `%s' isn't suitable for mnemonic activation",
3701                  G_OBJECT_TYPE_NAME (widget));
3702       gtk_widget_error_bell (widget);
3703     }
3704   return TRUE;
3705 }
3706
3707 static gboolean
3708 gtk_widget_real_key_press_event (GtkWidget         *widget,
3709                                  GdkEventKey       *event)
3710 {
3711   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3712 }
3713
3714 static gboolean
3715 gtk_widget_real_key_release_event (GtkWidget         *widget,
3716                                    GdkEventKey       *event)
3717 {
3718   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3719 }
3720
3721 static gboolean
3722 gtk_widget_real_focus_in_event (GtkWidget     *widget,
3723                                 GdkEventFocus *event)
3724 {
3725   gtk_widget_queue_shallow_draw (widget);
3726
3727   return FALSE;
3728 }
3729
3730 static gboolean
3731 gtk_widget_real_focus_out_event (GtkWidget     *widget,
3732                                  GdkEventFocus *event)
3733 {
3734   gtk_widget_queue_shallow_draw (widget);
3735
3736   return FALSE;
3737 }
3738
3739 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3740      (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3741
3742 /**
3743  * gtk_widget_event:
3744  * @widget: a #GtkWidget
3745  * @event: a #GdkEvent
3746  * 
3747  * Rarely-used function. This function is used to emit
3748  * the event signals on a widget (those signals should never
3749  * be emitted without using this function to do so).
3750  * If you want to synthesize an event though, don't use this function;
3751  * instead, use gtk_main_do_event() so the event will behave as if
3752  * it were in the event queue. Don't synthesize expose events; instead,
3753  * use gdk_window_invalidate_rect() to invalidate a region of the
3754  * window.
3755  * 
3756  * Return value: return from the event signal emission (%TRUE if the event was handled)
3757  **/
3758 gboolean
3759 gtk_widget_event (GtkWidget *widget,
3760                   GdkEvent  *event)
3761 {
3762   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3763   g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3764
3765   if (event->type == GDK_EXPOSE)
3766     {
3767       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3768                  "the same effect, call gdk_window_invalidate_rect/region(), "
3769                  "followed by gdk_window_process_updates().");
3770       return TRUE;
3771     }
3772   
3773   return gtk_widget_event_internal (widget, event);
3774 }
3775
3776
3777 /**
3778  * gtk_widget_send_expose:
3779  * @widget: a #GtkWidget
3780  * @event: a expose #GdkEvent
3781  * 
3782  * Very rarely-used function. This function is used to emit
3783  * an expose event signals on a widget. This function is not
3784  * normally used directly. The only time it is used is when
3785  * propagating an expose event to a child %NO_WINDOW widget, and
3786  * that is normally done using gtk_container_propagate_expose().
3787  *
3788  * If you want to force an area of a window to be redrawn, 
3789  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3790  * To cause the redraw to be done immediately, follow that call
3791  * with a call to gdk_window_process_updates().
3792  * 
3793  * Return value: return from the event signal emission (%TRUE if the event was handled)
3794  **/
3795 gint
3796 gtk_widget_send_expose (GtkWidget *widget,
3797                         GdkEvent  *event)
3798 {
3799   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3800   g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3801   g_return_val_if_fail (event != NULL, TRUE);
3802   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3803
3804   return gtk_widget_event_internal (widget, event);
3805 }
3806
3807 static gboolean
3808 event_window_is_still_viewable (GdkEvent *event)
3809 {
3810   /* Some programs, such as gnome-theme-manager, fake widgets
3811    * into exposing onto a pixmap by sending expose events with
3812    * event->window pointing to a pixmap
3813    */
3814   if (GDK_IS_PIXMAP (event->any.window))
3815     return event->type == GDK_EXPOSE;
3816   
3817   /* Check that we think the event's window is viewable before
3818    * delivering the event, to prevent suprises. We do this here
3819    * at the last moment, since the event may have been queued
3820    * up behind other events, held over a recursive main loop, etc.
3821    */
3822   switch (event->type)
3823     {
3824     case GDK_EXPOSE:
3825     case GDK_MOTION_NOTIFY:
3826     case GDK_BUTTON_PRESS:
3827     case GDK_2BUTTON_PRESS:
3828     case GDK_3BUTTON_PRESS:
3829     case GDK_KEY_PRESS:
3830     case GDK_ENTER_NOTIFY:
3831     case GDK_PROXIMITY_IN:
3832     case GDK_SCROLL:
3833       return event->any.window && gdk_window_is_viewable (event->any.window);
3834
3835 #if 0
3836     /* The following events are the second half of paired events;
3837      * we always deliver them to deal with widgets that clean up
3838      * on the second half.
3839      */
3840     case GDK_BUTTON_RELEASE:
3841     case GDK_KEY_RELEASE:
3842     case GDK_LEAVE_NOTIFY:
3843     case GDK_PROXIMITY_OUT:
3844 #endif      
3845       
3846     default:
3847       /* Remaining events would make sense on an not-viewable window,
3848        * or don't have an associated window.
3849        */
3850       return TRUE;
3851     }
3852 }
3853
3854 static gint
3855 gtk_widget_event_internal (GtkWidget *widget,
3856                            GdkEvent  *event)
3857 {
3858   gboolean return_val = FALSE;
3859
3860   /* We check only once for is-still-visible; if someone
3861    * hides the window in on of the signals on the widget,
3862    * they are responsible for returning TRUE to terminate
3863    * handling.
3864    */
3865   if (!event_window_is_still_viewable (event))
3866     return TRUE;
3867
3868   g_object_ref (widget);
3869
3870   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3871   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3872   if (!return_val)
3873     {
3874       gint signal_num;
3875
3876       switch (event->type)
3877         {
3878         case GDK_NOTHING:
3879           signal_num = -1;
3880           break;
3881         case GDK_BUTTON_PRESS:
3882         case GDK_2BUTTON_PRESS:
3883         case GDK_3BUTTON_PRESS:
3884           signal_num = BUTTON_PRESS_EVENT;
3885           break;
3886         case GDK_SCROLL:
3887           signal_num = SCROLL_EVENT;
3888           break;
3889         case GDK_BUTTON_RELEASE:
3890           signal_num = BUTTON_RELEASE_EVENT;
3891           break;
3892         case GDK_MOTION_NOTIFY:
3893           signal_num = MOTION_NOTIFY_EVENT;
3894           break;
3895         case GDK_DELETE:
3896           signal_num = DELETE_EVENT;
3897           break;
3898         case GDK_DESTROY:
3899           signal_num = DESTROY_EVENT;
3900           break;
3901         case GDK_KEY_PRESS:
3902           signal_num = KEY_PRESS_EVENT;
3903           break;
3904         case GDK_KEY_RELEASE:
3905           signal_num = KEY_RELEASE_EVENT;
3906           break;
3907         case GDK_ENTER_NOTIFY:
3908           signal_num = ENTER_NOTIFY_EVENT;
3909           break;
3910         case GDK_LEAVE_NOTIFY:
3911           signal_num = LEAVE_NOTIFY_EVENT;
3912           break;
3913         case GDK_FOCUS_CHANGE:
3914           signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3915           break;
3916         case GDK_CONFIGURE:
3917           signal_num = CONFIGURE_EVENT;
3918           break;
3919         case GDK_MAP:
3920           signal_num = MAP_EVENT;
3921           break;
3922         case GDK_UNMAP:
3923           signal_num = UNMAP_EVENT;
3924           break;
3925         case GDK_WINDOW_STATE:
3926           signal_num = WINDOW_STATE_EVENT;
3927           break;
3928         case GDK_PROPERTY_NOTIFY:
3929           signal_num = PROPERTY_NOTIFY_EVENT;
3930           break;
3931         case GDK_SELECTION_CLEAR:
3932           signal_num = SELECTION_CLEAR_EVENT;
3933           break;
3934         case GDK_SELECTION_REQUEST:
3935           signal_num = SELECTION_REQUEST_EVENT;
3936           break;
3937         case GDK_SELECTION_NOTIFY:
3938           signal_num = SELECTION_NOTIFY_EVENT;
3939           break;
3940         case GDK_PROXIMITY_IN:
3941           signal_num = PROXIMITY_IN_EVENT;
3942           break;
3943         case GDK_PROXIMITY_OUT:
3944           signal_num = PROXIMITY_OUT_EVENT;
3945           break;
3946         case GDK_NO_EXPOSE:
3947           signal_num = NO_EXPOSE_EVENT;
3948           break;
3949         case GDK_CLIENT_EVENT:
3950           signal_num = CLIENT_EVENT;
3951           break;
3952         case GDK_EXPOSE:
3953           signal_num = EXPOSE_EVENT;
3954           break;
3955         case GDK_VISIBILITY_NOTIFY:
3956           signal_num = VISIBILITY_NOTIFY_EVENT;
3957           break;
3958         case GDK_GRAB_BROKEN:
3959           signal_num = GRAB_BROKEN;
3960           break;
3961         default:
3962           g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3963           signal_num = -1;
3964           break;
3965         }
3966       if (signal_num != -1)
3967         g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3968     }
3969   if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3970     g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3971   else
3972     return_val = TRUE;
3973
3974   g_object_unref (widget);
3975
3976   return return_val;
3977 }
3978
3979 /**
3980  * gtk_widget_activate:
3981  * @widget: a #GtkWidget that's activatable
3982  * 
3983  * For widgets that can be "activated" (buttons, menu items, etc.)
3984  * this function activates them. Activation is what happens when you
3985  * press Enter on a widget during key navigation. If @widget isn't 
3986  * activatable, the function returns %FALSE.
3987  * 
3988  * Return value: %TRUE if the widget was activatable
3989  **/
3990 gboolean
3991 gtk_widget_activate (GtkWidget *widget)
3992 {
3993   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3994   
3995   if (WIDGET_CLASS (widget)->activate_signal)
3996     {
3997       /* FIXME: we should eventually check the signals signature here */
3998       g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3999
4000       return TRUE;
4001     }
4002   else
4003     return FALSE;
4004 }
4005
4006 /**
4007  * gtk_widget_set_scroll_adjustments:
4008  * @widget: a #GtkWidget
4009  * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4010  * @vadjustment: an adjustment for vertical scrolling, or %NULL
4011  *
4012  * For widgets that support scrolling, sets the scroll adjustments and
4013  * returns %TRUE.  For widgets that don't support scrolling, does
4014  * nothing and returns %FALSE. Widgets that don't support scrolling
4015  * can be scrolled by placing them in a #GtkViewport, which does
4016  * support scrolling.
4017  * 
4018  * Return value: %TRUE if the widget supports scrolling
4019  **/
4020 gboolean
4021 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
4022                                    GtkAdjustment *hadjustment,
4023                                    GtkAdjustment *vadjustment)
4024 {
4025   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4026   if (hadjustment)
4027     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4028   if (vadjustment)
4029     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4030
4031   if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
4032     {
4033       /* FIXME: we should eventually check the signals signature here */
4034       g_signal_emit (widget,
4035                      WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
4036                      hadjustment, vadjustment);
4037       return TRUE;
4038     }
4039   else
4040     return FALSE;
4041 }
4042
4043 static void
4044 gtk_widget_reparent_subwindows (GtkWidget *widget,
4045                                 GdkWindow *new_window)
4046 {
4047   if (GTK_WIDGET_NO_WINDOW (widget))
4048     {
4049       GList *children = gdk_window_get_children (widget->window);
4050       GList *tmp_list;
4051
4052       for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4053         {
4054           GtkWidget *child;
4055           GdkWindow *window = tmp_list->data;
4056
4057           gdk_window_get_user_data (window, (void **)&child);
4058           while (child && child != widget)
4059             child = child->parent;
4060
4061           if (child)
4062             gdk_window_reparent (window, new_window, 0, 0);
4063         }
4064
4065       g_list_free (children);
4066     }
4067   else
4068    {
4069      GdkWindow *parent;
4070      GList *tmp_list, *children;
4071
4072      parent = gdk_window_get_parent (widget->window);
4073
4074      if (parent == NULL)
4075        gdk_window_reparent (widget->window, new_window, 0, 0);
4076      else
4077        {
4078          children = gdk_window_get_children (parent);
4079          
4080          for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4081            {
4082              GtkWidget *child;
4083              GdkWindow *window = tmp_list->data;
4084              
4085              gdk_window_get_user_data (window, (void **)&child);
4086              if (child == widget)
4087                gdk_window_reparent (window, new_window, 0, 0);
4088            }
4089          
4090          g_list_free (children);
4091        }
4092    }
4093 }
4094
4095 static void
4096 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4097                                  gpointer   client_data)
4098 {
4099   g_assert (client_data != NULL);
4100   
4101   if (GTK_WIDGET_NO_WINDOW (widget))
4102     {
4103       if (widget->window)
4104         g_object_unref (widget->window);
4105       widget->window = (GdkWindow*) client_data;
4106       if (widget->window)
4107         g_object_ref (widget->window);
4108
4109       if (GTK_IS_CONTAINER (widget))
4110         gtk_container_forall (GTK_CONTAINER (widget),
4111                               gtk_widget_reparent_fixup_child,
4112                               client_data);
4113     }
4114 }
4115
4116 /**
4117  * gtk_widget_reparent:
4118  * @widget: a #GtkWidget
4119  * @new_parent: a #GtkContainer to move the widget into
4120  *
4121  * Moves a widget from one #GtkContainer to another, handling reference
4122  * count issues to avoid destroying the widget.
4123  * 
4124  **/
4125 void
4126 gtk_widget_reparent (GtkWidget *widget,
4127                      GtkWidget *new_parent)
4128 {
4129   g_return_if_fail (GTK_IS_WIDGET (widget));
4130   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4131   g_return_if_fail (widget->parent != NULL);
4132   
4133   if (widget->parent != new_parent)
4134     {
4135       /* First try to see if we can get away without unrealizing
4136        * the widget as we reparent it. if so we set a flag so
4137        * that gtk_widget_unparent doesn't unrealize widget
4138        */
4139       if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4140         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4141       
4142       g_object_ref (widget);
4143       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4144       gtk_container_add (GTK_CONTAINER (new_parent), widget);
4145       g_object_unref (widget);
4146       
4147       if (GTK_WIDGET_IN_REPARENT (widget))
4148         {
4149           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4150
4151           gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4152           gtk_widget_reparent_fixup_child (widget,
4153                                            gtk_widget_get_parent_window (widget));
4154         }
4155
4156       g_object_notify (G_OBJECT (widget), "parent");
4157     }
4158 }
4159
4160 /**
4161  * gtk_widget_intersect:
4162  * @widget: a #GtkWidget
4163  * @area: a rectangle
4164  * @intersection: rectangle to store intersection of @widget and @area
4165  * 
4166  * Computes the intersection of a @widget's area and @area, storing
4167  * the intersection in @intersection, and returns %TRUE if there was
4168  * an intersection.  @intersection may be %NULL if you're only
4169  * interested in whether there was an intersection.
4170  * 
4171  * Return value: %TRUE if there was an intersection
4172  **/
4173 gboolean
4174 gtk_widget_intersect (GtkWidget    *widget,
4175                       GdkRectangle *area,
4176                       GdkRectangle *intersection)
4177 {
4178   GdkRectangle *dest;
4179   GdkRectangle tmp;
4180   gint return_val;
4181   
4182   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4183   g_return_val_if_fail (area != NULL, FALSE);
4184   
4185   if (intersection)
4186     dest = intersection;
4187   else
4188     dest = &tmp;
4189   
4190   return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4191   
4192   if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4193     {
4194       intersection->x -= widget->allocation.x;
4195       intersection->y -= widget->allocation.y;
4196     }
4197   
4198   return return_val;
4199 }
4200
4201 /**
4202  * gtk_widget_region_intersect:
4203  * @widget: a #GtkWidget
4204  * @region: a #GdkRegion, in the same coordinate system as 
4205  *          @widget->allocation. That is, relative to @widget->window
4206  *          for %NO_WINDOW widgets; relative to the parent window
4207  *          of @widget->window for widgets with their own window.
4208  * @returns: A newly allocated region holding the intersection of @widget
4209  *           and @region. The coordinates of the return value are
4210  *           relative to @widget->window for %NO_WINDOW widgets, and
4211  *           relative to the parent window of @widget->window for
4212  *           widgets with their own window.
4213  * 
4214  * Computes the intersection of a @widget's area and @region, returning
4215  * the intersection. The result may be empty, use gdk_region_empty() to
4216  * check.
4217  **/
4218 GdkRegion *
4219 gtk_widget_region_intersect (GtkWidget *widget,
4220                              GdkRegion *region)
4221 {
4222   GdkRectangle rect;
4223   GdkRegion *dest;
4224   
4225   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4226   g_return_val_if_fail (region != NULL, NULL);
4227
4228   gtk_widget_get_draw_rectangle (widget, &rect);
4229   
4230   dest = gdk_region_rectangle (&rect);
4231  
4232   gdk_region_intersect (dest, region);
4233
4234   return dest;
4235 }
4236
4237 /**
4238  * _gtk_widget_grab_notify:
4239  * @widget: a #GtkWidget
4240  * @was_grabbed: whether a grab is now in effect
4241  * 
4242  * Emits the signal "grab_notify" on @widget.
4243  * 
4244  * Since: 2.6
4245  **/
4246 void
4247 _gtk_widget_grab_notify (GtkWidget *widget,
4248                          gboolean   was_grabbed)
4249 {
4250   g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
4251 }
4252
4253 /**
4254  * gtk_widget_grab_focus:
4255  * @widget: a #GtkWidget
4256  * 
4257  * Causes @widget to have the keyboard focus for the #GtkWindow it's
4258  * inside. @widget must be a focusable widget, such as a #GtkEntry;
4259  * something like #GtkFrame won't work. (More precisely, it must have the
4260  * %GTK_CAN_FOCUS flag set.)
4261  * 
4262  **/
4263 void
4264 gtk_widget_grab_focus (GtkWidget *widget)
4265 {
4266   g_return_if_fail (GTK_IS_WIDGET (widget));
4267
4268   if (!GTK_WIDGET_IS_SENSITIVE (widget))
4269     return;
4270   
4271   g_object_ref (widget);
4272   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
4273   g_object_notify (G_OBJECT (widget), "has-focus");
4274   g_object_unref (widget);
4275 }
4276
4277 static void
4278 reset_focus_recurse (GtkWidget *widget,
4279                      gpointer   data)
4280 {
4281   if (GTK_IS_CONTAINER (widget))
4282     {
4283       GtkContainer *container;
4284
4285       container = GTK_CONTAINER (widget);
4286       gtk_container_set_focus_child (container, NULL);
4287
4288       gtk_container_foreach (container,
4289                              reset_focus_recurse,
4290                              NULL);
4291     }
4292 }
4293
4294 static void
4295 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
4296 {
4297   if (GTK_WIDGET_CAN_FOCUS (focus_widget))
4298     {
4299       GtkWidget *toplevel;
4300       GtkWidget *widget;
4301       
4302       /* clear the current focus setting, break if the current widget
4303        * is the focus widget's parent, since containers above that will
4304        * be set by the next loop.
4305        */
4306       toplevel = gtk_widget_get_toplevel (focus_widget);
4307       if (GTK_WIDGET_TOPLEVEL (toplevel))
4308         {
4309           widget = GTK_WINDOW (toplevel)->focus_widget;
4310           
4311           if (widget == focus_widget)
4312             {
4313               /* We call _gtk_window_internal_set_focus() here so that the
4314                * toplevel window can request the focus if necessary.
4315                * This is needed when the toplevel is a GtkPlug
4316                */
4317               if (!GTK_WIDGET_HAS_FOCUS (widget))
4318                 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
4319
4320               return;
4321             }
4322           
4323           if (widget)
4324             {
4325               while (widget->parent && widget->parent != focus_widget->parent)
4326                 {
4327                   widget = widget->parent;
4328                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
4329                 }
4330             }
4331         }
4332       else if (toplevel != focus_widget)
4333         {
4334           /* gtk_widget_grab_focus() operates on a tree without window...
4335            * actually, this is very questionable behaviour.
4336            */
4337           
4338           gtk_container_foreach (GTK_CONTAINER (toplevel),
4339                                  reset_focus_recurse,
4340                                  NULL);
4341         }
4342
4343       /* now propagate the new focus up the widget tree and finally
4344        * set it on the window
4345        */
4346       widget = focus_widget;
4347       while (widget->parent)
4348         {
4349           gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4350           widget = widget->parent;
4351         }
4352       if (GTK_IS_WINDOW (widget))
4353         _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4354     }
4355 }
4356
4357 static gboolean
4358 gtk_widget_real_show_help (GtkWidget        *widget,
4359                            GtkWidgetHelpType help_type)
4360 {
4361   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4362     {
4363       _gtk_tooltips_toggle_keyboard_mode (widget);
4364       return TRUE;
4365     }
4366   else
4367     return FALSE;
4368 }
4369
4370 static gboolean
4371 gtk_widget_real_focus (GtkWidget         *widget,
4372                        GtkDirectionType   direction)
4373 {
4374   if (!GTK_WIDGET_CAN_FOCUS (widget))
4375     return FALSE;
4376   
4377   if (!gtk_widget_is_focus (widget))
4378     {
4379       gtk_widget_grab_focus (widget);
4380       return TRUE;
4381     }
4382   else
4383     return FALSE;
4384 }
4385
4386 static gboolean
4387 gtk_widget_real_keynav_failed (GtkWidget        *widget,
4388                                GtkDirectionType  direction)
4389 {
4390   gboolean cursor_only;
4391
4392   switch (direction)
4393     {
4394     case GTK_DIR_TAB_FORWARD:
4395     case GTK_DIR_TAB_BACKWARD:
4396       return FALSE;
4397
4398     case GTK_DIR_UP:
4399     case GTK_DIR_DOWN:
4400     case GTK_DIR_LEFT:
4401     case GTK_DIR_RIGHT:
4402       g_object_get (gtk_widget_get_settings (widget),
4403                     "gtk-keynav-cursor-only", &cursor_only,
4404                     NULL);
4405       if (cursor_only)
4406         return FALSE;
4407       break;
4408     }
4409
4410   gtk_widget_error_bell (widget);
4411
4412   return TRUE;
4413 }
4414
4415 /**
4416  * gtk_widget_is_focus:
4417  * @widget: a #GtkWidget
4418  * 
4419  * Determines if the widget is the focus widget within its
4420  * toplevel. (This does not mean that the %HAS_FOCUS flag is
4421  * necessarily set; %HAS_FOCUS will only be set if the
4422  * toplevel widget additionally has the global input focus.)
4423  * 
4424  * Return value: %TRUE if the widget is the focus widget.
4425  **/
4426 gboolean
4427 gtk_widget_is_focus (GtkWidget *widget)
4428 {
4429   GtkWidget *toplevel;
4430
4431   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4432
4433   toplevel = gtk_widget_get_toplevel (widget);
4434   
4435   if (GTK_IS_WINDOW (toplevel))
4436     return widget == GTK_WINDOW (toplevel)->focus_widget;
4437   else
4438     return FALSE;
4439 }
4440
4441 /**
4442  * gtk_widget_grab_default:
4443  * @widget: a #GtkWidget
4444  *
4445  * Causes @widget to become the default widget. @widget must have the
4446  * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4447  * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4448  * GTK_CAN_DEFAULT)</literal>.  The default widget is activated when the user
4449  * presses Enter in a window.  Default widgets must be activatable,
4450  * that is, gtk_widget_activate() should affect them.
4451  * 
4452  **/
4453 void
4454 gtk_widget_grab_default (GtkWidget *widget)
4455 {
4456   GtkWidget *window;
4457   
4458   g_return_if_fail (GTK_IS_WIDGET (widget));
4459   g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4460   
4461   window = gtk_widget_get_toplevel (widget);
4462   
4463   if (window && GTK_WIDGET_TOPLEVEL (window))
4464     gtk_window_set_default (GTK_WINDOW (window), widget);
4465   else
4466     g_warning (G_STRLOC ": widget not within a GtkWindow");
4467 }
4468
4469 /**
4470  * gtk_widget_set_name:
4471  * @widget: a #GtkWidget
4472  * @name: name for the widget
4473  *
4474  * Widgets can be named, which allows you to refer to them from a
4475  * gtkrc file. You can apply a style to widgets with a particular name
4476  * in the gtkrc file. See the documentation for gtkrc files (on the
4477  * same page as the docs for #GtkRcStyle).
4478  * 
4479  * Note that widget names are separated by periods in paths (see 
4480  * gtk_widget_path()), so names with embedded periods may cause confusion.
4481  **/
4482 void
4483 gtk_widget_set_name (GtkWidget   *widget,
4484                      const gchar *name)
4485 {
4486   gchar *new_name;
4487   
4488   g_return_if_fail (GTK_IS_WIDGET (widget));
4489
4490   new_name = g_strdup (name);
4491   g_free (widget->name);
4492   widget->name = new_name;
4493
4494   if (GTK_WIDGET_RC_STYLE (widget))
4495     gtk_widget_reset_rc_style (widget);
4496
4497   g_object_notify (G_OBJECT (widget), "name");
4498 }
4499
4500 /**
4501  * gtk_widget_get_name:
4502  * @widget: a #GtkWidget
4503  * 
4504  * Retrieves the name of a widget. See gtk_widget_set_name() for the
4505  * significance of widget names.
4506  * 
4507  * Return value: name of the widget. This string is owned by GTK+ and
4508  * should not be modified or freed
4509  **/
4510 G_CONST_RETURN gchar*
4511 gtk_widget_get_name (GtkWidget *widget)
4512 {
4513   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4514   
4515   if (widget->name)
4516     return widget->name;
4517   return g_type_name (GTK_WIDGET_TYPE (widget));
4518 }
4519
4520 /**
4521  * gtk_widget_set_state:
4522  * @widget: a #GtkWidget
4523  * @state: new state for @widget
4524  *
4525  * This function is for use in widget implementations. Sets the state
4526  * of a widget (insensitive, prelighted, etc.) Usually you should set
4527  * the state using wrapper functions such as gtk_widget_set_sensitive().
4528  * 
4529  **/
4530 void
4531 gtk_widget_set_state (GtkWidget           *widget,
4532                       GtkStateType         state)
4533 {
4534   gboolean touchscreen;
4535
4536   g_return_if_fail (GTK_IS_WIDGET (widget));
4537
4538   if (state == GTK_WIDGET_STATE (widget))
4539     return;
4540
4541   g_object_get (gtk_widget_get_settings (widget),
4542                 "gtk-touchscreen-mode", &touchscreen,
4543                 NULL);
4544   
4545   if (touchscreen && state == GTK_STATE_PRELIGHT)
4546     state = GTK_STATE_NORMAL;
4547
4548   if (state == GTK_STATE_INSENSITIVE)
4549     gtk_widget_set_sensitive (widget, FALSE);
4550   else
4551     {
4552       GtkStateData data;
4553
4554       data.state = state;
4555       data.state_restoration = FALSE;
4556       data.use_forall = FALSE;
4557       if (widget->parent)
4558         data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4559       else
4560         data.parent_sensitive = TRUE;
4561
4562       gtk_widget_propagate_state (widget, &data);
4563   
4564       if (GTK_WIDGET_DRAWABLE (widget))
4565         gtk_widget_queue_draw (widget);
4566     }
4567 }
4568
4569
4570 /**
4571  * gtk_widget_set_app_paintable:
4572  * @widget: a #GtkWidget
4573  * @app_paintable: %TRUE if the application will paint on the widget
4574  *
4575  * Sets whether the application intends to draw on the widget in
4576  * an ::expose-event handler. 
4577  *
4578  * This is a hint to the widget and does not affect the behavior of 
4579  * the GTK+ core; many widgets ignore this flag entirely. For widgets 
4580  * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow, 
4581  * the effect is to suppress default themed drawing of the widget's 
4582  * background. (Children of the widget will still be drawn.) The application 
4583  * is then entirely responsible for drawing the widget background.
4584  *
4585  * Note that the background is still drawn when the widget is mapped.
4586  * If this is not suitable (e.g. because you want to make a transparent
4587  * window using an RGBA visual), you can work around this by doing:
4588  * <informalexample><programlisting>
4589  *  gtk_widget_realize (window);
4590  *  gdk_window_set_back_pixmap (window->window, NULL, FALSE);
4591  *  gtk_widget_show (window);
4592  * </programlisting></informalexample> 
4593  **/
4594 void
4595 gtk_widget_set_app_paintable (GtkWidget *widget,
4596                               gboolean   app_paintable)
4597 {
4598   g_return_if_fail (GTK_IS_WIDGET (widget));
4599
4600   app_paintable = (app_paintable != FALSE);
4601
4602   if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4603     {
4604       if (app_paintable)
4605         GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4606       else
4607         GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4608
4609       if (GTK_WIDGET_DRAWABLE (widget))
4610         gtk_widget_queue_draw (widget);
4611
4612       g_object_notify (G_OBJECT (widget), "app-paintable");
4613     }
4614 }
4615
4616 /**
4617  * gtk_widget_set_double_buffered:
4618  * @widget: a #GtkWidget
4619  * @double_buffered: %TRUE to double-buffer a widget
4620  *
4621  * Widgets are double buffered by default; you can use this function
4622  * to turn off the buffering. "Double buffered" simply means that
4623  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4624  * automatically around expose events sent to the
4625  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4626  * window to an offscreen buffer, and gdk_window_end_paint() draws the
4627  * buffer to the screen. The result is that users see the window
4628  * update in one smooth step, and don't see individual graphics
4629  * primitives being rendered.
4630  *
4631  * In very simple terms, double buffered widgets don't flicker,
4632  * so you would only use this function to turn off double buffering
4633  * if you had special needs and really knew what you were doing.
4634  * 
4635  * Note: if you turn off double-buffering, you have to handle
4636  * expose events, since even the clearing to the background color or 
4637  * pixmap will not happen automatically (as it is done in 
4638  * gdk_window_begin_paint()).
4639  * 
4640  **/
4641 void
4642 gtk_widget_set_double_buffered (GtkWidget *widget,
4643                                 gboolean   double_buffered)
4644 {
4645   g_return_if_fail (GTK_IS_WIDGET (widget));
4646
4647   if (double_buffered)
4648     GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4649   else
4650     GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4651 }
4652
4653 /**
4654  * gtk_widget_set_redraw_on_allocate:
4655  * @widget: a #GtkWidget
4656  * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4657  *   when it is allocated to a new size. Otherwise, only the
4658  *   new portion of the widget will be redrawn.
4659  *
4660  * Sets whether the entire widget is queued for drawing when its size 
4661  * allocation changes. By default, this setting is %TRUE and
4662  * the entire widget is redrawn on every size change. If your widget
4663  * leaves the upper left unchanged when made bigger, turning this
4664  * setting on will improve performance.
4665
4666  * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4667  * off all allocation on resizing: the widget will not even redraw if
4668  * its position changes; this is to allow containers that don't draw
4669  * anything to avoid excess invalidations. If you set this flag on a
4670  * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window, 
4671  * you are responsible for invalidating both the old and new allocation 
4672  * of the widget when the widget is moved and responsible for invalidating
4673  * regions newly when the widget increases size.
4674  **/
4675 void
4676 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4677                                    gboolean   redraw_on_allocate)
4678 {
4679   g_return_if_fail (GTK_IS_WIDGET (widget));
4680
4681   if (redraw_on_allocate)
4682     GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4683   else
4684     GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4685 }
4686
4687 /**
4688  * gtk_widget_set_sensitive:
4689  * @widget: a #GtkWidget
4690  * @sensitive: %TRUE to make the widget sensitive
4691  *
4692  * Sets the sensitivity of a widget. A widget is sensitive if the user
4693  * can interact with it. Insensitive widgets are "grayed out" and the
4694  * user can't interact with them. Insensitive widgets are known as
4695  * "inactive", "disabled", or "ghosted" in some other toolkits.
4696  * 
4697  **/
4698 void
4699 gtk_widget_set_sensitive (GtkWidget *widget,
4700                           gboolean   sensitive)
4701 {
4702   GtkStateData data;
4703
4704   g_return_if_fail (GTK_IS_WIDGET (widget));
4705
4706   sensitive = (sensitive != FALSE);
4707
4708   if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4709     return;
4710
4711   if (sensitive)
4712     {
4713       GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4714       data.state = GTK_WIDGET_SAVED_STATE (widget);
4715     }
4716   else
4717     {
4718       GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4719       data.state = GTK_WIDGET_STATE (widget);
4720     }
4721   data.state_restoration = TRUE;
4722   data.use_forall = TRUE;
4723
4724   if (widget->parent)
4725     data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4726   else
4727     data.parent_sensitive = TRUE;
4728
4729   gtk_widget_propagate_state (widget, &data);
4730   if (GTK_WIDGET_DRAWABLE (widget))
4731     gtk_widget_queue_draw (widget);
4732
4733   g_object_notify (G_OBJECT (widget), "sensitive");
4734 }
4735
4736 /**
4737  * gtk_widget_set_parent:
4738  * @widget: a #GtkWidget
4739  * @parent: parent container
4740  *
4741  * This function is useful only when implementing subclasses of #GtkContainer.
4742  * Sets the container as the parent of @widget, and takes care of
4743  * some details such as updating the state and style of the child
4744  * to reflect its new location. The opposite function is
4745  * gtk_widget_unparent().
4746  * 
4747  **/
4748 void
4749 gtk_widget_set_parent (GtkWidget *widget,
4750                        GtkWidget *parent)
4751 {
4752   GtkStateData data;
4753   
4754   g_return_if_fail (GTK_IS_WIDGET (widget));
4755   g_return_if_fail (GTK_IS_WIDGET (parent));
4756   g_return_if_fail (widget != parent);
4757   if (widget->parent != NULL)
4758     {
4759       g_warning ("Can't set a parent on widget which has a parent\n");
4760       return;
4761     }
4762   if (GTK_WIDGET_TOPLEVEL (widget))
4763     {
4764       g_warning ("Can't set a parent on a toplevel widget\n");
4765       return;
4766     }
4767
4768   /* keep this function in sync with gtk_menu_attach_to_widget()
4769    */
4770
4771   g_object_ref_sink (widget);
4772   widget->parent = parent;
4773
4774   if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4775     data.state = GTK_WIDGET_STATE (parent);
4776   else
4777     data.state = GTK_WIDGET_STATE (widget);
4778   data.state_restoration = FALSE;
4779   data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4780   data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4781
4782   gtk_widget_propagate_state (widget, &data);
4783   
4784   gtk_widget_reset_rc_styles (widget);
4785
4786   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4787   if (GTK_WIDGET_ANCHORED (widget->parent))
4788     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4789   g_object_notify (G_OBJECT (widget), "parent");
4790
4791   /* Enforce realized/mapped invariants
4792    */
4793   if (GTK_WIDGET_REALIZED (widget->parent))
4794     gtk_widget_realize (widget);
4795
4796   if (GTK_WIDGET_VISIBLE (widget->parent) &&
4797       GTK_WIDGET_VISIBLE (widget))
4798     {
4799       if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4800           GTK_WIDGET_MAPPED (widget->parent))
4801         gtk_widget_map (widget);
4802
4803       gtk_widget_queue_resize (widget);
4804     }
4805 }
4806
4807 /**
4808  * gtk_widget_get_parent:
4809  * @widget: a #GtkWidget
4810  *
4811  * Returns the parent container of @widget.
4812  *
4813  * Return value: the parent container of @widget, or %NULL
4814  **/
4815 GtkWidget *
4816 gtk_widget_get_parent (GtkWidget *widget)
4817 {
4818   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4819
4820   return widget->parent;
4821 }
4822
4823 /*****************************************
4824  * Widget styles
4825  * see docs/styles.txt
4826  *****************************************/
4827
4828 /**
4829  * gtk_widget_set_style:
4830  * @widget: a #GtkWidget
4831  * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4832  *         gtk_widget_set_style() and go back to the default style
4833  *
4834  * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4835  * want to use this function; it interacts badly with themes, because
4836  * themes work by replacing the #GtkStyle. Instead, use
4837  * gtk_widget_modify_style().
4838  * 
4839  **/
4840 void
4841 gtk_widget_set_style (GtkWidget *widget,
4842                       GtkStyle  *style)
4843 {
4844   g_return_if_fail (GTK_IS_WIDGET (widget));
4845
4846   if (style)
4847     {
4848       gboolean initial_emission;
4849
4850       initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4851       
4852       GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4853       GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4854       
4855       gtk_widget_set_style_internal (widget, style, initial_emission);
4856     }
4857   else
4858     {
4859       if (GTK_WIDGET_USER_STYLE (widget))
4860         gtk_widget_reset_rc_style (widget);
4861     }
4862 }
4863
4864 /**
4865  * gtk_widget_ensure_style:
4866  * @widget: a #GtkWidget
4867  *
4868  * Ensures that @widget has a style (@widget->style). Not a very useful
4869  * function; most of the time, if you want the style, the widget is
4870  * realized, and realized widgets are guaranteed to have a style
4871  * already.
4872  * 
4873  **/
4874 void
4875 gtk_widget_ensure_style (GtkWidget *widget)
4876 {
4877   g_return_if_fail (GTK_IS_WIDGET (widget));
4878
4879   if (!GTK_WIDGET_USER_STYLE (widget) &&
4880       !GTK_WIDGET_RC_STYLE (widget))
4881     gtk_widget_reset_rc_style (widget);
4882 }
4883
4884 /* Look up the RC style for this widget, unsetting any user style that
4885  * may be in effect currently
4886  **/
4887 static void
4888 gtk_widget_reset_rc_style (GtkWidget *widget)
4889 {
4890   GtkStyle *new_style = NULL;
4891   gboolean initial_emission;
4892   
4893   initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4894
4895   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4896   GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4897   
4898   if (gtk_widget_has_screen (widget))
4899     new_style = gtk_rc_get_style (widget);
4900   if (!new_style)
4901     new_style = gtk_widget_get_default_style ();
4902
4903   if (initial_emission || new_style != widget->style)
4904     gtk_widget_set_style_internal (widget, new_style, initial_emission);
4905 }
4906
4907 /**
4908  * gtk_widget_get_style:
4909  * @widget: a #GtkWidget
4910  * 
4911  * Simply an accessor function that returns @widget->style.
4912  * 
4913  * Return value: the widget's #GtkStyle
4914  **/
4915 GtkStyle*
4916 gtk_widget_get_style (GtkWidget *widget)
4917 {
4918   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4919   
4920   return widget->style;
4921 }
4922
4923 /**
4924  * gtk_widget_modify_style:
4925  * @widget: a #GtkWidget
4926  * @style: the #GtkRcStyle holding the style modifications
4927  * 
4928  * Modifies style values on the widget. Modifications made using this
4929  * technique take precedence over style values set via an RC file,
4930  * however, they will be overriden if a style is explicitely set on
4931  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4932  * is designed so each field can either be set or unset, so it is
4933  * possible, using this function, to modify some style values and
4934  * leave the others unchanged.
4935  *
4936  * Note that modifications made with this function are not cumulative
4937  * with previous calls to gtk_widget_modify_style() or with such
4938  * functions as gtk_widget_modify_fg(). If you wish to retain
4939  * previous values, you must first call gtk_widget_get_modifier_style(),
4940  * make your modifications to the returned style, then call
4941  * gtk_widget_modify_style() with that style. On the other hand,
4942  * if you first call gtk_widget_modify_style(), subsequent calls
4943  * to such functions gtk_widget_modify_fg() will have a cumulative
4944  * effect with the initial modifications.
4945  **/
4946 void       
4947 gtk_widget_modify_style (GtkWidget      *widget,
4948                          GtkRcStyle     *style)
4949 {
4950   g_return_if_fail (GTK_IS_WIDGET (widget));
4951   g_return_if_fail (GTK_IS_RC_STYLE (style));
4952   
4953   g_object_set_qdata_full (G_OBJECT (widget),
4954                            quark_rc_style,
4955                            gtk_rc_style_copy (style),
4956                            (GDestroyNotify) gtk_rc_style_unref);
4957
4958   /* note that "style" may be invalid here if it was the old
4959    * modifier style and the only reference was our own.
4960    */
4961   
4962   if (GTK_WIDGET_RC_STYLE (widget))
4963     gtk_widget_reset_rc_style (widget);
4964 }
4965
4966 /**
4967  * gtk_widget_get_modifier_style:
4968  * @widget: a #GtkWidget
4969  * 
4970  * Returns the current modifier style for the widget. (As set by
4971  * gtk_widget_modify_style().) If no style has previously set, a new
4972  * #GtkRcStyle will be created with all values unset, and set as the
4973  * modifier style for the widget. If you make changes to this rc
4974  * style, you must call gtk_widget_modify_style(), passing in the
4975  * returned rc style, to make sure that your changes take effect.
4976  *
4977  * Caution: passing the style back to gtk_widget_modify_style() will
4978  * normally end up destroying it, because gtk_widget_modify_style() copies
4979  * the passed-in style and sets the copy as the new modifier style,
4980  * thus dropping any reference to the old modifier style. Add a reference
4981  * to the modifier style if you want to keep it alive.
4982  * 
4983  * Return value: the modifier style for the widget. This rc style is
4984  *   owned by the widget. If you want to keep a pointer to value this
4985  *   around, you must add a refcount using g_object_ref().
4986  **/
4987 GtkRcStyle *
4988 gtk_widget_get_modifier_style (GtkWidget      *widget)
4989 {
4990   GtkRcStyle *rc_style;
4991   
4992   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4993
4994   rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4995
4996   if (!rc_style)
4997     {
4998       rc_style = gtk_rc_style_new ();
4999       g_object_set_qdata_full (G_OBJECT (widget),
5000                                quark_rc_style,
5001                                rc_style,
5002                                (GDestroyNotify) gtk_rc_style_unref);
5003     }
5004
5005   return rc_style;
5006 }
5007
5008 static void
5009 gtk_widget_modify_color_component (GtkWidget      *widget,
5010                                    GtkRcFlags      component,
5011                                    GtkStateType    state,
5012                                    const GdkColor *color)
5013 {
5014   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
5015
5016   if (color)
5017     {
5018       switch (component)
5019         {
5020         case GTK_RC_FG:
5021           rc_style->fg[state] = *color;
5022           break;
5023         case GTK_RC_BG:
5024           rc_style->bg[state] = *color;
5025           break;
5026         case GTK_RC_TEXT:
5027           rc_style->text[state] = *color;
5028           break;
5029         case GTK_RC_BASE:
5030           rc_style->base[state] = *color;
5031           break;
5032         default:
5033           g_assert_not_reached();
5034         }
5035       
5036       rc_style->color_flags[state] |= component;
5037     }
5038   else
5039     rc_style->color_flags[state] &= ~component;
5040
5041   gtk_widget_modify_style (widget, rc_style);
5042 }
5043
5044 /**
5045  * gtk_widget_modify_fg:
5046  * @widget: a #GtkWidget.
5047  * @state: the state for which to set the foreground color.
5048  * @color: the color to assign (does not need to be allocated),
5049  *         or %NULL to undo the effect of previous calls to
5050  *         of gtk_widget_modify_fg().
5051  * 
5052  * Sets the foreground color for a widget in a particular state.  All
5053  * other style values are left untouched. See also
5054  * gtk_widget_modify_style().
5055  **/
5056 void
5057 gtk_widget_modify_fg (GtkWidget      *widget,
5058                       GtkStateType    state,
5059                       const GdkColor *color)
5060 {
5061   g_return_if_fail (GTK_IS_WIDGET (widget));
5062   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5063
5064   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5065 }
5066
5067 /**
5068  * gtk_widget_modify_bg:
5069  * @widget: a #GtkWidget.
5070  * @state: the state for which to set the background color.
5071  * @color: the color to assign (does not need to be allocated),
5072  *         or %NULL to undo the effect of previous calls to
5073  *         of gtk_widget_modify_bg().
5074  * 
5075  * Sets the background color for a widget in a particular state.  All
5076  * other style values are left untouched. See also
5077  * gtk_widget_modify_style(). 
5078  *
5079  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5080  * draw on their parent container's window and thus may not draw any background
5081  * themselves. This is the case for e.g. #GtkLabel. To modify the background
5082  * of such widgets, you have to set the background color on their parent; if you want 
5083  * to set the background of a rectangular area around a label, try placing the 
5084  * label in a #GtkEventBox widget and setting the background color on that.
5085  **/
5086 void
5087 gtk_widget_modify_bg (GtkWidget      *widget,
5088                       GtkStateType    state,
5089                       const GdkColor *color)
5090 {
5091   g_return_if_fail (GTK_IS_WIDGET (widget));
5092   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5093
5094   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5095 }
5096
5097 /**
5098  * gtk_widget_modify_text:
5099  * @widget: a #GtkWidget.
5100  * @state: the state for which to set the text color.
5101  * @color: the color to assign (does not need to be allocated),
5102  *         or %NULL to undo the effect of previous calls to
5103  *         of gtk_widget_modify_text().
5104  * 
5105  * Sets the text color for a widget in a particular state.  All other
5106  * style values are left untouched. The text color is the foreground
5107  * color used along with the base color (see gtk_widget_modify_base())
5108  * for widgets such as #GtkEntry and #GtkTextView. See also
5109  * gtk_widget_modify_style().
5110  **/
5111 void
5112 gtk_widget_modify_text (GtkWidget      *widget,
5113                         GtkStateType    state,
5114                         const GdkColor *color)
5115 {
5116   g_return_if_fail (GTK_IS_WIDGET (widget));
5117   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5118
5119   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5120 }
5121
5122 /**
5123  * gtk_widget_modify_base:
5124  * @widget: a #GtkWidget.
5125  * @state: the state for which to set the base color.
5126  * @color: the color to assign (does not need to be allocated),
5127  *         or %NULL to undo the effect of previous calls to
5128  *         of gtk_widget_modify_base().
5129  * 
5130  * Sets the base color for a widget in a particular state.
5131  * All other style values are left untouched. The base color
5132  * is the background color used along with the text color
5133  * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5134  * and #GtkTextView. See also gtk_widget_modify_style().
5135  *
5136  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5137  * draw on their parent container's window and thus may not draw any background
5138  * themselves. This is the case for e.g. #GtkLabel. To modify the background
5139  * of such widgets, you have to set the base color on their parent; if you want 
5140  * to set the background of a rectangular area around a label, try placing the 
5141  * label in a #GtkEventBox widget and setting the base color on that.
5142  **/
5143 void
5144 gtk_widget_modify_base (GtkWidget      *widget,
5145                         GtkStateType    state,
5146                         const GdkColor *color)
5147 {
5148   g_return_if_fail (GTK_IS_WIDGET (widget));
5149   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5150
5151   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5152 }
5153
5154 /**
5155  * gtk_widget_modify_font:
5156  * @widget: a #GtkWidget
5157  * @font_desc: the font description to use, or %NULL to undo
5158  *   the effect of previous calls to gtk_widget_modify_font().
5159  * 
5160  * Sets the font to use for a widget.  All other style values are left
5161  * untouched. See also gtk_widget_modify_style().
5162  **/
5163 void
5164 gtk_widget_modify_font (GtkWidget            *widget,
5165                         PangoFontDescription *font_desc)
5166 {
5167   GtkRcStyle *rc_style;
5168
5169   g_return_if_fail (GTK_IS_WIDGET (widget));
5170
5171   rc_style = gtk_widget_get_modifier_style (widget);  
5172
5173   if (rc_style->font_desc)
5174     pango_font_description_free (rc_style->font_desc);
5175
5176   if (font_desc)
5177     rc_style->font_desc = pango_font_description_copy (font_desc);
5178   else
5179     rc_style->font_desc = NULL;
5180   
5181   gtk_widget_modify_style (widget, rc_style);
5182 }
5183
5184 static void
5185 gtk_widget_direction_changed (GtkWidget        *widget,
5186                               GtkTextDirection  previous_direction)
5187 {
5188   gtk_widget_queue_resize (widget);
5189 }
5190
5191 static void
5192 gtk_widget_style_set (GtkWidget *widget,
5193                       GtkStyle  *previous_style)
5194 {
5195   if (GTK_WIDGET_REALIZED (widget) &&
5196       !GTK_WIDGET_NO_WINDOW (widget))
5197     gtk_style_set_background (widget->style, widget->window, widget->state);
5198 }
5199
5200 static void
5201 gtk_widget_set_style_internal (GtkWidget *widget,
5202                                GtkStyle  *style,
5203                                gboolean   initial_emission)
5204 {
5205   g_object_ref (widget);
5206   g_object_freeze_notify (G_OBJECT (widget));
5207
5208   if (widget->style != style)
5209     {
5210       GtkStyle *previous_style;
5211
5212       if (GTK_WIDGET_REALIZED (widget))
5213         {
5214           gtk_widget_reset_shapes (widget);
5215           gtk_style_detach (widget->style);
5216         }
5217       
5218       previous_style = widget->style;
5219       widget->style = style;
5220       g_object_ref (widget->style);
5221       
5222       if (GTK_WIDGET_REALIZED (widget))
5223         widget->style = gtk_style_attach (widget->style, widget->window);
5224
5225       gtk_widget_update_pango_context (widget);
5226       g_signal_emit (widget,
5227                      widget_signals[STYLE_SET],
5228                      0,
5229                      initial_emission ? NULL : previous_style);
5230       g_object_unref (previous_style);
5231
5232       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
5233         gtk_widget_queue_resize (widget);
5234     }
5235   else if (initial_emission)
5236     {
5237       gtk_widget_update_pango_context (widget);
5238       g_signal_emit (widget,
5239                      widget_signals[STYLE_SET],
5240                      0,
5241                      NULL);
5242     }
5243   g_object_notify (G_OBJECT (widget), "style");
5244   g_object_thaw_notify (G_OBJECT (widget));
5245   g_object_unref (widget);
5246 }
5247
5248 typedef struct {
5249   GtkWidget *previous_toplevel;
5250   GdkScreen *previous_screen;
5251   GdkScreen *new_screen;
5252 } HierarchyChangedInfo;
5253
5254 static void
5255 do_screen_change (GtkWidget *widget,
5256                   GdkScreen *old_screen,
5257                   GdkScreen *new_screen)
5258 {
5259   if (old_screen != new_screen)
5260     {
5261       if (old_screen)
5262         {
5263           PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5264           if (context)
5265             g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
5266         }
5267       
5268       g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
5269     }
5270 }
5271
5272 static void
5273 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
5274                                                 gpointer   client_data)
5275 {
5276   gboolean new_anchored;
5277   HierarchyChangedInfo *info = client_data;
5278
5279   new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
5280                  (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
5281
5282   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
5283     {
5284       g_object_ref (widget);
5285       
5286       if (new_anchored)
5287         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
5288       else
5289         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
5290       
5291       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
5292       do_screen_change (widget, info->previous_screen, info->new_screen);
5293       
5294       if (GTK_IS_CONTAINER (widget))
5295         gtk_container_forall (GTK_CONTAINER (widget),
5296                               gtk_widget_propagate_hierarchy_changed_recurse,
5297                               client_data);
5298       
5299       g_object_unref (widget);
5300     }
5301 }
5302
5303 /**
5304  * _gtk_widget_propagate_hierarchy_changed:
5305  * @widget: a #GtkWidget
5306  * @previous_toplevel: Previous toplevel
5307  * 
5308  * Propagates changes in the anchored state to a widget and all
5309  * children, unsetting or setting the %ANCHORED flag, and
5310  * emitting ::hierarchy_changed.
5311  **/
5312 void
5313 _gtk_widget_propagate_hierarchy_changed (GtkWidget    *widget,
5314                                          GtkWidget    *previous_toplevel)
5315 {
5316   HierarchyChangedInfo info;
5317
5318   info.previous_toplevel = previous_toplevel;
5319   info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
5320
5321   if (GTK_WIDGET_TOPLEVEL (widget) ||
5322       (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
5323     info.new_screen = gtk_widget_get_screen (widget);
5324   else
5325     info.new_screen = NULL;
5326
5327   if (info.previous_screen)
5328     g_object_ref (info.previous_screen);
5329   if (previous_toplevel)
5330     g_object_ref (previous_toplevel);
5331
5332   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
5333
5334   if (previous_toplevel)
5335     g_object_unref (previous_toplevel);
5336   if (info.previous_screen)
5337     g_object_unref (info.previous_screen);
5338 }
5339
5340 static void
5341 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
5342                                              gpointer   client_data)
5343 {
5344   HierarchyChangedInfo *info = client_data;
5345
5346   g_object_ref (widget);
5347   
5348   do_screen_change (widget, info->previous_screen, info->new_screen);
5349   
5350   if (GTK_IS_CONTAINER (widget))
5351     gtk_container_forall (GTK_CONTAINER (widget),
5352                           gtk_widget_propagate_screen_changed_recurse,
5353                           client_data);
5354   
5355   g_object_unref (widget);
5356 }
5357
5358 /**
5359  * gtk_widget_is_composited:
5360  * @widget: a #GtkWidget
5361  * 
5362  * Whether @widget can rely on having its alpha channel
5363  * drawn correctly. On X11 this function returns whether a
5364  * compositing manager is running for @widget's screen
5365  * 
5366  * Return value: %TRUE if the widget can rely on its alpha
5367  * channel being drawn correctly.
5368  * 
5369  * Since: 2.10
5370  */
5371 gboolean
5372 gtk_widget_is_composited (GtkWidget *widget)
5373 {
5374   GdkScreen *screen;
5375
5376   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5377   
5378   screen = gtk_widget_get_screen (widget);
5379   
5380   return gdk_screen_is_composited (screen);
5381 }
5382
5383 static void
5384 propagate_composited_changed (GtkWidget *widget,
5385                               gpointer dummy)
5386 {
5387   if (GTK_IS_CONTAINER (widget))
5388     {
5389       gtk_container_forall (GTK_CONTAINER (widget),
5390                             propagate_composited_changed,
5391                             NULL);
5392     }
5393   
5394   g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
5395 }
5396
5397 void
5398 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
5399 {
5400   propagate_composited_changed (widget, NULL);
5401 }
5402
5403 /**
5404  * _gtk_widget_propagate_screen_changed:
5405  * @widget: a #GtkWidget
5406  * @previous_screen: Previous screen
5407  * 
5408  * Propagates changes in the screen for a widget to all
5409  * children, emitting ::screen_changed.
5410  **/
5411 void
5412 _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
5413                                       GdkScreen    *previous_screen)
5414 {
5415   HierarchyChangedInfo info;
5416
5417   info.previous_screen = previous_screen;
5418   info.new_screen = gtk_widget_get_screen (widget);
5419
5420   if (previous_screen)
5421     g_object_ref (previous_screen);
5422
5423   gtk_widget_propagate_screen_changed_recurse (widget, &info);
5424
5425   if (previous_screen)
5426     g_object_unref (previous_screen);
5427 }
5428
5429 static void
5430 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
5431 {
5432   if (GTK_WIDGET_RC_STYLE (widget))
5433     gtk_widget_reset_rc_style (widget);
5434   
5435   if (GTK_IS_CONTAINER (widget))
5436     gtk_container_forall (GTK_CONTAINER (widget),
5437                           reset_rc_styles_recurse,
5438                           NULL);
5439 }
5440
5441 void
5442 gtk_widget_reset_rc_styles (GtkWidget *widget)
5443 {
5444   g_return_if_fail (GTK_IS_WIDGET (widget));
5445
5446   reset_rc_styles_recurse (widget, NULL);
5447 }
5448
5449 /**
5450  * gtk_widget_get_default_style:
5451  * 
5452  * Returns the default style used by all widgets initially.
5453  * 
5454  * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5455  * should not be modified or freed.
5456  */ 
5457 GtkStyle*
5458 gtk_widget_get_default_style (void)
5459 {
5460   if (!gtk_default_style)
5461     {
5462       gtk_default_style = gtk_style_new ();
5463       g_object_ref (gtk_default_style);
5464     }
5465   
5466   return gtk_default_style;
5467 }
5468
5469 static PangoContext *
5470 gtk_widget_peek_pango_context (GtkWidget *widget)
5471 {
5472   return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5473 }
5474
5475 /**
5476  * gtk_widget_get_pango_context:
5477  * @widget: a #GtkWidget
5478  * 
5479  * Gets a #PangoContext with the appropriate font map, font description,
5480  * and base direction for this widget. Unlike the context returned
5481  * by gtk_widget_create_pango_context(), this context is owned by
5482  * the widget (it can be used until the screen for the widget changes
5483  * or the widget is removed from its toplevel), and will be updated to
5484  * match any changes to the widget's attributes.
5485  *
5486  * If you create and keep a #PangoLayout using this context, you must
5487  * deal with changes to the context by calling pango_layout_context_changed()
5488  * on the layout in response to the ::style-set and ::direction-changed signals
5489  * for the widget.
5490  *
5491  * Return value: the #PangoContext for the widget.
5492  **/
5493 PangoContext *
5494 gtk_widget_get_pango_context (GtkWidget *widget)
5495 {
5496   PangoContext *context;
5497
5498   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5499   
5500   context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5501   if (!context)
5502     {
5503       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5504       g_object_set_qdata_full (G_OBJECT (widget),
5505                                quark_pango_context,
5506                                context,
5507                                g_object_unref);
5508     }
5509
5510   return context;
5511 }
5512
5513 static void
5514 update_pango_context (GtkWidget    *widget,
5515                       PangoContext *context)
5516 {
5517   pango_context_set_font_description (context, widget->style->font_desc);
5518   pango_context_set_base_dir (context,
5519                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5520                               PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5521 }
5522
5523 static void
5524 gtk_widget_update_pango_context (GtkWidget *widget)
5525 {
5526   PangoContext *context = gtk_widget_peek_pango_context (widget);
5527   
5528   if (context)
5529     {
5530       GdkScreen *screen;
5531
5532       update_pango_context (widget, context);
5533
5534       screen = gtk_widget_get_screen_unchecked (widget);
5535       if (screen)
5536         {
5537           pango_cairo_context_set_resolution (context,
5538                                               gdk_screen_get_resolution (screen));
5539           pango_cairo_context_set_font_options (context,
5540                                                 gdk_screen_get_font_options (screen));
5541         }
5542     }
5543 }
5544
5545 /**
5546  * gtk_widget_create_pango_context:
5547  * @widget: a #GtkWidget
5548  * 
5549  * Creates a new #PangoContext with the appropriate font map,
5550  * font description, and base direction for drawing text for
5551  * this widget. See also gtk_widget_get_pango_context().
5552  * 
5553  * Return value: the new #PangoContext
5554  **/
5555 PangoContext *
5556 gtk_widget_create_pango_context (GtkWidget *widget)
5557 {
5558   GdkScreen *screen;
5559   PangoContext *context;
5560
5561   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5562
5563   screen = gtk_widget_get_screen_unchecked (widget);
5564   if (!screen)
5565     {
5566       GTK_NOTE (MULTIHEAD,
5567                 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5568
5569       screen = gdk_screen_get_default ();
5570     }
5571
5572   context = gdk_pango_context_get_for_screen (screen);
5573
5574   update_pango_context (widget, context);
5575   pango_context_set_language (context, gtk_get_default_language ());
5576
5577   return context;
5578 }
5579
5580 /**
5581  * gtk_widget_create_pango_layout:
5582  * @widget: a #GtkWidget
5583  * @text:   text to set on the layout (can be %NULL)
5584  * 
5585  * Creates a new #PangoLayout with the appropriate font map,
5586  * font description, and base direction for drawing text for
5587  * this widget.
5588  *
5589  * If you keep a #PangoLayout created in this way around, in order to
5590  * notify the layout of changes to the base direction or font of this
5591  * widget, you must call pango_layout_context_changed() in response to
5592  * the ::style-set and ::direction-changed signals for the widget.
5593  * 
5594  * Return value: the new #PangoLayout
5595  **/
5596 PangoLayout *
5597 gtk_widget_create_pango_layout (GtkWidget   *widget,
5598                                 const gchar *text)
5599 {
5600   PangoLayout *layout;
5601   PangoContext *context;
5602
5603   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5604
5605   context = gtk_widget_get_pango_context (widget);
5606   layout = pango_layout_new (context);
5607
5608   if (text)
5609     pango_layout_set_text (layout, text, -1);
5610
5611   return layout;
5612 }
5613
5614 /**
5615  * gtk_widget_render_icon:
5616  * @widget: a #GtkWidget
5617  * @stock_id: a stock ID
5618  * @size: a stock size. A size of (GtkIconSize)-1 means render at 
5619  *     the size of the source and don't scale (if there are multiple 
5620  *     source sizes, GTK+ picks one of the available sizes).
5621  * @detail: render detail to pass to theme engine
5622  * 
5623  * A convenience function that uses the theme engine and RC file
5624  * settings for @widget to look up @stock_id and render it to
5625  * a pixbuf. @stock_id should be a stock icon ID such as
5626  * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5627  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5628  * identifies the widget or code doing the rendering, so that
5629  * theme engines can special-case rendering for that widget or code.
5630  *
5631  * The pixels in the returned #GdkPixbuf are shared with the rest of
5632  * the application and should not be modified. The pixbuf should be freed
5633  * after use with g_object_unref().
5634  *
5635  * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5636  **/
5637 GdkPixbuf*
5638 gtk_widget_render_icon (GtkWidget      *widget,
5639                         const gchar    *stock_id,
5640                         GtkIconSize     size,
5641                         const gchar    *detail)
5642 {
5643   GtkIconSet *icon_set;
5644   GdkPixbuf *retval;
5645   
5646   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5647   g_return_val_if_fail (stock_id != NULL, NULL);
5648   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5649   
5650   gtk_widget_ensure_style (widget);
5651   
5652   icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5653
5654   if (icon_set == NULL)
5655     return NULL;
5656
5657   retval = gtk_icon_set_render_icon (icon_set,
5658                                      widget->style,
5659                                      gtk_widget_get_direction (widget),
5660                                      GTK_WIDGET_STATE (widget),
5661                                      size,
5662                                      widget,
5663                                      detail);
5664
5665   return retval;
5666 }
5667
5668 /**
5669  * gtk_widget_set_parent_window:
5670  * @widget: a #GtkWidget.
5671  * @parent_window: the new parent window.
5672  *  
5673  * Sets a non default parent window for @widget.
5674  **/
5675 void
5676 gtk_widget_set_parent_window   (GtkWidget           *widget,
5677                                 GdkWindow           *parent_window)
5678 {
5679   GdkWindow *old_parent_window;
5680
5681   g_return_if_fail (GTK_IS_WIDGET (widget));
5682   
5683   old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5684                                           quark_parent_window);
5685
5686   if (parent_window != old_parent_window)
5687     {
5688       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
5689                           parent_window);
5690       if (old_parent_window)
5691         g_object_unref (old_parent_window);
5692       if (parent_window)
5693         g_object_ref (parent_window);
5694     }
5695 }
5696
5697
5698 /**
5699  * gtk_widget_set_child_visible:
5700  * @widget: a #GtkWidget
5701  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5702  *
5703  * Sets whether @widget should be mapped along with its when its parent
5704  * is mapped and @widget has been shown with gtk_widget_show(). 
5705  *
5706  * The child visibility can be set for widget before it is added to
5707  * a container with gtk_widget_set_parent(), to avoid mapping
5708  * children unnecessary before immediately unmapping them. However
5709  * it will be reset to its default state of %TRUE when the widget
5710  * is removed from a container.
5711  * 
5712  * Note that changing the child visibility of a widget does not
5713  * queue a resize on the widget. Most of the time, the size of
5714  * a widget is computed from all visible children, whether or
5715  * not they are mapped. If this is not the case, the container
5716  * can queue a resize itself.
5717  *
5718  * This function is only useful for container implementations and
5719  * never should be called by an application.
5720  **/
5721 void
5722 gtk_widget_set_child_visible (GtkWidget *widget,
5723                               gboolean   is_visible)
5724 {
5725   g_return_if_fail (GTK_IS_WIDGET (widget));
5726   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5727
5728   g_object_ref (widget);
5729
5730   if (is_visible)
5731     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5732   else
5733     {
5734       GtkWidget *toplevel;
5735       
5736       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5737
5738       toplevel = gtk_widget_get_toplevel (widget);
5739       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5740         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5741     }
5742
5743   if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5744     {
5745       if (GTK_WIDGET_MAPPED (widget->parent) &&
5746           GTK_WIDGET_CHILD_VISIBLE (widget) &&
5747           GTK_WIDGET_VISIBLE (widget))
5748         gtk_widget_map (widget);
5749       else
5750         gtk_widget_unmap (widget);
5751     }
5752
5753   g_object_unref (widget);
5754 }
5755
5756 /**
5757  * gtk_widget_get_child_visible:
5758  * @widget: a #GtkWidget
5759  * 
5760  * Gets the value set with gtk_widget_set_child_visible().
5761  * If you feel a need to use this function, your code probably
5762  * needs reorganization. 
5763  *
5764  * This function is only useful for container implementations and
5765  * never should be called by an application.
5766  *
5767  * Return value: %TRUE if the widget is mapped with the parent.
5768  **/
5769 gboolean
5770 gtk_widget_get_child_visible (GtkWidget *widget)
5771 {
5772   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5773   
5774   return GTK_WIDGET_CHILD_VISIBLE (widget);
5775 }
5776
5777 static GdkScreen *
5778 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5779 {
5780   GtkWidget *toplevel;
5781   
5782   toplevel = gtk_widget_get_toplevel (widget);
5783
5784   if (GTK_WIDGET_TOPLEVEL (toplevel))
5785     {
5786       if (GTK_IS_WINDOW (toplevel))
5787         return GTK_WINDOW (toplevel)->screen;
5788       else if (GTK_IS_INVISIBLE (toplevel))
5789         return GTK_INVISIBLE (widget)->screen;
5790     }
5791
5792   return NULL;
5793 }
5794
5795 /**
5796  * gtk_widget_get_screen:
5797  * @widget: a #GtkWidget
5798  * 
5799  * Get the #GdkScreen from the toplevel window associated with
5800  * this widget. This function can only be called after the widget
5801  * has been added to a widget hierarchy with a #GtkWindow
5802  * at the top.
5803  *
5804  * In general, you should only create screen specific
5805  * resources when a widget has been realized, and you should
5806  * free those resources when the widget is unrealized.
5807  * 
5808  * Return value: the #GdkScreen for the toplevel for this widget.
5809  *
5810  * Since: 2.2
5811  **/
5812 GdkScreen*
5813 gtk_widget_get_screen (GtkWidget *widget)
5814 {
5815   GdkScreen *screen;
5816   
5817   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5818
5819   screen = gtk_widget_get_screen_unchecked (widget);
5820
5821   if (screen)
5822     return screen;
5823   else
5824     {
5825 #if 0
5826       g_warning (G_STRLOC ": Can't get associated screen"
5827                  " for a widget unless it is inside a toplevel GtkWindow\n"
5828                  " widget type is %s associated top level type is %s",
5829                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5830                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5831 #endif
5832       return gdk_screen_get_default ();
5833     }
5834 }
5835
5836 /**
5837  * gtk_widget_has_screen:
5838  * @widget: a #GtkWidget
5839  * 
5840  * Checks whether there is a #GdkScreen is associated with
5841  * this widget. All toplevel widgets have an associated
5842  * screen, and all widgets added into a heirarchy with a toplevel
5843  * window at the top.
5844  * 
5845  * Return value: %TRUE if there is a #GdkScreen associcated
5846  *   with the widget.
5847  *
5848  * Since: 2.2
5849  **/
5850 gboolean
5851 gtk_widget_has_screen (GtkWidget *widget)
5852 {
5853   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5854
5855   return (gtk_widget_get_screen_unchecked (widget) != NULL);
5856 }
5857
5858 /**
5859  * gtk_widget_get_display:
5860  * @widget: a #GtkWidget
5861  * 
5862  * Get the #GdkDisplay for the toplevel window associated with
5863  * this widget. This function can only be called after the widget
5864  * has been added to a widget hierarchy with a #GtkWindow at the top.
5865  *
5866  * In general, you should only create display specific
5867  * resources when a widget has been realized, and you should
5868  * free those resources when the widget is unrealized.
5869  * 
5870  * Return value: the #GdkDisplay for the toplevel for this widget.
5871  *
5872  * Since: 2.2
5873  **/
5874 GdkDisplay*
5875 gtk_widget_get_display (GtkWidget *widget)
5876 {
5877   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5878   
5879   return gdk_screen_get_display (gtk_widget_get_screen (widget));
5880 }
5881
5882 /**
5883  * gtk_widget_get_root_window:
5884  * @widget: a #GtkWidget
5885  * 
5886  * Get the root window where this widget is located. This function can
5887  * only be called after the widget has been added to a widget
5888  * heirarchy with #GtkWindow at the top.
5889  *
5890  * The root window is useful for such purposes as creating a popup
5891  * #GdkWindow associated with the window. In general, you should only
5892  * create display specific resources when a widget has been realized,
5893  * and you should free those resources when the widget is unrealized.
5894  * 
5895  * Return value: the #GdkWindow root window for the toplevel for this widget.
5896  *
5897  * Since: 2.2
5898  **/
5899 GdkWindow*
5900 gtk_widget_get_root_window (GtkWidget *widget)
5901 {
5902   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5903
5904   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5905 }
5906
5907 /**
5908  * gtk_widget_get_parent_window:
5909  * @widget: a #GtkWidget.
5910  * @returns: the parent window of @widget.
5911  * 
5912  * Gets @widget's parent window.
5913  **/
5914 GdkWindow *
5915 gtk_widget_get_parent_window   (GtkWidget           *widget)
5916 {
5917   GdkWindow *parent_window;
5918
5919   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5920   
5921   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5922
5923   return (parent_window != NULL) ? parent_window : 
5924          (widget->parent != NULL) ? widget->parent->window : NULL;
5925 }
5926
5927 /**
5928  * gtk_widget_child_focus:
5929  * @widget: a #GtkWidget
5930  * @direction: direction of focus movement
5931  *
5932  * This function is used by custom widget implementations; if you're
5933  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5934  * to a particular widget, and gtk_container_set_focus_chain() to
5935  * change the focus tab order. So you may want to investigate those
5936  * functions instead.
5937  * 
5938  * gtk_widget_child_focus() is called by containers as the user moves
5939  * around the window using keyboard shortcuts. @direction indicates
5940  * what kind of motion is taking place (up, down, left, right, tab
5941  * forward, tab backward).  gtk_widget_child_focus() invokes the
5942  * "focus" signal on #GtkWidget; widgets override the default handler
5943  * for this signal in order to implement appropriate focus behavior.
5944  *
5945  * The "focus" default handler for a widget should return %TRUE if
5946  * moving in @direction left the focus on a focusable location inside
5947  * that widget, and %FALSE if moving in @direction moved the focus
5948  * outside the widget. If returning %TRUE, widgets normally
5949  * call gtk_widget_grab_focus() to place the focus accordingly;
5950  * if returning %FALSE, they don't modify the current focus location.
5951  * 
5952  * This function replaces gtk_container_focus() from GTK+ 1.2.  It was
5953  * necessary to check that the child was visible, sensitive, and
5954  * focusable before calling
5955  * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5956  * the widget is not currently in a focusable state, so there's no
5957  * need for those checks.
5958  * 
5959  * Return value: %TRUE if focus ended up inside @widget
5960  **/
5961 gboolean
5962 gtk_widget_child_focus (GtkWidget       *widget,
5963                         GtkDirectionType direction)
5964 {
5965   gboolean return_val;
5966
5967   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5968
5969   if (!GTK_WIDGET_VISIBLE (widget) ||
5970       !GTK_WIDGET_IS_SENSITIVE (widget))
5971     return FALSE;
5972
5973   /* child widgets must set CAN_FOCUS, containers
5974    * don't have to though.
5975    */
5976   if (!GTK_IS_CONTAINER (widget) &&
5977       !GTK_WIDGET_CAN_FOCUS (widget))
5978     return FALSE;
5979   
5980   g_signal_emit (widget,
5981                  widget_signals[FOCUS],
5982                  0,
5983                  direction, &return_val);
5984
5985   return return_val;
5986 }
5987
5988 /**
5989  * gtk_widget_keynav_failed:
5990  * @widget:    a #GtkWidget
5991  * @direction: direction of focus movement
5992  *
5993  * This function should be called whenever keyboard navigation within
5994  * a single widget hits a boundary. The function emits the
5995  * "keynav-changed" signal on the widget and its return value should
5996  * be interpreted in a way similar to the return value of
5997  * gtk_widget_child_focus():
5998  *
5999  * When %TRUE is returned, stay in the widget, the failed keyboard
6000  * navigation is Ok and/or there is nowhere we can/should move the
6001  * focus to.
6002  *
6003  * When %FALSE is returned, the caller should continue with keyboard
6004  * navigation outside the widget, e.g. by calling
6005  * gtk_widget_child_focus() on the widget's toplevel.
6006  *
6007  * The default implementation for the "keynav-failed" signal is to
6008  * return %TRUE for %GTK_DIR_TAB_FORWARD and
6009  * %GTK_DIR_TAB_BACKWARD. For the other values of #GtkDirectionType,
6010  * it looks at the "gtk-keynav-cursor-only" settings property and
6011  * returns %FALSE if the setting is %TRUE. This way the entire GUI
6012  * becomes cursor-navigatable on input devices such as mobile phones
6013  * which only have cursor keys but no tab key.
6014  *
6015  * Whenever the default implementation returns %TRUE, it also calls
6016  * gtk_widget_error_bell() to notify the user of the failed keyboard
6017  * navigation.
6018  *
6019  * A use case for providing an own implementation of keynav-failed (by
6020  * either connecting to it or by overriding it) would be a row of
6021  * #GtkEntry widgets where the user should be able to navigate the
6022  * entire row with the cursor keys, as e.g. known from GUIs that
6023  * require entering license keys.
6024  *
6025  * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6026  *               if the emitting widget should try to handle the keyboard
6027  *               navigation attempt in its parent container(s).
6028  *
6029  * Since: 2.12
6030  **/
6031 gboolean
6032 gtk_widget_keynav_failed (GtkWidget        *widget,
6033                           GtkDirectionType  direction)
6034 {
6035   gboolean return_val;
6036
6037   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6038
6039   g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6040                  direction, &return_val);
6041
6042   return return_val;
6043 }
6044
6045 /**
6046  * gtk_widget_error_bell:
6047  * @widget: a #GtkWidget
6048  *
6049  * Notifies the user about an input-related error on this widget. If
6050  * the gtk-error-bell settings property is %TRUE, it calls
6051  * gdk_window_beep(), otherwise it does nothing.
6052  *
6053  * Note that the effect of gdk_window_beep() can be configured in many
6054  * ways, depending on the windowing backend and the desktop environment
6055  * or window manager that is used.
6056  *
6057  * Since: 2.12
6058  **/
6059 void
6060 gtk_widget_error_bell (GtkWidget *widget)
6061 {
6062   gboolean beep;
6063
6064   g_return_if_fail (GTK_IS_WIDGET (widget));
6065
6066   g_object_get (gtk_widget_get_settings (widget),
6067                 "gtk-error-bell", &beep,
6068                 NULL);
6069
6070   if (beep && widget->window)
6071     gdk_window_beep (widget->window);
6072 }
6073
6074 /**
6075  * gtk_widget_set_uposition:
6076  * @widget: a #GtkWidget
6077  * @x: x position; -1 to unset x; -2 to leave x unchanged
6078  * @y: y position; -1 to unset y; -2 to leave y unchanged
6079  * 
6080  *
6081  * Sets the position of a widget. The funny "u" in the name comes from
6082  * the "user position" hint specified by the X Window System, and
6083  * exists for legacy reasons. This function doesn't work if a widget
6084  * is inside a container; it's only really useful on #GtkWindow.
6085  *
6086  * Don't use this function to center dialogs over the main application
6087  * window; most window managers will do the centering on your behalf
6088  * if you call gtk_window_set_transient_for(), and it's really not
6089  * possible to get the centering to work correctly in all cases from
6090  * application code. But if you insist, use gtk_window_set_position()
6091  * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6092  * manually.
6093  *
6094  * Note that although @x and @y can be individually unset, the position
6095  * is not honoured unless both @x and @y are set.
6096  **/
6097 void
6098 gtk_widget_set_uposition (GtkWidget *widget,
6099                           gint       x,
6100                           gint       y)
6101 {
6102   /* FIXME this function is the only place that aux_info->x and
6103    * aux_info->y are even used I believe, and this function is
6104    * deprecated. Should be cleaned up.
6105    *
6106    * (Actually, size_allocate uses them) -Yosh
6107    */
6108   
6109   GtkWidgetAuxInfo *aux_info;
6110   
6111   g_return_if_fail (GTK_IS_WIDGET (widget));
6112   
6113   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
6114   
6115   if (x > -2)
6116     {
6117       if (x == -1)
6118         aux_info->x_set = FALSE;
6119       else
6120         {
6121           aux_info->x_set = TRUE;
6122           aux_info->x = x;
6123         }
6124     }
6125
6126   if (y > -2)
6127     {
6128       if (y == -1)
6129         aux_info->y_set = FALSE;
6130       else
6131         {
6132           aux_info->y_set = TRUE;
6133           aux_info->y = y;
6134         }
6135     }
6136
6137   if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
6138     _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
6139   
6140   if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
6141     gtk_widget_size_allocate (widget, &widget->allocation);
6142 }
6143
6144 static void
6145 gtk_widget_set_usize_internal (GtkWidget *widget,
6146                                gint       width,
6147                                gint       height)
6148 {
6149   GtkWidgetAuxInfo *aux_info;
6150   gboolean changed = FALSE;
6151   
6152   g_object_freeze_notify (G_OBJECT (widget));
6153
6154   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
6155   
6156   if (width > -2 && aux_info->width != width)
6157     {
6158       g_object_notify (G_OBJECT (widget), "width-request");
6159       aux_info->width = width;
6160       changed = TRUE;
6161     }
6162   if (height > -2 && aux_info->height != height)
6163     {
6164       g_object_notify (G_OBJECT (widget), "height-request");  
6165       aux_info->height = height;
6166       changed = TRUE;
6167     }
6168   
6169   if (GTK_WIDGET_VISIBLE (widget) && changed)
6170     gtk_widget_queue_resize (widget);
6171
6172   g_object_thaw_notify (G_OBJECT (widget));
6173 }
6174
6175 /**
6176  * gtk_widget_set_usize:
6177  * @widget: a #GtkWidget
6178  * @width: minimum width, or -1 to unset
6179  * @height: minimum height, or -1 to unset
6180  *
6181  * Sets the minimum size of a widget; that is, the widget's size
6182  * request will be @width by @height. You can use this function to
6183  * force a widget to be either larger or smaller than it is. The
6184  * strange "usize" name dates from the early days of GTK+, and derives
6185  * from X Window System terminology. In many cases,
6186  * gtk_window_set_default_size() is a better choice for toplevel
6187  * windows than this function; setting the default size will still
6188  * allow users to shrink the window. Setting the usize will force them
6189  * to leave the window at least as large as the usize. When dealing
6190  * with window sizes, gtk_window_set_geometry_hints() can be a useful
6191  * function as well.
6192  * 
6193  * Note the inherent danger of setting any fixed size - themes,
6194  * translations into other languages, different fonts, and user action
6195  * can all change the appropriate size for a given widget. So, it's
6196  * basically impossible to hardcode a size that will always be
6197  * correct.
6198  * 
6199  * @Deprecated: Use gtk_widget_set_size_request() instead.
6200  **/
6201 void
6202 gtk_widget_set_usize (GtkWidget *widget,
6203                       gint       width,
6204                       gint       height)
6205 {
6206   g_return_if_fail (GTK_IS_WIDGET (widget));
6207   
6208   gtk_widget_set_usize_internal (widget, width, height);
6209 }
6210
6211 /**
6212  * gtk_widget_set_size_request:
6213  * @widget: a #GtkWidget
6214  * @width: width @widget should request, or -1 to unset
6215  * @height: height @widget should request, or -1 to unset
6216  *
6217  * Sets the minimum size of a widget; that is, the widget's size
6218  * request will be @width by @height. You can use this function to
6219  * force a widget to be either larger or smaller than it normally
6220  * would be.
6221  *
6222  * In most cases, gtk_window_set_default_size() is a better choice for
6223  * toplevel windows than this function; setting the default size will
6224  * still allow users to shrink the window. Setting the size request
6225  * will force them to leave the window at least as large as the size
6226  * request. When dealing with window sizes,
6227  * gtk_window_set_geometry_hints() can be a useful function as well.
6228  * 
6229  * Note the inherent danger of setting any fixed size - themes,
6230  * translations into other languages, different fonts, and user action
6231  * can all change the appropriate size for a given widget. So, it's
6232  * basically impossible to hardcode a size that will always be
6233  * correct.
6234  *
6235  * The size request of a widget is the smallest size a widget can
6236  * accept while still functioning well and drawing itself correctly.
6237  * However in some strange cases a widget may be allocated less than
6238  * its requested size, and in many cases a widget may be allocated more
6239  * space than it requested.
6240  *
6241  * If the size request in a given direction is -1 (unset), then
6242  * the "natural" size request of the widget will be used instead.
6243  *
6244  * Widgets can't actually be allocated a size less than 1 by 1, but
6245  * you can pass 0,0 to this function to mean "as small as possible."
6246  **/
6247 void
6248 gtk_widget_set_size_request (GtkWidget *widget,
6249                              gint       width,
6250                              gint       height)
6251 {
6252   g_return_if_fail (GTK_IS_WIDGET (widget));
6253   g_return_if_fail (width >= -1);
6254   g_return_if_fail (height >= -1);
6255
6256   if (width == 0)
6257     width = 1;
6258   if (height == 0)
6259     height = 1;
6260   
6261   gtk_widget_set_usize_internal (widget, width, height);
6262 }
6263
6264
6265 /**
6266  * gtk_widget_get_size_request:
6267  * @widget: a #GtkWidget
6268  * @width: return location for width, or %NULL
6269  * @height: return location for height, or %NULL
6270  *
6271  * Gets the size request that was explicitly set for the widget using
6272  * gtk_widget_set_size_request().  A value of -1 stored in @width or
6273  * @height indicates that that dimension has not been set explicitly
6274  * and the natural requisition of the widget will be used intead. See
6275  * gtk_widget_set_size_request(). To get the size a widget will
6276  * actually use, call gtk_widget_size_request() instead of
6277  * this function.
6278  **/
6279 void
6280 gtk_widget_get_size_request (GtkWidget *widget,
6281                              gint      *width,
6282                              gint      *height)
6283 {
6284   GtkWidgetAuxInfo *aux_info;
6285
6286   g_return_if_fail (GTK_IS_WIDGET (widget));
6287
6288   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
6289
6290   if (width)
6291     *width = aux_info ? aux_info->width : -1;
6292
6293   if (height)
6294     *height = aux_info ? aux_info->height : -1;
6295 }
6296
6297 /**
6298  * gtk_widget_set_events:
6299  * @widget: a #GtkWidget
6300  * @events: event mask
6301  *
6302  * Sets the event mask (see #GdkEventMask) for a widget. The event
6303  * mask determines which events a widget will receive. Keep in mind
6304  * that different widgets have different default event masks, and by
6305  * changing the event mask you may disrupt a widget's functionality,
6306  * so be careful. This function must be called while a widget is
6307  * unrealized. Consider gtk_widget_add_events() for widgets that are
6308  * already realized, or if you want to preserve the existing event
6309  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
6310  * to get events on those widgets, place them inside a #GtkEventBox
6311  * and receive events on the event box.
6312  **/
6313 void
6314 gtk_widget_set_events (GtkWidget *widget,
6315                        gint       events)
6316 {
6317   gint *eventp;
6318   
6319   g_return_if_fail (GTK_IS_WIDGET (widget));
6320   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6321   
6322   eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6323   
6324   if (events)
6325     {
6326       if (!eventp)
6327         eventp = g_slice_new (gint);
6328       
6329       *eventp = events;
6330       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
6331     }
6332   else if (eventp)
6333     {
6334       g_slice_free (gint, eventp);
6335       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
6336     }
6337
6338   g_object_notify (G_OBJECT (widget), "events");
6339 }
6340
6341 static void
6342 gtk_widget_add_events_internal (GtkWidget *widget,
6343                                 gint       events,
6344                                 GList     *window_list)
6345 {
6346   GList *l;
6347
6348   for (l = window_list; l != NULL; l = l->next)
6349     {
6350       GdkWindow *window = l->data;
6351       gpointer user_data;
6352
6353       gdk_window_get_user_data (window, &user_data);
6354       if (user_data == widget)
6355         {
6356           GList *children;
6357
6358           gdk_window_set_events (window, gdk_window_get_events (window) | events);
6359
6360           children = gdk_window_get_children (window);
6361           gtk_widget_add_events_internal (widget, events, children);
6362           g_list_free (children);
6363         }
6364     }
6365 }
6366
6367 /**
6368  * gtk_widget_add_events:
6369  * @widget: a #GtkWidget
6370  * @events: an event mask, see #GdkEventMask
6371  *
6372  * Adds the events in the bitfield @events to the event mask for
6373  * @widget. See gtk_widget_set_events() for details.
6374  * 
6375  **/
6376 void
6377 gtk_widget_add_events (GtkWidget *widget,
6378                        gint       events)
6379 {
6380   gint *eventp;
6381   
6382   g_return_if_fail (GTK_IS_WIDGET (widget));
6383
6384   eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6385   
6386   if (events)
6387     {
6388       if (!eventp)
6389         {
6390           eventp = g_slice_new (gint);
6391           *eventp = 0;
6392         }
6393       
6394       *eventp |= events;
6395       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
6396     }
6397   else if (eventp)
6398     {
6399       g_slice_free (gint, eventp);
6400       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
6401     }
6402
6403   if (GTK_WIDGET_REALIZED (widget))
6404     {
6405       GList *window_list;
6406
6407       if (GTK_WIDGET_NO_WINDOW (widget))
6408         window_list = gdk_window_get_children (widget->window);
6409       else
6410         window_list = g_list_prepend (NULL, widget->window);
6411
6412       gtk_widget_add_events_internal (widget, events, window_list);
6413
6414       g_list_free (window_list);
6415     }
6416
6417   g_object_notify (G_OBJECT (widget), "events");
6418 }
6419
6420 /**
6421  * gtk_widget_set_extension_events:
6422  * @widget: a #GtkWidget
6423  * @mode: bitfield of extension events to receive
6424  *
6425  * Sets the extension events mask to @mode. See #GdkExtensionMode
6426  * and gdk_input_set_extension_events().
6427  * 
6428  **/
6429 void
6430 gtk_widget_set_extension_events (GtkWidget *widget,
6431                                  GdkExtensionMode mode)
6432 {
6433   GdkExtensionMode *modep;
6434   
6435   g_return_if_fail (GTK_IS_WIDGET (widget));
6436   
6437   modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6438   
6439   if (!modep)
6440     modep = g_slice_new (GdkExtensionMode);
6441   
6442   *modep = mode;
6443   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
6444   g_object_notify (G_OBJECT (widget), "extension-events");
6445 }
6446
6447 /**
6448  * gtk_widget_get_toplevel:
6449  * @widget: a #GtkWidget
6450  * 
6451  * This function returns the topmost widget in the container hierarchy
6452  * @widget is a part of. If @widget has no parent widgets, it will be
6453  * returned as the topmost widget. No reference will be added to the
6454  * returned widget; it should not be unreferenced.
6455  *
6456  * Note the difference in behavior vs. gtk_widget_get_ancestor();
6457  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
6458  * would return
6459  * %NULL if @widget wasn't inside a toplevel window, and if the
6460  * window was inside a #GtkWindow-derived widget which was in turn
6461  * inside the toplevel #GtkWindow. While the second case may
6462  * seem unlikely, it actually happens when a #GtkPlug is embedded
6463  * inside a #GtkSocket within the same application.
6464  * 
6465  * To reliably find the toplevel #GtkWindow, use
6466  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
6467  * is set on the result.
6468  * <informalexample><programlisting>
6469  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6470  *  if (GTK_WIDGET_TOPLEVEL (toplevel))
6471  *    {
6472  *      [ Perform action on toplevel. ]
6473  *    }
6474  * </programlisting></informalexample>
6475  *
6476  * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
6477  **/
6478 GtkWidget*
6479 gtk_widget_get_toplevel (GtkWidget *widget)
6480 {
6481   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6482   
6483   while (widget->parent)
6484     widget = widget->parent;
6485   
6486   return widget;
6487 }
6488
6489 /**
6490  * gtk_widget_get_ancestor:
6491  * @widget: a #GtkWidget
6492  * @widget_type: ancestor type
6493  * 
6494  * Gets the first ancestor of @widget with type @widget_type. For example,
6495  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the 
6496  * first #GtkBox that's
6497  * an ancestor of @widget. No reference will be added to the returned widget;
6498  * it should not be unreferenced. See note about checking for a toplevel
6499  * #GtkWindow in the docs for gtk_widget_get_toplevel().
6500  * 
6501  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
6502  * considers @widget to be an ancestor of itself.
6503  *
6504  * Return value: the ancestor widget, or %NULL if not found
6505  **/
6506 GtkWidget*
6507 gtk_widget_get_ancestor (GtkWidget *widget,
6508                          GType      widget_type)
6509 {
6510   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6511   
6512   while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
6513     widget = widget->parent;
6514   
6515   if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
6516     return NULL;
6517   
6518   return widget;
6519 }
6520
6521 /**
6522  * gtk_widget_get_colormap:
6523  * @widget: a #GtkWidget
6524  * 
6525  * Gets the colormap that will be used to render @widget. No reference will
6526  * be added to the returned colormap; it should not be unreferenced.
6527  * 
6528  * Return value: the colormap used by @widget
6529  **/
6530 GdkColormap*
6531 gtk_widget_get_colormap (GtkWidget *widget)
6532 {
6533   GdkColormap *colormap;
6534   GtkWidget *tmp_widget;
6535   
6536   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6537   
6538   if (widget->window)
6539     {
6540       colormap = gdk_drawable_get_colormap (widget->window);
6541       /* If window was destroyed previously, we'll get NULL here */
6542       if (colormap)
6543         return colormap;
6544     }
6545
6546   tmp_widget = widget;
6547   while (tmp_widget)
6548     {
6549       colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
6550       if (colormap)
6551         return colormap;
6552
6553       tmp_widget= tmp_widget->parent;
6554     }
6555
6556   return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
6557 }
6558
6559 /**
6560  * gtk_widget_get_visual:
6561  * @widget: a #GtkWidget
6562  * 
6563  * Gets the visual that will be used to render @widget.
6564  * 
6565  * Return value: the visual for @widget
6566  **/
6567 GdkVisual*
6568 gtk_widget_get_visual (GtkWidget *widget)
6569 {
6570   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6571
6572   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6573 }
6574
6575 /**
6576  * gtk_widget_get_settings:
6577  * @widget: a #GtkWidget
6578  * 
6579  * Gets the settings object holding the settings (global property
6580  * settings, RC file information, etc) used for this widget.
6581  *
6582  * Note that this function can only be called when the #GtkWidget
6583  * is attached to a toplevel, since the settings object is specific
6584  * to a particular #GdkScreen.
6585  * 
6586  * Return value: the relevant #GtkSettings object
6587  **/
6588 GtkSettings*
6589 gtk_widget_get_settings (GtkWidget *widget)
6590 {
6591   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6592   
6593   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6594 }
6595
6596 /**
6597  * gtk_widget_set_colormap:
6598  * @widget: a #GtkWidget
6599  * @colormap: a colormap
6600  *
6601  * Sets the colormap for the widget to the given value. Widget must not
6602  * have been previously realized. This probably should only be used
6603  * from an <function>init()</function> function (i.e. from the constructor 
6604  * for the widget).
6605  * 
6606  **/
6607 void
6608 gtk_widget_set_colormap (GtkWidget   *widget,
6609                          GdkColormap *colormap)
6610 {
6611   g_return_if_fail (GTK_IS_WIDGET (widget));
6612   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6613   g_return_if_fail (GDK_IS_COLORMAP (colormap));
6614
6615   g_object_ref (colormap);
6616   
6617   g_object_set_qdata_full (G_OBJECT (widget), 
6618                            quark_colormap,
6619                            colormap,
6620                            g_object_unref);
6621 }
6622
6623 /**
6624  * gtk_widget_get_events:
6625  * @widget: a #GtkWidget
6626  * 
6627  * Returns the event mask for the widget (a bitfield containing flags
6628  * from the #GdkEventMask enumeration). These are the events that the widget
6629  * will receive.
6630  * 
6631  * Return value: event mask for @widget
6632  **/
6633 gint
6634 gtk_widget_get_events (GtkWidget *widget)
6635 {
6636   gint *events;
6637   
6638   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6639   
6640   events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6641   if (events)
6642     return *events;
6643   
6644   return 0;
6645 }
6646
6647 /**
6648  * gtk_widget_get_extension_events:
6649  * @widget: a #GtkWidget
6650  * 
6651  * Retrieves the extension events the widget will receive; see
6652  * gdk_input_set_extension_events().
6653  * 
6654  * Return value: extension events for @widget
6655  **/
6656 GdkExtensionMode
6657 gtk_widget_get_extension_events (GtkWidget *widget)
6658 {
6659   GdkExtensionMode *mode;
6660   
6661   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6662   
6663   mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6664   if (mode)
6665     return *mode;
6666   
6667   return 0;
6668 }
6669
6670 /**
6671  * gtk_widget_get_pointer:
6672  * @widget: a #GtkWidget
6673  * @x: return location for the X coordinate, or %NULL
6674  * @y: return location for the Y coordinate, or %NULL
6675  *
6676  * Obtains the location of the mouse pointer in widget coordinates.
6677  * Widget coordinates are a bit odd; for historical reasons, they are
6678  * defined as @widget->window coordinates for widgets that are not
6679  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6680  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6681  * 
6682  **/
6683 void
6684 gtk_widget_get_pointer (GtkWidget *widget,
6685                         gint      *x,
6686                         gint      *y)
6687 {
6688   g_return_if_fail (GTK_IS_WIDGET (widget));
6689   
6690   if (x)
6691     *x = -1;
6692   if (y)
6693     *y = -1;
6694   
6695   if (GTK_WIDGET_REALIZED (widget))
6696     {
6697       gdk_window_get_pointer (widget->window, x, y, NULL);
6698       
6699       if (GTK_WIDGET_NO_WINDOW (widget))
6700         {
6701           if (x)
6702             *x -= widget->allocation.x;
6703           if (y)
6704             *y -= widget->allocation.y;
6705         }
6706     }
6707 }
6708
6709 /**
6710  * gtk_widget_is_ancestor:
6711  * @widget: a #GtkWidget
6712  * @ancestor: another #GtkWidget
6713  * 
6714  * Determines whether @widget is somewhere inside @ancestor, possibly with
6715  * intermediate containers.
6716  * 
6717  * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6718  **/
6719 gboolean
6720 gtk_widget_is_ancestor (GtkWidget *widget,
6721                         GtkWidget *ancestor)
6722 {
6723   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6724   g_return_val_if_fail (ancestor != NULL, FALSE);
6725   
6726   while (widget)
6727     {
6728       if (widget->parent == ancestor)
6729         return TRUE;
6730       widget = widget->parent;
6731     }
6732   
6733   return FALSE;
6734 }
6735
6736 static GQuark quark_composite_name = 0;
6737
6738 /**
6739  * gtk_widget_set_composite_name:
6740  * @widget: a #GtkWidget.
6741  * @name: the name to set.
6742  * 
6743  * Sets a widgets composite name. The widget must be
6744  * a composite child of its parent; see gtk_widget_push_composite_child().
6745  **/
6746 void
6747 gtk_widget_set_composite_name (GtkWidget   *widget,
6748                                const gchar *name)
6749 {
6750   g_return_if_fail (GTK_IS_WIDGET (widget));
6751   g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6752   g_return_if_fail (name != NULL);
6753
6754   if (!quark_composite_name)
6755     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6756
6757   g_object_set_qdata_full (G_OBJECT (widget),
6758                            quark_composite_name,
6759                            g_strdup (name),
6760                            g_free);
6761 }
6762
6763 /**
6764  * gtk_widget_get_composite_name:
6765  * @widget: a #GtkWidget.
6766  * @returns: the composite name of @widget, or %NULL if @widget is not
6767  *   a composite child. The string should not be freed when it is no 
6768  *   longer needed.
6769  *
6770  * Obtains the composite name of a widget. 
6771  **/
6772 gchar*
6773 gtk_widget_get_composite_name (GtkWidget *widget)
6774 {
6775   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6776
6777   if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6778     return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6779                                                widget);
6780   else
6781     return NULL;
6782 }
6783
6784 /**
6785  * gtk_widget_push_composite_child:
6786  * 
6787  * Makes all newly-created widgets as composite children until
6788  * the corresponding gtk_widget_pop_composite_child() call.
6789  * 
6790  * A composite child is a child that's an implementation detail of the
6791  * container it's inside and should not be visible to people using the
6792  * container. Composite children aren't treated differently by GTK (but
6793  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
6794  * builders might want to treat them in a different way.
6795  * 
6796  * Here is a simple example:
6797  * <informalexample><programlisting>
6798  *   gtk_widget_push_composite_child (<!-- -->);
6799  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6800  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6801  *   gtk_widget_pop_composite_child (<!-- -->);
6802  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
6803  *                          GTK_WIDGET (scrolled_window));
6804  *   g_object_ref (scrolled_window->hscrollbar);
6805  * </programlisting></informalexample>
6806  **/
6807 void
6808 gtk_widget_push_composite_child (void)
6809 {
6810   composite_child_stack++;
6811 }
6812
6813 /**
6814  * gtk_widget_pop_composite_child:
6815  *
6816  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6817  **/ 
6818 void
6819 gtk_widget_pop_composite_child (void)
6820 {
6821   if (composite_child_stack)
6822     composite_child_stack--;
6823 }
6824
6825 /**
6826  * gtk_widget_push_colormap:
6827  * @cmap: a #GdkColormap
6828  *
6829  * Pushes @cmap onto a global stack of colormaps; the topmost
6830  * colormap on the stack will be used to create all widgets.
6831  * Remove @cmap with gtk_widget_pop_colormap(). There's little
6832  * reason to use this function.
6833  * 
6834  **/
6835 void
6836 gtk_widget_push_colormap (GdkColormap *cmap)
6837 {
6838   g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6839
6840   colormap_stack = g_slist_prepend (colormap_stack, cmap);
6841 }
6842
6843 /**
6844  * gtk_widget_pop_colormap:
6845  *
6846  * Removes a colormap pushed with gtk_widget_push_colormap().
6847  * 
6848  **/
6849 void
6850 gtk_widget_pop_colormap (void)
6851 {
6852   if (colormap_stack)
6853     colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6854 }
6855
6856 /**
6857  * gtk_widget_set_default_colormap:
6858  * @colormap: a #GdkColormap
6859  * 
6860  * Sets the default colormap to use when creating widgets.
6861  * gtk_widget_push_colormap() is a better function to use if
6862  * you only want to affect a few widgets, rather than all widgets.
6863  **/
6864 void
6865 gtk_widget_set_default_colormap (GdkColormap *colormap)
6866 {
6867   g_return_if_fail (GDK_IS_COLORMAP (colormap));
6868   
6869   gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6870                                    colormap);
6871 }
6872
6873 /**
6874  * gtk_widget_get_default_colormap:
6875  * 
6876  * Obtains the default colormap used to create widgets.
6877  * 
6878  * Return value: default widget colormap
6879  **/
6880 GdkColormap*
6881 gtk_widget_get_default_colormap (void)
6882 {
6883   return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6884 }
6885
6886 /**
6887  * gtk_widget_get_default_visual:
6888  * 
6889  * Obtains the visual of the default colormap. Not really useful;
6890  * used to be useful before gdk_colormap_get_visual() existed.
6891  * 
6892  * Return value: visual of the default colormap
6893  **/
6894 GdkVisual*
6895 gtk_widget_get_default_visual (void)
6896 {
6897   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6898 }
6899
6900 static void
6901 gtk_widget_emit_direction_changed (GtkWidget        *widget,
6902                                    GtkTextDirection  old_dir)
6903 {
6904   gtk_widget_update_pango_context (widget);
6905   
6906   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6907 }
6908
6909 /**
6910  * gtk_widget_set_direction:
6911  * @widget: a #GtkWidget
6912  * @dir:    the new direction
6913  * 
6914  * Sets the reading direction on a particular widget. This direction
6915  * controls the primary direction for widgets containing text,
6916  * and also the direction in which the children of a container are
6917  * packed. The ability to set the direction is present in order
6918  * so that correct localization into languages with right-to-left
6919  * reading directions can be done. Generally, applications will
6920  * let the default reading direction present, except for containers
6921  * where the containers are arranged in an order that is explicitely
6922  * visual rather than logical (such as buttons for text justification).
6923  *
6924  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6925  * set by gtk_widget_set_default_direction() will be used.
6926  **/
6927 void
6928 gtk_widget_set_direction (GtkWidget        *widget,
6929                           GtkTextDirection  dir)
6930 {
6931   GtkTextDirection old_dir;
6932   
6933   g_return_if_fail (GTK_IS_WIDGET (widget));
6934   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6935
6936   old_dir = gtk_widget_get_direction (widget);
6937   
6938   if (dir == GTK_TEXT_DIR_NONE)
6939     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6940   else
6941     {
6942       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6943       if (dir == GTK_TEXT_DIR_LTR)
6944         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6945       else
6946         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6947     }
6948
6949   if (old_dir != gtk_widget_get_direction (widget))
6950     gtk_widget_emit_direction_changed (widget, old_dir);
6951 }
6952
6953 /**
6954  * gtk_widget_get_direction:
6955  * @widget: a #GtkWidget
6956  * 
6957  * Gets the reading direction for a particular widget. See
6958  * gtk_widget_set_direction().
6959  * 
6960  * Return value: the reading direction for the widget.
6961  **/
6962 GtkTextDirection
6963 gtk_widget_get_direction (GtkWidget *widget)
6964 {
6965   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6966   
6967   if (GTK_WIDGET_DIRECTION_SET (widget))
6968     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6969   else
6970     return gtk_default_direction;
6971 }
6972
6973 static void
6974 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6975 {
6976   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6977
6978   g_object_ref (widget);
6979   
6980   if (!GTK_WIDGET_DIRECTION_SET (widget))
6981     gtk_widget_emit_direction_changed (widget, old_dir);
6982   
6983   if (GTK_IS_CONTAINER (widget))
6984     gtk_container_forall (GTK_CONTAINER (widget),
6985                           gtk_widget_set_default_direction_recurse,
6986                           data);
6987
6988   g_object_unref (widget);
6989 }
6990
6991 /**
6992  * gtk_widget_set_default_direction:
6993  * @dir: the new default direction. This cannot be
6994  *        %GTK_TEXT_DIR_NONE.
6995  * 
6996  * Sets the default reading direction for widgets where the
6997  * direction has not been explicitly set by gtk_widget_set_direction().
6998  **/
6999 void
7000 gtk_widget_set_default_direction (GtkTextDirection dir)
7001 {
7002   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7003
7004   if (dir != gtk_default_direction)
7005     {
7006       GList *toplevels, *tmp_list;
7007       GtkTextDirection old_dir = gtk_default_direction;
7008       
7009       gtk_default_direction = dir;
7010
7011       tmp_list = toplevels = gtk_window_list_toplevels ();
7012       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7013       
7014       while (tmp_list)
7015         {
7016           gtk_widget_set_default_direction_recurse (tmp_list->data,
7017                                                     GUINT_TO_POINTER (old_dir));
7018           g_object_unref (tmp_list->data);
7019           tmp_list = tmp_list->next;
7020         }
7021
7022       g_list_free (toplevels);
7023     }
7024 }
7025
7026 /**
7027  * gtk_widget_get_default_direction:
7028  * 
7029  * Obtains the current default reading direction. See
7030  * gtk_widget_set_default_direction().
7031  *
7032  * Return value: the current default direction. 
7033  **/
7034 GtkTextDirection
7035 gtk_widget_get_default_direction (void)
7036 {
7037   return gtk_default_direction;
7038 }
7039
7040 static void
7041 gtk_widget_dispose (GObject *object)
7042 {
7043   GtkWidget *widget = GTK_WIDGET (object);
7044
7045   if (widget->parent)
7046     gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7047   else if (GTK_WIDGET_VISIBLE (widget))
7048     gtk_widget_hide (widget);
7049
7050   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7051   if (GTK_WIDGET_REALIZED (widget))
7052     gtk_widget_unrealize (widget);
7053   
7054   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7055 }
7056
7057 static void
7058 gtk_widget_real_destroy (GtkObject *object)
7059 {
7060   /* gtk_object_destroy() will already hold a refcount on object */
7061   GtkWidget *widget = GTK_WIDGET (object);
7062
7063   /* wipe accelerator closures (keep order) */
7064   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7065   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7066
7067   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7068   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7069   
7070   gtk_grab_remove (widget);
7071   
7072   g_object_unref (widget->style);
7073   widget->style = gtk_widget_get_default_style ();
7074   g_object_ref (widget->style);
7075
7076   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7077 }
7078
7079 static void
7080 gtk_widget_finalize (GObject *object)
7081 {
7082   GtkWidget *widget = GTK_WIDGET (object);
7083   GtkWidgetAuxInfo *aux_info;
7084   gint *events;
7085   GdkExtensionMode *mode;
7086   GtkAccessible *accessible;
7087   
7088   gtk_grab_remove (widget);
7089
7090   g_object_unref (widget->style);
7091   widget->style = NULL;
7092
7093   if (widget->name)
7094     g_free (widget->name);
7095   
7096   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7097   if (aux_info)
7098     gtk_widget_aux_info_destroy (aux_info);
7099   
7100   events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
7101   if (events)
7102     g_slice_free (gint, events);
7103   
7104   mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
7105   if (mode)
7106     g_slice_free (GdkExtensionMode, mode);
7107
7108   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7109   if (accessible)
7110     g_object_unref (accessible);
7111
7112   G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7113 }
7114
7115 /*****************************************
7116  * gtk_widget_real_map:
7117  *
7118  *   arguments:
7119  *
7120  *   results:
7121  *****************************************/
7122
7123 static void
7124 gtk_widget_real_map (GtkWidget *widget)
7125 {
7126   g_assert (GTK_WIDGET_REALIZED (widget));
7127   
7128   if (!GTK_WIDGET_MAPPED (widget))
7129     {
7130       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7131       
7132       if (!GTK_WIDGET_NO_WINDOW (widget))
7133         gdk_window_show (widget->window);
7134     }
7135 }
7136
7137 /*****************************************
7138  * gtk_widget_real_unmap:
7139  *
7140  *   arguments:
7141  *
7142  *   results:
7143  *****************************************/
7144
7145 static void
7146 gtk_widget_real_unmap (GtkWidget *widget)
7147 {
7148   if (GTK_WIDGET_MAPPED (widget))
7149     {
7150       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7151
7152       if (!GTK_WIDGET_NO_WINDOW (widget))
7153         gdk_window_hide (widget->window);
7154     }
7155 }
7156
7157 /*****************************************
7158  * gtk_widget_real_realize:
7159  *
7160  *   arguments:
7161  *
7162  *   results:
7163  *****************************************/
7164
7165 static void
7166 gtk_widget_real_realize (GtkWidget *widget)
7167 {
7168   g_assert (GTK_WIDGET_NO_WINDOW (widget));
7169   
7170   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7171   if (widget->parent)
7172     {
7173       widget->window = gtk_widget_get_parent_window (widget);
7174       g_object_ref (widget->window);
7175     }
7176   widget->style = gtk_style_attach (widget->style, widget->window);
7177 }
7178
7179 /*****************************************
7180  * gtk_widget_real_unrealize:
7181  *
7182  *   arguments:
7183  *
7184  *   results:
7185  *****************************************/
7186
7187 static void
7188 gtk_widget_real_unrealize (GtkWidget *widget)
7189 {
7190   if (GTK_WIDGET_MAPPED (widget))
7191     gtk_widget_real_unmap (widget);
7192
7193   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7194
7195   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
7196    */
7197
7198    /* We must do unrealize child widget BEFORE container widget.
7199     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
7200     * So, unrealizing container widget bofore its children causes the problem 
7201     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
7202     */
7203
7204   if (GTK_IS_CONTAINER (widget))
7205     gtk_container_forall (GTK_CONTAINER (widget),
7206                           (GtkCallback) gtk_widget_unrealize,
7207                           NULL);
7208
7209   gtk_style_detach (widget->style);
7210   if (!GTK_WIDGET_NO_WINDOW (widget))
7211     {
7212       gdk_window_set_user_data (widget->window, NULL);
7213       gdk_window_destroy (widget->window);
7214       widget->window = NULL;
7215     }
7216   else
7217     {
7218       g_object_unref (widget->window);
7219       widget->window = NULL;
7220     }
7221
7222   gtk_selection_remove_all (widget);
7223   
7224   GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
7225 }
7226
7227 static void
7228 gtk_widget_real_size_request (GtkWidget         *widget,
7229                               GtkRequisition    *requisition)
7230 {
7231   requisition->width = widget->requisition.width;
7232   requisition->height = widget->requisition.height;
7233 }
7234
7235 /**
7236  * _gtk_widget_peek_colormap:
7237  * 
7238  * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
7239  * 
7240  * Return value: the currently pushed colormap, or %NULL if there is none.
7241  **/
7242 GdkColormap*
7243 _gtk_widget_peek_colormap (void)
7244 {
7245   if (colormap_stack)
7246     return (GdkColormap*) colormap_stack->data;
7247   return NULL;
7248 }
7249
7250 static void
7251 gtk_widget_propagate_state (GtkWidget           *widget,
7252                             GtkStateData        *data)
7253 {
7254   guint8 old_state;
7255
7256   /* don't call this function with state==GTK_STATE_INSENSITIVE,
7257    * parent_sensitive==TRUE on a sensitive widget
7258    */
7259
7260   old_state = GTK_WIDGET_STATE (widget);
7261
7262   if (data->parent_sensitive)
7263     {
7264       GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
7265
7266       if (GTK_WIDGET_IS_SENSITIVE (widget))
7267         {
7268           if (data->state_restoration)
7269             GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
7270           else
7271             GTK_WIDGET_STATE (widget) = data->state;
7272         }
7273       else
7274         {
7275           GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
7276           if (!data->state_restoration &&
7277               data->state != GTK_STATE_INSENSITIVE)
7278             GTK_WIDGET_SAVED_STATE (widget) = data->state;
7279         }
7280     }
7281   else
7282     {
7283       GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
7284       if (!data->state_restoration)
7285         {
7286           if (data->state != GTK_STATE_INSENSITIVE)
7287             GTK_WIDGET_SAVED_STATE (widget) = data->state;
7288         }
7289       else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
7290         GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
7291       GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
7292     }
7293
7294   if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
7295     {
7296       GtkWidget *window;
7297
7298       window = gtk_widget_get_toplevel (widget);
7299       if (window && GTK_WIDGET_TOPLEVEL (window))
7300         gtk_window_set_focus (GTK_WINDOW (window), NULL);
7301     }
7302
7303   if (old_state != GTK_WIDGET_STATE (widget))
7304     {
7305       g_object_ref (widget);
7306       
7307       if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
7308         gtk_grab_remove (widget);
7309       
7310       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
7311       
7312       if (GTK_IS_CONTAINER (widget))
7313         {
7314           data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
7315           data->state = GTK_WIDGET_STATE (widget);
7316           if (data->use_forall)
7317             gtk_container_forall (GTK_CONTAINER (widget),
7318                                   (GtkCallback) gtk_widget_propagate_state,
7319                                   data);
7320           else
7321             gtk_container_foreach (GTK_CONTAINER (widget),
7322                                    (GtkCallback) gtk_widget_propagate_state,
7323                                    data);
7324         }
7325       g_object_unref (widget);
7326     }
7327 }
7328
7329 /**
7330  * _gtk_widget_get_aux_info:
7331  * @widget: a #GtkWidget
7332  * @create: if %TRUE, create the structure if it doesn't exist
7333  * 
7334  * Get the #GtkWidgetAuxInfo structure for the widget.
7335  * 
7336  * Return value: the #GtkAuxInfo structure for the widget, or
7337  *    %NULL if @create is %FALSE and one doesn't already exist.
7338  **/
7339 GtkWidgetAuxInfo*
7340 _gtk_widget_get_aux_info (GtkWidget *widget,
7341                           gboolean   create)
7342 {
7343   GtkWidgetAuxInfo *aux_info;
7344   
7345   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
7346   if (!aux_info && create)
7347     {
7348       aux_info = g_slice_new (GtkWidgetAuxInfo);
7349
7350       aux_info->width = -1;
7351       aux_info->height = -1;
7352       aux_info->x = 0;
7353       aux_info->y = 0;
7354       aux_info->x_set = FALSE;
7355       aux_info->y_set = FALSE;
7356       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
7357     }
7358   
7359   return aux_info;
7360 }
7361
7362 /*****************************************
7363  * gtk_widget_aux_info_destroy:
7364  *
7365  *   arguments:
7366  *
7367  *   results:
7368  *****************************************/
7369
7370 static void
7371 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
7372 {
7373   g_slice_free (GtkWidgetAuxInfo, aux_info);
7374 }
7375
7376 static void
7377 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
7378 {
7379   g_object_unref (info->shape_mask);
7380   g_slice_free (GtkWidgetShapeInfo, info);
7381 }
7382
7383 /**
7384  * gtk_widget_shape_combine_mask: 
7385  * @widget: a #GtkWidget.
7386  * @shape_mask: shape to be added, or %NULL to remove an existing shape. 
7387  * @offset_x: X position of shape mask with respect to @window.
7388  * @offset_y: Y position of shape mask with respect to @window.
7389  * 
7390  * Sets a shape for this widget's GDK window. This allows for
7391  * transparent windows etc., see gdk_window_shape_combine_mask()
7392  * for more information.
7393  **/
7394 void
7395 gtk_widget_shape_combine_mask (GtkWidget *widget,
7396                                GdkBitmap *shape_mask,
7397                                gint       offset_x,
7398                                gint       offset_y)
7399 {
7400   GtkWidgetShapeInfo* shape_info;
7401   
7402   g_return_if_fail (GTK_IS_WIDGET (widget));
7403   /*  set_shape doesn't work on widgets without gdk window */
7404   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7405
7406   if (!shape_mask)
7407     {
7408       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7409       
7410       if (widget->window)
7411         gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
7412       
7413       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
7414     }
7415   else
7416     {
7417       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
7418       
7419       shape_info = g_slice_new (GtkWidgetShapeInfo);
7420       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
7421                                (GDestroyNotify) gtk_widget_shape_info_destroy);
7422       
7423       shape_info->shape_mask = g_object_ref (shape_mask);
7424       shape_info->offset_x = offset_x;
7425       shape_info->offset_y = offset_y;
7426       
7427       /* set shape if widget has a gdk window already.
7428        * otherwise the shape is scheduled to be set by gtk_widget_realize().
7429        */
7430       if (widget->window)
7431         gdk_window_shape_combine_mask (widget->window, shape_mask,
7432                                        offset_x, offset_y);
7433     }
7434 }
7435
7436 /**
7437  * gtk_widget_input_shape_combine_mask: 
7438  * @widget: a #GtkWidget.
7439  * @shape_mask: shape to be added, or %NULL to remove an existing shape. 
7440  * @offset_x: X position of shape mask with respect to @window.
7441  * @offset_y: Y position of shape mask with respect to @window.
7442  * 
7443  * Sets an input shape for this widget's GDK window. This allows for
7444  * windows which react to mouse click in a nonrectangular region, see 
7445  * gdk_window_input_shape_combine_mask() for more information.
7446  *
7447  * Since: 2.10
7448  **/
7449 void
7450 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
7451                                      GdkBitmap *shape_mask,
7452                                      gint       offset_x,
7453                                      gint       offset_y)
7454 {
7455   GtkWidgetShapeInfo* shape_info;
7456   
7457   g_return_if_fail (GTK_IS_WIDGET (widget));
7458   /*  set_shape doesn't work on widgets without gdk window */
7459   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
7460
7461   if (!shape_mask)
7462     {
7463       if (widget->window)
7464         gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
7465       
7466       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
7467     }
7468   else
7469     {
7470       shape_info = g_slice_new (GtkWidgetShapeInfo);
7471       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
7472                                shape_info,
7473                                (GDestroyNotify) gtk_widget_shape_info_destroy);
7474       
7475       shape_info->shape_mask = g_object_ref (shape_mask);
7476       shape_info->offset_x = offset_x;
7477       shape_info->offset_y = offset_y;
7478       
7479       /* set shape if widget has a gdk window already.
7480        * otherwise the shape is scheduled to be set by gtk_widget_realize().
7481        */
7482       if (widget->window)
7483         gdk_window_input_shape_combine_mask (widget->window, shape_mask,
7484                                              offset_x, offset_y);
7485     }
7486 }
7487
7488
7489 static void
7490 gtk_reset_shapes_recurse (GtkWidget *widget,
7491                           GdkWindow *window)
7492 {
7493   gpointer data;
7494   GList *list;
7495
7496   gdk_window_get_user_data (window, &data);
7497   if (data != widget)
7498     return;
7499
7500   gdk_window_shape_combine_mask (window, NULL, 0, 0);
7501   for (list = gdk_window_peek_children (window); list; list = list->next)
7502     gtk_reset_shapes_recurse (widget, list->data);
7503 }
7504
7505 /**
7506  * gtk_widget_reset_shapes:
7507  * @widget: a #GtkWidget.
7508  *
7509  * Recursively resets the shape on this widget and its descendants.
7510  **/
7511 void
7512 gtk_widget_reset_shapes (GtkWidget *widget)
7513 {
7514   g_return_if_fail (GTK_IS_WIDGET (widget));
7515   g_return_if_fail (GTK_WIDGET_REALIZED (widget));
7516
7517   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
7518     gtk_reset_shapes_recurse (widget, widget->window);
7519 }
7520
7521 /**
7522  * gtk_widget_ref:
7523  * @widget: a #GtkWidget
7524  * 
7525  * Adds a reference to a widget. This function is exactly the same
7526  * as calling g_object_ref(), and exists mostly for historical
7527  * reasons. It can still be convenient to avoid casting a widget
7528  * to a #GObject, it saves a small amount of typing.
7529  * 
7530  * Return value: the widget that was referenced
7531  **/
7532 GtkWidget*
7533 gtk_widget_ref (GtkWidget *widget)
7534 {
7535   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7536
7537   return (GtkWidget*) g_object_ref ((GObject*) widget);
7538 }
7539
7540 /**
7541  * gtk_widget_unref:
7542  * @widget: a #GtkWidget
7543  *
7544  * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
7545  * 
7546  **/
7547 void
7548 gtk_widget_unref (GtkWidget *widget)
7549 {
7550   g_return_if_fail (GTK_IS_WIDGET (widget));
7551
7552   g_object_unref ((GObject*) widget);
7553 }
7554
7555
7556 /* style properties
7557  */
7558
7559 /**
7560  * gtk_widget_class_install_style_property_parser:
7561  * @klass: a #GtkWidgetClass
7562  * @pspec: the #GParamSpec for the style property
7563  * @parser: the parser for the style property
7564  * 
7565  * Installs a style property on a widget class. 
7566  **/
7567 void
7568 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
7569                                                 GParamSpec         *pspec,
7570                                                 GtkRcPropertyParser parser)
7571 {
7572   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7573   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7574   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
7575   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
7576   
7577   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
7578     {
7579       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
7580                  G_OBJECT_CLASS_NAME (klass),
7581                  pspec->name);
7582       return;
7583     }
7584
7585   g_param_spec_ref_sink (pspec);
7586   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
7587   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
7588 }
7589
7590 /**
7591  * gtk_widget_class_install_style_property:
7592  * @klass: a #GtkWidgetClass
7593  * @pspec: the #GParamSpec for the property
7594  * 
7595  * Installs a style property on a widget class. The parser for the
7596  * style property is determined by the value type of @pspec.
7597  **/
7598 void
7599 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
7600                                          GParamSpec     *pspec)
7601 {
7602   GtkRcPropertyParser parser;
7603
7604   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
7605   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
7606
7607   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
7608
7609   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
7610 }
7611
7612 /**
7613  * gtk_widget_class_find_style_property:
7614  * @klass: a #GtkWidgetClass
7615  * @property_name: the name of the style property to find
7616  * @returns: the #GParamSpec of the style property or %NULL if @class has no
7617  *   style property with that name.
7618  *
7619  * Finds a style property of a widget class by name.
7620  *
7621  * Since: 2.2
7622  */
7623 GParamSpec*
7624 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7625                                       const gchar    *property_name)
7626 {
7627   g_return_val_if_fail (property_name != NULL, NULL);
7628
7629   return g_param_spec_pool_lookup (style_property_spec_pool,
7630                                    property_name,
7631                                    G_OBJECT_CLASS_TYPE (klass),
7632                                    TRUE);
7633 }
7634
7635 /**
7636  * gtk_widget_class_list_style_properties:
7637  * @klass: a #GtkWidgetClass
7638  * @n_properties: location to return the number of style properties found
7639  * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7640  *
7641  * Returns all style properties of a widget class.
7642  *
7643  * Since: 2.2
7644  */
7645 GParamSpec**
7646 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7647                                         guint          *n_properties)
7648 {
7649   GParamSpec **pspecs;
7650   guint n;
7651
7652   pspecs = g_param_spec_pool_list (style_property_spec_pool,
7653                                    G_OBJECT_CLASS_TYPE (klass),
7654                                    &n);
7655   if (n_properties)
7656     *n_properties = n;
7657
7658   return pspecs;
7659 }
7660
7661 /**
7662  * gtk_widget_style_get_property:
7663  * @widget: a #GtkWidget
7664  * @property_name: the name of a style property
7665  * @value: location to return the property value 
7666  *
7667  * Gets the value of a style property of @widget.
7668  */
7669 void
7670 gtk_widget_style_get_property (GtkWidget   *widget,
7671                                const gchar *property_name,
7672                                GValue      *value)
7673 {
7674   GParamSpec *pspec;
7675
7676   g_return_if_fail (GTK_IS_WIDGET (widget));
7677   g_return_if_fail (property_name != NULL);
7678   g_return_if_fail (G_IS_VALUE (value));
7679
7680   g_object_ref (widget);
7681   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7682                                     property_name,
7683                                     G_OBJECT_TYPE (widget),
7684                                     TRUE);
7685   if (!pspec)
7686     g_warning ("%s: widget class `%s' has no property named `%s'",
7687                G_STRLOC,
7688                G_OBJECT_TYPE_NAME (widget),
7689                property_name);
7690   else
7691     {
7692       const GValue *peek_value;
7693
7694       peek_value = _gtk_style_peek_property_value (widget->style,
7695                                                    G_OBJECT_TYPE (widget),
7696                                                    pspec,
7697                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7698       
7699       /* auto-conversion of the caller's value type
7700        */
7701       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7702         g_value_copy (peek_value, value);
7703       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7704         g_value_transform (peek_value, value);
7705       else
7706         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7707                    pspec->name,
7708                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7709                    G_VALUE_TYPE_NAME (value));
7710     }
7711   g_object_unref (widget);
7712 }
7713
7714 /**
7715  * gtk_widget_style_get_valist:
7716  * @widget: a #GtkWidget
7717  * @first_property_name: the name of the first property to get
7718  * @var_args: a <type>va_list</type> of pairs of property names and
7719  *     locations to return the property values, starting with the location
7720  *     for @first_property_name.
7721  * 
7722  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
7723  * bindings.
7724  */ 
7725 void
7726 gtk_widget_style_get_valist (GtkWidget   *widget,
7727                              const gchar *first_property_name,
7728                              va_list      var_args)
7729 {
7730   const gchar *name;
7731
7732   g_return_if_fail (GTK_IS_WIDGET (widget));
7733
7734   g_object_ref (widget);
7735
7736   name = first_property_name;
7737   while (name)
7738     {
7739       const GValue *peek_value;
7740       GParamSpec *pspec;
7741       gchar *error;
7742
7743       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7744                                         name,
7745                                         G_OBJECT_TYPE (widget),
7746                                         TRUE);
7747       if (!pspec)
7748         {
7749           g_warning ("%s: widget class `%s' has no property named `%s'",
7750                      G_STRLOC,
7751                      G_OBJECT_TYPE_NAME (widget),
7752                      name);
7753           break;
7754         }
7755       /* style pspecs are always readable so we can spare that check here */
7756
7757       peek_value = _gtk_style_peek_property_value (widget->style,
7758                                                    G_OBJECT_TYPE (widget),
7759                                                    pspec,
7760                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7761       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7762       if (error)
7763         {
7764           g_warning ("%s: %s", G_STRLOC, error);
7765           g_free (error);
7766           break;
7767         }
7768
7769       name = va_arg (var_args, gchar*);
7770     }
7771
7772   g_object_unref (widget);
7773 }
7774
7775 /**
7776  * gtk_widget_style_get:
7777  * @widget: a #GtkWidget
7778  * @first_property_name: the name of the first property to get
7779  * @Varargs: pairs of property names and locations to 
7780  *   return the property values, starting with the location for 
7781  *   @first_property_name, terminated by %NULL.
7782  *
7783  * Gets the values of a multiple style properties of @widget.
7784  */
7785 void
7786 gtk_widget_style_get (GtkWidget   *widget,
7787                       const gchar *first_property_name,
7788                       ...)
7789 {
7790   va_list var_args;
7791
7792   g_return_if_fail (GTK_IS_WIDGET (widget));
7793
7794   va_start (var_args, first_property_name);
7795   gtk_widget_style_get_valist (widget, first_property_name, var_args);
7796   va_end (var_args);
7797 }
7798
7799 /**
7800  * gtk_widget_path:
7801  * @widget: a #GtkWidget
7802  * @path_length: location to store length of the path, or %NULL
7803  * @path: location to store allocated path string, or %NULL 
7804  * @path_reversed: location to store allocated reverse path string, or %NULL
7805  *
7806  * Obtains the full path to @widget. The path is simply the name of a
7807  * widget and all its parents in the container hierarchy, separated by
7808  * periods. The name of a widget comes from
7809  * gtk_widget_get_name(). Paths are used to apply styles to a widget
7810  * in gtkrc configuration files.  Widget names are the type of the
7811  * widget by default (e.g. "GtkButton") or can be set to an
7812  * application-specific value with gtk_widget_set_name().  By setting
7813  * the name of a widget, you allow users or theme authors to apply
7814  * styles to that specific widget in their gtkrc
7815  * file. @path_reversed_p fills in the path in reverse order,
7816  * i.e. starting with @widget's name instead of starting with the name
7817  * of @widget's outermost ancestor.
7818  * 
7819  **/
7820 void
7821 gtk_widget_path (GtkWidget *widget,
7822                  guint     *path_length,
7823                  gchar    **path,
7824                  gchar    **path_reversed)
7825 {
7826   static gchar *rev_path = NULL;
7827   static guint tmp_path_len = 0;
7828   guint len;
7829   
7830   g_return_if_fail (GTK_IS_WIDGET (widget));
7831   
7832   len = 0;
7833   do
7834     {
7835       const gchar *string;
7836       const gchar *s;
7837       gchar *d;
7838       guint l;
7839       
7840       string = gtk_widget_get_name (widget);
7841       l = strlen (string);
7842       while (tmp_path_len <= len + l + 1)
7843         {
7844           tmp_path_len += INIT_PATH_SIZE;
7845           rev_path = g_realloc (rev_path, tmp_path_len);
7846         }
7847       s = string + l - 1;
7848       d = rev_path + len;
7849       while (s >= string)
7850         *(d++) = *(s--);
7851       len += l;
7852       
7853       widget = widget->parent;
7854       
7855       if (widget)
7856         rev_path[len++] = '.';
7857       else
7858         rev_path[len++] = 0;
7859     }
7860   while (widget);
7861   
7862   if (path_length)
7863     *path_length = len - 1;
7864   if (path_reversed)
7865     *path_reversed = g_strdup (rev_path);
7866   if (path)
7867     {
7868       *path = g_strdup (rev_path);
7869       g_strreverse (*path);
7870     }
7871 }
7872
7873 /**
7874  * gtk_widget_class_path:
7875  * @widget: a #GtkWidget
7876  * @path_length: location to store the length of the class path, or %NULL
7877  * @path: location to store the class path as an allocated string, or %NULL
7878  * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7879  *
7880  * Same as gtk_widget_path(), but always uses the name of a widget's type,
7881  * never uses a custom name set with gtk_widget_set_name().
7882  * 
7883  **/
7884 void
7885 gtk_widget_class_path (GtkWidget *widget,
7886                        guint     *path_length,
7887                        gchar    **path,
7888                        gchar    **path_reversed)
7889 {
7890   static gchar *rev_path = NULL;
7891   static guint tmp_path_len = 0;
7892   guint len;
7893   
7894   g_return_if_fail (GTK_IS_WIDGET (widget));
7895   
7896   len = 0;
7897   do
7898     {
7899       const gchar *string;
7900       const gchar *s;
7901       gchar *d;
7902       guint l;
7903       
7904       string = g_type_name (GTK_WIDGET_TYPE (widget));
7905       l = strlen (string);
7906       while (tmp_path_len <= len + l + 1)
7907         {
7908           tmp_path_len += INIT_PATH_SIZE;
7909           rev_path = g_realloc (rev_path, tmp_path_len);
7910         }
7911       s = string + l - 1;
7912       d = rev_path + len;
7913       while (s >= string)
7914         *(d++) = *(s--);
7915       len += l;
7916       
7917       widget = widget->parent;
7918       
7919       if (widget)
7920         rev_path[len++] = '.';
7921       else
7922         rev_path[len++] = 0;
7923     }
7924   while (widget);
7925   
7926   if (path_length)
7927     *path_length = len - 1;
7928   if (path_reversed)
7929     *path_reversed = g_strdup (rev_path);
7930   if (path)
7931     {
7932       *path = g_strdup (rev_path);
7933       g_strreverse (*path);
7934     }
7935 }
7936
7937 /**
7938  * gtk_requisition_copy:
7939  * @requisition: a #GtkRequisition.
7940  * @returns: a copy of @requisition.
7941  *
7942  * Copies a #GtkRequisition.
7943  **/
7944 GtkRequisition *
7945 gtk_requisition_copy (const GtkRequisition *requisition)
7946 {
7947   return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7948 }
7949
7950 /**
7951  * gtk_requisition_free:
7952  * @requisition: a #GtkRequisition.
7953  * 
7954  * Frees a #GtkRequisition.
7955  **/
7956 void
7957 gtk_requisition_free (GtkRequisition *requisition)
7958 {
7959   g_free (requisition);
7960 }
7961
7962 GType
7963 gtk_requisition_get_type (void)
7964 {
7965   static GType our_type = 0;
7966   
7967   if (our_type == 0)
7968     our_type = g_boxed_type_register_static (I_("GtkRequisition"),
7969                                              (GBoxedCopyFunc) gtk_requisition_copy,
7970                                              (GBoxedFreeFunc) gtk_requisition_free);
7971
7972   return our_type;
7973 }
7974
7975 /**
7976  * gtk_widget_get_accessible:
7977  * @widget: a #GtkWidget
7978  *
7979  * Returns the accessible object that describes the widget to an
7980  * assistive technology. 
7981  * 
7982  * If no accessibility library is loaded (i.e. no ATK implementation library is 
7983  * loaded via <envar>GTK_MODULES</envar> or via another application library, 
7984  * such as libgnome), then this #AtkObject instance may be a no-op. Likewise, 
7985  * if no class-specific #AtkObject implementation is available for the widget 
7986  * instance in question, it will inherit an #AtkObject implementation from the 
7987  * first ancestor class for which such an implementation is defined.
7988  *
7989  * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7990  * library contains more information about accessible objects and their uses.
7991  * 
7992  * Returns: the #AtkObject associated with @widget
7993  */
7994 AtkObject* 
7995 gtk_widget_get_accessible (GtkWidget *widget)
7996 {
7997   GtkWidgetClass *klass;
7998
7999   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8000
8001   klass = GTK_WIDGET_GET_CLASS (widget);
8002
8003   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
8004
8005   return klass->get_accessible (widget);
8006 }
8007
8008 static AtkObject* 
8009 gtk_widget_real_get_accessible (GtkWidget *widget)
8010 {
8011   AtkObject* accessible;
8012
8013   accessible = g_object_get_qdata (G_OBJECT (widget), 
8014                                    quark_accessible_object);
8015   if (!accessible)
8016   {
8017     AtkObjectFactory *factory;
8018     AtkRegistry *default_registry;
8019
8020     default_registry = atk_get_default_registry ();
8021     factory = atk_registry_get_factory (default_registry, 
8022                                         G_TYPE_FROM_INSTANCE (widget));
8023     accessible =
8024       atk_object_factory_create_accessible (factory,
8025                                             G_OBJECT (widget));
8026     g_object_set_qdata (G_OBJECT (widget), 
8027                         quark_accessible_object,
8028                         accessible);
8029   }
8030   return accessible;
8031 }
8032
8033 /*
8034  * Initialize a AtkImplementorIface instance's virtual pointers as
8035  * appropriate to this implementor's class (GtkWidget).
8036  */
8037 static void
8038 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
8039 {
8040   iface->ref_accessible = gtk_widget_ref_accessible;
8041 }
8042
8043 static AtkObject*
8044 gtk_widget_ref_accessible (AtkImplementor *implementor)
8045 {
8046   AtkObject *accessible;
8047
8048   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
8049   if (accessible)
8050     g_object_ref (accessible);
8051   return accessible;
8052 }
8053
8054 /**
8055  * gtk_widget_get_clipboard:
8056  * @widget: a #GtkWidget
8057  * @selection: a #GdkAtom which identifies the clipboard
8058  *             to use. %GDK_SELECTION_CLIPBOARD gives the
8059  *             default clipboard. Another common value
8060  *             is %GDK_SELECTION_PRIMARY, which gives
8061  *             the primary X selection. 
8062  * 
8063  * Returns the clipboard object for the given selection to
8064  * be used with @widget. @widget must have a #GdkDisplay
8065  * associated with it, so must be attached to a toplevel
8066  * window.
8067  * 
8068  * Return value: the appropriate clipboard object. If no
8069  *             clipboard already exists, a new one will
8070  *             be created. Once a clipboard object has
8071  *             been created, it is persistent for all time.
8072  *
8073  * Since: 2.2
8074  **/
8075 GtkClipboard *
8076 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
8077 {
8078   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8079   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
8080   
8081   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
8082                                         selection);
8083 }
8084
8085 /**
8086  * gtk_widget_list_mnemonic_labels:
8087  * @widget: a #GtkWidget
8088  * 
8089  * Returns a newly allocated list of the widgets, normally labels, for 
8090  * which this widget is a the target of a mnemonic (see for example, 
8091  * gtk_label_set_mnemonic_widget()).
8092
8093  * The widgets in the list are not individually referenced. If you
8094  * want to iterate through the list and perform actions involving
8095  * callbacks that might destroy the widgets, you
8096  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
8097  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
8098  * widgets afterwards.
8099
8100  * Return value: the list of mnemonic labels; free this list
8101  *  with g_list_free() when you are done with it.
8102  *
8103  * Since: 2.4
8104  **/
8105 GList *
8106 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
8107 {
8108   GList *list = NULL;
8109   GSList *l;
8110   
8111   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8112
8113   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
8114     list = g_list_prepend (list, l->data);
8115
8116   return list;
8117 }
8118
8119 /**
8120  * gtk_widget_add_mnemonic_label:
8121  * @widget: a #GtkWidget
8122  * @label: a #GtkWidget that acts as a mnemonic label for @widget.
8123  * 
8124  * Adds a widget to the list of mnemonic labels for
8125  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
8126  * list of mnemonic labels for the widget is cleared when the
8127  * widget is destroyed, so the caller must make sure to update
8128  * its internal state at this point as well, by using a connection
8129  * to the ::destroy signal or a weak notifier.
8130  *
8131  * Since: 2.4
8132  **/
8133 void
8134 gtk_widget_add_mnemonic_label (GtkWidget *widget,
8135                                GtkWidget *label)
8136 {
8137   GSList *old_list, *new_list;
8138
8139   g_return_if_fail (GTK_IS_WIDGET (widget));
8140   g_return_if_fail (GTK_IS_WIDGET (label));
8141
8142   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
8143   new_list = g_slist_prepend (old_list, label);
8144   
8145   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
8146                            new_list, (GDestroyNotify) g_slist_free);
8147 }
8148
8149 /**
8150  * gtk_widget_remove_mnemonic_label:
8151  * @widget: a #GtkWidget
8152  * @label: a #GtkWidget that was previously set as a mnemnic label for
8153  *         @widget with gtk_widget_add_mnemonic_label().
8154  * 
8155  * Removes a widget from the list of mnemonic labels for
8156  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
8157  * must have previously been added to the list with
8158  * gtk_widget_add_mnemonic_label().
8159  *
8160  * Since: 2.4
8161  **/
8162 void
8163 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
8164                                   GtkWidget *label)
8165 {
8166   GSList *old_list, *new_list;
8167
8168   g_return_if_fail (GTK_IS_WIDGET (widget));
8169   g_return_if_fail (GTK_IS_WIDGET (label));
8170
8171   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
8172   new_list = g_slist_remove (old_list, label);
8173
8174   if (new_list)
8175     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
8176                              new_list, (GDestroyNotify) g_slist_free);
8177 }
8178
8179 /**
8180  * gtk_widget_get_no_show_all:
8181  * @widget: a #GtkWidget
8182  * 
8183  * Returns the current value of the "no_show_all" property, which determines
8184  * whether calls to gtk_widget_show_all() and gtk_widget_hide_all() 
8185  * will affect this widget. 
8186  * 
8187  * Return value: the current value of the "no_show_all" property.
8188  *
8189  * Since: 2.4
8190  **/
8191 gboolean
8192 gtk_widget_get_no_show_all (GtkWidget *widget)
8193 {
8194   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8195   
8196   return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
8197 }
8198
8199 /**
8200  * gtk_widget_set_no_show_all:
8201  * @widget: a #GtkWidget
8202  * @no_show_all: the new value for the "no_show_all" property
8203  * 
8204  * Sets the "no_show_all" property, which determines whether calls to 
8205  * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget. 
8206  *
8207  * This is mostly for use in constructing widget hierarchies with externally
8208  * controlled visibility, see #GtkUIManager.
8209  * 
8210  * Since: 2.4
8211  **/
8212 void
8213 gtk_widget_set_no_show_all (GtkWidget *widget,
8214                             gboolean   no_show_all)
8215 {
8216   g_return_if_fail (GTK_IS_WIDGET (widget));
8217
8218   no_show_all = (no_show_all != FALSE);
8219
8220   if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
8221     return;
8222
8223   if (no_show_all)
8224     GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
8225   else
8226     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
8227   
8228   g_object_notify (G_OBJECT (widget), "no-show-all");
8229 }
8230
8231 #define __GTK_WIDGET_C__
8232 #include "gtkaliasdef.c"