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