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