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