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