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