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