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