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