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