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