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