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