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