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