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