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