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