]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
API: Remove gtk_widget_get_snapshot()
[~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_HALIGN,
283   PROP_VALIGN,
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:halign:
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_HALIGN,
882                                    g_param_spec_enum ("halign",
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:valign:
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_VALIGN,
898                                    g_param_spec_enum ("valign",
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_HALIGN:
2945       gtk_widget_set_halign (widget, g_value_get_enum (value));
2946       break;
2947     case PROP_VALIGN:
2948       gtk_widget_set_valign (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_HALIGN:
3081       g_value_set_enum (value, gtk_widget_get_halign (widget));
3082       break;
3083     case PROP_VALIGN:
3084       g_value_set_enum (value, gtk_widget_get_valign (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   cairo_region_t *region;
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           region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3841           gdk_window_shape_combine_region (priv->window, region, 0, 0);
3842         }
3843       
3844       region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3845       if (region)
3846         gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3847
3848       mode = gtk_widget_get_extension_events (widget);
3849       if (mode != GDK_EXTENSION_EVENTS_NONE)
3850         gtk_widget_set_extension_events_internal (widget, mode, NULL);
3851
3852       if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3853         gdk_window_set_support_multidevice (priv->window, TRUE);
3854
3855       _gtk_widget_enable_device_events (widget);
3856     }
3857 }
3858
3859 /**
3860  * gtk_widget_unrealize:
3861  * @widget: a #GtkWidget
3862  *
3863  * This function is only useful in widget implementations.
3864  * Causes a widget to be unrealized (frees all GDK resources
3865  * associated with the widget, such as @widget->window).
3866  **/
3867 void
3868 gtk_widget_unrealize (GtkWidget *widget)
3869 {
3870   g_return_if_fail (GTK_IS_WIDGET (widget));
3871
3872   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3873     gtk_widget_shape_combine_region (widget, NULL);
3874
3875   if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3876     gtk_widget_input_shape_combine_region (widget, NULL);
3877
3878   if (gtk_widget_get_realized (widget))
3879     {
3880       g_object_ref (widget);
3881       _gtk_tooltip_hide (widget);
3882       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3883       gtk_widget_set_realized (widget, FALSE);
3884       gtk_widget_set_mapped (widget, FALSE);
3885       g_object_unref (widget);
3886     }
3887 }
3888
3889 /*****************************************
3890  * Draw queueing.
3891  *****************************************/
3892
3893 /**
3894  * gtk_widget_queue_draw_area:
3895  * @widget: a #GtkWidget
3896  * @x: x coordinate of upper-left corner of rectangle to redraw
3897  * @y: y coordinate of upper-left corner of rectangle to redraw
3898  * @width: width of region to draw
3899  * @height: height of region to draw
3900  *
3901  * Invalidates the rectangular area of @widget defined by @x, @y,
3902  * @width and @height by calling gdk_window_invalidate_rect() on the
3903  * widget's window and all its child windows. Once the main loop
3904  * becomes idle (after the current batch of events has been processed,
3905  * roughly), the window will receive expose events for the union of
3906  * all regions that have been invalidated.
3907  *
3908  * Normally you would only use this function in widget
3909  * implementations. You might also use it, or
3910  * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3911  * #GtkDrawingArea or some portion thereof.
3912  *
3913  * Frequently you can just call gdk_window_invalidate_rect() or
3914  * gdk_window_invalidate_region() instead of this function. Those
3915  * functions will invalidate only a single window, instead of the
3916  * widget and all its children.
3917  *
3918  * The advantage of adding to the invalidated region compared to
3919  * simply drawing immediately is efficiency; using an invalid region
3920  * ensures that you only have to redraw one time.
3921  **/
3922 void       
3923 gtk_widget_queue_draw_area (GtkWidget *widget,
3924                             gint       x,
3925                             gint       y,
3926                             gint       width,
3927                             gint       height)
3928 {
3929   GtkWidgetPrivate *priv;
3930   GdkRectangle invalid_rect;
3931   GtkWidget *w;
3932   
3933   g_return_if_fail (GTK_IS_WIDGET (widget));
3934
3935   priv = widget->priv;
3936
3937   if (!gtk_widget_get_realized (widget))
3938     return;
3939   
3940   /* Just return if the widget or one of its ancestors isn't mapped */
3941   for (w = widget; w != NULL; w = w->priv->parent)
3942     if (!gtk_widget_get_mapped (w))
3943       return;
3944
3945   /* Find the correct widget */
3946
3947   if (gtk_widget_get_has_window (widget))
3948     {
3949       if (priv->parent)
3950         {
3951           /* Translate widget relative to window-relative */
3952
3953           gint wx, wy, wwidth, wheight;
3954
3955           gdk_window_get_position (priv->window, &wx, &wy);
3956           x -= wx - priv->allocation.x;
3957           y -= wy - priv->allocation.y;
3958
3959           gdk_drawable_get_size (priv->window, &wwidth, &wheight);
3960
3961           if (x + width <= 0 || y + height <= 0 ||
3962               x >= wwidth || y >= wheight)
3963             return;
3964           
3965           if (x < 0)
3966             {
3967               width += x;  x = 0;
3968             }
3969           if (y < 0)
3970             {
3971               height += y; y = 0;
3972             }
3973           if (x + width > wwidth)
3974             width = wwidth - x;
3975           if (y + height > wheight)
3976             height = wheight - y;
3977         }
3978     }
3979
3980   invalid_rect.x = x;
3981   invalid_rect.y = y;
3982   invalid_rect.width = width;
3983   invalid_rect.height = height;
3984   
3985   gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
3986 }
3987
3988 /**
3989  * gtk_widget_queue_draw:
3990  * @widget: a #GtkWidget
3991  *
3992  * Equivalent to calling gtk_widget_queue_draw_area() for the
3993  * entire area of a widget.
3994  **/
3995 void       
3996 gtk_widget_queue_draw (GtkWidget *widget)
3997 {
3998   GdkRectangle rect;
3999   
4000   g_return_if_fail (GTK_IS_WIDGET (widget));
4001
4002   gtk_widget_get_allocation (widget, &rect);
4003
4004   if (!gtk_widget_get_has_window (widget))
4005     gtk_widget_queue_draw_area (widget,
4006                                 rect.x, rect.y, rect.width, rect.height);
4007   else
4008     gtk_widget_queue_draw_area (widget,
4009                                 0, 0, rect.width, rect.height);
4010 }
4011
4012 /**
4013  * gtk_widget_queue_resize:
4014  * @widget: a #GtkWidget
4015  *
4016  * This function is only for use in widget implementations.
4017  * Flags a widget to have its size renegotiated; should
4018  * be called when a widget for some reason has a new size request.
4019  * For example, when you change the text in a #GtkLabel, #GtkLabel
4020  * queues a resize to ensure there's enough space for the new text.
4021  **/
4022 void
4023 gtk_widget_queue_resize (GtkWidget *widget)
4024 {
4025   g_return_if_fail (GTK_IS_WIDGET (widget));
4026
4027   if (gtk_widget_get_realized (widget))
4028     gtk_widget_queue_shallow_draw (widget);
4029       
4030   _gtk_size_group_queue_resize (widget);
4031 }
4032
4033 /**
4034  * gtk_widget_queue_resize_no_redraw:
4035  * @widget: a #GtkWidget
4036  *
4037  * This function works like gtk_widget_queue_resize(), 
4038  * except that the widget is not invalidated.
4039  *
4040  * Since: 2.4
4041  **/
4042 void
4043 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4044 {
4045   g_return_if_fail (GTK_IS_WIDGET (widget));
4046
4047   _gtk_size_group_queue_resize (widget);
4048 }
4049
4050 /**
4051  * gtk_widget_size_request:
4052  * @widget: a #GtkWidget
4053  * @requisition: (out): a #GtkRequisition to be filled in
4054  * 
4055  * This function is typically used when implementing a #GtkContainer
4056  * subclass.  Obtains the preferred size of a widget. The container
4057  * uses this information to arrange its child widgets and decide what
4058  * size allocations to give them with gtk_widget_size_allocate().
4059  *
4060  * You can also call this function from an application, with some
4061  * caveats. Most notably, getting a size request requires the widget
4062  * to be associated with a screen, because font information may be
4063  * needed. Multihead-aware applications should keep this in mind.
4064  *
4065  * Also remember that the size request is not necessarily the size
4066  * a widget will actually be allocated.
4067  *
4068  * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4069  **/
4070 void
4071 gtk_widget_size_request (GtkWidget      *widget,
4072                          GtkRequisition *requisition)
4073 {
4074   g_return_if_fail (GTK_IS_WIDGET (widget));
4075
4076   gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4077 }
4078
4079 /**
4080  * gtk_widget_get_child_requisition:
4081  * @widget: a #GtkWidget
4082  * @requisition: (out): a #GtkRequisition to be filled in
4083  * 
4084  * This function is only for use in widget implementations. Obtains
4085  * @widget->requisition, unless someone has forced a particular
4086  * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4087  * in which case it returns that geometry instead of the widget's
4088  * requisition.
4089  *
4090  * This function differs from gtk_widget_size_request() in that
4091  * it retrieves the last size request value from @widget->requisition,
4092  * while gtk_widget_size_request() actually calls the "size_request" method
4093  * on @widget to compute the size request and fill in @widget->requisition,
4094  * and only then returns @widget->requisition.
4095  *
4096  * Because this function does not call the "size_request" method, it
4097  * can only be used when you know that @widget->requisition is
4098  * up-to-date, that is, gtk_widget_size_request() has been called
4099  * since the last time a resize was queued. In general, only container
4100  * implementations have this information; applications should use
4101  * gtk_widget_size_request().
4102  *
4103  *
4104  * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4105  **/
4106 void
4107 gtk_widget_get_child_requisition (GtkWidget      *widget,
4108                                   GtkRequisition *requisition)
4109 {
4110   gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4111 }
4112
4113 static gboolean
4114 invalidate_predicate (GdkWindow *window,
4115                       gpointer   data)
4116 {
4117   gpointer user_data;
4118
4119   gdk_window_get_user_data (window, &user_data);
4120
4121   return (user_data == data);
4122 }
4123
4124 /* Invalidate @region in widget->window and all children
4125  * of widget->window owned by widget. @region is in the
4126  * same coordinates as widget->allocation and will be
4127  * modified by this call.
4128  */
4129 static void
4130 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4131                                       cairo_region_t *region)
4132 {
4133   GtkWidgetPrivate *priv = widget->priv;
4134
4135   if (!gtk_widget_get_realized (widget))
4136     return;
4137   
4138   if (gtk_widget_get_has_window (widget) && priv->parent)
4139     {
4140       int x, y;
4141
4142       gdk_window_get_position (priv->window, &x, &y);
4143       cairo_region_translate (region, -x, -y);
4144     }
4145
4146   gdk_window_invalidate_maybe_recurse (priv->window, region,
4147                                        invalidate_predicate, widget);
4148 }
4149
4150 /**
4151  * gtk_widget_queue_shallow_draw:
4152  * @widget: a #GtkWidget
4153  *
4154  * Like gtk_widget_queue_draw(), but only windows owned
4155  * by @widget are invalidated.
4156  **/
4157 static void
4158 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4159 {
4160   GdkRectangle rect;
4161   cairo_region_t *region;
4162
4163   if (!gtk_widget_get_realized (widget))
4164     return;
4165
4166   gtk_widget_get_allocation (widget, &rect);
4167
4168   region = cairo_region_create_rectangle (&rect);
4169   gtk_widget_invalidate_widget_windows (widget, region);
4170   cairo_region_destroy (region);
4171 }
4172
4173 /**
4174  * gtk_widget_size_allocate:
4175  * @widget: a #GtkWidget
4176  * @allocation: (inout): position and size to be allocated to @widget
4177  *
4178  * This function is only used by #GtkContainer subclasses, to assign a size
4179  * and position to their child widgets.
4180  *
4181  * In this function, the allocation may be adjusted. It will be forced
4182  * to a 1x1 minimum size, and the adjust_size_allocation virtual
4183  * method on the child will be used to adjust the allocation. Standard
4184  * adjustments include removing the widget's margins, and applying the
4185  * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4186  **/
4187 void
4188 gtk_widget_size_allocate (GtkWidget     *widget,
4189                           GtkAllocation *allocation)
4190 {
4191   GtkWidgetPrivate *priv;
4192   GdkRectangle real_allocation;
4193   GdkRectangle old_allocation;
4194   GdkRectangle adjusted_allocation;
4195   gboolean alloc_needed;
4196   gboolean size_changed;
4197   gboolean position_changed;
4198
4199   priv = widget->priv;
4200
4201   g_return_if_fail (GTK_IS_WIDGET (widget));
4202  
4203 #ifdef G_ENABLE_DEBUG
4204   if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4205     {
4206       gint depth;
4207       GtkWidget *parent;
4208       const gchar *name;
4209
4210       depth = 0;
4211       parent = widget;
4212       while (parent)
4213         {
4214           depth++;
4215           parent = gtk_widget_get_parent (parent);
4216         }
4217       
4218       name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4219       g_print ("gtk_widget_size_allocate: %*s%s %d %d\n", 
4220                2 * depth, " ", name, 
4221                allocation->width, allocation->height);
4222     }
4223 #endif /* G_ENABLE_DEBUG */
4224  
4225   alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4226   if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4227       !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget))      /* Preserve request/allocate ordering */
4228     GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4229
4230   old_allocation = priv->allocation;
4231   real_allocation = *allocation;
4232
4233   adjusted_allocation = real_allocation;
4234   GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4235
4236   if (adjusted_allocation.x < real_allocation.x ||
4237       adjusted_allocation.y < real_allocation.y ||
4238       (adjusted_allocation.x + adjusted_allocation.width) >
4239       (real_allocation.x + real_allocation.width) ||
4240       (adjusted_allocation.y + adjusted_allocation.height >
4241        real_allocation.y + real_allocation.height))
4242     {
4243       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",
4244                  G_OBJECT_TYPE_NAME (widget), widget,
4245                  real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4246                  adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4247       adjusted_allocation = real_allocation; /* veto it */
4248     }
4249   else
4250     {
4251       real_allocation = adjusted_allocation;
4252     }
4253
4254   if (real_allocation.width < 0 || real_allocation.height < 0)
4255     {
4256       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4257                  real_allocation.width,
4258                  real_allocation.height);
4259     }
4260   
4261   real_allocation.width = MAX (real_allocation.width, 1);
4262   real_allocation.height = MAX (real_allocation.height, 1);
4263
4264   size_changed = (old_allocation.width != real_allocation.width ||
4265                   old_allocation.height != real_allocation.height);
4266   position_changed = (old_allocation.x != real_allocation.x ||
4267                       old_allocation.y != real_allocation.y);
4268
4269   if (!alloc_needed && !size_changed && !position_changed)
4270     return;
4271   
4272   g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4273
4274   if (gtk_widget_get_mapped (widget))
4275     {
4276       if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4277         {
4278           /* Invalidate union(old_allaction,priv->allocation) in priv->window
4279            */
4280           cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4281           cairo_region_union_rectangle (invalidate, &old_allocation);
4282
4283           gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4284           cairo_region_destroy (invalidate);
4285         }
4286       
4287       if (size_changed)
4288         {
4289           if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4290             {
4291               /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4292                */
4293               cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4294               cairo_region_union_rectangle (invalidate, &old_allocation);
4295
4296               gtk_widget_invalidate_widget_windows (widget, invalidate);
4297               cairo_region_destroy (invalidate);
4298             }
4299         }
4300     }
4301
4302   if ((size_changed || position_changed) && priv->parent &&
4303       gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4304     {
4305       cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4306       gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4307       cairo_region_destroy (invalidate);
4308     }
4309 }
4310
4311 /**
4312  * gtk_widget_common_ancestor:
4313  * @widget_a: a #GtkWidget
4314  * @widget_b: a #GtkWidget
4315  * 
4316  * Find the common ancestor of @widget_a and @widget_b that
4317  * is closest to the two widgets.
4318  * 
4319  * Return value: the closest common ancestor of @widget_a and
4320  *   @widget_b or %NULL if @widget_a and @widget_b do not
4321  *   share a common ancestor.
4322  **/
4323 static GtkWidget *
4324 gtk_widget_common_ancestor (GtkWidget *widget_a,
4325                             GtkWidget *widget_b)
4326 {
4327   GtkWidget *parent_a;
4328   GtkWidget *parent_b;
4329   gint depth_a = 0;
4330   gint depth_b = 0;
4331
4332   parent_a = widget_a;
4333   while (parent_a->priv->parent)
4334     {
4335       parent_a = parent_a->priv->parent;
4336       depth_a++;
4337     }
4338
4339   parent_b = widget_b;
4340   while (parent_b->priv->parent)
4341     {
4342       parent_b = parent_b->priv->parent;
4343       depth_b++;
4344     }
4345
4346   if (parent_a != parent_b)
4347     return NULL;
4348
4349   while (depth_a > depth_b)
4350     {
4351       widget_a = widget_a->priv->parent;
4352       depth_a--;
4353     }
4354
4355   while (depth_b > depth_a)
4356     {
4357       widget_b = widget_b->priv->parent;
4358       depth_b--;
4359     }
4360
4361   while (widget_a != widget_b)
4362     {
4363       widget_a = widget_a->priv->parent;
4364       widget_b = widget_b->priv->parent;
4365     }
4366
4367   return widget_a;
4368 }
4369
4370 /**
4371  * gtk_widget_translate_coordinates:
4372  * @src_widget:  a #GtkWidget
4373  * @dest_widget: a #GtkWidget
4374  * @src_x: X position relative to @src_widget
4375  * @src_y: Y position relative to @src_widget
4376  * @dest_x: (out): location to store X position relative to @dest_widget
4377  * @dest_y: (out): location to store Y position relative to @dest_widget
4378  *
4379  * Translate coordinates relative to @src_widget's allocation to coordinates
4380  * relative to @dest_widget's allocations. In order to perform this
4381  * operation, both widgets must be realized, and must share a common
4382  * toplevel.
4383  * 
4384  * Return value: %FALSE if either widget was not realized, or there
4385  *   was no common ancestor. In this case, nothing is stored in
4386  *   *@dest_x and *@dest_y. Otherwise %TRUE.
4387  **/
4388 gboolean
4389 gtk_widget_translate_coordinates (GtkWidget  *src_widget,
4390                                   GtkWidget  *dest_widget,
4391                                   gint        src_x,
4392                                   gint        src_y,
4393                                   gint       *dest_x,
4394                                   gint       *dest_y)
4395 {
4396   GtkWidgetPrivate *src_priv = src_widget->priv;
4397   GtkWidgetPrivate *dest_priv = dest_widget->priv;
4398   GtkWidget *ancestor;
4399   GdkWindow *window;
4400   GList *dest_list = NULL;
4401
4402   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4403   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4404
4405   ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4406   if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4407     return FALSE;
4408
4409   /* Translate from allocation relative to window relative */
4410   if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4411     {
4412       gint wx, wy;
4413       gdk_window_get_position (src_priv->window, &wx, &wy);
4414
4415       src_x -= wx - src_priv->allocation.x;
4416       src_y -= wy - src_priv->allocation.y;
4417     }
4418   else
4419     {
4420       src_x += src_priv->allocation.x;
4421       src_y += src_priv->allocation.y;
4422     }
4423
4424   /* Translate to the common ancestor */
4425   window = src_priv->window;
4426   while (window != ancestor->priv->window)
4427     {
4428       gdouble dx, dy;
4429
4430       gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4431
4432       src_x = dx;
4433       src_y = dy;
4434
4435       window = gdk_window_get_effective_parent (window);
4436
4437       if (!window)              /* Handle GtkHandleBox */
4438         return FALSE;
4439     }
4440
4441   /* And back */
4442   window = dest_priv->window;
4443   while (window != ancestor->priv->window)
4444     {
4445       dest_list = g_list_prepend (dest_list, window);
4446
4447       window = gdk_window_get_effective_parent (window);
4448
4449       if (!window)              /* Handle GtkHandleBox */
4450         {
4451           g_list_free (dest_list);
4452           return FALSE;
4453         }
4454     }
4455
4456   while (dest_list)
4457     {
4458       gdouble dx, dy;
4459
4460       gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4461
4462       src_x = dx;
4463       src_y = dy;
4464
4465       dest_list = g_list_remove (dest_list, dest_list->data);
4466     }
4467
4468   /* Translate from window relative to allocation relative */
4469   if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4470     {
4471       gint wx, wy;
4472       gdk_window_get_position (dest_priv->window, &wx, &wy);
4473
4474       src_x += wx - dest_priv->allocation.x;
4475       src_y += wy - dest_priv->allocation.y;
4476     }
4477   else
4478     {
4479       src_x -= dest_priv->allocation.x;
4480       src_y -= dest_priv->allocation.y;
4481     }
4482
4483   if (dest_x)
4484     *dest_x = src_x;
4485   if (dest_y)
4486     *dest_y = src_y;
4487
4488   return TRUE;
4489 }
4490
4491 static void
4492 gtk_widget_real_size_allocate (GtkWidget     *widget,
4493                                GtkAllocation *allocation)
4494 {
4495   GtkWidgetPrivate *priv = widget->priv;
4496
4497   priv->allocation = *allocation;
4498
4499   if (gtk_widget_get_realized (widget) &&
4500       gtk_widget_get_has_window (widget))
4501      {
4502         gdk_window_move_resize (priv->window,
4503                                 allocation->x, allocation->y,
4504                                 allocation->width, allocation->height);
4505      }
4506 }
4507
4508 static void
4509 get_span_inside_border (GtkWidget              *widget,
4510                         GtkAlign                align,
4511                         int                     start_pad,
4512                         int                     end_pad,
4513                         int                     allocated_outside_size,
4514                         int                     natural_inside_size,
4515                         int                    *coord_inside_p,
4516                         int                    *size_inside_p)
4517 {
4518   int inside_allocated;
4519   int content_size;
4520   int coord, size;
4521
4522   inside_allocated = allocated_outside_size - start_pad - end_pad;
4523
4524   content_size = natural_inside_size;
4525   if (content_size > inside_allocated)
4526     {
4527       /* didn't get full natural size */
4528       content_size = inside_allocated;
4529     }
4530
4531   coord = size = 0; /* silence compiler */
4532   switch (align)
4533     {
4534     case GTK_ALIGN_FILL:
4535       coord = start_pad;
4536       size = inside_allocated;
4537       break;
4538     case GTK_ALIGN_START:
4539       coord = start_pad;
4540       size = content_size;
4541       break;
4542     case GTK_ALIGN_END:
4543       coord = allocated_outside_size - end_pad - content_size;
4544       size = content_size;
4545       break;
4546     case GTK_ALIGN_CENTER:
4547       coord = start_pad + (inside_allocated - content_size) / 2;
4548       size = content_size;
4549       break;
4550     }
4551
4552   if (coord_inside_p)
4553     *coord_inside_p = coord;
4554
4555   if (size_inside_p)
4556     *size_inside_p = size;
4557 }
4558
4559 static void
4560 get_span_inside_border_horizontal (GtkWidget              *widget,
4561                                    const GtkWidgetAuxInfo *aux_info,
4562                                    int                     allocated_outside_width,
4563                                    int                     natural_inside_width,
4564                                    int                    *x_inside_p,
4565                                    int                    *width_inside_p)
4566 {
4567   get_span_inside_border (widget,
4568                           aux_info->halign,
4569                           aux_info->margin.left,
4570                           aux_info->margin.right,
4571                           allocated_outside_width,
4572                           natural_inside_width,
4573                           x_inside_p,
4574                           width_inside_p);
4575 }
4576
4577 static void
4578 get_span_inside_border_vertical (GtkWidget              *widget,
4579                                  const GtkWidgetAuxInfo *aux_info,
4580                                  int                     allocated_outside_height,
4581                                  int                     natural_inside_height,
4582                                  int                    *y_inside_p,
4583                                  int                    *height_inside_p)
4584 {
4585   get_span_inside_border (widget,
4586                           aux_info->valign,
4587                           aux_info->margin.top,
4588                           aux_info->margin.bottom,
4589                           allocated_outside_height,
4590                           natural_inside_height,
4591                           y_inside_p,
4592                           height_inside_p);
4593 }
4594
4595 static void
4596 gtk_widget_real_adjust_size_allocation (GtkWidget         *widget,
4597                                         GtkAllocation     *allocation)
4598 {
4599   const GtkWidgetAuxInfo *aux_info;
4600   GtkRequisition min, natural;
4601   int x, y, w, h;
4602
4603   aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4604
4605   gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &min, &natural);
4606
4607   get_span_inside_border_horizontal (widget,
4608                                      aux_info,
4609                                      allocation->width,
4610                                      natural.width,
4611                                      &x, &w);
4612   get_span_inside_border_vertical (widget,
4613                                    aux_info,
4614                                    allocation->height,
4615                                    natural.height,
4616                                    &y, &h);
4617
4618   allocation->x += x;
4619   allocation->y += y;
4620   allocation->width = w;
4621   allocation->height = h;
4622 }
4623
4624 static gboolean
4625 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4626                                     guint      signal_id)
4627 {
4628   GtkWidgetPrivate *priv = widget->priv;
4629
4630   /* widgets must be onscreen for accels to take effect */
4631   return gtk_widget_is_sensitive (widget) &&
4632          gtk_widget_is_drawable (widget) &&
4633          gdk_window_is_viewable (priv->window);
4634 }
4635
4636 /**
4637  * gtk_widget_can_activate_accel:
4638  * @widget: a #GtkWidget
4639  * @signal_id: the ID of a signal installed on @widget
4640  * 
4641  * Determines whether an accelerator that activates the signal
4642  * identified by @signal_id can currently be activated.
4643  * This is done by emitting the #GtkWidget::can-activate-accel
4644  * signal on @widget; if the signal isn't overridden by a
4645  * handler or in a derived widget, then the default check is
4646  * that the widget must be sensitive, and the widget and all
4647  * its ancestors mapped.
4648  *
4649  * Return value: %TRUE if the accelerator can be activated.
4650  *
4651  * Since: 2.4
4652  **/
4653 gboolean
4654 gtk_widget_can_activate_accel (GtkWidget *widget,
4655                                guint      signal_id)
4656 {
4657   gboolean can_activate = FALSE;
4658   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4659   g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4660   return can_activate;
4661 }
4662
4663 typedef struct {
4664   GClosure   closure;
4665   guint      signal_id;
4666 } AccelClosure;
4667
4668 static void
4669 closure_accel_activate (GClosure     *closure,
4670                         GValue       *return_value,
4671                         guint         n_param_values,
4672                         const GValue *param_values,
4673                         gpointer      invocation_hint,
4674                         gpointer      marshal_data)
4675 {
4676   AccelClosure *aclosure = (AccelClosure*) closure;
4677   gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4678
4679   if (can_activate)
4680     g_signal_emit (closure->data, aclosure->signal_id, 0);
4681
4682   /* whether accelerator was handled */
4683   g_value_set_boolean (return_value, can_activate);
4684 }
4685
4686 static void
4687 closures_destroy (gpointer data)
4688 {
4689   GSList *slist, *closures = data;
4690
4691   for (slist = closures; slist; slist = slist->next)
4692     {
4693       g_closure_invalidate (slist->data);
4694       g_closure_unref (slist->data);
4695     }
4696   g_slist_free (closures);
4697 }
4698
4699 static GClosure*
4700 widget_new_accel_closure (GtkWidget *widget,
4701                           guint      signal_id)
4702 {
4703   AccelClosure *aclosure;
4704   GClosure *closure = NULL;
4705   GSList *slist, *closures;
4706
4707   closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4708   for (slist = closures; slist; slist = slist->next)
4709     if (!gtk_accel_group_from_accel_closure (slist->data))
4710       {
4711         /* reuse this closure */
4712         closure = slist->data;
4713         break;
4714       }
4715   if (!closure)
4716     {
4717       closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4718       closures = g_slist_prepend (closures, g_closure_ref (closure));
4719       g_closure_sink (closure);
4720       g_closure_set_marshal (closure, closure_accel_activate);
4721     }
4722   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4723   
4724   aclosure = (AccelClosure*) closure;
4725   g_assert (closure->data == widget);
4726   g_assert (closure->marshal == closure_accel_activate);
4727   aclosure->signal_id = signal_id;
4728
4729   return closure;
4730 }
4731
4732 /**
4733  * gtk_widget_add_accelerator
4734  * @widget:       widget to install an accelerator on
4735  * @accel_signal: widget signal to emit on accelerator activation
4736  * @accel_group:  accel group for this widget, added to its toplevel
4737  * @accel_key:    GDK keyval of the accelerator
4738  * @accel_mods:   modifier key combination of the accelerator
4739  * @accel_flags:  flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4740  *
4741  * Installs an accelerator for this @widget in @accel_group that causes
4742  * @accel_signal to be emitted if the accelerator is activated.
4743  * The @accel_group needs to be added to the widget's toplevel via
4744  * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4745  * Accelerators added through this function are not user changeable during
4746  * runtime. If you want to support accelerators that can be changed by the
4747  * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4748  * gtk_menu_item_set_accel_path() instead.
4749  */
4750 void
4751 gtk_widget_add_accelerator (GtkWidget      *widget,
4752                             const gchar    *accel_signal,
4753                             GtkAccelGroup  *accel_group,
4754                             guint           accel_key,
4755                             GdkModifierType accel_mods,
4756                             GtkAccelFlags   accel_flags)
4757 {
4758   GClosure *closure;
4759   GSignalQuery query;
4760
4761   g_return_if_fail (GTK_IS_WIDGET (widget));
4762   g_return_if_fail (accel_signal != NULL);
4763   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4764
4765   g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4766   if (!query.signal_id ||
4767       !(query.signal_flags & G_SIGNAL_ACTION) ||
4768       query.return_type != G_TYPE_NONE ||
4769       query.n_params)
4770     {
4771       /* hmm, should be elaborate enough */
4772       g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4773                  G_OBJECT_TYPE_NAME (widget), accel_signal);
4774       return;
4775     }
4776
4777   closure = widget_new_accel_closure (widget, query.signal_id);
4778
4779   g_object_ref (widget);
4780
4781   /* install the accelerator. since we don't map this onto an accel_path,
4782    * the accelerator will automatically be locked.
4783    */
4784   gtk_accel_group_connect (accel_group,
4785                            accel_key,
4786                            accel_mods,
4787                            accel_flags | GTK_ACCEL_LOCKED,
4788                            closure);
4789
4790   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4791
4792   g_object_unref (widget);
4793 }
4794
4795 /**
4796  * gtk_widget_remove_accelerator:
4797  * @widget:       widget to install an accelerator on
4798  * @accel_group:  accel group for this widget
4799  * @accel_key:    GDK keyval of the accelerator
4800  * @accel_mods:   modifier key combination of the accelerator
4801  * @returns:      whether an accelerator was installed and could be removed
4802  *
4803  * Removes an accelerator from @widget, previously installed with
4804  * gtk_widget_add_accelerator().
4805  */
4806 gboolean
4807 gtk_widget_remove_accelerator (GtkWidget      *widget,
4808                                GtkAccelGroup  *accel_group,
4809                                guint           accel_key,
4810                                GdkModifierType accel_mods)
4811 {
4812   GtkAccelGroupEntry *ag_entry;
4813   GList *slist, *clist;
4814   guint n;
4815   
4816   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4817   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4818
4819   ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4820   clist = gtk_widget_list_accel_closures (widget);
4821   for (slist = clist; slist; slist = slist->next)
4822     {
4823       guint i;
4824
4825       for (i = 0; i < n; i++)
4826         if (slist->data == (gpointer) ag_entry[i].closure)
4827           {
4828             gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4829
4830             g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4831
4832             g_list_free (clist);
4833
4834             return is_removed;
4835           }
4836     }
4837   g_list_free (clist);
4838
4839   g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4840              accel_key, accel_mods, accel_group,
4841              G_OBJECT_TYPE_NAME (widget), widget);
4842
4843   return FALSE;
4844 }
4845
4846 /**
4847  * gtk_widget_list_accel_closures:
4848  * @widget:  widget to list accelerator closures for
4849  *
4850  * Lists the closures used by @widget for accelerator group connections
4851  * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4852  * The closures can be used to monitor accelerator changes on @widget,
4853  * by connecting to the @GtkAccelGroup::accel-changed signal of the
4854  * #GtkAccelGroup of a closure which can be found out with
4855  * gtk_accel_group_from_accel_closure().
4856  *
4857  * Return value: (transfer container) (element-type GClosure):
4858  *     a newly allocated #GList of closures
4859  */
4860 GList*
4861 gtk_widget_list_accel_closures (GtkWidget *widget)
4862 {
4863   GSList *slist;
4864   GList *clist = NULL;
4865
4866   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4867
4868   for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4869     if (gtk_accel_group_from_accel_closure (slist->data))
4870       clist = g_list_prepend (clist, slist->data);
4871   return clist;
4872 }
4873
4874 typedef struct {
4875   GQuark         path_quark;
4876   GtkAccelGroup *accel_group;
4877   GClosure      *closure;
4878 } AccelPath;
4879
4880 static void
4881 destroy_accel_path (gpointer data)
4882 {
4883   AccelPath *apath = data;
4884
4885   gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4886
4887   /* closures_destroy takes care of unrefing the closure */
4888   g_object_unref (apath->accel_group);
4889   
4890   g_slice_free (AccelPath, apath);
4891 }
4892
4893
4894 /**
4895  * gtk_widget_set_accel_path:
4896  * @widget: a #GtkWidget
4897  * @accel_path: (allow-none): path used to look up the accelerator
4898  * @accel_group: (allow-none): a #GtkAccelGroup.
4899  *
4900  * Given an accelerator group, @accel_group, and an accelerator path,
4901  * @accel_path, sets up an accelerator in @accel_group so whenever the
4902  * key binding that is defined for @accel_path is pressed, @widget
4903  * will be activated.  This removes any accelerators (for any
4904  * accelerator group) installed by previous calls to
4905  * gtk_widget_set_accel_path(). Associating accelerators with
4906  * paths allows them to be modified by the user and the modifications
4907  * to be saved for future use. (See gtk_accel_map_save().)
4908  *
4909  * This function is a low level function that would most likely
4910  * be used by a menu creation system like #GtkUIManager. If you
4911  * use #GtkUIManager, setting up accelerator paths will be done
4912  * automatically.
4913  *
4914  * Even when you you aren't using #GtkUIManager, if you only want to
4915  * set up accelerators on menu items gtk_menu_item_set_accel_path()
4916  * provides a somewhat more convenient interface.
4917  * 
4918  * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4919  * pass a static string, you can save some memory by interning it first with 
4920  * g_intern_static_string().
4921  **/
4922 void
4923 gtk_widget_set_accel_path (GtkWidget     *widget,
4924                            const gchar   *accel_path,
4925                            GtkAccelGroup *accel_group)
4926 {
4927   AccelPath *apath;
4928
4929   g_return_if_fail (GTK_IS_WIDGET (widget));
4930   g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4931
4932   if (accel_path)
4933     {
4934       g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4935       g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4936
4937       gtk_accel_map_add_entry (accel_path, 0, 0);
4938       apath = g_slice_new (AccelPath);
4939       apath->accel_group = g_object_ref (accel_group);
4940       apath->path_quark = g_quark_from_string (accel_path);
4941       apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4942     }
4943   else
4944     apath = NULL;
4945
4946   /* also removes possible old settings */
4947   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4948
4949   if (apath)
4950     gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4951
4952   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4953 }
4954
4955 const gchar*
4956 _gtk_widget_get_accel_path (GtkWidget *widget,
4957                             gboolean  *locked)
4958 {
4959   AccelPath *apath;
4960
4961   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4962
4963   apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4964   if (locked)
4965     *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4966   return apath ? g_quark_to_string (apath->path_quark) : NULL;
4967 }
4968
4969 /**
4970  * gtk_widget_mnemonic_activate:
4971  * @widget: a #GtkWidget
4972  * @group_cycling:  %TRUE if there are other widgets with the same mnemonic
4973  *
4974  * Emits the #GtkWidget::mnemonic-activate signal.
4975  * 
4976  * The default handler for this signal activates the @widget if
4977  * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4978  * is %TRUE.
4979  *
4980  * Returns: %TRUE if the signal has been handled
4981  */
4982 gboolean
4983 gtk_widget_mnemonic_activate (GtkWidget *widget,
4984                               gboolean   group_cycling)
4985 {
4986   gboolean handled;
4987   
4988   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4989
4990   group_cycling = group_cycling != FALSE;
4991   if (!gtk_widget_is_sensitive (widget))
4992     handled = TRUE;
4993   else
4994     g_signal_emit (widget,
4995                    widget_signals[MNEMONIC_ACTIVATE],
4996                    0,
4997                    group_cycling,
4998                    &handled);
4999   return handled;
5000 }
5001
5002 static gboolean
5003 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5004                                    gboolean   group_cycling)
5005 {
5006   if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5007     gtk_widget_activate (widget);
5008   else if (gtk_widget_get_can_focus (widget))
5009     gtk_widget_grab_focus (widget);
5010   else
5011     {
5012       g_warning ("widget `%s' isn't suitable for mnemonic activation",
5013                  G_OBJECT_TYPE_NAME (widget));
5014       gtk_widget_error_bell (widget);
5015     }
5016   return TRUE;
5017 }
5018
5019 static gboolean
5020 gtk_widget_real_key_press_event (GtkWidget         *widget,
5021                                  GdkEventKey       *event)
5022 {
5023   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5024 }
5025
5026 static gboolean
5027 gtk_widget_real_key_release_event (GtkWidget         *widget,
5028                                    GdkEventKey       *event)
5029 {
5030   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5031 }
5032
5033 static gboolean
5034 gtk_widget_real_focus_in_event (GtkWidget     *widget,
5035                                 GdkEventFocus *event)
5036 {
5037   gtk_widget_queue_shallow_draw (widget);
5038
5039   return FALSE;
5040 }
5041
5042 static gboolean
5043 gtk_widget_real_focus_out_event (GtkWidget     *widget,
5044                                  GdkEventFocus *event)
5045 {
5046   gtk_widget_queue_shallow_draw (widget);
5047
5048   return FALSE;
5049 }
5050
5051 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5052      (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5053
5054 /**
5055  * gtk_widget_event:
5056  * @widget: a #GtkWidget
5057  * @event: a #GdkEvent
5058  * 
5059  * Rarely-used function. This function is used to emit
5060  * the event signals on a widget (those signals should never
5061  * be emitted without using this function to do so).
5062  * If you want to synthesize an event though, don't use this function;
5063  * instead, use gtk_main_do_event() so the event will behave as if
5064  * it were in the event queue. Don't synthesize expose events; instead,
5065  * use gdk_window_invalidate_rect() to invalidate a region of the
5066  * window.
5067  * 
5068  * Return value: return from the event signal emission (%TRUE if 
5069  *               the event was handled)
5070  **/
5071 gboolean
5072 gtk_widget_event (GtkWidget *widget,
5073                   GdkEvent  *event)
5074 {
5075   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5076   g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5077
5078   if (event->type == GDK_EXPOSE)
5079     {
5080       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5081                  "the same effect, call gdk_window_invalidate_rect/region(), "
5082                  "followed by gdk_window_process_updates().");
5083       return TRUE;
5084     }
5085   
5086   return gtk_widget_event_internal (widget, event);
5087 }
5088
5089
5090 /**
5091  * gtk_widget_send_expose:
5092  * @widget: a #GtkWidget
5093  * @event: a expose #GdkEvent
5094  * 
5095  * Very rarely-used function. This function is used to emit
5096  * an expose event signals on a widget. This function is not
5097  * normally used directly. The only time it is used is when
5098  * propagating an expose event to a child %NO_WINDOW widget, and
5099  * that is normally done using gtk_container_propagate_expose().
5100  *
5101  * If you want to force an area of a window to be redrawn, 
5102  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5103  * To cause the redraw to be done immediately, follow that call
5104  * with a call to gdk_window_process_updates().
5105  * 
5106  * Return value: return from the event signal emission (%TRUE if 
5107  *               the event was handled)
5108  **/
5109 gint
5110 gtk_widget_send_expose (GtkWidget *widget,
5111                         GdkEvent  *event)
5112 {
5113   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5114   g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5115   g_return_val_if_fail (event != NULL, TRUE);
5116   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5117
5118   return gtk_widget_event_internal (widget, event);
5119 }
5120
5121 static gboolean
5122 event_window_is_still_viewable (GdkEvent *event)
5123 {
5124   /* Some programs, such as gnome-theme-manager, fake widgets
5125    * into exposing onto a pixmap by sending expose events with
5126    * event->window pointing to a pixmap
5127    */
5128   if (GDK_IS_PIXMAP (event->any.window))
5129     return event->type == GDK_EXPOSE;
5130   
5131   /* Check that we think the event's window is viewable before
5132    * delivering the event, to prevent suprises. We do this here
5133    * at the last moment, since the event may have been queued
5134    * up behind other events, held over a recursive main loop, etc.
5135    */
5136   switch (event->type)
5137     {
5138     case GDK_EXPOSE:
5139     case GDK_MOTION_NOTIFY:
5140     case GDK_BUTTON_PRESS:
5141     case GDK_2BUTTON_PRESS:
5142     case GDK_3BUTTON_PRESS:
5143     case GDK_KEY_PRESS:
5144     case GDK_ENTER_NOTIFY:
5145     case GDK_PROXIMITY_IN:
5146     case GDK_SCROLL:
5147       return event->any.window && gdk_window_is_viewable (event->any.window);
5148
5149 #if 0
5150     /* The following events are the second half of paired events;
5151      * we always deliver them to deal with widgets that clean up
5152      * on the second half.
5153      */
5154     case GDK_BUTTON_RELEASE:
5155     case GDK_KEY_RELEASE:
5156     case GDK_LEAVE_NOTIFY:
5157     case GDK_PROXIMITY_OUT:
5158 #endif      
5159       
5160     default:
5161       /* Remaining events would make sense on an not-viewable window,
5162        * or don't have an associated window.
5163        */
5164       return TRUE;
5165     }
5166 }
5167
5168 static gint
5169 gtk_widget_event_internal (GtkWidget *widget,
5170                            GdkEvent  *event)
5171 {
5172   gboolean return_val = FALSE;
5173
5174   /* We check only once for is-still-visible; if someone
5175    * hides the window in on of the signals on the widget,
5176    * they are responsible for returning TRUE to terminate
5177    * handling.
5178    */
5179   if (!event_window_is_still_viewable (event))
5180     return TRUE;
5181
5182   g_object_ref (widget);
5183
5184   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5185   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5186   if (!return_val)
5187     {
5188       gint signal_num;
5189
5190       switch (event->type)
5191         {
5192         case GDK_NOTHING:
5193           signal_num = -1;
5194           break;
5195         case GDK_BUTTON_PRESS:
5196         case GDK_2BUTTON_PRESS:
5197         case GDK_3BUTTON_PRESS:
5198           signal_num = BUTTON_PRESS_EVENT;
5199           break;
5200         case GDK_SCROLL:
5201           signal_num = SCROLL_EVENT;
5202           break;
5203         case GDK_BUTTON_RELEASE:
5204           signal_num = BUTTON_RELEASE_EVENT;
5205           break;
5206         case GDK_MOTION_NOTIFY:
5207           signal_num = MOTION_NOTIFY_EVENT;
5208           break;
5209         case GDK_DELETE:
5210           signal_num = DELETE_EVENT;
5211           break;
5212         case GDK_DESTROY:
5213           signal_num = DESTROY_EVENT;
5214           _gtk_tooltip_hide (widget);
5215           break;
5216         case GDK_KEY_PRESS:
5217           signal_num = KEY_PRESS_EVENT;
5218           break;
5219         case GDK_KEY_RELEASE:
5220           signal_num = KEY_RELEASE_EVENT;
5221           break;
5222         case GDK_ENTER_NOTIFY:
5223           signal_num = ENTER_NOTIFY_EVENT;
5224           break;
5225         case GDK_LEAVE_NOTIFY:
5226           signal_num = LEAVE_NOTIFY_EVENT;
5227           break;
5228         case GDK_FOCUS_CHANGE:
5229           signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5230           if (event->focus_change.in)
5231             _gtk_tooltip_focus_in (widget);
5232           else
5233             _gtk_tooltip_focus_out (widget);
5234           break;
5235         case GDK_CONFIGURE:
5236           signal_num = CONFIGURE_EVENT;
5237           break;
5238         case GDK_MAP:
5239           signal_num = MAP_EVENT;
5240           break;
5241         case GDK_UNMAP:
5242           signal_num = UNMAP_EVENT;
5243           break;
5244         case GDK_WINDOW_STATE:
5245           signal_num = WINDOW_STATE_EVENT;
5246           break;
5247         case GDK_PROPERTY_NOTIFY:
5248           signal_num = PROPERTY_NOTIFY_EVENT;
5249           break;
5250         case GDK_SELECTION_CLEAR:
5251           signal_num = SELECTION_CLEAR_EVENT;
5252           break;
5253         case GDK_SELECTION_REQUEST:
5254           signal_num = SELECTION_REQUEST_EVENT;
5255           break;
5256         case GDK_SELECTION_NOTIFY:
5257           signal_num = SELECTION_NOTIFY_EVENT;
5258           break;
5259         case GDK_PROXIMITY_IN:
5260           signal_num = PROXIMITY_IN_EVENT;
5261           break;
5262         case GDK_PROXIMITY_OUT:
5263           signal_num = PROXIMITY_OUT_EVENT;
5264           break;
5265         case GDK_NO_EXPOSE:
5266           signal_num = NO_EXPOSE_EVENT;
5267           break;
5268         case GDK_CLIENT_EVENT:
5269           signal_num = CLIENT_EVENT;
5270           break;
5271         case GDK_EXPOSE:
5272           signal_num = EXPOSE_EVENT;
5273           break;
5274         case GDK_VISIBILITY_NOTIFY:
5275           signal_num = VISIBILITY_NOTIFY_EVENT;
5276           break;
5277         case GDK_GRAB_BROKEN:
5278           signal_num = GRAB_BROKEN;
5279           break;
5280         case GDK_DAMAGE:
5281           signal_num = DAMAGE_EVENT;
5282           break;
5283         default:
5284           g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5285           signal_num = -1;
5286           break;
5287         }
5288       if (signal_num != -1)
5289         g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5290     }
5291   if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5292     g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5293   else
5294     return_val = TRUE;
5295
5296   g_object_unref (widget);
5297
5298   return return_val;
5299 }
5300
5301 /**
5302  * gtk_widget_activate:
5303  * @widget: a #GtkWidget that's activatable
5304  * 
5305  * For widgets that can be "activated" (buttons, menu items, etc.)
5306  * this function activates them. Activation is what happens when you
5307  * press Enter on a widget during key navigation. If @widget isn't 
5308  * activatable, the function returns %FALSE.
5309  * 
5310  * Return value: %TRUE if the widget was activatable
5311  **/
5312 gboolean
5313 gtk_widget_activate (GtkWidget *widget)
5314 {
5315   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5316   
5317   if (WIDGET_CLASS (widget)->activate_signal)
5318     {
5319       /* FIXME: we should eventually check the signals signature here */
5320       g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5321
5322       return TRUE;
5323     }
5324   else
5325     return FALSE;
5326 }
5327
5328 /**
5329  * gtk_widget_set_scroll_adjustments:
5330  * @widget: a #GtkWidget
5331  * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5332  * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5333  *
5334  * For widgets that support scrolling, sets the scroll adjustments and
5335  * returns %TRUE.  For widgets that don't support scrolling, does
5336  * nothing and returns %FALSE. Widgets that don't support scrolling
5337  * can be scrolled by placing them in a #GtkViewport, which does
5338  * support scrolling.
5339  * 
5340  * Return value: %TRUE if the widget supports scrolling
5341  **/
5342 gboolean
5343 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
5344                                    GtkAdjustment *hadjustment,
5345                                    GtkAdjustment *vadjustment)
5346 {
5347   guint signal_id;
5348   GSignalQuery query;
5349
5350   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5351
5352   if (hadjustment)
5353     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5354   if (vadjustment)
5355     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5356
5357   signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5358   if (!signal_id)
5359     return FALSE;
5360
5361   g_signal_query (signal_id, &query);
5362   if (!query.signal_id ||
5363       !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5364       query.return_type != G_TYPE_NONE ||
5365       query.n_params != 2 ||
5366       query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5367       query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5368     {
5369       g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5370                  G_OBJECT_TYPE_NAME (widget), query.signal_name);
5371       return FALSE;
5372     }
5373       
5374   g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5375   return TRUE;
5376 }
5377
5378 static void
5379 gtk_widget_reparent_subwindows (GtkWidget *widget,
5380                                 GdkWindow *new_window)
5381 {
5382   GtkWidgetPrivate *priv = widget->priv;
5383
5384   if (!gtk_widget_get_has_window (widget))
5385     {
5386       GList *children = gdk_window_get_children (priv->window);
5387       GList *tmp_list;
5388
5389       for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5390         {
5391           GdkWindow *window = tmp_list->data;
5392           gpointer child;
5393
5394           gdk_window_get_user_data (window, &child);
5395           while (child && child != widget)
5396             child = ((GtkWidget*) child)->priv->parent;
5397
5398           if (child)
5399             gdk_window_reparent (window, new_window, 0, 0);
5400         }
5401
5402       g_list_free (children);
5403     }
5404   else
5405    {
5406      GdkWindow *parent;
5407      GList *tmp_list, *children;
5408
5409      parent = gdk_window_get_parent (priv->window);
5410
5411      if (parent == NULL)
5412        gdk_window_reparent (priv->window, new_window, 0, 0);
5413      else
5414        {
5415          children = gdk_window_get_children (parent);
5416          
5417          for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5418            {
5419              GdkWindow *window = tmp_list->data;
5420              gpointer child;
5421
5422              gdk_window_get_user_data (window, &child);
5423
5424              if (child == widget)
5425                gdk_window_reparent (window, new_window, 0, 0);
5426            }
5427          
5428          g_list_free (children);
5429        }
5430    }
5431 }
5432
5433 static void
5434 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5435                                  gpointer   client_data)
5436 {
5437   GtkWidgetPrivate *priv = widget->priv;
5438
5439   g_assert (client_data != NULL);
5440   
5441   if (!gtk_widget_get_has_window (widget))
5442     {
5443       if (priv->window)
5444         g_object_unref (priv->window);
5445       priv->window = (GdkWindow*) client_data;
5446       if (priv->window)
5447         g_object_ref (priv->window);
5448
5449       if (GTK_IS_CONTAINER (widget))
5450         gtk_container_forall (GTK_CONTAINER (widget),
5451                               gtk_widget_reparent_fixup_child,
5452                               client_data);
5453     }
5454 }
5455
5456 /**
5457  * gtk_widget_reparent:
5458  * @widget: a #GtkWidget
5459  * @new_parent: a #GtkContainer to move the widget into
5460  *
5461  * Moves a widget from one #GtkContainer to another, handling reference
5462  * count issues to avoid destroying the widget.
5463  **/
5464 void
5465 gtk_widget_reparent (GtkWidget *widget,
5466                      GtkWidget *new_parent)
5467 {
5468   GtkWidgetPrivate *priv;
5469
5470   g_return_if_fail (GTK_IS_WIDGET (widget));
5471   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5472   priv = widget->priv;
5473   g_return_if_fail (priv->parent != NULL);
5474
5475   if (priv->parent != new_parent)
5476     {
5477       /* First try to see if we can get away without unrealizing
5478        * the widget as we reparent it. if so we set a flag so
5479        * that gtk_widget_unparent doesn't unrealize widget
5480        */
5481       if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5482         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5483       
5484       g_object_ref (widget);
5485       gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5486       gtk_container_add (GTK_CONTAINER (new_parent), widget);
5487       g_object_unref (widget);
5488       
5489       if (GTK_WIDGET_IN_REPARENT (widget))
5490         {
5491           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5492
5493           gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5494           gtk_widget_reparent_fixup_child (widget,
5495                                            gtk_widget_get_parent_window (widget));
5496         }
5497
5498       g_object_notify (G_OBJECT (widget), "parent");
5499     }
5500 }
5501
5502 /**
5503  * gtk_widget_intersect:
5504  * @widget: a #GtkWidget
5505  * @area: a rectangle
5506  * @intersection: rectangle to store intersection of @widget and @area
5507  * 
5508  * Computes the intersection of a @widget's area and @area, storing
5509  * the intersection in @intersection, and returns %TRUE if there was
5510  * an intersection.  @intersection may be %NULL if you're only
5511  * interested in whether there was an intersection.
5512  * 
5513  * Return value: %TRUE if there was an intersection
5514  **/
5515 gboolean
5516 gtk_widget_intersect (GtkWidget          *widget,
5517                       const GdkRectangle *area,
5518                       GdkRectangle       *intersection)
5519 {
5520   GtkWidgetPrivate *priv;
5521   GdkRectangle *dest;
5522   GdkRectangle tmp;
5523   gint return_val;
5524   
5525   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5526   g_return_val_if_fail (area != NULL, FALSE);
5527
5528   priv = widget->priv;
5529
5530   if (intersection)
5531     dest = intersection;
5532   else
5533     dest = &tmp;
5534   
5535   return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5536   
5537   if (return_val && intersection && gtk_widget_get_has_window (widget))
5538     {
5539       intersection->x -= priv->allocation.x;
5540       intersection->y -= priv->allocation.y;
5541     }
5542   
5543   return return_val;
5544 }
5545
5546 /**
5547  * gtk_widget_region_intersect:
5548  * @widget: a #GtkWidget
5549  * @region: a #cairo_region_t, in the same coordinate system as 
5550  *          @widget->allocation. That is, relative to @widget->window
5551  *          for %NO_WINDOW widgets; relative to the parent window
5552  *          of @widget->window for widgets with their own window.
5553  * @returns: A newly allocated region holding the intersection of @widget
5554  *           and @region. The coordinates of the return value are
5555  *           relative to @widget->window for %NO_WINDOW widgets, and
5556  *           relative to the parent window of @widget->window for
5557  *           widgets with their own window.
5558  * 
5559  * Computes the intersection of a @widget's area and @region, returning
5560  * the intersection. The result may be empty, use cairo_region_is_empty() to
5561  * check.
5562  **/
5563 cairo_region_t *
5564 gtk_widget_region_intersect (GtkWidget       *widget,
5565                              const cairo_region_t *region)
5566 {
5567   GdkRectangle rect;
5568   cairo_region_t *dest;
5569   
5570   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5571   g_return_val_if_fail (region != NULL, NULL);
5572
5573   gtk_widget_get_allocation (widget, &rect);
5574   
5575   dest = cairo_region_create_rectangle (&rect);
5576  
5577   cairo_region_intersect (dest, region);
5578
5579   return dest;
5580 }
5581
5582 /**
5583  * _gtk_widget_grab_notify:
5584  * @widget: a #GtkWidget
5585  * @was_grabbed: whether a grab is now in effect
5586  * 
5587  * Emits the #GtkWidget::grab-notify signal on @widget.
5588  * 
5589  * Since: 2.6
5590  **/
5591 void
5592 _gtk_widget_grab_notify (GtkWidget *widget,
5593                          gboolean   was_grabbed)
5594 {
5595   g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5596 }
5597
5598 /**
5599  * gtk_widget_grab_focus:
5600  * @widget: a #GtkWidget
5601  * 
5602  * Causes @widget to have the keyboard focus for the #GtkWindow it's
5603  * inside. @widget must be a focusable widget, such as a #GtkEntry;
5604  * something like #GtkFrame won't work.
5605  *
5606  * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5607  * gtk_widget_set_can_focus() to modify that flag.
5608  *
5609  * The widget also needs to be realized and mapped. This is indicated by the
5610  * related signals. Grabbing the focus immediately after creating the widget
5611  * will likely fail and cause critical warnings.
5612  **/
5613 void
5614 gtk_widget_grab_focus (GtkWidget *widget)
5615 {
5616   g_return_if_fail (GTK_IS_WIDGET (widget));
5617
5618   if (!gtk_widget_is_sensitive (widget))
5619     return;
5620   
5621   g_object_ref (widget);
5622   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5623   g_object_notify (G_OBJECT (widget), "has-focus");
5624   g_object_unref (widget);
5625 }
5626
5627 static void
5628 reset_focus_recurse (GtkWidget *widget,
5629                      gpointer   data)
5630 {
5631   if (GTK_IS_CONTAINER (widget))
5632     {
5633       GtkContainer *container;
5634
5635       container = GTK_CONTAINER (widget);
5636       gtk_container_set_focus_child (container, NULL);
5637
5638       gtk_container_foreach (container,
5639                              reset_focus_recurse,
5640                              NULL);
5641     }
5642 }
5643
5644 static void
5645 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5646 {
5647   if (gtk_widget_get_can_focus (focus_widget))
5648     {
5649       GtkWidget *toplevel;
5650       GtkWidget *widget;
5651       
5652       /* clear the current focus setting, break if the current widget
5653        * is the focus widget's parent, since containers above that will
5654        * be set by the next loop.
5655        */
5656       toplevel = gtk_widget_get_toplevel (focus_widget);
5657       if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5658         {
5659           widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5660
5661           if (widget == focus_widget)
5662             {
5663               /* We call _gtk_window_internal_set_focus() here so that the
5664                * toplevel window can request the focus if necessary.
5665                * This is needed when the toplevel is a GtkPlug
5666                */
5667               if (!gtk_widget_has_focus (widget))
5668                 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5669
5670               return;
5671             }
5672           
5673           if (widget)
5674             {
5675               while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5676                 {
5677                   widget = widget->priv->parent;
5678                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5679                 }
5680             }
5681         }
5682       else if (toplevel != focus_widget)
5683         {
5684           /* gtk_widget_grab_focus() operates on a tree without window...
5685            * actually, this is very questionable behaviour.
5686            */
5687           
5688           gtk_container_foreach (GTK_CONTAINER (toplevel),
5689                                  reset_focus_recurse,
5690                                  NULL);
5691         }
5692
5693       /* now propagate the new focus up the widget tree and finally
5694        * set it on the window
5695        */
5696       widget = focus_widget;
5697       while (widget->priv->parent)
5698         {
5699           gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5700           widget = widget->priv->parent;
5701         }
5702       if (GTK_IS_WINDOW (widget))
5703         _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5704     }
5705 }
5706
5707 static gboolean
5708 gtk_widget_real_query_tooltip (GtkWidget  *widget,
5709                                gint        x,
5710                                gint        y,
5711                                gboolean    keyboard_tip,
5712                                GtkTooltip *tooltip)
5713 {
5714   gchar *tooltip_markup;
5715   gboolean has_tooltip;
5716
5717   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5718   has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5719
5720   if (has_tooltip && tooltip_markup)
5721     {
5722       gtk_tooltip_set_markup (tooltip, tooltip_markup);
5723       return TRUE;
5724     }
5725
5726   return FALSE;
5727 }
5728
5729 static gboolean
5730 gtk_widget_real_show_help (GtkWidget        *widget,
5731                            GtkWidgetHelpType help_type)
5732 {
5733   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5734     {
5735       _gtk_tooltip_toggle_keyboard_mode (widget);
5736
5737       return TRUE;
5738     }
5739   else
5740     return FALSE;
5741 }
5742
5743 static gboolean
5744 gtk_widget_real_focus (GtkWidget         *widget,
5745                        GtkDirectionType   direction)
5746 {
5747   if (!gtk_widget_get_can_focus (widget))
5748     return FALSE;
5749   
5750   if (!gtk_widget_is_focus (widget))
5751     {
5752       gtk_widget_grab_focus (widget);
5753       return TRUE;
5754     }
5755   else
5756     return FALSE;
5757 }
5758
5759 static void
5760 gtk_widget_real_move_focus (GtkWidget         *widget,
5761                             GtkDirectionType   direction)
5762 {
5763   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5764
5765   if (GTK_IS_WINDOW (toplevel) &&
5766       GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5767     {
5768       GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5769                                                    direction);
5770     }
5771 }
5772
5773 static gboolean
5774 gtk_widget_real_keynav_failed (GtkWidget        *widget,
5775                                GtkDirectionType  direction)
5776 {
5777   gboolean cursor_only;
5778
5779   switch (direction)
5780     {
5781     case GTK_DIR_TAB_FORWARD:
5782     case GTK_DIR_TAB_BACKWARD:
5783       return FALSE;
5784
5785     case GTK_DIR_UP:
5786     case GTK_DIR_DOWN:
5787     case GTK_DIR_LEFT:
5788     case GTK_DIR_RIGHT:
5789       g_object_get (gtk_widget_get_settings (widget),
5790                     "gtk-keynav-cursor-only", &cursor_only,
5791                     NULL);
5792       if (cursor_only)
5793         return FALSE;
5794       break;
5795     }
5796
5797   gtk_widget_error_bell (widget);
5798
5799   return TRUE;
5800 }
5801
5802 /**
5803  * gtk_widget_set_can_focus:
5804  * @widget: a #GtkWidget
5805  * @can_focus: whether or not @widget can own the input focus.
5806  *
5807  * Specifies whether @widget can own the input focus. See
5808  * gtk_widget_grab_focus() for actually setting the input focus on a
5809  * widget.
5810  *
5811  * Since: 2.18
5812  **/
5813 void
5814 gtk_widget_set_can_focus (GtkWidget *widget,
5815                           gboolean   can_focus)
5816 {
5817   g_return_if_fail (GTK_IS_WIDGET (widget));
5818
5819   if (can_focus != gtk_widget_get_can_focus (widget))
5820     {
5821       if (can_focus)
5822         GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5823       else
5824         GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5825
5826       gtk_widget_queue_resize (widget);
5827       g_object_notify (G_OBJECT (widget), "can-focus");
5828     }
5829 }
5830
5831 /**
5832  * gtk_widget_get_can_focus:
5833  * @widget: a #GtkWidget
5834  *
5835  * Determines whether @widget can own the input focus. See
5836  * gtk_widget_set_can_focus().
5837  *
5838  * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5839  *
5840  * Since: 2.18
5841  **/
5842 gboolean
5843 gtk_widget_get_can_focus (GtkWidget *widget)
5844 {
5845   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5846
5847   return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5848 }
5849
5850 /**
5851  * gtk_widget_has_focus:
5852  * @widget: a #GtkWidget
5853  *
5854  * Determines if the widget has the global input focus. See
5855  * gtk_widget_is_focus() for the difference between having the global
5856  * input focus, and only having the focus within a toplevel.
5857  *
5858  * Return value: %TRUE if the widget has the global input focus.
5859  *
5860  * Since: 2.18
5861  **/
5862 gboolean
5863 gtk_widget_has_focus (GtkWidget *widget)
5864 {
5865   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5866
5867   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5868 }
5869
5870 /**
5871  * gtk_widget_is_focus:
5872  * @widget: a #GtkWidget
5873  * 
5874  * Determines if the widget is the focus widget within its
5875  * toplevel. (This does not mean that the %HAS_FOCUS flag is
5876  * necessarily set; %HAS_FOCUS will only be set if the
5877  * toplevel widget additionally has the global input focus.)
5878  * 
5879  * Return value: %TRUE if the widget is the focus widget.
5880  **/
5881 gboolean
5882 gtk_widget_is_focus (GtkWidget *widget)
5883 {
5884   GtkWidget *toplevel;
5885
5886   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5887
5888   toplevel = gtk_widget_get_toplevel (widget);
5889   
5890   if (GTK_IS_WINDOW (toplevel))
5891     return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
5892   else
5893     return FALSE;
5894 }
5895
5896 /**
5897  * gtk_widget_set_can_default:
5898  * @widget: a #GtkWidget
5899  * @can_default: whether or not @widget can be a default widget.
5900  *
5901  * Specifies whether @widget can be a default widget. See
5902  * gtk_widget_grab_default() for details about the meaning of
5903  * "default".
5904  *
5905  * Since: 2.18
5906  **/
5907 void
5908 gtk_widget_set_can_default (GtkWidget *widget,
5909                             gboolean   can_default)
5910 {
5911   g_return_if_fail (GTK_IS_WIDGET (widget));
5912
5913   if (can_default != gtk_widget_get_can_default (widget))
5914     {
5915       if (can_default)
5916         GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5917       else
5918         GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5919
5920       gtk_widget_queue_resize (widget);
5921       g_object_notify (G_OBJECT (widget), "can-default");
5922     }
5923 }
5924
5925 /**
5926  * gtk_widget_get_can_default:
5927  * @widget: a #GtkWidget
5928  *
5929  * Determines whether @widget can be a default widget. See
5930  * gtk_widget_set_can_default().
5931  *
5932  * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5933  *
5934  * Since: 2.18
5935  **/
5936 gboolean
5937 gtk_widget_get_can_default (GtkWidget *widget)
5938 {
5939   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5940
5941   return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5942 }
5943
5944 /**
5945  * gtk_widget_has_default:
5946  * @widget: a #GtkWidget
5947  *
5948  * Determines whether @widget is the current default widget within its
5949  * toplevel. See gtk_widget_set_can_default().
5950  *
5951  * Return value: %TRUE if @widget is the current default widget within
5952  *     its toplevel, %FALSE otherwise
5953  *
5954  * Since: 2.18
5955  */
5956 gboolean
5957 gtk_widget_has_default (GtkWidget *widget)
5958 {
5959   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5960
5961   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5962 }
5963
5964 void
5965 _gtk_widget_set_has_default (GtkWidget *widget,
5966                              gboolean   has_default)
5967 {
5968   if (has_default)
5969     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5970   else
5971     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5972 }
5973
5974 /**
5975  * gtk_widget_grab_default:
5976  * @widget: a #GtkWidget
5977  *
5978  * Causes @widget to become the default widget. @widget must have the
5979  * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5980  * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5981  * %TRUE)</literal>. The default widget is activated when 
5982  * the user presses Enter in a window. Default widgets must be 
5983  * activatable, that is, gtk_widget_activate() should affect them. Note
5984  * that #GtkEntry widgets require the "activates-default" property
5985  * set to %TRUE before they activate the default widget when Enter
5986  * is pressed and the #GtkEntry is focused.
5987  **/
5988 void
5989 gtk_widget_grab_default (GtkWidget *widget)
5990 {
5991   GtkWidget *window;
5992   
5993   g_return_if_fail (GTK_IS_WIDGET (widget));
5994   g_return_if_fail (gtk_widget_get_can_default (widget));
5995   
5996   window = gtk_widget_get_toplevel (widget);
5997   
5998   if (window && gtk_widget_is_toplevel (window))
5999     gtk_window_set_default (GTK_WINDOW (window), widget);
6000   else
6001     g_warning (G_STRLOC ": widget not within a GtkWindow");
6002 }
6003
6004 /**
6005  * gtk_widget_set_receives_default:
6006  * @widget: a #GtkWidget
6007  * @receives_default: whether or not @widget can be a default widget.
6008  *
6009  * Specifies whether @widget will be treated as the default widget
6010  * within its toplevel when it has the focus, even if another widget
6011  * is the default.
6012  *
6013  * See gtk_widget_grab_default() for details about the meaning of
6014  * "default".
6015  *
6016  * Since: 2.18
6017  **/
6018 void
6019 gtk_widget_set_receives_default (GtkWidget *widget,
6020                                  gboolean   receives_default)
6021 {
6022   g_return_if_fail (GTK_IS_WIDGET (widget));
6023
6024   if (receives_default != gtk_widget_get_receives_default (widget))
6025     {
6026       if (receives_default)
6027         GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6028       else
6029         GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6030
6031       g_object_notify (G_OBJECT (widget), "receives-default");
6032     }
6033 }
6034
6035 /**
6036  * gtk_widget_get_receives_default:
6037  * @widget: a #GtkWidget
6038  *
6039  * Determines whether @widget is alyways treated as default widget
6040  * withing its toplevel when it has the focus, even if another widget
6041  * is the default.
6042  *
6043  * See gtk_widget_set_receives_default().
6044  *
6045  * Return value: %TRUE if @widget acts as default widget when focussed,
6046  *               %FALSE otherwise
6047  *
6048  * Since: 2.18
6049  **/
6050 gboolean
6051 gtk_widget_get_receives_default (GtkWidget *widget)
6052 {
6053   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6054
6055   return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6056 }
6057
6058 /**
6059  * gtk_widget_has_grab:
6060  * @widget: a #GtkWidget
6061  *
6062  * Determines whether the widget is currently grabbing events, so it
6063  * is the only widget receiving input events (keyboard and mouse).
6064  *
6065  * See also gtk_grab_add().
6066  *
6067  * Return value: %TRUE if the widget is in the grab_widgets stack
6068  *
6069  * Since: 2.18
6070  **/
6071 gboolean
6072 gtk_widget_has_grab (GtkWidget *widget)
6073 {
6074   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6075
6076   return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6077 }
6078
6079 void
6080 _gtk_widget_set_has_grab (GtkWidget *widget,
6081                           gboolean   has_grab)
6082 {
6083   if (has_grab)
6084     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6085   else
6086     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6087 }
6088
6089 /**
6090  * gtk_widget_device_is_shadowed:
6091  * @widget: a #GtkWidget
6092  * @device: a #GdkDevice
6093  *
6094  * Returns %TRUE if @device has been shadowed by a GTK+
6095  * device grab on another widget, so it would stop sending
6096  * events to @widget. This may be used in the
6097  * #GtkWidget::grab-notify signal to check for specific
6098  * devices. See gtk_device_grab_add().
6099  *
6100  * Returns: %TRUE if there is an ongoing grab on @device
6101  *          by another #GtkWidget than @widget.
6102  *
6103  * Since: 3.0
6104  **/
6105 gboolean
6106 gtk_widget_device_is_shadowed (GtkWidget *widget,
6107                                GdkDevice *device)
6108 {
6109   GtkWindowGroup *group;
6110   GtkWidget *grab_widget, *toplevel;
6111
6112   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6113   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6114
6115   if (!gtk_widget_get_realized (widget))
6116     return TRUE;
6117
6118   toplevel = gtk_widget_get_toplevel (widget);
6119
6120   if (GTK_IS_WINDOW (toplevel))
6121     group = gtk_window_get_group (GTK_WINDOW (toplevel));
6122   else
6123     group = gtk_window_get_group (NULL);
6124
6125   grab_widget = gtk_window_group_get_current_device_grab (group, device);
6126
6127   /* Widget not inside the hierarchy of grab_widget */
6128   if (grab_widget &&
6129       widget != grab_widget &&
6130       !gtk_widget_is_ancestor (widget, grab_widget))
6131     return TRUE;
6132
6133   grab_widget = gtk_window_group_get_current_grab (group);
6134   if (grab_widget && widget != grab_widget &&
6135       !gtk_widget_is_ancestor (widget, grab_widget))
6136     return TRUE;
6137
6138   return FALSE;
6139 }
6140
6141 /**
6142  * gtk_widget_set_name:
6143  * @widget: a #GtkWidget
6144  * @name: name for the widget
6145  *
6146  * Widgets can be named, which allows you to refer to them from a
6147  * gtkrc file. You can apply a style to widgets with a particular name
6148  * in the gtkrc file. See the documentation for gtkrc files (on the
6149  * same page as the docs for #GtkRcStyle).
6150  * 
6151  * Note that widget names are separated by periods in paths (see 
6152  * gtk_widget_path()), so names with embedded periods may cause confusion.
6153  **/
6154 void
6155 gtk_widget_set_name (GtkWidget   *widget,
6156                      const gchar *name)
6157 {
6158   GtkWidgetPrivate *priv;
6159   gchar *new_name;
6160   
6161   g_return_if_fail (GTK_IS_WIDGET (widget));
6162
6163   priv = widget->priv;
6164
6165   new_name = g_strdup (name);
6166   g_free (priv->name);
6167   priv->name = new_name;
6168
6169   if (gtk_widget_has_rc_style (widget))
6170     gtk_widget_reset_rc_style (widget);
6171
6172   g_object_notify (G_OBJECT (widget), "name");
6173 }
6174
6175 /**
6176  * gtk_widget_get_name:
6177  * @widget: a #GtkWidget
6178  * 
6179  * Retrieves the name of a widget. See gtk_widget_set_name() for the
6180  * significance of widget names.
6181  * 
6182  * Return value: name of the widget. This string is owned by GTK+ and
6183  * should not be modified or freed
6184  **/
6185 G_CONST_RETURN gchar*
6186 gtk_widget_get_name (GtkWidget *widget)
6187 {
6188   GtkWidgetPrivate *priv;
6189
6190   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6191
6192   priv = widget->priv;
6193
6194   if (priv->name)
6195     return priv->name;
6196   return G_OBJECT_TYPE_NAME (widget);
6197 }
6198
6199 /**
6200  * gtk_widget_set_state:
6201  * @widget: a #GtkWidget
6202  * @state: new state for @widget
6203  *
6204  * This function is for use in widget implementations. Sets the state
6205  * of a widget (insensitive, prelighted, etc.) Usually you should set
6206  * the state using wrapper functions such as gtk_widget_set_sensitive().
6207  **/
6208 void
6209 gtk_widget_set_state (GtkWidget           *widget,
6210                       GtkStateType         state)
6211 {
6212   GtkWidgetPrivate *priv;
6213
6214   g_return_if_fail (GTK_IS_WIDGET (widget));
6215
6216   priv = widget->priv;
6217
6218   if (state == gtk_widget_get_state (widget))
6219     return;
6220
6221   if (state == GTK_STATE_INSENSITIVE)
6222     gtk_widget_set_sensitive (widget, FALSE);
6223   else
6224     {
6225       GtkStateData data;
6226
6227       data.state = state;
6228       data.state_restoration = FALSE;
6229       data.use_forall = FALSE;
6230       if (priv->parent)
6231         data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6232       else
6233         data.parent_sensitive = TRUE;
6234
6235       gtk_widget_propagate_state (widget, &data);
6236   
6237       if (gtk_widget_is_drawable (widget))
6238         gtk_widget_queue_draw (widget);
6239     }
6240 }
6241
6242 /**
6243  * gtk_widget_get_state:
6244  * @widget: a #GtkWidget
6245  *
6246  * Returns the widget's state. See gtk_widget_set_state().
6247  *
6248  * Returns: the state of @widget.
6249  *
6250  * Since: 2.18
6251  */
6252 GtkStateType
6253 gtk_widget_get_state (GtkWidget *widget)
6254 {
6255   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6256
6257   return widget->priv->state;
6258 }
6259
6260 /**
6261  * gtk_widget_set_visible:
6262  * @widget: a #GtkWidget
6263  * @visible: whether the widget should be shown or not
6264  *
6265  * Sets the visibility state of @widget. Note that setting this to
6266  * %TRUE doesn't mean the widget is actually viewable, see
6267  * gtk_widget_get_visible().
6268  *
6269  * This function simply calls gtk_widget_show() or gtk_widget_hide()
6270  * but is nicer to use when the visibility of the widget depends on
6271  * some condition.
6272  *
6273  * Since: 2.18
6274  **/
6275 void
6276 gtk_widget_set_visible (GtkWidget *widget,
6277                         gboolean   visible)
6278 {
6279   g_return_if_fail (GTK_IS_WIDGET (widget));
6280
6281   if (visible != gtk_widget_get_visible (widget))
6282     {
6283       if (visible)
6284         gtk_widget_show (widget);
6285       else
6286         gtk_widget_hide (widget);
6287     }
6288 }
6289
6290 /**
6291  * gtk_widget_get_visible:
6292  * @widget: a #GtkWidget
6293  *
6294  * Determines whether the widget is visible. Note that this doesn't
6295  * take into account whether the widget's parent is also visible
6296  * or the widget is obscured in any way.
6297  *
6298  * See gtk_widget_set_visible().
6299  *
6300  * Return value: %TRUE if the widget is visible
6301  *
6302  * Since: 2.18
6303  **/
6304 gboolean
6305 gtk_widget_get_visible (GtkWidget *widget)
6306 {
6307   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6308
6309   return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6310 }
6311
6312 /**
6313  * gtk_widget_set_has_window:
6314  * @widget: a #GtkWidget
6315  * @has_window: whether or not @widget has a window.
6316  *
6317  * Specifies whether @widget has a #GdkWindow of its own. Note that
6318  * all realized widgets have a non-%NULL "window" pointer
6319  * (gtk_widget_get_window() never returns a %NULL window when a widget
6320  * is realized), but for many of them it's actually the #GdkWindow of
6321  * one of its parent widgets. Widgets that do not create a %window for
6322  * themselves in GtkWidget::realize() must announce this by
6323  * calling this function with @has_window = %FALSE.
6324  *
6325  * This function should only be called by widget implementations,
6326  * and they should call it in their init() function.
6327  *
6328  * Since: 2.18
6329  **/
6330 void
6331 gtk_widget_set_has_window (GtkWidget *widget,
6332                            gboolean   has_window)
6333 {
6334   g_return_if_fail (GTK_IS_WIDGET (widget));
6335
6336   if (has_window)
6337     GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6338   else
6339     GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6340 }
6341
6342 /**
6343  * gtk_widget_get_has_window:
6344  * @widget: a #GtkWidget
6345  *
6346  * Determines whether @widget has a #GdkWindow of its own. See
6347  * gtk_widget_set_has_window().
6348  *
6349  * Return value: %TRUE if @widget has a window, %FALSE otherwise
6350  *
6351  * Since: 2.18
6352  **/
6353 gboolean
6354 gtk_widget_get_has_window (GtkWidget *widget)
6355 {
6356   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6357
6358   return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6359 }
6360
6361 /**
6362  * gtk_widget_is_toplevel:
6363  * @widget: a #GtkWidget
6364  *
6365  * Determines whether @widget is a toplevel widget. Currently only
6366  * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6367  * widgets have no parent widget.
6368  *
6369  * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6370  *
6371  * Since: 2.18
6372  **/
6373 gboolean
6374 gtk_widget_is_toplevel (GtkWidget *widget)
6375 {
6376   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6377
6378   return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6379 }
6380
6381 void
6382 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6383                              gboolean   is_toplevel)
6384 {
6385   if (is_toplevel)
6386     GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6387   else
6388     GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6389 }
6390
6391 /**
6392  * gtk_widget_is_drawable:
6393  * @widget: a #GtkWidget
6394  *
6395  * Determines whether @widget can be drawn to. A widget can be drawn
6396  * to if it is mapped and visible.
6397  *
6398  * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6399  *
6400  * Since: 2.18
6401  **/
6402 gboolean
6403 gtk_widget_is_drawable (GtkWidget *widget)
6404 {
6405   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6406
6407   return (gtk_widget_get_visible (widget) &&
6408           gtk_widget_get_mapped (widget));
6409 }
6410
6411 /**
6412  * gtk_widget_get_realized:
6413  * @widget: a #GtkWidget
6414  *
6415  * Determines whether @widget is realized.
6416  *
6417  * Return value: %TRUE if @widget is realized, %FALSE otherwise
6418  *
6419  * Since: 2.20
6420  **/
6421 gboolean
6422 gtk_widget_get_realized (GtkWidget *widget)
6423 {
6424   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6425
6426   return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6427 }
6428
6429 /**
6430  * gtk_widget_set_realized:
6431  * @widget: a #GtkWidget
6432  * @realized: %TRUE to mark the widget as realized
6433  *
6434  * Marks the widget as being realized.
6435  *
6436  * This function should only ever be called in a derived widget's
6437  * "realize" or "unrealize" implementation.
6438  *
6439  * Since: 2.20
6440  */
6441 void
6442 gtk_widget_set_realized (GtkWidget *widget,
6443                          gboolean   realized)
6444 {
6445   g_return_if_fail (GTK_IS_WIDGET (widget));
6446
6447   if (realized)
6448     GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6449   else
6450     GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6451 }
6452
6453 /**
6454  * gtk_widget_get_mapped:
6455  * @widget: a #GtkWidget
6456  *
6457  * Whether the widget is mapped.
6458  *
6459  * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6460  *
6461  * Since: 2.20
6462  */
6463 gboolean
6464 gtk_widget_get_mapped (GtkWidget *widget)
6465 {
6466   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6467
6468   return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6469 }
6470
6471 /**
6472  * gtk_widget_set_mapped:
6473  * @widget: a #GtkWidget
6474  * @mapped: %TRUE to mark the widget as mapped
6475  *
6476  * Marks the widget as being realized.
6477  *
6478  * This function should only ever be called in a derived widget's
6479  * "map" or "unmap" implementation.
6480  *
6481  * Since: 2.20
6482  */
6483 void
6484 gtk_widget_set_mapped (GtkWidget *widget,
6485                        gboolean   mapped)
6486 {
6487   g_return_if_fail (GTK_IS_WIDGET (widget));
6488
6489   if (mapped)
6490     GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6491   else
6492     GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6493 }
6494
6495 /**
6496  * gtk_widget_set_app_paintable:
6497  * @widget: a #GtkWidget
6498  * @app_paintable: %TRUE if the application will paint on the widget
6499  *
6500  * Sets whether the application intends to draw on the widget in
6501  * an #GtkWidget::expose-event handler. 
6502  *
6503  * This is a hint to the widget and does not affect the behavior of 
6504  * the GTK+ core; many widgets ignore this flag entirely. For widgets 
6505  * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow, 
6506  * the effect is to suppress default themed drawing of the widget's 
6507  * background. (Children of the widget will still be drawn.) The application 
6508  * is then entirely responsible for drawing the widget background.
6509  *
6510  * Note that the background is still drawn when the widget is mapped.
6511  **/
6512 void
6513 gtk_widget_set_app_paintable (GtkWidget *widget,
6514                               gboolean   app_paintable)
6515 {
6516   g_return_if_fail (GTK_IS_WIDGET (widget));
6517
6518   app_paintable = (app_paintable != FALSE);
6519
6520   if (gtk_widget_get_app_paintable (widget) != app_paintable)
6521     {
6522       if (app_paintable)
6523         GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6524       else
6525         GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6526
6527       if (gtk_widget_is_drawable (widget))
6528         gtk_widget_queue_draw (widget);
6529
6530       g_object_notify (G_OBJECT (widget), "app-paintable");
6531     }
6532 }
6533
6534 /**
6535  * gtk_widget_get_app_paintable:
6536  * @widget: a #GtkWidget
6537  *
6538  * Determines whether the application intends to draw on the widget in
6539  * an #GtkWidget::expose-event handler.
6540  *
6541  * See gtk_widget_set_app_paintable()
6542  *
6543  * Return value: %TRUE if the widget is app paintable
6544  *
6545  * Since: 2.18
6546  **/
6547 gboolean
6548 gtk_widget_get_app_paintable (GtkWidget *widget)
6549 {
6550   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6551
6552   return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6553 }
6554
6555 /**
6556  * gtk_widget_set_double_buffered:
6557  * @widget: a #GtkWidget
6558  * @double_buffered: %TRUE to double-buffer a widget
6559  *
6560  * Widgets are double buffered by default; you can use this function
6561  * to turn off the buffering. "Double buffered" simply means that
6562  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6563  * automatically around expose events sent to the
6564  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6565  * window to an offscreen buffer, and gdk_window_end_paint() draws the
6566  * buffer to the screen. The result is that users see the window
6567  * update in one smooth step, and don't see individual graphics
6568  * primitives being rendered.
6569  *
6570  * In very simple terms, double buffered widgets don't flicker,
6571  * so you would only use this function to turn off double buffering
6572  * if you had special needs and really knew what you were doing.
6573  * 
6574  * Note: if you turn off double-buffering, you have to handle
6575  * expose events, since even the clearing to the background color or 
6576  * pixmap will not happen automatically (as it is done in 
6577  * gdk_window_begin_paint()).
6578  **/
6579 void
6580 gtk_widget_set_double_buffered (GtkWidget *widget,
6581                                 gboolean   double_buffered)
6582 {
6583   g_return_if_fail (GTK_IS_WIDGET (widget));
6584
6585   double_buffered = (double_buffered != FALSE);
6586
6587   if (double_buffered != gtk_widget_get_double_buffered (widget))
6588     {
6589       if (double_buffered)
6590         GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6591       else
6592         GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6593
6594       g_object_notify (G_OBJECT (widget), "double-buffered");
6595     }
6596 }
6597
6598 /**
6599  * gtk_widget_get_double_buffered:
6600  * @widget: a #GtkWidget
6601  *
6602  * Determines whether the widget is double buffered.
6603  *
6604  * See gtk_widget_set_double_buffered()
6605  *
6606  * Return value: %TRUE if the widget is double buffered
6607  *
6608  * Since: 2.18
6609  **/
6610 gboolean
6611 gtk_widget_get_double_buffered (GtkWidget *widget)
6612 {
6613   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6614
6615   return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6616 }
6617
6618 /**
6619  * gtk_widget_set_redraw_on_allocate:
6620  * @widget: a #GtkWidget
6621  * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6622  *   when it is allocated to a new size. Otherwise, only the
6623  *   new portion of the widget will be redrawn.
6624  *
6625  * Sets whether the entire widget is queued for drawing when its size 
6626  * allocation changes. By default, this setting is %TRUE and
6627  * the entire widget is redrawn on every size change. If your widget
6628  * leaves the upper left unchanged when made bigger, turning this
6629  * setting off will improve performance.
6630
6631  * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6632  * off all allocation on resizing: the widget will not even redraw if
6633  * its position changes; this is to allow containers that don't draw
6634  * anything to avoid excess invalidations. If you set this flag on a
6635  * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window, 
6636  * you are responsible for invalidating both the old and new allocation 
6637  * of the widget when the widget is moved and responsible for invalidating
6638  * regions newly when the widget increases size.
6639  **/
6640 void
6641 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6642                                    gboolean   redraw_on_allocate)
6643 {
6644   g_return_if_fail (GTK_IS_WIDGET (widget));
6645
6646   if (redraw_on_allocate)
6647     GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6648   else
6649     GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6650 }
6651
6652 /**
6653  * gtk_widget_set_sensitive:
6654  * @widget: a #GtkWidget
6655  * @sensitive: %TRUE to make the widget sensitive
6656  *
6657  * Sets the sensitivity of a widget. A widget is sensitive if the user
6658  * can interact with it. Insensitive widgets are "grayed out" and the
6659  * user can't interact with them. Insensitive widgets are known as
6660  * "inactive", "disabled", or "ghosted" in some other toolkits.
6661  **/
6662 void
6663 gtk_widget_set_sensitive (GtkWidget *widget,
6664                           gboolean   sensitive)
6665 {
6666   GtkWidgetPrivate *priv;
6667   GtkStateData data;
6668
6669   g_return_if_fail (GTK_IS_WIDGET (widget));
6670
6671   priv = widget->priv;
6672
6673   sensitive = (sensitive != FALSE);
6674
6675   if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6676     return;
6677
6678   if (sensitive)
6679     {
6680       GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6681       data.state = priv->saved_state;
6682     }
6683   else
6684     {
6685       GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6686       data.state = gtk_widget_get_state (widget);
6687     }
6688   data.state_restoration = TRUE;
6689   data.use_forall = TRUE;
6690
6691   if (priv->parent)
6692     data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6693   else
6694     data.parent_sensitive = TRUE;
6695
6696   gtk_widget_propagate_state (widget, &data);
6697   if (gtk_widget_is_drawable (widget))
6698     gtk_widget_queue_draw (widget);
6699
6700   g_object_notify (G_OBJECT (widget), "sensitive");
6701 }
6702
6703 /**
6704  * gtk_widget_get_sensitive:
6705  * @widget: a #GtkWidget
6706  *
6707  * Returns the widget's sensitivity (in the sense of returning
6708  * the value that has been set using gtk_widget_set_sensitive()).
6709  *
6710  * The effective sensitivity of a widget is however determined by both its
6711  * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6712  *
6713  * Returns: %TRUE if the widget is sensitive
6714  *
6715  * Since: 2.18
6716  */
6717 gboolean
6718 gtk_widget_get_sensitive (GtkWidget *widget)
6719 {
6720   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6721
6722   return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6723 }
6724
6725 /**
6726  * gtk_widget_is_sensitive:
6727  * @widget: a #GtkWidget
6728  *
6729  * Returns the widget's effective sensitivity, which means
6730  * it is sensitive itself and also its parent widget is sensntive
6731  *
6732  * Returns: %TRUE if the widget is effectively sensitive
6733  *
6734  * Since: 2.18
6735  */
6736 gboolean
6737 gtk_widget_is_sensitive (GtkWidget *widget)
6738 {
6739   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6740
6741   return (gtk_widget_get_sensitive (widget) &&
6742           (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6743 }
6744
6745 /**
6746  * gtk_widget_set_parent:
6747  * @widget: a #GtkWidget
6748  * @parent: parent container
6749  *
6750  * This function is useful only when implementing subclasses of 
6751  * #GtkContainer.
6752  * Sets the container as the parent of @widget, and takes care of
6753  * some details such as updating the state and style of the child
6754  * to reflect its new location. The opposite function is
6755  * gtk_widget_unparent().
6756  **/
6757 void
6758 gtk_widget_set_parent (GtkWidget *widget,
6759                        GtkWidget *parent)
6760 {
6761   GtkWidgetPrivate *priv;
6762   GtkStateData data;
6763   
6764   g_return_if_fail (GTK_IS_WIDGET (widget));
6765   g_return_if_fail (GTK_IS_WIDGET (parent));
6766   g_return_if_fail (widget != parent);
6767
6768   priv = widget->priv;
6769
6770   if (priv->parent != NULL)
6771     {
6772       g_warning ("Can't set a parent on widget which has a parent\n");
6773       return;
6774     }
6775   if (gtk_widget_is_toplevel (widget))
6776     {
6777       g_warning ("Can't set a parent on a toplevel widget\n");
6778       return;
6779     }
6780
6781   /* keep this function in sync with gtk_menu_attach_to_widget()
6782    */
6783
6784   g_object_ref_sink (widget);
6785   priv->parent = parent;
6786
6787   if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6788     data.state = gtk_widget_get_state (parent);
6789   else
6790     data.state = gtk_widget_get_state (widget);
6791   data.state_restoration = FALSE;
6792   data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6793   data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6794
6795   gtk_widget_propagate_state (widget, &data);
6796   
6797   gtk_widget_reset_rc_styles (widget);
6798
6799   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6800   if (GTK_WIDGET_ANCHORED (priv->parent))
6801     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6802   g_object_notify (G_OBJECT (widget), "parent");
6803
6804   /* Enforce realized/mapped invariants
6805    */
6806   if (gtk_widget_get_realized (priv->parent))
6807     gtk_widget_realize (widget);
6808
6809   if (gtk_widget_get_visible (priv->parent) &&
6810       gtk_widget_get_visible (widget))
6811     {
6812       if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6813           gtk_widget_get_mapped (priv->parent))
6814         gtk_widget_map (widget);
6815
6816       gtk_widget_queue_resize (widget);
6817     }
6818 }
6819
6820 /**
6821  * gtk_widget_get_parent:
6822  * @widget: a #GtkWidget
6823  *
6824  * Returns the parent container of @widget.
6825  *
6826  * Return value: (transfer none): the parent container of @widget, or %NULL
6827  **/
6828 GtkWidget *
6829 gtk_widget_get_parent (GtkWidget *widget)
6830 {
6831   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6832
6833   return widget->priv->parent;
6834 }
6835
6836 /*****************************************
6837  * Widget styles
6838  * see docs/styles.txt
6839  *****************************************/
6840
6841 /**
6842  * gtk_widget_style_attach:
6843  * @widget: a #GtkWidget
6844  *
6845  * This function attaches the widget's #GtkStyle to the widget's
6846  * #GdkWindow. It is a replacement for
6847  *
6848  * <programlisting>
6849  * widget->style = gtk_style_attach (widget->style, widget->window);
6850  * </programlisting>
6851  *
6852  * and should only ever be called in a derived widget's "realize"
6853  * implementation which does not chain up to its parent class'
6854  * "realize" implementation, because one of the parent classes
6855  * (finally #GtkWidget) would attach the style itself.
6856  *
6857  * Since: 2.20
6858  **/
6859 void
6860 gtk_widget_style_attach (GtkWidget *widget)
6861 {
6862   GtkWidgetPrivate *priv;
6863
6864   g_return_if_fail (GTK_IS_WIDGET (widget));
6865   g_return_if_fail (gtk_widget_get_realized (widget));
6866
6867   priv = widget->priv;
6868
6869   priv->style = gtk_style_attach (priv->style, priv->window);
6870 }
6871
6872 /**
6873  * gtk_widget_has_rc_style:
6874  * @widget: a #GtkWidget
6875  *
6876  * Determines if the widget style has been looked up through the rc mechanism.
6877  *
6878  * Returns: %TRUE if the widget has been looked up through the rc
6879  *   mechanism, %FALSE otherwise.
6880  *
6881  * Since: 2.20
6882  **/
6883 gboolean
6884 gtk_widget_has_rc_style (GtkWidget *widget)
6885 {
6886   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6887
6888   return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6889 }
6890
6891 /**
6892  * gtk_widget_set_style:
6893  * @widget: a #GtkWidget
6894  * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6895  *         gtk_widget_set_style() and go back to the default style
6896  *
6897  * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6898  * want to use this function; it interacts badly with themes, because
6899  * themes work by replacing the #GtkStyle. Instead, use
6900  * gtk_widget_modify_style().
6901  **/
6902 void
6903 gtk_widget_set_style (GtkWidget *widget,
6904                       GtkStyle  *style)
6905 {
6906   g_return_if_fail (GTK_IS_WIDGET (widget));
6907
6908   if (style)
6909     {
6910       gboolean initial_emission;
6911
6912       initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6913       
6914       GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6915       GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6916       
6917       gtk_widget_set_style_internal (widget, style, initial_emission);
6918     }
6919   else
6920     {
6921       if (GTK_WIDGET_USER_STYLE (widget))
6922         gtk_widget_reset_rc_style (widget);
6923     }
6924 }
6925
6926 /**
6927  * gtk_widget_ensure_style:
6928  * @widget: a #GtkWidget
6929  *
6930  * Ensures that @widget has a style (@widget->style). Not a very useful
6931  * function; most of the time, if you want the style, the widget is
6932  * realized, and realized widgets are guaranteed to have a style
6933  * already.
6934  **/
6935 void
6936 gtk_widget_ensure_style (GtkWidget *widget)
6937 {
6938   g_return_if_fail (GTK_IS_WIDGET (widget));
6939
6940   if (!GTK_WIDGET_USER_STYLE (widget) &&
6941       !gtk_widget_has_rc_style (widget))
6942     gtk_widget_reset_rc_style (widget);
6943 }
6944
6945 /* Look up the RC style for this widget, unsetting any user style that
6946  * may be in effect currently
6947  **/
6948 static void
6949 gtk_widget_reset_rc_style (GtkWidget *widget)
6950 {
6951   GtkWidgetPrivate *priv = widget->priv;
6952   GtkStyle *new_style = NULL;
6953   gboolean initial_emission;
6954   
6955   initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6956
6957   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6958   GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6959   
6960   if (gtk_widget_has_screen (widget))
6961     new_style = gtk_rc_get_style (widget);
6962   if (!new_style)
6963     new_style = gtk_widget_get_default_style ();
6964
6965   if (initial_emission || new_style != priv->style)
6966     gtk_widget_set_style_internal (widget, new_style, initial_emission);
6967 }
6968
6969 /**
6970  * gtk_widget_get_style:
6971  * @widget: a #GtkWidget
6972  * 
6973  * Simply an accessor function that returns @widget->style.
6974  *
6975  * Return value: (transfer none): the widget's #GtkStyle
6976  **/
6977 GtkStyle*
6978 gtk_widget_get_style (GtkWidget *widget)
6979 {
6980   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6981
6982   return widget->priv->style;
6983 }
6984
6985 /**
6986  * gtk_widget_modify_style:
6987  * @widget: a #GtkWidget
6988  * @style: the #GtkRcStyle holding the style modifications
6989  * 
6990  * Modifies style values on the widget. Modifications made using this
6991  * technique take precedence over style values set via an RC file,
6992  * however, they will be overriden if a style is explicitely set on
6993  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6994  * is designed so each field can either be set or unset, so it is
6995  * possible, using this function, to modify some style values and
6996  * leave the others unchanged.
6997  *
6998  * Note that modifications made with this function are not cumulative
6999  * with previous calls to gtk_widget_modify_style() or with such
7000  * functions as gtk_widget_modify_fg(). If you wish to retain
7001  * previous values, you must first call gtk_widget_get_modifier_style(),
7002  * make your modifications to the returned style, then call
7003  * gtk_widget_modify_style() with that style. On the other hand,
7004  * if you first call gtk_widget_modify_style(), subsequent calls
7005  * to such functions gtk_widget_modify_fg() will have a cumulative
7006  * effect with the initial modifications.
7007  **/
7008 void       
7009 gtk_widget_modify_style (GtkWidget      *widget,
7010                          GtkRcStyle     *style)
7011 {
7012   g_return_if_fail (GTK_IS_WIDGET (widget));
7013   g_return_if_fail (GTK_IS_RC_STYLE (style));
7014   
7015   g_object_set_qdata_full (G_OBJECT (widget),
7016                            quark_rc_style,
7017                            gtk_rc_style_copy (style),
7018                            (GDestroyNotify) g_object_unref);
7019
7020   /* note that "style" may be invalid here if it was the old
7021    * modifier style and the only reference was our own.
7022    */
7023   
7024   if (gtk_widget_has_rc_style (widget))
7025     gtk_widget_reset_rc_style (widget);
7026 }
7027
7028 /**
7029  * gtk_widget_get_modifier_style:
7030  * @widget: a #GtkWidget
7031  * 
7032  * Returns the current modifier style for the widget. (As set by
7033  * gtk_widget_modify_style().) If no style has previously set, a new
7034  * #GtkRcStyle will be created with all values unset, and set as the
7035  * modifier style for the widget. If you make changes to this rc
7036  * style, you must call gtk_widget_modify_style(), passing in the
7037  * returned rc style, to make sure that your changes take effect.
7038  *
7039  * Caution: passing the style back to gtk_widget_modify_style() will
7040  * normally end up destroying it, because gtk_widget_modify_style() copies
7041  * the passed-in style and sets the copy as the new modifier style,
7042  * thus dropping any reference to the old modifier style. Add a reference
7043  * to the modifier style if you want to keep it alive.
7044  *
7045  * Return value: (transfer none): the modifier style for the widget. This rc style is
7046  *   owned by the widget. If you want to keep a pointer to value this
7047  *   around, you must add a refcount using g_object_ref().
7048  **/
7049 GtkRcStyle *
7050 gtk_widget_get_modifier_style (GtkWidget      *widget)
7051 {
7052   GtkRcStyle *rc_style;
7053   
7054   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7055
7056   rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7057
7058   if (!rc_style)
7059     {
7060       rc_style = gtk_rc_style_new ();
7061       g_object_set_qdata_full (G_OBJECT (widget),
7062                                quark_rc_style,
7063                                rc_style,
7064                                (GDestroyNotify) g_object_unref);
7065     }
7066
7067   return rc_style;
7068 }
7069
7070 static void
7071 gtk_widget_modify_color_component (GtkWidget      *widget,
7072                                    GtkRcFlags      component,
7073                                    GtkStateType    state,
7074                                    const GdkColor *color)
7075 {
7076   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
7077
7078   if (color)
7079     {
7080       switch (component)
7081         {
7082         case GTK_RC_FG:
7083           rc_style->fg[state] = *color;
7084           break;
7085         case GTK_RC_BG:
7086           rc_style->bg[state] = *color;
7087           break;
7088         case GTK_RC_TEXT:
7089           rc_style->text[state] = *color;
7090           break;
7091         case GTK_RC_BASE:
7092           rc_style->base[state] = *color;
7093           break;
7094         default:
7095           g_assert_not_reached();
7096         }
7097       
7098       rc_style->color_flags[state] |= component;
7099     }
7100   else
7101     rc_style->color_flags[state] &= ~component;
7102
7103   gtk_widget_modify_style (widget, rc_style);
7104 }
7105
7106 /**
7107  * gtk_widget_modify_symbolic_color:
7108  * @widget: a #GtkWidget
7109  * @name: the name of the symbolic color to modify
7110  * @color: (allow-none): the color to assign (does not need to be allocated),
7111  *         or %NULL to undo the effect of previous calls to
7112  *         of gtk_widget_modify_symbolic_color().
7113  *
7114  * Sets a symbolic color for a widget.
7115  * All other style values are left untouched. See also
7116  * gtk_widget_modify_style().
7117  *
7118  * Since: 3.0
7119  **/
7120 void
7121 gtk_widget_modify_symbolic_color (GtkWidget      *widget,
7122                                   const gchar    *name,
7123                                   const GdkColor *color)
7124 {
7125   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7126
7127   _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7128
7129   gtk_widget_modify_style (widget, rc_style);
7130 }
7131
7132 /**
7133  * gtk_widget_modify_fg:
7134  * @widget: a #GtkWidget
7135  * @state: the state for which to set the foreground color
7136  * @color: (allow-none): the color to assign (does not need to be allocated),
7137  *         or %NULL to undo the effect of previous calls to
7138  *         of gtk_widget_modify_fg().
7139  *
7140  * Sets the foreground color for a widget in a particular state.
7141  * All other style values are left untouched. See also
7142  * gtk_widget_modify_style().
7143  **/
7144 void
7145 gtk_widget_modify_fg (GtkWidget      *widget,
7146                       GtkStateType    state,
7147                       const GdkColor *color)
7148 {
7149   g_return_if_fail (GTK_IS_WIDGET (widget));
7150   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7151
7152   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7153 }
7154
7155 /**
7156  * gtk_widget_modify_bg:
7157  * @widget: a #GtkWidget
7158  * @state: the state for which to set the background color
7159  * @color: (allow-none): the color to assign (does not need to be allocated),
7160  *         or %NULL to undo the effect of previous calls to
7161  *         of gtk_widget_modify_bg().
7162  *
7163  * Sets the background color for a widget in a particular state.
7164  * All other style values are left untouched. See also
7165  * gtk_widget_modify_style(). 
7166  *
7167  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7168  * draw on their parent container's window and thus may not draw any 
7169  * background themselves. This is the case for e.g. #GtkLabel. To modify 
7170  * the background of such widgets, you have to set the background color 
7171  * on their parent; if you want to set the background of a rectangular 
7172  * area around a label, try placing the label in a #GtkEventBox widget 
7173  * and setting the background color on that.
7174  **/
7175 void
7176 gtk_widget_modify_bg (GtkWidget      *widget,
7177                       GtkStateType    state,
7178                       const GdkColor *color)
7179 {
7180   g_return_if_fail (GTK_IS_WIDGET (widget));
7181   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7182
7183   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7184 }
7185
7186 /**
7187  * gtk_widget_modify_text:
7188  * @widget: a #GtkWidget
7189  * @state: the state for which to set the text color
7190  * @color: (allow-none): the color to assign (does not need to be allocated),
7191  *         or %NULL to undo the effect of previous calls to
7192  *         of gtk_widget_modify_text().
7193  *
7194  * Sets the text color for a widget in a particular state.  All other
7195  * style values are left untouched. The text color is the foreground
7196  * color used along with the base color (see gtk_widget_modify_base())
7197  * for widgets such as #GtkEntry and #GtkTextView. See also
7198  * gtk_widget_modify_style().
7199  **/
7200 void
7201 gtk_widget_modify_text (GtkWidget      *widget,
7202                         GtkStateType    state,
7203                         const GdkColor *color)
7204 {
7205   g_return_if_fail (GTK_IS_WIDGET (widget));
7206   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7207
7208   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7209 }
7210
7211 /**
7212  * gtk_widget_modify_base:
7213  * @widget: a #GtkWidget
7214  * @state: the state for which to set the base color
7215  * @color: (allow-none): the color to assign (does not need to be allocated),
7216  *         or %NULL to undo the effect of previous calls to
7217  *         of gtk_widget_modify_base().
7218  *
7219  * Sets the base color for a widget in a particular state.
7220  * All other style values are left untouched. The base color
7221  * is the background color used along with the text color
7222  * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7223  * and #GtkTextView. See also gtk_widget_modify_style().
7224  *
7225  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7226  * draw on their parent container's window and thus may not draw any 
7227  * background themselves. This is the case for e.g. #GtkLabel. To modify 
7228  * the background of such widgets, you have to set the base color on their 
7229  * parent; if you want to set the background of a rectangular area around 
7230  * a label, try placing the label in a #GtkEventBox widget and setting 
7231  * the base color on that.
7232  **/
7233 void
7234 gtk_widget_modify_base (GtkWidget      *widget,
7235                         GtkStateType    state,
7236                         const GdkColor *color)
7237 {
7238   g_return_if_fail (GTK_IS_WIDGET (widget));
7239   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7240
7241   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7242 }
7243
7244 static void
7245 modify_color_property (GtkWidget      *widget,
7246                        GtkRcStyle     *rc_style,
7247                        const char     *name,
7248                        const GdkColor *color)
7249 {
7250   GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7251   GQuark property_name = g_quark_from_string (name);
7252
7253   if (color)
7254     {
7255       GtkRcProperty rc_property = {0};
7256       char *color_name;
7257
7258       rc_property.type_name = type_name;
7259       rc_property.property_name = property_name;
7260       rc_property.origin = NULL;
7261
7262       color_name = gdk_color_to_string (color);
7263       g_value_init (&rc_property.value, G_TYPE_STRING);
7264       g_value_take_string (&rc_property.value, color_name);
7265
7266       _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7267
7268       g_value_unset (&rc_property.value);
7269     }
7270   else
7271     _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7272 }
7273
7274 /**
7275  * gtk_widget_modify_cursor:
7276  * @widget: a #GtkWidget
7277  * @primary: the color to use for primary cursor (does not need to be
7278  *           allocated), or %NULL to undo the effect of previous calls to
7279  *           of gtk_widget_modify_cursor().
7280  * @secondary: the color to use for secondary cursor (does not need to be
7281  *             allocated), or %NULL to undo the effect of previous calls to
7282  *             of gtk_widget_modify_cursor().
7283  *
7284  * Sets the cursor color to use in a widget, overriding the
7285  * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7286  * style properties. All other style values are left untouched. 
7287  * See also gtk_widget_modify_style().
7288  *
7289  * Since: 2.12
7290  **/
7291 void
7292 gtk_widget_modify_cursor (GtkWidget      *widget,
7293                           const GdkColor *primary,
7294                           const GdkColor *secondary)
7295 {
7296   GtkRcStyle *rc_style;
7297
7298   g_return_if_fail (GTK_IS_WIDGET (widget));
7299
7300   rc_style = gtk_widget_get_modifier_style (widget);
7301
7302   modify_color_property (widget, rc_style, "cursor-color", primary);
7303   modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7304
7305   gtk_widget_modify_style (widget, rc_style);
7306 }
7307
7308 /**
7309  * gtk_widget_modify_font:
7310  * @widget: a #GtkWidget
7311  * @font_desc: (allow-none): the font description to use, or %NULL to undo
7312  *   the effect of previous calls to gtk_widget_modify_font().
7313  *
7314  * Sets the font to use for a widget.  All other style values are left
7315  * untouched. See also gtk_widget_modify_style().
7316  **/
7317 void
7318 gtk_widget_modify_font (GtkWidget            *widget,
7319                         PangoFontDescription *font_desc)
7320 {
7321   GtkRcStyle *rc_style;
7322
7323   g_return_if_fail (GTK_IS_WIDGET (widget));
7324
7325   rc_style = gtk_widget_get_modifier_style (widget);  
7326
7327   if (rc_style->font_desc)
7328     pango_font_description_free (rc_style->font_desc);
7329
7330   if (font_desc)
7331     rc_style->font_desc = pango_font_description_copy (font_desc);
7332   else
7333     rc_style->font_desc = NULL;
7334   
7335   gtk_widget_modify_style (widget, rc_style);
7336 }
7337
7338 static void
7339 gtk_widget_real_direction_changed (GtkWidget        *widget,
7340                                    GtkTextDirection  previous_direction)
7341 {
7342   gtk_widget_queue_resize (widget);
7343 }
7344
7345 static void
7346 gtk_widget_real_style_set (GtkWidget *widget,
7347                            GtkStyle  *previous_style)
7348 {
7349   GtkWidgetPrivate *priv = widget->priv;
7350
7351   if (gtk_widget_get_realized (widget) &&
7352       gtk_widget_get_has_window (widget))
7353     gtk_style_set_background (priv->style, priv->window, priv->state);
7354 }
7355
7356 static void
7357 gtk_widget_set_style_internal (GtkWidget *widget,
7358                                GtkStyle  *style,
7359                                gboolean   initial_emission)
7360 {
7361   GtkWidgetPrivate *priv = widget->priv;
7362
7363   g_object_ref (widget);
7364   g_object_freeze_notify (G_OBJECT (widget));
7365
7366   if (priv->style != style)
7367     {
7368       GtkStyle *previous_style;
7369
7370       if (gtk_widget_get_realized (widget))
7371         {
7372           gtk_widget_reset_shapes (widget);
7373           gtk_style_detach (priv->style);
7374         }
7375
7376       previous_style = priv->style;
7377       priv->style = style;
7378       g_object_ref (priv->style);
7379
7380       if (gtk_widget_get_realized (widget))
7381         priv->style = gtk_style_attach (priv->style, priv->window);
7382
7383       gtk_widget_update_pango_context (widget);
7384       g_signal_emit (widget,
7385                      widget_signals[STYLE_SET],
7386                      0,
7387                      initial_emission ? NULL : previous_style);
7388       g_object_unref (previous_style);
7389
7390       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7391         gtk_widget_queue_resize (widget);
7392     }
7393   else if (initial_emission)
7394     {
7395       gtk_widget_update_pango_context (widget);
7396       g_signal_emit (widget,
7397                      widget_signals[STYLE_SET],
7398                      0,
7399                      NULL);
7400     }
7401   g_object_notify (G_OBJECT (widget), "style");
7402   g_object_thaw_notify (G_OBJECT (widget));
7403   g_object_unref (widget);
7404 }
7405
7406 typedef struct {
7407   GtkWidget *previous_toplevel;
7408   GdkScreen *previous_screen;
7409   GdkScreen *new_screen;
7410 } HierarchyChangedInfo;
7411
7412 static void
7413 do_screen_change (GtkWidget *widget,
7414                   GdkScreen *old_screen,
7415                   GdkScreen *new_screen)
7416 {
7417   if (old_screen != new_screen)
7418     {
7419       if (old_screen)
7420         {
7421           PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7422           if (context)
7423             g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7424         }
7425       
7426       _gtk_tooltip_hide (widget);
7427       g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7428     }
7429 }
7430
7431 static void
7432 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7433                                                 gpointer   client_data)
7434 {
7435   GtkWidgetPrivate *priv = widget->priv;
7436   HierarchyChangedInfo *info = client_data;
7437   gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7438                  (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7439
7440   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7441     {
7442       g_object_ref (widget);
7443       
7444       if (new_anchored)
7445         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7446       else
7447         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7448       
7449       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7450       do_screen_change (widget, info->previous_screen, info->new_screen);
7451       
7452       if (GTK_IS_CONTAINER (widget))
7453         gtk_container_forall (GTK_CONTAINER (widget),
7454                               gtk_widget_propagate_hierarchy_changed_recurse,
7455                               client_data);
7456       
7457       g_object_unref (widget);
7458     }
7459 }
7460
7461 /**
7462  * _gtk_widget_propagate_hierarchy_changed:
7463  * @widget: a #GtkWidget
7464  * @previous_toplevel: Previous toplevel
7465  * 
7466  * Propagates changes in the anchored state to a widget and all
7467  * children, unsetting or setting the %ANCHORED flag, and
7468  * emitting #GtkWidget::hierarchy-changed.
7469  **/
7470 void
7471 _gtk_widget_propagate_hierarchy_changed (GtkWidget    *widget,
7472                                          GtkWidget    *previous_toplevel)
7473 {
7474   GtkWidgetPrivate *priv = widget->priv;
7475   HierarchyChangedInfo info;
7476
7477   info.previous_toplevel = previous_toplevel;
7478   info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7479
7480   if (gtk_widget_is_toplevel (widget) ||
7481       (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7482     info.new_screen = gtk_widget_get_screen (widget);
7483   else
7484     info.new_screen = NULL;
7485
7486   if (info.previous_screen)
7487     g_object_ref (info.previous_screen);
7488   if (previous_toplevel)
7489     g_object_ref (previous_toplevel);
7490
7491   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7492
7493   if (previous_toplevel)
7494     g_object_unref (previous_toplevel);
7495   if (info.previous_screen)
7496     g_object_unref (info.previous_screen);
7497 }
7498
7499 static void
7500 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7501                                              gpointer   client_data)
7502 {
7503   HierarchyChangedInfo *info = client_data;
7504
7505   g_object_ref (widget);
7506   
7507   do_screen_change (widget, info->previous_screen, info->new_screen);
7508   
7509   if (GTK_IS_CONTAINER (widget))
7510     gtk_container_forall (GTK_CONTAINER (widget),
7511                           gtk_widget_propagate_screen_changed_recurse,
7512                           client_data);
7513   
7514   g_object_unref (widget);
7515 }
7516
7517 /**
7518  * gtk_widget_is_composited:
7519  * @widget: a #GtkWidget
7520  * 
7521  * Whether @widget can rely on having its alpha channel
7522  * drawn correctly. On X11 this function returns whether a
7523  * compositing manager is running for @widget's screen.
7524  *
7525  * Please note that the semantics of this call will change
7526  * in the future if used on a widget that has a composited
7527  * window in its hierarchy (as set by gdk_window_set_composited()).
7528  * 
7529  * Return value: %TRUE if the widget can rely on its alpha
7530  * channel being drawn correctly.
7531  * 
7532  * Since: 2.10
7533  */
7534 gboolean
7535 gtk_widget_is_composited (GtkWidget *widget)
7536 {
7537   GdkScreen *screen;
7538
7539   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7540   
7541   screen = gtk_widget_get_screen (widget);
7542   
7543   return gdk_screen_is_composited (screen);
7544 }
7545
7546 static void
7547 propagate_composited_changed (GtkWidget *widget,
7548                               gpointer dummy)
7549 {
7550   if (GTK_IS_CONTAINER (widget))
7551     {
7552       gtk_container_forall (GTK_CONTAINER (widget),
7553                             propagate_composited_changed,
7554                             NULL);
7555     }
7556   
7557   g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7558 }
7559
7560 void
7561 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7562 {
7563   propagate_composited_changed (widget, NULL);
7564 }
7565
7566 /**
7567  * _gtk_widget_propagate_screen_changed:
7568  * @widget: a #GtkWidget
7569  * @previous_screen: Previous screen
7570  * 
7571  * Propagates changes in the screen for a widget to all
7572  * children, emitting #GtkWidget::screen-changed.
7573  **/
7574 void
7575 _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
7576                                       GdkScreen    *previous_screen)
7577 {
7578   HierarchyChangedInfo info;
7579
7580   info.previous_screen = previous_screen;
7581   info.new_screen = gtk_widget_get_screen (widget);
7582
7583   if (previous_screen)
7584     g_object_ref (previous_screen);
7585
7586   gtk_widget_propagate_screen_changed_recurse (widget, &info);
7587
7588   if (previous_screen)
7589     g_object_unref (previous_screen);
7590 }
7591
7592 static void
7593 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7594 {
7595   if (gtk_widget_has_rc_style (widget))
7596     gtk_widget_reset_rc_style (widget);
7597   
7598   if (GTK_IS_CONTAINER (widget))
7599     gtk_container_forall (GTK_CONTAINER (widget),
7600                           reset_rc_styles_recurse,
7601                           NULL);
7602 }
7603
7604
7605 /**
7606  * gtk_widget_reset_rc_styles:
7607  * @widget: a #GtkWidget.
7608  *
7609  * Reset the styles of @widget and all descendents, so when
7610  * they are looked up again, they get the correct values
7611  * for the currently loaded RC file settings.
7612  *
7613  * This function is not useful for applications.
7614  */
7615 void
7616 gtk_widget_reset_rc_styles (GtkWidget *widget)
7617 {
7618   g_return_if_fail (GTK_IS_WIDGET (widget));
7619
7620   reset_rc_styles_recurse (widget, NULL);
7621 }
7622
7623 /**
7624  * gtk_widget_get_default_style:
7625  * 
7626  * Returns the default style used by all widgets initially.
7627  *
7628  * Returns: (transfer none): the default style. This #GtkStyle object is owned
7629  *          by GTK+ and should not be modified or freed.
7630  */
7631 GtkStyle*
7632 gtk_widget_get_default_style (void)
7633 {
7634   if (!gtk_default_style)
7635     {
7636       gtk_default_style = gtk_style_new ();
7637       g_object_ref (gtk_default_style);
7638     }
7639   
7640   return gtk_default_style;
7641 }
7642
7643 static PangoContext *
7644 gtk_widget_peek_pango_context (GtkWidget *widget)
7645 {
7646   return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7647 }
7648
7649 /**
7650  * gtk_widget_get_pango_context:
7651  * @widget: a #GtkWidget
7652  * 
7653  * Gets a #PangoContext with the appropriate font map, font description,
7654  * and base direction for this widget. Unlike the context returned
7655  * by gtk_widget_create_pango_context(), this context is owned by
7656  * the widget (it can be used until the screen for the widget changes
7657  * or the widget is removed from its toplevel), and will be updated to
7658  * match any changes to the widget's attributes.
7659  *
7660  * If you create and keep a #PangoLayout using this context, you must
7661  * deal with changes to the context by calling pango_layout_context_changed()
7662  * on the layout in response to the #GtkWidget::style-set and 
7663  * #GtkWidget::direction-changed signals for the widget.
7664  *
7665  * Return value: (transfer none): the #PangoContext for the widget.
7666  **/
7667 PangoContext *
7668 gtk_widget_get_pango_context (GtkWidget *widget)
7669 {
7670   PangoContext *context;
7671
7672   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7673   
7674   context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7675   if (!context)
7676     {
7677       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7678       g_object_set_qdata_full (G_OBJECT (widget),
7679                                quark_pango_context,
7680                                context,
7681                                g_object_unref);
7682     }
7683
7684   return context;
7685 }
7686
7687 static void
7688 update_pango_context (GtkWidget    *widget,
7689                       PangoContext *context)
7690 {
7691   GtkWidgetPrivate *priv = widget->priv;
7692
7693   pango_context_set_font_description (context, priv->style->font_desc);
7694   pango_context_set_base_dir (context,
7695                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7696                               PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7697 }
7698
7699 static void
7700 gtk_widget_update_pango_context (GtkWidget *widget)
7701 {
7702   PangoContext *context = gtk_widget_peek_pango_context (widget);
7703   
7704   if (context)
7705     {
7706       GdkScreen *screen;
7707
7708       update_pango_context (widget, context);
7709
7710       screen = gtk_widget_get_screen_unchecked (widget);
7711       if (screen)
7712         {
7713           pango_cairo_context_set_resolution (context,
7714                                               gdk_screen_get_resolution (screen));
7715           pango_cairo_context_set_font_options (context,
7716                                                 gdk_screen_get_font_options (screen));
7717         }
7718     }
7719 }
7720
7721 /**
7722  * gtk_widget_create_pango_context:
7723  * @widget: a #GtkWidget
7724  *
7725  * Creates a new #PangoContext with the appropriate font map,
7726  * font description, and base direction for drawing text for
7727  * this widget. See also gtk_widget_get_pango_context().
7728  *
7729  * Return value: (transfer full): the new #PangoContext
7730  **/
7731 PangoContext *
7732 gtk_widget_create_pango_context (GtkWidget *widget)
7733 {
7734   GdkScreen *screen;
7735   PangoContext *context;
7736
7737   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7738
7739   screen = gtk_widget_get_screen_unchecked (widget);
7740   if (!screen)
7741     {
7742       GTK_NOTE (MULTIHEAD,
7743                 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7744
7745       screen = gdk_screen_get_default ();
7746     }
7747
7748   context = gdk_pango_context_get_for_screen (screen);
7749
7750   update_pango_context (widget, context);
7751   pango_context_set_language (context, gtk_get_default_language ());
7752
7753   return context;
7754 }
7755
7756 /**
7757  * gtk_widget_create_pango_layout:
7758  * @widget: a #GtkWidget
7759  * @text: text to set on the layout (can be %NULL)
7760  *
7761  * Creates a new #PangoLayout with the appropriate font map,
7762  * font description, and base direction for drawing text for
7763  * this widget.
7764  *
7765  * If you keep a #PangoLayout created in this way around, in order to
7766  * notify the layout of changes to the base direction or font of this
7767  * widget, you must call pango_layout_context_changed() in response to
7768  * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7769  * for the widget.
7770  *
7771  * Return value: (transfer full): the new #PangoLayout
7772  **/
7773 PangoLayout *
7774 gtk_widget_create_pango_layout (GtkWidget   *widget,
7775                                 const gchar *text)
7776 {
7777   PangoLayout *layout;
7778   PangoContext *context;
7779
7780   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7781
7782   context = gtk_widget_get_pango_context (widget);
7783   layout = pango_layout_new (context);
7784
7785   if (text)
7786     pango_layout_set_text (layout, text, -1);
7787
7788   return layout;
7789 }
7790
7791 /**
7792  * gtk_widget_render_icon:
7793  * @widget: a #GtkWidget
7794  * @stock_id: a stock ID
7795  * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7796  *     render at the size of the source and don't scale (if there are
7797  *     multiple source sizes, GTK+ picks one of the available sizes).
7798  * @detail: (allow-none): render detail to pass to theme engine
7799  *
7800  * A convenience function that uses the theme engine and RC file
7801  * settings for @widget to look up @stock_id and render it to
7802  * a pixbuf. @stock_id should be a stock icon ID such as
7803  * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7804  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7805  * identifies the widget or code doing the rendering, so that
7806  * theme engines can special-case rendering for that widget or code.
7807  *
7808  * The pixels in the returned #GdkPixbuf are shared with the rest of
7809  * the application and should not be modified. The pixbuf should be freed
7810  * after use with g_object_unref().
7811  *
7812  * Return value: (transfer full): a new pixbuf, or %NULL if the
7813  *     stock ID wasn't known
7814  **/
7815 GdkPixbuf*
7816 gtk_widget_render_icon (GtkWidget      *widget,
7817                         const gchar    *stock_id,
7818                         GtkIconSize     size,
7819                         const gchar    *detail)
7820 {
7821   GtkWidgetPrivate *priv;
7822   GtkIconSet *icon_set;
7823   GdkPixbuf *retval;
7824   
7825   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7826   g_return_val_if_fail (stock_id != NULL, NULL);
7827   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7828
7829   priv = widget->priv;
7830
7831   gtk_widget_ensure_style (widget);
7832   
7833   icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7834
7835   if (icon_set == NULL)
7836     return NULL;
7837
7838   retval = gtk_icon_set_render_icon (icon_set,
7839                                      priv->style,
7840                                      gtk_widget_get_direction (widget),
7841                                      gtk_widget_get_state (widget),
7842                                      size,
7843                                      widget,
7844                                      detail);
7845
7846   return retval;
7847 }
7848
7849 /**
7850  * gtk_widget_set_parent_window:
7851  * @widget: a #GtkWidget.
7852  * @parent_window: the new parent window.
7853  *  
7854  * Sets a non default parent window for @widget.
7855  **/
7856 void
7857 gtk_widget_set_parent_window   (GtkWidget           *widget,
7858                                 GdkWindow           *parent_window)
7859 {
7860   GdkWindow *old_parent_window;
7861
7862   g_return_if_fail (GTK_IS_WIDGET (widget));
7863   
7864   old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7865                                           quark_parent_window);
7866
7867   if (parent_window != old_parent_window)
7868     {
7869       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
7870                           parent_window);
7871       if (old_parent_window)
7872         g_object_unref (old_parent_window);
7873       if (parent_window)
7874         g_object_ref (parent_window);
7875     }
7876 }
7877
7878 /**
7879  * gtk_widget_get_parent_window:
7880  * @widget: a #GtkWidget.
7881  *
7882  * Gets @widget's parent window.
7883  *
7884  * Returns: (transfer none): the parent window of @widget.
7885  **/
7886 GdkWindow *
7887 gtk_widget_get_parent_window (GtkWidget *widget)
7888 {
7889   GtkWidgetPrivate *priv;
7890   GdkWindow *parent_window;
7891
7892   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7893
7894   priv = widget->priv;
7895
7896   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7897
7898   return (parent_window != NULL) ? parent_window :
7899          (priv->parent != NULL) ? priv->parent->priv->window : NULL;
7900 }
7901
7902
7903 /**
7904  * gtk_widget_set_child_visible:
7905  * @widget: a #GtkWidget
7906  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7907  *
7908  * Sets whether @widget should be mapped along with its when its parent
7909  * is mapped and @widget has been shown with gtk_widget_show(). 
7910  *
7911  * The child visibility can be set for widget before it is added to
7912  * a container with gtk_widget_set_parent(), to avoid mapping
7913  * children unnecessary before immediately unmapping them. However
7914  * it will be reset to its default state of %TRUE when the widget
7915  * is removed from a container.
7916  * 
7917  * Note that changing the child visibility of a widget does not
7918  * queue a resize on the widget. Most of the time, the size of
7919  * a widget is computed from all visible children, whether or
7920  * not they are mapped. If this is not the case, the container
7921  * can queue a resize itself.
7922  *
7923  * This function is only useful for container implementations and
7924  * never should be called by an application.
7925  **/
7926 void
7927 gtk_widget_set_child_visible (GtkWidget *widget,
7928                               gboolean   is_visible)
7929 {
7930   GtkWidgetPrivate *priv;
7931
7932   g_return_if_fail (GTK_IS_WIDGET (widget));
7933   g_return_if_fail (!gtk_widget_is_toplevel (widget));
7934
7935   priv = widget->priv;
7936
7937   g_object_ref (widget);
7938
7939   if (is_visible)
7940     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7941   else
7942     {
7943       GtkWidget *toplevel;
7944       
7945       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7946
7947       toplevel = gtk_widget_get_toplevel (widget);
7948       if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7949         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7950     }
7951
7952   if (priv->parent && gtk_widget_get_realized (priv->parent))
7953     {
7954       if (gtk_widget_get_mapped (priv->parent) &&
7955           GTK_WIDGET_CHILD_VISIBLE (widget) &&
7956           gtk_widget_get_visible (widget))
7957         gtk_widget_map (widget);
7958       else
7959         gtk_widget_unmap (widget);
7960     }
7961
7962   g_object_unref (widget);
7963 }
7964
7965 /**
7966  * gtk_widget_get_child_visible:
7967  * @widget: a #GtkWidget
7968  * 
7969  * Gets the value set with gtk_widget_set_child_visible().
7970  * If you feel a need to use this function, your code probably
7971  * needs reorganization. 
7972  *
7973  * This function is only useful for container implementations and
7974  * never should be called by an application.
7975  *
7976  * Return value: %TRUE if the widget is mapped with the parent.
7977  **/
7978 gboolean
7979 gtk_widget_get_child_visible (GtkWidget *widget)
7980 {
7981   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7982   
7983   return GTK_WIDGET_CHILD_VISIBLE (widget);
7984 }
7985
7986 static GdkScreen *
7987 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7988 {
7989   GtkWidget *toplevel;
7990   
7991   toplevel = gtk_widget_get_toplevel (widget);
7992
7993   if (gtk_widget_is_toplevel (toplevel))
7994     {
7995       if (GTK_IS_WINDOW (toplevel))
7996         return gtk_window_get_screen (GTK_WINDOW (toplevel));
7997       else if (GTK_IS_INVISIBLE (toplevel))
7998         return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
7999     }
8000
8001   return NULL;
8002 }
8003
8004 /**
8005  * gtk_widget_get_screen:
8006  * @widget: a #GtkWidget
8007  * 
8008  * Get the #GdkScreen from the toplevel window associated with
8009  * this widget. This function can only be called after the widget
8010  * has been added to a widget hierarchy with a #GtkWindow
8011  * at the top.
8012  *
8013  * In general, you should only create screen specific
8014  * resources when a widget has been realized, and you should
8015  * free those resources when the widget is unrealized.
8016  *
8017  * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8018  *
8019  * Since: 2.2
8020  **/
8021 GdkScreen*
8022 gtk_widget_get_screen (GtkWidget *widget)
8023 {
8024   GdkScreen *screen;
8025   
8026   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8027
8028   screen = gtk_widget_get_screen_unchecked (widget);
8029
8030   if (screen)
8031     return screen;
8032   else
8033     {
8034 #if 0
8035       g_warning (G_STRLOC ": Can't get associated screen"
8036                  " for a widget unless it is inside a toplevel GtkWindow\n"
8037                  " widget type is %s associated top level type is %s",
8038                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8039                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8040 #endif
8041       return gdk_screen_get_default ();
8042     }
8043 }
8044
8045 /**
8046  * gtk_widget_has_screen:
8047  * @widget: a #GtkWidget
8048  * 
8049  * Checks whether there is a #GdkScreen is associated with
8050  * this widget. All toplevel widgets have an associated
8051  * screen, and all widgets added into a hierarchy with a toplevel
8052  * window at the top.
8053  * 
8054  * Return value: %TRUE if there is a #GdkScreen associcated
8055  *   with the widget.
8056  *
8057  * Since: 2.2
8058  **/
8059 gboolean
8060 gtk_widget_has_screen (GtkWidget *widget)
8061 {
8062   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8063
8064   return (gtk_widget_get_screen_unchecked (widget) != NULL);
8065 }
8066
8067 /**
8068  * gtk_widget_get_display:
8069  * @widget: a #GtkWidget
8070  * 
8071  * Get the #GdkDisplay for the toplevel window associated with
8072  * this widget. This function can only be called after the widget
8073  * has been added to a widget hierarchy with a #GtkWindow at the top.
8074  *
8075  * In general, you should only create display specific
8076  * resources when a widget has been realized, and you should
8077  * free those resources when the widget is unrealized.
8078  *
8079  * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8080  *
8081  * Since: 2.2
8082  **/
8083 GdkDisplay*
8084 gtk_widget_get_display (GtkWidget *widget)
8085 {
8086   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8087   
8088   return gdk_screen_get_display (gtk_widget_get_screen (widget));
8089 }
8090
8091 /**
8092  * gtk_widget_get_root_window:
8093  * @widget: a #GtkWidget
8094  * 
8095  * Get the root window where this widget is located. This function can
8096  * only be called after the widget has been added to a widget
8097  * hierarchy with #GtkWindow at the top.
8098  *
8099  * The root window is useful for such purposes as creating a popup
8100  * #GdkWindow associated with the window. In general, you should only
8101  * create display specific resources when a widget has been realized,
8102  * and you should free those resources when the widget is unrealized.
8103  *
8104  * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8105  *
8106  * Since: 2.2
8107  **/
8108 GdkWindow*
8109 gtk_widget_get_root_window (GtkWidget *widget)
8110 {
8111   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8112
8113   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8114 }
8115
8116 /**
8117  * gtk_widget_child_focus:
8118  * @widget: a #GtkWidget
8119  * @direction: direction of focus movement
8120  *
8121  * This function is used by custom widget implementations; if you're
8122  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8123  * to a particular widget, and gtk_container_set_focus_chain() to
8124  * change the focus tab order. So you may want to investigate those
8125  * functions instead.
8126  * 
8127  * gtk_widget_child_focus() is called by containers as the user moves
8128  * around the window using keyboard shortcuts. @direction indicates
8129  * what kind of motion is taking place (up, down, left, right, tab
8130  * forward, tab backward). gtk_widget_child_focus() emits the
8131  * #GtkWidget::focus signal; widgets override the default handler
8132  * for this signal in order to implement appropriate focus behavior.
8133  *
8134  * The default ::focus handler for a widget should return %TRUE if
8135  * moving in @direction left the focus on a focusable location inside
8136  * that widget, and %FALSE if moving in @direction moved the focus
8137  * outside the widget. If returning %TRUE, widgets normally
8138  * call gtk_widget_grab_focus() to place the focus accordingly;
8139  * if returning %FALSE, they don't modify the current focus location.
8140  *
8141  * Return value: %TRUE if focus ended up inside @widget
8142  **/
8143 gboolean
8144 gtk_widget_child_focus (GtkWidget       *widget,
8145                         GtkDirectionType direction)
8146 {
8147   gboolean return_val;
8148
8149   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8150
8151   if (!gtk_widget_get_visible (widget) ||
8152       !gtk_widget_is_sensitive (widget))
8153     return FALSE;
8154
8155   /* child widgets must set CAN_FOCUS, containers
8156    * don't have to though.
8157    */
8158   if (!GTK_IS_CONTAINER (widget) &&
8159       !gtk_widget_get_can_focus (widget))
8160     return FALSE;
8161   
8162   g_signal_emit (widget,
8163                  widget_signals[FOCUS],
8164                  0,
8165                  direction, &return_val);
8166
8167   return return_val;
8168 }
8169
8170 /**
8171  * gtk_widget_keynav_failed:
8172  * @widget: a #GtkWidget
8173  * @direction: direction of focus movement
8174  *
8175  * This function should be called whenever keyboard navigation within
8176  * a single widget hits a boundary. The function emits the
8177  * #GtkWidget::keynav-failed signal on the widget and its return
8178  * value should be interpreted in a way similar to the return value of
8179  * gtk_widget_child_focus():
8180  *
8181  * When %TRUE is returned, stay in the widget, the failed keyboard
8182  * navigation is Ok and/or there is nowhere we can/should move the
8183  * focus to.
8184  *
8185  * When %FALSE is returned, the caller should continue with keyboard
8186  * navigation outside the widget, e.g. by calling
8187  * gtk_widget_child_focus() on the widget's toplevel.
8188  *
8189  * The default ::keynav-failed handler returns %TRUE for 
8190  * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other 
8191  * values of #GtkDirectionType, it looks at the 
8192  * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE 
8193  * if the setting is %TRUE. This way the entire user interface
8194  * becomes cursor-navigatable on input devices such as mobile phones
8195  * which only have cursor keys but no tab key.
8196  *
8197  * Whenever the default handler returns %TRUE, it also calls
8198  * gtk_widget_error_bell() to notify the user of the failed keyboard
8199  * navigation.
8200  *
8201  * A use case for providing an own implementation of ::keynav-failed 
8202  * (either by connecting to it or by overriding it) would be a row of
8203  * #GtkEntry widgets where the user should be able to navigate the
8204  * entire row with the cursor keys, as e.g. known from user interfaces 
8205  * that require entering license keys.
8206  *
8207  * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8208  *               if the emitting widget should try to handle the keyboard
8209  *               navigation attempt in its parent container(s).
8210  *
8211  * Since: 2.12
8212  **/
8213 gboolean
8214 gtk_widget_keynav_failed (GtkWidget        *widget,
8215                           GtkDirectionType  direction)
8216 {
8217   gboolean return_val;
8218
8219   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8220
8221   g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8222                  direction, &return_val);
8223
8224   return return_val;
8225 }
8226
8227 /**
8228  * gtk_widget_error_bell:
8229  * @widget: a #GtkWidget
8230  *
8231  * Notifies the user about an input-related error on this widget. 
8232  * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8233  * gdk_window_beep(), otherwise it does nothing.
8234  *
8235  * Note that the effect of gdk_window_beep() can be configured in many
8236  * ways, depending on the windowing backend and the desktop environment
8237  * or window manager that is used.
8238  *
8239  * Since: 2.12
8240  **/
8241 void
8242 gtk_widget_error_bell (GtkWidget *widget)
8243 {
8244   GtkWidgetPrivate *priv;
8245   GtkSettings* settings;
8246   gboolean beep;
8247
8248   g_return_if_fail (GTK_IS_WIDGET (widget));
8249
8250   priv = widget->priv;
8251
8252   settings = gtk_widget_get_settings (widget);
8253   if (!settings)
8254     return;
8255
8256   g_object_get (settings,
8257                 "gtk-error-bell", &beep,
8258                 NULL);
8259
8260   if (beep && priv->window)
8261     gdk_window_beep (priv->window);
8262 }
8263
8264 static void
8265 gtk_widget_set_usize_internal (GtkWidget *widget,
8266                                gint       width,
8267                                gint       height)
8268 {
8269   GtkWidgetAuxInfo *aux_info;
8270   gboolean changed = FALSE;
8271   
8272   g_object_freeze_notify (G_OBJECT (widget));
8273
8274   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8275   
8276   if (width > -2 && aux_info->width != width)
8277     {
8278       g_object_notify (G_OBJECT (widget), "width-request");
8279       aux_info->width = width;
8280       changed = TRUE;
8281     }
8282   if (height > -2 && aux_info->height != height)
8283     {
8284       g_object_notify (G_OBJECT (widget), "height-request");  
8285       aux_info->height = height;
8286       changed = TRUE;
8287     }
8288   
8289   if (gtk_widget_get_visible (widget) && changed)
8290     gtk_widget_queue_resize (widget);
8291
8292   g_object_thaw_notify (G_OBJECT (widget));
8293 }
8294
8295 /**
8296  * gtk_widget_set_size_request:
8297  * @widget: a #GtkWidget
8298  * @width: width @widget should request, or -1 to unset
8299  * @height: height @widget should request, or -1 to unset
8300  *
8301  * Sets the minimum size of a widget; that is, the widget's size
8302  * request will be @width by @height. You can use this function to
8303  * force a widget to be either larger or smaller than it normally
8304  * would be.
8305  *
8306  * In most cases, gtk_window_set_default_size() is a better choice for
8307  * toplevel windows than this function; setting the default size will
8308  * still allow users to shrink the window. Setting the size request
8309  * will force them to leave the window at least as large as the size
8310  * request. When dealing with window sizes,
8311  * gtk_window_set_geometry_hints() can be a useful function as well.
8312  * 
8313  * Note the inherent danger of setting any fixed size - themes,
8314  * translations into other languages, different fonts, and user action
8315  * can all change the appropriate size for a given widget. So, it's
8316  * basically impossible to hardcode a size that will always be
8317  * correct.
8318  *
8319  * The size request of a widget is the smallest size a widget can
8320  * accept while still functioning well and drawing itself correctly.
8321  * However in some strange cases a widget may be allocated less than
8322  * its requested size, and in many cases a widget may be allocated more
8323  * space than it requested.
8324  *
8325  * If the size request in a given direction is -1 (unset), then
8326  * the "natural" size request of the widget will be used instead.
8327  *
8328  * Widgets can't actually be allocated a size less than 1 by 1, but
8329  * you can pass 0,0 to this function to mean "as small as possible."
8330  *
8331  * The size request set here does not include any margin from the
8332  * #GtkWidget properties margin-left, margin-right, margin-top, and
8333  * margin-bottom, but it does include pretty much all other padding
8334  * or border properties set by any subclass of #GtkWidget.
8335  **/
8336 void
8337 gtk_widget_set_size_request (GtkWidget *widget,
8338                              gint       width,
8339                              gint       height)
8340 {
8341   g_return_if_fail (GTK_IS_WIDGET (widget));
8342   g_return_if_fail (width >= -1);
8343   g_return_if_fail (height >= -1);
8344
8345   if (width == 0)
8346     width = 1;
8347   if (height == 0)
8348     height = 1;
8349   
8350   gtk_widget_set_usize_internal (widget, width, height);
8351 }
8352
8353
8354 /**
8355  * gtk_widget_get_size_request:
8356  * @widget: a #GtkWidget
8357  * @width: (out) (allow-none): return location for width, or %NULL
8358  * @height: (out) (allow-none): return location for height, or %NULL
8359  *
8360  * Gets the size request that was explicitly set for the widget using
8361  * gtk_widget_set_size_request(). A value of -1 stored in @width or
8362  * @height indicates that that dimension has not been set explicitly
8363  * and the natural requisition of the widget will be used intead. See
8364  * gtk_widget_set_size_request(). To get the size a widget will
8365  * actually request, call gtk_size_request_get_size() instead of
8366  * this function.
8367  **/
8368 void
8369 gtk_widget_get_size_request (GtkWidget *widget,
8370                              gint      *width,
8371                              gint      *height)
8372 {
8373   const GtkWidgetAuxInfo *aux_info;
8374
8375   g_return_if_fail (GTK_IS_WIDGET (widget));
8376
8377   aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8378
8379   if (width)
8380     *width = aux_info->width;
8381
8382   if (height)
8383     *height = aux_info->height;
8384 }
8385
8386 /**
8387  * gtk_widget_set_events:
8388  * @widget: a #GtkWidget
8389  * @events: event mask
8390  *
8391  * Sets the event mask (see #GdkEventMask) for a widget. The event
8392  * mask determines which events a widget will receive. Keep in mind
8393  * that different widgets have different default event masks, and by
8394  * changing the event mask you may disrupt a widget's functionality,
8395  * so be careful. This function must be called while a widget is
8396  * unrealized. Consider gtk_widget_add_events() for widgets that are
8397  * already realized, or if you want to preserve the existing event
8398  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8399  * to get events on those widgets, place them inside a #GtkEventBox
8400  * and receive events on the event box.
8401  **/
8402 void
8403 gtk_widget_set_events (GtkWidget *widget,
8404                        gint       events)
8405 {
8406   g_return_if_fail (GTK_IS_WIDGET (widget));
8407   g_return_if_fail (!gtk_widget_get_realized (widget));
8408   
8409   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8410                       GINT_TO_POINTER (events));
8411   g_object_notify (G_OBJECT (widget), "events");
8412 }
8413
8414 /**
8415  * gtk_widget_set_device_events:
8416  * @widget: a #GtkWidget
8417  * @device: a #GdkDevice
8418  * @events: event mask
8419  *
8420  * Sets the device event mask (see #GdkEventMask) for a widget. The event
8421  * mask determines which events a widget will receive from @device. Keep
8422  * in mind that different widgets have different default event masks, and by
8423  * changing the event mask you may disrupt a widget's functionality,
8424  * so be careful. This function must be called while a widget is
8425  * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8426  * already realized, or if you want to preserve the existing event
8427  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8428  * to get events on those widgets, place them inside a #GtkEventBox
8429  * and receive events on the event box.
8430  *
8431  * Since: 3.0
8432  **/
8433 void
8434 gtk_widget_set_device_events (GtkWidget    *widget,
8435                               GdkDevice    *device,
8436                               GdkEventMask  events)
8437 {
8438   GHashTable *device_events;
8439
8440   g_return_if_fail (GTK_IS_WIDGET (widget));
8441   g_return_if_fail (GDK_IS_DEVICE (device));
8442   g_return_if_fail (!gtk_widget_get_realized (widget));
8443
8444   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8445
8446   if (G_UNLIKELY (!device_events))
8447     {
8448       device_events = g_hash_table_new (NULL, NULL);
8449       g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8450                                (GDestroyNotify) g_hash_table_unref);
8451     }
8452
8453   g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8454 }
8455
8456 static void
8457 gtk_widget_add_events_internal_list (GtkWidget *widget,
8458                                      GdkDevice *device,
8459                                      gint       events,
8460                                      GList     *window_list)
8461 {
8462   GList *l;
8463
8464   for (l = window_list; l != NULL; l = l->next)
8465     {
8466       GdkWindow *window = l->data;
8467       gpointer user_data;
8468
8469       gdk_window_get_user_data (window, &user_data);
8470       if (user_data == widget)
8471         {
8472           GList *children;
8473
8474           if (device)
8475             gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8476           else
8477             gdk_window_set_events (window, gdk_window_get_events (window) | events);
8478
8479           children = gdk_window_get_children (window);
8480           gtk_widget_add_events_internal_list (widget, device, events, children);
8481           g_list_free (children);
8482         }
8483     }
8484 }
8485
8486 static void
8487 gtk_widget_add_events_internal (GtkWidget *widget,
8488                                 GdkDevice *device,
8489                                 gint       events)
8490 {
8491   GtkWidgetPrivate *priv = widget->priv;
8492   GList *window_list;
8493
8494   if (!gtk_widget_get_has_window (widget))
8495     window_list = gdk_window_get_children (priv->window);
8496   else
8497     window_list = g_list_prepend (NULL, priv->window);
8498
8499   gtk_widget_add_events_internal_list (widget, device, events, window_list);
8500
8501   g_list_free (window_list);
8502 }
8503
8504 /**
8505  * gtk_widget_add_events:
8506  * @widget: a #GtkWidget
8507  * @events: an event mask, see #GdkEventMask
8508  *
8509  * Adds the events in the bitfield @events to the event mask for
8510  * @widget. See gtk_widget_set_events() for details.
8511  **/
8512 void
8513 gtk_widget_add_events (GtkWidget *widget,
8514                        gint       events)
8515 {
8516   gint old_events;
8517
8518   g_return_if_fail (GTK_IS_WIDGET (widget));
8519
8520   old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8521   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8522                       GINT_TO_POINTER (old_events | events));
8523
8524   if (gtk_widget_get_realized (widget))
8525     gtk_widget_add_events_internal (widget, NULL, events);
8526
8527   g_object_notify (G_OBJECT (widget), "events");
8528 }
8529
8530 /**
8531  * gtk_widget_add_device_events:
8532  * @widget: a #GtkWidget
8533  * @device: a #GdkDevice
8534  * @events: an event mask, see #GdkEventMask
8535  *
8536  * Adds the device events in the bitfield @events to the event mask for
8537  * @widget. See gtk_widget_set_device_events() for details.
8538  *
8539  * Since: 3.0
8540  **/
8541 void
8542 gtk_widget_add_device_events (GtkWidget    *widget,
8543                               GdkDevice    *device,
8544                               GdkEventMask  events)
8545 {
8546   GdkEventMask old_events;
8547   GHashTable *device_events;
8548
8549   g_return_if_fail (GTK_IS_WIDGET (widget));
8550   g_return_if_fail (GDK_IS_DEVICE (device));
8551
8552   old_events = gtk_widget_get_device_events (widget, device);
8553
8554   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8555
8556   if (G_UNLIKELY (!device_events))
8557     {
8558       device_events = g_hash_table_new (NULL, NULL);
8559       g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8560                                (GDestroyNotify) g_hash_table_unref);
8561     }
8562
8563   g_hash_table_insert (device_events, device,
8564                        GUINT_TO_POINTER (old_events | events));
8565
8566   if (gtk_widget_get_realized (widget))
8567     gtk_widget_add_events_internal (widget, device, events);
8568
8569   g_object_notify (G_OBJECT (widget), "events");
8570 }
8571
8572 /**
8573  * gtk_widget_set_extension_events:
8574  * @widget: a #GtkWidget
8575  * @mode: bitfield of extension events to receive
8576  *
8577  * Sets the extension events mask to @mode. See #GdkExtensionMode
8578  * and gdk_input_set_extension_events().
8579  **/
8580 void
8581 gtk_widget_set_extension_events (GtkWidget *widget,
8582                                  GdkExtensionMode mode)
8583 {
8584   g_return_if_fail (GTK_IS_WIDGET (widget));
8585
8586   if (gtk_widget_get_realized (widget))
8587     gtk_widget_set_extension_events_internal (widget, mode, NULL);
8588
8589   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8590                       GINT_TO_POINTER (mode));
8591   g_object_notify (G_OBJECT (widget), "extension-events");
8592 }
8593
8594 /**
8595  * gtk_widget_get_toplevel:
8596  * @widget: a #GtkWidget
8597  * 
8598  * This function returns the topmost widget in the container hierarchy
8599  * @widget is a part of. If @widget has no parent widgets, it will be
8600  * returned as the topmost widget. No reference will be added to the
8601  * returned widget; it should not be unreferenced.
8602  *
8603  * Note the difference in behavior vs. gtk_widget_get_ancestor();
8604  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
8605  * would return
8606  * %NULL if @widget wasn't inside a toplevel window, and if the
8607  * window was inside a #GtkWindow-derived widget which was in turn
8608  * inside the toplevel #GtkWindow. While the second case may
8609  * seem unlikely, it actually happens when a #GtkPlug is embedded
8610  * inside a #GtkSocket within the same application.
8611  * 
8612  * To reliably find the toplevel #GtkWindow, use
8613  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8614  * is set on the result.
8615  * |[
8616  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8617  *  if (gtk_widget_is_toplevel (toplevel))
8618  *    {
8619  *      /&ast; Perform action on toplevel. &ast;/
8620  *    }
8621  * ]|
8622  *
8623  * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8624  *    if there's no ancestor.
8625  **/
8626 GtkWidget*
8627 gtk_widget_get_toplevel (GtkWidget *widget)
8628 {
8629   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8630
8631   while (widget->priv->parent)
8632     widget = widget->priv->parent;
8633
8634   return widget;
8635 }
8636
8637 /**
8638  * gtk_widget_get_ancestor:
8639  * @widget: a #GtkWidget
8640  * @widget_type: ancestor type
8641  * 
8642  * Gets the first ancestor of @widget with type @widget_type. For example,
8643  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets 
8644  * the first #GtkBox that's an ancestor of @widget. No reference will be 
8645  * added to the returned widget; it should not be unreferenced. See note 
8646  * about checking for a toplevel #GtkWindow in the docs for 
8647  * gtk_widget_get_toplevel().
8648  * 
8649  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
8650  * considers @widget to be an ancestor of itself.
8651  *
8652  * Return value: (transfer none): the ancestor widget, or %NULL if not found
8653  **/
8654 GtkWidget*
8655 gtk_widget_get_ancestor (GtkWidget *widget,
8656                          GType      widget_type)
8657 {
8658   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8659
8660   while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8661     widget = widget->priv->parent;
8662
8663   if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8664     return NULL;
8665   
8666   return widget;
8667 }
8668
8669 /**
8670  * gtk_widget_get_colormap:
8671  * @widget: a #GtkWidget
8672  * 
8673  * Gets the colormap that will be used to render @widget. No reference will
8674  * be added to the returned colormap; it should not be unreferenced.
8675  *
8676  * Return value: (transfer none): the colormap used by @widget
8677  **/
8678 GdkColormap*
8679 gtk_widget_get_colormap (GtkWidget *widget)
8680 {
8681   GtkWidgetPrivate *priv;
8682   GdkColormap *colormap;
8683   GtkWidget *tmp_widget;
8684   
8685   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8686
8687   priv = widget->priv;
8688
8689   if (priv->window)
8690     {
8691       colormap = gdk_drawable_get_colormap (priv->window);
8692       /* If window was destroyed previously, we'll get NULL here */
8693       if (colormap)
8694         return colormap;
8695     }
8696
8697   tmp_widget = widget;
8698   while (tmp_widget)
8699     {
8700       colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8701       if (colormap)
8702         return colormap;
8703
8704       tmp_widget= tmp_widget->priv->parent;
8705     }
8706
8707   return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8708 }
8709
8710 /**
8711  * gtk_widget_get_visual:
8712  * @widget: a #GtkWidget
8713  * 
8714  * Gets the visual that will be used to render @widget.
8715  *
8716  * Return value: (transfer none): the visual for @widget
8717  **/
8718 GdkVisual*
8719 gtk_widget_get_visual (GtkWidget *widget)
8720 {
8721   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8722
8723   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8724 }
8725
8726 /**
8727  * gtk_widget_get_settings:
8728  * @widget: a #GtkWidget
8729  * 
8730  * Gets the settings object holding the settings (global property
8731  * settings, RC file information, etc) used for this widget.
8732  *
8733  * Note that this function can only be called when the #GtkWidget
8734  * is attached to a toplevel, since the settings object is specific
8735  * to a particular #GdkScreen.
8736  *
8737  * Return value: (transfer none): the relevant #GtkSettings object
8738  **/
8739 GtkSettings*
8740 gtk_widget_get_settings (GtkWidget *widget)
8741 {
8742   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8743   
8744   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8745 }
8746
8747 /**
8748  * gtk_widget_set_colormap:
8749  * @widget: a #GtkWidget
8750  * @colormap: a colormap
8751  *
8752  * Sets the colormap for the widget to the given value. Widget must not
8753  * have been previously realized. This probably should only be used
8754  * from an <function>init()</function> function (i.e. from the constructor 
8755  * for the widget).
8756  **/
8757 void
8758 gtk_widget_set_colormap (GtkWidget   *widget,
8759                          GdkColormap *colormap)
8760 {
8761   g_return_if_fail (GTK_IS_WIDGET (widget));
8762   g_return_if_fail (!gtk_widget_get_realized (widget));
8763   g_return_if_fail (GDK_IS_COLORMAP (colormap));
8764
8765   g_object_ref (colormap);
8766   
8767   g_object_set_qdata_full (G_OBJECT (widget), 
8768                            quark_colormap,
8769                            colormap,
8770                            g_object_unref);
8771 }
8772
8773 /**
8774  * gtk_widget_get_events:
8775  * @widget: a #GtkWidget
8776  * 
8777  * Returns the event mask for the widget (a bitfield containing flags
8778  * from the #GdkEventMask enumeration). These are the events that the widget
8779  * will receive.
8780  * 
8781  * Return value: event mask for @widget
8782  **/
8783 gint
8784 gtk_widget_get_events (GtkWidget *widget)
8785 {
8786   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8787
8788   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8789 }
8790
8791 /**
8792  * gtk_widget_get_device_events:
8793  * @widget: a #GtkWidget
8794  * @device: a #GdkDevice
8795  *
8796  * Returns the events mask for the widget corresponding to an specific device. These
8797  * are the events that the widget will receive when @device operates on it.
8798  *
8799  * Returns: device event mask for @widget
8800  *
8801  * Since: 3.0
8802  **/
8803 GdkEventMask
8804 gtk_widget_get_device_events (GtkWidget *widget,
8805                               GdkDevice *device)
8806 {
8807   GHashTable *device_events;
8808
8809   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8810   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8811
8812   device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8813
8814   if (!device_events)
8815     return 0;
8816
8817   return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8818 }
8819
8820 /**
8821  * gtk_widget_get_extension_events:
8822  * @widget: a #GtkWidget
8823  * 
8824  * Retrieves the extension events the widget will receive; see
8825  * gdk_input_set_extension_events().
8826  * 
8827  * Return value: extension events for @widget
8828  **/
8829 GdkExtensionMode
8830 gtk_widget_get_extension_events (GtkWidget *widget)
8831 {
8832   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8833
8834   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8835 }
8836
8837 /**
8838  * gtk_widget_get_pointer:
8839  * @widget: a #GtkWidget
8840  * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8841  * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8842  *
8843  * Obtains the location of the mouse pointer in widget coordinates.
8844  * Widget coordinates are a bit odd; for historical reasons, they are
8845  * defined as @widget->window coordinates for widgets that are not
8846  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8847  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8848  **/
8849 void
8850 gtk_widget_get_pointer (GtkWidget *widget,
8851                         gint      *x,
8852                         gint      *y)
8853 {
8854   GtkWidgetPrivate *priv;
8855
8856   g_return_if_fail (GTK_IS_WIDGET (widget));
8857
8858   priv = widget->priv;
8859
8860   if (x)
8861     *x = -1;
8862   if (y)
8863     *y = -1;
8864   
8865   if (gtk_widget_get_realized (widget))
8866     {
8867       gdk_window_get_pointer (priv->window, x, y, NULL);
8868
8869       if (!gtk_widget_get_has_window (widget))
8870         {
8871           if (x)
8872             *x -= priv->allocation.x;
8873           if (y)
8874             *y -= priv->allocation.y;
8875         }
8876     }
8877 }
8878
8879 /**
8880  * gtk_widget_is_ancestor:
8881  * @widget: a #GtkWidget
8882  * @ancestor: another #GtkWidget
8883  * 
8884  * Determines whether @widget is somewhere inside @ancestor, possibly with
8885  * intermediate containers.
8886  * 
8887  * Return value: %TRUE if @ancestor contains @widget as a child, 
8888  *    grandchild, great grandchild, etc.
8889  **/
8890 gboolean
8891 gtk_widget_is_ancestor (GtkWidget *widget,
8892                         GtkWidget *ancestor)
8893 {
8894   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8895   g_return_val_if_fail (ancestor != NULL, FALSE);
8896
8897   while (widget)
8898     {
8899       if (widget->priv->parent == ancestor)
8900         return TRUE;
8901       widget = widget->priv->parent;
8902     }
8903   
8904   return FALSE;
8905 }
8906
8907 static GQuark quark_composite_name = 0;
8908
8909 /**
8910  * gtk_widget_set_composite_name:
8911  * @widget: a #GtkWidget.
8912  * @name: the name to set
8913  * 
8914  * Sets a widgets composite name. The widget must be
8915  * a composite child of its parent; see gtk_widget_push_composite_child().
8916  **/
8917 void
8918 gtk_widget_set_composite_name (GtkWidget   *widget,
8919                                const gchar *name)
8920 {
8921   g_return_if_fail (GTK_IS_WIDGET (widget));
8922   g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8923   g_return_if_fail (name != NULL);
8924
8925   if (!quark_composite_name)
8926     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8927
8928   g_object_set_qdata_full (G_OBJECT (widget),
8929                            quark_composite_name,
8930                            g_strdup (name),
8931                            g_free);
8932 }
8933
8934 /**
8935  * gtk_widget_get_composite_name:
8936  * @widget: a #GtkWidget
8937  *
8938  * Obtains the composite name of a widget. 
8939  *
8940  * Returns: the composite name of @widget, or %NULL if @widget is not
8941  *   a composite child. The string should be freed when it is no 
8942  *   longer needed.
8943  **/
8944 gchar*
8945 gtk_widget_get_composite_name (GtkWidget *widget)
8946 {
8947   GtkWidgetPrivate *priv;
8948
8949   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8950
8951   priv = widget->priv;
8952
8953   if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
8954     return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
8955                                                widget);
8956   else
8957     return NULL;
8958 }
8959
8960 /**
8961  * gtk_widget_push_composite_child:
8962  * 
8963  * Makes all newly-created widgets as composite children until
8964  * the corresponding gtk_widget_pop_composite_child() call.
8965  * 
8966  * A composite child is a child that's an implementation detail of the
8967  * container it's inside and should not be visible to people using the
8968  * container. Composite children aren't treated differently by GTK (but
8969  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
8970  * builders might want to treat them in a different way.
8971  * 
8972  * Here is a simple example:
8973  * |[
8974  *   gtk_widget_push_composite_child ();
8975  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8976  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8977  *   gtk_widget_pop_composite_child ();
8978  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
8979  *                          GTK_WIDGET (scrolled_window));
8980  *   g_object_ref (scrolled_window->hscrollbar);
8981  * ]|
8982  **/
8983 void
8984 gtk_widget_push_composite_child (void)
8985 {
8986   composite_child_stack++;
8987 }
8988
8989 /**
8990  * gtk_widget_pop_composite_child:
8991  *
8992  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8993  **/ 
8994 void
8995 gtk_widget_pop_composite_child (void)
8996 {
8997   if (composite_child_stack)
8998     composite_child_stack--;
8999 }
9000
9001 /**
9002  * gtk_widget_push_colormap:
9003  * @cmap: a #GdkColormap
9004  *
9005  * Pushes @cmap onto a global stack of colormaps; the topmost
9006  * colormap on the stack will be used to create all widgets.
9007  * Remove @cmap with gtk_widget_pop_colormap(). There's little
9008  * reason to use this function.
9009  **/
9010 void
9011 gtk_widget_push_colormap (GdkColormap *cmap)
9012 {
9013   g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
9014
9015   colormap_stack = g_slist_prepend (colormap_stack, cmap);
9016 }
9017
9018 /**
9019  * gtk_widget_pop_colormap:
9020  *
9021  * Removes a colormap pushed with gtk_widget_push_colormap().
9022  **/
9023 void
9024 gtk_widget_pop_colormap (void)
9025 {
9026   if (colormap_stack)
9027     colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
9028 }
9029
9030 /**
9031  * gtk_widget_set_default_colormap:
9032  * @colormap: a #GdkColormap
9033  * 
9034  * Sets the default colormap to use when creating widgets.
9035  * gtk_widget_push_colormap() is a better function to use if
9036  * you only want to affect a few widgets, rather than all widgets.
9037  **/
9038 void
9039 gtk_widget_set_default_colormap (GdkColormap *colormap)
9040 {
9041   g_return_if_fail (GDK_IS_COLORMAP (colormap));
9042   
9043   gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
9044                                    colormap);
9045 }
9046
9047 /**
9048  * gtk_widget_get_default_colormap:
9049  * 
9050  * Obtains the default colormap used to create widgets.
9051  *
9052  * Return value: (transfer none): default widget colormap
9053  **/
9054 GdkColormap*
9055 gtk_widget_get_default_colormap (void)
9056 {
9057   return gdk_screen_get_default_colormap (gdk_screen_get_default ());
9058 }
9059
9060 /**
9061  * gtk_widget_get_default_visual:
9062  * 
9063  * Obtains the visual of the default colormap. Not really useful;
9064  * used to be useful before gdk_colormap_get_visual() existed.
9065  *
9066  * Return value: (transfer none): visual of the default colormap
9067  **/
9068 GdkVisual*
9069 gtk_widget_get_default_visual (void)
9070 {
9071   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
9072 }
9073
9074 static void
9075 gtk_widget_emit_direction_changed (GtkWidget        *widget,
9076                                    GtkTextDirection  old_dir)
9077 {
9078   gtk_widget_update_pango_context (widget);
9079   
9080   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9081 }
9082
9083 /**
9084  * gtk_widget_set_direction:
9085  * @widget: a #GtkWidget
9086  * @dir:    the new direction
9087  * 
9088  * Sets the reading direction on a particular widget. This direction
9089  * controls the primary direction for widgets containing text,
9090  * and also the direction in which the children of a container are
9091  * packed. The ability to set the direction is present in order
9092  * so that correct localization into languages with right-to-left
9093  * reading directions can be done. Generally, applications will
9094  * let the default reading direction present, except for containers
9095  * where the containers are arranged in an order that is explicitely
9096  * visual rather than logical (such as buttons for text justification).
9097  *
9098  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9099  * set by gtk_widget_set_default_direction() will be used.
9100  **/
9101 void
9102 gtk_widget_set_direction (GtkWidget        *widget,
9103                           GtkTextDirection  dir)
9104 {
9105   GtkTextDirection old_dir;
9106   
9107   g_return_if_fail (GTK_IS_WIDGET (widget));
9108   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9109
9110   old_dir = gtk_widget_get_direction (widget);
9111   
9112   if (dir == GTK_TEXT_DIR_NONE)
9113     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9114   else
9115     {
9116       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9117       if (dir == GTK_TEXT_DIR_LTR)
9118         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9119       else
9120         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9121     }
9122
9123   if (old_dir != gtk_widget_get_direction (widget))
9124     gtk_widget_emit_direction_changed (widget, old_dir);
9125 }
9126
9127 /**
9128  * gtk_widget_get_direction:
9129  * @widget: a #GtkWidget
9130  * 
9131  * Gets the reading direction for a particular widget. See
9132  * gtk_widget_set_direction().
9133  * 
9134  * Return value: the reading direction for the widget.
9135  **/
9136 GtkTextDirection
9137 gtk_widget_get_direction (GtkWidget *widget)
9138 {
9139   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9140   
9141   if (GTK_WIDGET_DIRECTION_SET (widget))
9142     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9143   else
9144     return gtk_default_direction;
9145 }
9146
9147 static void
9148 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9149 {
9150   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9151
9152   g_object_ref (widget);
9153   
9154   if (!GTK_WIDGET_DIRECTION_SET (widget))
9155     gtk_widget_emit_direction_changed (widget, old_dir);
9156   
9157   if (GTK_IS_CONTAINER (widget))
9158     gtk_container_forall (GTK_CONTAINER (widget),
9159                           gtk_widget_set_default_direction_recurse,
9160                           data);
9161
9162   g_object_unref (widget);
9163 }
9164
9165 /**
9166  * gtk_widget_set_default_direction:
9167  * @dir: the new default direction. This cannot be
9168  *        %GTK_TEXT_DIR_NONE.
9169  * 
9170  * Sets the default reading direction for widgets where the
9171  * direction has not been explicitly set by gtk_widget_set_direction().
9172  **/
9173 void
9174 gtk_widget_set_default_direction (GtkTextDirection dir)
9175 {
9176   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9177
9178   if (dir != gtk_default_direction)
9179     {
9180       GList *toplevels, *tmp_list;
9181       GtkTextDirection old_dir = gtk_default_direction;
9182       
9183       gtk_default_direction = dir;
9184
9185       tmp_list = toplevels = gtk_window_list_toplevels ();
9186       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9187       
9188       while (tmp_list)
9189         {
9190           gtk_widget_set_default_direction_recurse (tmp_list->data,
9191                                                     GUINT_TO_POINTER (old_dir));
9192           g_object_unref (tmp_list->data);
9193           tmp_list = tmp_list->next;
9194         }
9195
9196       g_list_free (toplevels);
9197     }
9198 }
9199
9200 /**
9201  * gtk_widget_get_default_direction:
9202  * 
9203  * Obtains the current default reading direction. See
9204  * gtk_widget_set_default_direction().
9205  *
9206  * Return value: the current default direction. 
9207  **/
9208 GtkTextDirection
9209 gtk_widget_get_default_direction (void)
9210 {
9211   return gtk_default_direction;
9212 }
9213
9214 static void
9215 gtk_widget_dispose (GObject *object)
9216 {
9217   GtkWidget *widget = GTK_WIDGET (object);
9218   GtkWidgetPrivate *priv = widget->priv;
9219
9220   if (priv->parent)
9221     gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9222   else if (gtk_widget_get_visible (widget))
9223     gtk_widget_hide (widget);
9224
9225   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9226   if (gtk_widget_get_realized (widget))
9227     gtk_widget_unrealize (widget);
9228   
9229   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9230 }
9231
9232 static void
9233 gtk_widget_real_destroy (GtkObject *object)
9234 {
9235   /* gtk_object_destroy() will already hold a refcount on object */
9236   GtkWidget *widget = GTK_WIDGET (object);
9237   GtkWidgetPrivate *priv = widget->priv;
9238
9239   /* wipe accelerator closures (keep order) */
9240   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9241   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9242
9243   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9244   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9245   
9246   gtk_grab_remove (widget);
9247
9248   g_object_unref (priv->style);
9249   priv->style = gtk_widget_get_default_style ();
9250   g_object_ref (priv->style);
9251
9252   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9253 }
9254
9255 static void
9256 gtk_widget_finalize (GObject *object)
9257 {
9258   GtkWidget *widget = GTK_WIDGET (object);
9259   GtkWidgetPrivate *priv = widget->priv;
9260   GtkWidgetAuxInfo *aux_info;
9261   GtkAccessible *accessible;
9262   
9263   gtk_grab_remove (widget);
9264
9265   g_object_unref (priv->style);
9266   priv->style = NULL;
9267
9268   g_free (priv->name);
9269   
9270   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9271   if (aux_info)
9272     gtk_widget_aux_info_destroy (aux_info);
9273
9274   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9275   if (accessible)
9276     g_object_unref (accessible);
9277
9278   G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9279 }
9280
9281 /*****************************************
9282  * gtk_widget_real_map:
9283  *
9284  *   arguments:
9285  *
9286  *   results:
9287  *****************************************/
9288
9289 static void
9290 gtk_widget_real_map (GtkWidget *widget)
9291 {
9292   GtkWidgetPrivate *priv = widget->priv;
9293
9294   g_assert (gtk_widget_get_realized (widget));
9295   
9296   if (!gtk_widget_get_mapped (widget))
9297     {
9298       gtk_widget_set_mapped (widget, TRUE);
9299       
9300       if (gtk_widget_get_has_window (widget))
9301         gdk_window_show (priv->window);
9302     }
9303 }
9304
9305 /*****************************************
9306  * gtk_widget_real_unmap:
9307  *
9308  *   arguments:
9309  *
9310  *   results:
9311  *****************************************/
9312
9313 static void
9314 gtk_widget_real_unmap (GtkWidget *widget)
9315 {
9316   GtkWidgetPrivate *priv = widget->priv;
9317
9318   if (gtk_widget_get_mapped (widget))
9319     {
9320       gtk_widget_set_mapped (widget, FALSE);
9321
9322       if (gtk_widget_get_has_window (widget))
9323         gdk_window_hide (priv->window);
9324     }
9325 }
9326
9327 /*****************************************
9328  * gtk_widget_real_realize:
9329  *
9330  *   arguments:
9331  *
9332  *   results:
9333  *****************************************/
9334
9335 static void
9336 gtk_widget_real_realize (GtkWidget *widget)
9337 {
9338   GtkWidgetPrivate *priv = widget->priv;
9339
9340   g_assert (!gtk_widget_get_has_window (widget));
9341   
9342   gtk_widget_set_realized (widget, TRUE);
9343   if (priv->parent)
9344     {
9345       priv->window = gtk_widget_get_parent_window (widget);
9346       g_object_ref (priv->window);
9347     }
9348   priv->style = gtk_style_attach (priv->style, priv->window);
9349 }
9350
9351 /*****************************************
9352  * gtk_widget_real_unrealize:
9353  *
9354  *   arguments:
9355  *
9356  *   results:
9357  *****************************************/
9358
9359 static void
9360 gtk_widget_real_unrealize (GtkWidget *widget)
9361 {
9362   GtkWidgetPrivate *priv = widget->priv;
9363
9364   if (gtk_widget_get_mapped (widget))
9365     gtk_widget_real_unmap (widget);
9366
9367   gtk_widget_set_mapped (widget, FALSE);
9368
9369   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9370    */
9371
9372    /* We must do unrealize child widget BEFORE container widget.
9373     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9374     * So, unrealizing container widget bofore its children causes the problem 
9375     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9376     */
9377
9378   if (GTK_IS_CONTAINER (widget))
9379     gtk_container_forall (GTK_CONTAINER (widget),
9380                           (GtkCallback) gtk_widget_unrealize,
9381                           NULL);
9382
9383   gtk_style_detach (priv->style);
9384   if (gtk_widget_get_has_window (widget))
9385     {
9386       gdk_window_set_user_data (priv->window, NULL);
9387       gdk_window_destroy (priv->window);
9388       priv->window = NULL;
9389     }
9390   else
9391     {
9392       g_object_unref (priv->window);
9393       priv->window = NULL;
9394     }
9395
9396   gtk_selection_remove_all (widget);
9397   
9398   gtk_widget_set_realized (widget, FALSE);
9399 }
9400
9401 static void
9402 gtk_widget_real_size_request (GtkWidget         *widget,
9403                               GtkRequisition    *requisition)
9404 {
9405   requisition->width  = 0;
9406   requisition->height = 0;
9407 }
9408
9409 static void
9410 gtk_widget_real_adjust_size_request (GtkWidget         *widget,
9411                                      GtkOrientation     orientation,
9412                                      gint               for_size,
9413                                      gint              *minimum_size,
9414                                      gint              *natural_size)
9415 {
9416   const GtkWidgetAuxInfo *aux_info;
9417
9418   aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9419
9420   if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9421       aux_info->width > 0)
9422     {
9423       *minimum_size = MAX (*minimum_size, aux_info->width);
9424     }
9425   else if (orientation == GTK_ORIENTATION_VERTICAL &&
9426            aux_info->height > 0)
9427     {
9428       *minimum_size = MAX (*minimum_size, aux_info->height);
9429     }
9430
9431   /* Fix it if set_size_request made natural size smaller than min size.
9432    * This would also silently fix broken widgets, but we warn about them
9433    * in gtksizerequest.c when calling their size request vfuncs.
9434    */
9435   *natural_size = MAX (*natural_size, *minimum_size);
9436
9437   if (orientation == GTK_ORIENTATION_HORIZONTAL)
9438     {
9439       *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9440       *natural_size += (aux_info->margin.left + aux_info->margin.right);
9441     }
9442   else
9443     {
9444       *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9445       *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9446     }
9447 }
9448
9449 /**
9450  * _gtk_widget_peek_colormap:
9451  * 
9452  * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
9453  * 
9454  * Return value: the currently pushed colormap, or %NULL if there is none.
9455  **/
9456 GdkColormap*
9457 _gtk_widget_peek_colormap (void)
9458 {
9459   if (colormap_stack)
9460     return (GdkColormap*) colormap_stack->data;
9461   return NULL;
9462 }
9463
9464 /**
9465  * _gtk_widget_peek_request_cache:
9466  * 
9467  * Returns the address of the widget's request cache (strictly for
9468  * internal use in gtksizerequest.c)
9469  * 
9470  * Return value: the address of @widget's size request cache.
9471  **/
9472 gpointer
9473 _gtk_widget_peek_request_cache (GtkWidget *widget)
9474 {
9475   /* Don't bother slowing things down with the return_if_fail guards here */
9476   return &widget->priv->requests;
9477 }
9478
9479 /*
9480  * _gtk_widget_set_device_window:
9481  * @widget: a #GtkWidget.
9482  * @device: a #GdkDevice.
9483  * @window: the new device window.
9484  *
9485  * Sets pointer window for @widget and @device.  Does not ref @window.
9486  * Actually stores it on the #GdkScreen, but you don't need to know that.
9487  */
9488 void
9489 _gtk_widget_set_device_window (GtkWidget *widget,
9490                                GdkDevice *device,
9491                                GdkWindow *window)
9492 {
9493   GtkWidgetPrivate *priv;
9494   GdkScreen *screen;
9495   GHashTable *device_window;
9496
9497   g_return_if_fail (GTK_IS_WIDGET (widget));
9498   g_return_if_fail (GDK_IS_DEVICE (device));
9499   g_return_if_fail (!window || GDK_IS_WINDOW (window));
9500
9501   priv = widget->priv;
9502
9503   if (!gtk_widget_get_realized (widget))
9504     return;
9505
9506   screen = gdk_drawable_get_screen (priv->window);
9507   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9508
9509   if (G_UNLIKELY (!device_window))
9510     {
9511       device_window = g_hash_table_new (NULL, NULL);
9512       g_object_set_qdata_full (G_OBJECT (screen),
9513                                quark_pointer_window,
9514                                device_window,
9515                                (GDestroyNotify) g_hash_table_destroy);
9516     }
9517
9518   if (window)
9519     g_hash_table_insert (device_window, device, window);
9520   else
9521     g_hash_table_remove (device_window, device);
9522 }
9523
9524 /*
9525  * _gtk_widget_get_device_window:
9526  * @widget: a #GtkWidget.
9527  * @device: a #GdkDevice.
9528  *
9529  * Return value: the device window set on the #GdkScreen @widget is attached
9530  * to, or %NULL.
9531  */
9532 GdkWindow *
9533 _gtk_widget_get_device_window (GtkWidget *widget,
9534                                GdkDevice *device)
9535 {
9536   GtkWidgetPrivate *priv;
9537   GdkScreen *screen;
9538   GHashTable *device_window;
9539   GdkWindow *window;
9540   GtkWidget *w;
9541
9542   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9543   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9544
9545   priv = widget->priv;
9546
9547   if (!gtk_widget_get_realized (widget))
9548     return NULL;
9549
9550   screen = gdk_drawable_get_screen (priv->window);
9551   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9552
9553   if (G_UNLIKELY (!device_window))
9554     return NULL;
9555
9556   window = g_hash_table_lookup (device_window, device);
9557
9558   if (!window)
9559     return NULL;
9560
9561   gdk_window_get_user_data (window, (gpointer *) &w);
9562
9563   if (widget != w)
9564     return NULL;
9565
9566   return window;
9567 }
9568
9569 /*
9570  * _gtk_widget_list_devices:
9571  * @widget: a #GtkWidget.
9572  *
9573  * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9574  * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9575  * be freed.
9576  */
9577 GList *
9578 _gtk_widget_list_devices (GtkWidget *widget)
9579 {
9580   GtkWidgetPrivate *priv;
9581   GdkScreen *screen;
9582   GHashTableIter iter;
9583   GHashTable *device_window;
9584   GList *devices = NULL;
9585   gpointer key, value;
9586
9587   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9588
9589   priv = widget->priv;
9590
9591   if (!gtk_widget_get_realized (widget))
9592     return NULL;
9593
9594   screen = gdk_drawable_get_screen (priv->window);
9595   device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9596
9597   if (G_UNLIKELY (!device_window))
9598     return NULL;
9599
9600   g_hash_table_iter_init (&iter, device_window);
9601
9602   while (g_hash_table_iter_next (&iter, &key, &value))
9603     {
9604       GdkDevice *device = key;
9605       GdkWindow *window = value;
9606       GtkWidget *w;
9607
9608       if (window)
9609         {
9610           gdk_window_get_user_data (window, (gpointer *) &w);
9611
9612           if (widget == w)
9613             devices = g_list_prepend (devices, device);
9614         }
9615     }
9616
9617   return devices;
9618 }
9619
9620 static void
9621 synth_crossing (GtkWidget       *widget,
9622                 GdkEventType     type,
9623                 GdkWindow       *window,
9624                 GdkDevice       *device,
9625                 GdkCrossingMode  mode,
9626                 GdkNotifyType    detail)
9627 {
9628   GdkEvent *event;
9629
9630   event = gdk_event_new (type);
9631
9632   event->crossing.window = g_object_ref (window);
9633   event->crossing.send_event = TRUE;
9634   event->crossing.subwindow = g_object_ref (window);
9635   event->crossing.time = GDK_CURRENT_TIME;
9636   event->crossing.x = event->crossing.y = 0;
9637   event->crossing.x_root = event->crossing.y_root = 0;
9638   event->crossing.mode = mode;
9639   event->crossing.detail = detail;
9640   event->crossing.focus = FALSE;
9641   event->crossing.state = 0;
9642   gdk_event_set_device (event, device);
9643
9644   if (!widget)
9645     widget = gtk_get_event_widget (event);
9646
9647   if (widget)
9648     gtk_widget_event_internal (widget, event);
9649
9650   gdk_event_free (event);
9651 }
9652
9653 /*
9654  * _gtk_widget_synthesize_crossing:
9655  * @from: the #GtkWidget the virtual pointer is leaving.
9656  * @to: the #GtkWidget the virtual pointer is moving to.
9657  * @mode: the #GdkCrossingMode to place on the synthesized events.
9658  *
9659  * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9660  *
9661  * The real pointer window is the window that most recently received an enter notify
9662  * event.  Windows that don't select for crossing events can't become the real
9663  * poiner window.  The real pointer widget that owns the real pointer window.  The
9664  * effective pointer window is the same as the real pointer window unless the real
9665  * pointer widget is either insensitive or there is a grab on a widget that is not
9666  * an ancestor of the real pointer widget (in which case the effective pointer
9667  * window should be the root window).
9668  *
9669  * When the effective pointer window is the same as the real poiner window, we
9670  * receive crossing events from the windowing system.  When the effective pointer
9671  * window changes to become different from the real pointer window we synthesize
9672  * crossing events, attempting to follow X protocol rules:
9673  *
9674  * When the root window becomes the effective pointer window:
9675  *   - leave notify on real pointer window, detail Ancestor
9676  *   - leave notify on all of its ancestors, detail Virtual
9677  *   - enter notify on root window, detail Inferior
9678  *
9679  * When the root window ceases to be the effective pointer window:
9680  *   - leave notify on root window, detail Inferior
9681  *   - enter notify on all ancestors of real pointer window, detail Virtual
9682  *   - enter notify on real pointer window, detail Ancestor
9683  */
9684 void
9685 _gtk_widget_synthesize_crossing (GtkWidget       *from,
9686                                  GtkWidget       *to,
9687                                  GdkDevice       *device,
9688                                  GdkCrossingMode  mode)
9689 {
9690   GdkWindow *from_window = NULL, *to_window = NULL;
9691
9692   g_return_if_fail (from != NULL || to != NULL);
9693
9694   if (from != NULL)
9695     {
9696       from_window = _gtk_widget_get_device_window (from, device);
9697
9698       if (!from_window)
9699         from_window = from->priv->window;
9700     }
9701
9702   if (to != NULL)
9703     {
9704       to_window = _gtk_widget_get_device_window (to, device);
9705
9706       if (!to_window)
9707         to_window = to->priv->window;
9708     }
9709
9710   if (from_window == NULL && to_window == NULL)
9711     ;
9712   else if (from_window != NULL && to_window == NULL)
9713     {
9714       GList *from_ancestors = NULL, *list;
9715       GdkWindow *from_ancestor = from_window;
9716
9717       while (from_ancestor != NULL)
9718         {
9719           from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9720           if (from_ancestor == NULL)
9721             break;
9722           from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9723         }
9724
9725       synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9726                       device, mode, GDK_NOTIFY_ANCESTOR);
9727       for (list = g_list_last (from_ancestors); list; list = list->prev)
9728         {
9729           synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9730                           device, mode, GDK_NOTIFY_VIRTUAL);
9731         }
9732
9733       /* XXX: enter/inferior on root window? */
9734
9735       g_list_free (from_ancestors);
9736     }
9737   else if (from_window == NULL && to_window != NULL)
9738     {
9739       GList *to_ancestors = NULL, *list;
9740       GdkWindow *to_ancestor = to_window;
9741
9742       while (to_ancestor != NULL)
9743         {
9744           to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9745           if (to_ancestor == NULL)
9746             break;
9747           to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9748         }
9749
9750       /* XXX: leave/inferior on root window? */
9751
9752       for (list = to_ancestors; list; list = list->next)
9753         {
9754           synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9755                           device, mode, GDK_NOTIFY_VIRTUAL);
9756         }
9757       synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9758                       device, mode, GDK_NOTIFY_ANCESTOR);
9759
9760       g_list_free (to_ancestors);
9761     }
9762   else if (from_window == to_window)
9763     ;
9764   else
9765     {
9766       GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9767       GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9768
9769       while (from_ancestor != NULL || to_ancestor != NULL)
9770         {
9771           if (from_ancestor != NULL)
9772             {
9773               from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9774               if (from_ancestor == to_window)
9775                 break;
9776               if (from_ancestor)
9777                 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9778             }
9779           if (to_ancestor != NULL)
9780             {
9781               to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9782               if (to_ancestor == from_window)
9783                 break;
9784               if (to_ancestor)
9785                 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9786             }
9787         }
9788       if (to_ancestor == from_window)
9789         {
9790           if (mode != GDK_CROSSING_GTK_UNGRAB)
9791             synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9792                             device, mode, GDK_NOTIFY_INFERIOR);
9793           for (list = to_ancestors; list; list = list->next)
9794             synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data, 
9795                             device, mode, GDK_NOTIFY_VIRTUAL);
9796           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9797                           device, mode, GDK_NOTIFY_ANCESTOR);
9798         }
9799       else if (from_ancestor == to_window)
9800         {
9801           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9802                           device, mode, GDK_NOTIFY_ANCESTOR);
9803           for (list = g_list_last (from_ancestors); list; list = list->prev)
9804             {
9805               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9806                               device, mode, GDK_NOTIFY_VIRTUAL);
9807             }
9808           if (mode != GDK_CROSSING_GTK_GRAB)
9809             synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9810                             device, mode, GDK_NOTIFY_INFERIOR);
9811         }
9812       else
9813         {
9814           while (from_ancestors != NULL && to_ancestors != NULL 
9815                  && from_ancestors->data == to_ancestors->data)
9816             {
9817               from_ancestors = g_list_delete_link (from_ancestors, 
9818                                                    from_ancestors);
9819               to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9820             }
9821
9822           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9823                           device, mode, GDK_NOTIFY_NONLINEAR);
9824
9825           for (list = g_list_last (from_ancestors); list; list = list->prev)
9826             {
9827               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9828                               device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9829             }
9830           for (list = to_ancestors; list; list = list->next)
9831             {
9832               synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9833                               device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9834             }
9835           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9836                           device, mode, GDK_NOTIFY_NONLINEAR);
9837         }
9838       g_list_free (from_ancestors);
9839       g_list_free (to_ancestors);
9840     }
9841 }
9842
9843 static void
9844 gtk_widget_propagate_state (GtkWidget           *widget,
9845                             GtkStateData        *data)
9846 {
9847   GtkWidgetPrivate *priv = widget->priv;
9848   guint8 old_state = gtk_widget_get_state (widget);
9849   guint8 old_saved_state = priv->saved_state;
9850
9851   /* don't call this function with state==GTK_STATE_INSENSITIVE,
9852    * parent_sensitive==TRUE on a sensitive widget
9853    */
9854
9855
9856   if (data->parent_sensitive)
9857     GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9858   else
9859     GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9860
9861   if (gtk_widget_is_sensitive (widget))
9862     {
9863       if (data->state_restoration)
9864         priv->state = priv->saved_state;
9865       else
9866         priv->state = data->state;
9867     }
9868   else
9869     {
9870       if (!data->state_restoration)
9871         {
9872           if (data->state != GTK_STATE_INSENSITIVE)
9873             priv->saved_state = data->state;
9874         }
9875       else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9876         priv->saved_state = gtk_widget_get_state (widget);
9877       priv->state = GTK_STATE_INSENSITIVE;
9878     }
9879
9880   if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9881     {
9882       GtkWidget *window;
9883
9884       window = gtk_widget_get_toplevel (widget);
9885       if (window && gtk_widget_is_toplevel (window))
9886         gtk_window_set_focus (GTK_WINDOW (window), NULL);
9887     }
9888
9889   if (old_state != gtk_widget_get_state (widget) ||
9890       old_saved_state != priv->saved_state)
9891     {
9892       g_object_ref (widget);
9893
9894       if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9895         gtk_grab_remove (widget);
9896
9897       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9898
9899       if (!GTK_WIDGET_SHADOWED (widget))
9900         {
9901           GList *event_windows = NULL;
9902           GList *devices, *d;
9903
9904           devices = _gtk_widget_list_devices (widget);
9905
9906           for (d = devices; d; d = d->next)
9907             {
9908               GdkWindow *window;
9909               GdkDevice *device;
9910
9911               device = d->data;
9912               window = _gtk_widget_get_device_window (widget, device);
9913
9914               /* Do not propagate more than once to the
9915                * same window if non-multidevice aware.
9916                */
9917               if (!gdk_window_get_support_multidevice (window) &&
9918                   g_list_find (event_windows, window))
9919                 continue;
9920
9921               if (!gtk_widget_is_sensitive (widget))
9922                 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9923                                                  GDK_CROSSING_STATE_CHANGED);
9924               else if (old_state == GTK_STATE_INSENSITIVE)
9925                 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9926                                                  GDK_CROSSING_STATE_CHANGED);
9927
9928               event_windows = g_list_prepend (event_windows, window);
9929             }
9930
9931           g_list_free (event_windows);
9932           g_list_free (devices);
9933         }
9934
9935       if (GTK_IS_CONTAINER (widget))
9936         {
9937           data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9938           if (data->use_forall)
9939             gtk_container_forall (GTK_CONTAINER (widget),
9940                                   (GtkCallback) gtk_widget_propagate_state,
9941                                   data);
9942           else
9943             gtk_container_foreach (GTK_CONTAINER (widget),
9944                                    (GtkCallback) gtk_widget_propagate_state,
9945                                    data);
9946         }
9947       g_object_unref (widget);
9948     }
9949 }
9950
9951 static const GtkWidgetAuxInfo default_aux_info = {
9952   -1, -1,
9953   GTK_ALIGN_FILL,
9954   GTK_ALIGN_FILL,
9955   { 0, 0, 0, 0 }
9956 };
9957
9958 /*
9959  * _gtk_widget_get_aux_info:
9960  * @widget: a #GtkWidget
9961  * @create: if %TRUE, create the structure if it doesn't exist
9962  * 
9963  * Get the #GtkWidgetAuxInfo structure for the widget.
9964  * 
9965  * Return value: the #GtkAuxInfo structure for the widget, or
9966  *    %NULL if @create is %FALSE and one doesn't already exist.
9967  */
9968 GtkWidgetAuxInfo*
9969 _gtk_widget_get_aux_info (GtkWidget *widget,
9970                           gboolean   create)
9971 {
9972   GtkWidgetAuxInfo *aux_info;
9973   
9974   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9975   if (!aux_info && create)
9976     {
9977       aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9978
9979       *aux_info = default_aux_info;
9980
9981       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9982     }
9983   
9984   return aux_info;
9985 }
9986
9987 static const GtkWidgetAuxInfo*
9988 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
9989 {
9990   GtkWidgetAuxInfo *aux_info;
9991
9992   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
9993   if (aux_info == NULL)
9994     {
9995       return &default_aux_info;
9996     }
9997   else
9998     {
9999       return aux_info;
10000     }
10001 }
10002
10003 /*****************************************
10004  * gtk_widget_aux_info_destroy:
10005  *
10006  *   arguments:
10007  *
10008  *   results:
10009  *****************************************/
10010
10011 static void
10012 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10013 {
10014   g_slice_free (GtkWidgetAuxInfo, aux_info);
10015 }
10016
10017 /**
10018  * gtk_widget_shape_combine_region: 
10019  * @widget: a #GtkWidget
10020  * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10021  * 
10022  * Sets a shape for this widget's GDK window. This allows for
10023  * transparent windows etc., see gdk_window_shape_combine_region()
10024  * for more information.
10025  *
10026  * Since: 3.0
10027  **/
10028 void
10029 gtk_widget_shape_combine_region (GtkWidget *widget,
10030                                  cairo_region_t *region)
10031 {
10032   GtkWidgetPrivate *priv;
10033   
10034   g_return_if_fail (GTK_IS_WIDGET (widget));
10035   /*  set_shape doesn't work on widgets without gdk window */
10036   g_return_if_fail (gtk_widget_get_has_window (widget));
10037
10038   priv = widget->priv;
10039
10040   if (region == NULL)
10041     {
10042       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10043       
10044       if (priv->window)
10045         gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10046       
10047       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10048     }
10049   else
10050     {
10051       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10052       
10053       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10054                                cairo_region_copy (region),
10055                                (GDestroyNotify) cairo_region_destroy);
10056       
10057       /* set shape if widget has a gdk window already.
10058        * otherwise the shape is scheduled to be set by gtk_widget_realize().
10059        */
10060       if (priv->window)
10061         gdk_window_shape_combine_region (priv->window, region, 0, 0);
10062     }
10063 }
10064
10065 /**
10066  * gtk_widget_input_shape_combine_region:
10067  * @widget: a #GtkWidget
10068  * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10069  *
10070  * Sets an input shape for this widget's GDK window. This allows for
10071  * windows which react to mouse click in a nonrectangular region, see 
10072  * gdk_window_input_shape_combine_region() for more information.
10073  *
10074  * Since: 3.0
10075  **/
10076 void
10077 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10078                                        cairo_region_t *region)
10079 {
10080   GtkWidgetPrivate *priv;
10081   
10082   g_return_if_fail (GTK_IS_WIDGET (widget));
10083   /*  set_shape doesn't work on widgets without gdk window */
10084   g_return_if_fail (gtk_widget_get_has_window (widget));
10085
10086   priv = widget->priv;
10087
10088   if (region == NULL)
10089     {
10090       if (priv->window)
10091         gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10092       
10093       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10094     }
10095   else
10096     {
10097       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
10098                                cairo_region_copy (region),
10099                                (GDestroyNotify) cairo_region_destroy);
10100       
10101       /* set shape if widget has a gdk window already.
10102        * otherwise the shape is scheduled to be set by gtk_widget_realize().
10103        */
10104       if (priv->window)
10105         gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10106     }
10107 }
10108
10109
10110 static void
10111 gtk_reset_shapes_recurse (GtkWidget *widget,
10112                           GdkWindow *window)
10113 {
10114   gpointer data;
10115   GList *list;
10116
10117   gdk_window_get_user_data (window, &data);
10118   if (data != widget)
10119     return;
10120
10121   gdk_window_shape_combine_region (window, NULL, 0, 0);
10122   for (list = gdk_window_peek_children (window); list; list = list->next)
10123     gtk_reset_shapes_recurse (widget, list->data);
10124 }
10125
10126 /**
10127  * gtk_widget_reset_shapes:
10128  * @widget: a #GtkWidget
10129  *
10130  * Recursively resets the shape on this widget and its descendants.
10131  **/
10132 void
10133 gtk_widget_reset_shapes (GtkWidget *widget)
10134 {
10135   GtkWidgetPrivate *priv;
10136
10137   g_return_if_fail (GTK_IS_WIDGET (widget));
10138   g_return_if_fail (gtk_widget_get_realized (widget));
10139
10140   priv = widget->priv;
10141
10142   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10143     gtk_reset_shapes_recurse (widget, priv->window);
10144 }
10145
10146 /* style properties
10147  */
10148
10149 /**
10150  * gtk_widget_class_install_style_property_parser:
10151  * @klass: a #GtkWidgetClass
10152  * @pspec: the #GParamSpec for the style property
10153  * @parser: the parser for the style property
10154  * 
10155  * Installs a style property on a widget class. 
10156  **/
10157 void
10158 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
10159                                                 GParamSpec         *pspec,
10160                                                 GtkRcPropertyParser parser)
10161 {
10162   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10163   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10164   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10165   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10166   
10167   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10168     {
10169       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10170                  G_OBJECT_CLASS_NAME (klass),
10171                  pspec->name);
10172       return;
10173     }
10174
10175   g_param_spec_ref_sink (pspec);
10176   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10177   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10178 }
10179
10180 /**
10181  * gtk_widget_class_install_style_property:
10182  * @klass: a #GtkWidgetClass
10183  * @pspec: the #GParamSpec for the property
10184  * 
10185  * Installs a style property on a widget class. The parser for the
10186  * style property is determined by the value type of @pspec.
10187  **/
10188 void
10189 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10190                                          GParamSpec     *pspec)
10191 {
10192   GtkRcPropertyParser parser;
10193
10194   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10195   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10196
10197   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10198
10199   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10200 }
10201
10202 /**
10203  * gtk_widget_class_find_style_property:
10204  * @klass: a #GtkWidgetClass
10205  * @property_name: the name of the style property to find
10206  * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10207  *   style property with that name.
10208  *
10209  * Finds a style property of a widget class by name.
10210  *
10211  * Since: 2.2
10212  */
10213 GParamSpec*
10214 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10215                                       const gchar    *property_name)
10216 {
10217   g_return_val_if_fail (property_name != NULL, NULL);
10218
10219   return g_param_spec_pool_lookup (style_property_spec_pool,
10220                                    property_name,
10221                                    G_OBJECT_CLASS_TYPE (klass),
10222                                    TRUE);
10223 }
10224
10225 /**
10226  * gtk_widget_class_list_style_properties:
10227  * @klass: a #GtkWidgetClass
10228  * @n_properties: location to return the number of style properties found
10229  * @returns: an newly allocated array of #GParamSpec*. The array must 
10230  *       be freed with g_free().
10231  *
10232  * Returns all style properties of a widget class.
10233  *
10234  * Since: 2.2
10235  */
10236 GParamSpec**
10237 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10238                                         guint          *n_properties)
10239 {
10240   GParamSpec **pspecs;
10241   guint n;
10242
10243   pspecs = g_param_spec_pool_list (style_property_spec_pool,
10244                                    G_OBJECT_CLASS_TYPE (klass),
10245                                    &n);
10246   if (n_properties)
10247     *n_properties = n;
10248
10249   return pspecs;
10250 }
10251
10252 /**
10253  * gtk_widget_style_get_property:
10254  * @widget: a #GtkWidget
10255  * @property_name: the name of a style property
10256  * @value: location to return the property value 
10257  *
10258  * Gets the value of a style property of @widget.
10259  */
10260 void
10261 gtk_widget_style_get_property (GtkWidget   *widget,
10262                                const gchar *property_name,
10263                                GValue      *value)
10264 {
10265   GtkWidgetPrivate *priv;
10266   GParamSpec *pspec;
10267
10268   g_return_if_fail (GTK_IS_WIDGET (widget));
10269   g_return_if_fail (property_name != NULL);
10270   g_return_if_fail (G_IS_VALUE (value));
10271
10272   priv = widget->priv;
10273
10274   g_object_ref (widget);
10275   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10276                                     property_name,
10277                                     G_OBJECT_TYPE (widget),
10278                                     TRUE);
10279   if (!pspec)
10280     g_warning ("%s: widget class `%s' has no property named `%s'",
10281                G_STRLOC,
10282                G_OBJECT_TYPE_NAME (widget),
10283                property_name);
10284   else
10285     {
10286       const GValue *peek_value;
10287
10288       peek_value = _gtk_style_peek_property_value (priv->style,
10289                                                    G_OBJECT_TYPE (widget),
10290                                                    pspec,
10291                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10292       
10293       /* auto-conversion of the caller's value type
10294        */
10295       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10296         g_value_copy (peek_value, value);
10297       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10298         g_value_transform (peek_value, value);
10299       else
10300         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10301                    pspec->name,
10302                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10303                    G_VALUE_TYPE_NAME (value));
10304     }
10305   g_object_unref (widget);
10306 }
10307
10308 /**
10309  * gtk_widget_style_get_valist:
10310  * @widget: a #GtkWidget
10311  * @first_property_name: the name of the first property to get
10312  * @var_args: a <type>va_list</type> of pairs of property names and
10313  *     locations to return the property values, starting with the location
10314  *     for @first_property_name.
10315  * 
10316  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
10317  * bindings.
10318  */ 
10319 void
10320 gtk_widget_style_get_valist (GtkWidget   *widget,
10321                              const gchar *first_property_name,
10322                              va_list      var_args)
10323 {
10324   GtkWidgetPrivate *priv;
10325   const gchar *name;
10326
10327   g_return_if_fail (GTK_IS_WIDGET (widget));
10328
10329   priv = widget->priv;
10330
10331   g_object_ref (widget);
10332
10333   name = first_property_name;
10334   while (name)
10335     {
10336       const GValue *peek_value;
10337       GParamSpec *pspec;
10338       gchar *error;
10339
10340       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10341                                         name,
10342                                         G_OBJECT_TYPE (widget),
10343                                         TRUE);
10344       if (!pspec)
10345         {
10346           g_warning ("%s: widget class `%s' has no property named `%s'",
10347                      G_STRLOC,
10348                      G_OBJECT_TYPE_NAME (widget),
10349                      name);
10350           break;
10351         }
10352       /* style pspecs are always readable so we can spare that check here */
10353
10354       peek_value = _gtk_style_peek_property_value (priv->style,
10355                                                    G_OBJECT_TYPE (widget),
10356                                                    pspec,
10357                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10358       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10359       if (error)
10360         {
10361           g_warning ("%s: %s", G_STRLOC, error);
10362           g_free (error);
10363           break;
10364         }
10365
10366       name = va_arg (var_args, gchar*);
10367     }
10368
10369   g_object_unref (widget);
10370 }
10371
10372 /**
10373  * gtk_widget_style_get:
10374  * @widget: a #GtkWidget
10375  * @first_property_name: the name of the first property to get
10376  * @Varargs: pairs of property names and locations to 
10377  *   return the property values, starting with the location for 
10378  *   @first_property_name, terminated by %NULL.
10379  *
10380  * Gets the values of a multiple style properties of @widget.
10381  */
10382 void
10383 gtk_widget_style_get (GtkWidget   *widget,
10384                       const gchar *first_property_name,
10385                       ...)
10386 {
10387   va_list var_args;
10388
10389   g_return_if_fail (GTK_IS_WIDGET (widget));
10390
10391   va_start (var_args, first_property_name);
10392   gtk_widget_style_get_valist (widget, first_property_name, var_args);
10393   va_end (var_args);
10394 }
10395
10396 /**
10397  * gtk_widget_path:
10398  * @widget: a #GtkWidget
10399  * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10400  * @path: (out) (allow-none):  location to store allocated path string, or %NULL
10401  * @path_reversed: (out) (allow-none):  location to store allocated reverse path string, or %NULL
10402  *
10403  * Obtains the full path to @widget. The path is simply the name of a
10404  * widget and all its parents in the container hierarchy, separated by
10405  * periods. The name of a widget comes from
10406  * gtk_widget_get_name(). Paths are used to apply styles to a widget
10407  * in gtkrc configuration files. Widget names are the type of the
10408  * widget by default (e.g. "GtkButton") or can be set to an
10409  * application-specific value with gtk_widget_set_name(). By setting
10410  * the name of a widget, you allow users or theme authors to apply
10411  * styles to that specific widget in their gtkrc
10412  * file. @path_reversed_p fills in the path in reverse order,
10413  * i.e. starting with @widget's name instead of starting with the name
10414  * of @widget's outermost ancestor.
10415  **/
10416 void
10417 gtk_widget_path (GtkWidget *widget,
10418                  guint     *path_length,
10419                  gchar    **path,
10420                  gchar    **path_reversed)
10421 {
10422   static gchar *rev_path = NULL;
10423   static guint tmp_path_len = 0;
10424   guint len;
10425   
10426   g_return_if_fail (GTK_IS_WIDGET (widget));
10427
10428   len = 0;
10429   do
10430     {
10431       const gchar *string;
10432       const gchar *s;
10433       gchar *d;
10434       guint l;
10435       
10436       string = gtk_widget_get_name (widget);
10437       l = strlen (string);
10438       while (tmp_path_len <= len + l + 1)
10439         {
10440           tmp_path_len += INIT_PATH_SIZE;
10441           rev_path = g_realloc (rev_path, tmp_path_len);
10442         }
10443       s = string + l - 1;
10444       d = rev_path + len;
10445       while (s >= string)
10446         *(d++) = *(s--);
10447       len += l;
10448
10449       widget = widget->priv->parent;
10450
10451       if (widget)
10452         rev_path[len++] = '.';
10453       else
10454         rev_path[len++] = 0;
10455     }
10456   while (widget);
10457   
10458   if (path_length)
10459     *path_length = len - 1;
10460   if (path_reversed)
10461     *path_reversed = g_strdup (rev_path);
10462   if (path)
10463     {
10464       *path = g_strdup (rev_path);
10465       g_strreverse (*path);
10466     }
10467 }
10468
10469 /**
10470  * gtk_widget_class_path:
10471  * @widget: a #GtkWidget
10472  * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10473  * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10474  * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10475  *    string, or %NULL
10476  *
10477  * Same as gtk_widget_path(), but always uses the name of a widget's type,
10478  * never uses a custom name set with gtk_widget_set_name().
10479  * 
10480  **/
10481 void
10482 gtk_widget_class_path (GtkWidget *widget,
10483                        guint     *path_length,
10484                        gchar    **path,
10485                        gchar    **path_reversed)
10486 {
10487   static gchar *rev_path = NULL;
10488   static guint tmp_path_len = 0;
10489   guint len;
10490   
10491   g_return_if_fail (GTK_IS_WIDGET (widget));
10492
10493   len = 0;
10494   do
10495     {
10496       const gchar *string;
10497       const gchar *s;
10498       gchar *d;
10499       guint l;
10500       
10501       string = g_type_name (G_OBJECT_TYPE (widget));
10502       l = strlen (string);
10503       while (tmp_path_len <= len + l + 1)
10504         {
10505           tmp_path_len += INIT_PATH_SIZE;
10506           rev_path = g_realloc (rev_path, tmp_path_len);
10507         }
10508       s = string + l - 1;
10509       d = rev_path + len;
10510       while (s >= string)
10511         *(d++) = *(s--);
10512       len += l;
10513
10514       widget = widget->priv->parent;
10515
10516       if (widget)
10517         rev_path[len++] = '.';
10518       else
10519         rev_path[len++] = 0;
10520     }
10521   while (widget);
10522   
10523   if (path_length)
10524     *path_length = len - 1;
10525   if (path_reversed)
10526     *path_reversed = g_strdup (rev_path);
10527   if (path)
10528     {
10529       *path = g_strdup (rev_path);
10530       g_strreverse (*path);
10531     }
10532 }
10533
10534 /**
10535  * gtk_requisition_new:
10536  *
10537  * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10538  *
10539  * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10540  *   be freed with gtk_requisition_free().
10541  *
10542  * Since: 3.0
10543  */
10544 GtkRequisition *
10545 gtk_requisition_new (void)
10546 {
10547   return g_slice_new0 (GtkRequisition);
10548 }
10549
10550 /**
10551  * gtk_requisition_copy:
10552  * @requisition: a #GtkRequisition
10553  *
10554  * Copies a #GtkRequisition.
10555  *
10556  * Returns: a copy of @requisition
10557  **/
10558 GtkRequisition *
10559 gtk_requisition_copy (const GtkRequisition *requisition)
10560 {
10561   return g_slice_dup (GtkRequisition, requisition);
10562 }
10563
10564 /**
10565  * gtk_requisition_free:
10566  * @requisition: a #GtkRequisition
10567  * 
10568  * Frees a #GtkRequisition.
10569  **/
10570 void
10571 gtk_requisition_free (GtkRequisition *requisition)
10572 {
10573   g_slice_free (GtkRequisition, requisition);
10574 }
10575
10576 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10577                      gtk_requisition_copy,
10578                      gtk_requisition_free)
10579
10580 /**
10581  * gtk_widget_get_accessible:
10582  * @widget: a #GtkWidget
10583  *
10584  * Returns the accessible object that describes the widget to an
10585  * assistive technology.
10586  *
10587  * If no accessibility library is loaded (i.e. no ATK implementation library is
10588  * loaded via <envar>GTK_MODULES</envar> or via another application library,
10589  * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10590  * if no class-specific #AtkObject implementation is available for the widget
10591  * instance in question, it will inherit an #AtkObject implementation from the
10592  * first ancestor class for which such an implementation is defined.
10593  *
10594  * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10595  * library contains more information about accessible objects and their uses.
10596  *
10597  * Returns: (transfer none): the #AtkObject associated with @widget
10598  */
10599 AtkObject*
10600 gtk_widget_get_accessible (GtkWidget *widget)
10601 {
10602   GtkWidgetClass *klass;
10603
10604   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10605
10606   klass = GTK_WIDGET_GET_CLASS (widget);
10607
10608   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10609
10610   return klass->get_accessible (widget);
10611 }
10612
10613 static AtkObject* 
10614 gtk_widget_real_get_accessible (GtkWidget *widget)
10615 {
10616   AtkObject* accessible;
10617
10618   accessible = g_object_get_qdata (G_OBJECT (widget), 
10619                                    quark_accessible_object);
10620   if (!accessible)
10621   {
10622     AtkObjectFactory *factory;
10623     AtkRegistry *default_registry;
10624
10625     default_registry = atk_get_default_registry ();
10626     factory = atk_registry_get_factory (default_registry, 
10627                                         G_TYPE_FROM_INSTANCE (widget));
10628     accessible =
10629       atk_object_factory_create_accessible (factory,
10630                                             G_OBJECT (widget));
10631     g_object_set_qdata (G_OBJECT (widget), 
10632                         quark_accessible_object,
10633                         accessible);
10634   }
10635   return accessible;
10636 }
10637
10638 /*
10639  * Initialize a AtkImplementorIface instance's virtual pointers as
10640  * appropriate to this implementor's class (GtkWidget).
10641  */
10642 static void
10643 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10644 {
10645   iface->ref_accessible = gtk_widget_ref_accessible;
10646 }
10647
10648 static AtkObject*
10649 gtk_widget_ref_accessible (AtkImplementor *implementor)
10650 {
10651   AtkObject *accessible;
10652
10653   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10654   if (accessible)
10655     g_object_ref (accessible);
10656   return accessible;
10657 }
10658
10659 /*
10660  * GtkBuildable implementation
10661  */
10662 static GQuark            quark_builder_has_default = 0;
10663 static GQuark            quark_builder_has_focus = 0;
10664 static GQuark            quark_builder_atk_relations = 0;
10665 static GQuark            quark_builder_set_name = 0;
10666
10667 static void
10668 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10669 {
10670   quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10671   quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10672   quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10673   quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10674
10675   iface->set_name = gtk_widget_buildable_set_name;
10676   iface->get_name = gtk_widget_buildable_get_name;
10677   iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10678   iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10679   iface->parser_finished = gtk_widget_buildable_parser_finished;
10680   iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10681   iface->custom_finished = gtk_widget_buildable_custom_finished;
10682 }
10683
10684 static void
10685 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10686                                const gchar  *name)
10687 {
10688   g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10689                            g_strdup (name), g_free);
10690 }
10691
10692 static const gchar *
10693 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10694 {
10695   return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10696 }
10697
10698 static GObject *
10699 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10700                                          GtkBuilder   *builder,
10701                                          const gchar  *childname)
10702 {
10703   if (strcmp (childname, "accessible") == 0)
10704     return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10705
10706   return NULL;
10707 }
10708
10709 static void
10710 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10711                                              GtkBuilder   *builder,
10712                                              const gchar  *name,
10713                                              const GValue *value)
10714 {
10715   if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10716       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10717                           GINT_TO_POINTER (TRUE));
10718   else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10719       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10720                           GINT_TO_POINTER (TRUE));
10721   else
10722     g_object_set_property (G_OBJECT (buildable), name, value);
10723 }
10724
10725 typedef struct
10726 {
10727   gchar *action_name;
10728   GString *description;
10729   gchar *context;
10730   gboolean translatable;
10731 } AtkActionData;
10732
10733 typedef struct
10734 {
10735   gchar *target;
10736   gchar *type;
10737 } AtkRelationData;
10738
10739 static void
10740 free_action (AtkActionData *data, gpointer user_data)
10741 {
10742   g_free (data->action_name);
10743   g_string_free (data->description, TRUE);
10744   g_free (data->context);
10745   g_slice_free (AtkActionData, data);
10746 }
10747
10748 static void
10749 free_relation (AtkRelationData *data, gpointer user_data)
10750 {
10751   g_free (data->target);
10752   g_free (data->type);
10753   g_slice_free (AtkRelationData, data);
10754 }
10755
10756 static void
10757 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10758                                       GtkBuilder   *builder)
10759 {
10760   GSList *atk_relations;
10761
10762   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10763     gtk_widget_grab_default (GTK_WIDGET (buildable));
10764   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10765     gtk_widget_grab_focus (GTK_WIDGET (buildable));
10766
10767   atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10768                                       quark_builder_atk_relations);
10769   if (atk_relations)
10770     {
10771       AtkObject *accessible;
10772       AtkRelationSet *relation_set;
10773       GSList *l;
10774       GObject *target;
10775       AtkRelationType relation_type;
10776       AtkObject *target_accessible;
10777
10778       accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10779       relation_set = atk_object_ref_relation_set (accessible);
10780
10781       for (l = atk_relations; l; l = l->next)
10782         {
10783           AtkRelationData *relation = (AtkRelationData*)l->data;
10784
10785           target = gtk_builder_get_object (builder, relation->target);
10786           if (!target)
10787             {
10788               g_warning ("Target object %s in <relation> does not exist",
10789                          relation->target);
10790               continue;
10791             }
10792           target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10793           g_assert (target_accessible != NULL);
10794
10795           relation_type = atk_relation_type_for_name (relation->type);
10796           if (relation_type == ATK_RELATION_NULL)
10797             {
10798               g_warning ("<relation> type %s not found",
10799                          relation->type);
10800               continue;
10801             }
10802           atk_relation_set_add_relation_by_type (relation_set, relation_type,
10803                                                  target_accessible);
10804         }
10805       g_object_unref (relation_set);
10806
10807       g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10808       g_slist_free (atk_relations);
10809       g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10810                           NULL);
10811     }
10812 }
10813
10814 typedef struct
10815 {
10816   GSList *actions;
10817   GSList *relations;
10818 } AccessibilitySubParserData;
10819
10820 static void
10821 accessibility_start_element (GMarkupParseContext  *context,
10822                              const gchar          *element_name,
10823                              const gchar         **names,
10824                              const gchar         **values,
10825                              gpointer              user_data,
10826                              GError              **error)
10827 {
10828   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10829   guint i;
10830   gint line_number, char_number;
10831
10832   if (strcmp (element_name, "relation") == 0)
10833     {
10834       gchar *target = NULL;
10835       gchar *type = NULL;
10836       AtkRelationData *relation;
10837
10838       for (i = 0; names[i]; i++)
10839         {
10840           if (strcmp (names[i], "target") == 0)
10841             target = g_strdup (values[i]);
10842           else if (strcmp (names[i], "type") == 0)
10843             type = g_strdup (values[i]);
10844           else
10845             {
10846               g_markup_parse_context_get_position (context,
10847                                                    &line_number,
10848                                                    &char_number);
10849               g_set_error (error,
10850                            GTK_BUILDER_ERROR,
10851                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10852                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10853                            "<input>",
10854                            line_number, char_number, names[i], "relation");
10855               g_free (target);
10856               g_free (type);
10857               return;
10858             }
10859         }
10860
10861       if (!target || !type)
10862         {
10863           g_markup_parse_context_get_position (context,
10864                                                &line_number,
10865                                                &char_number);
10866           g_set_error (error,
10867                        GTK_BUILDER_ERROR,
10868                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10869                        "%s:%d:%d <%s> requires attribute \"%s\"",
10870                        "<input>",
10871                        line_number, char_number, "relation",
10872                        type ? "target" : "type");
10873           g_free (target);
10874           g_free (type);
10875           return;
10876         }
10877
10878       relation = g_slice_new (AtkRelationData);
10879       relation->target = target;
10880       relation->type = type;
10881
10882       data->relations = g_slist_prepend (data->relations, relation);
10883     }
10884   else if (strcmp (element_name, "action") == 0)
10885     {
10886       const gchar *action_name = NULL;
10887       const gchar *description = NULL;
10888       const gchar *msg_context = NULL;
10889       gboolean translatable = FALSE;
10890       AtkActionData *action;
10891
10892       for (i = 0; names[i]; i++)
10893         {
10894           if (strcmp (names[i], "action_name") == 0)
10895             action_name = values[i];
10896           else if (strcmp (names[i], "description") == 0)
10897             description = values[i];
10898           else if (strcmp (names[i], "translatable") == 0)
10899             {
10900               if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10901                 return;
10902             }
10903           else if (strcmp (names[i], "comments") == 0)
10904             {
10905               /* do nothing, comments are for translators */
10906             }
10907           else if (strcmp (names[i], "context") == 0)
10908             msg_context = values[i];
10909           else
10910             {
10911               g_markup_parse_context_get_position (context,
10912                                                    &line_number,
10913                                                    &char_number);
10914               g_set_error (error,
10915                            GTK_BUILDER_ERROR,
10916                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10917                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10918                            "<input>",
10919                            line_number, char_number, names[i], "action");
10920               return;
10921             }
10922         }
10923
10924       if (!action_name)
10925         {
10926           g_markup_parse_context_get_position (context,
10927                                                &line_number,
10928                                                &char_number);
10929           g_set_error (error,
10930                        GTK_BUILDER_ERROR,
10931                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10932                        "%s:%d:%d <%s> requires attribute \"%s\"",
10933                        "<input>",
10934                        line_number, char_number, "action",
10935                        "action_name");
10936           return;
10937         }
10938
10939       action = g_slice_new (AtkActionData);
10940       action->action_name = g_strdup (action_name);
10941       action->description = g_string_new (description);
10942       action->context = g_strdup (msg_context);
10943       action->translatable = translatable;
10944
10945       data->actions = g_slist_prepend (data->actions, action);
10946     }
10947   else if (strcmp (element_name, "accessibility") == 0)
10948     ;
10949   else
10950     g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10951 }
10952
10953 static void
10954 accessibility_text (GMarkupParseContext  *context,
10955                     const gchar          *text,
10956                     gsize                 text_len,
10957                     gpointer              user_data,
10958                     GError              **error)
10959 {
10960   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10961
10962   if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10963     {
10964       AtkActionData *action = data->actions->data;
10965
10966       g_string_append_len (action->description, text, text_len);
10967     }
10968 }
10969
10970 static const GMarkupParser accessibility_parser =
10971   {
10972     accessibility_start_element,
10973     NULL,
10974     accessibility_text,
10975   };
10976
10977 typedef struct
10978 {
10979   GObject *object;
10980   guint    key;
10981   guint    modifiers;
10982   gchar   *signal;
10983 } AccelGroupParserData;
10984
10985 static void
10986 accel_group_start_element (GMarkupParseContext  *context,
10987                            const gchar          *element_name,
10988                            const gchar         **names,
10989                            const gchar         **values,
10990                            gpointer              user_data,
10991                            GError              **error)
10992 {
10993   gint i;
10994   guint key = 0;
10995   guint modifiers = 0;
10996   gchar *signal = NULL;
10997   AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10998
10999   for (i = 0; names[i]; i++)
11000     {
11001       if (strcmp (names[i], "key") == 0)
11002         key = gdk_keyval_from_name (values[i]);
11003       else if (strcmp (names[i], "modifiers") == 0)
11004         {
11005           if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11006                                                values[i],
11007                                                &modifiers,
11008                                                error))
11009               return;
11010         }
11011       else if (strcmp (names[i], "signal") == 0)
11012         signal = g_strdup (values[i]);
11013     }
11014
11015   if (key == 0 || signal == NULL)
11016     {
11017       g_warning ("<accelerator> requires key and signal attributes");
11018       return;
11019     }
11020   parser_data->key = key;
11021   parser_data->modifiers = modifiers;
11022   parser_data->signal = signal;
11023 }
11024
11025 static const GMarkupParser accel_group_parser =
11026   {
11027     accel_group_start_element,
11028   };
11029
11030 static gboolean
11031 gtk_widget_buildable_custom_tag_start (GtkBuildable     *buildable,
11032                                        GtkBuilder       *builder,
11033                                        GObject          *child,
11034                                        const gchar      *tagname,
11035                                        GMarkupParser    *parser,
11036                                        gpointer         *data)
11037 {
11038   g_assert (buildable);
11039
11040   if (strcmp (tagname, "accelerator") == 0)
11041     {
11042       AccelGroupParserData *parser_data;
11043
11044       parser_data = g_slice_new0 (AccelGroupParserData);
11045       parser_data->object = g_object_ref (buildable);
11046       *parser = accel_group_parser;
11047       *data = parser_data;
11048       return TRUE;
11049     }
11050   if (strcmp (tagname, "accessibility") == 0)
11051     {
11052       AccessibilitySubParserData *parser_data;
11053
11054       parser_data = g_slice_new0 (AccessibilitySubParserData);
11055       *parser = accessibility_parser;
11056       *data = parser_data;
11057       return TRUE;
11058     }
11059   return FALSE;
11060 }
11061
11062 void
11063 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11064                                           GtkWidget *toplevel,
11065                                           gpointer   user_data)
11066 {
11067   AccelGroupParserData *accel_data;
11068   GSList *accel_groups;
11069   GtkAccelGroup *accel_group;
11070
11071   g_return_if_fail (GTK_IS_WIDGET (widget));
11072   g_return_if_fail (GTK_IS_WIDGET (toplevel));
11073   g_return_if_fail (user_data != NULL);
11074
11075   accel_data = (AccelGroupParserData*)user_data;
11076   accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11077   if (g_slist_length (accel_groups) == 0)
11078     {
11079       accel_group = gtk_accel_group_new ();
11080       gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11081     }
11082   else
11083     {
11084       g_assert (g_slist_length (accel_groups) == 1);
11085       accel_group = g_slist_nth_data (accel_groups, 0);
11086     }
11087
11088   gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11089                               accel_data->signal,
11090                               accel_group,
11091                               accel_data->key,
11092                               accel_data->modifiers,
11093                               GTK_ACCEL_VISIBLE);
11094
11095   g_object_unref (accel_data->object);
11096   g_free (accel_data->signal);
11097   g_slice_free (AccelGroupParserData, accel_data);
11098 }
11099
11100 static void
11101 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11102                                       GtkBuilder   *builder,
11103                                       GObject      *child,
11104                                       const gchar  *tagname,
11105                                       gpointer      user_data)
11106 {
11107   AccelGroupParserData *accel_data;
11108   AccessibilitySubParserData *a11y_data;
11109   GtkWidget *toplevel;
11110
11111   if (strcmp (tagname, "accelerator") == 0)
11112     {
11113       accel_data = (AccelGroupParserData*)user_data;
11114       g_assert (accel_data->object);
11115
11116       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11117
11118       _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11119     }
11120   else if (strcmp (tagname, "accessibility") == 0)
11121     {
11122       a11y_data = (AccessibilitySubParserData*)user_data;
11123
11124       if (a11y_data->actions)
11125         {
11126           AtkObject *accessible;
11127           AtkAction *action;
11128           gint i, n_actions;
11129           GSList *l;
11130
11131           accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11132
11133           action = ATK_ACTION (accessible);
11134           n_actions = atk_action_get_n_actions (action);
11135
11136           for (l = a11y_data->actions; l; l = l->next)
11137             {
11138               AtkActionData *action_data = (AtkActionData*)l->data;
11139
11140               for (i = 0; i < n_actions; i++)
11141                 if (strcmp (atk_action_get_name (action, i),
11142                             action_data->action_name) == 0)
11143                   break;
11144
11145               if (i < n_actions)
11146                 {
11147                   gchar *description;
11148
11149                   if (action_data->translatable && action_data->description->len)
11150                     description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11151                                                                  action_data->context,
11152                                                                  action_data->description->str);
11153                   else
11154                     description = action_data->description->str;
11155
11156                   atk_action_set_description (action, i, description);
11157                 }
11158             }
11159
11160           g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11161           g_slist_free (a11y_data->actions);
11162         }
11163
11164       if (a11y_data->relations)
11165         g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11166                             a11y_data->relations);
11167
11168       g_slice_free (AccessibilitySubParserData, a11y_data);
11169     }
11170 }
11171
11172 /*
11173  * GtkSizeRequest implementation
11174  */
11175 static void
11176 gtk_widget_real_get_width (GtkSizeRequest *widget,
11177                            gint           *minimum_size,
11178                            gint           *natural_size)
11179 {
11180   if (minimum_size)
11181     *minimum_size = 0;
11182
11183   if (natural_size)
11184     *natural_size = 0;
11185 }
11186
11187 static void
11188 gtk_widget_real_get_height (GtkSizeRequest *widget,
11189                             gint           *minimum_size,
11190                             gint           *natural_size)
11191 {
11192   if (minimum_size)
11193     *minimum_size = 0;
11194
11195   if (natural_size)
11196     *natural_size = 0;
11197 }
11198
11199 static void
11200 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11201                                       gint       width,
11202                                       gint      *minimum_height,
11203                                       gint      *natural_height)
11204 {
11205   GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11206 }
11207
11208 static void
11209 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11210                                       gint       height,
11211                                       gint      *minimum_width,
11212                                       gint      *natural_width)
11213 {
11214   GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11215 }
11216
11217 static void
11218 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11219 {
11220   iface->get_width            = gtk_widget_real_get_width;
11221   iface->get_height           = gtk_widget_real_get_height;
11222   iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11223   iface->get_height_for_width = gtk_widget_real_get_height_for_width;  
11224 }
11225
11226 /**
11227  * gtk_widget_get_halign:
11228  * @widget: a #GtkWidget
11229  *
11230  * Gets the value of the #GtkWidget:halign property.
11231  *
11232  * Returns: the horizontal alignment of @widget
11233  */
11234 GtkAlign
11235 gtk_widget_get_halign (GtkWidget *widget)
11236 {
11237   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11238   return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11239 }
11240
11241 /**
11242  * gtk_widget_set_halign:
11243  * @widget: a #GtkWidget
11244  * @align: the horizontal alignment
11245  *
11246  * Sets the horizontal alignment of @widget.
11247  * See the #GtkWidget:halign property.
11248  */
11249 void
11250 gtk_widget_set_halign (GtkWidget *widget,
11251                        GtkAlign   align)
11252 {
11253   GtkWidgetAuxInfo *aux_info;
11254
11255   g_return_if_fail (GTK_IS_WIDGET (widget));
11256
11257   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11258
11259   if (aux_info->halign == align)
11260     return;
11261
11262   aux_info->halign = align;
11263   gtk_widget_queue_resize (widget);
11264   g_object_notify (G_OBJECT (widget), "halign");
11265 }
11266
11267 /**
11268  * gtk_widget_get_valign:
11269  * @widget: a #GtkWidget
11270  *
11271  * Gets the value of the #GtkWidget:valign property.
11272  *
11273  * Returns: the vertical alignment of @widget
11274  */
11275 GtkAlign
11276 gtk_widget_get_valign (GtkWidget *widget)
11277 {
11278   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11279   return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11280 }
11281
11282 /**
11283  * gtk_widget_set_valign:
11284  * @widget: a #GtkWidget
11285  * @align: the vertical alignment
11286  *
11287  * Sets the vertical alignment of @widget.
11288  * See the #GtkWidget:valign property.
11289  */
11290 void
11291 gtk_widget_set_valign (GtkWidget *widget,
11292                        GtkAlign   align)
11293 {
11294   GtkWidgetAuxInfo *aux_info;
11295
11296   g_return_if_fail (GTK_IS_WIDGET (widget));
11297
11298   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11299
11300   if (aux_info->valign == align)
11301     return;
11302
11303   aux_info->valign = align;
11304   gtk_widget_queue_resize (widget);
11305   g_object_notify (G_OBJECT (widget), "valign");
11306 }
11307
11308 /**
11309  * gtk_widget_get_margin_left:
11310  * @widget: a #GtkWidget
11311  *
11312  * Gets the value of the #GtkWidget:margin-left property.
11313  *
11314  * Returns: The left margin of @widget
11315  */
11316 gint
11317 gtk_widget_get_margin_left (GtkWidget *widget)
11318 {
11319   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11320
11321   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11322 }
11323
11324 /**
11325  * gtk_widget_set_margin_left:
11326  * @widget: a #GtkWidget
11327  * @margin: the left margin
11328  *
11329  * Sets the left margin of @widget.
11330  * See the #GtkWidget:margin-left property.
11331  */
11332 void
11333 gtk_widget_set_margin_left (GtkWidget *widget,
11334                             gint       margin)
11335 {
11336   GtkWidgetAuxInfo *aux_info;
11337
11338   g_return_if_fail (GTK_IS_WIDGET (widget));
11339   g_return_if_fail (margin <= G_MAXINT16);
11340
11341   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11342
11343   if (aux_info->margin.left == margin)
11344     return;
11345
11346   aux_info->margin.left = margin;
11347   gtk_widget_queue_resize (widget);
11348   g_object_notify (G_OBJECT (widget), "margin-left");
11349 }
11350
11351 /**
11352  * gtk_widget_get_margin_right:
11353  * @widget: a #GtkWidget
11354  *
11355  * Gets the value of the #GtkWidget:margin-right property.
11356  *
11357  * Returns: The left margin of @widget
11358  */
11359 gint
11360 gtk_widget_get_margin_right (GtkWidget *widget)
11361 {
11362   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11363
11364   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11365 }
11366
11367 /**
11368  * gtk_widget_set_margin_right:
11369  * @widget: a #GtkWidget
11370  * @margin: the right margin
11371  *
11372  * Sets the right margin of @widget.
11373  * See the #GtkWidget:margin-right property.
11374  */
11375 void
11376 gtk_widget_set_margin_right (GtkWidget *widget,
11377                              gint       margin)
11378 {
11379   GtkWidgetAuxInfo *aux_info;
11380
11381   g_return_if_fail (GTK_IS_WIDGET (widget));
11382   g_return_if_fail (margin <= G_MAXINT16);
11383
11384   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11385
11386   if (aux_info->margin.right == margin)
11387     return;
11388
11389   aux_info->margin.right = margin;
11390   gtk_widget_queue_resize (widget);
11391   g_object_notify (G_OBJECT (widget), "margin-right");
11392 }
11393
11394 /**
11395  * gtk_widget_get_margin_top:
11396  * @widget: a #GtkWidget
11397  *
11398  * Gets the value of the #GtkWidget:margin-top property.
11399  *
11400  * Returns: The top margin of @widget
11401  */
11402 gint
11403 gtk_widget_get_margin_top (GtkWidget *widget)
11404 {
11405   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11406
11407   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11408 }
11409
11410 /**
11411  * gtk_widget_set_margin_top:
11412  * @widget: a #GtkWidget
11413  * @margin: the top margin
11414  *
11415  * Sets the top margin of @widget.
11416  * See the #GtkWidget:margin-top property.
11417  */
11418 void
11419 gtk_widget_set_margin_top (GtkWidget *widget,
11420                            gint       margin)
11421 {
11422   GtkWidgetAuxInfo *aux_info;
11423
11424   g_return_if_fail (GTK_IS_WIDGET (widget));
11425   g_return_if_fail (margin <= G_MAXINT16);
11426
11427   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11428
11429   if (aux_info->margin.top == margin)
11430     return;
11431
11432   aux_info->margin.top = margin;
11433   gtk_widget_queue_resize (widget);
11434   g_object_notify (G_OBJECT (widget), "margin-top");
11435 }
11436
11437 /**
11438  * gtk_widget_get_margin_bottom:
11439  * @widget: a #GtkWidget
11440  *
11441  * Gets the value of the #GtkWidget:margin-bottom property.
11442  *
11443  * Returns: The bottom margin of @widget
11444  */
11445 gint
11446 gtk_widget_get_margin_bottom (GtkWidget *widget)
11447 {
11448   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11449
11450   return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11451 }
11452
11453 /**
11454  * gtk_widget_set_margin_bottom:
11455  * @widget: a #GtkWidget
11456  * @margin: the bottom margin
11457  *
11458  * Sets the bottom margin of @widget.
11459  * See the #GtkWidget:margin-bottom property.
11460  */
11461 void
11462 gtk_widget_set_margin_bottom (GtkWidget *widget,
11463                               gint       margin)
11464 {
11465   GtkWidgetAuxInfo *aux_info;
11466
11467   g_return_if_fail (GTK_IS_WIDGET (widget));
11468   g_return_if_fail (margin <= G_MAXINT16);
11469
11470   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11471
11472   if (aux_info->margin.bottom == margin)
11473     return;
11474
11475   aux_info->margin.bottom = margin;
11476   gtk_widget_queue_resize (widget);
11477   g_object_notify (G_OBJECT (widget), "margin-bottom");
11478 }
11479
11480 /**
11481  * gtk_widget_get_clipboard:
11482  * @widget: a #GtkWidget
11483  * @selection: a #GdkAtom which identifies the clipboard
11484  *             to use. %GDK_SELECTION_CLIPBOARD gives the
11485  *             default clipboard. Another common value
11486  *             is %GDK_SELECTION_PRIMARY, which gives
11487  *             the primary X selection. 
11488  * 
11489  * Returns the clipboard object for the given selection to
11490  * be used with @widget. @widget must have a #GdkDisplay
11491  * associated with it, so must be attached to a toplevel
11492  * window.
11493  *
11494  * Return value: (transfer none): the appropriate clipboard object. If no
11495  *             clipboard already exists, a new one will
11496  *             be created. Once a clipboard object has
11497  *             been created, it is persistent for all time.
11498  *
11499  * Since: 2.2
11500  **/
11501 GtkClipboard *
11502 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11503 {
11504   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11505   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11506
11507   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11508                                         selection);
11509 }
11510
11511 /**
11512  * gtk_widget_list_mnemonic_labels:
11513  * @widget: a #GtkWidget
11514  *
11515  * Returns a newly allocated list of the widgets, normally labels, for
11516  * which this widget is the target of a mnemonic (see for example,
11517  * gtk_label_set_mnemonic_widget()).
11518
11519  * The widgets in the list are not individually referenced. If you
11520  * want to iterate through the list and perform actions involving
11521  * callbacks that might destroy the widgets, you
11522  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11523  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11524  * widgets afterwards.
11525
11526  * Return value: (element-type GtkWidget) (transfer container): the list of
11527  *  mnemonic labels; free this list
11528  *  with g_list_free() when you are done with it.
11529  *
11530  * Since: 2.4
11531  **/
11532 GList *
11533 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11534 {
11535   GList *list = NULL;
11536   GSList *l;
11537   
11538   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11539
11540   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11541     list = g_list_prepend (list, l->data);
11542
11543   return list;
11544 }
11545
11546 /**
11547  * gtk_widget_add_mnemonic_label:
11548  * @widget: a #GtkWidget
11549  * @label: a #GtkWidget that acts as a mnemonic label for @widget
11550  * 
11551  * Adds a widget to the list of mnemonic labels for
11552  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11553  * list of mnemonic labels for the widget is cleared when the
11554  * widget is destroyed, so the caller must make sure to update
11555  * its internal state at this point as well, by using a connection
11556  * to the #GtkWidget::destroy signal or a weak notifier.
11557  *
11558  * Since: 2.4
11559  **/
11560 void
11561 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11562                                GtkWidget *label)
11563 {
11564   GSList *old_list, *new_list;
11565
11566   g_return_if_fail (GTK_IS_WIDGET (widget));
11567   g_return_if_fail (GTK_IS_WIDGET (label));
11568
11569   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11570   new_list = g_slist_prepend (old_list, label);
11571   
11572   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11573                            new_list, (GDestroyNotify) g_slist_free);
11574 }
11575
11576 /**
11577  * gtk_widget_remove_mnemonic_label:
11578  * @widget: a #GtkWidget
11579  * @label: a #GtkWidget that was previously set as a mnemnic label for
11580  *         @widget with gtk_widget_add_mnemonic_label().
11581  * 
11582  * Removes a widget from the list of mnemonic labels for
11583  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11584  * must have previously been added to the list with
11585  * gtk_widget_add_mnemonic_label().
11586  *
11587  * Since: 2.4
11588  **/
11589 void
11590 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11591                                   GtkWidget *label)
11592 {
11593   GSList *old_list, *new_list;
11594
11595   g_return_if_fail (GTK_IS_WIDGET (widget));
11596   g_return_if_fail (GTK_IS_WIDGET (label));
11597
11598   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11599   new_list = g_slist_remove (old_list, label);
11600
11601   if (new_list)
11602     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11603                              new_list, (GDestroyNotify) g_slist_free);
11604 }
11605
11606 /**
11607  * gtk_widget_get_no_show_all:
11608  * @widget: a #GtkWidget
11609  * 
11610  * Returns the current value of the GtkWidget:no-show-all property, 
11611  * which determines whether calls to gtk_widget_show_all() and 
11612  * gtk_widget_hide_all() will affect this widget. 
11613  * 
11614  * Return value: the current value of the "no-show-all" property.
11615  *
11616  * Since: 2.4
11617  **/
11618 gboolean
11619 gtk_widget_get_no_show_all (GtkWidget *widget)
11620 {
11621   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11622   
11623   return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11624 }
11625
11626 /**
11627  * gtk_widget_set_no_show_all:
11628  * @widget: a #GtkWidget
11629  * @no_show_all: the new value for the "no-show-all" property
11630  * 
11631  * Sets the #GtkWidget:no-show-all property, which determines whether 
11632  * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect 
11633  * this widget. 
11634  *
11635  * This is mostly for use in constructing widget hierarchies with externally
11636  * controlled visibility, see #GtkUIManager.
11637  * 
11638  * Since: 2.4
11639  **/
11640 void
11641 gtk_widget_set_no_show_all (GtkWidget *widget,
11642                             gboolean   no_show_all)
11643 {
11644   g_return_if_fail (GTK_IS_WIDGET (widget));
11645
11646   no_show_all = (no_show_all != FALSE);
11647
11648   if (no_show_all == gtk_widget_get_no_show_all (widget))
11649     return;
11650
11651   if (no_show_all)
11652     GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11653   else
11654     GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11655   
11656   g_object_notify (G_OBJECT (widget), "no-show-all");
11657 }
11658
11659
11660 static void
11661 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11662                                  gboolean   has_tooltip,
11663                                  gboolean   force)
11664 {
11665   GtkWidgetPrivate *priv = widget->priv;
11666   gboolean priv_has_tooltip;
11667
11668   priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11669                                        quark_has_tooltip));
11670
11671   if (priv_has_tooltip != has_tooltip || force)
11672     {
11673       priv_has_tooltip = has_tooltip;
11674
11675       if (priv_has_tooltip)
11676         {
11677           if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11678             gdk_window_set_events (priv->window,
11679                                    gdk_window_get_events (priv->window) |
11680                                    GDK_LEAVE_NOTIFY_MASK |
11681                                    GDK_POINTER_MOTION_MASK |
11682                                    GDK_POINTER_MOTION_HINT_MASK);
11683
11684           if (gtk_widget_get_has_window (widget))
11685               gtk_widget_add_events (widget,
11686                                      GDK_LEAVE_NOTIFY_MASK |
11687                                      GDK_POINTER_MOTION_MASK |
11688                                      GDK_POINTER_MOTION_HINT_MASK);
11689         }
11690
11691       g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11692                           GUINT_TO_POINTER (priv_has_tooltip));
11693     }
11694 }
11695
11696 /**
11697  * gtk_widget_set_tooltip_window:
11698  * @widget: a #GtkWidget
11699  * @custom_window: (allow-none): a #GtkWindow, or %NULL
11700  *
11701  * Replaces the default, usually yellow, window used for displaying
11702  * tooltips with @custom_window. GTK+ will take care of showing and
11703  * hiding @custom_window at the right moment, to behave likewise as
11704  * the default tooltip window. If @custom_window is %NULL, the default
11705  * tooltip window will be used.
11706  *
11707  * If the custom window should have the default theming it needs to
11708  * have the name "gtk-tooltip", see gtk_widget_set_name().
11709  *
11710  * Since: 2.12
11711  */
11712 void
11713 gtk_widget_set_tooltip_window (GtkWidget *widget,
11714                                GtkWindow *custom_window)
11715 {
11716   gboolean has_tooltip;
11717   gchar *tooltip_markup;
11718
11719   g_return_if_fail (GTK_IS_WIDGET (widget));
11720   g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11721
11722   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11723
11724   if (custom_window)
11725     g_object_ref (custom_window);
11726
11727   g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11728                            custom_window, g_object_unref);
11729
11730   has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11731   gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11732
11733   if (has_tooltip && gtk_widget_get_visible (widget))
11734     gtk_widget_queue_tooltip_query (widget);
11735 }
11736
11737 /**
11738  * gtk_widget_get_tooltip_window:
11739  * @widget: a #GtkWidget
11740  *
11741  * Returns the #GtkWindow of the current tooltip. This can be the
11742  * GtkWindow created by default, or the custom tooltip window set
11743  * using gtk_widget_set_tooltip_window().
11744  *
11745  * Return value: (transfer none): The #GtkWindow of the current tooltip.
11746  *
11747  * Since: 2.12
11748  */
11749 GtkWindow *
11750 gtk_widget_get_tooltip_window (GtkWidget *widget)
11751 {
11752   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11753
11754   return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11755 }
11756
11757 /**
11758  * gtk_widget_trigger_tooltip_query:
11759  * @widget: a #GtkWidget
11760  *
11761  * Triggers a tooltip query on the display where the toplevel of @widget
11762  * is located. See gtk_tooltip_trigger_tooltip_query() for more
11763  * information.
11764  *
11765  * Since: 2.12
11766  */
11767 void
11768 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11769 {
11770   gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11771 }
11772
11773 static guint tooltip_query_id;
11774 static GSList *tooltip_query_displays;
11775
11776 static gboolean
11777 tooltip_query_idle (gpointer data)
11778 {
11779   g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11780   g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11781   g_slist_free (tooltip_query_displays);
11782
11783   tooltip_query_displays = NULL;
11784   tooltip_query_id = 0;
11785
11786   return FALSE;
11787 }
11788
11789 static void
11790 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11791 {
11792   GdkDisplay *display;
11793
11794   display = gtk_widget_get_display (widget);
11795
11796   if (!g_slist_find (tooltip_query_displays, display))
11797     tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11798
11799   if (tooltip_query_id == 0)
11800     tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11801 }
11802
11803 /**
11804  * gtk_widget_set_tooltip_text:
11805  * @widget: a #GtkWidget
11806  * @text: the contents of the tooltip for @widget
11807  *
11808  * Sets @text as the contents of the tooltip. This function will take
11809  * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11810  * handler for the GtkWidget::query-tooltip signal.
11811  *
11812  * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11813  *
11814  * Since: 2.12
11815  */
11816 void
11817 gtk_widget_set_tooltip_text (GtkWidget   *widget,
11818                              const gchar *text)
11819 {
11820   g_return_if_fail (GTK_IS_WIDGET (widget));
11821
11822   g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11823 }
11824
11825 /**
11826  * gtk_widget_get_tooltip_text:
11827  * @widget: a #GtkWidget
11828  *
11829  * Gets the contents of the tooltip for @widget.
11830  *
11831  * Return value: the tooltip text, or %NULL. You should free the
11832  *   returned string with g_free() when done.
11833  *
11834  * Since: 2.12
11835  */
11836 gchar *
11837 gtk_widget_get_tooltip_text (GtkWidget *widget)
11838 {
11839   gchar *text = NULL;
11840
11841   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11842
11843   g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11844
11845   return text;
11846 }
11847
11848 /**
11849  * gtk_widget_set_tooltip_markup:
11850  * @widget: a #GtkWidget
11851  * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11852  *
11853  * Sets @markup as the contents of the tooltip, which is marked up with
11854  *  the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11855  *
11856  * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11857  * and of the default handler for the GtkWidget::query-tooltip signal.
11858  *
11859  * See also the GtkWidget:tooltip-markup property and
11860  * gtk_tooltip_set_markup().
11861  *
11862  * Since: 2.12
11863  */
11864 void
11865 gtk_widget_set_tooltip_markup (GtkWidget   *widget,
11866                                const gchar *markup)
11867 {
11868   g_return_if_fail (GTK_IS_WIDGET (widget));
11869
11870   g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11871 }
11872
11873 /**
11874  * gtk_widget_get_tooltip_markup:
11875  * @widget: a #GtkWidget
11876  *
11877  * Gets the contents of the tooltip for @widget.
11878  *
11879  * Return value: the tooltip text, or %NULL. You should free the
11880  *   returned string with g_free() when done.
11881  *
11882  * Since: 2.12
11883  */
11884 gchar *
11885 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11886 {
11887   gchar *text = NULL;
11888
11889   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11890
11891   g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11892
11893   return text;
11894 }
11895
11896 /**
11897  * gtk_widget_set_has_tooltip:
11898  * @widget: a #GtkWidget
11899  * @has_tooltip: whether or not @widget has a tooltip.
11900  *
11901  * Sets the has-tooltip property on @widget to @has_tooltip.  See
11902  * GtkWidget:has-tooltip for more information.
11903  *
11904  * Since: 2.12
11905  */
11906 void
11907 gtk_widget_set_has_tooltip (GtkWidget *widget,
11908                             gboolean   has_tooltip)
11909 {
11910   g_return_if_fail (GTK_IS_WIDGET (widget));
11911
11912   g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11913 }
11914
11915 /**
11916  * gtk_widget_get_has_tooltip:
11917  * @widget: a #GtkWidget
11918  *
11919  * Returns the current value of the has-tooltip property.  See
11920  * GtkWidget:has-tooltip for more information.
11921  *
11922  * Return value: current value of has-tooltip on @widget.
11923  *
11924  * Since: 2.12
11925  */
11926 gboolean
11927 gtk_widget_get_has_tooltip (GtkWidget *widget)
11928 {
11929   gboolean has_tooltip = FALSE;
11930
11931   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11932
11933   g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11934
11935   return has_tooltip;
11936 }
11937
11938 /**
11939  * gtk_widget_get_allocation:
11940  * @widget: a #GtkWidget
11941  * @allocation: (out): a pointer to a #GtkAllocation to copy to
11942  *
11943  * Retrieves the widget's allocation.
11944  *
11945  * Note, when implementing a #GtkContainer: a widget's allocation will
11946  * be its "adjusted" allocation, that is, the widget's parent
11947  * container typically calls gtk_widget_size_allocate() with an
11948  * allocation, and that allocation is then adjusted (to handle margin
11949  * and alignment for example) before assignment to the widget.
11950  * gtk_widget_get_allocation() returns the adjusted allocation that
11951  * was actually assigned to the widget. The adjusted allocation is
11952  * guaranteed to be completely contained within the
11953  * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11954  * is guaranteed that its children stay inside the assigned bounds,
11955  * but not that they have exactly the bounds the container assigned.
11956  * There is no way to get the original allocation assigned by
11957  * gtk_widget_size_allocate(), since it isn't stored; if a container
11958  * implementation needs that information it will have to track it itself.
11959  *
11960  * Since: 2.18
11961  */
11962 void
11963 gtk_widget_get_allocation (GtkWidget     *widget,
11964                            GtkAllocation *allocation)
11965 {
11966   GtkWidgetPrivate *priv;
11967
11968   g_return_if_fail (GTK_IS_WIDGET (widget));
11969   g_return_if_fail (allocation != NULL);
11970
11971   priv = widget->priv;
11972
11973   *allocation = priv->allocation;
11974 }
11975
11976 /**
11977  * gtk_widget_set_allocation:
11978  * @widget: a #GtkWidget
11979  * @allocation: a pointer to a #GtkAllocation to copy from
11980  *
11981  * Sets the widget's allocation.  This should not be used
11982  * directly, but from within a widget's size_allocate method.
11983  *
11984  * The allocation set should be the "adjusted" or actual
11985  * allocation. If you're implementing a #GtkContainer, you want to use
11986  * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
11987  * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
11988  * allocation inside gtk_widget_size_allocate() to create an adjusted
11989  * allocation.
11990  *
11991  * Since: 2.18
11992  */
11993 void
11994 gtk_widget_set_allocation (GtkWidget           *widget,
11995                            const GtkAllocation *allocation)
11996 {
11997   GtkWidgetPrivate *priv;
11998
11999   g_return_if_fail (GTK_IS_WIDGET (widget));
12000   g_return_if_fail (allocation != NULL);
12001
12002   priv = widget->priv;
12003
12004   priv->allocation = *allocation;
12005 }
12006
12007 /**
12008  * gtk_widget_get_requisition:
12009  * @widget: a #GtkWidget
12010  * @requisition: (out): a pointer to a #GtkRequisition to copy to
12011  *
12012  * Retrieves the widget's requisition.
12013  *
12014  * This function should only be used by widget implementations in
12015  * order to figure whether the widget's requisition has actually
12016  * changed after some internal state change (so that they can call
12017  * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12018  *
12019  * Normally, gtk_widget_size_request() should be used.
12020  *
12021  * Since: 2.20
12022  *
12023  * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12024  * removed, If you need to cache sizes across requests and allocations,
12025  * add an explicit cache to the widget in question instead.
12026  */
12027 void
12028 gtk_widget_get_requisition (GtkWidget      *widget,
12029                             GtkRequisition *requisition)
12030 {
12031   g_return_if_fail (GTK_IS_WIDGET (widget));
12032   g_return_if_fail (requisition != NULL);
12033
12034   gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12035 }
12036
12037 /**
12038  * gtk_widget_set_window:
12039  * @widget: a #GtkWidget
12040  * @window: a #GdkWindow
12041  *
12042  * Sets a widget's window. This function should only be used in a
12043  * widget's GtkWidget::realize() implementation. The %window passed is
12044  * usually either new window created with gdk_window_new(), or the
12045  * window of its parent widget as returned by
12046  * gtk_widget_get_parent_window().
12047  *
12048  * Widgets must indicate whether they will create their own #GdkWindow
12049  * by calling gtk_widget_set_has_window(). This is usually done in the
12050  * widget's init() function.
12051  *
12052  * <note><para>This function does not add any reference to @window.</para></note>
12053  *
12054  * Since: 2.18
12055  */
12056 void
12057 gtk_widget_set_window (GtkWidget *widget,
12058                        GdkWindow *window)
12059 {
12060   GtkWidgetPrivate *priv;
12061
12062   g_return_if_fail (GTK_IS_WIDGET (widget));
12063   g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12064
12065   priv = widget->priv;
12066
12067   if (priv->window != window)
12068     {
12069       priv->window = window;
12070       g_object_notify (G_OBJECT (widget), "window");
12071     }
12072 }
12073
12074 /**
12075  * gtk_widget_get_window:
12076  * @widget: a #GtkWidget
12077  *
12078  * Returns the widget's window if it is realized, %NULL otherwise
12079  *
12080  * Return value: (transfer none): @widget's window.
12081  *
12082  * Since: 2.14
12083  */
12084 GdkWindow*
12085 gtk_widget_get_window (GtkWidget *widget)
12086 {
12087   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12088
12089   return widget->priv->window;
12090 }
12091
12092 /**
12093  * gtk_widget_get_support_multidevice:
12094  * @widget: a #GtkWidget
12095  *
12096  * Returns %TRUE if @widget is multiple pointer aware. See
12097  * gtk_widget_set_support_multidevice() for more information.
12098  *
12099  * Returns: %TRUE is @widget is multidevice aware.
12100  **/
12101 gboolean
12102 gtk_widget_get_support_multidevice (GtkWidget *widget)
12103 {
12104   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12105
12106   return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12107 }
12108
12109 /**
12110  * gtk_widget_set_support_multidevice:
12111  * @widget: a #GtkWidget
12112  * @support_multidevice: %TRUE to support input from multiple devices.
12113  *
12114  * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12115  * @widget will start receiving multiple, per device enter/leave events. Note
12116  * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12117  * gdk_window_set_support_multidevice() will have to be called manually on them.
12118  *
12119  * Since: 3.0
12120  **/
12121 void
12122 gtk_widget_set_support_multidevice (GtkWidget *widget,
12123                                     gboolean   support_multidevice)
12124 {
12125   GtkWidgetPrivate *priv;
12126
12127   g_return_if_fail (GTK_IS_WIDGET (widget));
12128
12129   priv = widget->priv;
12130
12131   if (support_multidevice)
12132     {
12133       GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12134       gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12135     }
12136   else
12137     {
12138       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12139       gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12140     }
12141
12142   if (gtk_widget_get_realized (widget))
12143     gdk_window_set_support_multidevice (priv->window, support_multidevice);
12144 }
12145
12146 static void
12147 _gtk_widget_set_has_focus (GtkWidget *widget,
12148                            gboolean   has_focus)
12149 {
12150   if (has_focus)
12151     GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12152   else
12153     GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12154 }
12155
12156 /**
12157  * gtk_widget_send_focus_change:
12158  * @widget: a #GtkWidget
12159  * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12160  *
12161  * Sends the focus change @event to @widget
12162  *
12163  * This function is not meant to be used by applications. The only time it
12164  * should be used is when it is necessary for a #GtkWidget to assign focus
12165  * to a widget that is semantically owned by the first widget even though
12166  * it's not a direct child - for instance, a search entry in a floating
12167  * window similar to the quick search in #GtkTreeView.
12168  *
12169  * An example of its usage is:
12170  *
12171  * |[
12172  *   GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12173  *
12174  *   fevent->focus_change.type = GDK_FOCUS_CHANGE;
12175  *   fevent->focus_change.in = TRUE;
12176  *   fevent->focus_change.window = gtk_widget_get_window (widget);
12177  *   if (fevent->focus_change.window != NULL)
12178  *     g_object_ref (fevent->focus_change.window);
12179  *
12180  *   gtk_widget_send_focus_change (widget, fevent);
12181  *
12182  *   gdk_event_free (event);
12183  * ]|
12184  *
12185  * Return value: the return value from the event signal emission: %TRUE
12186  *   if the event was handled, and %FALSE otherwise
12187  *
12188  * Since: 2.20
12189  */
12190 gboolean
12191 gtk_widget_send_focus_change (GtkWidget *widget,
12192                               GdkEvent  *event)
12193 {
12194   gboolean res;
12195
12196   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12197   g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12198
12199   g_object_ref (widget);
12200
12201   _gtk_widget_set_has_focus (widget, event->focus_change.in);
12202
12203   res = gtk_widget_event (widget, event);
12204
12205   g_object_notify (G_OBJECT (widget), "has-focus");
12206
12207   g_object_unref (widget);
12208
12209   return res;
12210 }