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