]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
fb63f4b51ac408d5bc476128b83be7debd0fa728
[~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 const cairo_user_data_key_t window_key;
5074
5075 static GdkWindow *
5076 gtk_cairo_get_window (cairo_t *cr)
5077 {
5078   g_return_val_if_fail (cr != NULL, NULL);
5079
5080   return cairo_get_user_data (cr, &window_key);
5081 }
5082
5083 /**
5084  * gtk_cairo_should_draw_window:
5085  * @cr: a cairo context
5086  * @window: the window to check
5087  *
5088  * This function is supposed to be called in GtkWidget::draw
5089  * implementations for widgets that support multiple windows.
5090  * @cr must be untransformed from invoking of the draw function.
5091  * This function will return %TRUE if the contents of the given
5092  * @window are supposed to be drawn and %FALSE otherwise. Note
5093  * that when the drawing was not initiated by the windowing
5094  * system this function will return %TRUE for all windows, so
5095  * you need to draw the bottommost window first. Also, do not
5096  * use "else if" statements to check which window should be drawn.
5097  *
5098  * Returns: %TRUE if @window should be drawn
5099  **/
5100 gboolean
5101 gtk_cairo_should_draw_window (cairo_t *cr,
5102                               GdkWindow *window)
5103 {
5104   GdkWindow *cairo_window;
5105
5106   g_return_val_if_fail (cr != NULL, FALSE);
5107   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5108
5109   cairo_window = gtk_cairo_get_window (cr);
5110   
5111   return cairo_window == NULL ||
5112          cairo_window == window;
5113 }
5114
5115 static void
5116 gtk_cairo_set_window (cairo_t   *cr,
5117                       GdkWindow *window)
5118 {
5119   cairo_set_user_data (cr, &window_key, window, NULL);
5120 }
5121 static gboolean
5122 gtk_widget_real_expose_event (GtkWidget      *widget,
5123                               GdkEventExpose *expose)
5124 {
5125   GdkWindow *window;
5126   gboolean result = FALSE;
5127   cairo_t *cr;
5128
5129   if (!gtk_widget_is_drawable (widget))
5130     return FALSE;
5131
5132   cr = gdk_cairo_create (expose->window);
5133   gtk_cairo_set_window (cr, expose->window);
5134
5135   gdk_cairo_region (cr, expose->region);
5136   cairo_clip (cr);
5137
5138   /* translate cairo context properly */
5139   window = gtk_widget_get_window (widget);
5140   if (window != expose->window)
5141     {
5142       int x, y;
5143
5144       if (gdk_window_get_parent (expose->window) == window)
5145         {
5146           gdk_window_get_position (expose->window, &x, &y);
5147         }
5148       else
5149         {
5150           int ex, ey;
5151           gdk_window_get_origin (expose->window, &ex, &ey);
5152           gdk_window_get_origin (window, &x, &y);
5153           x = ex - x;
5154           y = ey - y;
5155         }
5156
5157       cairo_translate (cr, -x, -y);
5158     }
5159
5160
5161   if (!gtk_widget_get_has_window (widget))
5162     {
5163       cairo_translate (cr,
5164                        widget->priv->allocation.x,
5165                        widget->priv->allocation.y);
5166     }
5167
5168   g_signal_emit (widget, widget_signals[DRAW], 
5169                  0, cr,
5170                  &result);
5171
5172   /* unset here, so if someone keeps a reference to cr we
5173    * don't leak the window. */
5174   gtk_cairo_set_window (cr, NULL);
5175   cairo_destroy (cr);
5176
5177   return result;
5178 }
5179
5180 static gboolean
5181 gtk_widget_real_key_press_event (GtkWidget         *widget,
5182                                  GdkEventKey       *event)
5183 {
5184   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5185 }
5186
5187 static gboolean
5188 gtk_widget_real_key_release_event (GtkWidget         *widget,
5189                                    GdkEventKey       *event)
5190 {
5191   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5192 }
5193
5194 static gboolean
5195 gtk_widget_real_focus_in_event (GtkWidget     *widget,
5196                                 GdkEventFocus *event)
5197 {
5198   gtk_widget_queue_shallow_draw (widget);
5199
5200   return FALSE;
5201 }
5202
5203 static gboolean
5204 gtk_widget_real_focus_out_event (GtkWidget     *widget,
5205                                  GdkEventFocus *event)
5206 {
5207   gtk_widget_queue_shallow_draw (widget);
5208
5209   return FALSE;
5210 }
5211
5212 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5213      (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5214
5215 /**
5216  * gtk_widget_event:
5217  * @widget: a #GtkWidget
5218  * @event: a #GdkEvent
5219  * 
5220  * Rarely-used function. This function is used to emit
5221  * the event signals on a widget (those signals should never
5222  * be emitted without using this function to do so).
5223  * If you want to synthesize an event though, don't use this function;
5224  * instead, use gtk_main_do_event() so the event will behave as if
5225  * it were in the event queue. Don't synthesize expose events; instead,
5226  * use gdk_window_invalidate_rect() to invalidate a region of the
5227  * window.
5228  * 
5229  * Return value: return from the event signal emission (%TRUE if 
5230  *               the event was handled)
5231  **/
5232 gboolean
5233 gtk_widget_event (GtkWidget *widget,
5234                   GdkEvent  *event)
5235 {
5236   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5237   g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5238
5239   if (event->type == GDK_EXPOSE)
5240     {
5241       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5242                  "the same effect, call gdk_window_invalidate_rect/region(), "
5243                  "followed by gdk_window_process_updates().");
5244       return TRUE;
5245     }
5246   
5247   return gtk_widget_event_internal (widget, event);
5248 }
5249
5250
5251 /**
5252  * gtk_widget_send_expose:
5253  * @widget: a #GtkWidget
5254  * @event: a expose #GdkEvent
5255  * 
5256  * Very rarely-used function. This function is used to emit
5257  * an expose event signals on a widget. This function is not
5258  * normally used directly. The only time it is used is when
5259  * propagating an expose event to a child %NO_WINDOW widget, and
5260  * that is normally done using gtk_container_propagate_expose().
5261  *
5262  * If you want to force an area of a window to be redrawn, 
5263  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5264  * To cause the redraw to be done immediately, follow that call
5265  * with a call to gdk_window_process_updates().
5266  * 
5267  * Return value: return from the event signal emission (%TRUE if 
5268  *               the event was handled)
5269  **/
5270 gint
5271 gtk_widget_send_expose (GtkWidget *widget,
5272                         GdkEvent  *event)
5273 {
5274   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5275   g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5276   g_return_val_if_fail (event != NULL, TRUE);
5277   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5278
5279   return gtk_widget_event_internal (widget, event);
5280 }
5281
5282 static gboolean
5283 event_window_is_still_viewable (GdkEvent *event)
5284 {
5285   /* Check that we think the event's window is viewable before
5286    * delivering the event, to prevent suprises. We do this here
5287    * at the last moment, since the event may have been queued
5288    * up behind other events, held over a recursive main loop, etc.
5289    */
5290   switch (event->type)
5291     {
5292     case GDK_EXPOSE:
5293     case GDK_MOTION_NOTIFY:
5294     case GDK_BUTTON_PRESS:
5295     case GDK_2BUTTON_PRESS:
5296     case GDK_3BUTTON_PRESS:
5297     case GDK_KEY_PRESS:
5298     case GDK_ENTER_NOTIFY:
5299     case GDK_PROXIMITY_IN:
5300     case GDK_SCROLL:
5301       return event->any.window && gdk_window_is_viewable (event->any.window);
5302
5303 #if 0
5304     /* The following events are the second half of paired events;
5305      * we always deliver them to deal with widgets that clean up
5306      * on the second half.
5307      */
5308     case GDK_BUTTON_RELEASE:
5309     case GDK_KEY_RELEASE:
5310     case GDK_LEAVE_NOTIFY:
5311     case GDK_PROXIMITY_OUT:
5312 #endif      
5313       
5314     default:
5315       /* Remaining events would make sense on an not-viewable window,
5316        * or don't have an associated window.
5317        */
5318       return TRUE;
5319     }
5320 }
5321
5322 static gint
5323 gtk_widget_event_internal (GtkWidget *widget,
5324                            GdkEvent  *event)
5325 {
5326   gboolean return_val = FALSE;
5327
5328   /* We check only once for is-still-visible; if someone
5329    * hides the window in on of the signals on the widget,
5330    * they are responsible for returning TRUE to terminate
5331    * handling.
5332    */
5333   if (!event_window_is_still_viewable (event))
5334     return TRUE;
5335
5336   g_object_ref (widget);
5337
5338   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5339   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5340   if (!return_val)
5341     {
5342       gint signal_num;
5343
5344       switch (event->type)
5345         {
5346         case GDK_NOTHING:
5347           signal_num = -1;
5348           break;
5349         case GDK_BUTTON_PRESS:
5350         case GDK_2BUTTON_PRESS:
5351         case GDK_3BUTTON_PRESS:
5352           signal_num = BUTTON_PRESS_EVENT;
5353           break;
5354         case GDK_SCROLL:
5355           signal_num = SCROLL_EVENT;
5356           break;
5357         case GDK_BUTTON_RELEASE:
5358           signal_num = BUTTON_RELEASE_EVENT;
5359           break;
5360         case GDK_MOTION_NOTIFY:
5361           signal_num = MOTION_NOTIFY_EVENT;
5362           break;
5363         case GDK_DELETE:
5364           signal_num = DELETE_EVENT;
5365           break;
5366         case GDK_DESTROY:
5367           signal_num = DESTROY_EVENT;
5368           _gtk_tooltip_hide (widget);
5369           break;
5370         case GDK_KEY_PRESS:
5371           signal_num = KEY_PRESS_EVENT;
5372           break;
5373         case GDK_KEY_RELEASE:
5374           signal_num = KEY_RELEASE_EVENT;
5375           break;
5376         case GDK_ENTER_NOTIFY:
5377           signal_num = ENTER_NOTIFY_EVENT;
5378           break;
5379         case GDK_LEAVE_NOTIFY:
5380           signal_num = LEAVE_NOTIFY_EVENT;
5381           break;
5382         case GDK_FOCUS_CHANGE:
5383           signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5384           if (event->focus_change.in)
5385             _gtk_tooltip_focus_in (widget);
5386           else
5387             _gtk_tooltip_focus_out (widget);
5388           break;
5389         case GDK_CONFIGURE:
5390           signal_num = CONFIGURE_EVENT;
5391           break;
5392         case GDK_MAP:
5393           signal_num = MAP_EVENT;
5394           break;
5395         case GDK_UNMAP:
5396           signal_num = UNMAP_EVENT;
5397           break;
5398         case GDK_WINDOW_STATE:
5399           signal_num = WINDOW_STATE_EVENT;
5400           break;
5401         case GDK_PROPERTY_NOTIFY:
5402           signal_num = PROPERTY_NOTIFY_EVENT;
5403           break;
5404         case GDK_SELECTION_CLEAR:
5405           signal_num = SELECTION_CLEAR_EVENT;
5406           break;
5407         case GDK_SELECTION_REQUEST:
5408           signal_num = SELECTION_REQUEST_EVENT;
5409           break;
5410         case GDK_SELECTION_NOTIFY:
5411           signal_num = SELECTION_NOTIFY_EVENT;
5412           break;
5413         case GDK_PROXIMITY_IN:
5414           signal_num = PROXIMITY_IN_EVENT;
5415           break;
5416         case GDK_PROXIMITY_OUT:
5417           signal_num = PROXIMITY_OUT_EVENT;
5418           break;
5419         case GDK_NO_EXPOSE:
5420           signal_num = NO_EXPOSE_EVENT;
5421           break;
5422         case GDK_CLIENT_EVENT:
5423           signal_num = CLIENT_EVENT;
5424           break;
5425         case GDK_EXPOSE:
5426           signal_num = EXPOSE_EVENT;
5427           break;
5428         case GDK_VISIBILITY_NOTIFY:
5429           signal_num = VISIBILITY_NOTIFY_EVENT;
5430           break;
5431         case GDK_GRAB_BROKEN:
5432           signal_num = GRAB_BROKEN;
5433           break;
5434         case GDK_DAMAGE:
5435           signal_num = DAMAGE_EVENT;
5436           break;
5437         default:
5438           g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5439           signal_num = -1;
5440           break;
5441         }
5442       if (signal_num != -1)
5443         g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5444     }
5445   if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5446     g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5447   else
5448     return_val = TRUE;
5449
5450   g_object_unref (widget);
5451
5452   return return_val;
5453 }
5454
5455 /**
5456  * gtk_widget_activate:
5457  * @widget: a #GtkWidget that's activatable
5458  * 
5459  * For widgets that can be "activated" (buttons, menu items, etc.)
5460  * this function activates them. Activation is what happens when you
5461  * press Enter on a widget during key navigation. If @widget isn't 
5462  * activatable, the function returns %FALSE.
5463  * 
5464  * Return value: %TRUE if the widget was activatable
5465  **/
5466 gboolean
5467 gtk_widget_activate (GtkWidget *widget)
5468 {
5469   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5470   
5471   if (WIDGET_CLASS (widget)->activate_signal)
5472     {
5473       /* FIXME: we should eventually check the signals signature here */
5474       g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5475
5476       return TRUE;
5477     }
5478   else
5479     return FALSE;
5480 }
5481
5482 /**
5483  * gtk_widget_set_scroll_adjustments:
5484  * @widget: a #GtkWidget
5485  * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5486  * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5487  *
5488  * For widgets that support scrolling, sets the scroll adjustments and
5489  * returns %TRUE.  For widgets that don't support scrolling, does
5490  * nothing and returns %FALSE. Widgets that don't support scrolling
5491  * can be scrolled by placing them in a #GtkViewport, which does
5492  * support scrolling.
5493  * 
5494  * Return value: %TRUE if the widget supports scrolling
5495  **/
5496 gboolean
5497 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
5498                                    GtkAdjustment *hadjustment,
5499                                    GtkAdjustment *vadjustment)
5500 {
5501   guint signal_id;
5502   GSignalQuery query;
5503
5504   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5505
5506   if (hadjustment)
5507     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5508   if (vadjustment)
5509     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5510
5511   signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5512   if (!signal_id)
5513     return FALSE;
5514
5515   g_signal_query (signal_id, &query);
5516   if (!query.signal_id ||
5517       !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5518       query.return_type != G_TYPE_NONE ||
5519       query.n_params != 2 ||
5520       query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5521       query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5522     {
5523       g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5524                  G_OBJECT_TYPE_NAME (widget), query.signal_name);
5525       return FALSE;
5526     }
5527       
5528   g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5529   return TRUE;
5530 }
5531
5532 static void
5533 gtk_widget_reparent_subwindows (GtkWidget *widget,
5534                                 GdkWindow *new_window)
5535 {
5536   GtkWidgetPrivate *priv = widget->priv;
5537
5538   if (!gtk_widget_get_has_window (widget))
5539     {
5540       GList *children = gdk_window_get_children (priv->window);
5541       GList *tmp_list;
5542
5543       for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5544         {
5545           GdkWindow *window = tmp_list->data;
5546           gpointer child;
5547
5548           gdk_window_get_user_data (window, &child);
5549           while (child && child != widget)
5550             child = ((GtkWidget*) child)->priv->parent;
5551
5552           if (child)
5553             gdk_window_reparent (window, new_window, 0, 0);
5554         }
5555
5556       g_list_free (children);
5557     }
5558   else
5559    {
5560      GdkWindow *parent;
5561      GList *tmp_list, *children;
5562
5563      parent = gdk_window_get_parent (priv->window);
5564
5565      if (parent == NULL)
5566        gdk_window_reparent (priv->window, new_window, 0, 0);
5567      else
5568        {
5569          children = gdk_window_get_children (parent);
5570          
5571          for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5572            {
5573              GdkWindow *window = tmp_list->data;
5574              gpointer child;
5575
5576              gdk_window_get_user_data (window, &child);
5577
5578              if (child == widget)
5579                gdk_window_reparent (window, new_window, 0, 0);
5580            }
5581          
5582          g_list_free (children);
5583        }
5584    }
5585 }
5586
5587 static void
5588 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5589                                  gpointer   client_data)
5590 {
5591   GtkWidgetPrivate *priv = widget->priv;
5592
5593   g_assert (client_data != NULL);
5594   
5595   if (!gtk_widget_get_has_window (widget))
5596     {
5597       if (priv->window)
5598         g_object_unref (priv->window);
5599       priv->window = (GdkWindow*) client_data;
5600       if (priv->window)
5601         g_object_ref (priv->window);
5602
5603       if (GTK_IS_CONTAINER (widget))
5604         gtk_container_forall (GTK_CONTAINER (widget),
5605                               gtk_widget_reparent_fixup_child,
5606                               client_data);
5607     }
5608 }
5609
5610 /**
5611  * gtk_widget_reparent:
5612  * @widget: a #GtkWidget
5613  * @new_parent: a #GtkContainer to move the widget into
5614  *
5615  * Moves a widget from one #GtkContainer to another, handling reference
5616  * count issues to avoid destroying the widget.
5617  **/
5618 void
5619 gtk_widget_reparent (GtkWidget *widget,
5620                      GtkWidget *new_parent)
5621 {
5622   GtkWidgetPrivate *priv;
5623
5624   g_return_if_fail (GTK_IS_WIDGET (widget));
5625   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5626   priv = widget->priv;
5627   g_return_if_fail (priv->parent != NULL);
5628
5629   if (priv->parent != new_parent)
5630     {
5631       /* First try to see if we can get away without unrealizing
5632        * the widget as we reparent it. if so we set a flag so
5633        * that gtk_widget_unparent doesn't unrealize widget
5634        */
5635       if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5636         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5637       
5638       g_object_ref (widget);
5639       gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5640       gtk_container_add (GTK_CONTAINER (new_parent), widget);
5641       g_object_unref (widget);
5642       
5643       if (GTK_WIDGET_IN_REPARENT (widget))
5644         {
5645           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5646
5647           gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5648           gtk_widget_reparent_fixup_child (widget,
5649                                            gtk_widget_get_parent_window (widget));
5650         }
5651
5652       g_object_notify (G_OBJECT (widget), "parent");
5653     }
5654 }
5655
5656 /**
5657  * gtk_widget_intersect:
5658  * @widget: a #GtkWidget
5659  * @area: a rectangle
5660  * @intersection: rectangle to store intersection of @widget and @area
5661  * 
5662  * Computes the intersection of a @widget's area and @area, storing
5663  * the intersection in @intersection, and returns %TRUE if there was
5664  * an intersection.  @intersection may be %NULL if you're only
5665  * interested in whether there was an intersection.
5666  * 
5667  * Return value: %TRUE if there was an intersection
5668  **/
5669 gboolean
5670 gtk_widget_intersect (GtkWidget          *widget,
5671                       const GdkRectangle *area,
5672                       GdkRectangle       *intersection)
5673 {
5674   GtkWidgetPrivate *priv;
5675   GdkRectangle *dest;
5676   GdkRectangle tmp;
5677   gint return_val;
5678   
5679   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5680   g_return_val_if_fail (area != NULL, FALSE);
5681
5682   priv = widget->priv;
5683
5684   if (intersection)
5685     dest = intersection;
5686   else
5687     dest = &tmp;
5688   
5689   return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5690   
5691   if (return_val && intersection && gtk_widget_get_has_window (widget))
5692     {
5693       intersection->x -= priv->allocation.x;
5694       intersection->y -= priv->allocation.y;
5695     }
5696   
5697   return return_val;
5698 }
5699
5700 /**
5701  * gtk_widget_region_intersect:
5702  * @widget: a #GtkWidget
5703  * @region: a #cairo_region_t, in the same coordinate system as 
5704  *          @widget->allocation. That is, relative to @widget->window
5705  *          for %NO_WINDOW widgets; relative to the parent window
5706  *          of @widget->window for widgets with their own window.
5707  * @returns: A newly allocated region holding the intersection of @widget
5708  *           and @region. The coordinates of the return value are
5709  *           relative to @widget->window for %NO_WINDOW widgets, and
5710  *           relative to the parent window of @widget->window for
5711  *           widgets with their own window.
5712  * 
5713  * Computes the intersection of a @widget's area and @region, returning
5714  * the intersection. The result may be empty, use cairo_region_is_empty() to
5715  * check.
5716  **/
5717 cairo_region_t *
5718 gtk_widget_region_intersect (GtkWidget       *widget,
5719                              const cairo_region_t *region)
5720 {
5721   GdkRectangle rect;
5722   cairo_region_t *dest;
5723   
5724   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5725   g_return_val_if_fail (region != NULL, NULL);
5726
5727   gtk_widget_get_allocation (widget, &rect);
5728   
5729   dest = cairo_region_create_rectangle (&rect);
5730  
5731   cairo_region_intersect (dest, region);
5732
5733   return dest;
5734 }
5735
5736 /**
5737  * _gtk_widget_grab_notify:
5738  * @widget: a #GtkWidget
5739  * @was_grabbed: whether a grab is now in effect
5740  * 
5741  * Emits the #GtkWidget::grab-notify signal on @widget.
5742  * 
5743  * Since: 2.6
5744  **/
5745 void
5746 _gtk_widget_grab_notify (GtkWidget *widget,
5747                          gboolean   was_grabbed)
5748 {
5749   g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5750 }
5751
5752 /**
5753  * gtk_widget_grab_focus:
5754  * @widget: a #GtkWidget
5755  * 
5756  * Causes @widget to have the keyboard focus for the #GtkWindow it's
5757  * inside. @widget must be a focusable widget, such as a #GtkEntry;
5758  * something like #GtkFrame won't work.
5759  *
5760  * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5761  * gtk_widget_set_can_focus() to modify that flag.
5762  *
5763  * The widget also needs to be realized and mapped. This is indicated by the
5764  * related signals. Grabbing the focus immediately after creating the widget
5765  * will likely fail and cause critical warnings.
5766  **/
5767 void
5768 gtk_widget_grab_focus (GtkWidget *widget)
5769 {
5770   g_return_if_fail (GTK_IS_WIDGET (widget));
5771
5772   if (!gtk_widget_is_sensitive (widget))
5773     return;
5774   
5775   g_object_ref (widget);
5776   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5777   g_object_notify (G_OBJECT (widget), "has-focus");
5778   g_object_unref (widget);
5779 }
5780
5781 static void
5782 reset_focus_recurse (GtkWidget *widget,
5783                      gpointer   data)
5784 {
5785   if (GTK_IS_CONTAINER (widget))
5786     {
5787       GtkContainer *container;
5788
5789       container = GTK_CONTAINER (widget);
5790       gtk_container_set_focus_child (container, NULL);
5791
5792       gtk_container_foreach (container,
5793                              reset_focus_recurse,
5794                              NULL);
5795     }
5796 }
5797
5798 static void
5799 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5800 {
5801   if (gtk_widget_get_can_focus (focus_widget))
5802     {
5803       GtkWidget *toplevel;
5804       GtkWidget *widget;
5805       
5806       /* clear the current focus setting, break if the current widget
5807        * is the focus widget's parent, since containers above that will
5808        * be set by the next loop.
5809        */
5810       toplevel = gtk_widget_get_toplevel (focus_widget);
5811       if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5812         {
5813           widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5814
5815           if (widget == focus_widget)
5816             {
5817               /* We call _gtk_window_internal_set_focus() here so that the
5818                * toplevel window can request the focus if necessary.
5819                * This is needed when the toplevel is a GtkPlug
5820                */
5821               if (!gtk_widget_has_focus (widget))
5822                 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5823
5824               return;
5825             }
5826           
5827           if (widget)
5828             {
5829               while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5830                 {
5831                   widget = widget->priv->parent;
5832                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5833                 }
5834             }
5835         }
5836       else if (toplevel != focus_widget)
5837         {
5838           /* gtk_widget_grab_focus() operates on a tree without window...
5839            * actually, this is very questionable behaviour.
5840            */
5841           
5842           gtk_container_foreach (GTK_CONTAINER (toplevel),
5843                                  reset_focus_recurse,
5844                                  NULL);
5845         }
5846
5847       /* now propagate the new focus up the widget tree and finally
5848        * set it on the window
5849        */
5850       widget = focus_widget;
5851       while (widget->priv->parent)
5852         {
5853           gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5854           widget = widget->priv->parent;
5855         }
5856       if (GTK_IS_WINDOW (widget))
5857         _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5858     }
5859 }
5860
5861 static gboolean
5862 gtk_widget_real_query_tooltip (GtkWidget  *widget,
5863                                gint        x,
5864                                gint        y,
5865                                gboolean    keyboard_tip,
5866                                GtkTooltip *tooltip)
5867 {
5868   gchar *tooltip_markup;
5869   gboolean has_tooltip;
5870
5871   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5872   has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5873
5874   if (has_tooltip && tooltip_markup)
5875     {
5876       gtk_tooltip_set_markup (tooltip, tooltip_markup);
5877       return TRUE;
5878     }
5879
5880   return FALSE;
5881 }
5882
5883 static gboolean
5884 gtk_widget_real_show_help (GtkWidget        *widget,
5885                            GtkWidgetHelpType help_type)
5886 {
5887   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5888     {
5889       _gtk_tooltip_toggle_keyboard_mode (widget);
5890
5891       return TRUE;
5892     }
5893   else
5894     return FALSE;
5895 }
5896
5897 static gboolean
5898 gtk_widget_real_focus (GtkWidget         *widget,
5899                        GtkDirectionType   direction)
5900 {
5901   if (!gtk_widget_get_can_focus (widget))
5902     return FALSE;
5903   
5904   if (!gtk_widget_is_focus (widget))
5905     {
5906       gtk_widget_grab_focus (widget);
5907       return TRUE;
5908     }
5909   else
5910     return FALSE;
5911 }
5912
5913 static void
5914 gtk_widget_real_move_focus (GtkWidget         *widget,
5915                             GtkDirectionType   direction)
5916 {
5917   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5918
5919   if (GTK_IS_WINDOW (toplevel) &&
5920       GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5921     {
5922       GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5923                                                    direction);
5924     }
5925 }
5926
5927 static gboolean
5928 gtk_widget_real_keynav_failed (GtkWidget        *widget,
5929                                GtkDirectionType  direction)
5930 {
5931   gboolean cursor_only;
5932
5933   switch (direction)
5934     {
5935     case GTK_DIR_TAB_FORWARD:
5936     case GTK_DIR_TAB_BACKWARD:
5937       return FALSE;
5938
5939     case GTK_DIR_UP:
5940     case GTK_DIR_DOWN:
5941     case GTK_DIR_LEFT:
5942     case GTK_DIR_RIGHT:
5943       g_object_get (gtk_widget_get_settings (widget),
5944                     "gtk-keynav-cursor-only", &cursor_only,
5945                     NULL);
5946       if (cursor_only)
5947         return FALSE;
5948       break;
5949     }
5950
5951   gtk_widget_error_bell (widget);
5952
5953   return TRUE;
5954 }
5955
5956 /**
5957  * gtk_widget_set_can_focus:
5958  * @widget: a #GtkWidget
5959  * @can_focus: whether or not @widget can own the input focus.
5960  *
5961  * Specifies whether @widget can own the input focus. See
5962  * gtk_widget_grab_focus() for actually setting the input focus on a
5963  * widget.
5964  *
5965  * Since: 2.18
5966  **/
5967 void
5968 gtk_widget_set_can_focus (GtkWidget *widget,
5969                           gboolean   can_focus)
5970 {
5971   g_return_if_fail (GTK_IS_WIDGET (widget));
5972
5973   if (can_focus != gtk_widget_get_can_focus (widget))
5974     {
5975       if (can_focus)
5976         GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5977       else
5978         GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5979
5980       gtk_widget_queue_resize (widget);
5981       g_object_notify (G_OBJECT (widget), "can-focus");
5982     }
5983 }
5984
5985 /**
5986  * gtk_widget_get_can_focus:
5987  * @widget: a #GtkWidget
5988  *
5989  * Determines whether @widget can own the input focus. See
5990  * gtk_widget_set_can_focus().
5991  *
5992  * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5993  *
5994  * Since: 2.18
5995  **/
5996 gboolean
5997 gtk_widget_get_can_focus (GtkWidget *widget)
5998 {
5999   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6000
6001   return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
6002 }
6003
6004 /**
6005  * gtk_widget_has_focus:
6006  * @widget: a #GtkWidget
6007  *
6008  * Determines if the widget has the global input focus. See
6009  * gtk_widget_is_focus() for the difference between having the global
6010  * input focus, and only having the focus within a toplevel.
6011  *
6012  * Return value: %TRUE if the widget has the global input focus.
6013  *
6014  * Since: 2.18
6015  **/
6016 gboolean
6017 gtk_widget_has_focus (GtkWidget *widget)
6018 {
6019   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6020
6021   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
6022 }
6023
6024 /**
6025  * gtk_widget_is_focus:
6026  * @widget: a #GtkWidget
6027  * 
6028  * Determines if the widget is the focus widget within its
6029  * toplevel. (This does not mean that the %HAS_FOCUS flag is
6030  * necessarily set; %HAS_FOCUS will only be set if the
6031  * toplevel widget additionally has the global input focus.)
6032  * 
6033  * Return value: %TRUE if the widget is the focus widget.
6034  **/
6035 gboolean
6036 gtk_widget_is_focus (GtkWidget *widget)
6037 {
6038   GtkWidget *toplevel;
6039
6040   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6041
6042   toplevel = gtk_widget_get_toplevel (widget);
6043   
6044   if (GTK_IS_WINDOW (toplevel))
6045     return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6046   else
6047     return FALSE;
6048 }
6049
6050 /**
6051  * gtk_widget_set_can_default:
6052  * @widget: a #GtkWidget
6053  * @can_default: whether or not @widget can be a default widget.
6054  *
6055  * Specifies whether @widget can be a default widget. See
6056  * gtk_widget_grab_default() for details about the meaning of
6057  * "default".
6058  *
6059  * Since: 2.18
6060  **/
6061 void
6062 gtk_widget_set_can_default (GtkWidget *widget,
6063                             gboolean   can_default)
6064 {
6065   g_return_if_fail (GTK_IS_WIDGET (widget));
6066
6067   if (can_default != gtk_widget_get_can_default (widget))
6068     {
6069       if (can_default)
6070         GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
6071       else
6072         GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
6073
6074       gtk_widget_queue_resize (widget);
6075       g_object_notify (G_OBJECT (widget), "can-default");
6076     }
6077 }
6078
6079 /**
6080  * gtk_widget_get_can_default:
6081  * @widget: a #GtkWidget
6082  *
6083  * Determines whether @widget can be a default widget. See
6084  * gtk_widget_set_can_default().
6085  *
6086  * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6087  *
6088  * Since: 2.18
6089  **/
6090 gboolean
6091 gtk_widget_get_can_default (GtkWidget *widget)
6092 {
6093   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6094
6095   return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6096 }
6097
6098 /**
6099  * gtk_widget_has_default:
6100  * @widget: a #GtkWidget
6101  *
6102  * Determines whether @widget is the current default widget within its
6103  * toplevel. See gtk_widget_set_can_default().
6104  *
6105  * Return value: %TRUE if @widget is the current default widget within
6106  *     its toplevel, %FALSE otherwise
6107  *
6108  * Since: 2.18
6109  */
6110 gboolean
6111 gtk_widget_has_default (GtkWidget *widget)
6112 {
6113   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6114
6115   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6116 }
6117
6118 void
6119 _gtk_widget_set_has_default (GtkWidget *widget,
6120                              gboolean   has_default)
6121 {
6122   if (has_default)
6123     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6124   else
6125     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6126 }
6127
6128 /**
6129  * gtk_widget_grab_default:
6130  * @widget: a #GtkWidget
6131  *
6132  * Causes @widget to become the default widget. @widget must have the
6133  * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6134  * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6135  * %TRUE)</literal>. The default widget is activated when 
6136  * the user presses Enter in a window. Default widgets must be 
6137  * activatable, that is, gtk_widget_activate() should affect them. Note
6138  * that #GtkEntry widgets require the "activates-default" property
6139  * set to %TRUE before they activate the default widget when Enter
6140  * is pressed and the #GtkEntry is focused.
6141  **/
6142 void
6143 gtk_widget_grab_default (GtkWidget *widget)
6144 {
6145   GtkWidget *window;
6146   
6147   g_return_if_fail (GTK_IS_WIDGET (widget));
6148   g_return_if_fail (gtk_widget_get_can_default (widget));
6149   
6150   window = gtk_widget_get_toplevel (widget);
6151   
6152   if (window && gtk_widget_is_toplevel (window))
6153     gtk_window_set_default (GTK_WINDOW (window), widget);
6154   else
6155     g_warning (G_STRLOC ": widget not within a GtkWindow");
6156 }
6157
6158 /**
6159  * gtk_widget_set_receives_default:
6160  * @widget: a #GtkWidget
6161  * @receives_default: whether or not @widget can be a default widget.
6162  *
6163  * Specifies whether @widget will be treated as the default widget
6164  * within its toplevel when it has the focus, even if another widget
6165  * is the default.
6166  *
6167  * See gtk_widget_grab_default() for details about the meaning of
6168  * "default".
6169  *
6170  * Since: 2.18
6171  **/
6172 void
6173 gtk_widget_set_receives_default (GtkWidget *widget,
6174                                  gboolean   receives_default)
6175 {
6176   g_return_if_fail (GTK_IS_WIDGET (widget));
6177
6178   if (receives_default != gtk_widget_get_receives_default (widget))
6179     {
6180       if (receives_default)
6181         GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6182       else
6183         GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6184
6185       g_object_notify (G_OBJECT (widget), "receives-default");
6186     }
6187 }
6188
6189 /**
6190  * gtk_widget_get_receives_default:
6191  * @widget: a #GtkWidget
6192  *
6193  * Determines whether @widget is alyways treated as default widget
6194  * withing its toplevel when it has the focus, even if another widget
6195  * is the default.
6196  *
6197  * See gtk_widget_set_receives_default().
6198  *
6199  * Return value: %TRUE if @widget acts as default widget when focussed,
6200  *               %FALSE otherwise
6201  *
6202  * Since: 2.18
6203  **/
6204 gboolean
6205 gtk_widget_get_receives_default (GtkWidget *widget)
6206 {
6207   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6208
6209   return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6210 }
6211
6212 /**
6213  * gtk_widget_has_grab:
6214  * @widget: a #GtkWidget
6215  *
6216  * Determines whether the widget is currently grabbing events, so it
6217  * is the only widget receiving input events (keyboard and mouse).
6218  *
6219  * See also gtk_grab_add().
6220  *
6221  * Return value: %TRUE if the widget is in the grab_widgets stack
6222  *
6223  * Since: 2.18
6224  **/
6225 gboolean
6226 gtk_widget_has_grab (GtkWidget *widget)
6227 {
6228   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6229
6230   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6231 }
6232
6233 void
6234 _gtk_widget_set_has_grab (GtkWidget *widget,
6235                           gboolean   has_grab)
6236 {
6237   if (has_grab)
6238     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6239   else
6240     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6241 }
6242
6243 /**
6244  * gtk_widget_device_is_shadowed:
6245  * @widget: a #GtkWidget
6246  * @device: a #GdkDevice
6247  *
6248  * Returns %TRUE if @device has been shadowed by a GTK+
6249  * device grab on another widget, so it would stop sending
6250  * events to @widget. This may be used in the
6251  * #GtkWidget::grab-notify signal to check for specific
6252  * devices. See gtk_device_grab_add().
6253  *
6254  * Returns: %TRUE if there is an ongoing grab on @device
6255  *          by another #GtkWidget than @widget.
6256  *
6257  * Since: 3.0
6258  **/
6259 gboolean
6260 gtk_widget_device_is_shadowed (GtkWidget *widget,
6261                                GdkDevice *device)
6262 {
6263   GtkWindowGroup *group;
6264   GtkWidget *grab_widget, *toplevel;
6265
6266   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6267   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6268
6269   if (!gtk_widget_get_realized (widget))
6270     return TRUE;
6271
6272   toplevel = gtk_widget_get_toplevel (widget);
6273
6274   if (GTK_IS_WINDOW (toplevel))
6275     group = gtk_window_get_group (GTK_WINDOW (toplevel));
6276   else
6277     group = gtk_window_get_group (NULL);
6278
6279   grab_widget = gtk_window_group_get_current_device_grab (group, device);
6280
6281   /* Widget not inside the hierarchy of grab_widget */
6282   if (grab_widget &&
6283       widget != grab_widget &&
6284       !gtk_widget_is_ancestor (widget, grab_widget))
6285     return TRUE;
6286
6287   grab_widget = gtk_window_group_get_current_grab (group);
6288   if (grab_widget && widget != grab_widget &&
6289       !gtk_widget_is_ancestor (widget, grab_widget))
6290     return TRUE;
6291
6292   return FALSE;
6293 }
6294
6295 /**
6296  * gtk_widget_set_name:
6297  * @widget: a #GtkWidget
6298  * @name: name for the widget
6299  *
6300  * Widgets can be named, which allows you to refer to them from a
6301  * gtkrc file. You can apply a style to widgets with a particular name
6302  * in the gtkrc file. See the documentation for gtkrc files (on the
6303  * same page as the docs for #GtkRcStyle).
6304  * 
6305  * Note that widget names are separated by periods in paths (see 
6306  * gtk_widget_path()), so names with embedded periods may cause confusion.
6307  **/
6308 void
6309 gtk_widget_set_name (GtkWidget   *widget,
6310                      const gchar *name)
6311 {
6312   GtkWidgetPrivate *priv;
6313   gchar *new_name;
6314   
6315   g_return_if_fail (GTK_IS_WIDGET (widget));
6316
6317   priv = widget->priv;
6318
6319   new_name = g_strdup (name);
6320   g_free (priv->name);
6321   priv->name = new_name;
6322
6323   if (gtk_widget_has_rc_style (widget))
6324     gtk_widget_reset_rc_style (widget);
6325
6326   g_object_notify (G_OBJECT (widget), "name");
6327 }
6328
6329 /**
6330  * gtk_widget_get_name:
6331  * @widget: a #GtkWidget
6332  * 
6333  * Retrieves the name of a widget. See gtk_widget_set_name() for the
6334  * significance of widget names.
6335  * 
6336  * Return value: name of the widget. This string is owned by GTK+ and
6337  * should not be modified or freed
6338  **/
6339 G_CONST_RETURN gchar*
6340 gtk_widget_get_name (GtkWidget *widget)
6341 {
6342   GtkWidgetPrivate *priv;
6343
6344   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6345
6346   priv = widget->priv;
6347
6348   if (priv->name)
6349     return priv->name;
6350   return G_OBJECT_TYPE_NAME (widget);
6351 }
6352
6353 /**
6354  * gtk_widget_set_state:
6355  * @widget: a #GtkWidget
6356  * @state: new state for @widget
6357  *
6358  * This function is for use in widget implementations. Sets the state
6359  * of a widget (insensitive, prelighted, etc.) Usually you should set
6360  * the state using wrapper functions such as gtk_widget_set_sensitive().
6361  **/
6362 void
6363 gtk_widget_set_state (GtkWidget           *widget,
6364                       GtkStateType         state)
6365 {
6366   GtkWidgetPrivate *priv;
6367
6368   g_return_if_fail (GTK_IS_WIDGET (widget));
6369
6370   priv = widget->priv;
6371
6372   if (state == gtk_widget_get_state (widget))
6373     return;
6374
6375   if (state == GTK_STATE_INSENSITIVE)
6376     gtk_widget_set_sensitive (widget, FALSE);
6377   else
6378     {
6379       GtkStateData data;
6380
6381       data.state = state;
6382       data.state_restoration = FALSE;
6383       data.use_forall = FALSE;
6384       if (priv->parent)
6385         data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6386       else
6387         data.parent_sensitive = TRUE;
6388
6389       gtk_widget_propagate_state (widget, &data);
6390   
6391       if (gtk_widget_is_drawable (widget))
6392         gtk_widget_queue_draw (widget);
6393     }
6394 }
6395
6396 /**
6397  * gtk_widget_get_state:
6398  * @widget: a #GtkWidget
6399  *
6400  * Returns the widget's state. See gtk_widget_set_state().
6401  *
6402  * Returns: the state of @widget.
6403  *
6404  * Since: 2.18
6405  */
6406 GtkStateType
6407 gtk_widget_get_state (GtkWidget *widget)
6408 {
6409   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6410
6411   return widget->priv->state;
6412 }
6413
6414 /**
6415  * gtk_widget_set_visible:
6416  * @widget: a #GtkWidget
6417  * @visible: whether the widget should be shown or not
6418  *
6419  * Sets the visibility state of @widget. Note that setting this to
6420  * %TRUE doesn't mean the widget is actually viewable, see
6421  * gtk_widget_get_visible().
6422  *
6423  * This function simply calls gtk_widget_show() or gtk_widget_hide()
6424  * but is nicer to use when the visibility of the widget depends on
6425  * some condition.
6426  *
6427  * Since: 2.18
6428  **/
6429 void
6430 gtk_widget_set_visible (GtkWidget *widget,
6431                         gboolean   visible)
6432 {
6433   g_return_if_fail (GTK_IS_WIDGET (widget));
6434
6435   if (visible != gtk_widget_get_visible (widget))
6436     {
6437       if (visible)
6438         gtk_widget_show (widget);
6439       else
6440         gtk_widget_hide (widget);
6441     }
6442 }
6443
6444 /**
6445  * gtk_widget_get_visible:
6446  * @widget: a #GtkWidget
6447  *
6448  * Determines whether the widget is visible. Note that this doesn't
6449  * take into account whether the widget's parent is also visible
6450  * or the widget is obscured in any way.
6451  *
6452  * See gtk_widget_set_visible().
6453  *
6454  * Return value: %TRUE if the widget is visible
6455  *
6456  * Since: 2.18
6457  **/
6458 gboolean
6459 gtk_widget_get_visible (GtkWidget *widget)
6460 {
6461   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6462
6463   return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6464 }
6465
6466 /**
6467  * gtk_widget_set_has_window:
6468  * @widget: a #GtkWidget
6469  * @has_window: whether or not @widget has a window.
6470  *
6471  * Specifies whether @widget has a #GdkWindow of its own. Note that
6472  * all realized widgets have a non-%NULL "window" pointer
6473  * (gtk_widget_get_window() never returns a %NULL window when a widget
6474  * is realized), but for many of them it's actually the #GdkWindow of
6475  * one of its parent widgets. Widgets that do not create a %window for
6476  * themselves in GtkWidget::realize() must announce this by
6477  * calling this function with @has_window = %FALSE.
6478  *
6479  * This function should only be called by widget implementations,
6480  * and they should call it in their init() function.
6481  *
6482  * Since: 2.18
6483  **/
6484 void
6485 gtk_widget_set_has_window (GtkWidget *widget,
6486                            gboolean   has_window)
6487 {
6488   g_return_if_fail (GTK_IS_WIDGET (widget));
6489
6490   if (has_window)
6491     GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6492   else
6493     GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6494 }
6495
6496 /**
6497  * gtk_widget_get_has_window:
6498  * @widget: a #GtkWidget
6499  *
6500  * Determines whether @widget has a #GdkWindow of its own. See
6501  * gtk_widget_set_has_window().
6502  *
6503  * Return value: %TRUE if @widget has a window, %FALSE otherwise
6504  *
6505  * Since: 2.18
6506  **/
6507 gboolean
6508 gtk_widget_get_has_window (GtkWidget *widget)
6509 {
6510   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6511
6512   return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6513 }
6514
6515 /**
6516  * gtk_widget_is_toplevel:
6517  * @widget: a #GtkWidget
6518  *
6519  * Determines whether @widget is a toplevel widget. Currently only
6520  * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6521  * widgets have no parent widget.
6522  *
6523  * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6524  *
6525  * Since: 2.18
6526  **/
6527 gboolean
6528 gtk_widget_is_toplevel (GtkWidget *widget)
6529 {
6530   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6531
6532   return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6533 }
6534
6535 void
6536 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6537                              gboolean   is_toplevel)
6538 {
6539   if (is_toplevel)
6540     GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6541   else
6542     GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6543 }
6544
6545 /**
6546  * gtk_widget_is_drawable:
6547  * @widget: a #GtkWidget
6548  *
6549  * Determines whether @widget can be drawn to. A widget can be drawn
6550  * to if it is mapped and visible.
6551  *
6552  * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6553  *
6554  * Since: 2.18
6555  **/
6556 gboolean
6557 gtk_widget_is_drawable (GtkWidget *widget)
6558 {
6559   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6560
6561   return (gtk_widget_get_visible (widget) &&
6562           gtk_widget_get_mapped (widget));
6563 }
6564
6565 /**
6566  * gtk_widget_get_realized:
6567  * @widget: a #GtkWidget
6568  *
6569  * Determines whether @widget is realized.
6570  *
6571  * Return value: %TRUE if @widget is realized, %FALSE otherwise
6572  *
6573  * Since: 2.20
6574  **/
6575 gboolean
6576 gtk_widget_get_realized (GtkWidget *widget)
6577 {
6578   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6579
6580   return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6581 }
6582
6583 /**
6584  * gtk_widget_set_realized:
6585  * @widget: a #GtkWidget
6586  * @realized: %TRUE to mark the widget as realized
6587  *
6588  * Marks the widget as being realized.
6589  *
6590  * This function should only ever be called in a derived widget's
6591  * "realize" or "unrealize" implementation.
6592  *
6593  * Since: 2.20
6594  */
6595 void
6596 gtk_widget_set_realized (GtkWidget *widget,
6597                          gboolean   realized)
6598 {
6599   g_return_if_fail (GTK_IS_WIDGET (widget));
6600
6601   if (realized)
6602     GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6603   else
6604     GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6605 }
6606
6607 /**
6608  * gtk_widget_get_mapped:
6609  * @widget: a #GtkWidget
6610  *
6611  * Whether the widget is mapped.
6612  *
6613  * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6614  *
6615  * Since: 2.20
6616  */
6617 gboolean
6618 gtk_widget_get_mapped (GtkWidget *widget)
6619 {
6620   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6621
6622   return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6623 }
6624
6625 /**
6626  * gtk_widget_set_mapped:
6627  * @widget: a #GtkWidget
6628  * @mapped: %TRUE to mark the widget as mapped
6629  *
6630  * Marks the widget as being realized.
6631  *
6632  * This function should only ever be called in a derived widget's
6633  * "map" or "unmap" implementation.
6634  *
6635  * Since: 2.20
6636  */
6637 void
6638 gtk_widget_set_mapped (GtkWidget *widget,
6639                        gboolean   mapped)
6640 {
6641   g_return_if_fail (GTK_IS_WIDGET (widget));
6642
6643   if (mapped)
6644     GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6645   else
6646     GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6647 }
6648
6649 /**
6650  * gtk_widget_set_app_paintable:
6651  * @widget: a #GtkWidget
6652  * @app_paintable: %TRUE if the application will paint on the widget
6653  *
6654  * Sets whether the application intends to draw on the widget in
6655  * an #GtkWidget::expose-event handler. 
6656  *
6657  * This is a hint to the widget and does not affect the behavior of 
6658  * the GTK+ core; many widgets ignore this flag entirely. For widgets 
6659  * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow, 
6660  * the effect is to suppress default themed drawing of the widget's 
6661  * background. (Children of the widget will still be drawn.) The application 
6662  * is then entirely responsible for drawing the widget background.
6663  *
6664  * Note that the background is still drawn when the widget is mapped.
6665  **/
6666 void
6667 gtk_widget_set_app_paintable (GtkWidget *widget,
6668                               gboolean   app_paintable)
6669 {
6670   g_return_if_fail (GTK_IS_WIDGET (widget));
6671
6672   app_paintable = (app_paintable != FALSE);
6673
6674   if (gtk_widget_get_app_paintable (widget) != app_paintable)
6675     {
6676       if (app_paintable)
6677         GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6678       else
6679         GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6680
6681       if (gtk_widget_is_drawable (widget))
6682         gtk_widget_queue_draw (widget);
6683
6684       g_object_notify (G_OBJECT (widget), "app-paintable");
6685     }
6686 }
6687
6688 /**
6689  * gtk_widget_get_app_paintable:
6690  * @widget: a #GtkWidget
6691  *
6692  * Determines whether the application intends to draw on the widget in
6693  * an #GtkWidget::expose-event handler.
6694  *
6695  * See gtk_widget_set_app_paintable()
6696  *
6697  * Return value: %TRUE if the widget is app paintable
6698  *
6699  * Since: 2.18
6700  **/
6701 gboolean
6702 gtk_widget_get_app_paintable (GtkWidget *widget)
6703 {
6704   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6705
6706   return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6707 }
6708
6709 /**
6710  * gtk_widget_set_double_buffered:
6711  * @widget: a #GtkWidget
6712  * @double_buffered: %TRUE to double-buffer a widget
6713  *
6714  * Widgets are double buffered by default; you can use this function
6715  * to turn off the buffering. "Double buffered" simply means that
6716  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6717  * automatically around expose events sent to the
6718  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6719  * window to an offscreen buffer, and gdk_window_end_paint() draws the
6720  * buffer to the screen. The result is that users see the window
6721  * update in one smooth step, and don't see individual graphics
6722  * primitives being rendered.
6723  *
6724  * In very simple terms, double buffered widgets don't flicker,
6725  * so you would only use this function to turn off double buffering
6726  * if you had special needs and really knew what you were doing.
6727  * 
6728  * Note: if you turn off double-buffering, you have to handle
6729  * expose events, since even the clearing to the background color or 
6730  * pixmap will not happen automatically (as it is done in 
6731  * gdk_window_begin_paint()).
6732  **/
6733 void
6734 gtk_widget_set_double_buffered (GtkWidget *widget,
6735                                 gboolean   double_buffered)
6736 {
6737   g_return_if_fail (GTK_IS_WIDGET (widget));
6738
6739   double_buffered = (double_buffered != FALSE);
6740
6741   if (double_buffered != gtk_widget_get_double_buffered (widget))
6742     {
6743       if (double_buffered)
6744         GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6745       else
6746         GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6747
6748       g_object_notify (G_OBJECT (widget), "double-buffered");
6749     }
6750 }
6751
6752 /**
6753  * gtk_widget_get_double_buffered:
6754  * @widget: a #GtkWidget
6755  *
6756  * Determines whether the widget is double buffered.
6757  *
6758  * See gtk_widget_set_double_buffered()
6759  *
6760  * Return value: %TRUE if the widget is double buffered
6761  *
6762  * Since: 2.18
6763  **/
6764 gboolean
6765 gtk_widget_get_double_buffered (GtkWidget *widget)
6766 {
6767   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6768
6769   return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6770 }
6771
6772 /**
6773  * gtk_widget_set_redraw_on_allocate:
6774  * @widget: a #GtkWidget
6775  * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6776  *   when it is allocated to a new size. Otherwise, only the
6777  *   new portion of the widget will be redrawn.
6778  *
6779  * Sets whether the entire widget is queued for drawing when its size 
6780  * allocation changes. By default, this setting is %TRUE and
6781  * the entire widget is redrawn on every size change. If your widget
6782  * leaves the upper left unchanged when made bigger, turning this
6783  * setting off will improve performance.
6784
6785  * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6786  * off all allocation on resizing: the widget will not even redraw if
6787  * its position changes; this is to allow containers that don't draw
6788  * anything to avoid excess invalidations. If you set this flag on a
6789  * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window, 
6790  * you are responsible for invalidating both the old and new allocation 
6791  * of the widget when the widget is moved and responsible for invalidating
6792  * regions newly when the widget increases size.
6793  **/
6794 void
6795 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6796                                    gboolean   redraw_on_allocate)
6797 {
6798   g_return_if_fail (GTK_IS_WIDGET (widget));
6799
6800   if (redraw_on_allocate)
6801     GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6802   else
6803     GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6804 }
6805
6806 /**
6807  * gtk_widget_set_sensitive:
6808  * @widget: a #GtkWidget
6809  * @sensitive: %TRUE to make the widget sensitive
6810  *
6811  * Sets the sensitivity of a widget. A widget is sensitive if the user
6812  * can interact with it. Insensitive widgets are "grayed out" and the
6813  * user can't interact with them. Insensitive widgets are known as
6814  * "inactive", "disabled", or "ghosted" in some other toolkits.
6815  **/
6816 void
6817 gtk_widget_set_sensitive (GtkWidget *widget,
6818                           gboolean   sensitive)
6819 {
6820   GtkWidgetPrivate *priv;
6821   GtkStateData data;
6822
6823   g_return_if_fail (GTK_IS_WIDGET (widget));
6824
6825   priv = widget->priv;
6826
6827   sensitive = (sensitive != FALSE);
6828
6829   if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6830     return;
6831
6832   if (sensitive)
6833     {
6834       GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6835       data.state = priv->saved_state;
6836     }
6837   else
6838     {
6839       GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6840       data.state = gtk_widget_get_state (widget);
6841     }
6842   data.state_restoration = TRUE;
6843   data.use_forall = TRUE;
6844
6845   if (priv->parent)
6846     data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6847   else
6848     data.parent_sensitive = TRUE;
6849
6850   gtk_widget_propagate_state (widget, &data);
6851   if (gtk_widget_is_drawable (widget))
6852     gtk_widget_queue_draw (widget);
6853
6854   g_object_notify (G_OBJECT (widget), "sensitive");
6855 }
6856
6857 /**
6858  * gtk_widget_get_sensitive:
6859  * @widget: a #GtkWidget
6860  *
6861  * Returns the widget's sensitivity (in the sense of returning
6862  * the value that has been set using gtk_widget_set_sensitive()).
6863  *
6864  * The effective sensitivity of a widget is however determined by both its
6865  * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6866  *
6867  * Returns: %TRUE if the widget is sensitive
6868  *
6869  * Since: 2.18
6870  */
6871 gboolean
6872 gtk_widget_get_sensitive (GtkWidget *widget)
6873 {
6874   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6875
6876   return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6877 }
6878
6879 /**
6880  * gtk_widget_is_sensitive:
6881  * @widget: a #GtkWidget
6882  *
6883  * Returns the widget's effective sensitivity, which means
6884  * it is sensitive itself and also its parent widget is sensntive
6885  *
6886  * Returns: %TRUE if the widget is effectively sensitive
6887  *
6888  * Since: 2.18
6889  */
6890 gboolean
6891 gtk_widget_is_sensitive (GtkWidget *widget)
6892 {
6893   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6894
6895   return (gtk_widget_get_sensitive (widget) &&
6896           (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6897 }
6898
6899 /**
6900  * gtk_widget_set_parent:
6901  * @widget: a #GtkWidget
6902  * @parent: parent container
6903  *
6904  * This function is useful only when implementing subclasses of 
6905  * #GtkContainer.
6906  * Sets the container as the parent of @widget, and takes care of
6907  * some details such as updating the state and style of the child
6908  * to reflect its new location. The opposite function is
6909  * gtk_widget_unparent().
6910  **/
6911 void
6912 gtk_widget_set_parent (GtkWidget *widget,
6913                        GtkWidget *parent)
6914 {
6915   GtkWidgetPrivate *priv;
6916   GtkStateData data;
6917   
6918   g_return_if_fail (GTK_IS_WIDGET (widget));
6919   g_return_if_fail (GTK_IS_WIDGET (parent));
6920   g_return_if_fail (widget != parent);
6921
6922   priv = widget->priv;
6923
6924   if (priv->parent != NULL)
6925     {
6926       g_warning ("Can't set a parent on widget which has a parent\n");
6927       return;
6928     }
6929   if (gtk_widget_is_toplevel (widget))
6930     {
6931       g_warning ("Can't set a parent on a toplevel widget\n");
6932       return;
6933     }
6934
6935   /* keep this function in sync with gtk_menu_attach_to_widget()
6936    */
6937
6938   g_object_ref_sink (widget);
6939   priv->parent = parent;
6940
6941   if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6942     data.state = gtk_widget_get_state (parent);
6943   else
6944     data.state = gtk_widget_get_state (widget);
6945   data.state_restoration = FALSE;
6946   data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6947   data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6948
6949   gtk_widget_propagate_state (widget, &data);
6950   
6951   gtk_widget_reset_rc_styles (widget);
6952
6953   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6954   if (GTK_WIDGET_ANCHORED (priv->parent))
6955     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6956   g_object_notify (G_OBJECT (widget), "parent");
6957
6958   /* Enforce realized/mapped invariants
6959    */
6960   if (gtk_widget_get_realized (priv->parent))
6961     gtk_widget_realize (widget);
6962
6963   if (gtk_widget_get_visible (priv->parent) &&
6964       gtk_widget_get_visible (widget))
6965     {
6966       if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6967           gtk_widget_get_mapped (priv->parent))
6968         gtk_widget_map (widget);
6969
6970       gtk_widget_queue_resize (widget);
6971     }
6972 }
6973
6974 /**
6975  * gtk_widget_get_parent:
6976  * @widget: a #GtkWidget
6977  *
6978  * Returns the parent container of @widget.
6979  *
6980  * Return value: (transfer none): the parent container of @widget, or %NULL
6981  **/
6982 GtkWidget *
6983 gtk_widget_get_parent (GtkWidget *widget)
6984 {
6985   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6986
6987   return widget->priv->parent;
6988 }
6989
6990 /*****************************************
6991  * Widget styles
6992  * see docs/styles.txt
6993  *****************************************/
6994
6995 /**
6996  * gtk_widget_style_attach:
6997  * @widget: a #GtkWidget
6998  *
6999  * This function attaches the widget's #GtkStyle to the widget's
7000  * #GdkWindow. It is a replacement for
7001  *
7002  * <programlisting>
7003  * widget->style = gtk_style_attach (widget->style, widget->window);
7004  * </programlisting>
7005  *
7006  * and should only ever be called in a derived widget's "realize"
7007  * implementation which does not chain up to its parent class'
7008  * "realize" implementation, because one of the parent classes
7009  * (finally #GtkWidget) would attach the style itself.
7010  *
7011  * Since: 2.20
7012  **/
7013 void
7014 gtk_widget_style_attach (GtkWidget *widget)
7015 {
7016   GtkWidgetPrivate *priv;
7017
7018   g_return_if_fail (GTK_IS_WIDGET (widget));
7019   g_return_if_fail (gtk_widget_get_realized (widget));
7020
7021   priv = widget->priv;
7022
7023   priv->style = gtk_style_attach (priv->style, priv->window);
7024 }
7025
7026 /**
7027  * gtk_widget_has_rc_style:
7028  * @widget: a #GtkWidget
7029  *
7030  * Determines if the widget style has been looked up through the rc mechanism.
7031  *
7032  * Returns: %TRUE if the widget has been looked up through the rc
7033  *   mechanism, %FALSE otherwise.
7034  *
7035  * Since: 2.20
7036  **/
7037 gboolean
7038 gtk_widget_has_rc_style (GtkWidget *widget)
7039 {
7040   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7041
7042   return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
7043 }
7044
7045 /**
7046  * gtk_widget_set_style:
7047  * @widget: a #GtkWidget
7048  * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7049  *         gtk_widget_set_style() and go back to the default style
7050  *
7051  * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7052  * want to use this function; it interacts badly with themes, because
7053  * themes work by replacing the #GtkStyle. Instead, use
7054  * gtk_widget_modify_style().
7055  **/
7056 void
7057 gtk_widget_set_style (GtkWidget *widget,
7058                       GtkStyle  *style)
7059 {
7060   g_return_if_fail (GTK_IS_WIDGET (widget));
7061
7062   if (style)
7063     {
7064       gboolean initial_emission;
7065
7066       initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7067       
7068       GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
7069       GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
7070       
7071       gtk_widget_set_style_internal (widget, style, initial_emission);
7072     }
7073   else
7074     {
7075       if (GTK_WIDGET_USER_STYLE (widget))
7076         gtk_widget_reset_rc_style (widget);
7077     }
7078 }
7079
7080 /**
7081  * gtk_widget_ensure_style:
7082  * @widget: a #GtkWidget
7083  *
7084  * Ensures that @widget has a style (@widget->style). Not a very useful
7085  * function; most of the time, if you want the style, the widget is
7086  * realized, and realized widgets are guaranteed to have a style
7087  * already.
7088  **/
7089 void
7090 gtk_widget_ensure_style (GtkWidget *widget)
7091 {
7092   g_return_if_fail (GTK_IS_WIDGET (widget));
7093
7094   if (!GTK_WIDGET_USER_STYLE (widget) &&
7095       !gtk_widget_has_rc_style (widget))
7096     gtk_widget_reset_rc_style (widget);
7097 }
7098
7099 /* Look up the RC style for this widget, unsetting any user style that
7100  * may be in effect currently
7101  **/
7102 static void
7103 gtk_widget_reset_rc_style (GtkWidget *widget)
7104 {
7105   GtkWidgetPrivate *priv = widget->priv;
7106   GtkStyle *new_style = NULL;
7107   gboolean initial_emission;
7108   
7109   initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7110
7111   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7112   GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7113   
7114   if (gtk_widget_has_screen (widget))
7115     new_style = gtk_rc_get_style (widget);
7116   if (!new_style)
7117     new_style = gtk_widget_get_default_style ();
7118
7119   if (initial_emission || new_style != priv->style)
7120     gtk_widget_set_style_internal (widget, new_style, initial_emission);
7121 }
7122
7123 /**
7124  * gtk_widget_get_style:
7125  * @widget: a #GtkWidget
7126  * 
7127  * Simply an accessor function that returns @widget->style.
7128  *
7129  * Return value: (transfer none): the widget's #GtkStyle
7130  **/
7131 GtkStyle*
7132 gtk_widget_get_style (GtkWidget *widget)
7133 {
7134   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7135
7136   return widget->priv->style;
7137 }
7138
7139 /**
7140  * gtk_widget_modify_style:
7141  * @widget: a #GtkWidget
7142  * @style: the #GtkRcStyle holding the style modifications
7143  * 
7144  * Modifies style values on the widget. Modifications made using this
7145  * technique take precedence over style values set via an RC file,
7146  * however, they will be overriden if a style is explicitely set on
7147  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7148  * is designed so each field can either be set or unset, so it is
7149  * possible, using this function, to modify some style values and
7150  * leave the others unchanged.
7151  *
7152  * Note that modifications made with this function are not cumulative
7153  * with previous calls to gtk_widget_modify_style() or with such
7154  * functions as gtk_widget_modify_fg(). If you wish to retain
7155  * previous values, you must first call gtk_widget_get_modifier_style(),
7156  * make your modifications to the returned style, then call
7157  * gtk_widget_modify_style() with that style. On the other hand,
7158  * if you first call gtk_widget_modify_style(), subsequent calls
7159  * to such functions gtk_widget_modify_fg() will have a cumulative
7160  * effect with the initial modifications.
7161  **/
7162 void       
7163 gtk_widget_modify_style (GtkWidget      *widget,
7164                          GtkRcStyle     *style)
7165 {
7166   g_return_if_fail (GTK_IS_WIDGET (widget));
7167   g_return_if_fail (GTK_IS_RC_STYLE (style));
7168   
7169   g_object_set_qdata_full (G_OBJECT (widget),
7170                            quark_rc_style,
7171                            gtk_rc_style_copy (style),
7172                            (GDestroyNotify) g_object_unref);
7173
7174   /* note that "style" may be invalid here if it was the old
7175    * modifier style and the only reference was our own.
7176    */
7177   
7178   if (gtk_widget_has_rc_style (widget))
7179     gtk_widget_reset_rc_style (widget);
7180 }
7181
7182 /**
7183  * gtk_widget_get_modifier_style:
7184  * @widget: a #GtkWidget
7185  * 
7186  * Returns the current modifier style for the widget. (As set by
7187  * gtk_widget_modify_style().) If no style has previously set, a new
7188  * #GtkRcStyle will be created with all values unset, and set as the
7189  * modifier style for the widget. If you make changes to this rc
7190  * style, you must call gtk_widget_modify_style(), passing in the
7191  * returned rc style, to make sure that your changes take effect.
7192  *
7193  * Caution: passing the style back to gtk_widget_modify_style() will
7194  * normally end up destroying it, because gtk_widget_modify_style() copies
7195  * the passed-in style and sets the copy as the new modifier style,
7196  * thus dropping any reference to the old modifier style. Add a reference
7197  * to the modifier style if you want to keep it alive.
7198  *
7199  * Return value: (transfer none): the modifier style for the widget. This rc style is
7200  *   owned by the widget. If you want to keep a pointer to value this
7201  *   around, you must add a refcount using g_object_ref().
7202  **/
7203 GtkRcStyle *
7204 gtk_widget_get_modifier_style (GtkWidget      *widget)
7205 {
7206   GtkRcStyle *rc_style;
7207   
7208   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7209
7210   rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7211
7212   if (!rc_style)
7213     {
7214       rc_style = gtk_rc_style_new ();
7215       g_object_set_qdata_full (G_OBJECT (widget),
7216                                quark_rc_style,
7217                                rc_style,
7218                                (GDestroyNotify) g_object_unref);
7219     }
7220
7221   return rc_style;
7222 }
7223
7224 static void
7225 gtk_widget_modify_color_component (GtkWidget      *widget,
7226                                    GtkRcFlags      component,
7227                                    GtkStateType    state,
7228                                    const GdkColor *color)
7229 {
7230   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
7231
7232   if (color)
7233     {
7234       switch (component)
7235         {
7236         case GTK_RC_FG:
7237           rc_style->fg[state] = *color;
7238           break;
7239         case GTK_RC_BG:
7240           rc_style->bg[state] = *color;
7241           break;
7242         case GTK_RC_TEXT:
7243           rc_style->text[state] = *color;
7244           break;
7245         case GTK_RC_BASE:
7246           rc_style->base[state] = *color;
7247           break;
7248         default:
7249           g_assert_not_reached();
7250         }
7251       
7252       rc_style->color_flags[state] |= component;
7253     }
7254   else
7255     rc_style->color_flags[state] &= ~component;
7256
7257   gtk_widget_modify_style (widget, rc_style);
7258 }
7259
7260 /**
7261  * gtk_widget_modify_symbolic_color:
7262  * @widget: a #GtkWidget
7263  * @name: the name of the symbolic color to modify
7264  * @color: (allow-none): the color to assign (does not need to be allocated),
7265  *         or %NULL to undo the effect of previous calls to
7266  *         of gtk_widget_modify_symbolic_color().
7267  *
7268  * Sets a symbolic color for a widget.
7269  * All other style values are left untouched. See also
7270  * gtk_widget_modify_style().
7271  *
7272  * Since: 3.0
7273  **/
7274 void
7275 gtk_widget_modify_symbolic_color (GtkWidget      *widget,
7276                                   const gchar    *name,
7277                                   const GdkColor *color)
7278 {
7279   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7280
7281   _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7282
7283   gtk_widget_modify_style (widget, rc_style);
7284 }
7285
7286 /**
7287  * gtk_widget_modify_fg:
7288  * @widget: a #GtkWidget
7289  * @state: the state for which to set the foreground color
7290  * @color: (allow-none): the color to assign (does not need to be allocated),
7291  *         or %NULL to undo the effect of previous calls to
7292  *         of gtk_widget_modify_fg().
7293  *
7294  * Sets the foreground color for a widget in a particular state.
7295  * All other style values are left untouched. See also
7296  * gtk_widget_modify_style().
7297  **/
7298 void
7299 gtk_widget_modify_fg (GtkWidget      *widget,
7300                       GtkStateType    state,
7301                       const GdkColor *color)
7302 {
7303   g_return_if_fail (GTK_IS_WIDGET (widget));
7304   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7305
7306   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7307 }
7308
7309 /**
7310  * gtk_widget_modify_bg:
7311  * @widget: a #GtkWidget
7312  * @state: the state for which to set the background color
7313  * @color: (allow-none): the color to assign (does not need to be allocated),
7314  *         or %NULL to undo the effect of previous calls to
7315  *         of gtk_widget_modify_bg().
7316  *
7317  * Sets the background color for a widget in a particular state.
7318  * All other style values are left untouched. See also
7319  * gtk_widget_modify_style(). 
7320  *
7321  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7322  * draw on their parent container's window and thus may not draw any 
7323  * background themselves. This is the case for e.g. #GtkLabel. To modify 
7324  * the background of such widgets, you have to set the background color 
7325  * on their parent; if you want to set the background of a rectangular 
7326  * area around a label, try placing the label in a #GtkEventBox widget 
7327  * and setting the background color on that.
7328  **/
7329 void
7330 gtk_widget_modify_bg (GtkWidget      *widget,
7331                       GtkStateType    state,
7332                       const GdkColor *color)
7333 {
7334   g_return_if_fail (GTK_IS_WIDGET (widget));
7335   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7336
7337   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7338 }
7339
7340 /**
7341  * gtk_widget_modify_text:
7342  * @widget: a #GtkWidget
7343  * @state: the state for which to set the text color
7344  * @color: (allow-none): the color to assign (does not need to be allocated),
7345  *         or %NULL to undo the effect of previous calls to
7346  *         of gtk_widget_modify_text().
7347  *
7348  * Sets the text color for a widget in a particular state.  All other
7349  * style values are left untouched. The text color is the foreground
7350  * color used along with the base color (see gtk_widget_modify_base())
7351  * for widgets such as #GtkEntry and #GtkTextView. See also
7352  * gtk_widget_modify_style().
7353  **/
7354 void
7355 gtk_widget_modify_text (GtkWidget      *widget,
7356                         GtkStateType    state,
7357                         const GdkColor *color)
7358 {
7359   g_return_if_fail (GTK_IS_WIDGET (widget));
7360   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7361
7362   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7363 }
7364
7365 /**
7366  * gtk_widget_modify_base:
7367  * @widget: a #GtkWidget
7368  * @state: the state for which to set the base color
7369  * @color: (allow-none): the color to assign (does not need to be allocated),
7370  *         or %NULL to undo the effect of previous calls to
7371  *         of gtk_widget_modify_base().
7372  *
7373  * Sets the base color for a widget in a particular state.
7374  * All other style values are left untouched. The base color
7375  * is the background color used along with the text color
7376  * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7377  * and #GtkTextView. See also gtk_widget_modify_style().
7378  *
7379  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7380  * draw on their parent container's window and thus may not draw any 
7381  * background themselves. This is the case for e.g. #GtkLabel. To modify 
7382  * the background of such widgets, you have to set the base color on their 
7383  * parent; if you want to set the background of a rectangular area around 
7384  * a label, try placing the label in a #GtkEventBox widget and setting 
7385  * the base color on that.
7386  **/
7387 void
7388 gtk_widget_modify_base (GtkWidget      *widget,
7389                         GtkStateType    state,
7390                         const GdkColor *color)
7391 {
7392   g_return_if_fail (GTK_IS_WIDGET (widget));
7393   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7394
7395   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7396 }
7397
7398 static void
7399 modify_color_property (GtkWidget      *widget,
7400                        GtkRcStyle     *rc_style,
7401                        const char     *name,
7402                        const GdkColor *color)
7403 {
7404   GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7405   GQuark property_name = g_quark_from_string (name);
7406
7407   if (color)
7408     {
7409       GtkRcProperty rc_property = {0};
7410       char *color_name;
7411
7412       rc_property.type_name = type_name;
7413       rc_property.property_name = property_name;
7414       rc_property.origin = NULL;
7415
7416       color_name = gdk_color_to_string (color);
7417       g_value_init (&rc_property.value, G_TYPE_STRING);
7418       g_value_take_string (&rc_property.value, color_name);
7419
7420       _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7421
7422       g_value_unset (&rc_property.value);
7423     }
7424   else
7425     _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7426 }
7427
7428 /**
7429  * gtk_widget_modify_cursor:
7430  * @widget: a #GtkWidget
7431  * @primary: the color to use for primary cursor (does not need to be
7432  *           allocated), or %NULL to undo the effect of previous calls to
7433  *           of gtk_widget_modify_cursor().
7434  * @secondary: the color to use for secondary cursor (does not need to be
7435  *             allocated), or %NULL to undo the effect of previous calls to
7436  *             of gtk_widget_modify_cursor().
7437  *
7438  * Sets the cursor color to use in a widget, overriding the
7439  * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7440  * style properties. All other style values are left untouched. 
7441  * See also gtk_widget_modify_style().
7442  *
7443  * Since: 2.12
7444  **/
7445 void
7446 gtk_widget_modify_cursor (GtkWidget      *widget,
7447                           const GdkColor *primary,
7448                           const GdkColor *secondary)
7449 {
7450   GtkRcStyle *rc_style;
7451
7452   g_return_if_fail (GTK_IS_WIDGET (widget));
7453
7454   rc_style = gtk_widget_get_modifier_style (widget);
7455
7456   modify_color_property (widget, rc_style, "cursor-color", primary);
7457   modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7458
7459   gtk_widget_modify_style (widget, rc_style);
7460 }
7461
7462 /**
7463  * gtk_widget_modify_font:
7464  * @widget: a #GtkWidget
7465  * @font_desc: (allow-none): the font description to use, or %NULL to undo
7466  *   the effect of previous calls to gtk_widget_modify_font().
7467  *
7468  * Sets the font to use for a widget.  All other style values are left
7469  * untouched. See also gtk_widget_modify_style().
7470  **/
7471 void
7472 gtk_widget_modify_font (GtkWidget            *widget,
7473                         PangoFontDescription *font_desc)
7474 {
7475   GtkRcStyle *rc_style;
7476
7477   g_return_if_fail (GTK_IS_WIDGET (widget));
7478
7479   rc_style = gtk_widget_get_modifier_style (widget);  
7480
7481   if (rc_style->font_desc)
7482     pango_font_description_free (rc_style->font_desc);
7483
7484   if (font_desc)
7485     rc_style->font_desc = pango_font_description_copy (font_desc);
7486   else
7487     rc_style->font_desc = NULL;
7488   
7489   gtk_widget_modify_style (widget, rc_style);
7490 }
7491
7492 static void
7493 gtk_widget_real_direction_changed (GtkWidget        *widget,
7494                                    GtkTextDirection  previous_direction)
7495 {
7496   gtk_widget_queue_resize (widget);
7497 }
7498
7499 static void
7500 gtk_widget_real_style_set (GtkWidget *widget,
7501                            GtkStyle  *previous_style)
7502 {
7503   GtkWidgetPrivate *priv = widget->priv;
7504
7505   if (gtk_widget_get_realized (widget) &&
7506       gtk_widget_get_has_window (widget))
7507     gtk_style_set_background (priv->style, priv->window, priv->state);
7508 }
7509
7510 static void
7511 gtk_widget_set_style_internal (GtkWidget *widget,
7512                                GtkStyle  *style,
7513                                gboolean   initial_emission)
7514 {
7515   GtkWidgetPrivate *priv = widget->priv;
7516
7517   g_object_ref (widget);
7518   g_object_freeze_notify (G_OBJECT (widget));
7519
7520   if (priv->style != style)
7521     {
7522       GtkStyle *previous_style;
7523
7524       if (gtk_widget_get_realized (widget))
7525         {
7526           gtk_widget_reset_shapes (widget);
7527           gtk_style_detach (priv->style);
7528         }
7529
7530       previous_style = priv->style;
7531       priv->style = style;
7532       g_object_ref (priv->style);
7533
7534       if (gtk_widget_get_realized (widget))
7535         priv->style = gtk_style_attach (priv->style, priv->window);
7536
7537       gtk_widget_update_pango_context (widget);
7538       g_signal_emit (widget,
7539                      widget_signals[STYLE_SET],
7540                      0,
7541                      initial_emission ? NULL : previous_style);
7542       g_object_unref (previous_style);
7543
7544       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7545         gtk_widget_queue_resize (widget);
7546     }
7547   else if (initial_emission)
7548     {
7549       gtk_widget_update_pango_context (widget);
7550       g_signal_emit (widget,
7551                      widget_signals[STYLE_SET],
7552                      0,
7553                      NULL);
7554     }
7555   g_object_notify (G_OBJECT (widget), "style");
7556   g_object_thaw_notify (G_OBJECT (widget));
7557   g_object_unref (widget);
7558 }
7559
7560 typedef struct {
7561   GtkWidget *previous_toplevel;
7562   GdkScreen *previous_screen;
7563   GdkScreen *new_screen;
7564 } HierarchyChangedInfo;
7565
7566 static void
7567 do_screen_change (GtkWidget *widget,
7568                   GdkScreen *old_screen,
7569                   GdkScreen *new_screen)
7570 {
7571   if (old_screen != new_screen)
7572     {
7573       if (old_screen)
7574         {
7575           PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7576           if (context)
7577             g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7578         }
7579       
7580       _gtk_tooltip_hide (widget);
7581       g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7582     }
7583 }
7584
7585 static void
7586 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7587                                                 gpointer   client_data)
7588 {
7589   GtkWidgetPrivate *priv = widget->priv;
7590   HierarchyChangedInfo *info = client_data;
7591   gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7592                  (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7593
7594   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7595     {
7596       g_object_ref (widget);
7597       
7598       if (new_anchored)
7599         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7600       else
7601         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7602       
7603       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7604       do_screen_change (widget, info->previous_screen, info->new_screen);
7605       
7606       if (GTK_IS_CONTAINER (widget))
7607         gtk_container_forall (GTK_CONTAINER (widget),
7608                               gtk_widget_propagate_hierarchy_changed_recurse,
7609                               client_data);
7610       
7611       g_object_unref (widget);
7612     }
7613 }
7614
7615 /**
7616  * _gtk_widget_propagate_hierarchy_changed:
7617  * @widget: a #GtkWidget
7618  * @previous_toplevel: Previous toplevel
7619  * 
7620  * Propagates changes in the anchored state to a widget and all
7621  * children, unsetting or setting the %ANCHORED flag, and
7622  * emitting #GtkWidget::hierarchy-changed.
7623  **/
7624 void
7625 _gtk_widget_propagate_hierarchy_changed (GtkWidget    *widget,
7626                                          GtkWidget    *previous_toplevel)
7627 {
7628   GtkWidgetPrivate *priv = widget->priv;
7629   HierarchyChangedInfo info;
7630
7631   info.previous_toplevel = previous_toplevel;
7632   info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7633
7634   if (gtk_widget_is_toplevel (widget) ||
7635       (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7636     info.new_screen = gtk_widget_get_screen (widget);
7637   else
7638     info.new_screen = NULL;
7639
7640   if (info.previous_screen)
7641     g_object_ref (info.previous_screen);
7642   if (previous_toplevel)
7643     g_object_ref (previous_toplevel);
7644
7645   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7646
7647   if (previous_toplevel)
7648     g_object_unref (previous_toplevel);
7649   if (info.previous_screen)
7650     g_object_unref (info.previous_screen);
7651 }
7652
7653 static void
7654 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7655                                              gpointer   client_data)
7656 {
7657   HierarchyChangedInfo *info = client_data;
7658
7659   g_object_ref (widget);
7660   
7661   do_screen_change (widget, info->previous_screen, info->new_screen);
7662   
7663   if (GTK_IS_CONTAINER (widget))
7664     gtk_container_forall (GTK_CONTAINER (widget),
7665                           gtk_widget_propagate_screen_changed_recurse,
7666                           client_data);
7667   
7668   g_object_unref (widget);
7669 }
7670
7671 /**
7672  * gtk_widget_is_composited:
7673  * @widget: a #GtkWidget
7674  * 
7675  * Whether @widget can rely on having its alpha channel
7676  * drawn correctly. On X11 this function returns whether a
7677  * compositing manager is running for @widget's screen.
7678  *
7679  * Please note that the semantics of this call will change
7680  * in the future if used on a widget that has a composited
7681  * window in its hierarchy (as set by gdk_window_set_composited()).
7682  * 
7683  * Return value: %TRUE if the widget can rely on its alpha
7684  * channel being drawn correctly.
7685  * 
7686  * Since: 2.10
7687  */
7688 gboolean
7689 gtk_widget_is_composited (GtkWidget *widget)
7690 {
7691   GdkScreen *screen;
7692
7693   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7694   
7695   screen = gtk_widget_get_screen (widget);
7696   
7697   return gdk_screen_is_composited (screen);
7698 }
7699
7700 static void
7701 propagate_composited_changed (GtkWidget *widget,
7702                               gpointer dummy)
7703 {
7704   if (GTK_IS_CONTAINER (widget))
7705     {
7706       gtk_container_forall (GTK_CONTAINER (widget),
7707                             propagate_composited_changed,
7708                             NULL);
7709     }
7710   
7711   g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7712 }
7713
7714 void
7715 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7716 {
7717   propagate_composited_changed (widget, NULL);
7718 }
7719
7720 /**
7721  * _gtk_widget_propagate_screen_changed:
7722  * @widget: a #GtkWidget
7723  * @previous_screen: Previous screen
7724  * 
7725  * Propagates changes in the screen for a widget to all
7726  * children, emitting #GtkWidget::screen-changed.
7727  **/
7728 void
7729 _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
7730                                       GdkScreen    *previous_screen)
7731 {
7732   HierarchyChangedInfo info;
7733
7734   info.previous_screen = previous_screen;
7735   info.new_screen = gtk_widget_get_screen (widget);
7736
7737   if (previous_screen)
7738     g_object_ref (previous_screen);
7739
7740   gtk_widget_propagate_screen_changed_recurse (widget, &info);
7741
7742   if (previous_screen)
7743     g_object_unref (previous_screen);
7744 }
7745
7746 static void
7747 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7748 {
7749   if (gtk_widget_has_rc_style (widget))
7750     gtk_widget_reset_rc_style (widget);
7751   
7752   if (GTK_IS_CONTAINER (widget))
7753     gtk_container_forall (GTK_CONTAINER (widget),
7754                           reset_rc_styles_recurse,
7755                           NULL);
7756 }
7757
7758
7759 /**
7760  * gtk_widget_reset_rc_styles:
7761  * @widget: a #GtkWidget.
7762  *
7763  * Reset the styles of @widget and all descendents, so when
7764  * they are looked up again, they get the correct values
7765  * for the currently loaded RC file settings.
7766  *
7767  * This function is not useful for applications.
7768  */
7769 void
7770 gtk_widget_reset_rc_styles (GtkWidget *widget)
7771 {
7772   g_return_if_fail (GTK_IS_WIDGET (widget));
7773
7774   reset_rc_styles_recurse (widget, NULL);
7775 }
7776
7777 /**
7778  * gtk_widget_get_default_style:
7779  * 
7780  * Returns the default style used by all widgets initially.
7781  *
7782  * Returns: (transfer none): the default style. This #GtkStyle object is owned
7783  *          by GTK+ and should not be modified or freed.
7784  */
7785 GtkStyle*
7786 gtk_widget_get_default_style (void)
7787 {
7788   if (!gtk_default_style)
7789     {
7790       gtk_default_style = gtk_style_new ();
7791       g_object_ref (gtk_default_style);
7792     }
7793   
7794   return gtk_default_style;
7795 }
7796
7797 static PangoContext *
7798 gtk_widget_peek_pango_context (GtkWidget *widget)
7799 {
7800   return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7801 }
7802
7803 /**
7804  * gtk_widget_get_pango_context:
7805  * @widget: a #GtkWidget
7806  * 
7807  * Gets a #PangoContext with the appropriate font map, font description,
7808  * and base direction for this widget. Unlike the context returned
7809  * by gtk_widget_create_pango_context(), this context is owned by
7810  * the widget (it can be used until the screen for the widget changes
7811  * or the widget is removed from its toplevel), and will be updated to
7812  * match any changes to the widget's attributes.
7813  *
7814  * If you create and keep a #PangoLayout using this context, you must
7815  * deal with changes to the context by calling pango_layout_context_changed()
7816  * on the layout in response to the #GtkWidget::style-set and 
7817  * #GtkWidget::direction-changed signals for the widget.
7818  *
7819  * Return value: (transfer none): the #PangoContext for the widget.
7820  **/
7821 PangoContext *
7822 gtk_widget_get_pango_context (GtkWidget *widget)
7823 {
7824   PangoContext *context;
7825
7826   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7827   
7828   context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7829   if (!context)
7830     {
7831       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7832       g_object_set_qdata_full (G_OBJECT (widget),
7833                                quark_pango_context,
7834                                context,
7835                                g_object_unref);
7836     }
7837
7838   return context;
7839 }
7840
7841 static void
7842 update_pango_context (GtkWidget    *widget,
7843                       PangoContext *context)
7844 {
7845   GtkWidgetPrivate *priv = widget->priv;
7846
7847   pango_context_set_font_description (context, priv->style->font_desc);
7848   pango_context_set_base_dir (context,
7849                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7850                               PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7851 }
7852
7853 static void
7854 gtk_widget_update_pango_context (GtkWidget *widget)
7855 {
7856   PangoContext *context = gtk_widget_peek_pango_context (widget);
7857   
7858   if (context)
7859     {
7860       GdkScreen *screen;
7861
7862       update_pango_context (widget, context);
7863
7864       screen = gtk_widget_get_screen_unchecked (widget);
7865       if (screen)
7866         {
7867           pango_cairo_context_set_resolution (context,
7868                                               gdk_screen_get_resolution (screen));
7869           pango_cairo_context_set_font_options (context,
7870                                                 gdk_screen_get_font_options (screen));
7871         }
7872     }
7873 }
7874
7875 /**
7876  * gtk_widget_create_pango_context:
7877  * @widget: a #GtkWidget
7878  *
7879  * Creates a new #PangoContext with the appropriate font map,
7880  * font description, and base direction for drawing text for
7881  * this widget. See also gtk_widget_get_pango_context().
7882  *
7883  * Return value: (transfer full): the new #PangoContext
7884  **/
7885 PangoContext *
7886 gtk_widget_create_pango_context (GtkWidget *widget)
7887 {
7888   GdkScreen *screen;
7889   PangoContext *context;
7890
7891   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7892
7893   screen = gtk_widget_get_screen_unchecked (widget);
7894   if (!screen)
7895     {
7896       GTK_NOTE (MULTIHEAD,
7897                 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7898
7899       screen = gdk_screen_get_default ();
7900     }
7901
7902   context = gdk_pango_context_get_for_screen (screen);
7903
7904   update_pango_context (widget, context);
7905   pango_context_set_language (context, gtk_get_default_language ());
7906
7907   return context;
7908 }
7909
7910 /**
7911  * gtk_widget_create_pango_layout:
7912  * @widget: a #GtkWidget
7913  * @text: text to set on the layout (can be %NULL)
7914  *
7915  * Creates a new #PangoLayout with the appropriate font map,
7916  * font description, and base direction for drawing text for
7917  * this widget.
7918  *
7919  * If you keep a #PangoLayout created in this way around, in order to
7920  * notify the layout of changes to the base direction or font of this
7921  * widget, you must call pango_layout_context_changed() in response to
7922  * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7923  * for the widget.
7924  *
7925  * Return value: (transfer full): the new #PangoLayout
7926  **/
7927 PangoLayout *
7928 gtk_widget_create_pango_layout (GtkWidget   *widget,
7929                                 const gchar *text)
7930 {
7931   PangoLayout *layout;
7932   PangoContext *context;
7933
7934   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7935
7936   context = gtk_widget_get_pango_context (widget);
7937   layout = pango_layout_new (context);
7938
7939   if (text)
7940     pango_layout_set_text (layout, text, -1);
7941
7942   return layout;
7943 }
7944
7945 /**
7946  * gtk_widget_render_icon:
7947  * @widget: a #GtkWidget
7948  * @stock_id: a stock ID
7949  * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7950  *     render at the size of the source and don't scale (if there are
7951  *     multiple source sizes, GTK+ picks one of the available sizes).
7952  * @detail: (allow-none): render detail to pass to theme engine
7953  *
7954  * A convenience function that uses the theme engine and RC file
7955  * settings for @widget to look up @stock_id and render it to
7956  * a pixbuf. @stock_id should be a stock icon ID such as
7957  * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7958  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7959  * identifies the widget or code doing the rendering, so that
7960  * theme engines can special-case rendering for that widget or code.
7961  *
7962  * The pixels in the returned #GdkPixbuf are shared with the rest of
7963  * the application and should not be modified. The pixbuf should be freed
7964  * after use with g_object_unref().
7965  *
7966  * Return value: (transfer full): a new pixbuf, or %NULL if the
7967  *     stock ID wasn't known
7968  **/
7969 GdkPixbuf*
7970 gtk_widget_render_icon (GtkWidget      *widget,
7971                         const gchar    *stock_id,
7972                         GtkIconSize     size,
7973                         const gchar    *detail)
7974 {
7975   GtkWidgetPrivate *priv;
7976   GtkIconSet *icon_set;
7977   GdkPixbuf *retval;
7978   
7979   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7980   g_return_val_if_fail (stock_id != NULL, NULL);
7981   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7982
7983   priv = widget->priv;
7984
7985   gtk_widget_ensure_style (widget);
7986   
7987   icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7988
7989   if (icon_set == NULL)
7990     return NULL;
7991
7992   retval = gtk_icon_set_render_icon (icon_set,
7993                                      priv->style,
7994                                      gtk_widget_get_direction (widget),
7995                                      gtk_widget_get_state (widget),
7996                                      size,
7997                                      widget,
7998                                      detail);
7999
8000   return retval;
8001 }
8002
8003 /**
8004  * gtk_widget_set_parent_window:
8005  * @widget: a #GtkWidget.
8006  * @parent_window: the new parent window.
8007  *  
8008  * Sets a non default parent window for @widget.
8009  **/
8010 void
8011 gtk_widget_set_parent_window   (GtkWidget           *widget,
8012                                 GdkWindow           *parent_window)
8013 {
8014   GdkWindow *old_parent_window;
8015
8016   g_return_if_fail (GTK_IS_WIDGET (widget));
8017   
8018   old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8019                                           quark_parent_window);
8020
8021   if (parent_window != old_parent_window)
8022     {
8023       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
8024                           parent_window);
8025       if (old_parent_window)
8026         g_object_unref (old_parent_window);
8027       if (parent_window)
8028         g_object_ref (parent_window);
8029     }
8030 }
8031
8032 /**
8033  * gtk_widget_get_parent_window:
8034  * @widget: a #GtkWidget.
8035  *
8036  * Gets @widget's parent window.
8037  *
8038  * Returns: (transfer none): the parent window of @widget.
8039  **/
8040 GdkWindow *
8041 gtk_widget_get_parent_window (GtkWidget *widget)
8042 {
8043   GtkWidgetPrivate *priv;
8044   GdkWindow *parent_window;
8045
8046   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8047
8048   priv = widget->priv;
8049
8050   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8051
8052   return (parent_window != NULL) ? parent_window :
8053          (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8054 }
8055
8056
8057 /**
8058  * gtk_widget_set_child_visible:
8059  * @widget: a #GtkWidget
8060  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8061  *
8062  * Sets whether @widget should be mapped along with its when its parent
8063  * is mapped and @widget has been shown with gtk_widget_show(). 
8064  *
8065  * The child visibility can be set for widget before it is added to
8066  * a container with gtk_widget_set_parent(), to avoid mapping
8067  * children unnecessary before immediately unmapping them. However
8068  * it will be reset to its default state of %TRUE when the widget
8069  * is removed from a container.
8070  * 
8071  * Note that changing the child visibility of a widget does not
8072  * queue a resize on the widget. Most of the time, the size of
8073  * a widget is computed from all visible children, whether or
8074  * not they are mapped. If this is not the case, the container
8075  * can queue a resize itself.
8076  *
8077  * This function is only useful for container implementations and
8078  * never should be called by an application.
8079  **/
8080 void
8081 gtk_widget_set_child_visible (GtkWidget *widget,
8082                               gboolean   is_visible)
8083 {
8084   GtkWidgetPrivate *priv;
8085
8086   g_return_if_fail (GTK_IS_WIDGET (widget));
8087   g_return_if_fail (!gtk_widget_is_toplevel (widget));
8088
8089   priv = widget->priv;
8090
8091   g_object_ref (widget);
8092
8093   if (is_visible)
8094     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8095   else
8096     {
8097       GtkWidget *toplevel;
8098       
8099       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8100
8101       toplevel = gtk_widget_get_toplevel (widget);
8102       if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8103         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8104     }
8105
8106   if (priv->parent && gtk_widget_get_realized (priv->parent))
8107     {
8108       if (gtk_widget_get_mapped (priv->parent) &&
8109           GTK_WIDGET_CHILD_VISIBLE (widget) &&
8110           gtk_widget_get_visible (widget))
8111         gtk_widget_map (widget);
8112       else
8113         gtk_widget_unmap (widget);
8114     }
8115
8116   g_object_unref (widget);
8117 }
8118
8119 /**
8120  * gtk_widget_get_child_visible:
8121  * @widget: a #GtkWidget
8122  * 
8123  * Gets the value set with gtk_widget_set_child_visible().
8124  * If you feel a need to use this function, your code probably
8125  * needs reorganization. 
8126  *
8127  * This function is only useful for container implementations and
8128  * never should be called by an application.
8129  *
8130  * Return value: %TRUE if the widget is mapped with the parent.
8131  **/
8132 gboolean
8133 gtk_widget_get_child_visible (GtkWidget *widget)
8134 {
8135   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8136   
8137   return GTK_WIDGET_CHILD_VISIBLE (widget);
8138 }
8139
8140 static GdkScreen *
8141 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8142 {
8143   GtkWidget *toplevel;
8144   
8145   toplevel = gtk_widget_get_toplevel (widget);
8146
8147   if (gtk_widget_is_toplevel (toplevel))
8148     {
8149       if (GTK_IS_WINDOW (toplevel))
8150         return gtk_window_get_screen (GTK_WINDOW (toplevel));
8151       else if (GTK_IS_INVISIBLE (toplevel))
8152         return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8153     }
8154
8155   return NULL;
8156 }
8157
8158 /**
8159  * gtk_widget_get_screen:
8160  * @widget: a #GtkWidget
8161  * 
8162  * Get the #GdkScreen from the toplevel window associated with
8163  * this widget. This function can only be called after the widget
8164  * has been added to a widget hierarchy with a #GtkWindow
8165  * at the top.
8166  *
8167  * In general, you should only create screen specific
8168  * resources when a widget has been realized, and you should
8169  * free those resources when the widget is unrealized.
8170  *
8171  * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8172  *
8173  * Since: 2.2
8174  **/
8175 GdkScreen*
8176 gtk_widget_get_screen (GtkWidget *widget)
8177 {
8178   GdkScreen *screen;
8179   
8180   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8181
8182   screen = gtk_widget_get_screen_unchecked (widget);
8183
8184   if (screen)
8185     return screen;
8186   else
8187     {
8188 #if 0
8189       g_warning (G_STRLOC ": Can't get associated screen"
8190                  " for a widget unless it is inside a toplevel GtkWindow\n"
8191                  " widget type is %s associated top level type is %s",
8192                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8193                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8194 #endif
8195       return gdk_screen_get_default ();
8196     }
8197 }
8198
8199 /**
8200  * gtk_widget_has_screen:
8201  * @widget: a #GtkWidget
8202  * 
8203  * Checks whether there is a #GdkScreen is associated with
8204  * this widget. All toplevel widgets have an associated
8205  * screen, and all widgets added into a hierarchy with a toplevel
8206  * window at the top.
8207  * 
8208  * Return value: %TRUE if there is a #GdkScreen associcated
8209  *   with the widget.
8210  *
8211  * Since: 2.2
8212  **/
8213 gboolean
8214 gtk_widget_has_screen (GtkWidget *widget)
8215 {
8216   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8217
8218   return (gtk_widget_get_screen_unchecked (widget) != NULL);
8219 }
8220
8221 /**
8222  * gtk_widget_get_display:
8223  * @widget: a #GtkWidget
8224  * 
8225  * Get the #GdkDisplay for the toplevel window associated with
8226  * this widget. This function can only be called after the widget
8227  * has been added to a widget hierarchy with a #GtkWindow at the top.
8228  *
8229  * In general, you should only create display specific
8230  * resources when a widget has been realized, and you should
8231  * free those resources when the widget is unrealized.
8232  *
8233  * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8234  *
8235  * Since: 2.2
8236  **/
8237 GdkDisplay*
8238 gtk_widget_get_display (GtkWidget *widget)
8239 {
8240   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8241   
8242   return gdk_screen_get_display (gtk_widget_get_screen (widget));
8243 }
8244
8245 /**
8246  * gtk_widget_get_root_window:
8247  * @widget: a #GtkWidget
8248  * 
8249  * Get the root window where this widget is located. This function can
8250  * only be called after the widget has been added to a widget
8251  * hierarchy with #GtkWindow at the top.
8252  *
8253  * The root window is useful for such purposes as creating a popup
8254  * #GdkWindow associated with the window. In general, you should only
8255  * create display specific resources when a widget has been realized,
8256  * and you should free those resources when the widget is unrealized.
8257  *
8258  * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8259  *
8260  * Since: 2.2
8261  **/
8262 GdkWindow*
8263 gtk_widget_get_root_window (GtkWidget *widget)
8264 {
8265   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8266
8267   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8268 }
8269
8270 /**
8271  * gtk_widget_child_focus:
8272  * @widget: a #GtkWidget
8273  * @direction: direction of focus movement
8274  *
8275  * This function is used by custom widget implementations; if you're
8276  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8277  * to a particular widget, and gtk_container_set_focus_chain() to
8278  * change the focus tab order. So you may want to investigate those
8279  * functions instead.
8280  * 
8281  * gtk_widget_child_focus() is called by containers as the user moves
8282  * around the window using keyboard shortcuts. @direction indicates
8283  * what kind of motion is taking place (up, down, left, right, tab
8284  * forward, tab backward). gtk_widget_child_focus() emits the
8285  * #GtkWidget::focus signal; widgets override the default handler
8286  * for this signal in order to implement appropriate focus behavior.
8287  *
8288  * The default ::focus handler for a widget should return %TRUE if
8289  * moving in @direction left the focus on a focusable location inside
8290  * that widget, and %FALSE if moving in @direction moved the focus
8291  * outside the widget. If returning %TRUE, widgets normally
8292  * call gtk_widget_grab_focus() to place the focus accordingly;
8293  * if returning %FALSE, they don't modify the current focus location.
8294  *
8295  * Return value: %TRUE if focus ended up inside @widget
8296  **/
8297 gboolean
8298 gtk_widget_child_focus (GtkWidget       *widget,
8299                         GtkDirectionType direction)
8300 {
8301   gboolean return_val;
8302
8303   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8304
8305   if (!gtk_widget_get_visible (widget) ||
8306       !gtk_widget_is_sensitive (widget))
8307     return FALSE;
8308
8309   /* child widgets must set CAN_FOCUS, containers
8310    * don't have to though.
8311    */
8312   if (!GTK_IS_CONTAINER (widget) &&
8313       !gtk_widget_get_can_focus (widget))
8314     return FALSE;
8315   
8316   g_signal_emit (widget,
8317                  widget_signals[FOCUS],
8318                  0,
8319                  direction, &return_val);
8320
8321   return return_val;
8322 }
8323
8324 /**
8325  * gtk_widget_keynav_failed:
8326  * @widget: a #GtkWidget
8327  * @direction: direction of focus movement
8328  *
8329  * This function should be called whenever keyboard navigation within
8330  * a single widget hits a boundary. The function emits the
8331  * #GtkWidget::keynav-failed signal on the widget and its return
8332  * value should be interpreted in a way similar to the return value of
8333  * gtk_widget_child_focus():
8334  *
8335  * When %TRUE is returned, stay in the widget, the failed keyboard
8336  * navigation is Ok and/or there is nowhere we can/should move the
8337  * focus to.
8338  *
8339  * When %FALSE is returned, the caller should continue with keyboard
8340  * navigation outside the widget, e.g. by calling
8341  * gtk_widget_child_focus() on the widget's toplevel.
8342  *
8343  * The default ::keynav-failed handler returns %TRUE for 
8344  * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other 
8345  * values of #GtkDirectionType, it looks at the 
8346  * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE 
8347  * if the setting is %TRUE. This way the entire user interface
8348  * becomes cursor-navigatable on input devices such as mobile phones
8349  * which only have cursor keys but no tab key.
8350  *
8351  * Whenever the default handler returns %TRUE, it also calls
8352  * gtk_widget_error_bell() to notify the user of the failed keyboard
8353  * navigation.
8354  *
8355  * A use case for providing an own implementation of ::keynav-failed 
8356  * (either by connecting to it or by overriding it) would be a row of
8357  * #GtkEntry widgets where the user should be able to navigate the
8358  * entire row with the cursor keys, as e.g. known from user interfaces 
8359  * that require entering license keys.
8360  *
8361  * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8362  *               if the emitting widget should try to handle the keyboard
8363  *               navigation attempt in its parent container(s).
8364  *
8365  * Since: 2.12
8366  **/
8367 gboolean
8368 gtk_widget_keynav_failed (GtkWidget        *widget,
8369                           GtkDirectionType  direction)
8370 {
8371   gboolean return_val;
8372
8373   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8374
8375   g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8376                  direction, &return_val);
8377
8378   return return_val;
8379 }
8380
8381 /**
8382  * gtk_widget_error_bell:
8383  * @widget: a #GtkWidget
8384  *
8385  * Notifies the user about an input-related error on this widget. 
8386  * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8387  * gdk_window_beep(), otherwise it does nothing.
8388  *
8389  * Note that the effect of gdk_window_beep() can be configured in many
8390  * ways, depending on the windowing backend and the desktop environment
8391  * or window manager that is used.
8392  *
8393  * Since: 2.12
8394  **/
8395 void
8396 gtk_widget_error_bell (GtkWidget *widget)
8397 {
8398   GtkWidgetPrivate *priv;
8399   GtkSettings* settings;
8400   gboolean beep;
8401
8402   g_return_if_fail (GTK_IS_WIDGET (widget));
8403
8404   priv = widget->priv;
8405
8406   settings = gtk_widget_get_settings (widget);
8407   if (!settings)
8408     return;
8409
8410   g_object_get (settings,
8411                 "gtk-error-bell", &beep,
8412                 NULL);
8413
8414   if (beep && priv->window)
8415     gdk_window_beep (priv->window);
8416 }
8417
8418 static void
8419 gtk_widget_set_usize_internal (GtkWidget *widget,
8420                                gint       width,
8421                                gint       height)
8422 {
8423   GtkWidgetAuxInfo *aux_info;
8424   gboolean changed = FALSE;
8425   
8426   g_object_freeze_notify (G_OBJECT (widget));
8427
8428   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8429   
8430   if (width > -2 && aux_info->width != width)
8431     {
8432       g_object_notify (G_OBJECT (widget), "width-request");
8433       aux_info->width = width;
8434       changed = TRUE;
8435     }
8436   if (height > -2 && aux_info->height != height)
8437     {
8438       g_object_notify (G_OBJECT (widget), "height-request");  
8439       aux_info->height = height;
8440       changed = TRUE;
8441     }
8442   
8443   if (gtk_widget_get_visible (widget) && changed)
8444     gtk_widget_queue_resize (widget);
8445
8446   g_object_thaw_notify (G_OBJECT (widget));
8447 }
8448
8449 /**
8450  * gtk_widget_set_size_request:
8451  * @widget: a #GtkWidget
8452  * @width: width @widget should request, or -1 to unset
8453  * @height: height @widget should request, or -1 to unset
8454  *
8455  * Sets the minimum size of a widget; that is, the widget's size
8456  * request will be @width by @height. You can use this function to
8457  * force a widget to be either larger or smaller than it normally
8458  * would be.
8459  *
8460  * In most cases, gtk_window_set_default_size() is a better choice for
8461  * toplevel windows than this function; setting the default size will
8462  * still allow users to shrink the window. Setting the size request
8463  * will force them to leave the window at least as large as the size
8464  * request. When dealing with window sizes,
8465  * gtk_window_set_geometry_hints() can be a useful function as well.
8466  * 
8467  * Note the inherent danger of setting any fixed size - themes,
8468  * translations into other languages, different fonts, and user action
8469  * can all change the appropriate size for a given widget. So, it's
8470  * basically impossible to hardcode a size that will always be
8471  * correct.
8472  *
8473  * The size request of a widget is the smallest size a widget can
8474  * accept while still functioning well and drawing itself correctly.
8475  * However in some strange cases a widget may be allocated less than
8476  * its requested size, and in many cases a widget may be allocated more
8477  * space than it requested.
8478  *
8479  * If the size request in a given direction is -1 (unset), then
8480  * the "natural" size request of the widget will be used instead.
8481  *
8482  * Widgets can't actually be allocated a size less than 1 by 1, but
8483  * you can pass 0,0 to this function to mean "as small as possible."
8484  *
8485  * The size request set here does not include any margin from the
8486  * #GtkWidget properties margin-left, margin-right, margin-top, and
8487  * margin-bottom, but it does include pretty much all other padding
8488  * or border properties set by any subclass of #GtkWidget.
8489  **/
8490 void
8491 gtk_widget_set_size_request (GtkWidget *widget,
8492                              gint       width,
8493                              gint       height)
8494 {
8495   g_return_if_fail (GTK_IS_WIDGET (widget));
8496   g_return_if_fail (width >= -1);
8497   g_return_if_fail (height >= -1);
8498
8499   if (width == 0)
8500     width = 1;
8501   if (height == 0)
8502     height = 1;
8503   
8504   gtk_widget_set_usize_internal (widget, width, height);
8505 }
8506
8507
8508 /**
8509  * gtk_widget_get_size_request:
8510  * @widget: a #GtkWidget
8511  * @width: (out) (allow-none): return location for width, or %NULL
8512  * @height: (out) (allow-none): return location for height, or %NULL
8513  *
8514  * Gets the size request that was explicitly set for the widget using
8515  * gtk_widget_set_size_request(). A value of -1 stored in @width or
8516  * @height indicates that that dimension has not been set explicitly
8517  * and the natural requisition of the widget will be used intead. See
8518  * gtk_widget_set_size_request(). To get the size a widget will
8519  * actually request, call gtk_size_request_get_size() instead of
8520  * this function.
8521  **/
8522 void
8523 gtk_widget_get_size_request (GtkWidget *widget,
8524                              gint      *width,
8525                              gint      *height)
8526 {
8527   const GtkWidgetAuxInfo *aux_info;
8528
8529   g_return_if_fail (GTK_IS_WIDGET (widget));
8530
8531   aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8532
8533   if (width)
8534     *width = aux_info->width;
8535
8536   if (height)
8537     *height = aux_info->height;
8538 }
8539
8540 /**
8541  * gtk_widget_set_events:
8542  * @widget: a #GtkWidget
8543  * @events: event mask
8544  *
8545  * Sets the event mask (see #GdkEventMask) for a widget. The event
8546  * mask determines which events a widget will receive. Keep in mind
8547  * that different widgets have different default event masks, and by
8548  * changing the event mask you may disrupt a widget's functionality,
8549  * so be careful. This function must be called while a widget is
8550  * unrealized. Consider gtk_widget_add_events() for widgets that are
8551  * already realized, or if you want to preserve the existing event
8552  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8553  * to get events on those widgets, place them inside a #GtkEventBox
8554  * and receive events on the event box.
8555  **/
8556 void
8557 gtk_widget_set_events (GtkWidget *widget,
8558                        gint       events)
8559 {
8560   g_return_if_fail (GTK_IS_WIDGET (widget));
8561   g_return_if_fail (!gtk_widget_get_realized (widget));
8562   
8563   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8564                       GINT_TO_POINTER (events));
8565   g_object_notify (G_OBJECT (widget), "events");
8566 }
8567
8568 /**
8569  * gtk_widget_set_device_events:
8570  * @widget: a #GtkWidget
8571  * @device: a #GdkDevice
8572  * @events: event mask
8573  *
8574  * Sets the device event mask (see #GdkEventMask) for a widget. The event
8575  * mask determines which events a widget will receive from @device. Keep
8576  * in mind that different widgets have different default event masks, and by
8577  * changing the event mask you may disrupt a widget's functionality,
8578  * so be careful. This function must be called while a widget is
8579  * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8580  * already realized, or if you want to preserve the existing event
8581  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8582  * to get events on those widgets, place them inside a #GtkEventBox
8583  * and receive events on the event box.
8584  *
8585  * Since: 3.0
8586  **/
8587 void
8588 gtk_widget_set_device_events (GtkWidget    *widget,
8589                               GdkDevice    *device,
8590                               GdkEventMask  events)
8591 {
8592   GHashTable *device_events;
8593
8594   g_return_if_fail (GTK_IS_WIDGET (widget));
8595   g_return_if_fail (GDK_IS_DEVICE (device));
8596   g_return_if_fail (!gtk_widget_get_realized (widget));
8597
8598   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8599
8600   if (G_UNLIKELY (!device_events))
8601     {
8602       device_events = g_hash_table_new (NULL, NULL);
8603       g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8604                                (GDestroyNotify) g_hash_table_unref);
8605     }
8606
8607   g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8608 }
8609
8610 static void
8611 gtk_widget_add_events_internal_list (GtkWidget *widget,
8612                                      GdkDevice *device,
8613                                      gint       events,
8614                                      GList     *window_list)
8615 {
8616   GList *l;
8617
8618   for (l = window_list; l != NULL; l = l->next)
8619     {
8620       GdkWindow *window = l->data;
8621       gpointer user_data;
8622
8623       gdk_window_get_user_data (window, &user_data);
8624       if (user_data == widget)
8625         {
8626           GList *children;
8627
8628           if (device)
8629             gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8630           else
8631             gdk_window_set_events (window, gdk_window_get_events (window) | events);
8632
8633           children = gdk_window_get_children (window);
8634           gtk_widget_add_events_internal_list (widget, device, events, children);
8635           g_list_free (children);
8636         }
8637     }
8638 }
8639
8640 static void
8641 gtk_widget_add_events_internal (GtkWidget *widget,
8642                                 GdkDevice *device,
8643                                 gint       events)
8644 {
8645   GtkWidgetPrivate *priv = widget->priv;
8646   GList *window_list;
8647
8648   if (!gtk_widget_get_has_window (widget))
8649     window_list = gdk_window_get_children (priv->window);
8650   else
8651     window_list = g_list_prepend (NULL, priv->window);
8652
8653   gtk_widget_add_events_internal_list (widget, device, events, window_list);
8654
8655   g_list_free (window_list);
8656 }
8657
8658 /**
8659  * gtk_widget_add_events:
8660  * @widget: a #GtkWidget
8661  * @events: an event mask, see #GdkEventMask
8662  *
8663  * Adds the events in the bitfield @events to the event mask for
8664  * @widget. See gtk_widget_set_events() for details.
8665  **/
8666 void
8667 gtk_widget_add_events (GtkWidget *widget,
8668                        gint       events)
8669 {
8670   gint old_events;
8671
8672   g_return_if_fail (GTK_IS_WIDGET (widget));
8673
8674   old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8675   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8676                       GINT_TO_POINTER (old_events | events));
8677
8678   if (gtk_widget_get_realized (widget))
8679     gtk_widget_add_events_internal (widget, NULL, events);
8680
8681   g_object_notify (G_OBJECT (widget), "events");
8682 }
8683
8684 /**
8685  * gtk_widget_add_device_events:
8686  * @widget: a #GtkWidget
8687  * @device: a #GdkDevice
8688  * @events: an event mask, see #GdkEventMask
8689  *
8690  * Adds the device events in the bitfield @events to the event mask for
8691  * @widget. See gtk_widget_set_device_events() for details.
8692  *
8693  * Since: 3.0
8694  **/
8695 void
8696 gtk_widget_add_device_events (GtkWidget    *widget,
8697                               GdkDevice    *device,
8698                               GdkEventMask  events)
8699 {
8700   GdkEventMask old_events;
8701   GHashTable *device_events;
8702
8703   g_return_if_fail (GTK_IS_WIDGET (widget));
8704   g_return_if_fail (GDK_IS_DEVICE (device));
8705
8706   old_events = gtk_widget_get_device_events (widget, device);
8707
8708   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8709
8710   if (G_UNLIKELY (!device_events))
8711     {
8712       device_events = g_hash_table_new (NULL, NULL);
8713       g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8714                                (GDestroyNotify) g_hash_table_unref);
8715     }
8716
8717   g_hash_table_insert (device_events, device,
8718                        GUINT_TO_POINTER (old_events | events));
8719
8720   if (gtk_widget_get_realized (widget))
8721     gtk_widget_add_events_internal (widget, device, events);
8722
8723   g_object_notify (G_OBJECT (widget), "events");
8724 }
8725
8726 /**
8727  * gtk_widget_set_extension_events:
8728  * @widget: a #GtkWidget
8729  * @mode: bitfield of extension events to receive
8730  *
8731  * Sets the extension events mask to @mode. See #GdkExtensionMode
8732  * and gdk_input_set_extension_events().
8733  **/
8734 void
8735 gtk_widget_set_extension_events (GtkWidget *widget,
8736                                  GdkExtensionMode mode)
8737 {
8738   g_return_if_fail (GTK_IS_WIDGET (widget));
8739
8740   if (gtk_widget_get_realized (widget))
8741     gtk_widget_set_extension_events_internal (widget, mode, NULL);
8742
8743   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8744                       GINT_TO_POINTER (mode));
8745   g_object_notify (G_OBJECT (widget), "extension-events");
8746 }
8747
8748 /**
8749  * gtk_widget_get_toplevel:
8750  * @widget: a #GtkWidget
8751  * 
8752  * This function returns the topmost widget in the container hierarchy
8753  * @widget is a part of. If @widget has no parent widgets, it will be
8754  * returned as the topmost widget. No reference will be added to the
8755  * returned widget; it should not be unreferenced.
8756  *
8757  * Note the difference in behavior vs. gtk_widget_get_ancestor();
8758  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
8759  * would return
8760  * %NULL if @widget wasn't inside a toplevel window, and if the
8761  * window was inside a #GtkWindow-derived widget which was in turn
8762  * inside the toplevel #GtkWindow. While the second case may
8763  * seem unlikely, it actually happens when a #GtkPlug is embedded
8764  * inside a #GtkSocket within the same application.
8765  * 
8766  * To reliably find the toplevel #GtkWindow, use
8767  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8768  * is set on the result.
8769  * |[
8770  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8771  *  if (gtk_widget_is_toplevel (toplevel))
8772  *    {
8773  *      /&ast; Perform action on toplevel. &ast;/
8774  *    }
8775  * ]|
8776  *
8777  * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8778  *    if there's no ancestor.
8779  **/
8780 GtkWidget*
8781 gtk_widget_get_toplevel (GtkWidget *widget)
8782 {
8783   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8784
8785   while (widget->priv->parent)
8786     widget = widget->priv->parent;
8787
8788   return widget;
8789 }
8790
8791 /**
8792  * gtk_widget_get_ancestor:
8793  * @widget: a #GtkWidget
8794  * @widget_type: ancestor type
8795  * 
8796  * Gets the first ancestor of @widget with type @widget_type. For example,
8797  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets 
8798  * the first #GtkBox that's an ancestor of @widget. No reference will be 
8799  * added to the returned widget; it should not be unreferenced. See note 
8800  * about checking for a toplevel #GtkWindow in the docs for 
8801  * gtk_widget_get_toplevel().
8802  * 
8803  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
8804  * considers @widget to be an ancestor of itself.
8805  *
8806  * Return value: (transfer none): the ancestor widget, or %NULL if not found
8807  **/
8808 GtkWidget*
8809 gtk_widget_get_ancestor (GtkWidget *widget,
8810                          GType      widget_type)
8811 {
8812   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8813
8814   while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8815     widget = widget->priv->parent;
8816
8817   if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8818     return NULL;
8819   
8820   return widget;
8821 }
8822
8823 /**
8824  * gtk_widget_get_visual:
8825  * @widget: a #GtkWidget
8826  * 
8827  * Gets the visual that will be used to render @widget.
8828  *
8829  * Return value: (transfer none): the visual for @widget
8830  **/
8831 GdkVisual*
8832 gtk_widget_get_visual (GtkWidget *widget)
8833 {
8834   GtkWidget *w;
8835
8836   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8837
8838   for (w = widget; w != NULL; w = w->priv->parent)
8839     {
8840       if (gtk_widget_get_has_window (w) &&
8841           w->priv->window)
8842         return gdk_window_get_visual (w->priv->window);
8843
8844       if (GTK_IS_WINDOW (w))
8845         return _gtk_window_get_visual (GTK_WINDOW (w));
8846     }
8847
8848   return gdk_screen_get_system_visual (gdk_screen_get_default ());
8849 }
8850
8851 /**
8852  * gtk_widget_get_settings:
8853  * @widget: a #GtkWidget
8854  * 
8855  * Gets the settings object holding the settings (global property
8856  * settings, RC file information, etc) used for this widget.
8857  *
8858  * Note that this function can only be called when the #GtkWidget
8859  * is attached to a toplevel, since the settings object is specific
8860  * to a particular #GdkScreen.
8861  *
8862  * Return value: (transfer none): the relevant #GtkSettings object
8863  **/
8864 GtkSettings*
8865 gtk_widget_get_settings (GtkWidget *widget)
8866 {
8867   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8868   
8869   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8870 }
8871
8872 /**
8873  * gtk_widget_get_events:
8874  * @widget: a #GtkWidget
8875  * 
8876  * Returns the event mask for the widget (a bitfield containing flags
8877  * from the #GdkEventMask enumeration). These are the events that the widget
8878  * will receive.
8879  * 
8880  * Return value: event mask for @widget
8881  **/
8882 gint
8883 gtk_widget_get_events (GtkWidget *widget)
8884 {
8885   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8886
8887   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8888 }
8889
8890 /**
8891  * gtk_widget_get_device_events:
8892  * @widget: a #GtkWidget
8893  * @device: a #GdkDevice
8894  *
8895  * Returns the events mask for the widget corresponding to an specific device. These
8896  * are the events that the widget will receive when @device operates on it.
8897  *
8898  * Returns: device event mask for @widget
8899  *
8900  * Since: 3.0
8901  **/
8902 GdkEventMask
8903 gtk_widget_get_device_events (GtkWidget *widget,
8904                               GdkDevice *device)
8905 {
8906   GHashTable *device_events;
8907
8908   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8909   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8910
8911   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8912
8913   if (!device_events)
8914     return 0;
8915
8916   return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8917 }
8918
8919 /**
8920  * gtk_widget_get_extension_events:
8921  * @widget: a #GtkWidget
8922  * 
8923  * Retrieves the extension events the widget will receive; see
8924  * gdk_input_set_extension_events().
8925  * 
8926  * Return value: extension events for @widget
8927  **/
8928 GdkExtensionMode
8929 gtk_widget_get_extension_events (GtkWidget *widget)
8930 {
8931   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8932
8933   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8934 }
8935
8936 /**
8937  * gtk_widget_get_pointer:
8938  * @widget: a #GtkWidget
8939  * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8940  * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8941  *
8942  * Obtains the location of the mouse pointer in widget coordinates.
8943  * Widget coordinates are a bit odd; for historical reasons, they are
8944  * defined as @widget->window coordinates for widgets that are not
8945  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8946  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8947  **/
8948 void
8949 gtk_widget_get_pointer (GtkWidget *widget,
8950                         gint      *x,
8951                         gint      *y)
8952 {
8953   GtkWidgetPrivate *priv;
8954
8955   g_return_if_fail (GTK_IS_WIDGET (widget));
8956
8957   priv = widget->priv;
8958
8959   if (x)
8960     *x = -1;
8961   if (y)
8962     *y = -1;
8963   
8964   if (gtk_widget_get_realized (widget))
8965     {
8966       gdk_window_get_pointer (priv->window, x, y, NULL);
8967
8968       if (!gtk_widget_get_has_window (widget))
8969         {
8970           if (x)
8971             *x -= priv->allocation.x;
8972           if (y)
8973             *y -= priv->allocation.y;
8974         }
8975     }
8976 }
8977
8978 /**
8979  * gtk_widget_is_ancestor:
8980  * @widget: a #GtkWidget
8981  * @ancestor: another #GtkWidget
8982  * 
8983  * Determines whether @widget is somewhere inside @ancestor, possibly with
8984  * intermediate containers.
8985  * 
8986  * Return value: %TRUE if @ancestor contains @widget as a child, 
8987  *    grandchild, great grandchild, etc.
8988  **/
8989 gboolean
8990 gtk_widget_is_ancestor (GtkWidget *widget,
8991                         GtkWidget *ancestor)
8992 {
8993   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8994   g_return_val_if_fail (ancestor != NULL, FALSE);
8995
8996   while (widget)
8997     {
8998       if (widget->priv->parent == ancestor)
8999         return TRUE;
9000       widget = widget->priv->parent;
9001     }
9002   
9003   return FALSE;
9004 }
9005
9006 static GQuark quark_composite_name = 0;
9007
9008 /**
9009  * gtk_widget_set_composite_name:
9010  * @widget: a #GtkWidget.
9011  * @name: the name to set
9012  * 
9013  * Sets a widgets composite name. The widget must be
9014  * a composite child of its parent; see gtk_widget_push_composite_child().
9015  **/
9016 void
9017 gtk_widget_set_composite_name (GtkWidget   *widget,
9018                                const gchar *name)
9019 {
9020   g_return_if_fail (GTK_IS_WIDGET (widget));
9021   g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
9022   g_return_if_fail (name != NULL);
9023
9024   if (!quark_composite_name)
9025     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9026
9027   g_object_set_qdata_full (G_OBJECT (widget),
9028                            quark_composite_name,
9029                            g_strdup (name),
9030                            g_free);
9031 }
9032
9033 /**
9034  * gtk_widget_get_composite_name:
9035  * @widget: a #GtkWidget
9036  *
9037  * Obtains the composite name of a widget. 
9038  *
9039  * Returns: the composite name of @widget, or %NULL if @widget is not
9040  *   a composite child. The string should be freed when it is no 
9041  *   longer needed.
9042  **/
9043 gchar*
9044 gtk_widget_get_composite_name (GtkWidget *widget)
9045 {
9046   GtkWidgetPrivate *priv;
9047
9048   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9049
9050   priv = widget->priv;
9051
9052   if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
9053     return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9054                                                widget);
9055   else
9056     return NULL;
9057 }
9058
9059 /**
9060  * gtk_widget_push_composite_child:
9061  * 
9062  * Makes all newly-created widgets as composite children until
9063  * the corresponding gtk_widget_pop_composite_child() call.
9064  * 
9065  * A composite child is a child that's an implementation detail of the
9066  * container it's inside and should not be visible to people using the
9067  * container. Composite children aren't treated differently by GTK (but
9068  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
9069  * builders might want to treat them in a different way.
9070  * 
9071  * Here is a simple example:
9072  * |[
9073  *   gtk_widget_push_composite_child ();
9074  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9075  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9076  *   gtk_widget_pop_composite_child ();
9077  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
9078  *                          GTK_WIDGET (scrolled_window));
9079  *   g_object_ref (scrolled_window->hscrollbar);
9080  * ]|
9081  **/
9082 void
9083 gtk_widget_push_composite_child (void)
9084 {
9085   composite_child_stack++;
9086 }
9087
9088 /**
9089  * gtk_widget_pop_composite_child:
9090  *
9091  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9092  **/ 
9093 void
9094 gtk_widget_pop_composite_child (void)
9095 {
9096   if (composite_child_stack)
9097     composite_child_stack--;
9098 }
9099
9100 static void
9101 gtk_widget_emit_direction_changed (GtkWidget        *widget,
9102                                    GtkTextDirection  old_dir)
9103 {
9104   gtk_widget_update_pango_context (widget);
9105   
9106   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9107 }
9108
9109 /**
9110  * gtk_widget_set_direction:
9111  * @widget: a #GtkWidget
9112  * @dir:    the new direction
9113  * 
9114  * Sets the reading direction on a particular widget. This direction
9115  * controls the primary direction for widgets containing text,
9116  * and also the direction in which the children of a container are
9117  * packed. The ability to set the direction is present in order
9118  * so that correct localization into languages with right-to-left
9119  * reading directions can be done. Generally, applications will
9120  * let the default reading direction present, except for containers
9121  * where the containers are arranged in an order that is explicitely
9122  * visual rather than logical (such as buttons for text justification).
9123  *
9124  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9125  * set by gtk_widget_set_default_direction() will be used.
9126  **/
9127 void
9128 gtk_widget_set_direction (GtkWidget        *widget,
9129                           GtkTextDirection  dir)
9130 {
9131   GtkTextDirection old_dir;
9132   
9133   g_return_if_fail (GTK_IS_WIDGET (widget));
9134   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9135
9136   old_dir = gtk_widget_get_direction (widget);
9137   
9138   if (dir == GTK_TEXT_DIR_NONE)
9139     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9140   else
9141     {
9142       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9143       if (dir == GTK_TEXT_DIR_LTR)
9144         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9145       else
9146         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9147     }
9148
9149   if (old_dir != gtk_widget_get_direction (widget))
9150     gtk_widget_emit_direction_changed (widget, old_dir);
9151 }
9152
9153 /**
9154  * gtk_widget_get_direction:
9155  * @widget: a #GtkWidget
9156  * 
9157  * Gets the reading direction for a particular widget. See
9158  * gtk_widget_set_direction().
9159  * 
9160  * Return value: the reading direction for the widget.
9161  **/
9162 GtkTextDirection
9163 gtk_widget_get_direction (GtkWidget *widget)
9164 {
9165   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9166   
9167   if (GTK_WIDGET_DIRECTION_SET (widget))
9168     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9169   else
9170     return gtk_default_direction;
9171 }
9172
9173 static void
9174 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9175 {
9176   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9177
9178   g_object_ref (widget);
9179   
9180   if (!GTK_WIDGET_DIRECTION_SET (widget))
9181     gtk_widget_emit_direction_changed (widget, old_dir);
9182   
9183   if (GTK_IS_CONTAINER (widget))
9184     gtk_container_forall (GTK_CONTAINER (widget),
9185                           gtk_widget_set_default_direction_recurse,
9186                           data);
9187
9188   g_object_unref (widget);
9189 }
9190
9191 /**
9192  * gtk_widget_set_default_direction:
9193  * @dir: the new default direction. This cannot be
9194  *        %GTK_TEXT_DIR_NONE.
9195  * 
9196  * Sets the default reading direction for widgets where the
9197  * direction has not been explicitly set by gtk_widget_set_direction().
9198  **/
9199 void
9200 gtk_widget_set_default_direction (GtkTextDirection dir)
9201 {
9202   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9203
9204   if (dir != gtk_default_direction)
9205     {
9206       GList *toplevels, *tmp_list;
9207       GtkTextDirection old_dir = gtk_default_direction;
9208       
9209       gtk_default_direction = dir;
9210
9211       tmp_list = toplevels = gtk_window_list_toplevels ();
9212       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9213       
9214       while (tmp_list)
9215         {
9216           gtk_widget_set_default_direction_recurse (tmp_list->data,
9217                                                     GUINT_TO_POINTER (old_dir));
9218           g_object_unref (tmp_list->data);
9219           tmp_list = tmp_list->next;
9220         }
9221
9222       g_list_free (toplevels);
9223     }
9224 }
9225
9226 /**
9227  * gtk_widget_get_default_direction:
9228  * 
9229  * Obtains the current default reading direction. See
9230  * gtk_widget_set_default_direction().
9231  *
9232  * Return value: the current default direction. 
9233  **/
9234 GtkTextDirection
9235 gtk_widget_get_default_direction (void)
9236 {
9237   return gtk_default_direction;
9238 }
9239
9240 static void
9241 gtk_widget_dispose (GObject *object)
9242 {
9243   GtkWidget *widget = GTK_WIDGET (object);
9244   GtkWidgetPrivate *priv = widget->priv;
9245
9246   if (priv->parent)
9247     gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9248   else if (gtk_widget_get_visible (widget))
9249     gtk_widget_hide (widget);
9250
9251   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9252   if (gtk_widget_get_realized (widget))
9253     gtk_widget_unrealize (widget);
9254   
9255   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9256 }
9257
9258 static void
9259 gtk_widget_real_destroy (GtkObject *object)
9260 {
9261   /* gtk_object_destroy() will already hold a refcount on object */
9262   GtkWidget *widget = GTK_WIDGET (object);
9263   GtkWidgetPrivate *priv = widget->priv;
9264
9265   /* wipe accelerator closures (keep order) */
9266   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9267   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9268
9269   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9270   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9271   
9272   gtk_grab_remove (widget);
9273
9274   g_object_unref (priv->style);
9275   priv->style = gtk_widget_get_default_style ();
9276   g_object_ref (priv->style);
9277
9278   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9279 }
9280
9281 static void
9282 gtk_widget_finalize (GObject *object)
9283 {
9284   GtkWidget *widget = GTK_WIDGET (object);
9285   GtkWidgetPrivate *priv = widget->priv;
9286   GtkWidgetAuxInfo *aux_info;
9287   GtkAccessible *accessible;
9288   
9289   gtk_grab_remove (widget);
9290
9291   g_object_unref (priv->style);
9292   priv->style = NULL;
9293
9294   g_free (priv->name);
9295   
9296   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9297   if (aux_info)
9298     gtk_widget_aux_info_destroy (aux_info);
9299
9300   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9301   if (accessible)
9302     g_object_unref (accessible);
9303
9304   G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9305 }
9306
9307 /*****************************************
9308  * gtk_widget_real_map:
9309  *
9310  *   arguments:
9311  *
9312  *   results:
9313  *****************************************/
9314
9315 static void
9316 gtk_widget_real_map (GtkWidget *widget)
9317 {
9318   GtkWidgetPrivate *priv = widget->priv;
9319
9320   g_assert (gtk_widget_get_realized (widget));
9321   
9322   if (!gtk_widget_get_mapped (widget))
9323     {
9324       gtk_widget_set_mapped (widget, TRUE);
9325       
9326       if (gtk_widget_get_has_window (widget))
9327         gdk_window_show (priv->window);
9328     }
9329 }
9330
9331 /*****************************************
9332  * gtk_widget_real_unmap:
9333  *
9334  *   arguments:
9335  *
9336  *   results:
9337  *****************************************/
9338
9339 static void
9340 gtk_widget_real_unmap (GtkWidget *widget)
9341 {
9342   GtkWidgetPrivate *priv = widget->priv;
9343
9344   if (gtk_widget_get_mapped (widget))
9345     {
9346       gtk_widget_set_mapped (widget, FALSE);
9347
9348       if (gtk_widget_get_has_window (widget))
9349         gdk_window_hide (priv->window);
9350     }
9351 }
9352
9353 /*****************************************
9354  * gtk_widget_real_realize:
9355  *
9356  *   arguments:
9357  *
9358  *   results:
9359  *****************************************/
9360
9361 static void
9362 gtk_widget_real_realize (GtkWidget *widget)
9363 {
9364   GtkWidgetPrivate *priv = widget->priv;
9365
9366   g_assert (!gtk_widget_get_has_window (widget));
9367   
9368   gtk_widget_set_realized (widget, TRUE);
9369   if (priv->parent)
9370     {
9371       priv->window = gtk_widget_get_parent_window (widget);
9372       g_object_ref (priv->window);
9373     }
9374   priv->style = gtk_style_attach (priv->style, priv->window);
9375 }
9376
9377 /*****************************************
9378  * gtk_widget_real_unrealize:
9379  *
9380  *   arguments:
9381  *
9382  *   results:
9383  *****************************************/
9384
9385 static void
9386 gtk_widget_real_unrealize (GtkWidget *widget)
9387 {
9388   GtkWidgetPrivate *priv = widget->priv;
9389
9390   if (gtk_widget_get_mapped (widget))
9391     gtk_widget_real_unmap (widget);
9392
9393   gtk_widget_set_mapped (widget, FALSE);
9394
9395   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9396    */
9397
9398    /* We must do unrealize child widget BEFORE container widget.
9399     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9400     * So, unrealizing container widget bofore its children causes the problem 
9401     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9402     */
9403
9404   if (GTK_IS_CONTAINER (widget))
9405     gtk_container_forall (GTK_CONTAINER (widget),
9406                           (GtkCallback) gtk_widget_unrealize,
9407                           NULL);
9408
9409   gtk_style_detach (priv->style);
9410   if (gtk_widget_get_has_window (widget))
9411     {
9412       gdk_window_set_user_data (priv->window, NULL);
9413       gdk_window_destroy (priv->window);
9414       priv->window = NULL;
9415     }
9416   else
9417     {
9418       g_object_unref (priv->window);
9419       priv->window = NULL;
9420     }
9421
9422   gtk_selection_remove_all (widget);
9423   
9424   gtk_widget_set_realized (widget, FALSE);
9425 }
9426
9427 static void
9428 gtk_widget_real_size_request (GtkWidget         *widget,
9429                               GtkRequisition    *requisition)
9430 {
9431   requisition->width  = 0;
9432   requisition->height = 0;
9433 }
9434
9435 static void
9436 gtk_widget_real_adjust_size_request (GtkWidget         *widget,
9437                                      GtkOrientation     orientation,
9438                                      gint               for_size,
9439                                      gint              *minimum_size,
9440                                      gint              *natural_size)
9441 {
9442   const GtkWidgetAuxInfo *aux_info;
9443
9444   aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9445
9446   if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9447       aux_info->width > 0)
9448     {
9449       *minimum_size = MAX (*minimum_size, aux_info->width);
9450     }
9451   else if (orientation == GTK_ORIENTATION_VERTICAL &&
9452            aux_info->height > 0)
9453     {
9454       *minimum_size = MAX (*minimum_size, aux_info->height);
9455     }
9456
9457   /* Fix it if set_size_request made natural size smaller than min size.
9458    * This would also silently fix broken widgets, but we warn about them
9459    * in gtksizerequest.c when calling their size request vfuncs.
9460    */
9461   *natural_size = MAX (*natural_size, *minimum_size);
9462
9463   if (orientation == GTK_ORIENTATION_HORIZONTAL)
9464     {
9465       *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9466       *natural_size += (aux_info->margin.left + aux_info->margin.right);
9467     }
9468   else
9469     {
9470       *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9471       *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9472     }
9473 }
9474
9475 /**
9476  * _gtk_widget_peek_request_cache:
9477  * 
9478  * Returns the address of the widget's request cache (strictly for
9479  * internal use in gtksizerequest.c)
9480  * 
9481  * Return value: the address of @widget's size request cache.
9482  **/
9483 gpointer
9484 _gtk_widget_peek_request_cache (GtkWidget *widget)
9485 {
9486   /* Don't bother slowing things down with the return_if_fail guards here */
9487   return &widget->priv->requests;
9488 }
9489
9490 /*
9491  * _gtk_widget_set_device_window:
9492  * @widget: a #GtkWidget.
9493  * @device: a #GdkDevice.
9494  * @window: the new device window.
9495  *
9496  * Sets pointer window for @widget and @device.  Does not ref @window.
9497  * Actually stores it on the #GdkScreen, but you don't need to know that.
9498  */
9499 void
9500 _gtk_widget_set_device_window (GtkWidget *widget,
9501                                GdkDevice *device,
9502                                GdkWindow *window)
9503 {
9504   GtkWidgetPrivate *priv;
9505   GdkScreen *screen;
9506   GHashTable *device_window;
9507
9508   g_return_if_fail (GTK_IS_WIDGET (widget));
9509   g_return_if_fail (GDK_IS_DEVICE (device));
9510   g_return_if_fail (!window || GDK_IS_WINDOW (window));
9511
9512   priv = widget->priv;
9513
9514   if (!gtk_widget_get_realized (widget))
9515     return;
9516
9517   screen = gdk_window_get_screen (priv->window);
9518   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9519
9520   if (G_UNLIKELY (!device_window))
9521     {
9522       device_window = g_hash_table_new (NULL, NULL);
9523       g_object_set_qdata_full (G_OBJECT (screen),
9524                                quark_pointer_window,
9525                                device_window,
9526                                (GDestroyNotify) g_hash_table_destroy);
9527     }
9528
9529   if (window)
9530     g_hash_table_insert (device_window, device, window);
9531   else
9532     g_hash_table_remove (device_window, device);
9533 }
9534
9535 /*
9536  * _gtk_widget_get_device_window:
9537  * @widget: a #GtkWidget.
9538  * @device: a #GdkDevice.
9539  *
9540  * Return value: the device window set on the #GdkScreen @widget is attached
9541  * to, or %NULL.
9542  */
9543 GdkWindow *
9544 _gtk_widget_get_device_window (GtkWidget *widget,
9545                                GdkDevice *device)
9546 {
9547   GtkWidgetPrivate *priv;
9548   GdkScreen *screen;
9549   GHashTable *device_window;
9550   GdkWindow *window;
9551   GtkWidget *w;
9552
9553   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9554   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9555
9556   priv = widget->priv;
9557
9558   if (!gtk_widget_get_realized (widget))
9559     return NULL;
9560
9561   screen = gdk_window_get_screen (priv->window);
9562   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9563
9564   if (G_UNLIKELY (!device_window))
9565     return NULL;
9566
9567   window = g_hash_table_lookup (device_window, device);
9568
9569   if (!window)
9570     return NULL;
9571
9572   gdk_window_get_user_data (window, (gpointer *) &w);
9573
9574   if (widget != w)
9575     return NULL;
9576
9577   return window;
9578 }
9579
9580 /*
9581  * _gtk_widget_list_devices:
9582  * @widget: a #GtkWidget.
9583  *
9584  * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9585  * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9586  * be freed.
9587  */
9588 GList *
9589 _gtk_widget_list_devices (GtkWidget *widget)
9590 {
9591   GtkWidgetPrivate *priv;
9592   GdkScreen *screen;
9593   GHashTableIter iter;
9594   GHashTable *device_window;
9595   GList *devices = NULL;
9596   gpointer key, value;
9597
9598   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9599
9600   priv = widget->priv;
9601
9602   if (!gtk_widget_get_realized (widget))
9603     return NULL;
9604
9605   screen = gdk_window_get_screen (priv->window);
9606   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9607
9608   if (G_UNLIKELY (!device_window))
9609     return NULL;
9610
9611   g_hash_table_iter_init (&iter, device_window);
9612
9613   while (g_hash_table_iter_next (&iter, &key, &value))
9614     {
9615       GdkDevice *device = key;
9616       GdkWindow *window = value;
9617       GtkWidget *w;
9618
9619       if (window)
9620         {
9621           gdk_window_get_user_data (window, (gpointer *) &w);
9622
9623           if (widget == w)
9624             devices = g_list_prepend (devices, device);
9625         }
9626     }
9627
9628   return devices;
9629 }
9630
9631 static void
9632 synth_crossing (GtkWidget       *widget,
9633                 GdkEventType     type,
9634                 GdkWindow       *window,
9635                 GdkDevice       *device,
9636                 GdkCrossingMode  mode,
9637                 GdkNotifyType    detail)
9638 {
9639   GdkEvent *event;
9640
9641   event = gdk_event_new (type);
9642
9643   event->crossing.window = g_object_ref (window);
9644   event->crossing.send_event = TRUE;
9645   event->crossing.subwindow = g_object_ref (window);
9646   event->crossing.time = GDK_CURRENT_TIME;
9647   event->crossing.x = event->crossing.y = 0;
9648   event->crossing.x_root = event->crossing.y_root = 0;
9649   event->crossing.mode = mode;
9650   event->crossing.detail = detail;
9651   event->crossing.focus = FALSE;
9652   event->crossing.state = 0;
9653   gdk_event_set_device (event, device);
9654
9655   if (!widget)
9656     widget = gtk_get_event_widget (event);
9657
9658   if (widget)
9659     gtk_widget_event_internal (widget, event);
9660
9661   gdk_event_free (event);
9662 }
9663
9664 /*
9665  * _gtk_widget_synthesize_crossing:
9666  * @from: the #GtkWidget the virtual pointer is leaving.
9667  * @to: the #GtkWidget the virtual pointer is moving to.
9668  * @mode: the #GdkCrossingMode to place on the synthesized events.
9669  *
9670  * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9671  *
9672  * The real pointer window is the window that most recently received an enter notify
9673  * event.  Windows that don't select for crossing events can't become the real
9674  * poiner window.  The real pointer widget that owns the real pointer window.  The
9675  * effective pointer window is the same as the real pointer window unless the real
9676  * pointer widget is either insensitive or there is a grab on a widget that is not
9677  * an ancestor of the real pointer widget (in which case the effective pointer
9678  * window should be the root window).
9679  *
9680  * When the effective pointer window is the same as the real poiner window, we
9681  * receive crossing events from the windowing system.  When the effective pointer
9682  * window changes to become different from the real pointer window we synthesize
9683  * crossing events, attempting to follow X protocol rules:
9684  *
9685  * When the root window becomes the effective pointer window:
9686  *   - leave notify on real pointer window, detail Ancestor
9687  *   - leave notify on all of its ancestors, detail Virtual
9688  *   - enter notify on root window, detail Inferior
9689  *
9690  * When the root window ceases to be the effective pointer window:
9691  *   - leave notify on root window, detail Inferior
9692  *   - enter notify on all ancestors of real pointer window, detail Virtual
9693  *   - enter notify on real pointer window, detail Ancestor
9694  */
9695 void
9696 _gtk_widget_synthesize_crossing (GtkWidget       *from,
9697                                  GtkWidget       *to,
9698                                  GdkDevice       *device,
9699                                  GdkCrossingMode  mode)
9700 {
9701   GdkWindow *from_window = NULL, *to_window = NULL;
9702
9703   g_return_if_fail (from != NULL || to != NULL);
9704
9705   if (from != NULL)
9706     {
9707       from_window = _gtk_widget_get_device_window (from, device);
9708
9709       if (!from_window)
9710         from_window = from->priv->window;
9711     }
9712
9713   if (to != NULL)
9714     {
9715       to_window = _gtk_widget_get_device_window (to, device);
9716
9717       if (!to_window)
9718         to_window = to->priv->window;
9719     }
9720
9721   if (from_window == NULL && to_window == NULL)
9722     ;
9723   else if (from_window != NULL && to_window == NULL)
9724     {
9725       GList *from_ancestors = NULL, *list;
9726       GdkWindow *from_ancestor = from_window;
9727
9728       while (from_ancestor != NULL)
9729         {
9730           from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9731           if (from_ancestor == NULL)
9732             break;
9733           from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9734         }
9735
9736       synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9737                       device, mode, GDK_NOTIFY_ANCESTOR);
9738       for (list = g_list_last (from_ancestors); list; list = list->prev)
9739         {
9740           synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9741                           device, mode, GDK_NOTIFY_VIRTUAL);
9742         }
9743
9744       /* XXX: enter/inferior on root window? */
9745
9746       g_list_free (from_ancestors);
9747     }
9748   else if (from_window == NULL && to_window != NULL)
9749     {
9750       GList *to_ancestors = NULL, *list;
9751       GdkWindow *to_ancestor = to_window;
9752
9753       while (to_ancestor != NULL)
9754         {
9755           to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9756           if (to_ancestor == NULL)
9757             break;
9758           to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9759         }
9760
9761       /* XXX: leave/inferior on root window? */
9762
9763       for (list = to_ancestors; list; list = list->next)
9764         {
9765           synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9766                           device, mode, GDK_NOTIFY_VIRTUAL);
9767         }
9768       synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9769                       device, mode, GDK_NOTIFY_ANCESTOR);
9770
9771       g_list_free (to_ancestors);
9772     }
9773   else if (from_window == to_window)
9774     ;
9775   else
9776     {
9777       GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9778       GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9779
9780       while (from_ancestor != NULL || to_ancestor != NULL)
9781         {
9782           if (from_ancestor != NULL)
9783             {
9784               from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9785               if (from_ancestor == to_window)
9786                 break;
9787               if (from_ancestor)
9788                 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9789             }
9790           if (to_ancestor != NULL)
9791             {
9792               to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9793               if (to_ancestor == from_window)
9794                 break;
9795               if (to_ancestor)
9796                 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9797             }
9798         }
9799       if (to_ancestor == from_window)
9800         {
9801           if (mode != GDK_CROSSING_GTK_UNGRAB)
9802             synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9803                             device, mode, GDK_NOTIFY_INFERIOR);
9804           for (list = to_ancestors; list; list = list->next)
9805             synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data, 
9806                             device, mode, GDK_NOTIFY_VIRTUAL);
9807           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9808                           device, mode, GDK_NOTIFY_ANCESTOR);
9809         }
9810       else if (from_ancestor == to_window)
9811         {
9812           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9813                           device, mode, GDK_NOTIFY_ANCESTOR);
9814           for (list = g_list_last (from_ancestors); list; list = list->prev)
9815             {
9816               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9817                               device, mode, GDK_NOTIFY_VIRTUAL);
9818             }
9819           if (mode != GDK_CROSSING_GTK_GRAB)
9820             synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9821                             device, mode, GDK_NOTIFY_INFERIOR);
9822         }
9823       else
9824         {
9825           while (from_ancestors != NULL && to_ancestors != NULL 
9826                  && from_ancestors->data == to_ancestors->data)
9827             {
9828               from_ancestors = g_list_delete_link (from_ancestors, 
9829                                                    from_ancestors);
9830               to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9831             }
9832
9833           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9834                           device, mode, GDK_NOTIFY_NONLINEAR);
9835
9836           for (list = g_list_last (from_ancestors); list; list = list->prev)
9837             {
9838               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9839                               device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9840             }
9841           for (list = to_ancestors; list; list = list->next)
9842             {
9843               synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9844                               device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9845             }
9846           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9847                           device, mode, GDK_NOTIFY_NONLINEAR);
9848         }
9849       g_list_free (from_ancestors);
9850       g_list_free (to_ancestors);
9851     }
9852 }
9853
9854 static void
9855 gtk_widget_propagate_state (GtkWidget           *widget,
9856                             GtkStateData        *data)
9857 {
9858   GtkWidgetPrivate *priv = widget->priv;
9859   guint8 old_state = gtk_widget_get_state (widget);
9860   guint8 old_saved_state = priv->saved_state;
9861
9862   /* don't call this function with state==GTK_STATE_INSENSITIVE,
9863    * parent_sensitive==TRUE on a sensitive widget
9864    */
9865
9866
9867   if (data->parent_sensitive)
9868     GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9869   else
9870     GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9871
9872   if (gtk_widget_is_sensitive (widget))
9873     {
9874       if (data->state_restoration)
9875         priv->state = priv->saved_state;
9876       else
9877         priv->state = data->state;
9878     }
9879   else
9880     {
9881       if (!data->state_restoration)
9882         {
9883           if (data->state != GTK_STATE_INSENSITIVE)
9884             priv->saved_state = data->state;
9885         }
9886       else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9887         priv->saved_state = gtk_widget_get_state (widget);
9888       priv->state = GTK_STATE_INSENSITIVE;
9889     }
9890
9891   if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9892     {
9893       GtkWidget *window;
9894
9895       window = gtk_widget_get_toplevel (widget);
9896       if (window && gtk_widget_is_toplevel (window))
9897         gtk_window_set_focus (GTK_WINDOW (window), NULL);
9898     }
9899
9900   if (old_state != gtk_widget_get_state (widget) ||
9901       old_saved_state != priv->saved_state)
9902     {
9903       g_object_ref (widget);
9904
9905       if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9906         gtk_grab_remove (widget);
9907
9908       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9909
9910       if (!GTK_WIDGET_SHADOWED (widget))
9911         {
9912           GList *event_windows = NULL;
9913           GList *devices, *d;
9914
9915           devices = _gtk_widget_list_devices (widget);
9916
9917           for (d = devices; d; d = d->next)
9918             {
9919               GdkWindow *window;
9920               GdkDevice *device;
9921
9922               device = d->data;
9923               window = _gtk_widget_get_device_window (widget, device);
9924
9925               /* Do not propagate more than once to the
9926                * same window if non-multidevice aware.
9927                */
9928               if (!gdk_window_get_support_multidevice (window) &&
9929                   g_list_find (event_windows, window))
9930                 continue;
9931
9932               if (!gtk_widget_is_sensitive (widget))
9933                 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9934                                                  GDK_CROSSING_STATE_CHANGED);
9935               else if (old_state == GTK_STATE_INSENSITIVE)
9936                 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9937                                                  GDK_CROSSING_STATE_CHANGED);
9938
9939               event_windows = g_list_prepend (event_windows, window);
9940             }
9941
9942           g_list_free (event_windows);
9943           g_list_free (devices);
9944         }
9945
9946       if (GTK_IS_CONTAINER (widget))
9947         {
9948           data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9949           if (data->use_forall)
9950             gtk_container_forall (GTK_CONTAINER (widget),
9951                                   (GtkCallback) gtk_widget_propagate_state,
9952                                   data);
9953           else
9954             gtk_container_foreach (GTK_CONTAINER (widget),
9955                                    (GtkCallback) gtk_widget_propagate_state,
9956                                    data);
9957         }
9958       g_object_unref (widget);
9959     }
9960 }
9961
9962 static const GtkWidgetAuxInfo default_aux_info = {
9963   -1, -1,
9964   GTK_ALIGN_FILL,
9965   GTK_ALIGN_FILL,
9966   { 0, 0, 0, 0 }
9967 };
9968
9969 /*
9970  * _gtk_widget_get_aux_info:
9971  * @widget: a #GtkWidget
9972  * @create: if %TRUE, create the structure if it doesn't exist
9973  * 
9974  * Get the #GtkWidgetAuxInfo structure for the widget.
9975  * 
9976  * Return value: the #GtkAuxInfo structure for the widget, or
9977  *    %NULL if @create is %FALSE and one doesn't already exist.
9978  */
9979 GtkWidgetAuxInfo*
9980 _gtk_widget_get_aux_info (GtkWidget *widget,
9981                           gboolean   create)
9982 {
9983   GtkWidgetAuxInfo *aux_info;
9984   
9985   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9986   if (!aux_info && create)
9987     {
9988       aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9989
9990       *aux_info = default_aux_info;
9991
9992       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9993     }
9994   
9995   return aux_info;
9996 }
9997
9998 static const GtkWidgetAuxInfo*
9999 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10000 {
10001   GtkWidgetAuxInfo *aux_info;
10002
10003   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10004   if (aux_info == NULL)
10005     {
10006       return &default_aux_info;
10007     }
10008   else
10009     {
10010       return aux_info;
10011     }
10012 }
10013
10014 /*****************************************
10015  * gtk_widget_aux_info_destroy:
10016  *
10017  *   arguments:
10018  *
10019  *   results:
10020  *****************************************/
10021
10022 static void
10023 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10024 {
10025   g_slice_free (GtkWidgetAuxInfo, aux_info);
10026 }
10027
10028 /**
10029  * gtk_widget_shape_combine_region: 
10030  * @widget: a #GtkWidget
10031  * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10032  * 
10033  * Sets a shape for this widget's GDK window. This allows for
10034  * transparent windows etc., see gdk_window_shape_combine_region()
10035  * for more information.
10036  *
10037  * Since: 3.0
10038  **/
10039 void
10040 gtk_widget_shape_combine_region (GtkWidget *widget,
10041                                  cairo_region_t *region)
10042 {
10043   GtkWidgetPrivate *priv;
10044   
10045   g_return_if_fail (GTK_IS_WIDGET (widget));
10046   /*  set_shape doesn't work on widgets without gdk window */
10047   g_return_if_fail (gtk_widget_get_has_window (widget));
10048
10049   priv = widget->priv;
10050
10051   if (region == NULL)
10052     {
10053       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10054       
10055       if (priv->window)
10056         gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10057       
10058       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10059     }
10060   else
10061     {
10062       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10063       
10064       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10065                                cairo_region_copy (region),
10066                                (GDestroyNotify) cairo_region_destroy);
10067       
10068       /* set shape if widget has a gdk window already.
10069        * otherwise the shape is scheduled to be set by gtk_widget_realize().
10070        */
10071       if (priv->window)
10072         gdk_window_shape_combine_region (priv->window, region, 0, 0);
10073     }
10074 }
10075
10076 /**
10077  * gtk_widget_input_shape_combine_region:
10078  * @widget: a #GtkWidget
10079  * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10080  *
10081  * Sets an input shape for this widget's GDK window. This allows for
10082  * windows which react to mouse click in a nonrectangular region, see 
10083  * gdk_window_input_shape_combine_region() for more information.
10084  *
10085  * Since: 3.0
10086  **/
10087 void
10088 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10089                                        cairo_region_t *region)
10090 {
10091   GtkWidgetPrivate *priv;
10092   
10093   g_return_if_fail (GTK_IS_WIDGET (widget));
10094   /*  set_shape doesn't work on widgets without gdk window */
10095   g_return_if_fail (gtk_widget_get_has_window (widget));
10096
10097   priv = widget->priv;
10098
10099   if (region == NULL)
10100     {
10101       if (priv->window)
10102         gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10103       
10104       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10105     }
10106   else
10107     {
10108       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
10109                                cairo_region_copy (region),
10110                                (GDestroyNotify) cairo_region_destroy);
10111       
10112       /* set shape if widget has a gdk window already.
10113        * otherwise the shape is scheduled to be set by gtk_widget_realize().
10114        */
10115       if (priv->window)
10116         gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10117     }
10118 }
10119
10120
10121 static void
10122 gtk_reset_shapes_recurse (GtkWidget *widget,
10123                           GdkWindow *window)
10124 {
10125   gpointer data;
10126   GList *list;
10127
10128   gdk_window_get_user_data (window, &data);
10129   if (data != widget)
10130     return;
10131
10132   gdk_window_shape_combine_region (window, NULL, 0, 0);
10133   for (list = gdk_window_peek_children (window); list; list = list->next)
10134     gtk_reset_shapes_recurse (widget, list->data);
10135 }
10136
10137 /**
10138  * gtk_widget_reset_shapes:
10139  * @widget: a #GtkWidget
10140  *
10141  * Recursively resets the shape on this widget and its descendants.
10142  **/
10143 void
10144 gtk_widget_reset_shapes (GtkWidget *widget)
10145 {
10146   GtkWidgetPrivate *priv;
10147
10148   g_return_if_fail (GTK_IS_WIDGET (widget));
10149   g_return_if_fail (gtk_widget_get_realized (widget));
10150
10151   priv = widget->priv;
10152
10153   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10154     gtk_reset_shapes_recurse (widget, priv->window);
10155 }
10156
10157 /* style properties
10158  */
10159
10160 /**
10161  * gtk_widget_class_install_style_property_parser:
10162  * @klass: a #GtkWidgetClass
10163  * @pspec: the #GParamSpec for the style property
10164  * @parser: the parser for the style property
10165  * 
10166  * Installs a style property on a widget class. 
10167  **/
10168 void
10169 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
10170                                                 GParamSpec         *pspec,
10171                                                 GtkRcPropertyParser parser)
10172 {
10173   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10174   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10175   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10176   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10177   
10178   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10179     {
10180       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10181                  G_OBJECT_CLASS_NAME (klass),
10182                  pspec->name);
10183       return;
10184     }
10185
10186   g_param_spec_ref_sink (pspec);
10187   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10188   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10189 }
10190
10191 /**
10192  * gtk_widget_class_install_style_property:
10193  * @klass: a #GtkWidgetClass
10194  * @pspec: the #GParamSpec for the property
10195  * 
10196  * Installs a style property on a widget class. The parser for the
10197  * style property is determined by the value type of @pspec.
10198  **/
10199 void
10200 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10201                                          GParamSpec     *pspec)
10202 {
10203   GtkRcPropertyParser parser;
10204
10205   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10206   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10207
10208   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10209
10210   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10211 }
10212
10213 /**
10214  * gtk_widget_class_find_style_property:
10215  * @klass: a #GtkWidgetClass
10216  * @property_name: the name of the style property to find
10217  * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10218  *   style property with that name.
10219  *
10220  * Finds a style property of a widget class by name.
10221  *
10222  * Since: 2.2
10223  */
10224 GParamSpec*
10225 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10226                                       const gchar    *property_name)
10227 {
10228   g_return_val_if_fail (property_name != NULL, NULL);
10229
10230   return g_param_spec_pool_lookup (style_property_spec_pool,
10231                                    property_name,
10232                                    G_OBJECT_CLASS_TYPE (klass),
10233                                    TRUE);
10234 }
10235
10236 /**
10237  * gtk_widget_class_list_style_properties:
10238  * @klass: a #GtkWidgetClass
10239  * @n_properties: location to return the number of style properties found
10240  * @returns: an newly allocated array of #GParamSpec*. The array must 
10241  *       be freed with g_free().
10242  *
10243  * Returns all style properties of a widget class.
10244  *
10245  * Since: 2.2
10246  */
10247 GParamSpec**
10248 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10249                                         guint          *n_properties)
10250 {
10251   GParamSpec **pspecs;
10252   guint n;
10253
10254   pspecs = g_param_spec_pool_list (style_property_spec_pool,
10255                                    G_OBJECT_CLASS_TYPE (klass),
10256                                    &n);
10257   if (n_properties)
10258     *n_properties = n;
10259
10260   return pspecs;
10261 }
10262
10263 /**
10264  * gtk_widget_style_get_property:
10265  * @widget: a #GtkWidget
10266  * @property_name: the name of a style property
10267  * @value: location to return the property value 
10268  *
10269  * Gets the value of a style property of @widget.
10270  */
10271 void
10272 gtk_widget_style_get_property (GtkWidget   *widget,
10273                                const gchar *property_name,
10274                                GValue      *value)
10275 {
10276   GtkWidgetPrivate *priv;
10277   GParamSpec *pspec;
10278
10279   g_return_if_fail (GTK_IS_WIDGET (widget));
10280   g_return_if_fail (property_name != NULL);
10281   g_return_if_fail (G_IS_VALUE (value));
10282
10283   priv = widget->priv;
10284
10285   g_object_ref (widget);
10286   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10287                                     property_name,
10288                                     G_OBJECT_TYPE (widget),
10289                                     TRUE);
10290   if (!pspec)
10291     g_warning ("%s: widget class `%s' has no property named `%s'",
10292                G_STRLOC,
10293                G_OBJECT_TYPE_NAME (widget),
10294                property_name);
10295   else
10296     {
10297       const GValue *peek_value;
10298
10299       peek_value = _gtk_style_peek_property_value (priv->style,
10300                                                    G_OBJECT_TYPE (widget),
10301                                                    pspec,
10302                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10303       
10304       /* auto-conversion of the caller's value type
10305        */
10306       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10307         g_value_copy (peek_value, value);
10308       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10309         g_value_transform (peek_value, value);
10310       else
10311         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10312                    pspec->name,
10313                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10314                    G_VALUE_TYPE_NAME (value));
10315     }
10316   g_object_unref (widget);
10317 }
10318
10319 /**
10320  * gtk_widget_style_get_valist:
10321  * @widget: a #GtkWidget
10322  * @first_property_name: the name of the first property to get
10323  * @var_args: a <type>va_list</type> of pairs of property names and
10324  *     locations to return the property values, starting with the location
10325  *     for @first_property_name.
10326  * 
10327  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
10328  * bindings.
10329  */ 
10330 void
10331 gtk_widget_style_get_valist (GtkWidget   *widget,
10332                              const gchar *first_property_name,
10333                              va_list      var_args)
10334 {
10335   GtkWidgetPrivate *priv;
10336   const gchar *name;
10337
10338   g_return_if_fail (GTK_IS_WIDGET (widget));
10339
10340   priv = widget->priv;
10341
10342   g_object_ref (widget);
10343
10344   name = first_property_name;
10345   while (name)
10346     {
10347       const GValue *peek_value;
10348       GParamSpec *pspec;
10349       gchar *error;
10350
10351       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10352                                         name,
10353                                         G_OBJECT_TYPE (widget),
10354                                         TRUE);
10355       if (!pspec)
10356         {
10357           g_warning ("%s: widget class `%s' has no property named `%s'",
10358                      G_STRLOC,
10359                      G_OBJECT_TYPE_NAME (widget),
10360                      name);
10361           break;
10362         }
10363       /* style pspecs are always readable so we can spare that check here */
10364
10365       peek_value = _gtk_style_peek_property_value (priv->style,
10366                                                    G_OBJECT_TYPE (widget),
10367                                                    pspec,
10368                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10369       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10370       if (error)
10371         {
10372           g_warning ("%s: %s", G_STRLOC, error);
10373           g_free (error);
10374           break;
10375         }
10376
10377       name = va_arg (var_args, gchar*);
10378     }
10379
10380   g_object_unref (widget);
10381 }
10382
10383 /**
10384  * gtk_widget_style_get:
10385  * @widget: a #GtkWidget
10386  * @first_property_name: the name of the first property to get
10387  * @Varargs: pairs of property names and locations to 
10388  *   return the property values, starting with the location for 
10389  *   @first_property_name, terminated by %NULL.
10390  *
10391  * Gets the values of a multiple style properties of @widget.
10392  */
10393 void
10394 gtk_widget_style_get (GtkWidget   *widget,
10395                       const gchar *first_property_name,
10396                       ...)
10397 {
10398   va_list var_args;
10399
10400   g_return_if_fail (GTK_IS_WIDGET (widget));
10401
10402   va_start (var_args, first_property_name);
10403   gtk_widget_style_get_valist (widget, first_property_name, var_args);
10404   va_end (var_args);
10405 }
10406
10407 /**
10408  * gtk_widget_path:
10409  * @widget: a #GtkWidget
10410  * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10411  * @path: (out) (allow-none):  location to store allocated path string, or %NULL
10412  * @path_reversed: (out) (allow-none):  location to store allocated reverse path string, or %NULL
10413  *
10414  * Obtains the full path to @widget. The path is simply the name of a
10415  * widget and all its parents in the container hierarchy, separated by
10416  * periods. The name of a widget comes from
10417  * gtk_widget_get_name(). Paths are used to apply styles to a widget
10418  * in gtkrc configuration files. Widget names are the type of the
10419  * widget by default (e.g. "GtkButton") or can be set to an
10420  * application-specific value with gtk_widget_set_name(). By setting
10421  * the name of a widget, you allow users or theme authors to apply
10422  * styles to that specific widget in their gtkrc
10423  * file. @path_reversed_p fills in the path in reverse order,
10424  * i.e. starting with @widget's name instead of starting with the name
10425  * of @widget's outermost ancestor.
10426  **/
10427 void
10428 gtk_widget_path (GtkWidget *widget,
10429                  guint     *path_length,
10430                  gchar    **path,
10431                  gchar    **path_reversed)
10432 {
10433   static gchar *rev_path = NULL;
10434   static guint tmp_path_len = 0;
10435   guint len;
10436   
10437   g_return_if_fail (GTK_IS_WIDGET (widget));
10438
10439   len = 0;
10440   do
10441     {
10442       const gchar *string;
10443       const gchar *s;
10444       gchar *d;
10445       guint l;
10446       
10447       string = gtk_widget_get_name (widget);
10448       l = strlen (string);
10449       while (tmp_path_len <= len + l + 1)
10450         {
10451           tmp_path_len += INIT_PATH_SIZE;
10452           rev_path = g_realloc (rev_path, tmp_path_len);
10453         }
10454       s = string + l - 1;
10455       d = rev_path + len;
10456       while (s >= string)
10457         *(d++) = *(s--);
10458       len += l;
10459
10460       widget = widget->priv->parent;
10461
10462       if (widget)
10463         rev_path[len++] = '.';
10464       else
10465         rev_path[len++] = 0;
10466     }
10467   while (widget);
10468   
10469   if (path_length)
10470     *path_length = len - 1;
10471   if (path_reversed)
10472     *path_reversed = g_strdup (rev_path);
10473   if (path)
10474     {
10475       *path = g_strdup (rev_path);
10476       g_strreverse (*path);
10477     }
10478 }
10479
10480 /**
10481  * gtk_widget_class_path:
10482  * @widget: a #GtkWidget
10483  * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10484  * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10485  * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10486  *    string, or %NULL
10487  *
10488  * Same as gtk_widget_path(), but always uses the name of a widget's type,
10489  * never uses a custom name set with gtk_widget_set_name().
10490  * 
10491  **/
10492 void
10493 gtk_widget_class_path (GtkWidget *widget,
10494                        guint     *path_length,
10495                        gchar    **path,
10496                        gchar    **path_reversed)
10497 {
10498   static gchar *rev_path = NULL;
10499   static guint tmp_path_len = 0;
10500   guint len;
10501   
10502   g_return_if_fail (GTK_IS_WIDGET (widget));
10503
10504   len = 0;
10505   do
10506     {
10507       const gchar *string;
10508       const gchar *s;
10509       gchar *d;
10510       guint l;
10511       
10512       string = g_type_name (G_OBJECT_TYPE (widget));
10513       l = strlen (string);
10514       while (tmp_path_len <= len + l + 1)
10515         {
10516           tmp_path_len += INIT_PATH_SIZE;
10517           rev_path = g_realloc (rev_path, tmp_path_len);
10518         }
10519       s = string + l - 1;
10520       d = rev_path + len;
10521       while (s >= string)
10522         *(d++) = *(s--);
10523       len += l;
10524
10525       widget = widget->priv->parent;
10526
10527       if (widget)
10528         rev_path[len++] = '.';
10529       else
10530         rev_path[len++] = 0;
10531     }
10532   while (widget);
10533   
10534   if (path_length)
10535     *path_length = len - 1;
10536   if (path_reversed)
10537     *path_reversed = g_strdup (rev_path);
10538   if (path)
10539     {
10540       *path = g_strdup (rev_path);
10541       g_strreverse (*path);
10542     }
10543 }
10544
10545 /**
10546  * gtk_requisition_new:
10547  *
10548  * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10549  *
10550  * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10551  *   be freed with gtk_requisition_free().
10552  *
10553  * Since: 3.0
10554  */
10555 GtkRequisition *
10556 gtk_requisition_new (void)
10557 {
10558   return g_slice_new0 (GtkRequisition);
10559 }
10560
10561 /**
10562  * gtk_requisition_copy:
10563  * @requisition: a #GtkRequisition
10564  *
10565  * Copies a #GtkRequisition.
10566  *
10567  * Returns: a copy of @requisition
10568  **/
10569 GtkRequisition *
10570 gtk_requisition_copy (const GtkRequisition *requisition)
10571 {
10572   return g_slice_dup (GtkRequisition, requisition);
10573 }
10574
10575 /**
10576  * gtk_requisition_free:
10577  * @requisition: a #GtkRequisition
10578  * 
10579  * Frees a #GtkRequisition.
10580  **/
10581 void
10582 gtk_requisition_free (GtkRequisition *requisition)
10583 {
10584   g_slice_free (GtkRequisition, requisition);
10585 }
10586
10587 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10588                      gtk_requisition_copy,
10589                      gtk_requisition_free)
10590
10591 /**
10592  * gtk_widget_get_accessible:
10593  * @widget: a #GtkWidget
10594  *
10595  * Returns the accessible object that describes the widget to an
10596  * assistive technology.
10597  *
10598  * If no accessibility library is loaded (i.e. no ATK implementation library is
10599  * loaded via <envar>GTK_MODULES</envar> or via another application library,
10600  * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10601  * if no class-specific #AtkObject implementation is available for the widget
10602  * instance in question, it will inherit an #AtkObject implementation from the
10603  * first ancestor class for which such an implementation is defined.
10604  *
10605  * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10606  * library contains more information about accessible objects and their uses.
10607  *
10608  * Returns: (transfer none): the #AtkObject associated with @widget
10609  */
10610 AtkObject*
10611 gtk_widget_get_accessible (GtkWidget *widget)
10612 {
10613   GtkWidgetClass *klass;
10614
10615   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10616
10617   klass = GTK_WIDGET_GET_CLASS (widget);
10618
10619   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10620
10621   return klass->get_accessible (widget);
10622 }
10623
10624 static AtkObject* 
10625 gtk_widget_real_get_accessible (GtkWidget *widget)
10626 {
10627   AtkObject* accessible;
10628
10629   accessible = g_object_get_qdata (G_OBJECT (widget), 
10630                                    quark_accessible_object);
10631   if (!accessible)
10632   {
10633     AtkObjectFactory *factory;
10634     AtkRegistry *default_registry;
10635
10636     default_registry = atk_get_default_registry ();
10637     factory = atk_registry_get_factory (default_registry, 
10638                                         G_TYPE_FROM_INSTANCE (widget));
10639     accessible =
10640       atk_object_factory_create_accessible (factory,
10641                                             G_OBJECT (widget));
10642     g_object_set_qdata (G_OBJECT (widget), 
10643                         quark_accessible_object,
10644                         accessible);
10645   }
10646   return accessible;
10647 }
10648
10649 /*
10650  * Initialize a AtkImplementorIface instance's virtual pointers as
10651  * appropriate to this implementor's class (GtkWidget).
10652  */
10653 static void
10654 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10655 {
10656   iface->ref_accessible = gtk_widget_ref_accessible;
10657 }
10658
10659 static AtkObject*
10660 gtk_widget_ref_accessible (AtkImplementor *implementor)
10661 {
10662   AtkObject *accessible;
10663
10664   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10665   if (accessible)
10666     g_object_ref (accessible);
10667   return accessible;
10668 }
10669
10670 /*
10671  * GtkBuildable implementation
10672  */
10673 static GQuark            quark_builder_has_default = 0;
10674 static GQuark            quark_builder_has_focus = 0;
10675 static GQuark            quark_builder_atk_relations = 0;
10676 static GQuark            quark_builder_set_name = 0;
10677
10678 static void
10679 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10680 {
10681   quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10682   quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10683   quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10684   quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10685
10686   iface->set_name = gtk_widget_buildable_set_name;
10687   iface->get_name = gtk_widget_buildable_get_name;
10688   iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10689   iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10690   iface->parser_finished = gtk_widget_buildable_parser_finished;
10691   iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10692   iface->custom_finished = gtk_widget_buildable_custom_finished;
10693 }
10694
10695 static void
10696 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10697                                const gchar  *name)
10698 {
10699   g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10700                            g_strdup (name), g_free);
10701 }
10702
10703 static const gchar *
10704 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10705 {
10706   return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10707 }
10708
10709 static GObject *
10710 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10711                                          GtkBuilder   *builder,
10712                                          const gchar  *childname)
10713 {
10714   if (strcmp (childname, "accessible") == 0)
10715     return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10716
10717   return NULL;
10718 }
10719
10720 static void
10721 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10722                                              GtkBuilder   *builder,
10723                                              const gchar  *name,
10724                                              const GValue *value)
10725 {
10726   if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10727       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10728                           GINT_TO_POINTER (TRUE));
10729   else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10730       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10731                           GINT_TO_POINTER (TRUE));
10732   else
10733     g_object_set_property (G_OBJECT (buildable), name, value);
10734 }
10735
10736 typedef struct
10737 {
10738   gchar *action_name;
10739   GString *description;
10740   gchar *context;
10741   gboolean translatable;
10742 } AtkActionData;
10743
10744 typedef struct
10745 {
10746   gchar *target;
10747   gchar *type;
10748 } AtkRelationData;
10749
10750 static void
10751 free_action (AtkActionData *data, gpointer user_data)
10752 {
10753   g_free (data->action_name);
10754   g_string_free (data->description, TRUE);
10755   g_free (data->context);
10756   g_slice_free (AtkActionData, data);
10757 }
10758
10759 static void
10760 free_relation (AtkRelationData *data, gpointer user_data)
10761 {
10762   g_free (data->target);
10763   g_free (data->type);
10764   g_slice_free (AtkRelationData, data);
10765 }
10766
10767 static void
10768 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10769                                       GtkBuilder   *builder)
10770 {
10771   GSList *atk_relations;
10772
10773   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10774     gtk_widget_grab_default (GTK_WIDGET (buildable));
10775   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10776     gtk_widget_grab_focus (GTK_WIDGET (buildable));
10777
10778   atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10779                                       quark_builder_atk_relations);
10780   if (atk_relations)
10781     {
10782       AtkObject *accessible;
10783       AtkRelationSet *relation_set;
10784       GSList *l;
10785       GObject *target;
10786       AtkRelationType relation_type;
10787       AtkObject *target_accessible;
10788
10789       accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10790       relation_set = atk_object_ref_relation_set (accessible);
10791
10792       for (l = atk_relations; l; l = l->next)
10793         {
10794           AtkRelationData *relation = (AtkRelationData*)l->data;
10795
10796           target = gtk_builder_get_object (builder, relation->target);
10797           if (!target)
10798             {
10799               g_warning ("Target object %s in <relation> does not exist",
10800                          relation->target);
10801               continue;
10802             }
10803           target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10804           g_assert (target_accessible != NULL);
10805
10806           relation_type = atk_relation_type_for_name (relation->type);
10807           if (relation_type == ATK_RELATION_NULL)
10808             {
10809               g_warning ("<relation> type %s not found",
10810                          relation->type);
10811               continue;
10812             }
10813           atk_relation_set_add_relation_by_type (relation_set, relation_type,
10814                                                  target_accessible);
10815         }
10816       g_object_unref (relation_set);
10817
10818       g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10819       g_slist_free (atk_relations);
10820       g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10821                           NULL);
10822     }
10823 }
10824
10825 typedef struct
10826 {
10827   GSList *actions;
10828   GSList *relations;
10829 } AccessibilitySubParserData;
10830
10831 static void
10832 accessibility_start_element (GMarkupParseContext  *context,
10833                              const gchar          *element_name,
10834                              const gchar         **names,
10835                              const gchar         **values,
10836                              gpointer              user_data,
10837                              GError              **error)
10838 {
10839   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10840   guint i;
10841   gint line_number, char_number;
10842
10843   if (strcmp (element_name, "relation") == 0)
10844     {
10845       gchar *target = NULL;
10846       gchar *type = NULL;
10847       AtkRelationData *relation;
10848
10849       for (i = 0; names[i]; i++)
10850         {
10851           if (strcmp (names[i], "target") == 0)
10852             target = g_strdup (values[i]);
10853           else if (strcmp (names[i], "type") == 0)
10854             type = g_strdup (values[i]);
10855           else
10856             {
10857               g_markup_parse_context_get_position (context,
10858                                                    &line_number,
10859                                                    &char_number);
10860               g_set_error (error,
10861                            GTK_BUILDER_ERROR,
10862                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10863                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10864                            "<input>",
10865                            line_number, char_number, names[i], "relation");
10866               g_free (target);
10867               g_free (type);
10868               return;
10869             }
10870         }
10871
10872       if (!target || !type)
10873         {
10874           g_markup_parse_context_get_position (context,
10875                                                &line_number,
10876                                                &char_number);
10877           g_set_error (error,
10878                        GTK_BUILDER_ERROR,
10879                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10880                        "%s:%d:%d <%s> requires attribute \"%s\"",
10881                        "<input>",
10882                        line_number, char_number, "relation",
10883                        type ? "target" : "type");
10884           g_free (target);
10885           g_free (type);
10886           return;
10887         }
10888
10889       relation = g_slice_new (AtkRelationData);
10890       relation->target = target;
10891       relation->type = type;
10892
10893       data->relations = g_slist_prepend (data->relations, relation);
10894     }
10895   else if (strcmp (element_name, "action") == 0)
10896     {
10897       const gchar *action_name = NULL;
10898       const gchar *description = NULL;
10899       const gchar *msg_context = NULL;
10900       gboolean translatable = FALSE;
10901       AtkActionData *action;
10902
10903       for (i = 0; names[i]; i++)
10904         {
10905           if (strcmp (names[i], "action_name") == 0)
10906             action_name = values[i];
10907           else if (strcmp (names[i], "description") == 0)
10908             description = values[i];
10909           else if (strcmp (names[i], "translatable") == 0)
10910             {
10911               if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10912                 return;
10913             }
10914           else if (strcmp (names[i], "comments") == 0)
10915             {
10916               /* do nothing, comments are for translators */
10917             }
10918           else if (strcmp (names[i], "context") == 0)
10919             msg_context = values[i];
10920           else
10921             {
10922               g_markup_parse_context_get_position (context,
10923                                                    &line_number,
10924                                                    &char_number);
10925               g_set_error (error,
10926                            GTK_BUILDER_ERROR,
10927                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10928                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10929                            "<input>",
10930                            line_number, char_number, names[i], "action");
10931               return;
10932             }
10933         }
10934
10935       if (!action_name)
10936         {
10937           g_markup_parse_context_get_position (context,
10938                                                &line_number,
10939                                                &char_number);
10940           g_set_error (error,
10941                        GTK_BUILDER_ERROR,
10942                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10943                        "%s:%d:%d <%s> requires attribute \"%s\"",
10944                        "<input>",
10945                        line_number, char_number, "action",
10946                        "action_name");
10947           return;
10948         }
10949
10950       action = g_slice_new (AtkActionData);
10951       action->action_name = g_strdup (action_name);
10952       action->description = g_string_new (description);
10953       action->context = g_strdup (msg_context);
10954       action->translatable = translatable;
10955
10956       data->actions = g_slist_prepend (data->actions, action);
10957     }
10958   else if (strcmp (element_name, "accessibility") == 0)
10959     ;
10960   else
10961     g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10962 }
10963
10964 static void
10965 accessibility_text (GMarkupParseContext  *context,
10966                     const gchar          *text,
10967                     gsize                 text_len,
10968                     gpointer              user_data,
10969                     GError              **error)
10970 {
10971   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10972
10973   if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10974     {
10975       AtkActionData *action = data->actions->data;
10976
10977       g_string_append_len (action->description, text, text_len);
10978     }
10979 }
10980
10981 static const GMarkupParser accessibility_parser =
10982   {
10983     accessibility_start_element,
10984     NULL,
10985     accessibility_text,
10986   };
10987
10988 typedef struct
10989 {
10990   GObject *object;
10991   guint    key;
10992   guint    modifiers;
10993   gchar   *signal;
10994 } AccelGroupParserData;
10995
10996 static void
10997 accel_group_start_element (GMarkupParseContext  *context,
10998                            const gchar          *element_name,
10999                            const gchar         **names,
11000                            const gchar         **values,
11001                            gpointer              user_data,
11002                            GError              **error)
11003 {
11004   gint i;
11005   guint key = 0;
11006   guint modifiers = 0;
11007   gchar *signal = NULL;
11008   AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11009
11010   for (i = 0; names[i]; i++)
11011     {
11012       if (strcmp (names[i], "key") == 0)
11013         key = gdk_keyval_from_name (values[i]);
11014       else if (strcmp (names[i], "modifiers") == 0)
11015         {
11016           if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11017                                                values[i],
11018                                                &modifiers,
11019                                                error))
11020               return;
11021         }
11022       else if (strcmp (names[i], "signal") == 0)
11023         signal = g_strdup (values[i]);
11024     }
11025
11026   if (key == 0 || signal == NULL)
11027     {
11028       g_warning ("<accelerator> requires key and signal attributes");
11029       return;
11030     }
11031   parser_data->key = key;
11032   parser_data->modifiers = modifiers;
11033   parser_data->signal = signal;
11034 }
11035
11036 static const GMarkupParser accel_group_parser =
11037   {
11038     accel_group_start_element,
11039   };
11040
11041 static gboolean
11042 gtk_widget_buildable_custom_tag_start (GtkBuildable     *buildable,
11043                                        GtkBuilder       *builder,
11044                                        GObject          *child,
11045                                        const gchar      *tagname,
11046                                        GMarkupParser    *parser,
11047                                        gpointer         *data)
11048 {
11049   g_assert (buildable);
11050
11051   if (strcmp (tagname, "accelerator") == 0)
11052     {
11053       AccelGroupParserData *parser_data;
11054
11055       parser_data = g_slice_new0 (AccelGroupParserData);
11056       parser_data->object = g_object_ref (buildable);
11057       *parser = accel_group_parser;
11058       *data = parser_data;
11059       return TRUE;
11060     }
11061   if (strcmp (tagname, "accessibility") == 0)
11062     {
11063       AccessibilitySubParserData *parser_data;
11064
11065       parser_data = g_slice_new0 (AccessibilitySubParserData);
11066       *parser = accessibility_parser;
11067       *data = parser_data;
11068       return TRUE;
11069     }
11070   return FALSE;
11071 }
11072
11073 void
11074 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11075                                           GtkWidget *toplevel,
11076                                           gpointer   user_data)
11077 {
11078   AccelGroupParserData *accel_data;
11079   GSList *accel_groups;
11080   GtkAccelGroup *accel_group;
11081
11082   g_return_if_fail (GTK_IS_WIDGET (widget));
11083   g_return_if_fail (GTK_IS_WIDGET (toplevel));
11084   g_return_if_fail (user_data != NULL);
11085
11086   accel_data = (AccelGroupParserData*)user_data;
11087   accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11088   if (g_slist_length (accel_groups) == 0)
11089     {
11090       accel_group = gtk_accel_group_new ();
11091       gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11092     }
11093   else
11094     {
11095       g_assert (g_slist_length (accel_groups) == 1);
11096       accel_group = g_slist_nth_data (accel_groups, 0);
11097     }
11098
11099   gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11100                               accel_data->signal,
11101                               accel_group,
11102                               accel_data->key,
11103                               accel_data->modifiers,
11104                               GTK_ACCEL_VISIBLE);
11105
11106   g_object_unref (accel_data->object);
11107   g_free (accel_data->signal);
11108   g_slice_free (AccelGroupParserData, accel_data);
11109 }
11110
11111 static void
11112 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11113                                       GtkBuilder   *builder,
11114                                       GObject      *child,
11115                                       const gchar  *tagname,
11116                                       gpointer      user_data)
11117 {
11118   AccelGroupParserData *accel_data;
11119   AccessibilitySubParserData *a11y_data;
11120   GtkWidget *toplevel;
11121
11122   if (strcmp (tagname, "accelerator") == 0)
11123     {
11124       accel_data = (AccelGroupParserData*)user_data;
11125       g_assert (accel_data->object);
11126
11127       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11128
11129       _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11130     }
11131   else if (strcmp (tagname, "accessibility") == 0)
11132     {
11133       a11y_data = (AccessibilitySubParserData*)user_data;
11134
11135       if (a11y_data->actions)
11136         {
11137           AtkObject *accessible;
11138           AtkAction *action;
11139           gint i, n_actions;
11140           GSList *l;
11141
11142           accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11143
11144           action = ATK_ACTION (accessible);
11145           n_actions = atk_action_get_n_actions (action);
11146
11147           for (l = a11y_data->actions; l; l = l->next)
11148             {
11149               AtkActionData *action_data = (AtkActionData*)l->data;
11150
11151               for (i = 0; i < n_actions; i++)
11152                 if (strcmp (atk_action_get_name (action, i),
11153                             action_data->action_name) == 0)
11154                   break;
11155
11156               if (i < n_actions)
11157                 {
11158                   gchar *description;
11159
11160                   if (action_data->translatable && action_data->description->len)
11161                     description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11162                                                                  action_data->context,
11163                                                                  action_data->description->str);
11164                   else
11165                     description = action_data->description->str;
11166
11167                   atk_action_set_description (action, i, description);
11168                 }
11169             }
11170
11171           g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11172           g_slist_free (a11y_data->actions);
11173         }
11174
11175       if (a11y_data->relations)
11176         g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11177                             a11y_data->relations);
11178
11179       g_slice_free (AccessibilitySubParserData, a11y_data);
11180     }
11181 }
11182
11183 /*
11184  * GtkSizeRequest implementation
11185  */
11186 static void
11187 gtk_widget_real_get_width (GtkSizeRequest *widget,
11188                            gint           *minimum_size,
11189                            gint           *natural_size)
11190 {
11191   if (minimum_size)
11192     *minimum_size = 0;
11193
11194   if (natural_size)
11195     *natural_size = 0;
11196 }
11197
11198 static void
11199 gtk_widget_real_get_height (GtkSizeRequest *widget,
11200                             gint           *minimum_size,
11201                             gint           *natural_size)
11202 {
11203   if (minimum_size)
11204     *minimum_size = 0;
11205
11206   if (natural_size)
11207     *natural_size = 0;
11208 }
11209
11210 static void
11211 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11212                                       gint       width,
11213                                       gint      *minimum_height,
11214                                       gint      *natural_height)
11215 {
11216   GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11217 }
11218
11219 static void
11220 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11221                                       gint       height,
11222                                       gint      *minimum_width,
11223                                       gint      *natural_width)
11224 {
11225   GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11226 }
11227
11228 static void
11229 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11230 {
11231   iface->get_width            = gtk_widget_real_get_width;
11232   iface->get_height           = gtk_widget_real_get_height;
11233   iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11234   iface->get_height_for_width = gtk_widget_real_get_height_for_width;  
11235 }
11236
11237 /**
11238  * gtk_widget_get_halign:
11239  * @widget: a #GtkWidget
11240  *
11241  * Gets the value of the #GtkWidget:halign property.
11242  *
11243  * Returns: the horizontal alignment of @widget
11244  */
11245 GtkAlign
11246 gtk_widget_get_halign (GtkWidget *widget)
11247 {
11248   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11249   return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11250 }
11251
11252 /**
11253  * gtk_widget_set_halign:
11254  * @widget: a #GtkWidget
11255  * @align: the horizontal alignment
11256  *
11257  * Sets the horizontal alignment of @widget.
11258  * See the #GtkWidget:halign property.
11259  */
11260 void
11261 gtk_widget_set_halign (GtkWidget *widget,
11262                        GtkAlign   align)
11263 {
11264   GtkWidgetAuxInfo *aux_info;
11265
11266   g_return_if_fail (GTK_IS_WIDGET (widget));
11267
11268   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11269
11270   if (aux_info->halign == align)
11271     return;
11272
11273   aux_info->halign = align;
11274   gtk_widget_queue_resize (widget);
11275   g_object_notify (G_OBJECT (widget), "halign");
11276 }
11277
11278 /**
11279  * gtk_widget_get_valign:
11280  * @widget: a #GtkWidget
11281  *
11282  * Gets the value of the #GtkWidget:valign property.
11283  *
11284  * Returns: the vertical alignment of @widget
11285  */
11286 GtkAlign
11287 gtk_widget_get_valign (GtkWidget *widget)
11288 {
11289   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11290   return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11291 }
11292
11293 /**
11294  * gtk_widget_set_valign:
11295  * @widget: a #GtkWidget
11296  * @align: the vertical alignment
11297  *
11298  * Sets the vertical alignment of @widget.
11299  * See the #GtkWidget:valign property.
11300  */
11301 void
11302 gtk_widget_set_valign (GtkWidget *widget,
11303                        GtkAlign   align)
11304 {
11305   GtkWidgetAuxInfo *aux_info;
11306
11307   g_return_if_fail (GTK_IS_WIDGET (widget));
11308
11309   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11310
11311   if (aux_info->valign == align)
11312     return;
11313
11314   aux_info->valign = align;
11315   gtk_widget_queue_resize (widget);
11316   g_object_notify (G_OBJECT (widget), "valign");
11317 }
11318
11319 /**
11320  * gtk_widget_get_margin_left:
11321  * @widget: a #GtkWidget
11322  *
11323  * Gets the value of the #GtkWidget:margin-left property.
11324  *
11325  * Returns: The left margin of @widget
11326  */
11327 gint
11328 gtk_widget_get_margin_left (GtkWidget *widget)
11329 {
11330   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11331
11332   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11333 }
11334
11335 /**
11336  * gtk_widget_set_margin_left:
11337  * @widget: a #GtkWidget
11338  * @margin: the left margin
11339  *
11340  * Sets the left margin of @widget.
11341  * See the #GtkWidget:margin-left property.
11342  */
11343 void
11344 gtk_widget_set_margin_left (GtkWidget *widget,
11345                             gint       margin)
11346 {
11347   GtkWidgetAuxInfo *aux_info;
11348
11349   g_return_if_fail (GTK_IS_WIDGET (widget));
11350   g_return_if_fail (margin <= G_MAXINT16);
11351
11352   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11353
11354   if (aux_info->margin.left == margin)
11355     return;
11356
11357   aux_info->margin.left = margin;
11358   gtk_widget_queue_resize (widget);
11359   g_object_notify (G_OBJECT (widget), "margin-left");
11360 }
11361
11362 /**
11363  * gtk_widget_get_margin_right:
11364  * @widget: a #GtkWidget
11365  *
11366  * Gets the value of the #GtkWidget:margin-right property.
11367  *
11368  * Returns: The left margin of @widget
11369  */
11370 gint
11371 gtk_widget_get_margin_right (GtkWidget *widget)
11372 {
11373   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11374
11375   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11376 }
11377
11378 /**
11379  * gtk_widget_set_margin_right:
11380  * @widget: a #GtkWidget
11381  * @margin: the right margin
11382  *
11383  * Sets the right margin of @widget.
11384  * See the #GtkWidget:margin-right property.
11385  */
11386 void
11387 gtk_widget_set_margin_right (GtkWidget *widget,
11388                              gint       margin)
11389 {
11390   GtkWidgetAuxInfo *aux_info;
11391
11392   g_return_if_fail (GTK_IS_WIDGET (widget));
11393   g_return_if_fail (margin <= G_MAXINT16);
11394
11395   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11396
11397   if (aux_info->margin.right == margin)
11398     return;
11399
11400   aux_info->margin.right = margin;
11401   gtk_widget_queue_resize (widget);
11402   g_object_notify (G_OBJECT (widget), "margin-right");
11403 }
11404
11405 /**
11406  * gtk_widget_get_margin_top:
11407  * @widget: a #GtkWidget
11408  *
11409  * Gets the value of the #GtkWidget:margin-top property.
11410  *
11411  * Returns: The top margin of @widget
11412  */
11413 gint
11414 gtk_widget_get_margin_top (GtkWidget *widget)
11415 {
11416   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11417
11418   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11419 }
11420
11421 /**
11422  * gtk_widget_set_margin_top:
11423  * @widget: a #GtkWidget
11424  * @margin: the top margin
11425  *
11426  * Sets the top margin of @widget.
11427  * See the #GtkWidget:margin-top property.
11428  */
11429 void
11430 gtk_widget_set_margin_top (GtkWidget *widget,
11431                            gint       margin)
11432 {
11433   GtkWidgetAuxInfo *aux_info;
11434
11435   g_return_if_fail (GTK_IS_WIDGET (widget));
11436   g_return_if_fail (margin <= G_MAXINT16);
11437
11438   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11439
11440   if (aux_info->margin.top == margin)
11441     return;
11442
11443   aux_info->margin.top = margin;
11444   gtk_widget_queue_resize (widget);
11445   g_object_notify (G_OBJECT (widget), "margin-top");
11446 }
11447
11448 /**
11449  * gtk_widget_get_margin_bottom:
11450  * @widget: a #GtkWidget
11451  *
11452  * Gets the value of the #GtkWidget:margin-bottom property.
11453  *
11454  * Returns: The bottom margin of @widget
11455  */
11456 gint
11457 gtk_widget_get_margin_bottom (GtkWidget *widget)
11458 {
11459   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11460
11461   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11462 }
11463
11464 /**
11465  * gtk_widget_set_margin_bottom:
11466  * @widget: a #GtkWidget
11467  * @margin: the bottom margin
11468  *
11469  * Sets the bottom margin of @widget.
11470  * See the #GtkWidget:margin-bottom property.
11471  */
11472 void
11473 gtk_widget_set_margin_bottom (GtkWidget *widget,
11474                               gint       margin)
11475 {
11476   GtkWidgetAuxInfo *aux_info;
11477
11478   g_return_if_fail (GTK_IS_WIDGET (widget));
11479   g_return_if_fail (margin <= G_MAXINT16);
11480
11481   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11482
11483   if (aux_info->margin.bottom == margin)
11484     return;
11485
11486   aux_info->margin.bottom = margin;
11487   gtk_widget_queue_resize (widget);
11488   g_object_notify (G_OBJECT (widget), "margin-bottom");
11489 }
11490
11491 /**
11492  * gtk_widget_get_clipboard:
11493  * @widget: a #GtkWidget
11494  * @selection: a #GdkAtom which identifies the clipboard
11495  *             to use. %GDK_SELECTION_CLIPBOARD gives the
11496  *             default clipboard. Another common value
11497  *             is %GDK_SELECTION_PRIMARY, which gives
11498  *             the primary X selection. 
11499  * 
11500  * Returns the clipboard object for the given selection to
11501  * be used with @widget. @widget must have a #GdkDisplay
11502  * associated with it, so must be attached to a toplevel
11503  * window.
11504  *
11505  * Return value: (transfer none): the appropriate clipboard object. If no
11506  *             clipboard already exists, a new one will
11507  *             be created. Once a clipboard object has
11508  *             been created, it is persistent for all time.
11509  *
11510  * Since: 2.2
11511  **/
11512 GtkClipboard *
11513 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11514 {
11515   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11516   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11517
11518   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11519                                         selection);
11520 }
11521
11522 /**
11523  * gtk_widget_list_mnemonic_labels:
11524  * @widget: a #GtkWidget
11525  *
11526  * Returns a newly allocated list of the widgets, normally labels, for
11527  * which this widget is the target of a mnemonic (see for example,
11528  * gtk_label_set_mnemonic_widget()).
11529
11530  * The widgets in the list are not individually referenced. If you
11531  * want to iterate through the list and perform actions involving
11532  * callbacks that might destroy the widgets, you
11533  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11534  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11535  * widgets afterwards.
11536
11537  * Return value: (element-type GtkWidget) (transfer container): the list of
11538  *  mnemonic labels; free this list
11539  *  with g_list_free() when you are done with it.
11540  *
11541  * Since: 2.4
11542  **/
11543 GList *
11544 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11545 {
11546   GList *list = NULL;
11547   GSList *l;
11548   
11549   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11550
11551   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11552     list = g_list_prepend (list, l->data);
11553
11554   return list;
11555 }
11556
11557 /**
11558  * gtk_widget_add_mnemonic_label:
11559  * @widget: a #GtkWidget
11560  * @label: a #GtkWidget that acts as a mnemonic label for @widget
11561  * 
11562  * Adds a widget to the list of mnemonic labels for
11563  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11564  * list of mnemonic labels for the widget is cleared when the
11565  * widget is destroyed, so the caller must make sure to update
11566  * its internal state at this point as well, by using a connection
11567  * to the #GtkWidget::destroy signal or a weak notifier.
11568  *
11569  * Since: 2.4
11570  **/
11571 void
11572 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11573                                GtkWidget *label)
11574 {
11575   GSList *old_list, *new_list;
11576
11577   g_return_if_fail (GTK_IS_WIDGET (widget));
11578   g_return_if_fail (GTK_IS_WIDGET (label));
11579
11580   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11581   new_list = g_slist_prepend (old_list, label);
11582   
11583   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11584                            new_list, (GDestroyNotify) g_slist_free);
11585 }
11586
11587 /**
11588  * gtk_widget_remove_mnemonic_label:
11589  * @widget: a #GtkWidget
11590  * @label: a #GtkWidget that was previously set as a mnemnic label for
11591  *         @widget with gtk_widget_add_mnemonic_label().
11592  * 
11593  * Removes a widget from the list of mnemonic labels for
11594  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11595  * must have previously been added to the list with
11596  * gtk_widget_add_mnemonic_label().
11597  *
11598  * Since: 2.4
11599  **/
11600 void
11601 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11602                                   GtkWidget *label)
11603 {
11604   GSList *old_list, *new_list;
11605
11606   g_return_if_fail (GTK_IS_WIDGET (widget));
11607   g_return_if_fail (GTK_IS_WIDGET (label));
11608
11609   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11610   new_list = g_slist_remove (old_list, label);
11611
11612   if (new_list)
11613     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11614                              new_list, (GDestroyNotify) g_slist_free);
11615 }
11616
11617 /**
11618  * gtk_widget_get_no_show_all:
11619  * @widget: a #GtkWidget
11620  * 
11621  * Returns the current value of the GtkWidget:no-show-all property, 
11622  * which determines whether calls to gtk_widget_show_all() and 
11623  * gtk_widget_hide_all() will affect this widget. 
11624  * 
11625  * Return value: the current value of the "no-show-all" property.
11626  *
11627  * Since: 2.4
11628  **/
11629 gboolean
11630 gtk_widget_get_no_show_all (GtkWidget *widget)
11631 {
11632   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11633   
11634   return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11635 }
11636
11637 /**
11638  * gtk_widget_set_no_show_all:
11639  * @widget: a #GtkWidget
11640  * @no_show_all: the new value for the "no-show-all" property
11641  * 
11642  * Sets the #GtkWidget:no-show-all property, which determines whether 
11643  * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect 
11644  * this widget. 
11645  *
11646  * This is mostly for use in constructing widget hierarchies with externally
11647  * controlled visibility, see #GtkUIManager.
11648  * 
11649  * Since: 2.4
11650  **/
11651 void
11652 gtk_widget_set_no_show_all (GtkWidget *widget,
11653                             gboolean   no_show_all)
11654 {
11655   g_return_if_fail (GTK_IS_WIDGET (widget));
11656
11657   no_show_all = (no_show_all != FALSE);
11658
11659   if (no_show_all == gtk_widget_get_no_show_all (widget))
11660     return;
11661
11662   if (no_show_all)
11663     GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11664   else
11665     GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11666   
11667   g_object_notify (G_OBJECT (widget), "no-show-all");
11668 }
11669
11670
11671 static void
11672 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11673                                  gboolean   has_tooltip,
11674                                  gboolean   force)
11675 {
11676   GtkWidgetPrivate *priv = widget->priv;
11677   gboolean priv_has_tooltip;
11678
11679   priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11680                                        quark_has_tooltip));
11681
11682   if (priv_has_tooltip != has_tooltip || force)
11683     {
11684       priv_has_tooltip = has_tooltip;
11685
11686       if (priv_has_tooltip)
11687         {
11688           if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11689             gdk_window_set_events (priv->window,
11690                                    gdk_window_get_events (priv->window) |
11691                                    GDK_LEAVE_NOTIFY_MASK |
11692                                    GDK_POINTER_MOTION_MASK |
11693                                    GDK_POINTER_MOTION_HINT_MASK);
11694
11695           if (gtk_widget_get_has_window (widget))
11696               gtk_widget_add_events (widget,
11697                                      GDK_LEAVE_NOTIFY_MASK |
11698                                      GDK_POINTER_MOTION_MASK |
11699                                      GDK_POINTER_MOTION_HINT_MASK);
11700         }
11701
11702       g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11703                           GUINT_TO_POINTER (priv_has_tooltip));
11704     }
11705 }
11706
11707 /**
11708  * gtk_widget_set_tooltip_window:
11709  * @widget: a #GtkWidget
11710  * @custom_window: (allow-none): a #GtkWindow, or %NULL
11711  *
11712  * Replaces the default, usually yellow, window used for displaying
11713  * tooltips with @custom_window. GTK+ will take care of showing and
11714  * hiding @custom_window at the right moment, to behave likewise as
11715  * the default tooltip window. If @custom_window is %NULL, the default
11716  * tooltip window will be used.
11717  *
11718  * If the custom window should have the default theming it needs to
11719  * have the name "gtk-tooltip", see gtk_widget_set_name().
11720  *
11721  * Since: 2.12
11722  */
11723 void
11724 gtk_widget_set_tooltip_window (GtkWidget *widget,
11725                                GtkWindow *custom_window)
11726 {
11727   gboolean has_tooltip;
11728   gchar *tooltip_markup;
11729
11730   g_return_if_fail (GTK_IS_WIDGET (widget));
11731   g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11732
11733   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11734
11735   if (custom_window)
11736     g_object_ref (custom_window);
11737
11738   g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11739                            custom_window, g_object_unref);
11740
11741   has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11742   gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11743
11744   if (has_tooltip && gtk_widget_get_visible (widget))
11745     gtk_widget_queue_tooltip_query (widget);
11746 }
11747
11748 /**
11749  * gtk_widget_get_tooltip_window:
11750  * @widget: a #GtkWidget
11751  *
11752  * Returns the #GtkWindow of the current tooltip. This can be the
11753  * GtkWindow created by default, or the custom tooltip window set
11754  * using gtk_widget_set_tooltip_window().
11755  *
11756  * Return value: (transfer none): The #GtkWindow of the current tooltip.
11757  *
11758  * Since: 2.12
11759  */
11760 GtkWindow *
11761 gtk_widget_get_tooltip_window (GtkWidget *widget)
11762 {
11763   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11764
11765   return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11766 }
11767
11768 /**
11769  * gtk_widget_trigger_tooltip_query:
11770  * @widget: a #GtkWidget
11771  *
11772  * Triggers a tooltip query on the display where the toplevel of @widget
11773  * is located. See gtk_tooltip_trigger_tooltip_query() for more
11774  * information.
11775  *
11776  * Since: 2.12
11777  */
11778 void
11779 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11780 {
11781   gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11782 }
11783
11784 static guint tooltip_query_id;
11785 static GSList *tooltip_query_displays;
11786
11787 static gboolean
11788 tooltip_query_idle (gpointer data)
11789 {
11790   g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11791   g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11792   g_slist_free (tooltip_query_displays);
11793
11794   tooltip_query_displays = NULL;
11795   tooltip_query_id = 0;
11796
11797   return FALSE;
11798 }
11799
11800 static void
11801 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11802 {
11803   GdkDisplay *display;
11804
11805   display = gtk_widget_get_display (widget);
11806
11807   if (!g_slist_find (tooltip_query_displays, display))
11808     tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11809
11810   if (tooltip_query_id == 0)
11811     tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11812 }
11813
11814 /**
11815  * gtk_widget_set_tooltip_text:
11816  * @widget: a #GtkWidget
11817  * @text: the contents of the tooltip for @widget
11818  *
11819  * Sets @text as the contents of the tooltip. This function will take
11820  * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11821  * handler for the GtkWidget::query-tooltip signal.
11822  *
11823  * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11824  *
11825  * Since: 2.12
11826  */
11827 void
11828 gtk_widget_set_tooltip_text (GtkWidget   *widget,
11829                              const gchar *text)
11830 {
11831   g_return_if_fail (GTK_IS_WIDGET (widget));
11832
11833   g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11834 }
11835
11836 /**
11837  * gtk_widget_get_tooltip_text:
11838  * @widget: a #GtkWidget
11839  *
11840  * Gets the contents of the tooltip for @widget.
11841  *
11842  * Return value: the tooltip text, or %NULL. You should free the
11843  *   returned string with g_free() when done.
11844  *
11845  * Since: 2.12
11846  */
11847 gchar *
11848 gtk_widget_get_tooltip_text (GtkWidget *widget)
11849 {
11850   gchar *text = NULL;
11851
11852   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11853
11854   g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11855
11856   return text;
11857 }
11858
11859 /**
11860  * gtk_widget_set_tooltip_markup:
11861  * @widget: a #GtkWidget
11862  * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11863  *
11864  * Sets @markup as the contents of the tooltip, which is marked up with
11865  *  the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11866  *
11867  * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11868  * and of the default handler for the GtkWidget::query-tooltip signal.
11869  *
11870  * See also the GtkWidget:tooltip-markup property and
11871  * gtk_tooltip_set_markup().
11872  *
11873  * Since: 2.12
11874  */
11875 void
11876 gtk_widget_set_tooltip_markup (GtkWidget   *widget,
11877                                const gchar *markup)
11878 {
11879   g_return_if_fail (GTK_IS_WIDGET (widget));
11880
11881   g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11882 }
11883
11884 /**
11885  * gtk_widget_get_tooltip_markup:
11886  * @widget: a #GtkWidget
11887  *
11888  * Gets the contents of the tooltip for @widget.
11889  *
11890  * Return value: the tooltip text, or %NULL. You should free the
11891  *   returned string with g_free() when done.
11892  *
11893  * Since: 2.12
11894  */
11895 gchar *
11896 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11897 {
11898   gchar *text = NULL;
11899
11900   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11901
11902   g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11903
11904   return text;
11905 }
11906
11907 /**
11908  * gtk_widget_set_has_tooltip:
11909  * @widget: a #GtkWidget
11910  * @has_tooltip: whether or not @widget has a tooltip.
11911  *
11912  * Sets the has-tooltip property on @widget to @has_tooltip.  See
11913  * GtkWidget:has-tooltip for more information.
11914  *
11915  * Since: 2.12
11916  */
11917 void
11918 gtk_widget_set_has_tooltip (GtkWidget *widget,
11919                             gboolean   has_tooltip)
11920 {
11921   g_return_if_fail (GTK_IS_WIDGET (widget));
11922
11923   g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11924 }
11925
11926 /**
11927  * gtk_widget_get_has_tooltip:
11928  * @widget: a #GtkWidget
11929  *
11930  * Returns the current value of the has-tooltip property.  See
11931  * GtkWidget:has-tooltip for more information.
11932  *
11933  * Return value: current value of has-tooltip on @widget.
11934  *
11935  * Since: 2.12
11936  */
11937 gboolean
11938 gtk_widget_get_has_tooltip (GtkWidget *widget)
11939 {
11940   gboolean has_tooltip = FALSE;
11941
11942   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11943
11944   g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11945
11946   return has_tooltip;
11947 }
11948
11949 /**
11950  * gtk_widget_get_allocation:
11951  * @widget: a #GtkWidget
11952  * @allocation: (out): a pointer to a #GtkAllocation to copy to
11953  *
11954  * Retrieves the widget's allocation.
11955  *
11956  * Note, when implementing a #GtkContainer: a widget's allocation will
11957  * be its "adjusted" allocation, that is, the widget's parent
11958  * container typically calls gtk_widget_size_allocate() with an
11959  * allocation, and that allocation is then adjusted (to handle margin
11960  * and alignment for example) before assignment to the widget.
11961  * gtk_widget_get_allocation() returns the adjusted allocation that
11962  * was actually assigned to the widget. The adjusted allocation is
11963  * guaranteed to be completely contained within the
11964  * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11965  * is guaranteed that its children stay inside the assigned bounds,
11966  * but not that they have exactly the bounds the container assigned.
11967  * There is no way to get the original allocation assigned by
11968  * gtk_widget_size_allocate(), since it isn't stored; if a container
11969  * implementation needs that information it will have to track it itself.
11970  *
11971  * Since: 2.18
11972  */
11973 void
11974 gtk_widget_get_allocation (GtkWidget     *widget,
11975                            GtkAllocation *allocation)
11976 {
11977   GtkWidgetPrivate *priv;
11978
11979   g_return_if_fail (GTK_IS_WIDGET (widget));
11980   g_return_if_fail (allocation != NULL);
11981
11982   priv = widget->priv;
11983
11984   *allocation = priv->allocation;
11985 }
11986
11987 /**
11988  * gtk_widget_set_allocation:
11989  * @widget: a #GtkWidget
11990  * @allocation: a pointer to a #GtkAllocation to copy from
11991  *
11992  * Sets the widget's allocation.  This should not be used
11993  * directly, but from within a widget's size_allocate method.
11994  *
11995  * The allocation set should be the "adjusted" or actual
11996  * allocation. If you're implementing a #GtkContainer, you want to use
11997  * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
11998  * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
11999  * allocation inside gtk_widget_size_allocate() to create an adjusted
12000  * allocation.
12001  *
12002  * Since: 2.18
12003  */
12004 void
12005 gtk_widget_set_allocation (GtkWidget           *widget,
12006                            const GtkAllocation *allocation)
12007 {
12008   GtkWidgetPrivate *priv;
12009
12010   g_return_if_fail (GTK_IS_WIDGET (widget));
12011   g_return_if_fail (allocation != NULL);
12012
12013   priv = widget->priv;
12014
12015   priv->allocation = *allocation;
12016 }
12017
12018 /**
12019  * gtk_widget_get_allocated_width:
12020  * @widget: the widget to query
12021  *
12022  * Returns the width that has currently been allocated to @widget.
12023  * This function is intended to be used when implementing handlers
12024  * for the GtkWidget::draw function.
12025  *
12026  * Returns: the width of the @widget
12027  **/
12028 int
12029 gtk_widget_get_allocated_width (GtkWidget *widget)
12030 {
12031   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12032
12033   return widget->priv->allocation.width;
12034 }
12035
12036 /**
12037  * gtk_widget_get_allocated_height:
12038  * @widget: the widget to query
12039  *
12040  * Returns the height that has currently been allocated to @widget.
12041  * This function is intended to be used when implementing handlers
12042  * for the GtkWidget::draw function.
12043  *
12044  * Returns: the height of the @widget
12045  **/
12046 int
12047 gtk_widget_get_allocated_height (GtkWidget *widget)
12048 {
12049   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12050
12051   return widget->priv->allocation.height;
12052 }
12053
12054 /**
12055  * gtk_widget_get_requisition:
12056  * @widget: a #GtkWidget
12057  * @requisition: (out): a pointer to a #GtkRequisition to copy to
12058  *
12059  * Retrieves the widget's requisition.
12060  *
12061  * This function should only be used by widget implementations in
12062  * order to figure whether the widget's requisition has actually
12063  * changed after some internal state change (so that they can call
12064  * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12065  *
12066  * Normally, gtk_widget_size_request() should be used.
12067  *
12068  * Since: 2.20
12069  *
12070  * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12071  * removed, If you need to cache sizes across requests and allocations,
12072  * add an explicit cache to the widget in question instead.
12073  */
12074 void
12075 gtk_widget_get_requisition (GtkWidget      *widget,
12076                             GtkRequisition *requisition)
12077 {
12078   g_return_if_fail (GTK_IS_WIDGET (widget));
12079   g_return_if_fail (requisition != NULL);
12080
12081   gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12082 }
12083
12084 /**
12085  * gtk_widget_set_window:
12086  * @widget: a #GtkWidget
12087  * @window: a #GdkWindow
12088  *
12089  * Sets a widget's window. This function should only be used in a
12090  * widget's GtkWidget::realize() implementation. The %window passed is
12091  * usually either new window created with gdk_window_new(), or the
12092  * window of its parent widget as returned by
12093  * gtk_widget_get_parent_window().
12094  *
12095  * Widgets must indicate whether they will create their own #GdkWindow
12096  * by calling gtk_widget_set_has_window(). This is usually done in the
12097  * widget's init() function.
12098  *
12099  * <note><para>This function does not add any reference to @window.</para></note>
12100  *
12101  * Since: 2.18
12102  */
12103 void
12104 gtk_widget_set_window (GtkWidget *widget,
12105                        GdkWindow *window)
12106 {
12107   GtkWidgetPrivate *priv;
12108
12109   g_return_if_fail (GTK_IS_WIDGET (widget));
12110   g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12111
12112   priv = widget->priv;
12113
12114   if (priv->window != window)
12115     {
12116       priv->window = window;
12117       g_object_notify (G_OBJECT (widget), "window");
12118     }
12119 }
12120
12121 /**
12122  * gtk_widget_get_window:
12123  * @widget: a #GtkWidget
12124  *
12125  * Returns the widget's window if it is realized, %NULL otherwise
12126  *
12127  * Return value: (transfer none): @widget's window.
12128  *
12129  * Since: 2.14
12130  */
12131 GdkWindow*
12132 gtk_widget_get_window (GtkWidget *widget)
12133 {
12134   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12135
12136   return widget->priv->window;
12137 }
12138
12139 /**
12140  * gtk_widget_get_support_multidevice:
12141  * @widget: a #GtkWidget
12142  *
12143  * Returns %TRUE if @widget is multiple pointer aware. See
12144  * gtk_widget_set_support_multidevice() for more information.
12145  *
12146  * Returns: %TRUE is @widget is multidevice aware.
12147  **/
12148 gboolean
12149 gtk_widget_get_support_multidevice (GtkWidget *widget)
12150 {
12151   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12152
12153   return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12154 }
12155
12156 /**
12157  * gtk_widget_set_support_multidevice:
12158  * @widget: a #GtkWidget
12159  * @support_multidevice: %TRUE to support input from multiple devices.
12160  *
12161  * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12162  * @widget will start receiving multiple, per device enter/leave events. Note
12163  * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12164  * gdk_window_set_support_multidevice() will have to be called manually on them.
12165  *
12166  * Since: 3.0
12167  **/
12168 void
12169 gtk_widget_set_support_multidevice (GtkWidget *widget,
12170                                     gboolean   support_multidevice)
12171 {
12172   GtkWidgetPrivate *priv;
12173
12174   g_return_if_fail (GTK_IS_WIDGET (widget));
12175
12176   priv = widget->priv;
12177
12178   if (support_multidevice)
12179     {
12180       GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12181       gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12182     }
12183   else
12184     {
12185       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12186       gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12187     }
12188
12189   if (gtk_widget_get_realized (widget))
12190     gdk_window_set_support_multidevice (priv->window, support_multidevice);
12191 }
12192
12193 static void
12194 _gtk_widget_set_has_focus (GtkWidget *widget,
12195                            gboolean   has_focus)
12196 {
12197   if (has_focus)
12198     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12199   else
12200     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12201 }
12202
12203 /**
12204  * gtk_widget_send_focus_change:
12205  * @widget: a #GtkWidget
12206  * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12207  *
12208  * Sends the focus change @event to @widget
12209  *
12210  * This function is not meant to be used by applications. The only time it
12211  * should be used is when it is necessary for a #GtkWidget to assign focus
12212  * to a widget that is semantically owned by the first widget even though
12213  * it's not a direct child - for instance, a search entry in a floating
12214  * window similar to the quick search in #GtkTreeView.
12215  *
12216  * An example of its usage is:
12217  *
12218  * |[
12219  *   GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12220  *
12221  *   fevent->focus_change.type = GDK_FOCUS_CHANGE;
12222  *   fevent->focus_change.in = TRUE;
12223  *   fevent->focus_change.window = gtk_widget_get_window (widget);
12224  *   if (fevent->focus_change.window != NULL)
12225  *     g_object_ref (fevent->focus_change.window);
12226  *
12227  *   gtk_widget_send_focus_change (widget, fevent);
12228  *
12229  *   gdk_event_free (event);
12230  * ]|
12231  *
12232  * Return value: the return value from the event signal emission: %TRUE
12233  *   if the event was handled, and %FALSE otherwise
12234  *
12235  * Since: 2.20
12236  */
12237 gboolean
12238 gtk_widget_send_focus_change (GtkWidget *widget,
12239                               GdkEvent  *event)
12240 {
12241   gboolean res;
12242
12243   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12244   g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12245
12246   g_object_ref (widget);
12247
12248   _gtk_widget_set_has_focus (widget, event->focus_change.in);
12249
12250   res = gtk_widget_event (widget, event);
12251
12252   g_object_notify (G_OBJECT (widget), "has-focus");
12253
12254   g_object_unref (widget);
12255
12256   return res;
12257 }