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