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