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