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