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