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