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