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