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