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