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