]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
Change GtkIconSize to int in params/return values
[~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: (inout) (transfer none): 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: (out): location to store X position relative to @dest_widget
4163  * @dest_y: (out): 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: (allow-none): path used to look up the accelerator
4547  * @accel_group: (allow-none): 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: (allow-none): an adjustment for horizontal scrolling, or %NULL
4981  * @vadjustment: (allow-none): 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: (transfer none): 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: (allow-none): 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: (transfer none): 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: (transfer none): 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: (allow-none): 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: (allow-none): 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: (allow-none): 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: (allow-none): 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: (allow-none): 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: (transfer none): 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: (transfer none): 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: (type int) a stock size. A size of (GtkIconSize)-1 means
7163  *     render at the size of the source and don't scale (if there are
7164  *     multiple source sizes, GTK+ picks one of the available sizes).
7165  * @detail: (allow-none): 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  *
7245  * Gets @widget's parent window.
7246  *
7247  * Returns: (transfer none): the parent window of @widget.
7248  **/
7249 GdkWindow *
7250 gtk_widget_get_parent_window (GtkWidget *widget)
7251 {
7252   GdkWindow *parent_window;
7253
7254   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7255
7256   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7257
7258   return (parent_window != NULL) ? parent_window :
7259          (widget->parent != NULL) ? widget->parent->window : NULL;
7260 }
7261
7262
7263 /**
7264  * gtk_widget_set_child_visible:
7265  * @widget: a #GtkWidget
7266  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7267  *
7268  * Sets whether @widget should be mapped along with its when its parent
7269  * is mapped and @widget has been shown with gtk_widget_show(). 
7270  *
7271  * The child visibility can be set for widget before it is added to
7272  * a container with gtk_widget_set_parent(), to avoid mapping
7273  * children unnecessary before immediately unmapping them. However
7274  * it will be reset to its default state of %TRUE when the widget
7275  * is removed from a container.
7276  * 
7277  * Note that changing the child visibility of a widget does not
7278  * queue a resize on the widget. Most of the time, the size of
7279  * a widget is computed from all visible children, whether or
7280  * not they are mapped. If this is not the case, the container
7281  * can queue a resize itself.
7282  *
7283  * This function is only useful for container implementations and
7284  * never should be called by an application.
7285  **/
7286 void
7287 gtk_widget_set_child_visible (GtkWidget *widget,
7288                               gboolean   is_visible)
7289 {
7290   g_return_if_fail (GTK_IS_WIDGET (widget));
7291   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
7292
7293   g_object_ref (widget);
7294
7295   if (is_visible)
7296     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7297   else
7298     {
7299       GtkWidget *toplevel;
7300       
7301       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7302
7303       toplevel = gtk_widget_get_toplevel (widget);
7304       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
7305         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7306     }
7307
7308   if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
7309     {
7310       if (GTK_WIDGET_MAPPED (widget->parent) &&
7311           GTK_WIDGET_CHILD_VISIBLE (widget) &&
7312           GTK_WIDGET_VISIBLE (widget))
7313         gtk_widget_map (widget);
7314       else
7315         gtk_widget_unmap (widget);
7316     }
7317
7318   g_object_unref (widget);
7319 }
7320
7321 /**
7322  * gtk_widget_get_child_visible:
7323  * @widget: a #GtkWidget
7324  * 
7325  * Gets the value set with gtk_widget_set_child_visible().
7326  * If you feel a need to use this function, your code probably
7327  * needs reorganization. 
7328  *
7329  * This function is only useful for container implementations and
7330  * never should be called by an application.
7331  *
7332  * Return value: %TRUE if the widget is mapped with the parent.
7333  **/
7334 gboolean
7335 gtk_widget_get_child_visible (GtkWidget *widget)
7336 {
7337   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7338   
7339   return GTK_WIDGET_CHILD_VISIBLE (widget);
7340 }
7341
7342 static GdkScreen *
7343 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7344 {
7345   GtkWidget *toplevel;
7346   
7347   toplevel = gtk_widget_get_toplevel (widget);
7348
7349   if (GTK_WIDGET_TOPLEVEL (toplevel))
7350     {
7351       if (GTK_IS_WINDOW (toplevel))
7352         return GTK_WINDOW (toplevel)->screen;
7353       else if (GTK_IS_INVISIBLE (toplevel))
7354         return GTK_INVISIBLE (widget)->screen;
7355     }
7356
7357   return NULL;
7358 }
7359
7360 /**
7361  * gtk_widget_get_screen:
7362  * @widget: a #GtkWidget
7363  * 
7364  * Get the #GdkScreen from the toplevel window associated with
7365  * this widget. This function can only be called after the widget
7366  * has been added to a widget hierarchy with a #GtkWindow
7367  * at the top.
7368  *
7369  * In general, you should only create screen specific
7370  * resources when a widget has been realized, and you should
7371  * free those resources when the widget is unrealized.
7372  *
7373  * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7374  *
7375  * Since: 2.2
7376  **/
7377 GdkScreen*
7378 gtk_widget_get_screen (GtkWidget *widget)
7379 {
7380   GdkScreen *screen;
7381   
7382   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7383
7384   screen = gtk_widget_get_screen_unchecked (widget);
7385
7386   if (screen)
7387     return screen;
7388   else
7389     {
7390 #if 0
7391       g_warning (G_STRLOC ": Can't get associated screen"
7392                  " for a widget unless it is inside a toplevel GtkWindow\n"
7393                  " widget type is %s associated top level type is %s",
7394                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7395                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7396 #endif
7397       return gdk_screen_get_default ();
7398     }
7399 }
7400
7401 /**
7402  * gtk_widget_has_screen:
7403  * @widget: a #GtkWidget
7404  * 
7405  * Checks whether there is a #GdkScreen is associated with
7406  * this widget. All toplevel widgets have an associated
7407  * screen, and all widgets added into a hierarchy with a toplevel
7408  * window at the top.
7409  * 
7410  * Return value: %TRUE if there is a #GdkScreen associcated
7411  *   with the widget.
7412  *
7413  * Since: 2.2
7414  **/
7415 gboolean
7416 gtk_widget_has_screen (GtkWidget *widget)
7417 {
7418   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7419
7420   return (gtk_widget_get_screen_unchecked (widget) != NULL);
7421 }
7422
7423 /**
7424  * gtk_widget_get_display:
7425  * @widget: a #GtkWidget
7426  * 
7427  * Get the #GdkDisplay for the toplevel window associated with
7428  * this widget. This function can only be called after the widget
7429  * has been added to a widget hierarchy with a #GtkWindow at the top.
7430  *
7431  * In general, you should only create display specific
7432  * resources when a widget has been realized, and you should
7433  * free those resources when the widget is unrealized.
7434  *
7435  * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7436  *
7437  * Since: 2.2
7438  **/
7439 GdkDisplay*
7440 gtk_widget_get_display (GtkWidget *widget)
7441 {
7442   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7443   
7444   return gdk_screen_get_display (gtk_widget_get_screen (widget));
7445 }
7446
7447 /**
7448  * gtk_widget_get_root_window:
7449  * @widget: a #GtkWidget
7450  * 
7451  * Get the root window where this widget is located. This function can
7452  * only be called after the widget has been added to a widget
7453  * hierarchy with #GtkWindow at the top.
7454  *
7455  * The root window is useful for such purposes as creating a popup
7456  * #GdkWindow associated with the window. In general, you should only
7457  * create display specific resources when a widget has been realized,
7458  * and you should free those resources when the widget is unrealized.
7459  *
7460  * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7461  *
7462  * Since: 2.2
7463  **/
7464 GdkWindow*
7465 gtk_widget_get_root_window (GtkWidget *widget)
7466 {
7467   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7468
7469   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7470 }
7471
7472 /**
7473  * gtk_widget_child_focus:
7474  * @widget: a #GtkWidget
7475  * @direction: direction of focus movement
7476  *
7477  * This function is used by custom widget implementations; if you're
7478  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7479  * to a particular widget, and gtk_container_set_focus_chain() to
7480  * change the focus tab order. So you may want to investigate those
7481  * functions instead.
7482  * 
7483  * gtk_widget_child_focus() is called by containers as the user moves
7484  * around the window using keyboard shortcuts. @direction indicates
7485  * what kind of motion is taking place (up, down, left, right, tab
7486  * forward, tab backward). gtk_widget_child_focus() emits the
7487  * #GtkWidget::focus" signal; widgets override the default handler
7488  * for this signal in order to implement appropriate focus behavior.
7489  *
7490  * The default ::focus handler for a widget should return %TRUE if
7491  * moving in @direction left the focus on a focusable location inside
7492  * that widget, and %FALSE if moving in @direction moved the focus
7493  * outside the widget. If returning %TRUE, widgets normally
7494  * call gtk_widget_grab_focus() to place the focus accordingly;
7495  * if returning %FALSE, they don't modify the current focus location.
7496  * 
7497  * This function replaces gtk_container_focus() from GTK+ 1.2.  
7498  * It was necessary to check that the child was visible, sensitive, 
7499  * and focusable before calling gtk_container_focus(). 
7500  * gtk_widget_child_focus() returns %FALSE if the widget is not 
7501  * currently in a focusable state, so there's no need for those checks.
7502  * 
7503  * Return value: %TRUE if focus ended up inside @widget
7504  **/
7505 gboolean
7506 gtk_widget_child_focus (GtkWidget       *widget,
7507                         GtkDirectionType direction)
7508 {
7509   gboolean return_val;
7510
7511   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7512
7513   if (!GTK_WIDGET_VISIBLE (widget) ||
7514       !GTK_WIDGET_IS_SENSITIVE (widget))
7515     return FALSE;
7516
7517   /* child widgets must set CAN_FOCUS, containers
7518    * don't have to though.
7519    */
7520   if (!GTK_IS_CONTAINER (widget) &&
7521       !GTK_WIDGET_CAN_FOCUS (widget))
7522     return FALSE;
7523   
7524   g_signal_emit (widget,
7525                  widget_signals[FOCUS],
7526                  0,
7527                  direction, &return_val);
7528
7529   return return_val;
7530 }
7531
7532 /**
7533  * gtk_widget_keynav_failed:
7534  * @widget: a #GtkWidget
7535  * @direction: direction of focus movement
7536  *
7537  * This function should be called whenever keyboard navigation within
7538  * a single widget hits a boundary. The function emits the
7539  * #GtkWidget::keynav-failed signal on the widget and its return
7540  * value should be interpreted in a way similar to the return value of
7541  * gtk_widget_child_focus():
7542  *
7543  * When %TRUE is returned, stay in the widget, the failed keyboard
7544  * navigation is Ok and/or there is nowhere we can/should move the
7545  * focus to.
7546  *
7547  * When %FALSE is returned, the caller should continue with keyboard
7548  * navigation outside the widget, e.g. by calling
7549  * gtk_widget_child_focus() on the widget's toplevel.
7550  *
7551  * The default ::keynav-failed handler returns %TRUE for 
7552  * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other 
7553  * values of #GtkDirectionType, it looks at the 
7554  * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE 
7555  * if the setting is %TRUE. This way the entire user interface
7556  * becomes cursor-navigatable on input devices such as mobile phones
7557  * which only have cursor keys but no tab key.
7558  *
7559  * Whenever the default handler returns %TRUE, it also calls
7560  * gtk_widget_error_bell() to notify the user of the failed keyboard
7561  * navigation.
7562  *
7563  * A use case for providing an own implementation of ::keynav-failed 
7564  * (either by connecting to it or by overriding it) would be a row of
7565  * #GtkEntry widgets where the user should be able to navigate the
7566  * entire row with the cursor keys, as e.g. known from user interfaces 
7567  * that require entering license keys.
7568  *
7569  * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7570  *               if the emitting widget should try to handle the keyboard
7571  *               navigation attempt in its parent container(s).
7572  *
7573  * Since: 2.12
7574  **/
7575 gboolean
7576 gtk_widget_keynav_failed (GtkWidget        *widget,
7577                           GtkDirectionType  direction)
7578 {
7579   gboolean return_val;
7580
7581   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7582
7583   g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7584                  direction, &return_val);
7585
7586   return return_val;
7587 }
7588
7589 /**
7590  * gtk_widget_error_bell:
7591  * @widget: a #GtkWidget
7592  *
7593  * Notifies the user about an input-related error on this widget. 
7594  * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7595  * gdk_window_beep(), otherwise it does nothing.
7596  *
7597  * Note that the effect of gdk_window_beep() can be configured in many
7598  * ways, depending on the windowing backend and the desktop environment
7599  * or window manager that is used.
7600  *
7601  * Since: 2.12
7602  **/
7603 void
7604 gtk_widget_error_bell (GtkWidget *widget)
7605 {
7606   GtkSettings* settings;
7607   gboolean beep;
7608
7609   g_return_if_fail (GTK_IS_WIDGET (widget));
7610
7611   settings = gtk_widget_get_settings (widget);
7612   if (!settings)
7613     return;
7614
7615   g_object_get (settings,
7616                 "gtk-error-bell", &beep,
7617                 NULL);
7618
7619   if (beep && widget->window)
7620     gdk_window_beep (widget->window);
7621 }
7622
7623 /**
7624  * gtk_widget_set_uposition:
7625  * @widget: a #GtkWidget
7626  * @x: x position; -1 to unset x; -2 to leave x unchanged
7627  * @y: y position; -1 to unset y; -2 to leave y unchanged
7628  * 
7629  *
7630  * Sets the position of a widget. The funny "u" in the name comes from
7631  * the "user position" hint specified by the X Window System, and
7632  * exists for legacy reasons. This function doesn't work if a widget
7633  * is inside a container; it's only really useful on #GtkWindow.
7634  *
7635  * Don't use this function to center dialogs over the main application
7636  * window; most window managers will do the centering on your behalf
7637  * if you call gtk_window_set_transient_for(), and it's really not
7638  * possible to get the centering to work correctly in all cases from
7639  * application code. But if you insist, use gtk_window_set_position()
7640  * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7641  * manually.
7642  *
7643  * Note that although @x and @y can be individually unset, the position
7644  * is not honoured unless both @x and @y are set.
7645  **/
7646 void
7647 gtk_widget_set_uposition (GtkWidget *widget,
7648                           gint       x,
7649                           gint       y)
7650 {
7651   /* FIXME this function is the only place that aux_info->x and
7652    * aux_info->y are even used I believe, and this function is
7653    * deprecated. Should be cleaned up.
7654    *
7655    * (Actually, size_allocate uses them) -Yosh
7656    */
7657   
7658   GtkWidgetAuxInfo *aux_info;
7659   
7660   g_return_if_fail (GTK_IS_WIDGET (widget));
7661   
7662   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7663   
7664   if (x > -2)
7665     {
7666       if (x == -1)
7667         aux_info->x_set = FALSE;
7668       else
7669         {
7670           aux_info->x_set = TRUE;
7671           aux_info->x = x;
7672         }
7673     }
7674
7675   if (y > -2)
7676     {
7677       if (y == -1)
7678         aux_info->y_set = FALSE;
7679       else
7680         {
7681           aux_info->y_set = TRUE;
7682           aux_info->y = y;
7683         }
7684     }
7685
7686   if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7687     _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7688   
7689   if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7690     gtk_widget_size_allocate (widget, &widget->allocation);
7691 }
7692
7693 static void
7694 gtk_widget_set_usize_internal (GtkWidget *widget,
7695                                gint       width,
7696                                gint       height)
7697 {
7698   GtkWidgetAuxInfo *aux_info;
7699   gboolean changed = FALSE;
7700   
7701   g_object_freeze_notify (G_OBJECT (widget));
7702
7703   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7704   
7705   if (width > -2 && aux_info->width != width)
7706     {
7707       g_object_notify (G_OBJECT (widget), "width-request");
7708       aux_info->width = width;
7709       changed = TRUE;
7710     }
7711   if (height > -2 && aux_info->height != height)
7712     {
7713       g_object_notify (G_OBJECT (widget), "height-request");  
7714       aux_info->height = height;
7715       changed = TRUE;
7716     }
7717   
7718   if (GTK_WIDGET_VISIBLE (widget) && changed)
7719     gtk_widget_queue_resize (widget);
7720
7721   g_object_thaw_notify (G_OBJECT (widget));
7722 }
7723
7724 /**
7725  * gtk_widget_set_usize:
7726  * @widget: a #GtkWidget
7727  * @width: minimum width, or -1 to unset
7728  * @height: minimum height, or -1 to unset
7729  *
7730  * Sets the minimum size of a widget; that is, the widget's size
7731  * request will be @width by @height. You can use this function to
7732  * force a widget to be either larger or smaller than it is. The
7733  * strange "usize" name dates from the early days of GTK+, and derives
7734  * from X Window System terminology. In many cases,
7735  * gtk_window_set_default_size() is a better choice for toplevel
7736  * windows than this function; setting the default size will still
7737  * allow users to shrink the window. Setting the usize will force them
7738  * to leave the window at least as large as the usize. When dealing
7739  * with window sizes, gtk_window_set_geometry_hints() can be a useful
7740  * function as well.
7741  * 
7742  * Note the inherent danger of setting any fixed size - themes,
7743  * translations into other languages, different fonts, and user action
7744  * can all change the appropriate size for a given widget. So, it's
7745  * basically impossible to hardcode a size that will always be
7746  * correct.
7747  * 
7748  * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7749  **/
7750 void
7751 gtk_widget_set_usize (GtkWidget *widget,
7752                       gint       width,
7753                       gint       height)
7754 {
7755   g_return_if_fail (GTK_IS_WIDGET (widget));
7756   
7757   gtk_widget_set_usize_internal (widget, width, height);
7758 }
7759
7760 /**
7761  * gtk_widget_set_size_request:
7762  * @widget: a #GtkWidget
7763  * @width: width @widget should request, or -1 to unset
7764  * @height: height @widget should request, or -1 to unset
7765  *
7766  * Sets the minimum size of a widget; that is, the widget's size
7767  * request will be @width by @height. You can use this function to
7768  * force a widget to be either larger or smaller than it normally
7769  * would be.
7770  *
7771  * In most cases, gtk_window_set_default_size() is a better choice for
7772  * toplevel windows than this function; setting the default size will
7773  * still allow users to shrink the window. Setting the size request
7774  * will force them to leave the window at least as large as the size
7775  * request. When dealing with window sizes,
7776  * gtk_window_set_geometry_hints() can be a useful function as well.
7777  * 
7778  * Note the inherent danger of setting any fixed size - themes,
7779  * translations into other languages, different fonts, and user action
7780  * can all change the appropriate size for a given widget. So, it's
7781  * basically impossible to hardcode a size that will always be
7782  * correct.
7783  *
7784  * The size request of a widget is the smallest size a widget can
7785  * accept while still functioning well and drawing itself correctly.
7786  * However in some strange cases a widget may be allocated less than
7787  * its requested size, and in many cases a widget may be allocated more
7788  * space than it requested.
7789  *
7790  * If the size request in a given direction is -1 (unset), then
7791  * the "natural" size request of the widget will be used instead.
7792  *
7793  * Widgets can't actually be allocated a size less than 1 by 1, but
7794  * you can pass 0,0 to this function to mean "as small as possible."
7795  **/
7796 void
7797 gtk_widget_set_size_request (GtkWidget *widget,
7798                              gint       width,
7799                              gint       height)
7800 {
7801   g_return_if_fail (GTK_IS_WIDGET (widget));
7802   g_return_if_fail (width >= -1);
7803   g_return_if_fail (height >= -1);
7804
7805   if (width == 0)
7806     width = 1;
7807   if (height == 0)
7808     height = 1;
7809   
7810   gtk_widget_set_usize_internal (widget, width, height);
7811 }
7812
7813
7814 /**
7815  * gtk_widget_get_size_request:
7816  * @widget: a #GtkWidget
7817  * @width: (out): return location for width, or %NULL
7818  * @height: (out): return location for height, or %NULL
7819  *
7820  * Gets the size request that was explicitly set for the widget using
7821  * gtk_widget_set_size_request(). A value of -1 stored in @width or
7822  * @height indicates that that dimension has not been set explicitly
7823  * and the natural requisition of the widget will be used intead. See
7824  * gtk_widget_set_size_request(). To get the size a widget will
7825  * actually use, call gtk_widget_size_request() instead of
7826  * this function.
7827  **/
7828 void
7829 gtk_widget_get_size_request (GtkWidget *widget,
7830                              gint      *width,
7831                              gint      *height)
7832 {
7833   GtkWidgetAuxInfo *aux_info;
7834
7835   g_return_if_fail (GTK_IS_WIDGET (widget));
7836
7837   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7838
7839   if (width)
7840     *width = aux_info ? aux_info->width : -1;
7841
7842   if (height)
7843     *height = aux_info ? aux_info->height : -1;
7844 }
7845
7846 /**
7847  * gtk_widget_set_events:
7848  * @widget: a #GtkWidget
7849  * @events: event mask
7850  *
7851  * Sets the event mask (see #GdkEventMask) for a widget. The event
7852  * mask determines which events a widget will receive. Keep in mind
7853  * that different widgets have different default event masks, and by
7854  * changing the event mask you may disrupt a widget's functionality,
7855  * so be careful. This function must be called while a widget is
7856  * unrealized. Consider gtk_widget_add_events() for widgets that are
7857  * already realized, or if you want to preserve the existing event
7858  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7859  * to get events on those widgets, place them inside a #GtkEventBox
7860  * and receive events on the event box.
7861  **/
7862 void
7863 gtk_widget_set_events (GtkWidget *widget,
7864                        gint       events)
7865 {
7866   g_return_if_fail (GTK_IS_WIDGET (widget));
7867   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7868   
7869   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7870                       GINT_TO_POINTER (events));
7871   g_object_notify (G_OBJECT (widget), "events");
7872 }
7873
7874 static void
7875 gtk_widget_add_events_internal (GtkWidget *widget,
7876                                 gint       events,
7877                                 GList     *window_list)
7878 {
7879   GList *l;
7880
7881   for (l = window_list; l != NULL; l = l->next)
7882     {
7883       GdkWindow *window = l->data;
7884       gpointer user_data;
7885
7886       gdk_window_get_user_data (window, &user_data);
7887       if (user_data == widget)
7888         {
7889           GList *children;
7890
7891           gdk_window_set_events (window, gdk_window_get_events (window) | events);
7892
7893           children = gdk_window_get_children (window);
7894           gtk_widget_add_events_internal (widget, events, children);
7895           g_list_free (children);
7896         }
7897     }
7898 }
7899
7900 /**
7901  * gtk_widget_add_events:
7902  * @widget: a #GtkWidget
7903  * @events: an event mask, see #GdkEventMask
7904  *
7905  * Adds the events in the bitfield @events to the event mask for
7906  * @widget. See gtk_widget_set_events() for details.
7907  **/
7908 void
7909 gtk_widget_add_events (GtkWidget *widget,
7910                        gint       events)
7911 {
7912   gint old_events;
7913
7914   g_return_if_fail (GTK_IS_WIDGET (widget));
7915
7916   old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7917   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7918                       GINT_TO_POINTER (old_events | events));
7919
7920   if (GTK_WIDGET_REALIZED (widget))
7921     {
7922       GList *window_list;
7923
7924       if (GTK_WIDGET_NO_WINDOW (widget))
7925         window_list = gdk_window_get_children (widget->window);
7926       else
7927         window_list = g_list_prepend (NULL, widget->window);
7928
7929       gtk_widget_add_events_internal (widget, events, window_list);
7930
7931       g_list_free (window_list);
7932     }
7933
7934   g_object_notify (G_OBJECT (widget), "events");
7935 }
7936
7937 /**
7938  * gtk_widget_set_extension_events:
7939  * @widget: a #GtkWidget
7940  * @mode: bitfield of extension events to receive
7941  *
7942  * Sets the extension events mask to @mode. See #GdkExtensionMode
7943  * and gdk_input_set_extension_events().
7944  **/
7945 void
7946 gtk_widget_set_extension_events (GtkWidget *widget,
7947                                  GdkExtensionMode mode)
7948 {
7949   g_return_if_fail (GTK_IS_WIDGET (widget));
7950
7951   if (GTK_WIDGET_REALIZED (widget))
7952     gtk_widget_set_extension_events_internal (widget, mode, NULL);
7953
7954   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7955                       GINT_TO_POINTER (mode));
7956   g_object_notify (G_OBJECT (widget), "extension-events");
7957 }
7958
7959 /**
7960  * gtk_widget_get_toplevel:
7961  * @widget: a #GtkWidget
7962  * 
7963  * This function returns the topmost widget in the container hierarchy
7964  * @widget is a part of. If @widget has no parent widgets, it will be
7965  * returned as the topmost widget. No reference will be added to the
7966  * returned widget; it should not be unreferenced.
7967  *
7968  * Note the difference in behavior vs. gtk_widget_get_ancestor();
7969  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
7970  * would return
7971  * %NULL if @widget wasn't inside a toplevel window, and if the
7972  * window was inside a #GtkWindow-derived widget which was in turn
7973  * inside the toplevel #GtkWindow. While the second case may
7974  * seem unlikely, it actually happens when a #GtkPlug is embedded
7975  * inside a #GtkSocket within the same application.
7976  * 
7977  * To reliably find the toplevel #GtkWindow, use
7978  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7979  * is set on the result.
7980  * |[
7981  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7982  *  if (GTK_WIDGET_TOPLEVEL (toplevel))
7983  *    {
7984  *      /&ast; Perform action on toplevel. &ast;/
7985  *    }
7986  * ]|
7987  *
7988  * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
7989  *    if there's no ancestor.
7990  **/
7991 GtkWidget*
7992 gtk_widget_get_toplevel (GtkWidget *widget)
7993 {
7994   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7995   
7996   while (widget->parent)
7997     widget = widget->parent;
7998   
7999   return widget;
8000 }
8001
8002 /**
8003  * gtk_widget_get_ancestor:
8004  * @widget: a #GtkWidget
8005  * @widget_type: ancestor type
8006  * 
8007  * Gets the first ancestor of @widget with type @widget_type. For example,
8008  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets 
8009  * the first #GtkBox that's an ancestor of @widget. No reference will be 
8010  * added to the returned widget; it should not be unreferenced. See note 
8011  * about checking for a toplevel #GtkWindow in the docs for 
8012  * gtk_widget_get_toplevel().
8013  * 
8014  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
8015  * considers @widget to be an ancestor of itself.
8016  *
8017  * Return value: (transfer none): the ancestor widget, or %NULL if not found
8018  **/
8019 GtkWidget*
8020 gtk_widget_get_ancestor (GtkWidget *widget,
8021                          GType      widget_type)
8022 {
8023   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8024   
8025   while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
8026     widget = widget->parent;
8027   
8028   if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
8029     return NULL;
8030   
8031   return widget;
8032 }
8033
8034 /**
8035  * gtk_widget_get_colormap:
8036  * @widget: a #GtkWidget
8037  * 
8038  * Gets the colormap that will be used to render @widget. No reference will
8039  * be added to the returned colormap; it should not be unreferenced.
8040  *
8041  * Return value: (transfer none): the colormap used by @widget
8042  **/
8043 GdkColormap*
8044 gtk_widget_get_colormap (GtkWidget *widget)
8045 {
8046   GdkColormap *colormap;
8047   GtkWidget *tmp_widget;
8048   
8049   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8050   
8051   if (widget->window)
8052     {
8053       colormap = gdk_drawable_get_colormap (widget->window);
8054       /* If window was destroyed previously, we'll get NULL here */
8055       if (colormap)
8056         return colormap;
8057     }
8058
8059   tmp_widget = widget;
8060   while (tmp_widget)
8061     {
8062       colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8063       if (colormap)
8064         return colormap;
8065
8066       tmp_widget= tmp_widget->parent;
8067     }
8068
8069   return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8070 }
8071
8072 /**
8073  * gtk_widget_get_visual:
8074  * @widget: a #GtkWidget
8075  * 
8076  * Gets the visual that will be used to render @widget.
8077  *
8078  * Return value: (transfer none): the visual for @widget
8079  **/
8080 GdkVisual*
8081 gtk_widget_get_visual (GtkWidget *widget)
8082 {
8083   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8084
8085   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8086 }
8087
8088 /**
8089  * gtk_widget_get_settings:
8090  * @widget: a #GtkWidget
8091  * 
8092  * Gets the settings object holding the settings (global property
8093  * settings, RC file information, etc) used for this widget.
8094  *
8095  * Note that this function can only be called when the #GtkWidget
8096  * is attached to a toplevel, since the settings object is specific
8097  * to a particular #GdkScreen.
8098  *
8099  * Return value: (transfer none): the relevant #GtkSettings object
8100  **/
8101 GtkSettings*
8102 gtk_widget_get_settings (GtkWidget *widget)
8103 {
8104   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8105   
8106   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8107 }
8108
8109 /**
8110  * gtk_widget_set_colormap:
8111  * @widget: a #GtkWidget
8112  * @colormap: a colormap
8113  *
8114  * Sets the colormap for the widget to the given value. Widget must not
8115  * have been previously realized. This probably should only be used
8116  * from an <function>init()</function> function (i.e. from the constructor 
8117  * for the widget).
8118  **/
8119 void
8120 gtk_widget_set_colormap (GtkWidget   *widget,
8121                          GdkColormap *colormap)
8122 {
8123   g_return_if_fail (GTK_IS_WIDGET (widget));
8124   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
8125   g_return_if_fail (GDK_IS_COLORMAP (colormap));
8126
8127   g_object_ref (colormap);
8128   
8129   g_object_set_qdata_full (G_OBJECT (widget), 
8130                            quark_colormap,
8131                            colormap,
8132                            g_object_unref);
8133 }
8134
8135 /**
8136  * gtk_widget_get_events:
8137  * @widget: a #GtkWidget
8138  * 
8139  * Returns the event mask for the widget (a bitfield containing flags
8140  * from the #GdkEventMask enumeration). These are the events that the widget
8141  * will receive.
8142  * 
8143  * Return value: event mask for @widget
8144  **/
8145 gint
8146 gtk_widget_get_events (GtkWidget *widget)
8147 {
8148   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8149
8150   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8151 }
8152
8153 /**
8154  * gtk_widget_get_extension_events:
8155  * @widget: a #GtkWidget
8156  * 
8157  * Retrieves the extension events the widget will receive; see
8158  * gdk_input_set_extension_events().
8159  * 
8160  * Return value: extension events for @widget
8161  **/
8162 GdkExtensionMode
8163 gtk_widget_get_extension_events (GtkWidget *widget)
8164 {
8165   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8166
8167   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8168 }
8169
8170 /**
8171  * gtk_widget_get_pointer:
8172  * @widget: a #GtkWidget
8173  * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8174  * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8175  *
8176  * Obtains the location of the mouse pointer in widget coordinates.
8177  * Widget coordinates are a bit odd; for historical reasons, they are
8178  * defined as @widget->window coordinates for widgets that are not
8179  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8180  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8181  **/
8182 void
8183 gtk_widget_get_pointer (GtkWidget *widget,
8184                         gint      *x,
8185                         gint      *y)
8186 {
8187   g_return_if_fail (GTK_IS_WIDGET (widget));
8188   
8189   if (x)
8190     *x = -1;
8191   if (y)
8192     *y = -1;
8193   
8194   if (GTK_WIDGET_REALIZED (widget))
8195     {
8196       gdk_window_get_pointer (widget->window, x, y, NULL);
8197       
8198       if (GTK_WIDGET_NO_WINDOW (widget))
8199         {
8200           if (x)
8201             *x -= widget->allocation.x;
8202           if (y)
8203             *y -= widget->allocation.y;
8204         }
8205     }
8206 }
8207
8208 /**
8209  * gtk_widget_is_ancestor:
8210  * @widget: a #GtkWidget
8211  * @ancestor: another #GtkWidget
8212  * 
8213  * Determines whether @widget is somewhere inside @ancestor, possibly with
8214  * intermediate containers.
8215  * 
8216  * Return value: %TRUE if @ancestor contains @widget as a child, 
8217  *    grandchild, great grandchild, etc.
8218  **/
8219 gboolean
8220 gtk_widget_is_ancestor (GtkWidget *widget,
8221                         GtkWidget *ancestor)
8222 {
8223   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8224   g_return_val_if_fail (ancestor != NULL, FALSE);
8225   
8226   while (widget)
8227     {
8228       if (widget->parent == ancestor)
8229         return TRUE;
8230       widget = widget->parent;
8231     }
8232   
8233   return FALSE;
8234 }
8235
8236 static GQuark quark_composite_name = 0;
8237
8238 /**
8239  * gtk_widget_set_composite_name:
8240  * @widget: a #GtkWidget.
8241  * @name: the name to set
8242  * 
8243  * Sets a widgets composite name. The widget must be
8244  * a composite child of its parent; see gtk_widget_push_composite_child().
8245  **/
8246 void
8247 gtk_widget_set_composite_name (GtkWidget   *widget,
8248                                const gchar *name)
8249 {
8250   g_return_if_fail (GTK_IS_WIDGET (widget));
8251   g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
8252   g_return_if_fail (name != NULL);
8253
8254   if (!quark_composite_name)
8255     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8256
8257   g_object_set_qdata_full (G_OBJECT (widget),
8258                            quark_composite_name,
8259                            g_strdup (name),
8260                            g_free);
8261 }
8262
8263 /**
8264  * gtk_widget_get_composite_name:
8265  * @widget: a #GtkWidget
8266  *
8267  * Obtains the composite name of a widget. 
8268  *
8269  * Returns: the composite name of @widget, or %NULL if @widget is not
8270  *   a composite child. The string should be freed when it is no 
8271  *   longer needed.
8272  **/
8273 gchar*
8274 gtk_widget_get_composite_name (GtkWidget *widget)
8275 {
8276   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8277
8278   if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
8279     return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8280                                                widget);
8281   else
8282     return NULL;
8283 }
8284
8285 /**
8286  * gtk_widget_push_composite_child:
8287  * 
8288  * Makes all newly-created widgets as composite children until
8289  * the corresponding gtk_widget_pop_composite_child() call.
8290  * 
8291  * A composite child is a child that's an implementation detail of the
8292  * container it's inside and should not be visible to people using the
8293  * container. Composite children aren't treated differently by GTK (but
8294  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
8295  * builders might want to treat them in a different way.
8296  * 
8297  * Here is a simple example:
8298  * |[
8299  *   gtk_widget_push_composite_child ();
8300  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8301  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8302  *   gtk_widget_pop_composite_child ();
8303  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
8304  *                          GTK_WIDGET (scrolled_window));
8305  *   g_object_ref (scrolled_window->hscrollbar);
8306  * ]|
8307  **/
8308 void
8309 gtk_widget_push_composite_child (void)
8310 {
8311   composite_child_stack++;
8312 }
8313
8314 /**
8315  * gtk_widget_pop_composite_child:
8316  *
8317  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8318  **/ 
8319 void
8320 gtk_widget_pop_composite_child (void)
8321 {
8322   if (composite_child_stack)
8323     composite_child_stack--;
8324 }
8325
8326 /**
8327  * gtk_widget_push_colormap:
8328  * @cmap: a #GdkColormap
8329  *
8330  * Pushes @cmap onto a global stack of colormaps; the topmost
8331  * colormap on the stack will be used to create all widgets.
8332  * Remove @cmap with gtk_widget_pop_colormap(). There's little
8333  * reason to use this function.
8334  **/
8335 void
8336 gtk_widget_push_colormap (GdkColormap *cmap)
8337 {
8338   g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8339
8340   colormap_stack = g_slist_prepend (colormap_stack, cmap);
8341 }
8342
8343 /**
8344  * gtk_widget_pop_colormap:
8345  *
8346  * Removes a colormap pushed with gtk_widget_push_colormap().
8347  **/
8348 void
8349 gtk_widget_pop_colormap (void)
8350 {
8351   if (colormap_stack)
8352     colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8353 }
8354
8355 /**
8356  * gtk_widget_set_default_colormap:
8357  * @colormap: a #GdkColormap
8358  * 
8359  * Sets the default colormap to use when creating widgets.
8360  * gtk_widget_push_colormap() is a better function to use if
8361  * you only want to affect a few widgets, rather than all widgets.
8362  **/
8363 void
8364 gtk_widget_set_default_colormap (GdkColormap *colormap)
8365 {
8366   g_return_if_fail (GDK_IS_COLORMAP (colormap));
8367   
8368   gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8369                                    colormap);
8370 }
8371
8372 /**
8373  * gtk_widget_get_default_colormap:
8374  * 
8375  * Obtains the default colormap used to create widgets.
8376  *
8377  * Return value: (transfer none): default widget colormap
8378  **/
8379 GdkColormap*
8380 gtk_widget_get_default_colormap (void)
8381 {
8382   return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8383 }
8384
8385 /**
8386  * gtk_widget_get_default_visual:
8387  * 
8388  * Obtains the visual of the default colormap. Not really useful;
8389  * used to be useful before gdk_colormap_get_visual() existed.
8390  *
8391  * Return value: (transfer none): visual of the default colormap
8392  **/
8393 GdkVisual*
8394 gtk_widget_get_default_visual (void)
8395 {
8396   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8397 }
8398
8399 static void
8400 gtk_widget_emit_direction_changed (GtkWidget        *widget,
8401                                    GtkTextDirection  old_dir)
8402 {
8403   gtk_widget_update_pango_context (widget);
8404   
8405   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8406 }
8407
8408 /**
8409  * gtk_widget_set_direction:
8410  * @widget: a #GtkWidget
8411  * @dir:    the new direction
8412  * 
8413  * Sets the reading direction on a particular widget. This direction
8414  * controls the primary direction for widgets containing text,
8415  * and also the direction in which the children of a container are
8416  * packed. The ability to set the direction is present in order
8417  * so that correct localization into languages with right-to-left
8418  * reading directions can be done. Generally, applications will
8419  * let the default reading direction present, except for containers
8420  * where the containers are arranged in an order that is explicitely
8421  * visual rather than logical (such as buttons for text justification).
8422  *
8423  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8424  * set by gtk_widget_set_default_direction() will be used.
8425  **/
8426 void
8427 gtk_widget_set_direction (GtkWidget        *widget,
8428                           GtkTextDirection  dir)
8429 {
8430   GtkTextDirection old_dir;
8431   
8432   g_return_if_fail (GTK_IS_WIDGET (widget));
8433   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8434
8435   old_dir = gtk_widget_get_direction (widget);
8436   
8437   if (dir == GTK_TEXT_DIR_NONE)
8438     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8439   else
8440     {
8441       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8442       if (dir == GTK_TEXT_DIR_LTR)
8443         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8444       else
8445         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8446     }
8447
8448   if (old_dir != gtk_widget_get_direction (widget))
8449     gtk_widget_emit_direction_changed (widget, old_dir);
8450 }
8451
8452 /**
8453  * gtk_widget_get_direction:
8454  * @widget: a #GtkWidget
8455  * 
8456  * Gets the reading direction for a particular widget. See
8457  * gtk_widget_set_direction().
8458  * 
8459  * Return value: the reading direction for the widget.
8460  **/
8461 GtkTextDirection
8462 gtk_widget_get_direction (GtkWidget *widget)
8463 {
8464   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8465   
8466   if (GTK_WIDGET_DIRECTION_SET (widget))
8467     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8468   else
8469     return gtk_default_direction;
8470 }
8471
8472 static void
8473 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8474 {
8475   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8476
8477   g_object_ref (widget);
8478   
8479   if (!GTK_WIDGET_DIRECTION_SET (widget))
8480     gtk_widget_emit_direction_changed (widget, old_dir);
8481   
8482   if (GTK_IS_CONTAINER (widget))
8483     gtk_container_forall (GTK_CONTAINER (widget),
8484                           gtk_widget_set_default_direction_recurse,
8485                           data);
8486
8487   g_object_unref (widget);
8488 }
8489
8490 /**
8491  * gtk_widget_set_default_direction:
8492  * @dir: the new default direction. This cannot be
8493  *        %GTK_TEXT_DIR_NONE.
8494  * 
8495  * Sets the default reading direction for widgets where the
8496  * direction has not been explicitly set by gtk_widget_set_direction().
8497  **/
8498 void
8499 gtk_widget_set_default_direction (GtkTextDirection dir)
8500 {
8501   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8502
8503   if (dir != gtk_default_direction)
8504     {
8505       GList *toplevels, *tmp_list;
8506       GtkTextDirection old_dir = gtk_default_direction;
8507       
8508       gtk_default_direction = dir;
8509
8510       tmp_list = toplevels = gtk_window_list_toplevels ();
8511       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8512       
8513       while (tmp_list)
8514         {
8515           gtk_widget_set_default_direction_recurse (tmp_list->data,
8516                                                     GUINT_TO_POINTER (old_dir));
8517           g_object_unref (tmp_list->data);
8518           tmp_list = tmp_list->next;
8519         }
8520
8521       g_list_free (toplevels);
8522     }
8523 }
8524
8525 /**
8526  * gtk_widget_get_default_direction:
8527  * 
8528  * Obtains the current default reading direction. See
8529  * gtk_widget_set_default_direction().
8530  *
8531  * Return value: the current default direction. 
8532  **/
8533 GtkTextDirection
8534 gtk_widget_get_default_direction (void)
8535 {
8536   return gtk_default_direction;
8537 }
8538
8539 static void
8540 gtk_widget_dispose (GObject *object)
8541 {
8542   GtkWidget *widget = GTK_WIDGET (object);
8543
8544   if (widget->parent)
8545     gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8546   else if (GTK_WIDGET_VISIBLE (widget))
8547     gtk_widget_hide (widget);
8548
8549   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8550   if (GTK_WIDGET_REALIZED (widget))
8551     gtk_widget_unrealize (widget);
8552   
8553   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8554 }
8555
8556 static void
8557 gtk_widget_real_destroy (GtkObject *object)
8558 {
8559   /* gtk_object_destroy() will already hold a refcount on object */
8560   GtkWidget *widget = GTK_WIDGET (object);
8561
8562   /* wipe accelerator closures (keep order) */
8563   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8564   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8565
8566   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8567   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8568   
8569   gtk_grab_remove (widget);
8570   
8571   g_object_unref (widget->style);
8572   widget->style = gtk_widget_get_default_style ();
8573   g_object_ref (widget->style);
8574
8575   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8576 }
8577
8578 static void
8579 gtk_widget_finalize (GObject *object)
8580 {
8581   GtkWidget *widget = GTK_WIDGET (object);
8582   GtkWidgetAuxInfo *aux_info;
8583   GtkAccessible *accessible;
8584   
8585   gtk_grab_remove (widget);
8586
8587   g_object_unref (widget->style);
8588   widget->style = NULL;
8589
8590   g_free (widget->name);
8591   
8592   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8593   if (aux_info)
8594     gtk_widget_aux_info_destroy (aux_info);
8595
8596   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8597   if (accessible)
8598     g_object_unref (accessible);
8599
8600   G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8601 }
8602
8603 /*****************************************
8604  * gtk_widget_real_map:
8605  *
8606  *   arguments:
8607  *
8608  *   results:
8609  *****************************************/
8610
8611 static void
8612 gtk_widget_real_map (GtkWidget *widget)
8613 {
8614   g_assert (GTK_WIDGET_REALIZED (widget));
8615   
8616   if (!GTK_WIDGET_MAPPED (widget))
8617     {
8618       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
8619       
8620       if (!GTK_WIDGET_NO_WINDOW (widget))
8621         gdk_window_show (widget->window);
8622     }
8623 }
8624
8625 /*****************************************
8626  * gtk_widget_real_unmap:
8627  *
8628  *   arguments:
8629  *
8630  *   results:
8631  *****************************************/
8632
8633 static void
8634 gtk_widget_real_unmap (GtkWidget *widget)
8635 {
8636   if (GTK_WIDGET_MAPPED (widget))
8637     {
8638       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8639
8640       if (!GTK_WIDGET_NO_WINDOW (widget))
8641         gdk_window_hide (widget->window);
8642     }
8643 }
8644
8645 /*****************************************
8646  * gtk_widget_real_realize:
8647  *
8648  *   arguments:
8649  *
8650  *   results:
8651  *****************************************/
8652
8653 static void
8654 gtk_widget_real_realize (GtkWidget *widget)
8655 {
8656   g_assert (GTK_WIDGET_NO_WINDOW (widget));
8657   
8658   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8659   if (widget->parent)
8660     {
8661       widget->window = gtk_widget_get_parent_window (widget);
8662       g_object_ref (widget->window);
8663     }
8664   widget->style = gtk_style_attach (widget->style, widget->window);
8665 }
8666
8667 /*****************************************
8668  * gtk_widget_real_unrealize:
8669  *
8670  *   arguments:
8671  *
8672  *   results:
8673  *****************************************/
8674
8675 static void
8676 gtk_widget_real_unrealize (GtkWidget *widget)
8677 {
8678   if (GTK_WIDGET_MAPPED (widget))
8679     gtk_widget_real_unmap (widget);
8680
8681   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8682
8683   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8684    */
8685
8686    /* We must do unrealize child widget BEFORE container widget.
8687     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8688     * So, unrealizing container widget bofore its children causes the problem 
8689     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8690     */
8691
8692   if (GTK_IS_CONTAINER (widget))
8693     gtk_container_forall (GTK_CONTAINER (widget),
8694                           (GtkCallback) gtk_widget_unrealize,
8695                           NULL);
8696
8697   gtk_style_detach (widget->style);
8698   if (!GTK_WIDGET_NO_WINDOW (widget))
8699     {
8700       gdk_window_set_user_data (widget->window, NULL);
8701       gdk_window_destroy (widget->window);
8702       widget->window = NULL;
8703     }
8704   else
8705     {
8706       g_object_unref (widget->window);
8707       widget->window = NULL;
8708     }
8709
8710   gtk_selection_remove_all (widget);
8711   
8712   GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8713 }
8714
8715 static void
8716 gtk_widget_real_size_request (GtkWidget         *widget,
8717                               GtkRequisition    *requisition)
8718 {
8719   requisition->width = widget->requisition.width;
8720   requisition->height = widget->requisition.height;
8721 }
8722
8723 /**
8724  * _gtk_widget_peek_colormap:
8725  * 
8726  * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8727  * 
8728  * Return value: the currently pushed colormap, or %NULL if there is none.
8729  **/
8730 GdkColormap*
8731 _gtk_widget_peek_colormap (void)
8732 {
8733   if (colormap_stack)
8734     return (GdkColormap*) colormap_stack->data;
8735   return NULL;
8736 }
8737
8738 /*
8739  * _gtk_widget_set_pointer_window:
8740  * @widget: a #GtkWidget.
8741  * @pointer_window: the new pointer window.
8742  *
8743  * Sets pointer window for @widget.  Does not ref @pointer_window.
8744  * Actually stores it on the #GdkScreen, but you don't need to know that.
8745  */
8746 void
8747 _gtk_widget_set_pointer_window (GtkWidget *widget,
8748                                 GdkWindow *pointer_window)
8749 {
8750   g_return_if_fail (GTK_IS_WIDGET (widget));
8751
8752   if (GTK_WIDGET_REALIZED (widget))
8753     {
8754       GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8755
8756       g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8757                           pointer_window);
8758     }
8759 }
8760
8761 /*
8762  * _gtk_widget_get_pointer_window:
8763  * @widget: a #GtkWidget.
8764  *
8765  * Return value: the pointer window set on the #GdkScreen @widget is attached
8766  * to, or %NULL.
8767  */
8768 GdkWindow *
8769 _gtk_widget_get_pointer_window (GtkWidget *widget)
8770 {
8771   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8772
8773   if (GTK_WIDGET_REALIZED (widget))
8774     {
8775       GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8776
8777       return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8778     }
8779
8780   return NULL;
8781 }
8782
8783 static void
8784 synth_crossing (GtkWidget      *widget,
8785                 GdkEventType    type,
8786                 GdkWindow      *window,
8787                 GdkCrossingMode mode,
8788                 GdkNotifyType   detail)
8789 {
8790   GdkEvent *event;
8791   
8792   event = gdk_event_new (type);
8793
8794   event->crossing.window = g_object_ref (window);
8795   event->crossing.send_event = TRUE;
8796   event->crossing.subwindow = g_object_ref (window);
8797   event->crossing.time = GDK_CURRENT_TIME;
8798   event->crossing.x = event->crossing.y = 0;
8799   event->crossing.x_root = event->crossing.y_root = 0;
8800   event->crossing.mode = mode;
8801   event->crossing.detail = detail;
8802   event->crossing.focus = FALSE;
8803   event->crossing.state = 0;
8804
8805   if (!widget)
8806     widget = gtk_get_event_widget (event);
8807
8808   if (widget)
8809     gtk_widget_event_internal (widget, event);
8810
8811   gdk_event_free (event);
8812 }
8813
8814 /*
8815  * _gtk_widget_is_pointer_widget:
8816  * @widget: a #GtkWidget
8817  *
8818  * Returns %TRUE if the pointer window belongs to @widget.
8819  */
8820 gboolean
8821 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8822 {
8823   if (GTK_WIDGET_HAS_POINTER (widget))
8824     {
8825       GdkWindow *win;
8826       GtkWidget *wid;
8827
8828       win = _gtk_widget_get_pointer_window (widget);
8829       if (win)
8830         {
8831           gdk_window_get_user_data (win, (gpointer *)&wid);
8832           if (wid == widget)
8833             return TRUE;
8834         }
8835     }
8836
8837   return FALSE;
8838 }
8839
8840 /*
8841  * _gtk_widget_synthesize_crossing:
8842  * @from: the #GtkWidget the virtual pointer is leaving.
8843  * @to: the #GtkWidget the virtual pointer is moving to.
8844  * @mode: the #GdkCrossingMode to place on the synthesized events.
8845  *
8846  * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8847  *
8848  * The real pointer window is the window that most recently received an enter notify
8849  * event.  Windows that don't select for crossing events can't become the real
8850  * poiner window.  The real pointer widget that owns the real pointer window.  The
8851  * effective pointer window is the same as the real pointer window unless the real
8852  * pointer widget is either insensitive or there is a grab on a widget that is not
8853  * an ancestor of the real pointer widget (in which case the effective pointer
8854  * window should be the root window).
8855  *
8856  * When the effective pointer window is the same as the real poiner window, we
8857  * receive crossing events from the windowing system.  When the effective pointer
8858  * window changes to become different from the real pointer window we synthesize
8859  * crossing events, attempting to follow X protocol rules:
8860  *
8861  * When the root window becomes the effective pointer window:
8862  *   - leave notify on real pointer window, detail Ancestor
8863  *   - leave notify on all of its ancestors, detail Virtual
8864  *   - enter notify on root window, detail Inferior
8865  *
8866  * When the root window ceases to be the effective pointer window:
8867  *   - leave notify on root window, detail Inferior
8868  *   - enter notify on all ancestors of real pointer window, detail Virtual
8869  *   - enter notify on real pointer window, detail Ancestor
8870  */
8871 void
8872 _gtk_widget_synthesize_crossing (GtkWidget      *from,
8873                                  GtkWidget      *to,
8874                                  GdkCrossingMode mode)
8875 {
8876   GdkWindow *from_window = NULL, *to_window = NULL;
8877
8878   g_return_if_fail (from != NULL || to != NULL);
8879
8880   if (from != NULL)
8881     from_window = GTK_WIDGET_HAS_POINTER (from)
8882       ? _gtk_widget_get_pointer_window (from) : from->window;
8883   if (to != NULL)
8884     to_window = GTK_WIDGET_HAS_POINTER (to)
8885       ? _gtk_widget_get_pointer_window (to) : to->window;
8886
8887   if (from_window == NULL && to_window == NULL)
8888     ;
8889   else if (from_window != NULL && to_window == NULL)
8890     {
8891       GList *from_ancestors = NULL, *list;
8892       GdkWindow *from_ancestor = from_window;
8893
8894       while (from_ancestor != NULL)
8895         {
8896           from_ancestor = gdk_window_get_parent (from_ancestor);
8897           if (from_ancestor == NULL)
8898             break;
8899           from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8900         }
8901
8902       synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8903                       mode, GDK_NOTIFY_ANCESTOR);
8904       for (list = g_list_last (from_ancestors); list; list = list->prev)
8905         {
8906           synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8907                           mode, GDK_NOTIFY_VIRTUAL);
8908         }
8909
8910       /* XXX: enter/inferior on root window? */
8911
8912       g_list_free (from_ancestors);
8913     }
8914   else if (from_window == NULL && to_window != NULL)
8915     {
8916       GList *to_ancestors = NULL, *list;
8917       GdkWindow *to_ancestor = to_window;
8918
8919       while (to_ancestor != NULL)
8920         {
8921           to_ancestor = gdk_window_get_parent (to_ancestor);
8922           if (to_ancestor == NULL)
8923             break;
8924           to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8925         }
8926
8927       /* XXX: leave/inferior on root window? */
8928
8929       for (list = to_ancestors; list; list = list->next)
8930         {
8931           synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8932                           mode, GDK_NOTIFY_VIRTUAL);
8933         }
8934       synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8935                       mode, GDK_NOTIFY_ANCESTOR);
8936
8937       g_list_free (to_ancestors);
8938     }
8939   else if (from_window == to_window)
8940     ;
8941   else
8942     {
8943       GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8944       GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8945
8946       while (from_ancestor != NULL || to_ancestor != NULL)
8947         {
8948           if (from_ancestor != NULL)
8949             {
8950               from_ancestor = gdk_window_get_parent (from_ancestor);
8951               if (from_ancestor == to_window)
8952                 break;
8953               if (from_ancestor)
8954                 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8955             }
8956           if (to_ancestor != NULL)
8957             {
8958               to_ancestor = gdk_window_get_parent (to_ancestor);
8959               if (to_ancestor == from_window)
8960                 break;
8961               if (to_ancestor)
8962                 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8963             }
8964         }
8965       if (to_ancestor == from_window)
8966         {
8967           if (mode != GDK_CROSSING_GTK_UNGRAB)
8968             synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8969                             mode, GDK_NOTIFY_INFERIOR);
8970           for (list = to_ancestors; list; list = list->next)
8971             synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data, 
8972                             mode, GDK_NOTIFY_VIRTUAL);
8973           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8974                           mode, GDK_NOTIFY_ANCESTOR);
8975         }
8976       else if (from_ancestor == to_window)
8977         {
8978           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8979                           mode, GDK_NOTIFY_ANCESTOR);
8980           for (list = g_list_last (from_ancestors); list; list = list->prev)
8981             {
8982               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8983                               mode, GDK_NOTIFY_VIRTUAL);
8984             }
8985           if (mode != GDK_CROSSING_GTK_GRAB)
8986             synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8987                             mode, GDK_NOTIFY_INFERIOR);
8988         }
8989       else
8990         {
8991           while (from_ancestors != NULL && to_ancestors != NULL 
8992                  && from_ancestors->data == to_ancestors->data)
8993             {
8994               from_ancestors = g_list_delete_link (from_ancestors, 
8995                                                    from_ancestors);
8996               to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8997             }
8998
8999           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9000                           mode, GDK_NOTIFY_NONLINEAR);
9001
9002           for (list = g_list_last (from_ancestors); list; list = list->prev)
9003             {
9004               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9005                               mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9006             }
9007           for (list = to_ancestors; list; list = list->next)
9008             {
9009               synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9010                               mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9011             }
9012           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9013                           mode, GDK_NOTIFY_NONLINEAR);
9014         }
9015       g_list_free (from_ancestors);
9016       g_list_free (to_ancestors);
9017     }
9018 }
9019
9020 static void
9021 gtk_widget_propagate_state (GtkWidget           *widget,
9022                             GtkStateData        *data)
9023 {
9024   guint8 old_state = GTK_WIDGET_STATE (widget);
9025   guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
9026
9027   /* don't call this function with state==GTK_STATE_INSENSITIVE,
9028    * parent_sensitive==TRUE on a sensitive widget
9029    */
9030
9031
9032   if (data->parent_sensitive)
9033     GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9034   else
9035     GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9036
9037   if (GTK_WIDGET_IS_SENSITIVE (widget))
9038     {
9039       if (data->state_restoration)
9040         GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
9041       else
9042         GTK_WIDGET_STATE (widget) = data->state;
9043     }
9044   else
9045     {
9046       if (!data->state_restoration)
9047         {
9048           if (data->state != GTK_STATE_INSENSITIVE)
9049             GTK_WIDGET_SAVED_STATE (widget) = data->state;
9050         }
9051       else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
9052         GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
9053       GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
9054     }
9055
9056   if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
9057     {
9058       GtkWidget *window;
9059
9060       window = gtk_widget_get_toplevel (widget);
9061       if (window && GTK_WIDGET_TOPLEVEL (window))
9062         gtk_window_set_focus (GTK_WINDOW (window), NULL);
9063     }
9064
9065   if (old_state != GTK_WIDGET_STATE (widget) ||
9066       old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
9067     {
9068       g_object_ref (widget);
9069
9070       if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
9071         gtk_grab_remove (widget);
9072
9073       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9074
9075       if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9076         {
9077           if (!GTK_WIDGET_IS_SENSITIVE (widget))
9078             _gtk_widget_synthesize_crossing (widget, NULL, 
9079                                              GDK_CROSSING_STATE_CHANGED);
9080           else if (old_state == GTK_STATE_INSENSITIVE)
9081             _gtk_widget_synthesize_crossing (NULL, widget, 
9082                                              GDK_CROSSING_STATE_CHANGED);
9083         }
9084
9085       if (GTK_IS_CONTAINER (widget))
9086         {
9087           data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
9088           if (data->use_forall)
9089             gtk_container_forall (GTK_CONTAINER (widget),
9090                                   (GtkCallback) gtk_widget_propagate_state,
9091                                   data);
9092           else
9093             gtk_container_foreach (GTK_CONTAINER (widget),
9094                                    (GtkCallback) gtk_widget_propagate_state,
9095                                    data);
9096         }
9097       g_object_unref (widget);
9098     }
9099 }
9100
9101 /*
9102  * _gtk_widget_get_aux_info:
9103  * @widget: a #GtkWidget
9104  * @create: if %TRUE, create the structure if it doesn't exist
9105  * 
9106  * Get the #GtkWidgetAuxInfo structure for the widget.
9107  * 
9108  * Return value: the #GtkAuxInfo structure for the widget, or
9109  *    %NULL if @create is %FALSE and one doesn't already exist.
9110  */
9111 GtkWidgetAuxInfo*
9112 _gtk_widget_get_aux_info (GtkWidget *widget,
9113                           gboolean   create)
9114 {
9115   GtkWidgetAuxInfo *aux_info;
9116   
9117   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9118   if (!aux_info && create)
9119     {
9120       aux_info = g_slice_new (GtkWidgetAuxInfo);
9121
9122       aux_info->width = -1;
9123       aux_info->height = -1;
9124       aux_info->x = 0;
9125       aux_info->y = 0;
9126       aux_info->x_set = FALSE;
9127       aux_info->y_set = FALSE;
9128       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9129     }
9130   
9131   return aux_info;
9132 }
9133
9134 /*****************************************
9135  * gtk_widget_aux_info_destroy:
9136  *
9137  *   arguments:
9138  *
9139  *   results:
9140  *****************************************/
9141
9142 static void
9143 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9144 {
9145   g_slice_free (GtkWidgetAuxInfo, aux_info);
9146 }
9147
9148 static void
9149 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9150 {
9151   g_object_unref (info->shape_mask);
9152   g_slice_free (GtkWidgetShapeInfo, info);
9153 }
9154
9155 /**
9156  * gtk_widget_shape_combine_mask: 
9157  * @widget: a #GtkWidget
9158  * @shape_mask: shape to be added, or %NULL to remove an existing shape
9159  * @offset_x: X position of shape mask with respect to @window
9160  * @offset_y: Y position of shape mask with respect to @window
9161  * 
9162  * Sets a shape for this widget's GDK window. This allows for
9163  * transparent windows etc., see gdk_window_shape_combine_mask()
9164  * for more information.
9165  **/
9166 void
9167 gtk_widget_shape_combine_mask (GtkWidget *widget,
9168                                GdkBitmap *shape_mask,
9169                                gint       offset_x,
9170                                gint       offset_y)
9171 {
9172   GtkWidgetShapeInfo* shape_info;
9173   
9174   g_return_if_fail (GTK_IS_WIDGET (widget));
9175   /*  set_shape doesn't work on widgets without gdk window */
9176   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9177
9178   if (!shape_mask)
9179     {
9180       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9181       
9182       if (widget->window)
9183         gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9184       
9185       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9186     }
9187   else
9188     {
9189       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9190       
9191       shape_info = g_slice_new (GtkWidgetShapeInfo);
9192       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9193                                (GDestroyNotify) gtk_widget_shape_info_destroy);
9194       
9195       shape_info->shape_mask = g_object_ref (shape_mask);
9196       shape_info->offset_x = offset_x;
9197       shape_info->offset_y = offset_y;
9198       
9199       /* set shape if widget has a gdk window already.
9200        * otherwise the shape is scheduled to be set by gtk_widget_realize().
9201        */
9202       if (widget->window)
9203         gdk_window_shape_combine_mask (widget->window, shape_mask,
9204                                        offset_x, offset_y);
9205     }
9206 }
9207
9208 /**
9209  * gtk_widget_input_shape_combine_mask:
9210  * @widget: a #GtkWidget
9211  * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9212  * @offset_x: X position of shape mask with respect to @window
9213  * @offset_y: Y position of shape mask with respect to @window
9214  *
9215  * Sets an input shape for this widget's GDK window. This allows for
9216  * windows which react to mouse click in a nonrectangular region, see 
9217  * gdk_window_input_shape_combine_mask() for more information.
9218  *
9219  * Since: 2.10
9220  **/
9221 void
9222 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9223                                      GdkBitmap *shape_mask,
9224                                      gint       offset_x,
9225                                      gint       offset_y)
9226 {
9227   GtkWidgetShapeInfo* shape_info;
9228   
9229   g_return_if_fail (GTK_IS_WIDGET (widget));
9230   /*  set_shape doesn't work on widgets without gdk window */
9231   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9232
9233   if (!shape_mask)
9234     {
9235       if (widget->window)
9236         gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9237       
9238       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9239     }
9240   else
9241     {
9242       shape_info = g_slice_new (GtkWidgetShapeInfo);
9243       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
9244                                shape_info,
9245                                (GDestroyNotify) gtk_widget_shape_info_destroy);
9246       
9247       shape_info->shape_mask = g_object_ref (shape_mask);
9248       shape_info->offset_x = offset_x;
9249       shape_info->offset_y = offset_y;
9250       
9251       /* set shape if widget has a gdk window already.
9252        * otherwise the shape is scheduled to be set by gtk_widget_realize().
9253        */
9254       if (widget->window)
9255         gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9256                                              offset_x, offset_y);
9257     }
9258 }
9259
9260
9261 static void
9262 gtk_reset_shapes_recurse (GtkWidget *widget,
9263                           GdkWindow *window)
9264 {
9265   gpointer data;
9266   GList *list;
9267
9268   gdk_window_get_user_data (window, &data);
9269   if (data != widget)
9270     return;
9271
9272   gdk_window_shape_combine_mask (window, NULL, 0, 0);
9273   for (list = gdk_window_peek_children (window); list; list = list->next)
9274     gtk_reset_shapes_recurse (widget, list->data);
9275 }
9276
9277 /**
9278  * gtk_widget_reset_shapes:
9279  * @widget: a #GtkWidget
9280  *
9281  * Recursively resets the shape on this widget and its descendants.
9282  **/
9283 void
9284 gtk_widget_reset_shapes (GtkWidget *widget)
9285 {
9286   g_return_if_fail (GTK_IS_WIDGET (widget));
9287   g_return_if_fail (GTK_WIDGET_REALIZED (widget));
9288
9289   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9290     gtk_reset_shapes_recurse (widget, widget->window);
9291 }
9292
9293 /**
9294  * gtk_widget_ref:
9295  * @widget: a #GtkWidget
9296  * 
9297  * Adds a reference to a widget. This function is exactly the same
9298  * as calling g_object_ref(), and exists mostly for historical
9299  * reasons. It can still be convenient to avoid casting a widget
9300  * to a #GObject, it saves a small amount of typing.
9301  * 
9302  * Return value: the widget that was referenced
9303  *
9304  * Deprecated: 2.12: Use g_object_ref() instead.
9305  **/
9306 GtkWidget*
9307 gtk_widget_ref (GtkWidget *widget)
9308 {
9309   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9310
9311   return (GtkWidget*) g_object_ref ((GObject*) widget);
9312 }
9313
9314 /**
9315  * gtk_widget_unref:
9316  * @widget: a #GtkWidget
9317  *
9318  * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9319  * 
9320  * Deprecated: 2.12: Use g_object_unref() instead.
9321  **/
9322 void
9323 gtk_widget_unref (GtkWidget *widget)
9324 {
9325   g_return_if_fail (GTK_IS_WIDGET (widget));
9326
9327   g_object_unref ((GObject*) widget);
9328 }
9329
9330 static void
9331 expose_window (GdkWindow *window)
9332 {
9333   GdkEvent event;
9334   GList *l, *children;
9335   gpointer user_data;
9336   gboolean is_double_buffered;
9337
9338   gdk_window_get_user_data (window, &user_data);
9339
9340   if (user_data)
9341     is_double_buffered = GTK_WIDGET_DOUBLE_BUFFERED (GTK_WIDGET (user_data));
9342   else
9343     is_double_buffered = FALSE;
9344   
9345   event.expose.type = GDK_EXPOSE;
9346   event.expose.window = g_object_ref (window);
9347   event.expose.send_event = FALSE;
9348   event.expose.count = 0;
9349   event.expose.area.x = 0;
9350   event.expose.area.y = 0;
9351   gdk_drawable_get_size (GDK_DRAWABLE (window),
9352                          &event.expose.area.width,
9353                          &event.expose.area.height);
9354   event.expose.region = gdk_region_rectangle (&event.expose.area);
9355
9356   /* If this is not double buffered, force a double buffer so that
9357      redirection works. */
9358   if (!is_double_buffered)
9359     gdk_window_begin_paint_region (window, event.expose.region);
9360   
9361   gtk_main_do_event (&event);
9362
9363   if (!is_double_buffered)
9364     gdk_window_end_paint (window);
9365   
9366   children = gdk_window_peek_children (window);
9367   for (l = children; l != NULL; l = l->next)
9368     {
9369       GdkWindow *child = l->data;
9370
9371       /* Don't expose input-only windows */
9372       if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9373         expose_window (l->data);
9374     }
9375   
9376   g_object_unref (window);
9377 }
9378
9379 /**
9380  * gtk_widget_get_snapshot:
9381  * @widget:    a #GtkWidget
9382  * @clip_rect: a #GdkRectangle or %NULL
9383  *
9384  * Create a #GdkPixmap of the contents of the widget and its children.
9385  *
9386  * Works even if the widget is obscured. The depth and visual of the
9387  * resulting pixmap is dependent on the widget being snapshot and likely
9388  * differs from those of a target widget displaying the pixmap.
9389  * The function gdk_pixbuf_get_from_drawable() can be used to convert
9390  * the pixmap to a visual independant representation.
9391  *
9392  * The snapshot area used by this function is the @widget's allocation plus
9393  * any extra space occupied by additional windows belonging to this widget
9394  * (such as the arrows of a spin button).
9395  * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9396  * 
9397  * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9398  * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9399  * interpreted widget relative. If width or height of @clip_rect are 0 or
9400  * negative, the width or height of the resulting pixmap will be shrunken
9401  * by the respective amount.
9402  * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9403  * chop off 5 pixels at each side of the snapshot pixmap.
9404  * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9405  * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9406  * can be used to preserve the auto-grown snapshot area and use @clip_rect
9407  * as a pure output parameter.
9408  *
9409  * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9410  *
9411  * Return value: #GdkPixmap snapshot of the widget
9412  * 
9413  * Since: 2.14
9414  **/
9415 GdkPixmap*
9416 gtk_widget_get_snapshot (GtkWidget    *widget,
9417                          GdkRectangle *clip_rect)
9418 {
9419   int x, y, width, height;
9420   GdkWindow *parent_window = NULL;
9421   GdkPixmap *pixmap;
9422   GList *windows = NULL, *list;
9423
9424   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9425   if (!GTK_WIDGET_VISIBLE (widget))
9426     return NULL;
9427
9428   /* the widget (and parent_window) must be realized to be drawable */
9429   if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
9430     gtk_widget_realize (widget->parent);
9431   if (!GTK_WIDGET_REALIZED (widget))
9432     gtk_widget_realize (widget);
9433
9434   /* determine snapshot rectangle */
9435   x = widget->allocation.x;
9436   y = widget->allocation.y;
9437   width = widget->allocation.width;
9438   height = widget->allocation.height;
9439
9440   if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
9441     {
9442       /* grow snapshot rectangle to cover all widget windows */
9443       parent_window = gtk_widget_get_parent_window (widget);
9444       for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9445         {
9446           GdkWindow *subwin = list->data;
9447           gpointer windata;
9448           int wx, wy, ww, wh;
9449           gdk_window_get_user_data (subwin, &windata);
9450           if (windata != widget)
9451             continue;
9452           windows = g_list_prepend (windows, subwin);
9453           gdk_window_get_position (subwin, &wx, &wy);
9454           gdk_drawable_get_size (subwin, &ww, &wh);
9455           /* grow snapshot rectangle by extra widget sub window */
9456           if (wx < x)
9457             {
9458               width += x - wx;
9459               x = wx;
9460             }
9461           if (wy < y)
9462             {
9463               height += y - wy;
9464               y = wy;
9465             }
9466           if (x + width < wx + ww)
9467             width += wx + ww - (x + width);
9468           if (y + height < wy + wh)
9469             height += wy + wh - (y + height);
9470         }
9471     }
9472   else if (!widget->parent)
9473     x = y = 0; /* toplevel */
9474
9475   /* at this point, (x,y,width,height) is the parent_window relative
9476    * snapshot area covering all of widget's windows.
9477    */
9478
9479   /* shrink snapshot size by clip_rectangle */
9480   if (clip_rect)
9481     {
9482       GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9483       clip.x = clip.x < 0 ? x : clip.x;
9484       clip.y = clip.y < 0 ? y : clip.y;
9485       clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9486       clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9487       if (widget->parent)
9488         {
9489           /* offset clip_rect, so it's parent_window relative */
9490           if (clip_rect->x >= 0)
9491             clip.x += widget->allocation.x;
9492           if (clip_rect->y >= 0)
9493             clip.y += widget->allocation.y;
9494         }
9495       if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9496         {
9497           g_list_free (windows);
9498           clip_rect->width = clip_rect->height = 0;
9499           return NULL; /* empty snapshot area */
9500         }
9501       x = snap.x;
9502       y = snap.y;
9503       width = snap.width;
9504       height = snap.height;
9505     }
9506
9507   /* render snapshot */
9508   pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9509   for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9510     {
9511       GdkWindow *subwin = list->data;
9512       int wx, wy;
9513       if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9514         continue; /* Input only window */
9515       gdk_window_get_position (subwin, &wx, &wy);
9516       gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9517                                        MAX (0, wx - x), MAX (0, wy - y), width, height);
9518
9519       expose_window (subwin);
9520     }
9521   if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9522     {
9523       gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9524       expose_window (widget->window);
9525     }
9526   for (list = windows; list; list = list->next)
9527     gdk_window_remove_redirection (list->data);
9528   if (!windows) /* NO_WINDOW || toplevel */
9529     gdk_window_remove_redirection (widget->window);
9530   g_list_free (windows);
9531
9532   /* return pixmap and snapshot rectangle coordinates */
9533   if (clip_rect)
9534     {
9535       clip_rect->x = x;
9536       clip_rect->y = y;
9537       clip_rect->width = width;
9538       clip_rect->height = height;
9539       if (widget->parent)
9540         {
9541           /* offset clip_rect from parent_window so it's widget relative */
9542           clip_rect->x -= widget->allocation.x;
9543           clip_rect->y -= widget->allocation.y;
9544         }
9545       if (0)
9546         g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9547                     G_OBJECT_TYPE_NAME (widget),
9548                     clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9549     }
9550   return pixmap;
9551 }
9552
9553 /* style properties
9554  */
9555
9556 /**
9557  * gtk_widget_class_install_style_property_parser:
9558  * @klass: a #GtkWidgetClass
9559  * @pspec: the #GParamSpec for the style property
9560  * @parser: the parser for the style property
9561  * 
9562  * Installs a style property on a widget class. 
9563  **/
9564 void
9565 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
9566                                                 GParamSpec         *pspec,
9567                                                 GtkRcPropertyParser parser)
9568 {
9569   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9570   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9571   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9572   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9573   
9574   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9575     {
9576       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9577                  G_OBJECT_CLASS_NAME (klass),
9578                  pspec->name);
9579       return;
9580     }
9581
9582   g_param_spec_ref_sink (pspec);
9583   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9584   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9585 }
9586
9587 /**
9588  * gtk_widget_class_install_style_property:
9589  * @klass: a #GtkWidgetClass
9590  * @pspec: the #GParamSpec for the property
9591  * 
9592  * Installs a style property on a widget class. The parser for the
9593  * style property is determined by the value type of @pspec.
9594  **/
9595 void
9596 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9597                                          GParamSpec     *pspec)
9598 {
9599   GtkRcPropertyParser parser;
9600
9601   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9602   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9603
9604   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9605
9606   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9607 }
9608
9609 /**
9610  * gtk_widget_class_find_style_property:
9611  * @klass: a #GtkWidgetClass
9612  * @property_name: the name of the style property to find
9613  * @returns: the #GParamSpec of the style property or %NULL if @class has no
9614  *   style property with that name.
9615  *
9616  * Finds a style property of a widget class by name.
9617  *
9618  * Since: 2.2
9619  */
9620 GParamSpec*
9621 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9622                                       const gchar    *property_name)
9623 {
9624   g_return_val_if_fail (property_name != NULL, NULL);
9625
9626   return g_param_spec_pool_lookup (style_property_spec_pool,
9627                                    property_name,
9628                                    G_OBJECT_CLASS_TYPE (klass),
9629                                    TRUE);
9630 }
9631
9632 /**
9633  * gtk_widget_class_list_style_properties:
9634  * @klass: a #GtkWidgetClass
9635  * @n_properties: location to return the number of style properties found
9636  * @returns: an newly allocated array of #GParamSpec*. The array must 
9637  *       be freed with g_free().
9638  *
9639  * Returns all style properties of a widget class.
9640  *
9641  * Since: 2.2
9642  */
9643 GParamSpec**
9644 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9645                                         guint          *n_properties)
9646 {
9647   GParamSpec **pspecs;
9648   guint n;
9649
9650   pspecs = g_param_spec_pool_list (style_property_spec_pool,
9651                                    G_OBJECT_CLASS_TYPE (klass),
9652                                    &n);
9653   if (n_properties)
9654     *n_properties = n;
9655
9656   return pspecs;
9657 }
9658
9659 /**
9660  * gtk_widget_style_get_property:
9661  * @widget: a #GtkWidget
9662  * @property_name: the name of a style property
9663  * @value: location to return the property value 
9664  *
9665  * Gets the value of a style property of @widget.
9666  */
9667 void
9668 gtk_widget_style_get_property (GtkWidget   *widget,
9669                                const gchar *property_name,
9670                                GValue      *value)
9671 {
9672   GParamSpec *pspec;
9673
9674   g_return_if_fail (GTK_IS_WIDGET (widget));
9675   g_return_if_fail (property_name != NULL);
9676   g_return_if_fail (G_IS_VALUE (value));
9677
9678   g_object_ref (widget);
9679   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9680                                     property_name,
9681                                     G_OBJECT_TYPE (widget),
9682                                     TRUE);
9683   if (!pspec)
9684     g_warning ("%s: widget class `%s' has no property named `%s'",
9685                G_STRLOC,
9686                G_OBJECT_TYPE_NAME (widget),
9687                property_name);
9688   else
9689     {
9690       const GValue *peek_value;
9691
9692       peek_value = _gtk_style_peek_property_value (widget->style,
9693                                                    G_OBJECT_TYPE (widget),
9694                                                    pspec,
9695                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9696       
9697       /* auto-conversion of the caller's value type
9698        */
9699       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9700         g_value_copy (peek_value, value);
9701       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9702         g_value_transform (peek_value, value);
9703       else
9704         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9705                    pspec->name,
9706                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9707                    G_VALUE_TYPE_NAME (value));
9708     }
9709   g_object_unref (widget);
9710 }
9711
9712 /**
9713  * gtk_widget_style_get_valist:
9714  * @widget: a #GtkWidget
9715  * @first_property_name: the name of the first property to get
9716  * @var_args: a <type>va_list</type> of pairs of property names and
9717  *     locations to return the property values, starting with the location
9718  *     for @first_property_name.
9719  * 
9720  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
9721  * bindings.
9722  */ 
9723 void
9724 gtk_widget_style_get_valist (GtkWidget   *widget,
9725                              const gchar *first_property_name,
9726                              va_list      var_args)
9727 {
9728   const gchar *name;
9729
9730   g_return_if_fail (GTK_IS_WIDGET (widget));
9731
9732   g_object_ref (widget);
9733
9734   name = first_property_name;
9735   while (name)
9736     {
9737       const GValue *peek_value;
9738       GParamSpec *pspec;
9739       gchar *error;
9740
9741       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9742                                         name,
9743                                         G_OBJECT_TYPE (widget),
9744                                         TRUE);
9745       if (!pspec)
9746         {
9747           g_warning ("%s: widget class `%s' has no property named `%s'",
9748                      G_STRLOC,
9749                      G_OBJECT_TYPE_NAME (widget),
9750                      name);
9751           break;
9752         }
9753       /* style pspecs are always readable so we can spare that check here */
9754
9755       peek_value = _gtk_style_peek_property_value (widget->style,
9756                                                    G_OBJECT_TYPE (widget),
9757                                                    pspec,
9758                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9759       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9760       if (error)
9761         {
9762           g_warning ("%s: %s", G_STRLOC, error);
9763           g_free (error);
9764           break;
9765         }
9766
9767       name = va_arg (var_args, gchar*);
9768     }
9769
9770   g_object_unref (widget);
9771 }
9772
9773 /**
9774  * gtk_widget_style_get:
9775  * @widget: a #GtkWidget
9776  * @first_property_name: the name of the first property to get
9777  * @Varargs: pairs of property names and locations to 
9778  *   return the property values, starting with the location for 
9779  *   @first_property_name, terminated by %NULL.
9780  *
9781  * Gets the values of a multiple style properties of @widget.
9782  */
9783 void
9784 gtk_widget_style_get (GtkWidget   *widget,
9785                       const gchar *first_property_name,
9786                       ...)
9787 {
9788   va_list var_args;
9789
9790   g_return_if_fail (GTK_IS_WIDGET (widget));
9791
9792   va_start (var_args, first_property_name);
9793   gtk_widget_style_get_valist (widget, first_property_name, var_args);
9794   va_end (var_args);
9795 }
9796
9797 /**
9798  * gtk_widget_path:
9799  * @widget: a #GtkWidget
9800  * @path_length: (out) (allow-none): location to store length of the path, or %NULL
9801  * @path: (out) (allow-none):  location to store allocated path string, or %NULL
9802  * @path_reversed: (out) (allow-none):  location to store allocated reverse path string, or %NULL
9803  *
9804  * Obtains the full path to @widget. The path is simply the name of a
9805  * widget and all its parents in the container hierarchy, separated by
9806  * periods. The name of a widget comes from
9807  * gtk_widget_get_name(). Paths are used to apply styles to a widget
9808  * in gtkrc configuration files. Widget names are the type of the
9809  * widget by default (e.g. "GtkButton") or can be set to an
9810  * application-specific value with gtk_widget_set_name(). By setting
9811  * the name of a widget, you allow users or theme authors to apply
9812  * styles to that specific widget in their gtkrc
9813  * file. @path_reversed_p fills in the path in reverse order,
9814  * i.e. starting with @widget's name instead of starting with the name
9815  * of @widget's outermost ancestor.
9816  **/
9817 void
9818 gtk_widget_path (GtkWidget *widget,
9819                  guint     *path_length,
9820                  gchar    **path,
9821                  gchar    **path_reversed)
9822 {
9823   static gchar *rev_path = NULL;
9824   static guint tmp_path_len = 0;
9825   guint len;
9826   
9827   g_return_if_fail (GTK_IS_WIDGET (widget));
9828   
9829   len = 0;
9830   do
9831     {
9832       const gchar *string;
9833       const gchar *s;
9834       gchar *d;
9835       guint l;
9836       
9837       string = gtk_widget_get_name (widget);
9838       l = strlen (string);
9839       while (tmp_path_len <= len + l + 1)
9840         {
9841           tmp_path_len += INIT_PATH_SIZE;
9842           rev_path = g_realloc (rev_path, tmp_path_len);
9843         }
9844       s = string + l - 1;
9845       d = rev_path + len;
9846       while (s >= string)
9847         *(d++) = *(s--);
9848       len += l;
9849       
9850       widget = widget->parent;
9851       
9852       if (widget)
9853         rev_path[len++] = '.';
9854       else
9855         rev_path[len++] = 0;
9856     }
9857   while (widget);
9858   
9859   if (path_length)
9860     *path_length = len - 1;
9861   if (path_reversed)
9862     *path_reversed = g_strdup (rev_path);
9863   if (path)
9864     {
9865       *path = g_strdup (rev_path);
9866       g_strreverse (*path);
9867     }
9868 }
9869
9870 /**
9871  * gtk_widget_class_path:
9872  * @widget: a #GtkWidget
9873  * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
9874  * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
9875  * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
9876  *    string, or %NULL
9877  *
9878  * Same as gtk_widget_path(), but always uses the name of a widget's type,
9879  * never uses a custom name set with gtk_widget_set_name().
9880  * 
9881  **/
9882 void
9883 gtk_widget_class_path (GtkWidget *widget,
9884                        guint     *path_length,
9885                        gchar    **path,
9886                        gchar    **path_reversed)
9887 {
9888   static gchar *rev_path = NULL;
9889   static guint tmp_path_len = 0;
9890   guint len;
9891   
9892   g_return_if_fail (GTK_IS_WIDGET (widget));
9893   
9894   len = 0;
9895   do
9896     {
9897       const gchar *string;
9898       const gchar *s;
9899       gchar *d;
9900       guint l;
9901       
9902       string = g_type_name (GTK_WIDGET_TYPE (widget));
9903       l = strlen (string);
9904       while (tmp_path_len <= len + l + 1)
9905         {
9906           tmp_path_len += INIT_PATH_SIZE;
9907           rev_path = g_realloc (rev_path, tmp_path_len);
9908         }
9909       s = string + l - 1;
9910       d = rev_path + len;
9911       while (s >= string)
9912         *(d++) = *(s--);
9913       len += l;
9914       
9915       widget = widget->parent;
9916       
9917       if (widget)
9918         rev_path[len++] = '.';
9919       else
9920         rev_path[len++] = 0;
9921     }
9922   while (widget);
9923   
9924   if (path_length)
9925     *path_length = len - 1;
9926   if (path_reversed)
9927     *path_reversed = g_strdup (rev_path);
9928   if (path)
9929     {
9930       *path = g_strdup (rev_path);
9931       g_strreverse (*path);
9932     }
9933 }
9934
9935 /**
9936  * gtk_requisition_copy:
9937  * @requisition: a #GtkRequisition
9938  *
9939  * Copies a #GtkRequisition.
9940  *
9941  * Returns: a copy of @requisition
9942  **/
9943 GtkRequisition *
9944 gtk_requisition_copy (const GtkRequisition *requisition)
9945 {
9946   return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9947 }
9948
9949 /**
9950  * gtk_requisition_free:
9951  * @requisition: a #GtkRequisition
9952  * 
9953  * Frees a #GtkRequisition.
9954  **/
9955 void
9956 gtk_requisition_free (GtkRequisition *requisition)
9957 {
9958   g_free (requisition);
9959 }
9960
9961 GType
9962 gtk_requisition_get_type (void)
9963 {
9964   static GType our_type = 0;
9965   
9966   if (our_type == 0)
9967     our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9968                                              (GBoxedCopyFunc) gtk_requisition_copy,
9969                                              (GBoxedFreeFunc) gtk_requisition_free);
9970
9971   return our_type;
9972 }
9973
9974 /**
9975  * gtk_widget_get_accessible:
9976  * @widget: a #GtkWidget
9977  *
9978  * Returns the accessible object that describes the widget to an
9979  * assistive technology. 
9980  * 
9981  * If no accessibility library is loaded (i.e. no ATK implementation library is 
9982  * loaded via <envar>GTK_MODULES</envar> or via another application library, 
9983  * such as libgnome), then this #AtkObject instance may be a no-op. Likewise, 
9984  * if no class-specific #AtkObject implementation is available for the widget 
9985  * instance in question, it will inherit an #AtkObject implementation from the 
9986  * first ancestor class for which such an implementation is defined.
9987  *
9988  * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9989  * library contains more information about accessible objects and their uses.
9990  *
9991  * Returns: (transfer none): the #AtkObject associated with @widget
9992  */
9993 AtkObject*
9994 gtk_widget_get_accessible (GtkWidget *widget)
9995 {
9996   GtkWidgetClass *klass;
9997
9998   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9999
10000   klass = GTK_WIDGET_GET_CLASS (widget);
10001
10002   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10003
10004   return klass->get_accessible (widget);
10005 }
10006
10007 static AtkObject* 
10008 gtk_widget_real_get_accessible (GtkWidget *widget)
10009 {
10010   AtkObject* accessible;
10011
10012   accessible = g_object_get_qdata (G_OBJECT (widget), 
10013                                    quark_accessible_object);
10014   if (!accessible)
10015   {
10016     AtkObjectFactory *factory;
10017     AtkRegistry *default_registry;
10018
10019     default_registry = atk_get_default_registry ();
10020     factory = atk_registry_get_factory (default_registry, 
10021                                         G_TYPE_FROM_INSTANCE (widget));
10022     accessible =
10023       atk_object_factory_create_accessible (factory,
10024                                             G_OBJECT (widget));
10025     g_object_set_qdata (G_OBJECT (widget), 
10026                         quark_accessible_object,
10027                         accessible);
10028   }
10029   return accessible;
10030 }
10031
10032 /*
10033  * Initialize a AtkImplementorIface instance's virtual pointers as
10034  * appropriate to this implementor's class (GtkWidget).
10035  */
10036 static void
10037 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10038 {
10039   iface->ref_accessible = gtk_widget_ref_accessible;
10040 }
10041
10042 static AtkObject*
10043 gtk_widget_ref_accessible (AtkImplementor *implementor)
10044 {
10045   AtkObject *accessible;
10046
10047   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10048   if (accessible)
10049     g_object_ref (accessible);
10050   return accessible;
10051 }
10052
10053 /*
10054  * GtkBuildable implementation
10055  */
10056 static GQuark            quark_builder_has_default = 0;
10057 static GQuark            quark_builder_has_focus = 0;
10058 static GQuark            quark_builder_atk_relations = 0;
10059 static GQuark            quark_builder_set_name = 0;
10060
10061 static void
10062 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10063 {
10064   quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10065   quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10066   quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10067   quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10068
10069   iface->set_name = gtk_widget_buildable_set_name;
10070   iface->get_name = gtk_widget_buildable_get_name;
10071   iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10072   iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10073   iface->parser_finished = gtk_widget_buildable_parser_finished;
10074   iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10075   iface->custom_finished = gtk_widget_buildable_custom_finished;
10076 }
10077
10078 static void
10079 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10080                                const gchar  *name)
10081 {
10082   g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10083                            g_strdup (name), g_free);
10084 }
10085
10086 static const gchar *
10087 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10088 {
10089   return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10090 }
10091
10092 static GObject *
10093 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10094                                          GtkBuilder   *builder,
10095                                          const gchar  *childname)
10096 {
10097   if (strcmp (childname, "accessible") == 0)
10098     return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10099
10100   return NULL;
10101 }
10102
10103 static void
10104 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10105                                              GtkBuilder   *builder,
10106                                              const gchar  *name,
10107                                              const GValue *value)
10108 {
10109   if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10110       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10111                           GINT_TO_POINTER (TRUE));
10112   else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10113       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10114                           GINT_TO_POINTER (TRUE));
10115   else
10116     g_object_set_property (G_OBJECT (buildable), name, value);
10117 }
10118
10119 typedef struct
10120 {
10121   gchar *action_name;
10122   GString *description;
10123   gchar *context;
10124   gboolean translatable;
10125 } AtkActionData;
10126
10127 typedef struct
10128 {
10129   gchar *target;
10130   gchar *type;
10131 } AtkRelationData;
10132
10133 static void
10134 free_action (AtkActionData *data, gpointer user_data)
10135 {
10136   g_free (data->action_name);
10137   g_string_free (data->description, TRUE);
10138   g_free (data->context);
10139   g_slice_free (AtkActionData, data);
10140 }
10141
10142 static void
10143 free_relation (AtkRelationData *data, gpointer user_data)
10144 {
10145   g_free (data->target);
10146   g_free (data->type);
10147   g_slice_free (AtkRelationData, data);
10148 }
10149
10150 static void
10151 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10152                                       GtkBuilder   *builder)
10153 {
10154   GSList *atk_relations;
10155
10156   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10157     gtk_widget_grab_default (GTK_WIDGET (buildable));
10158   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10159     gtk_widget_grab_focus (GTK_WIDGET (buildable));
10160
10161   atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10162                                       quark_builder_atk_relations);
10163   if (atk_relations)
10164     {
10165       AtkObject *accessible;
10166       AtkRelationSet *relation_set;
10167       GSList *l;
10168       GObject *target;
10169       AtkRelationType relation_type;
10170       AtkObject *target_accessible;
10171
10172       accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10173       relation_set = atk_object_ref_relation_set (accessible);
10174
10175       for (l = atk_relations; l; l = l->next)
10176         {
10177           AtkRelationData *relation = (AtkRelationData*)l->data;
10178
10179           target = gtk_builder_get_object (builder, relation->target);
10180           if (!target)
10181             {
10182               g_warning ("Target object %s in <relation> does not exist",
10183                          relation->target);
10184               continue;
10185             }
10186           target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10187           g_assert (target_accessible != NULL);
10188
10189           relation_type = atk_relation_type_for_name (relation->type);
10190           if (relation_type == ATK_RELATION_NULL)
10191             {
10192               g_warning ("<relation> type %s not found",
10193                          relation->type);
10194               continue;
10195             }
10196           atk_relation_set_add_relation_by_type (relation_set, relation_type,
10197                                                  target_accessible);
10198         }
10199       g_object_unref (relation_set);
10200
10201       g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10202       g_slist_free (atk_relations);
10203       g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10204                           NULL);
10205     }
10206 }
10207
10208 typedef struct
10209 {
10210   GSList *actions;
10211   GSList *relations;
10212 } AccessibilitySubParserData;
10213
10214 static void
10215 accessibility_start_element (GMarkupParseContext  *context,
10216                              const gchar          *element_name,
10217                              const gchar         **names,
10218                              const gchar         **values,
10219                              gpointer              user_data,
10220                              GError              **error)
10221 {
10222   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10223   guint i;
10224   gint line_number, char_number;
10225
10226   if (strcmp (element_name, "relation") == 0)
10227     {
10228       gchar *target = NULL;
10229       gchar *type = NULL;
10230       AtkRelationData *relation;
10231
10232       for (i = 0; names[i]; i++)
10233         {
10234           if (strcmp (names[i], "target") == 0)
10235             target = g_strdup (values[i]);
10236           else if (strcmp (names[i], "type") == 0)
10237             type = g_strdup (values[i]);
10238           else
10239             {
10240               g_markup_parse_context_get_position (context,
10241                                                    &line_number,
10242                                                    &char_number);
10243               g_set_error (error,
10244                            GTK_BUILDER_ERROR,
10245                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10246                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10247                            "<input>",
10248                            line_number, char_number, names[i], "relation");
10249               g_free (target);
10250               g_free (type);
10251               return;
10252             }
10253         }
10254
10255       if (!target || !type)
10256         {
10257           g_markup_parse_context_get_position (context,
10258                                                &line_number,
10259                                                &char_number);
10260           g_set_error (error,
10261                        GTK_BUILDER_ERROR,
10262                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10263                        "%s:%d:%d <%s> requires attribute \"%s\"",
10264                        "<input>",
10265                        line_number, char_number, "relation",
10266                        type ? "target" : "type");
10267           g_free (target);
10268           g_free (type);
10269           return;
10270         }
10271
10272       relation = g_slice_new (AtkRelationData);
10273       relation->target = target;
10274       relation->type = type;
10275
10276       data->relations = g_slist_prepend (data->relations, relation);
10277     }
10278   else if (strcmp (element_name, "action") == 0)
10279     {
10280       const gchar *action_name = NULL;
10281       const gchar *description = NULL;
10282       const gchar *msg_context = NULL;
10283       gboolean translatable = FALSE;
10284       AtkActionData *action;
10285
10286       for (i = 0; names[i]; i++)
10287         {
10288           if (strcmp (names[i], "action_name") == 0)
10289             action_name = values[i];
10290           else if (strcmp (names[i], "description") == 0)
10291             description = values[i];
10292           else if (strcmp (names[i], "translatable") == 0)
10293             {
10294               if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10295                 return;
10296             }
10297           else if (strcmp (names[i], "comments") == 0)
10298             {
10299               /* do nothing, comments are for translators */
10300             }
10301           else if (strcmp (names[i], "context") == 0)
10302             msg_context = values[i];
10303           else
10304             {
10305               g_markup_parse_context_get_position (context,
10306                                                    &line_number,
10307                                                    &char_number);
10308               g_set_error (error,
10309                            GTK_BUILDER_ERROR,
10310                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10311                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10312                            "<input>",
10313                            line_number, char_number, names[i], "action");
10314               return;
10315             }
10316         }
10317
10318       if (!action_name)
10319         {
10320           g_markup_parse_context_get_position (context,
10321                                                &line_number,
10322                                                &char_number);
10323           g_set_error (error,
10324                        GTK_BUILDER_ERROR,
10325                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10326                        "%s:%d:%d <%s> requires attribute \"%s\"",
10327                        "<input>",
10328                        line_number, char_number, "action",
10329                        "action_name");
10330           return;
10331         }
10332
10333       action = g_slice_new (AtkActionData);
10334       action->action_name = g_strdup (action_name);
10335       action->description = g_string_new (description);
10336       action->context = g_strdup (msg_context);
10337       action->translatable = translatable;
10338
10339       data->actions = g_slist_prepend (data->actions, action);
10340     }
10341   else if (strcmp (element_name, "accessibility") == 0)
10342     ;
10343   else
10344     g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10345 }
10346
10347 static void
10348 accessibility_text (GMarkupParseContext  *context,
10349                     const gchar          *text,
10350                     gsize                 text_len,
10351                     gpointer              user_data,
10352                     GError              **error)
10353 {
10354   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10355
10356   if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10357     {
10358       AtkActionData *action = data->actions->data;
10359
10360       g_string_append_len (action->description, text, text_len);
10361     }
10362 }
10363
10364 static const GMarkupParser accessibility_parser =
10365   {
10366     accessibility_start_element,
10367     NULL,
10368     accessibility_text,
10369   };
10370
10371 typedef struct
10372 {
10373   GObject *object;
10374   guint    key;
10375   guint    modifiers;
10376   gchar   *signal;
10377 } AccelGroupParserData;
10378
10379 static void
10380 accel_group_start_element (GMarkupParseContext  *context,
10381                            const gchar          *element_name,
10382                            const gchar         **names,
10383                            const gchar         **values,
10384                            gpointer              user_data,
10385                            GError              **error)
10386 {
10387   gint i;
10388   guint key = 0;
10389   guint modifiers = 0;
10390   gchar *signal = NULL;
10391   AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10392
10393   for (i = 0; names[i]; i++)
10394     {
10395       if (strcmp (names[i], "key") == 0)
10396         key = gdk_keyval_from_name (values[i]);
10397       else if (strcmp (names[i], "modifiers") == 0)
10398         {
10399           if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10400                                                values[i],
10401                                                &modifiers,
10402                                                error))
10403               return;
10404         }
10405       else if (strcmp (names[i], "signal") == 0)
10406         signal = g_strdup (values[i]);
10407     }
10408
10409   if (key == 0 || signal == NULL)
10410     {
10411       g_warning ("<accelerator> requires key and signal attributes");
10412       return;
10413     }
10414   parser_data->key = key;
10415   parser_data->modifiers = modifiers;
10416   parser_data->signal = signal;
10417 }
10418
10419 static const GMarkupParser accel_group_parser =
10420   {
10421     accel_group_start_element,
10422   };
10423
10424 static gboolean
10425 gtk_widget_buildable_custom_tag_start (GtkBuildable     *buildable,
10426                                        GtkBuilder       *builder,
10427                                        GObject          *child,
10428                                        const gchar      *tagname,
10429                                        GMarkupParser    *parser,
10430                                        gpointer         *data)
10431 {
10432   g_assert (buildable);
10433
10434   if (strcmp (tagname, "accelerator") == 0)
10435     {
10436       AccelGroupParserData *parser_data;
10437
10438       parser_data = g_slice_new0 (AccelGroupParserData);
10439       parser_data->object = g_object_ref (buildable);
10440       *parser = accel_group_parser;
10441       *data = parser_data;
10442       return TRUE;
10443     }
10444   if (strcmp (tagname, "accessibility") == 0)
10445     {
10446       AccessibilitySubParserData *parser_data;
10447
10448       parser_data = g_slice_new0 (AccessibilitySubParserData);
10449       *parser = accessibility_parser;
10450       *data = parser_data;
10451       return TRUE;
10452     }
10453   return FALSE;
10454 }
10455
10456 void
10457 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10458                                           GtkWidget *toplevel,
10459                                           gpointer   user_data)
10460 {
10461   AccelGroupParserData *accel_data;
10462   GSList *accel_groups;
10463   GtkAccelGroup *accel_group;
10464
10465   g_return_if_fail (GTK_IS_WIDGET (widget));
10466   g_return_if_fail (GTK_IS_WIDGET (toplevel));
10467   g_return_if_fail (user_data != NULL);
10468
10469   accel_data = (AccelGroupParserData*)user_data;
10470   accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10471   if (g_slist_length (accel_groups) == 0)
10472     {
10473       accel_group = gtk_accel_group_new ();
10474       gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10475     }
10476   else
10477     {
10478       g_assert (g_slist_length (accel_groups) == 1);
10479       accel_group = g_slist_nth_data (accel_groups, 0);
10480     }
10481
10482   gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10483                               accel_data->signal,
10484                               accel_group,
10485                               accel_data->key,
10486                               accel_data->modifiers,
10487                               GTK_ACCEL_VISIBLE);
10488
10489   g_object_unref (accel_data->object);
10490   g_free (accel_data->signal);
10491   g_slice_free (AccelGroupParserData, accel_data);
10492 }
10493
10494 static void
10495 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10496                                       GtkBuilder   *builder,
10497                                       GObject      *child,
10498                                       const gchar  *tagname,
10499                                       gpointer      user_data)
10500 {
10501   AccelGroupParserData *accel_data;
10502   AccessibilitySubParserData *a11y_data;
10503   GtkWidget *toplevel;
10504
10505   if (strcmp (tagname, "accelerator") == 0)
10506     {
10507       accel_data = (AccelGroupParserData*)user_data;
10508       g_assert (accel_data->object);
10509
10510       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10511
10512       _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10513     }
10514   else if (strcmp (tagname, "accessibility") == 0)
10515     {
10516       a11y_data = (AccessibilitySubParserData*)user_data;
10517
10518       if (a11y_data->actions)
10519         {
10520           AtkObject *accessible;
10521           AtkAction *action;
10522           gint i, n_actions;
10523           GSList *l;
10524
10525           accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10526
10527           action = ATK_ACTION (accessible);
10528           n_actions = atk_action_get_n_actions (action);
10529
10530           for (l = a11y_data->actions; l; l = l->next)
10531             {
10532               AtkActionData *action_data = (AtkActionData*)l->data;
10533
10534               for (i = 0; i < n_actions; i++)
10535                 if (strcmp (atk_action_get_name (action, i),
10536                             action_data->action_name) == 0)
10537                   break;
10538
10539               if (i < n_actions)
10540                 {
10541                   gchar *description;
10542
10543                   if (action_data->translatable && action_data->description->len)
10544                     description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10545                                                                  action_data->context,
10546                                                                  action_data->description->str);
10547                   else
10548                     description = action_data->description->str;
10549
10550                   atk_action_set_description (action, i, description);
10551                 }
10552             }
10553
10554           g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10555           g_slist_free (a11y_data->actions);
10556         }
10557
10558       if (a11y_data->relations)
10559         g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10560                             a11y_data->relations);
10561
10562       g_slice_free (AccessibilitySubParserData, a11y_data);
10563     }
10564 }
10565
10566
10567 /**
10568  * gtk_widget_get_clipboard:
10569  * @widget: a #GtkWidget
10570  * @selection: a #GdkAtom which identifies the clipboard
10571  *             to use. %GDK_SELECTION_CLIPBOARD gives the
10572  *             default clipboard. Another common value
10573  *             is %GDK_SELECTION_PRIMARY, which gives
10574  *             the primary X selection. 
10575  * 
10576  * Returns the clipboard object for the given selection to
10577  * be used with @widget. @widget must have a #GdkDisplay
10578  * associated with it, so must be attached to a toplevel
10579  * window.
10580  *
10581  * Return value: (transfer none): the appropriate clipboard object. If no
10582  *             clipboard already exists, a new one will
10583  *             be created. Once a clipboard object has
10584  *             been created, it is persistent for all time.
10585  *
10586  * Since: 2.2
10587  **/
10588 GtkClipboard *
10589 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10590 {
10591   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10592   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10593   
10594   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10595                                         selection);
10596 }
10597
10598 /**
10599  * gtk_widget_list_mnemonic_labels:
10600  * @widget: a #GtkWidget
10601  * 
10602  * Returns a newly allocated list of the widgets, normally labels, for 
10603  * which this widget is a the target of a mnemonic (see for example, 
10604  * gtk_label_set_mnemonic_widget()).
10605
10606  * The widgets in the list are not individually referenced. If you
10607  * want to iterate through the list and perform actions involving
10608  * callbacks that might destroy the widgets, you
10609  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10610  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10611  * widgets afterwards.
10612
10613  * Return value: (element-type GtkWidget) (transfer container): the list of
10614  *  mnemonic labels; free this list
10615  *  with g_list_free() when you are done with it.
10616  *
10617  * Since: 2.4
10618  **/
10619 GList *
10620 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10621 {
10622   GList *list = NULL;
10623   GSList *l;
10624   
10625   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10626
10627   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10628     list = g_list_prepend (list, l->data);
10629
10630   return list;
10631 }
10632
10633 /**
10634  * gtk_widget_add_mnemonic_label:
10635  * @widget: a #GtkWidget
10636  * @label: a #GtkWidget that acts as a mnemonic label for @widget
10637  * 
10638  * Adds a widget to the list of mnemonic labels for
10639  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10640  * list of mnemonic labels for the widget is cleared when the
10641  * widget is destroyed, so the caller must make sure to update
10642  * its internal state at this point as well, by using a connection
10643  * to the #GtkWidget::destroy signal or a weak notifier.
10644  *
10645  * Since: 2.4
10646  **/
10647 void
10648 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10649                                GtkWidget *label)
10650 {
10651   GSList *old_list, *new_list;
10652
10653   g_return_if_fail (GTK_IS_WIDGET (widget));
10654   g_return_if_fail (GTK_IS_WIDGET (label));
10655
10656   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10657   new_list = g_slist_prepend (old_list, label);
10658   
10659   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10660                            new_list, (GDestroyNotify) g_slist_free);
10661 }
10662
10663 /**
10664  * gtk_widget_remove_mnemonic_label:
10665  * @widget: a #GtkWidget
10666  * @label: a #GtkWidget that was previously set as a mnemnic label for
10667  *         @widget with gtk_widget_add_mnemonic_label().
10668  * 
10669  * Removes a widget from the list of mnemonic labels for
10670  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10671  * must have previously been added to the list with
10672  * gtk_widget_add_mnemonic_label().
10673  *
10674  * Since: 2.4
10675  **/
10676 void
10677 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10678                                   GtkWidget *label)
10679 {
10680   GSList *old_list, *new_list;
10681
10682   g_return_if_fail (GTK_IS_WIDGET (widget));
10683   g_return_if_fail (GTK_IS_WIDGET (label));
10684
10685   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10686   new_list = g_slist_remove (old_list, label);
10687
10688   if (new_list)
10689     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10690                              new_list, (GDestroyNotify) g_slist_free);
10691 }
10692
10693 /**
10694  * gtk_widget_get_no_show_all:
10695  * @widget: a #GtkWidget
10696  * 
10697  * Returns the current value of the GtkWidget:no-show-all property, 
10698  * which determines whether calls to gtk_widget_show_all() and 
10699  * gtk_widget_hide_all() will affect this widget. 
10700  * 
10701  * Return value: the current value of the "no-show-all" property.
10702  *
10703  * Since: 2.4
10704  **/
10705 gboolean
10706 gtk_widget_get_no_show_all (GtkWidget *widget)
10707 {
10708   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10709   
10710   return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10711 }
10712
10713 /**
10714  * gtk_widget_set_no_show_all:
10715  * @widget: a #GtkWidget
10716  * @no_show_all: the new value for the "no-show-all" property
10717  * 
10718  * Sets the #GtkWidget:no-show-all property, which determines whether 
10719  * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect 
10720  * this widget. 
10721  *
10722  * This is mostly for use in constructing widget hierarchies with externally
10723  * controlled visibility, see #GtkUIManager.
10724  * 
10725  * Since: 2.4
10726  **/
10727 void
10728 gtk_widget_set_no_show_all (GtkWidget *widget,
10729                             gboolean   no_show_all)
10730 {
10731   g_return_if_fail (GTK_IS_WIDGET (widget));
10732
10733   no_show_all = (no_show_all != FALSE);
10734
10735   if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10736     return;
10737
10738   if (no_show_all)
10739     GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10740   else
10741     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10742   
10743   g_object_notify (G_OBJECT (widget), "no-show-all");
10744 }
10745
10746
10747 static void
10748 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10749                                  gboolean   has_tooltip,
10750                                  gboolean   force)
10751 {
10752   gboolean priv_has_tooltip;
10753
10754   priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10755                                        quark_has_tooltip));
10756
10757   if (priv_has_tooltip != has_tooltip || force)
10758     {
10759       priv_has_tooltip = has_tooltip;
10760
10761       if (priv_has_tooltip)
10762         {
10763           if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
10764             gdk_window_set_events (widget->window,
10765                                    gdk_window_get_events (widget->window) |
10766                                    GDK_LEAVE_NOTIFY_MASK |
10767                                    GDK_POINTER_MOTION_MASK |
10768                                    GDK_POINTER_MOTION_HINT_MASK);
10769
10770           if (!GTK_WIDGET_NO_WINDOW (widget))
10771               gtk_widget_add_events (widget,
10772                                      GDK_LEAVE_NOTIFY_MASK |
10773                                      GDK_POINTER_MOTION_MASK |
10774                                      GDK_POINTER_MOTION_HINT_MASK);
10775         }
10776
10777       g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10778                           GUINT_TO_POINTER (priv_has_tooltip));
10779     }
10780 }
10781
10782 /**
10783  * gtk_widget_set_tooltip_window:
10784  * @widget: a #GtkWidget
10785  * @custom_window: a #GtkWindow, or %NULL
10786  *
10787  * Replaces the default, usually yellow, window used for displaying
10788  * tooltips with @custom_window. GTK+ will take care of showing and
10789  * hiding @custom_window at the right moment, to behave likewise as
10790  * the default tooltip window. If @custom_window is %NULL, the default
10791  * tooltip window will be used.
10792  *
10793  * If the custom window should have the default theming it needs to
10794  * have the name "gtk-tooltip", see gtk_widget_set_name().
10795  *
10796  * Since: 2.12
10797  */
10798 void
10799 gtk_widget_set_tooltip_window (GtkWidget *widget,
10800                                GtkWindow *custom_window)
10801 {
10802   gboolean has_tooltip;
10803   gchar *tooltip_markup;
10804
10805   g_return_if_fail (GTK_IS_WIDGET (widget));
10806   g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10807
10808   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10809
10810   if (custom_window)
10811     g_object_ref (custom_window);
10812
10813   g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10814                            custom_window, g_object_unref);
10815
10816   has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10817   gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10818
10819   if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10820     gtk_widget_queue_tooltip_query (widget);
10821 }
10822
10823 /**
10824  * gtk_widget_get_tooltip_window:
10825  * @widget: a #GtkWidget
10826  *
10827  * Returns the #GtkWindow of the current tooltip. This can be the
10828  * GtkWindow created by default, or the custom tooltip window set
10829  * using gtk_widget_set_tooltip_window().
10830  *
10831  * Return value: (transfer none): The #GtkWindow of the current tooltip.
10832  *
10833  * Since: 2.12
10834  */
10835 GtkWindow *
10836 gtk_widget_get_tooltip_window (GtkWidget *widget)
10837 {
10838   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10839
10840   return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10841 }
10842
10843 /**
10844  * gtk_widget_trigger_tooltip_query:
10845  * @widget: a #GtkWidget
10846  *
10847  * Triggers a tooltip query on the display where the toplevel of @widget
10848  * is located. See gtk_tooltip_trigger_tooltip_query() for more
10849  * information.
10850  *
10851  * Since: 2.12
10852  */
10853 void
10854 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10855 {
10856   gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10857 }
10858
10859 static guint tooltip_query_id;
10860 static GSList *tooltip_query_displays;
10861
10862 static gboolean
10863 tooltip_query_idle (gpointer data)
10864 {
10865   g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
10866   g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
10867   g_slist_free (tooltip_query_displays);
10868
10869   tooltip_query_displays = NULL;
10870   tooltip_query_id = 0;
10871
10872   return FALSE;
10873 }
10874
10875 static void
10876 gtk_widget_queue_tooltip_query (GtkWidget *widget)
10877 {
10878   GdkDisplay *display;
10879
10880   display = gtk_widget_get_display (widget);
10881
10882   if (!g_slist_find (tooltip_query_displays, display))
10883     tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
10884
10885   if (tooltip_query_id == 0)
10886     tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
10887 }
10888
10889 /**
10890  * gtk_widget_set_tooltip_text:
10891  * @widget: a #GtkWidget
10892  * @text: the contents of the tooltip for @widget
10893  *
10894  * Sets @text as the contents of the tooltip. This function will take
10895  * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10896  * handler for the GtkWidget::query-tooltip signal.
10897  *
10898  * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10899  *
10900  * Since: 2.12
10901  */
10902 void
10903 gtk_widget_set_tooltip_text (GtkWidget   *widget,
10904                              const gchar *text)
10905 {
10906   g_return_if_fail (GTK_IS_WIDGET (widget));
10907
10908   g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10909 }
10910
10911 /**
10912  * gtk_widget_get_tooltip_text:
10913  * @widget: a #GtkWidget
10914  *
10915  * Gets the contents of the tooltip for @widget.
10916  *
10917  * Return value: the tooltip text, or %NULL. You should free the
10918  *   returned string with g_free() when done.
10919  *
10920  * Since: 2.12
10921  */
10922 gchar *
10923 gtk_widget_get_tooltip_text (GtkWidget *widget)
10924 {
10925   gchar *text = NULL;
10926
10927   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10928
10929   g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10930
10931   return text;
10932 }
10933
10934 /**
10935  * gtk_widget_set_tooltip_markup:
10936  * @widget: a #GtkWidget
10937  * @markup: the contents of the tooltip for @widget, or %NULL
10938  *
10939  * Sets @markup as the contents of the tooltip, which is marked up with
10940  *  the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10941  *
10942  * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10943  * and of the default handler for the GtkWidget::query-tooltip signal.
10944  *
10945  * See also the GtkWidget:tooltip-markup property and
10946  * gtk_tooltip_set_markup().
10947  *
10948  * Since: 2.12
10949  */
10950 void
10951 gtk_widget_set_tooltip_markup (GtkWidget   *widget,
10952                                const gchar *markup)
10953 {
10954   g_return_if_fail (GTK_IS_WIDGET (widget));
10955
10956   g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10957 }
10958
10959 /**
10960  * gtk_widget_get_tooltip_markup:
10961  * @widget: a #GtkWidget
10962  *
10963  * Gets the contents of the tooltip for @widget.
10964  *
10965  * Return value: the tooltip text, or %NULL. You should free the
10966  *   returned string with g_free() when done.
10967  *
10968  * Since: 2.12
10969  */
10970 gchar *
10971 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10972 {
10973   gchar *text = NULL;
10974
10975   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10976
10977   g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10978
10979   return text;
10980 }
10981
10982 /**
10983  * gtk_widget_set_has_tooltip:
10984  * @widget: a #GtkWidget
10985  * @has_tooltip: whether or not @widget has a tooltip.
10986  *
10987  * Sets the has-tooltip property on @widget to @has_tooltip.  See
10988  * GtkWidget:has-tooltip for more information.
10989  *
10990  * Since: 2.12
10991  */
10992 void
10993 gtk_widget_set_has_tooltip (GtkWidget *widget,
10994                             gboolean   has_tooltip)
10995 {
10996   g_return_if_fail (GTK_IS_WIDGET (widget));
10997
10998   g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
10999 }
11000
11001 /**
11002  * gtk_widget_get_has_tooltip:
11003  * @widget: a #GtkWidget
11004  *
11005  * Returns the current value of the has-tooltip property.  See
11006  * GtkWidget:has-tooltip for more information.
11007  *
11008  * Return value: current value of has-tooltip on @widget.
11009  *
11010  * Since: 2.12
11011  */
11012 gboolean
11013 gtk_widget_get_has_tooltip (GtkWidget *widget)
11014 {
11015   gboolean has_tooltip = FALSE;
11016
11017   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11018
11019   g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11020
11021   return has_tooltip;
11022 }
11023
11024 /**
11025  * gtk_widget_get_allocation:
11026  * @widget: a #GtkWidget
11027  * @allocation: (out): a pointer to a #GtkAllocation to copy to
11028  *
11029  * Retrieves the widget's allocation.
11030  *
11031  * Since: 2.18
11032  */
11033 void
11034 gtk_widget_get_allocation (GtkWidget     *widget,
11035                            GtkAllocation *allocation)
11036 {
11037   g_return_if_fail (GTK_IS_WIDGET (widget));
11038   g_return_if_fail (allocation != NULL);
11039
11040   *allocation = widget->allocation;
11041 }
11042
11043 /**
11044  * gtk_widget_set_allocation:
11045  * @widget: a #GtkWidget
11046  * @allocation: a pointer to a #GtkAllocation to copy from
11047  *
11048  * Sets the widget's allocation.  This should not be used
11049  * directly, but from within a widget's size_allocate method.
11050  *
11051  * Since: 2.18
11052  */
11053 void
11054 gtk_widget_set_allocation (GtkWidget           *widget,
11055                            const GtkAllocation *allocation)
11056 {
11057   g_return_if_fail (GTK_IS_WIDGET (widget));
11058   g_return_if_fail (allocation != NULL);
11059
11060   widget->allocation = *allocation;
11061 }
11062
11063 /**
11064  * gtk_widget_set_window:
11065  * @widget: a #GtkWidget
11066  * @window: a #GdkWindow
11067  *
11068  * Sets a widget's window. This function should only be used in a
11069  * widget's GtkWidget::realize() implementation. The %window passed is
11070  * usually either new window created with gdk_window_new(), or the
11071  * window of its parent widget as returned by
11072  * gtk_widget_get_parent_window().
11073  *
11074  * Widgets must indicate whether they will create their own #GdkWindow
11075  * by calling gtk_widget_set_has_window(). This is usually done in the
11076  * widget's init() function.
11077  *
11078  * Since: 2.18
11079  */
11080 void
11081 gtk_widget_set_window (GtkWidget *widget,
11082                        GdkWindow *window)
11083 {
11084   g_return_if_fail (GTK_IS_WIDGET (widget));
11085   g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11086
11087   if (widget->window != window)
11088     {
11089       widget->window = window;
11090       g_object_notify (G_OBJECT (widget), "window");
11091     }
11092 }
11093
11094 /**
11095  * gtk_widget_get_window:
11096  * @widget: a #GtkWidget
11097  *
11098  * Returns the widget's window if it is realized, %NULL otherwise
11099  *
11100  * Return value: @widget's window.
11101  *
11102  * Since: 2.14
11103  */
11104 GdkWindow*
11105 gtk_widget_get_window (GtkWidget *widget)
11106 {
11107   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11108
11109   return widget->window;
11110 }
11111
11112 #define __GTK_WIDGET_C__
11113 #include "gtkaliasdef.c"