]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
removed call to gdk_pango_context_set_colormap() which isn't needed any
[~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 "gtkalias.h"
32 #include "gtkcontainer.h"
33 #include "gtkaccelmap.h"
34 #include "gtkclipboard.h"
35 #include "gtkiconfactory.h"
36 #include "gtkintl.h"
37 #include "gtkmain.h"
38 #include "gtkmarshalers.h"
39 #include "gtkrc.h"
40 #include "gtkselection.h"
41 #include "gtksettings.h"
42 #include "gtksizegroup.h"
43 #include "gtkwidget.h"
44 #include "gtkwindow.h"
45 #include "gtkbindings.h"
46 #include "gtkprivate.h"
47 #include "gdk/gdk.h"
48 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
49 #include <gobject/gvaluecollector.h>
50 #include <gobject/gobjectnotifyqueue.c>
51 #include "gdk/gdkkeysyms.h"
52 #include "gtkintl.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltips.h"
55 #include "gtkinvisible.h"
56
57 #define WIDGET_CLASS(w)  GTK_WIDGET_GET_CLASS (w)
58 #define INIT_PATH_SIZE  (512)
59
60
61 enum {
62   SHOW,
63   HIDE,
64   MAP,
65   UNMAP,
66   REALIZE,
67   UNREALIZE,
68   SIZE_REQUEST,
69   SIZE_ALLOCATE,
70   STATE_CHANGED,
71   PARENT_SET,
72   HIERARCHY_CHANGED,
73   STYLE_SET,
74   DIRECTION_CHANGED,
75   GRAB_NOTIFY,
76   CHILD_NOTIFY,
77   MNEMONIC_ACTIVATE,
78   GRAB_FOCUS,
79   FOCUS,
80   EVENT,
81   EVENT_AFTER,
82   BUTTON_PRESS_EVENT,
83   BUTTON_RELEASE_EVENT,
84   SCROLL_EVENT,
85   MOTION_NOTIFY_EVENT,
86   DELETE_EVENT,
87   DESTROY_EVENT,
88   EXPOSE_EVENT,
89   KEY_PRESS_EVENT,
90   KEY_RELEASE_EVENT,
91   ENTER_NOTIFY_EVENT,
92   LEAVE_NOTIFY_EVENT,
93   CONFIGURE_EVENT,
94   FOCUS_IN_EVENT,
95   FOCUS_OUT_EVENT,
96   MAP_EVENT,
97   UNMAP_EVENT,
98   PROPERTY_NOTIFY_EVENT,
99   SELECTION_CLEAR_EVENT,
100   SELECTION_REQUEST_EVENT,
101   SELECTION_NOTIFY_EVENT,
102   SELECTION_GET,
103   SELECTION_RECEIVED,
104   PROXIMITY_IN_EVENT,
105   PROXIMITY_OUT_EVENT,
106   DRAG_BEGIN,
107   DRAG_END,
108   DRAG_DATA_DELETE,
109   DRAG_LEAVE,
110   DRAG_MOTION,
111   DRAG_DROP,
112   DRAG_DATA_GET,
113   DRAG_DATA_RECEIVED,
114   CLIENT_EVENT,
115   NO_EXPOSE_EVENT,
116   VISIBILITY_NOTIFY_EVENT,
117   WINDOW_STATE_EVENT,
118   POPUP_MENU,
119   SHOW_HELP,
120   ACCEL_CLOSURES_CHANGED,
121   SCREEN_CHANGED,
122   CAN_ACTIVATE_ACCEL,
123   LAST_SIGNAL
124 };
125
126 enum {
127   PROP_0,
128   PROP_NAME,
129   PROP_PARENT,
130   PROP_WIDTH_REQUEST,
131   PROP_HEIGHT_REQUEST,
132   PROP_VISIBLE,
133   PROP_SENSITIVE,
134   PROP_APP_PAINTABLE,
135   PROP_CAN_FOCUS,
136   PROP_HAS_FOCUS,
137   PROP_IS_FOCUS,
138   PROP_CAN_DEFAULT,
139   PROP_HAS_DEFAULT,
140   PROP_RECEIVES_DEFAULT,
141   PROP_COMPOSITE_CHILD,
142   PROP_STYLE,
143   PROP_EVENTS,
144   PROP_EXTENSION_EVENTS,
145   PROP_NO_SHOW_ALL
146 };
147
148 typedef struct  _GtkStateData    GtkStateData;
149
150 struct _GtkStateData
151 {
152   GtkStateType  state;
153   guint         state_restoration : 1;
154   guint         parent_sensitive : 1;
155   guint         use_forall : 1;
156 };
157
158
159 /* --- prototypes --- */
160 static void     gtk_widget_class_init            (GtkWidgetClass    *klass);
161 static void     gtk_widget_init                  (GtkWidget         *widget);
162 static void     gtk_widget_set_property          (GObject           *object,
163                                                   guint              prop_id,
164                                                   const GValue      *value,
165                                                   GParamSpec        *pspec);
166 static void     gtk_widget_get_property          (GObject           *object,
167                                                   guint              prop_id,
168                                                   GValue            *value,
169                                                   GParamSpec        *pspec);
170 static void     gtk_widget_dispose               (GObject           *object);
171 static void     gtk_widget_real_destroy          (GtkObject         *object);
172 static void     gtk_widget_finalize              (GObject           *object);
173 static void     gtk_widget_real_show             (GtkWidget         *widget);
174 static void     gtk_widget_real_hide             (GtkWidget         *widget);
175 static void     gtk_widget_real_map              (GtkWidget         *widget);
176 static void     gtk_widget_real_unmap            (GtkWidget         *widget);
177 static void     gtk_widget_real_realize          (GtkWidget         *widget);
178 static void     gtk_widget_real_unrealize        (GtkWidget         *widget);
179 static void     gtk_widget_real_size_request     (GtkWidget         *widget,
180                                                   GtkRequisition    *requisition);
181 static void     gtk_widget_real_size_allocate    (GtkWidget         *widget,
182                                                   GtkAllocation     *allocation);
183 static void     gtk_widget_style_set             (GtkWidget         *widget,
184                                                   GtkStyle          *previous_style);
185 static void     gtk_widget_direction_changed     (GtkWidget         *widget,
186                                                   GtkTextDirection   previous_direction);
187
188 static void     gtk_widget_real_grab_focus       (GtkWidget         *focus_widget);
189 static gboolean gtk_widget_real_show_help        (GtkWidget         *widget,
190                                                   GtkWidgetHelpType  help_type);
191
192 static void     gtk_widget_dispatch_child_properties_changed    (GtkWidget        *object,
193                                                                  guint             n_pspecs,
194                                                                  GParamSpec      **pspecs);
195 static gboolean         gtk_widget_real_key_press_event         (GtkWidget        *widget,
196                                                                  GdkEventKey      *event);
197 static gboolean         gtk_widget_real_key_release_event       (GtkWidget        *widget,
198                                                                  GdkEventKey      *event);
199 static gboolean         gtk_widget_real_focus_in_event           (GtkWidget       *widget,
200                                                                   GdkEventFocus   *event);
201 static gboolean         gtk_widget_real_focus_out_event         (GtkWidget        *widget,
202                                                                  GdkEventFocus    *event);
203 static gboolean         gtk_widget_real_focus                   (GtkWidget        *widget,
204                                                                  GtkDirectionType  direction);
205 static PangoContext*    gtk_widget_peek_pango_context           (GtkWidget        *widget);
206 static void             gtk_widget_propagate_state              (GtkWidget        *widget,
207                                                                  GtkStateData     *data);
208 static void             gtk_widget_reset_rc_style               (GtkWidget        *widget);
209 static void             gtk_widget_set_style_internal           (GtkWidget        *widget,
210                                                                  GtkStyle         *style,
211                                                                  gboolean          initial_emission);
212 static gint             gtk_widget_event_internal               (GtkWidget        *widget,
213                                                                  GdkEvent         *event);
214 static gboolean         gtk_widget_real_mnemonic_activate       (GtkWidget        *widget,
215                                                                  gboolean          group_cycling);
216 static void             gtk_widget_aux_info_destroy             (GtkWidgetAuxInfo *aux_info);
217 static AtkObject*       gtk_widget_real_get_accessible          (GtkWidget        *widget);
218 static void             gtk_widget_accessible_interface_init    (AtkImplementorIface *iface);
219 static AtkObject*       gtk_widget_ref_accessible               (AtkImplementor *implementor);
220 static void             gtk_widget_invalidate_widget_windows    (GtkWidget        *widget,
221                                                                  GdkRegion        *region);
222 static GdkScreen *      gtk_widget_get_screen_unchecked         (GtkWidget        *widget);
223 static void             gtk_widget_queue_shallow_draw           (GtkWidget        *widget);
224 static gboolean         gtk_widget_real_can_activate_accel      (GtkWidget *widget,
225                                                                  guint      signal_id);
226      
227 static void gtk_widget_set_usize_internal (GtkWidget *widget,
228                                            gint       width,
229                                            gint       height);
230
231
232 /* --- variables --- */
233 static gpointer         parent_class = NULL;
234 static guint            widget_signals[LAST_SIGNAL] = { 0 };
235 static GMemChunk       *aux_info_mem_chunk = NULL;
236 static GtkStyle        *gtk_default_style = NULL;
237 static GSList          *colormap_stack = NULL;
238 static guint            composite_child_stack = 0;
239 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
240 static GParamSpecPool  *style_property_spec_pool = NULL;
241
242 static GQuark           quark_property_parser = 0;
243 static GQuark           quark_aux_info = 0;
244 static GQuark           quark_accel_path = 0;
245 static GQuark           quark_accel_closures = 0;
246 static GQuark           quark_event_mask = 0;
247 static GQuark           quark_extension_event_mode = 0;
248 static GQuark           quark_parent_window = 0;
249 static GQuark           quark_shape_info = 0;
250 static GQuark           quark_colormap = 0;
251 static GQuark           quark_pango_context = 0;
252 static GQuark           quark_rc_style = 0;
253 static GQuark           quark_accessible_object = 0;
254 static GQuark           quark_mnemonic_labels = 0;
255 GParamSpecPool         *_gtk_widget_child_property_pool = NULL;
256 GObjectNotifyContext   *_gtk_widget_child_property_notify_context = NULL;
257
258 /* --- functions --- */
259 GType
260 gtk_widget_get_type (void)
261 {
262   static GType widget_type = 0;
263   
264   if (!widget_type)
265     {
266       static const GTypeInfo widget_info =
267       {
268         sizeof (GtkWidgetClass),
269         NULL,           /* base_init */
270         NULL,           /* base_finalize */
271         (GClassInitFunc) gtk_widget_class_init,
272         NULL,           /* class_finalize */
273         NULL,           /* class_init */
274         sizeof (GtkWidget),
275         0,              /* n_preallocs */
276         (GInstanceInitFunc) gtk_widget_init,
277         NULL,           /* value_table */
278       };
279       
280       static const GInterfaceInfo accessibility_info =
281       {
282         (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
283         (GInterfaceFinalizeFunc) NULL,
284         NULL /* interface data */
285       };
286
287       widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget", 
288                                             &widget_info, G_TYPE_FLAG_ABSTRACT);
289
290       g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
291                                    &accessibility_info) ;
292
293     }
294   
295   return widget_type;
296 }
297
298 static void
299 child_property_notify_dispatcher (GObject     *object,
300                                   guint        n_pspecs,
301                                   GParamSpec **pspecs)
302 {
303   GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
304 }
305
306 static void
307 gtk_widget_class_init (GtkWidgetClass *klass)
308 {
309   static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
310   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
311   GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
312   GtkBindingSet *binding_set;
313   
314   parent_class = g_type_class_peek_parent (klass);
315
316   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
317   quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
318   quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
319   quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
320   quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
321   quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
322   quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
323   quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
324   quark_colormap = g_quark_from_static_string ("gtk-colormap");
325   quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
326   quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
327   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
328   quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
329
330   style_property_spec_pool = g_param_spec_pool_new (FALSE);
331   _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
332   cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
333   cpn_context.dispatcher = child_property_notify_dispatcher;
334   _gtk_widget_child_property_notify_context = &cpn_context;
335
336   gobject_class->dispose = gtk_widget_dispose;
337   gobject_class->finalize = gtk_widget_finalize;
338   gobject_class->set_property = gtk_widget_set_property;
339   gobject_class->get_property = gtk_widget_get_property;
340
341   object_class->destroy = gtk_widget_real_destroy;
342   
343   klass->activate_signal = 0;
344   klass->set_scroll_adjustments_signal = 0;
345   klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
346   klass->show = gtk_widget_real_show;
347   klass->show_all = gtk_widget_show;
348   klass->hide = gtk_widget_real_hide;
349   klass->hide_all = gtk_widget_hide;
350   klass->map = gtk_widget_real_map;
351   klass->unmap = gtk_widget_real_unmap;
352   klass->realize = gtk_widget_real_realize;
353   klass->unrealize = gtk_widget_real_unrealize;
354   klass->size_request = gtk_widget_real_size_request;
355   klass->size_allocate = gtk_widget_real_size_allocate;
356   klass->state_changed = NULL;
357   klass->parent_set = NULL;
358   klass->hierarchy_changed = NULL;
359   klass->style_set = gtk_widget_style_set;
360   klass->direction_changed = gtk_widget_direction_changed;
361   klass->grab_notify = NULL;
362   klass->child_notify = NULL;
363   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
364   klass->grab_focus = gtk_widget_real_grab_focus;
365   klass->focus = gtk_widget_real_focus;
366   klass->event = NULL;
367   klass->button_press_event = NULL;
368   klass->button_release_event = NULL;
369   klass->motion_notify_event = NULL;
370   klass->delete_event = NULL;
371   klass->destroy_event = NULL;
372   klass->expose_event = NULL;
373   klass->key_press_event = gtk_widget_real_key_press_event;
374   klass->key_release_event = gtk_widget_real_key_release_event;
375   klass->enter_notify_event = NULL;
376   klass->leave_notify_event = NULL;
377   klass->configure_event = NULL;
378   klass->focus_in_event = gtk_widget_real_focus_in_event;
379   klass->focus_out_event = gtk_widget_real_focus_out_event;
380   klass->map_event = NULL;
381   klass->unmap_event = NULL;
382   klass->window_state_event = NULL;
383   klass->property_notify_event = _gtk_selection_property_notify;
384   klass->selection_clear_event = gtk_selection_clear;
385   klass->selection_request_event = _gtk_selection_request;
386   klass->selection_notify_event = _gtk_selection_notify;
387   klass->selection_received = NULL;
388   klass->proximity_in_event = NULL;
389   klass->proximity_out_event = NULL;
390   klass->drag_begin = NULL;
391   klass->drag_end = NULL;
392   klass->drag_data_delete = NULL;
393   klass->drag_leave = NULL;
394   klass->drag_motion = NULL;
395   klass->drag_drop = NULL;
396   klass->drag_data_received = NULL;
397   klass->screen_changed = NULL;
398   klass->can_activate_accel = gtk_widget_real_can_activate_accel;
399
400   klass->show_help = gtk_widget_real_show_help;
401   
402   /* Accessibility support */
403   klass->get_accessible = gtk_widget_real_get_accessible;
404
405   klass->no_expose_event = NULL;
406
407   g_object_class_install_property (gobject_class,
408                                    PROP_NAME,
409                                    g_param_spec_string ("name",
410                                                         P_("Widget name"),
411                                                         P_("The name of the widget"),
412                                                         NULL,
413                                                         G_PARAM_READWRITE));
414   g_object_class_install_property (gobject_class,
415                                    PROP_PARENT,
416                                    g_param_spec_object ("parent",
417                                                         P_("Parent widget"), 
418                                                         P_("The parent widget of this widget. Must be a Container widget"),
419                                                         GTK_TYPE_CONTAINER,
420                                                         G_PARAM_READWRITE));
421
422   g_object_class_install_property (gobject_class,
423                                    PROP_WIDTH_REQUEST,
424                                    g_param_spec_int ("width_request",
425                                                      P_("Width request"),
426                                                      P_("Override for width request of the widget, or -1 if natural request should be used"),
427                                                      -1,
428                                                      G_MAXINT,
429                                                      -1,
430                                                      G_PARAM_READWRITE));
431   g_object_class_install_property (gobject_class,
432                                    PROP_HEIGHT_REQUEST,
433                                    g_param_spec_int ("height_request",
434                                                      P_("Height request"),
435                                                      P_("Override for height request of the widget, or -1 if natural request should be used"),
436                                                      -1,
437                                                      G_MAXINT,
438                                                      -1,
439                                                      G_PARAM_READWRITE));
440   g_object_class_install_property (gobject_class,
441                                    PROP_VISIBLE,
442                                    g_param_spec_boolean ("visible",
443                                                          P_("Visible"),
444                                                          P_("Whether the widget is visible"),
445                                                          FALSE,
446                                                          G_PARAM_READWRITE));
447   g_object_class_install_property (gobject_class,
448                                    PROP_SENSITIVE,
449                                    g_param_spec_boolean ("sensitive",
450                                                          P_("Sensitive"),
451                                                          P_("Whether the widget responds to input"),
452                                                          TRUE,
453                                                          G_PARAM_READWRITE));
454   g_object_class_install_property (gobject_class,
455                                    PROP_APP_PAINTABLE,
456                                    g_param_spec_boolean ("app_paintable",
457                                                          P_("Application paintable"),
458                                                          P_("Whether the application will paint directly on the widget"),
459                                                          FALSE,
460                                                          G_PARAM_READWRITE));
461   g_object_class_install_property (gobject_class,
462                                    PROP_CAN_FOCUS,
463                                    g_param_spec_boolean ("can_focus",
464                                                          P_("Can focus"),
465                                                          P_("Whether the widget can accept the input focus"),
466                                                          FALSE,
467                                                          G_PARAM_READWRITE));
468   g_object_class_install_property (gobject_class,
469                                    PROP_HAS_FOCUS,
470                                    g_param_spec_boolean ("has_focus",
471                                                          P_("Has focus"),
472                                                          P_("Whether the widget has the input focus"),
473                                                          FALSE,
474                                                          G_PARAM_READWRITE));
475   g_object_class_install_property (gobject_class,
476                                    PROP_IS_FOCUS,
477                                    g_param_spec_boolean ("is_focus",
478                                                          P_("Is focus"),
479                                                          P_("Whether the widget is the focus widget within the toplevel"),
480                                                          FALSE,
481                                                          G_PARAM_READWRITE));
482   g_object_class_install_property (gobject_class,
483                                    PROP_CAN_DEFAULT,
484                                    g_param_spec_boolean ("can_default",
485                                                          P_("Can default"),
486                                                          P_("Whether the widget can be the default widget"),
487                                                          FALSE,
488                                                          G_PARAM_READWRITE));
489   g_object_class_install_property (gobject_class,
490                                    PROP_HAS_DEFAULT,
491                                    g_param_spec_boolean ("has_default",
492                                                          P_("Has default"),
493                                                          P_("Whether the widget is the default widget"),
494                                                          FALSE,
495                                                          G_PARAM_READWRITE));
496   g_object_class_install_property (gobject_class,
497                                    PROP_RECEIVES_DEFAULT,
498                                    g_param_spec_boolean ("receives_default",
499                                                          P_("Receives default"),
500                                                          P_("If TRUE, the widget will receive the default action when it is focused"),
501                                                          FALSE,
502                                                          G_PARAM_READWRITE));
503   g_object_class_install_property (gobject_class,
504                                    PROP_COMPOSITE_CHILD,
505                                    g_param_spec_boolean ("composite_child",
506                                                          P_("Composite child"),
507                                                          P_("Whether the widget is part of a composite widget"),
508                                                          FALSE,
509                                                          G_PARAM_READABLE));
510   g_object_class_install_property (gobject_class,
511                                    PROP_STYLE,
512                                    g_param_spec_object ("style",
513                                                         P_("Style"),
514                                                         P_("The style of the widget, which contains information about how it will look (colors etc)"),
515                                                         GTK_TYPE_STYLE,
516                                                         G_PARAM_READWRITE));
517   g_object_class_install_property (gobject_class,
518                                    PROP_EVENTS,
519                                    g_param_spec_flags ("events",
520                                                        P_("Events"),
521                                                        P_("The event mask that decides what kind of GdkEvents this widget gets"),
522                                                        GDK_TYPE_EVENT_MASK,
523                                                        GDK_STRUCTURE_MASK,
524                                                        G_PARAM_READWRITE));
525   g_object_class_install_property (gobject_class,
526                                    PROP_EXTENSION_EVENTS,
527                                    g_param_spec_enum ("extension_events",
528                                                       P_("Extension events"),
529                                                       P_("The mask that decides what kind of extension events this widget gets"),
530                                                       GDK_TYPE_EXTENSION_MODE,
531                                                       GDK_EXTENSION_EVENTS_NONE,
532                                                       G_PARAM_READWRITE));
533   g_object_class_install_property (gobject_class,
534                                    PROP_NO_SHOW_ALL,
535                                    g_param_spec_boolean ("no_show_all",
536                                                          P_("No show all"),
537                                                          P_("Whether gtk_widget_show_all() should not affect this widget"),
538                                                          FALSE,
539                                                          G_PARAM_READWRITE));
540   widget_signals[SHOW] =
541     g_signal_new ("show",
542                   G_TYPE_FROM_CLASS (gobject_class),
543                   G_SIGNAL_RUN_FIRST,
544                   G_STRUCT_OFFSET (GtkWidgetClass, show),
545                   NULL, NULL,
546                   _gtk_marshal_VOID__VOID,
547                   G_TYPE_NONE, 0);
548   widget_signals[HIDE] =
549     g_signal_new ("hide",
550                   G_TYPE_FROM_CLASS (gobject_class),
551                   G_SIGNAL_RUN_FIRST,
552                   G_STRUCT_OFFSET (GtkWidgetClass, hide),
553                   NULL, NULL,
554                   _gtk_marshal_VOID__VOID,
555                   G_TYPE_NONE, 0);
556   widget_signals[MAP] =
557     g_signal_new ("map",
558                   G_TYPE_FROM_CLASS (gobject_class),
559                   G_SIGNAL_RUN_FIRST,
560                   G_STRUCT_OFFSET (GtkWidgetClass, map),
561                   NULL, NULL,
562                   _gtk_marshal_VOID__VOID,
563                   G_TYPE_NONE, 0);
564   widget_signals[UNMAP] =
565     g_signal_new ("unmap",
566                   G_TYPE_FROM_CLASS (gobject_class),
567                   G_SIGNAL_RUN_FIRST,
568                   G_STRUCT_OFFSET (GtkWidgetClass, unmap),
569                   NULL, NULL,
570                   _gtk_marshal_VOID__VOID,
571                   G_TYPE_NONE, 0);
572   widget_signals[REALIZE] =
573     g_signal_new ("realize",
574                   G_TYPE_FROM_CLASS (gobject_class),
575                   G_SIGNAL_RUN_FIRST,
576                   G_STRUCT_OFFSET (GtkWidgetClass, realize),
577                   NULL, NULL,
578                   _gtk_marshal_VOID__VOID,
579                   G_TYPE_NONE, 0);
580   widget_signals[UNREALIZE] =
581     g_signal_new ("unrealize",
582                   G_TYPE_FROM_CLASS (gobject_class),
583                   G_SIGNAL_RUN_LAST,
584                   G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
585                   NULL, NULL,
586                   _gtk_marshal_VOID__VOID,
587                   G_TYPE_NONE, 0);
588   widget_signals[SIZE_REQUEST] =
589     g_signal_new ("size_request",
590                   G_TYPE_FROM_CLASS (gobject_class),
591                   G_SIGNAL_RUN_FIRST,
592                   G_STRUCT_OFFSET (GtkWidgetClass, size_request),
593                   NULL, NULL,
594                   _gtk_marshal_VOID__BOXED,
595                   G_TYPE_NONE, 1,
596                   GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
597   widget_signals[SIZE_ALLOCATE] = 
598     g_signal_new ("size_allocate",
599                   G_TYPE_FROM_CLASS (gobject_class),
600                   G_SIGNAL_RUN_FIRST,
601                   G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
602                   NULL, NULL,
603                   _gtk_marshal_VOID__BOXED,
604                   G_TYPE_NONE, 1,
605                   GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
606   widget_signals[STATE_CHANGED] =
607     g_signal_new ("state_changed",
608                   G_TYPE_FROM_CLASS (gobject_class),
609                   G_SIGNAL_RUN_FIRST,
610                   G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
611                   NULL, NULL,
612                   _gtk_marshal_VOID__ENUM,
613                   G_TYPE_NONE, 1,
614                   GTK_TYPE_STATE_TYPE);
615   widget_signals[PARENT_SET] =
616     g_signal_new ("parent_set",
617                   G_TYPE_FROM_CLASS (gobject_class),
618                   G_SIGNAL_RUN_FIRST,
619                   G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
620                   NULL, NULL,
621                   _gtk_marshal_VOID__OBJECT,
622                   G_TYPE_NONE, 1,
623                   GTK_TYPE_WIDGET);
624   widget_signals[HIERARCHY_CHANGED] =
625     g_signal_new ("hierarchy_changed",
626                   G_TYPE_FROM_CLASS (gobject_class),
627                   G_SIGNAL_RUN_LAST,
628                   G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
629                   NULL, NULL,
630                   _gtk_marshal_VOID__OBJECT,
631                   G_TYPE_NONE, 1,
632                   GTK_TYPE_WIDGET);
633   widget_signals[STYLE_SET] =
634     g_signal_new ("style_set",
635                   G_TYPE_FROM_CLASS (gobject_class),
636                   G_SIGNAL_RUN_FIRST,
637                   G_STRUCT_OFFSET (GtkWidgetClass, style_set),
638                   NULL, NULL,
639                   _gtk_marshal_VOID__OBJECT,
640                   G_TYPE_NONE, 1,
641                   GTK_TYPE_STYLE);
642   widget_signals[DIRECTION_CHANGED] =
643     g_signal_new ("direction_changed",
644                   G_TYPE_FROM_CLASS (gobject_class),
645                   G_SIGNAL_RUN_FIRST,
646                   G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
647                   NULL, NULL,
648                   _gtk_marshal_VOID__ENUM,
649                   G_TYPE_NONE, 1,
650                   GTK_TYPE_TEXT_DIRECTION);
651   widget_signals[GRAB_NOTIFY] =
652     g_signal_new ("grab_notify",
653                   G_TYPE_FROM_CLASS (gobject_class),
654                   G_SIGNAL_RUN_FIRST,
655                   G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
656                   NULL, NULL,
657                   _gtk_marshal_VOID__BOOLEAN,
658                   G_TYPE_NONE, 1,
659                   G_TYPE_BOOLEAN);
660
661 /**
662  * GtkWidget::child-notify:
663  * @widget: the object which received the signal.
664  * @pspec: the #GParamSpec of the changed child property.
665  *
666  * The ::child-notify signal is emitted for each child property that has 
667  * changed on an object. The signal's detail holds the property name. 
668  */
669   widget_signals[CHILD_NOTIFY] =
670     g_signal_new ("child_notify",
671                    G_TYPE_FROM_CLASS (gobject_class),
672                    G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
673                    G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
674                    NULL, NULL,
675                    g_cclosure_marshal_VOID__PARAM,
676                    G_TYPE_NONE, 1,
677                    G_TYPE_PARAM);
678   widget_signals[MNEMONIC_ACTIVATE] =
679     g_signal_new ("mnemonic_activate",
680                   G_TYPE_FROM_CLASS (gobject_class),
681                   G_SIGNAL_RUN_LAST,
682                   G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
683                   _gtk_boolean_handled_accumulator, NULL,
684                   _gtk_marshal_BOOLEAN__BOOLEAN,
685                   G_TYPE_BOOLEAN, 1,
686                   G_TYPE_BOOLEAN);
687   widget_signals[GRAB_FOCUS] =
688     g_signal_new ("grab_focus",
689                   G_TYPE_FROM_CLASS (gobject_class),
690                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
691                   G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
692                   NULL, NULL,
693                   _gtk_marshal_VOID__VOID,
694                   G_TYPE_NONE, 0);
695   widget_signals[FOCUS] =
696     g_signal_new ("focus",
697                   G_TYPE_FROM_CLASS (object_class),
698                   G_SIGNAL_RUN_LAST,
699                   G_STRUCT_OFFSET (GtkWidgetClass, focus),
700                   _gtk_boolean_handled_accumulator, NULL,
701                   _gtk_marshal_BOOLEAN__ENUM,
702                   G_TYPE_BOOLEAN, 1,
703                   GTK_TYPE_DIRECTION_TYPE);
704   widget_signals[EVENT] =
705     g_signal_new ("event",
706                   G_TYPE_FROM_CLASS (gobject_class),
707                   G_SIGNAL_RUN_LAST,
708                   G_STRUCT_OFFSET (GtkWidgetClass, event),
709                   _gtk_boolean_handled_accumulator, NULL,
710                   _gtk_marshal_BOOLEAN__BOXED,
711                   G_TYPE_BOOLEAN, 1,
712                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
713   widget_signals[EVENT_AFTER] =
714     g_signal_new ("event-after",
715                   G_TYPE_FROM_CLASS (gobject_class),
716                   0,
717                   0,
718                   NULL, NULL,
719                   _gtk_marshal_VOID__BOXED,
720                   G_TYPE_NONE, 1,
721                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
722   widget_signals[BUTTON_PRESS_EVENT] =
723     g_signal_new ("button_press_event",
724                   G_TYPE_FROM_CLASS (gobject_class),
725                   G_SIGNAL_RUN_LAST,
726                   G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
727                   _gtk_boolean_handled_accumulator, NULL,
728                   _gtk_marshal_BOOLEAN__BOXED,
729                   G_TYPE_BOOLEAN, 1,
730                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
731   widget_signals[BUTTON_RELEASE_EVENT] =
732     g_signal_new ("button_release_event",
733                   G_TYPE_FROM_CLASS (gobject_class),
734                   G_SIGNAL_RUN_LAST,
735                   G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
736                   _gtk_boolean_handled_accumulator, NULL,
737                   _gtk_marshal_BOOLEAN__BOXED,
738                   G_TYPE_BOOLEAN, 1,
739                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
740   widget_signals[SCROLL_EVENT] =
741     g_signal_new ("scroll_event",
742                   G_TYPE_FROM_CLASS (gobject_class),
743                   G_SIGNAL_RUN_LAST,
744                   G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
745                   _gtk_boolean_handled_accumulator, NULL,
746                   _gtk_marshal_BOOLEAN__BOXED,
747                   G_TYPE_BOOLEAN, 1,
748                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
749   widget_signals[MOTION_NOTIFY_EVENT] =
750     g_signal_new ("motion_notify_event",
751                   G_TYPE_FROM_CLASS (gobject_class),
752                   G_SIGNAL_RUN_LAST,
753                   G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
754                   _gtk_boolean_handled_accumulator, NULL,
755                   _gtk_marshal_BOOLEAN__BOXED,
756                   G_TYPE_BOOLEAN, 1,
757                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
758   widget_signals[DELETE_EVENT] =
759     g_signal_new ("delete_event",
760                   G_TYPE_FROM_CLASS (gobject_class),
761                   G_SIGNAL_RUN_LAST,
762                   G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
763                   _gtk_boolean_handled_accumulator, NULL,
764                   _gtk_marshal_BOOLEAN__BOXED,
765                   G_TYPE_BOOLEAN, 1,
766                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
767   widget_signals[DESTROY_EVENT] =
768     g_signal_new ("destroy_event",
769                   G_TYPE_FROM_CLASS (gobject_class),
770                   G_SIGNAL_RUN_LAST,
771                   G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
772                   _gtk_boolean_handled_accumulator, NULL,
773                   _gtk_marshal_BOOLEAN__BOXED,
774                   G_TYPE_BOOLEAN, 1,
775                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
776   widget_signals[EXPOSE_EVENT] =
777     g_signal_new ("expose_event",
778                   G_TYPE_FROM_CLASS (gobject_class),
779                   G_SIGNAL_RUN_LAST,
780                   G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
781                   _gtk_boolean_handled_accumulator, NULL,
782                   _gtk_marshal_BOOLEAN__BOXED,
783                   G_TYPE_BOOLEAN, 1,
784                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
785   widget_signals[KEY_PRESS_EVENT] =
786     g_signal_new ("key_press_event",
787                   G_TYPE_FROM_CLASS (gobject_class),
788                   G_SIGNAL_RUN_LAST,
789                   G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
790                   _gtk_boolean_handled_accumulator, NULL,
791                   _gtk_marshal_BOOLEAN__BOXED,
792                   G_TYPE_BOOLEAN, 1,
793                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
794   widget_signals[KEY_RELEASE_EVENT] =
795     g_signal_new ("key_release_event",
796                   G_TYPE_FROM_CLASS (gobject_class),
797                   G_SIGNAL_RUN_LAST,
798                   G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
799                   _gtk_boolean_handled_accumulator, NULL,
800                   _gtk_marshal_BOOLEAN__BOXED,
801                   G_TYPE_BOOLEAN, 1,
802                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
803   widget_signals[ENTER_NOTIFY_EVENT] =
804     g_signal_new ("enter_notify_event",
805                   G_TYPE_FROM_CLASS (gobject_class),
806                   G_SIGNAL_RUN_LAST,
807                   G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
808                   _gtk_boolean_handled_accumulator, NULL,
809                   _gtk_marshal_BOOLEAN__BOXED,
810                   G_TYPE_BOOLEAN, 1,
811                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
812   widget_signals[LEAVE_NOTIFY_EVENT] =
813     g_signal_new ("leave_notify_event",
814                   G_TYPE_FROM_CLASS (gobject_class),
815                   G_SIGNAL_RUN_LAST,
816                   G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
817                   _gtk_boolean_handled_accumulator, NULL,
818                   _gtk_marshal_BOOLEAN__BOXED,
819                   G_TYPE_BOOLEAN, 1,
820                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
821   widget_signals[CONFIGURE_EVENT] =
822     g_signal_new ("configure_event",
823                   G_TYPE_FROM_CLASS (gobject_class),
824                   G_SIGNAL_RUN_LAST,
825                   G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
826                   _gtk_boolean_handled_accumulator, NULL,
827                   _gtk_marshal_BOOLEAN__BOXED,
828                   G_TYPE_BOOLEAN, 1,
829                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
830   widget_signals[FOCUS_IN_EVENT] =
831     g_signal_new ("focus_in_event",
832                   G_TYPE_FROM_CLASS (gobject_class),
833                   G_SIGNAL_RUN_LAST,
834                   G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
835                   _gtk_boolean_handled_accumulator, NULL,
836                   _gtk_marshal_BOOLEAN__BOXED,
837                   G_TYPE_BOOLEAN, 1,
838                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
839   widget_signals[FOCUS_OUT_EVENT] =
840     g_signal_new ("focus_out_event",
841                   G_TYPE_FROM_CLASS (gobject_class),
842                   G_SIGNAL_RUN_LAST,
843                   G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
844                   _gtk_boolean_handled_accumulator, NULL,
845                   _gtk_marshal_BOOLEAN__BOXED,
846                   G_TYPE_BOOLEAN, 1,
847                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
848   widget_signals[MAP_EVENT] =
849     g_signal_new ("map_event",
850                   G_TYPE_FROM_CLASS (gobject_class),
851                   G_SIGNAL_RUN_LAST,
852                   G_STRUCT_OFFSET (GtkWidgetClass, map_event),
853                   _gtk_boolean_handled_accumulator, NULL,
854                   _gtk_marshal_BOOLEAN__BOXED,
855                   G_TYPE_BOOLEAN, 1,
856                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
857   widget_signals[UNMAP_EVENT] =
858     g_signal_new ("unmap_event",
859                   G_TYPE_FROM_CLASS (gobject_class),
860                   G_SIGNAL_RUN_LAST,
861                   G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
862                   _gtk_boolean_handled_accumulator, NULL,
863                   _gtk_marshal_BOOLEAN__BOXED,
864                   G_TYPE_BOOLEAN, 1,
865                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
866   widget_signals[PROPERTY_NOTIFY_EVENT] =
867     g_signal_new ("property_notify_event",
868                   G_TYPE_FROM_CLASS (gobject_class),
869                   G_SIGNAL_RUN_LAST,
870                   G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
871                   _gtk_boolean_handled_accumulator, NULL,
872                   _gtk_marshal_BOOLEAN__BOXED,
873                   G_TYPE_BOOLEAN, 1,
874                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
875   widget_signals[SELECTION_CLEAR_EVENT] =
876     g_signal_new ("selection_clear_event",
877                   G_TYPE_FROM_CLASS (gobject_class),
878                   G_SIGNAL_RUN_LAST,
879                   G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
880                   _gtk_boolean_handled_accumulator, NULL,
881                   _gtk_marshal_BOOLEAN__BOXED,
882                   G_TYPE_BOOLEAN, 1,
883                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
884   widget_signals[SELECTION_REQUEST_EVENT] =
885     g_signal_new ("selection_request_event",
886                   G_TYPE_FROM_CLASS (gobject_class),
887                   G_SIGNAL_RUN_LAST,
888                   G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
889                   _gtk_boolean_handled_accumulator, NULL,
890                   _gtk_marshal_BOOLEAN__BOXED,
891                   G_TYPE_BOOLEAN, 1,
892                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
893   widget_signals[SELECTION_NOTIFY_EVENT] =
894     g_signal_new ("selection_notify_event",
895                   G_TYPE_FROM_CLASS (gobject_class),
896                   G_SIGNAL_RUN_LAST,
897                   G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
898                   _gtk_boolean_handled_accumulator, NULL,
899                   _gtk_marshal_BOOLEAN__BOXED,
900                   G_TYPE_BOOLEAN, 1,
901                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
902   widget_signals[SELECTION_RECEIVED] =
903     g_signal_new ("selection_received",
904                   G_TYPE_FROM_CLASS (gobject_class),
905                   G_SIGNAL_RUN_LAST,
906                   G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
907                   NULL, NULL,
908                   _gtk_marshal_VOID__BOXED_UINT,
909                   G_TYPE_NONE, 2,
910                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
911                   G_TYPE_UINT);
912   widget_signals[SELECTION_GET] =
913     g_signal_new ("selection_get",
914                   G_TYPE_FROM_CLASS (gobject_class),
915                   G_SIGNAL_RUN_LAST,
916                   G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
917                   NULL, NULL,
918                   _gtk_marshal_VOID__BOXED_UINT_UINT,
919                   G_TYPE_NONE, 3,
920                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
921                   G_TYPE_UINT,
922                   G_TYPE_UINT);
923   widget_signals[PROXIMITY_IN_EVENT] =
924     g_signal_new ("proximity_in_event",
925                   G_TYPE_FROM_CLASS (gobject_class),
926                   G_SIGNAL_RUN_LAST,
927                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
928                   _gtk_boolean_handled_accumulator, NULL,
929                   _gtk_marshal_BOOLEAN__BOXED,
930                   G_TYPE_BOOLEAN, 1,
931                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
932   widget_signals[PROXIMITY_OUT_EVENT] =
933     g_signal_new ("proximity_out_event",
934                   G_TYPE_FROM_CLASS (gobject_class),
935                   G_SIGNAL_RUN_LAST,
936                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
937                   _gtk_boolean_handled_accumulator, NULL,
938                   _gtk_marshal_BOOLEAN__BOXED,
939                   G_TYPE_BOOLEAN, 1,
940                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
941
942   /**
943    * GtkWidget::drag-leave:
944    * @widget: the object which received the signal.
945    * @drag_context: the drag context
946    * @time: the timestamp of the motion event
947    *
948    * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
949    * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
950    * undo highlighting with gtk_drag_unhighlight()
951    */
952   widget_signals[DRAG_LEAVE] =
953     g_signal_new ("drag_leave",
954                   G_TYPE_FROM_CLASS (gobject_class),
955                   G_SIGNAL_RUN_LAST,
956                   G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
957                   NULL, NULL,
958                   _gtk_marshal_VOID__OBJECT_UINT,
959                   G_TYPE_NONE, 2,
960                   GDK_TYPE_DRAG_CONTEXT,
961                   G_TYPE_UINT);
962
963   /**
964    * GtkWidget::drag-begin:
965    * @widget: the object which received the signal.
966    * @drag_context: the drag context
967    *
968    * The ::drag-begin signal is emitted on the drag source when a drag is started. 
969    * A typical reason to connect to this signal is to set up a custom drag icon with
970    * gtk_drag_source_set_icon().
971    */
972   widget_signals[DRAG_BEGIN] =
973     g_signal_new ("drag_begin",
974                   G_TYPE_FROM_CLASS (gobject_class),
975                   G_SIGNAL_RUN_LAST,
976                   G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
977                   NULL, NULL,
978                   _gtk_marshal_VOID__OBJECT,
979                   G_TYPE_NONE, 1,
980                   GDK_TYPE_DRAG_CONTEXT);
981
982   /**
983    * GtkWidget::drag-end:
984    * @widget: the object which received the signal.
985    * @drag_context: the drag context
986    *
987    * The ::drag-end signal is emitted on the drag source when a drag is finished. 
988    * A typical reason to connect to this signal is to undo things done in ::drag-begin.
989    */
990   widget_signals[DRAG_END] =
991     g_signal_new ("drag_end",
992                   G_TYPE_FROM_CLASS (gobject_class),
993                   G_SIGNAL_RUN_LAST,
994                   G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
995                   NULL, NULL,
996                   _gtk_marshal_VOID__OBJECT,
997                   G_TYPE_NONE, 1,
998                   GDK_TYPE_DRAG_CONTEXT);
999
1000   /**
1001    * GtkWidget::drag-data-delete:
1002    * @widget: the object which received the signal.
1003    * @drag_context: the drag context
1004    *
1005    * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1006    * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1007    * the data that has been dropped. What "delete" means, depends on the context of the drag
1008    * operation. 
1009    */
1010   widget_signals[DRAG_DATA_DELETE] =
1011     g_signal_new ("drag_data_delete",
1012                   G_TYPE_FROM_CLASS (gobject_class),
1013                   G_SIGNAL_RUN_LAST,
1014                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1015                   NULL, NULL,
1016                   _gtk_marshal_VOID__OBJECT,
1017                   G_TYPE_NONE, 1,
1018                   GDK_TYPE_DRAG_CONTEXT);
1019
1020   /**
1021    * GtkWidget::drag-motion:
1022    * @widget: the object which received the signal.
1023    * @drag_context: the drag context
1024    * @x: the x coordinate of the current cursor position
1025    * @y: the y coordinate of the current cursor position
1026    * @time: the timestamp of the motion event
1027    * @returns: whether the cursor position is in a drop zone
1028    *
1029    * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1030    * the widget during a drag. The signal handler must determine whether the cursor position is in 
1031    * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1032    * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1033    * providing the necessary information for displaying feedback to the user, by calling
1034    * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1035    * based solely on the cursor position and the type of the data, the handler may inspect the dragged 
1036    * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received 
1037    * handler. 
1038    *
1039    * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1040    * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1041    * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight 
1042    * the drop site with gtk_drag_highlight().
1043    *
1044    * <informalexample><programlisting> 
1045    * static void
1046    * drag_motion (GtkWidget *widget,
1047    *              GdkDragContext *context,
1048    *              gint x,
1049    *              gint y,
1050    *              guint time)
1051    * {
1052    *   GdkAtom target;
1053    *  
1054    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1055    *  
1056    *   if (!private_data->drag_highlight) 
1057    *    {
1058    *      private_data->drag_highlight = 1;
1059    *      gtk_drag_highlight (widget);
1060    *    }
1061    *  
1062    *   target = gtk_drag_dest_find_target (widget, context, NULL);
1063    *   if (target == GDK_NONE)
1064    *     gdk_drag_status (context, 0, time);
1065    *   else 
1066    *    {
1067    *      private_data->pending_status = context->suggested_action;
1068    *      gtk_drag_get_data (widget, context, target, time);
1069    *    }
1070    *  
1071    *   return TRUE;
1072    * }
1073    *   
1074    * static void
1075    * drag_data_received (GtkWidget        *widget,
1076    *                     GdkDragContext   *context,
1077    *                     gint              x,
1078    *                     gint              y,
1079    *                     GtkSelectionData *selection_data,
1080    *                     guint             info,
1081    *                     guint             time)
1082    * {
1083    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1084    *   
1085    *   if (private_data->suggested_action) 
1086    *    {
1087    *      private_data->suggested_action = 0;
1088    *      
1089    *     /<!-- -->* We are getting this data due to a request in drag_motion,
1090    *      * rather than due to a request in drag_drop, so we are just
1091    *      * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1092    *      *<!-- -->/
1093    *      str = gtk_selection_data_get_text (selection_data);
1094    *      if (!data_is_acceptable (str)) 
1095    *        gdk_drag_status (context, 0, time);
1096    *      else
1097    *        gdk_drag_status (context, private_data->suggested_action, time);
1098    *    }
1099    *   else
1100    *    {
1101    *      /<!-- -->* accept the drop *<!-- -->/
1102    *    }
1103    * }
1104    * </programlisting></informalexample>
1105    */
1106   widget_signals[DRAG_MOTION] =
1107     g_signal_new ("drag_motion",
1108                   G_TYPE_FROM_CLASS (gobject_class),
1109                   G_SIGNAL_RUN_LAST,
1110                   G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1111                   _gtk_boolean_handled_accumulator, NULL,
1112                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1113                   G_TYPE_BOOLEAN, 4,
1114                   GDK_TYPE_DRAG_CONTEXT,
1115                   G_TYPE_INT,
1116                   G_TYPE_INT,
1117                   G_TYPE_UINT);
1118
1119   /**
1120    * GtkWidget::drag-drop:
1121    * @widget: the object which received the signal.
1122    * @drag_context: the drag context
1123    * @x: the x coordinate of the current cursor position
1124    * @y: the y coordinate of the current cursor position
1125    * @time: the timestamp of the motion event
1126    * @returns: whether the cursor position is in a drop zone
1127    *
1128    * The ::drag-drop signal is emitted on the drop site when the user drops the data
1129    * onto the widget. The signal handler must determine whether the cursor position is in 
1130    * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further 
1131    * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler 
1132    * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1133    * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1134    * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the 
1135    * supported targets.
1136    */
1137   widget_signals[DRAG_DROP] =
1138     g_signal_new ("drag_drop",
1139                   G_TYPE_FROM_CLASS (gobject_class),
1140                   G_SIGNAL_RUN_LAST,
1141                   G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1142                   _gtk_boolean_handled_accumulator, NULL,
1143                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1144                   G_TYPE_BOOLEAN, 4,
1145                   GDK_TYPE_DRAG_CONTEXT,
1146                   G_TYPE_INT,
1147                   G_TYPE_INT,
1148                   G_TYPE_UINT);
1149
1150   /** 
1151    * GtkWidget::drag-data-get:
1152    * @widget: the object which received the signal.
1153    * @drag_context: the drag context
1154    * @data: the #GtkSelectionData to be filled with the dragged data
1155    * @info: the info that has been registered with the target in the #GtkTargetList.
1156    * @time: the timestamp at which the data was requested
1157    *
1158    * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1159    * the data which is dragged. It is the responsibility of the signal handler to fill @data
1160    * with the data in the format which is indicated by @info. See gtk_selection_data_set() and 
1161    * gtk_selection_data_set_text().
1162    */
1163   widget_signals[DRAG_DATA_GET] =
1164     g_signal_new ("drag_data_get",
1165                   G_TYPE_FROM_CLASS (gobject_class),
1166                   G_SIGNAL_RUN_LAST,
1167                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1168                   NULL, NULL,
1169                   _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1170                   G_TYPE_NONE, 4,
1171                   GDK_TYPE_DRAG_CONTEXT,
1172                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1173                   G_TYPE_UINT,
1174                   G_TYPE_UINT);
1175
1176 /**
1177  * GtkWidget::drag-data-received:
1178  * @widget: the object which received the signal.
1179  * @drag_context: the drag context
1180  * @x: where the drop happened
1181  * @y: where the drop happened
1182  * @data: the received data
1183  * @info: the info that has been registered with the target in the #GtkTargetList.
1184  * @time: the timestamp at which the data was received
1185  *
1186  * The ::drag-data-received signal is emitted on the drop site when the dragged data has been 
1187  * received. If the data was received in order to determine whether the drop will be accepted, 
1188  * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag. 
1189  * If the data was received in response to a ::drag-drop signal (and this is the last target to be 
1190  * received), the handler for this signal is expected to process the received data and then call 
1191  * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed 
1192  * successfully. 
1193  * 
1194  * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(), 
1195  * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1196  * <informalexample><programlisting>
1197  * void  
1198  * drag_data_received (GtkWidget          *widget,
1199  *                     GdkDragContext     *drag_context,
1200  *                     gint                x,
1201  *                     gint                y,
1202  *                     GtkSelectionData   *data,
1203  *                     guint               info,
1204  *                     guint               time)
1205  * {
1206  *   if ((data->length >= 0) && (data->format == 8))
1207  *     {
1208  *       if (drag_context->action == GDK_ACTION_ASK) 
1209  *         {
1210  *           GtkWidget *dialog;
1211  *           gint response;
1212  *           
1213  *           dialog = gtk_message_dialog_new (NULL,
1214  *                                            GTK_DIALOG_MODAL | 
1215  *                                            GTK_DIALOG_DESTROY_WITH_PARENT,
1216  *                                            GTK_MESSAGE_INFO,
1217  *                                            GTK_BUTTONS_YES_NO,
1218  *                                            "Move the data ?\n");
1219  *           response = gtk_dialog_run (GTK_DIALOG (dialog));
1220  *           gtk_widget_destroy (dialog);
1221  *             
1222  *           if (response == GTK_RESPONSE_YES)
1223  *             drag_context->action = GDK_ACTION_MOVE;
1224  *           else
1225  *             drag_context->action = GDK_ACTION_COPY;
1226  *          }
1227  *          
1228  *       gtk_drag_finish (drag_context, TRUE, FALSE, time);
1229  *       return;
1230  *     }
1231  *       
1232  *    gtk_drag_finish (drag_context, FALSE, FALSE, time);
1233  *  }
1234  * </programlisting></informalexample>
1235  */
1236   widget_signals[DRAG_DATA_RECEIVED] =
1237     g_signal_new ("drag_data_received",
1238                   G_TYPE_FROM_CLASS (gobject_class),
1239                   G_SIGNAL_RUN_LAST,
1240                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1241                   NULL, NULL,
1242                   _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1243                   G_TYPE_NONE, 6,
1244                   GDK_TYPE_DRAG_CONTEXT,
1245                   G_TYPE_INT,
1246                   G_TYPE_INT,
1247                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1248                   G_TYPE_UINT,
1249                   G_TYPE_UINT);
1250   widget_signals[VISIBILITY_NOTIFY_EVENT] =
1251     g_signal_new ("visibility_notify_event",
1252                   G_TYPE_FROM_CLASS (gobject_class),
1253                   G_SIGNAL_RUN_LAST,
1254                   G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1255                   _gtk_boolean_handled_accumulator, NULL,
1256                   _gtk_marshal_BOOLEAN__BOXED,
1257                   G_TYPE_BOOLEAN, 1,
1258                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1259   widget_signals[CLIENT_EVENT] =
1260     g_signal_new ("client_event",
1261                   G_TYPE_FROM_CLASS (gobject_class),
1262                   G_SIGNAL_RUN_LAST,
1263                   G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1264                   _gtk_boolean_handled_accumulator, NULL,
1265                   _gtk_marshal_BOOLEAN__BOXED,
1266                   G_TYPE_BOOLEAN, 1,
1267                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1268   widget_signals[NO_EXPOSE_EVENT] =
1269     g_signal_new ("no_expose_event",
1270                   G_TYPE_FROM_CLASS (gobject_class),
1271                   G_SIGNAL_RUN_LAST,
1272                   G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1273                   _gtk_boolean_handled_accumulator, NULL,
1274                   _gtk_marshal_BOOLEAN__BOXED,
1275                   G_TYPE_BOOLEAN, 1,
1276                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1277   widget_signals[WINDOW_STATE_EVENT] =
1278     g_signal_new ("window_state_event",
1279                   G_TYPE_FROM_CLASS (gobject_class),
1280                   G_SIGNAL_RUN_LAST,
1281                   G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1282                   _gtk_boolean_handled_accumulator, NULL,
1283                   _gtk_marshal_BOOLEAN__BOXED,
1284                   G_TYPE_BOOLEAN, 1,
1285                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1286 /**
1287  * GtkWidget::popup-menu
1288  * @widget: the object which received the signal
1289  * @returns: TRUE if a menu was activated
1290  *
1291  * This signal gets emitted whenever a widget should pop up a context-sensitive
1292  * menu.  This usually happens through the standard key binding mechanism; by
1293  * pressing a certain key while a widget is focused, the user can cause the
1294  * widget to pop up a menu.  For example, the #GtkEntry widget creates a menu
1295  * with clipboard commands.  See <xref linkend="checklist-popup-menu"/> for an
1296  * example of how to use this signal.
1297  */
1298   widget_signals[POPUP_MENU] =
1299     g_signal_new ("popup_menu",
1300                   G_TYPE_FROM_CLASS (gobject_class),
1301                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1302                   G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1303                   _gtk_boolean_handled_accumulator, NULL,
1304                   _gtk_marshal_BOOLEAN__VOID,
1305                   G_TYPE_BOOLEAN, 0);
1306   widget_signals[SHOW_HELP] =
1307     g_signal_new ("show_help",
1308                   G_TYPE_FROM_CLASS (gobject_class),
1309                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1310                   G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1311                   _gtk_boolean_handled_accumulator, NULL,
1312                   _gtk_marshal_BOOLEAN__ENUM,
1313                   G_TYPE_BOOLEAN, 1,
1314                   GTK_TYPE_WIDGET_HELP_TYPE);
1315   widget_signals[ACCEL_CLOSURES_CHANGED] =
1316     g_signal_new ("accel_closures_changed",
1317                   G_TYPE_FROM_CLASS (gobject_class),
1318                   0,
1319                   0,
1320                   NULL, NULL,
1321                   _gtk_marshal_NONE__NONE,
1322                   G_TYPE_NONE, 0);
1323   widget_signals[SCREEN_CHANGED] =
1324     g_signal_new ("screen_changed",
1325                   G_TYPE_FROM_CLASS (gobject_class),
1326                   G_SIGNAL_RUN_LAST,
1327                   G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1328                   NULL, NULL,
1329                   _gtk_marshal_VOID__OBJECT,
1330                   G_TYPE_NONE, 1,
1331                   GDK_TYPE_SCREEN);
1332 /**
1333  * GtkWidget::can-activate-accel:
1334  * @widget: the object which received the signal
1335  * @signal_id: the ID of a signal installed on @widget
1336  * @returns: %TRUE if the signal can be activated.
1337  *
1338  * Determines whether an accelerator that activates the signal
1339  * identified by @signal_id can currently be activated.
1340  * This signal is present to allow applications and derived
1341  * widgets to override the default #GtkWidget handling
1342  * for determining whether an accelerator can be activated.
1343  */
1344   widget_signals[CAN_ACTIVATE_ACCEL] =
1345     g_signal_new ("can_activate_accel",
1346                   G_TYPE_FROM_CLASS (gobject_class),
1347                   G_SIGNAL_RUN_LAST,
1348                   G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1349                   _gtk_boolean_handled_accumulator, NULL,
1350                   _gtk_marshal_BOOLEAN__UINT,
1351                   G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1352
1353   binding_set = gtk_binding_set_by_class (klass);
1354   gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1355                                 "popup_menu", 0);
1356   gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1357                                 "popup_menu", 0);  
1358
1359   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1360                                 "show_help", 1,
1361                                 GTK_TYPE_WIDGET_HELP_TYPE,
1362                                 GTK_WIDGET_HELP_TOOLTIP);
1363   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1364                                 "show_help", 1,
1365                                 GTK_TYPE_WIDGET_HELP_TYPE,
1366                                 GTK_WIDGET_HELP_TOOLTIP);
1367   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1368                                 "show_help", 1,
1369                                 GTK_TYPE_WIDGET_HELP_TYPE,
1370                                 GTK_WIDGET_HELP_WHATS_THIS);  
1371   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1372                                 "show_help", 1,
1373                                 GTK_TYPE_WIDGET_HELP_TYPE,
1374                                 GTK_WIDGET_HELP_WHATS_THIS);
1375
1376   gtk_widget_class_install_style_property (klass,
1377                                            g_param_spec_boolean ("interior_focus",
1378                                                                  P_("Interior Focus"),
1379                                                                  P_("Whether to draw the focus indicator inside widgets"),
1380                                                                  TRUE,
1381                                                                  G_PARAM_READABLE));
1382
1383   gtk_widget_class_install_style_property (klass,
1384                                            g_param_spec_int ("focus-line-width",
1385                                                              P_("Focus linewidth"),
1386                                                              P_("Width, in pixels, of the focus indicator line"),
1387                                                              0, G_MAXINT, 1,
1388                                                              G_PARAM_READABLE));
1389
1390   gtk_widget_class_install_style_property (klass,
1391                                            g_param_spec_string ("focus-line-pattern",
1392                                                                 P_("Focus line dash pattern"),
1393                                                                 P_("Dash pattern used to draw the focus indicator"),
1394                                                                 "\1\1",
1395                                                                 G_PARAM_READABLE));
1396   gtk_widget_class_install_style_property (klass,
1397                                            g_param_spec_int ("focus-padding",
1398                                                              P_("Focus padding"),
1399                                                              P_("Width, in pixels, between focus indicator and the widget 'box'"),
1400                                                              0, G_MAXINT, 1,
1401                                                              G_PARAM_READABLE));
1402   gtk_widget_class_install_style_property (klass,
1403                                            g_param_spec_boxed ("cursor-color",
1404                                                                P_("Cursor color"),
1405                                                                P_("Color with which to draw insertion cursor"),
1406                                                                GDK_TYPE_COLOR,
1407                                                                G_PARAM_READABLE));
1408   gtk_widget_class_install_style_property (klass,
1409                                            g_param_spec_boxed ("secondary-cursor-color",
1410                                                                P_("Secondary cursor color"),
1411                                                                P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1412                                                                GDK_TYPE_COLOR,
1413                                                                G_PARAM_READABLE));
1414   gtk_widget_class_install_style_property (klass,
1415                                            g_param_spec_float ("cursor-aspect-ratio",
1416                                                                P_("Cursor line aspect ratio"),
1417                                                                P_("Aspect ratio with which to draw insertion cursor"),
1418                                                                0.0, 1.0, 0.04,
1419                                                                G_PARAM_READABLE));
1420 }
1421
1422 static void
1423 gtk_widget_set_property (GObject         *object,
1424                          guint            prop_id,
1425                          const GValue    *value,
1426                          GParamSpec      *pspec)
1427 {
1428   GtkWidget *widget = GTK_WIDGET (object);
1429
1430   switch (prop_id)
1431     {
1432       guint32 saved_flags;
1433       
1434     case PROP_NAME:
1435       gtk_widget_set_name (widget, g_value_get_string (value));
1436       break;
1437     case PROP_PARENT:
1438       gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1439       break;
1440     case PROP_WIDTH_REQUEST:
1441       gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1442       break;
1443     case PROP_HEIGHT_REQUEST:
1444       gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1445       break;
1446     case PROP_VISIBLE:
1447       if (g_value_get_boolean (value))
1448         gtk_widget_show (widget);
1449       else
1450         gtk_widget_hide (widget);
1451       break;
1452     case PROP_SENSITIVE:
1453       gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1454       break;
1455     case PROP_APP_PAINTABLE:
1456       gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1457       break;
1458     case PROP_CAN_FOCUS:
1459       saved_flags = GTK_WIDGET_FLAGS (widget);
1460       if (g_value_get_boolean (value))
1461         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1462       else
1463         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1464       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1465         gtk_widget_queue_resize (widget);
1466       break;
1467     case PROP_HAS_FOCUS:
1468       if (g_value_get_boolean (value))
1469         gtk_widget_grab_focus (widget);
1470       break;
1471     case PROP_IS_FOCUS:
1472       if (g_value_get_boolean (value))
1473         gtk_widget_grab_focus (widget);
1474       break;
1475     case PROP_CAN_DEFAULT:
1476       saved_flags = GTK_WIDGET_FLAGS (widget);
1477       if (g_value_get_boolean (value))
1478         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1479       else
1480         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1481       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1482         gtk_widget_queue_resize (widget);
1483       break;
1484     case PROP_HAS_DEFAULT:
1485       if (g_value_get_boolean (value))
1486         gtk_widget_grab_default (widget);
1487       break;
1488     case PROP_RECEIVES_DEFAULT:
1489       if (g_value_get_boolean (value))
1490         GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1491       else
1492         GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1493       break;
1494     case PROP_STYLE:
1495       gtk_widget_set_style (widget, g_value_get_object (value));
1496       break;
1497     case PROP_EVENTS:
1498       if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1499         gtk_widget_set_events (widget, g_value_get_flags (value));
1500       break;
1501     case PROP_EXTENSION_EVENTS:
1502       gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1503       break;
1504     case PROP_NO_SHOW_ALL:
1505       gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1506       break;
1507     default:
1508       break;
1509     }
1510 }
1511
1512 static void
1513 gtk_widget_get_property (GObject         *object,
1514                          guint            prop_id,
1515                          GValue          *value,
1516                          GParamSpec      *pspec)
1517 {
1518   GtkWidget *widget = GTK_WIDGET (object);
1519   
1520   switch (prop_id)
1521     {
1522       gint *eventp;
1523       GdkExtensionMode *modep;
1524
1525     case PROP_NAME:
1526       if (widget->name)
1527         g_value_set_string (value, widget->name);
1528       else
1529         g_value_set_string (value, "");
1530       break;
1531     case PROP_PARENT:
1532       if (widget->parent)
1533         g_value_set_object (value, widget->parent);
1534       else
1535         g_value_set_object (value, NULL);
1536       break;
1537     case PROP_WIDTH_REQUEST:
1538       {
1539         int w;
1540         gtk_widget_get_size_request (widget, &w, NULL);
1541         g_value_set_int (value, w);
1542       }
1543       break;
1544     case PROP_HEIGHT_REQUEST:
1545       {
1546         int h;
1547         gtk_widget_get_size_request (widget, NULL, &h);
1548         g_value_set_int (value, h);
1549       }
1550       break;
1551     case PROP_VISIBLE:
1552       g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1553       break;
1554     case PROP_SENSITIVE:
1555       g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1556       break;
1557     case PROP_APP_PAINTABLE:
1558       g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1559       break;
1560     case PROP_CAN_FOCUS:
1561       g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1562       break;
1563     case PROP_HAS_FOCUS:
1564       g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1565       break;
1566     case PROP_IS_FOCUS:
1567       g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1568       break;
1569     case PROP_CAN_DEFAULT:
1570       g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1571       break;
1572     case PROP_HAS_DEFAULT:
1573       g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1574       break;
1575     case PROP_RECEIVES_DEFAULT:
1576       g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1577       break;
1578     case PROP_COMPOSITE_CHILD:
1579       g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1580       break;
1581     case PROP_STYLE:
1582       g_value_set_object (value, gtk_widget_get_style (widget));
1583       break;
1584     case PROP_EVENTS:
1585       eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1586       if (!eventp)
1587         g_value_set_flags (value, 0);
1588       else
1589         g_value_set_flags (value, *eventp);
1590       break;
1591     case PROP_EXTENSION_EVENTS:
1592       modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1593       if (!modep)
1594         g_value_set_enum (value, 0);
1595       else
1596         g_value_set_enum (value, (GdkExtensionMode) *modep);
1597       break;
1598     case PROP_NO_SHOW_ALL:
1599       g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1600       break;
1601     default:
1602       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1603       break;
1604     }
1605 }
1606
1607 static void
1608 gtk_widget_init (GtkWidget *widget)
1609 {
1610   GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1611   widget->state = GTK_STATE_NORMAL;
1612   widget->saved_state = GTK_STATE_NORMAL;
1613   widget->name = NULL;
1614   widget->requisition.width = 0;
1615   widget->requisition.height = 0;
1616   widget->allocation.x = -1;
1617   widget->allocation.y = -1;
1618   widget->allocation.width = 1;
1619   widget->allocation.height = 1;
1620   widget->window = NULL;
1621   widget->parent = NULL;
1622
1623   GTK_WIDGET_SET_FLAGS (widget,
1624                         GTK_SENSITIVE |
1625                         GTK_PARENT_SENSITIVE |
1626                         (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1627                         GTK_DOUBLE_BUFFERED);
1628
1629   GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1630   GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1631   GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1632
1633   widget->style = gtk_widget_get_default_style ();
1634   g_object_ref (widget->style);
1635 }
1636
1637
1638 static void
1639 gtk_widget_dispatch_child_properties_changed (GtkWidget   *widget,
1640                                               guint        n_pspecs,
1641                                               GParamSpec **pspecs)
1642 {
1643   GtkWidget *container = widget->parent;
1644   guint i;
1645
1646   for (i = 0; widget->parent == container && i < n_pspecs; i++)
1647     g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1648 }
1649
1650 /**
1651  * gtk_widget_freeze_child_notify:
1652  * @widget: a #GtkWidget
1653  * 
1654  * Stops emission of "child-notify" signals on @widget. The signals are
1655  * queued until gtk_widget_thaw_child_notify() is called on @widget. 
1656  *
1657  * This is the analogue of g_object_freeze_notify() for child properties.
1658  **/
1659 void
1660 gtk_widget_freeze_child_notify (GtkWidget *widget)
1661 {
1662   g_return_if_fail (GTK_IS_WIDGET (widget));
1663
1664   if (!G_OBJECT (widget)->ref_count)
1665     return;
1666
1667   g_object_ref (widget);
1668   g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1669   g_object_unref (widget);
1670 }
1671
1672 /**
1673  * gtk_widget_child_notify:
1674  * @widget: a #GtkWidget
1675  * @child_property: the name of a child property installed on the 
1676  *                  class of @widget<!-- -->'s parent.
1677  * 
1678  * Emits a "child-notify" signal for the 
1679  * <link linkend="child-properties">child property</link> @child_property 
1680  * on @widget.
1681  *
1682  * This is the analogue of g_object_notify() for child properties.
1683  **/
1684 void
1685 gtk_widget_child_notify (GtkWidget    *widget,
1686                          const gchar  *child_property)
1687 {
1688   GParamSpec *pspec;
1689
1690   g_return_if_fail (GTK_IS_WIDGET (widget));
1691   g_return_if_fail (child_property != NULL);
1692   if (!G_OBJECT (widget)->ref_count || !widget->parent)
1693     return;
1694
1695   g_object_ref (widget);
1696   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1697                                     child_property,
1698                                     G_OBJECT_TYPE (widget->parent),
1699                                     TRUE);
1700   if (!pspec)
1701     g_warning ("%s: container class `%s' has no child property named `%s'",
1702                G_STRLOC,
1703                G_OBJECT_TYPE_NAME (widget->parent),
1704                child_property);
1705   else
1706     {
1707       GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1708
1709       g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1710       g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1711     }
1712   g_object_unref (widget);
1713 }
1714
1715 /**
1716  * gtk_widget_thaw_child_notify:
1717  * @widget: a #GtkWidget
1718  *
1719  * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1720  * This causes all queued "child-notify" signals on @widget to be emitted.
1721  */ 
1722 void
1723 gtk_widget_thaw_child_notify (GtkWidget *widget)
1724 {
1725   GObjectNotifyQueue *nqueue;
1726
1727   g_return_if_fail (GTK_IS_WIDGET (widget));
1728
1729   if (!G_OBJECT (widget)->ref_count)
1730     return;
1731
1732   g_object_ref (widget);
1733   nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1734   if (!nqueue || !nqueue->freeze_count)
1735     g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1736                G_OBJECT_TYPE_NAME (widget), widget);
1737   else
1738     g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1739   g_object_unref (widget);
1740 }
1741
1742
1743 /**
1744  * gtk_widget_new:
1745  * @type: type ID of the widget to create
1746  * @first_property_name: name of first property to set
1747  * @Varargs: value of first property, followed by more properties, %NULL-terminated
1748  * 
1749  * This is a convenience function for creating a widget and setting
1750  * its properties in one go. For example you might write:
1751  * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1752  * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1753  * g_object_new(), but returns a widget so you don't have to
1754  * cast the object yourself.
1755  * 
1756  * Return value: a new #GtkWidget of type @widget_type
1757  **/
1758 GtkWidget*
1759 gtk_widget_new (GType        type,
1760                 const gchar *first_property_name,
1761                 ...)
1762 {
1763   GtkWidget *widget;
1764   va_list var_args;
1765   
1766   g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1767   
1768   va_start (var_args, first_property_name);
1769   widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1770   va_end (var_args);
1771
1772   return widget;
1773 }
1774
1775 /**
1776  * gtk_widget_set:
1777  * @widget: a #GtkWidget
1778  * @first_property_name: name of first property to set
1779  * @Varargs: value of first property, followed by more properties, %NULL-terminated
1780  * 
1781  * Like g_object_set() - there's no reason to use this instead of
1782  * g_object_set().
1783  **/
1784 void
1785 gtk_widget_set (GtkWidget   *widget,
1786                 const gchar *first_property_name,
1787                 ...)
1788 {
1789   va_list var_args;
1790
1791   g_return_if_fail (GTK_IS_WIDGET (widget));
1792
1793   va_start (var_args, first_property_name);
1794   g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1795   va_end (var_args);
1796 }
1797
1798 static inline void         
1799 gtk_widget_queue_draw_child (GtkWidget *widget)
1800 {
1801   GtkWidget *parent;
1802
1803   parent = widget->parent;
1804   if (parent && GTK_WIDGET_DRAWABLE (parent))
1805     gtk_widget_queue_draw_area (parent,
1806                                 widget->allocation.x,
1807                                 widget->allocation.y,
1808                                 widget->allocation.width,
1809                                 widget->allocation.height);
1810 }
1811
1812 /**
1813  * gtk_widget_unparent:
1814  * @widget: a #GtkWidget
1815  * 
1816  * This function is only for use in widget implementations.
1817  * Should be called by implementations of the remove method
1818  * on #GtkContainer, to dissociate a child from the container.
1819  **/
1820 void
1821 gtk_widget_unparent (GtkWidget *widget)
1822 {
1823   GObjectNotifyQueue *nqueue;
1824   GtkWidget *toplevel;
1825   GtkWidget *old_parent;
1826   
1827   g_return_if_fail (GTK_IS_WIDGET (widget));
1828   if (widget->parent == NULL)
1829     return;
1830   
1831   /* keep this function in sync with gtk_menu_detach()
1832    */
1833
1834   g_object_freeze_notify (G_OBJECT (widget));
1835   nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1836
1837   toplevel = gtk_widget_get_toplevel (widget);
1838   if (GTK_WIDGET_TOPLEVEL (toplevel))
1839     _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1840
1841   if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1842     gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1843
1844   /* If we are unanchoring the child, we save around the toplevel
1845    * to emit hierarchy changed
1846    */
1847   if (GTK_WIDGET_ANCHORED (widget->parent))
1848     g_object_ref (toplevel);
1849   else
1850     toplevel = NULL;
1851
1852   gtk_widget_queue_draw_child (widget);
1853
1854   /* Reset the width and height here, to force reallocation if we
1855    * get added back to a new parent. This won't work if our new
1856    * allocation is smaller than 1x1 and we actually want a size of 1x1...
1857    * (would 0x0 be OK here?)
1858    */
1859   widget->allocation.width = 1;
1860   widget->allocation.height = 1;
1861   
1862   if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1863     gtk_widget_unrealize (widget);
1864
1865   /* Removing a widget from a container restores the child visible
1866    * flag to the default state, so it doesn't affect the child
1867    * in the next parent.
1868    */
1869   GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1870     
1871   old_parent = widget->parent;
1872   widget->parent = NULL;
1873   gtk_widget_set_parent_window (widget, NULL);
1874   g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1875   if (toplevel)
1876     {
1877       _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1878       g_object_unref (toplevel);
1879     }
1880       
1881   g_object_notify (G_OBJECT (widget), "parent");
1882   g_object_thaw_notify (G_OBJECT (widget));
1883   if (!widget->parent)
1884     g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1885   g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1886   g_object_unref (widget);
1887 }
1888
1889 /**
1890  * gtk_widget_destroy:
1891  * @widget: a #GtkWidget
1892  *
1893  * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1894  * you don't have to cast the widget to #GtkObject. When a widget is
1895  * destroyed, it will break any references it holds to other objects.
1896  * If the widget is inside a container, the widget will be removed
1897  * from the container. If the widget is a toplevel (derived from
1898  * #GtkWindow), it will be removed from the list of toplevels, and the
1899  * reference GTK+ holds to it will be removed. Removing a
1900  * widget from its container or the list of toplevels results in the
1901  * widget being finalized, unless you've added additional references
1902  * to the widget with g_object_ref().
1903  *
1904  * In most cases, only toplevel widgets (windows) require explicit
1905  * destruction, because when you destroy a toplevel its children will
1906  * be destroyed as well.
1907  * 
1908  **/
1909 void
1910 gtk_widget_destroy (GtkWidget *widget)
1911 {
1912   g_return_if_fail (GTK_IS_WIDGET (widget));
1913
1914   gtk_object_destroy ((GtkObject*) widget);
1915 }
1916
1917 /**
1918  * gtk_widget_destroyed:
1919  * @widget: a #GtkWidget
1920  * @widget_pointer: address of a variable that contains @widget
1921  *
1922  * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1923  * %NULL.  It's intended to be used as a callback connected to the
1924  * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1925  * as a signal handler, and pass the address of your widget variable
1926  * as user data. Then when the widget is destroyed, the variable will
1927  * be set to %NULL. Useful for example to avoid multiple copies
1928  * of the same dialog.
1929  * 
1930  **/
1931 void
1932 gtk_widget_destroyed (GtkWidget      *widget,
1933                       GtkWidget      **widget_pointer)
1934 {
1935   /* Don't make any assumptions about the
1936    *  value of widget!
1937    *  Even check widget_pointer.
1938    */
1939   if (widget_pointer)
1940     *widget_pointer = NULL;
1941 }
1942
1943 /**
1944  * gtk_widget_show:
1945  * @widget: a #GtkWidget
1946  * 
1947  * Flags a widget to be displayed. Any widget that isn't shown will
1948  * not appear on the screen. If you want to show all the widgets in a
1949  * container, it's easier to call gtk_widget_show_all() on the
1950  * container, instead of individually showing the widgets.
1951  *
1952  * Remember that you have to show the containers containing a widget,
1953  * in addition to the widget itself, before it will appear onscreen.
1954  *
1955  * When a toplevel container is shown, it is immediately realized and
1956  * mapped; other shown widgets are realized and mapped when their
1957  * toplevel container is realized and mapped.
1958  * 
1959  **/
1960 void
1961 gtk_widget_show (GtkWidget *widget)
1962 {
1963   if (!GTK_WIDGET_VISIBLE (widget))
1964     {
1965       g_object_ref (widget);
1966       if (!GTK_WIDGET_TOPLEVEL (widget))
1967         gtk_widget_queue_resize (widget);
1968       g_signal_emit (widget, widget_signals[SHOW], 0);
1969       g_object_notify (G_OBJECT (widget), "visible");
1970       g_object_unref (widget);
1971     }
1972 }
1973
1974 static void
1975 gtk_widget_real_show (GtkWidget *widget)
1976 {
1977   if (!GTK_WIDGET_VISIBLE (widget))
1978     {
1979       GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1980
1981       if (widget->parent &&
1982           GTK_WIDGET_MAPPED (widget->parent) &&
1983           GTK_WIDGET_CHILD_VISIBLE (widget) &&
1984           !GTK_WIDGET_MAPPED (widget))
1985         gtk_widget_map (widget);
1986     }
1987 }
1988
1989 static void
1990 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1991 {
1992   *flag = TRUE;
1993   g_signal_handlers_disconnect_by_func (widget,
1994                                         gtk_widget_show_map_callback, 
1995                                         flag);
1996 }
1997
1998 /**
1999  * gtk_widget_show_now:
2000  * @widget: a #GtkWidget
2001  * 
2002  * Shows a widget. If the widget is an unmapped toplevel widget
2003  * (i.e. a #GtkWindow that has not yet been shown), enter the main
2004  * loop and wait for the window to actually be mapped. Be careful;
2005  * because the main loop is running, anything can happen during
2006  * this function.
2007  **/
2008 void
2009 gtk_widget_show_now (GtkWidget *widget)
2010 {
2011   gint flag = FALSE;
2012   
2013   g_return_if_fail (GTK_IS_WIDGET (widget));
2014
2015   /* make sure we will get event */
2016   if (!GTK_WIDGET_MAPPED (widget) &&
2017       GTK_WIDGET_TOPLEVEL (widget))
2018     {
2019       gtk_widget_show (widget);
2020
2021       g_signal_connect (widget, "map_event",
2022                         G_CALLBACK (gtk_widget_show_map_callback), 
2023                         &flag);
2024
2025       while (!flag)
2026         gtk_main_iteration ();
2027     }
2028   else
2029     gtk_widget_show (widget);
2030 }
2031
2032 /**
2033  * gtk_widget_hide:
2034  * @widget: a #GtkWidget
2035  * 
2036  * Reverses the effects of gtk_widget_show(), causing the widget to be
2037  * hidden (invisible to the user).
2038  **/
2039 void
2040 gtk_widget_hide (GtkWidget *widget)
2041 {
2042   g_return_if_fail (GTK_IS_WIDGET (widget));
2043   
2044   if (GTK_WIDGET_VISIBLE (widget))
2045     {
2046       GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2047       
2048       g_object_ref (widget);
2049       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2050         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2051
2052       g_signal_emit (widget, widget_signals[HIDE], 0);
2053       if (!GTK_WIDGET_TOPLEVEL (widget))
2054         gtk_widget_queue_resize (widget);
2055       g_object_notify (G_OBJECT (widget), "visible");
2056       g_object_unref (widget);
2057     }
2058 }
2059
2060 static void
2061 gtk_widget_real_hide (GtkWidget *widget)
2062 {
2063   if (GTK_WIDGET_VISIBLE (widget))
2064     {
2065       GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2066       
2067       if (GTK_WIDGET_MAPPED (widget))
2068         gtk_widget_unmap (widget);
2069     }
2070 }
2071
2072 /**
2073  * gtk_widget_hide_on_delete:
2074  * @widget: a #GtkWidget
2075  * 
2076  * Utility function; intended to be connected to the "delete_event"
2077  * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2078  * argument, then returns %TRUE. If connected to "delete_event", the
2079  * result is that clicking the close button for a window (on the
2080  * window frame, top right corner usually) will hide but not destroy
2081  * the window. By default, GTK+ destroys windows when "delete_event"
2082  * is received.
2083  * 
2084  * Return value: %TRUE
2085  **/
2086 gboolean
2087 gtk_widget_hide_on_delete (GtkWidget      *widget)
2088 {
2089   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2090   
2091   gtk_widget_hide (widget);
2092   
2093   return TRUE;
2094 }
2095
2096 /**
2097  * gtk_widget_show_all:
2098  * @widget: a #GtkWidget
2099  * 
2100  * Recursively shows a widget, and any child widgets (if the widget is
2101  * a container).
2102  **/
2103 void
2104 gtk_widget_show_all (GtkWidget *widget)
2105 {
2106   GtkWidgetClass *class;
2107
2108   g_return_if_fail (GTK_IS_WIDGET (widget));
2109
2110   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2111     return;
2112
2113   class = GTK_WIDGET_GET_CLASS (widget);
2114
2115   if (class->show_all)
2116     class->show_all (widget);
2117 }
2118
2119 /**
2120  * gtk_widget_hide_all:
2121  * @widget: a #GtkWidget
2122  * 
2123  * Recursively hides a widget and any child widgets.
2124  **/
2125 void
2126 gtk_widget_hide_all (GtkWidget *widget)
2127 {
2128   GtkWidgetClass *class;
2129
2130   g_return_if_fail (GTK_IS_WIDGET (widget));
2131
2132   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2133     return;
2134
2135   class = GTK_WIDGET_GET_CLASS (widget);
2136
2137   if (class->hide_all)
2138     class->hide_all (widget);
2139 }
2140
2141 /**
2142  * gtk_widget_map:
2143  * @widget: a #GtkWidget
2144  * 
2145  * This function is only for use in widget implementations. Causes
2146  * a widget to be mapped if it isn't already.
2147  * 
2148  **/
2149 void
2150 gtk_widget_map (GtkWidget *widget)
2151 {
2152   g_return_if_fail (GTK_IS_WIDGET (widget));
2153   g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2154   g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2155   
2156   if (!GTK_WIDGET_MAPPED (widget))
2157     {
2158       if (!GTK_WIDGET_REALIZED (widget))
2159         gtk_widget_realize (widget);
2160
2161       g_signal_emit (widget, widget_signals[MAP], 0);
2162
2163       if (GTK_WIDGET_NO_WINDOW (widget))
2164         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2165     }
2166 }
2167
2168 /**
2169  * gtk_widget_unmap:
2170  * @widget: a #GtkWidget
2171  *
2172  * This function is only for use in widget implementations. Causes
2173  * a widget to be unmapped if it's currently mapped.
2174  * 
2175  **/
2176 void
2177 gtk_widget_unmap (GtkWidget *widget)
2178 {
2179   g_return_if_fail (GTK_IS_WIDGET (widget));
2180   
2181   if (GTK_WIDGET_MAPPED (widget))
2182     {
2183       if (GTK_WIDGET_NO_WINDOW (widget))
2184         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2185       g_signal_emit (widget, widget_signals[UNMAP], 0);
2186     }
2187 }
2188
2189 /**
2190  * gtk_widget_realize:
2191  * @widget: a #GtkWidget
2192  * 
2193  * Creates the GDK (windowing system) resources associated with a
2194  * widget.  For example, @widget->window will be created when a widget
2195  * is realized.  Normally realization happens implicitly; if you show
2196  * a widget and all its parent containers, then the widget will be
2197  * realized and mapped automatically.
2198  * 
2199  * Realizing a widget requires all
2200  * the widget's parent widgets to be realized; calling
2201  * gtk_widget_realize() realizes the widget's parents in addition to
2202  * @widget itself. If a widget is not yet inside a toplevel window
2203  * when you realize it, bad things will happen.
2204  *
2205  * This function is primarily used in widget implementations, and
2206  * isn't very useful otherwise. Many times when you think you might
2207  * need it, a better approach is to connect to a signal that will be
2208  * called after the widget is realized automatically, such as
2209  * "expose_event". Or simply g_signal_connect_after() to the
2210  * "realize" signal.
2211  *  
2212  **/
2213 void
2214 gtk_widget_realize (GtkWidget *widget)
2215 {
2216   gint events;
2217   GdkExtensionMode mode;
2218   GtkWidgetShapeInfo *shape_info;
2219   
2220   g_return_if_fail (GTK_IS_WIDGET (widget));
2221   g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2222                     GTK_IS_INVISIBLE (widget));
2223   
2224   if (!GTK_WIDGET_REALIZED (widget))
2225     {
2226       /*
2227         if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2228           g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2229       */
2230
2231       if (widget->parent == NULL &&
2232           !GTK_WIDGET_TOPLEVEL (widget))
2233         g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2234                    "inside a toplevel window is not going to work very well. "
2235                    "Widgets must be inside a toplevel container before realizing them.");
2236       
2237       if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2238         gtk_widget_realize (widget->parent);
2239
2240       gtk_widget_ensure_style (widget);
2241       
2242       g_signal_emit (widget, widget_signals[REALIZE], 0);
2243       
2244       if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2245         {
2246           shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2247           gdk_window_shape_combine_mask (widget->window,
2248                                          shape_info->shape_mask,
2249                                          shape_info->offset_x,
2250                                          shape_info->offset_y);
2251         }
2252       
2253       if (!GTK_WIDGET_NO_WINDOW (widget))
2254         {
2255           mode = gtk_widget_get_extension_events (widget);
2256           if (mode != GDK_EXTENSION_EVENTS_NONE)
2257             {
2258               events = gtk_widget_get_events (widget);
2259               gdk_input_set_extension_events (widget->window, events, mode);
2260             }
2261         }
2262       
2263     }
2264 }
2265
2266 /**
2267  * gtk_widget_unrealize:
2268  * @widget: a #GtkWidget
2269  *
2270  * This function is only useful in widget implementations.
2271  * Causes a widget to be unrealized (frees all GDK resources
2272  * associated with the widget, such as @widget->window).
2273  * 
2274  **/
2275 void
2276 gtk_widget_unrealize (GtkWidget *widget)
2277 {
2278   g_return_if_fail (GTK_IS_WIDGET (widget));
2279
2280   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2281     gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2282
2283   if (GTK_WIDGET_REALIZED (widget))
2284     {
2285       g_object_ref (widget);
2286       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2287       GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2288       g_object_unref (widget);
2289     }
2290 }
2291
2292 /*****************************************
2293  * Draw queueing.
2294  *****************************************/
2295
2296 /**
2297  * gtk_widget_queue_draw_area:
2298  * @widget: a #GtkWidget
2299  * @x: x coordinate of upper-left corner of rectangle to redraw
2300  * @y: y coordinate of upper-left corner of rectangle to redraw
2301  * @width: width of region to draw
2302  * @height: height of region to draw
2303  *
2304  * Invalidates the rectangular area of @widget defined by @x, @y,
2305  * @width and @height by calling gdk_window_invalidate_rect() on the
2306  * widget's window and all its child windows.  Once the main loop
2307  * becomes idle (after the current batch of events has been processed,
2308  * roughly), the window will receive expose events for the union of
2309  * all regions that have been invalidated.
2310  *
2311  * Normally you would only use this function in widget
2312  * implementations. You might also use it, or
2313  * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2314  * #GtkDrawingArea or some portion thereof.
2315  *
2316  * Frequently you can just call gdk_window_invalidate_rect() or
2317  * gdk_window_invalidate_region() instead of this function. Those
2318  * functions will invalidate only a single window, instead of the
2319  * widget and all its children.
2320  *
2321  * The advantage of adding to the invalidated region compared to
2322  * simply drawing immediately is efficiency; using an invalid region
2323  * ensures that you only have to redraw one time.
2324  * 
2325  **/
2326 void       
2327 gtk_widget_queue_draw_area (GtkWidget *widget,
2328                             gint       x,
2329                             gint       y,
2330                             gint       width,
2331                             gint       height)
2332 {
2333   GdkRectangle invalid_rect;
2334   GtkWidget *w;
2335   
2336   g_return_if_fail (GTK_IS_WIDGET (widget));
2337
2338   if (!GTK_WIDGET_REALIZED (widget))
2339     return;
2340   
2341   /* Just return if the widget or one of its ancestors isn't mapped */
2342   for (w = widget; w != NULL; w = w->parent)
2343     if (!GTK_WIDGET_MAPPED (w))
2344       return;
2345
2346   /* Find the correct widget */
2347
2348   if (!GTK_WIDGET_NO_WINDOW (widget))
2349     {
2350       if (widget->parent)
2351         {
2352           /* Translate widget relative to window-relative */
2353
2354           gint wx, wy, wwidth, wheight;
2355           
2356           gdk_window_get_position (widget->window, &wx, &wy);
2357           x -= wx - widget->allocation.x;
2358           y -= wy - widget->allocation.y;
2359           
2360           gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2361
2362           if (x + width <= 0 || y + height <= 0 ||
2363               x >= wwidth || y >= wheight)
2364             return;
2365           
2366           if (x < 0)
2367             {
2368               width += x;  x = 0;
2369             }
2370           if (y < 0)
2371             {
2372               height += y; y = 0;
2373             }
2374           if (x + width > wwidth)
2375             width = wwidth - x;
2376           if (y + height > wheight)
2377             height = wheight - y;
2378         }
2379     }
2380
2381   invalid_rect.x = x;
2382   invalid_rect.y = y;
2383   invalid_rect.width = width;
2384   invalid_rect.height = height;
2385   
2386   gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2387 }
2388
2389 /**
2390  * gtk_widget_queue_draw:
2391  * @widget: a #GtkWidget
2392  *
2393  * Equivalent to calling gtk_widget_queue_draw_area() for the
2394  * entire area of a widget.
2395  * 
2396  **/
2397 void       
2398 gtk_widget_queue_draw (GtkWidget *widget)
2399 {
2400   g_return_if_fail (GTK_IS_WIDGET (widget));
2401
2402   if (widget->allocation.width || widget->allocation.height)
2403     {
2404       if (GTK_WIDGET_NO_WINDOW (widget))
2405         gtk_widget_queue_draw_area (widget, widget->allocation.x,
2406                                     widget->allocation.y,
2407                                     widget->allocation.width, 
2408                                     widget->allocation.height);
2409       else
2410         gtk_widget_queue_draw_area (widget, 0, 0, 
2411                                     widget->allocation.width, 
2412                                     widget->allocation.height);
2413     }
2414 }
2415
2416 /* Invalidates the given area (allocation-relative-coordinates)
2417  * in all of the widget's windows
2418  */
2419 /**
2420  * gtk_widget_queue_clear_area:
2421  * @widget: a #GtkWidget
2422  * @x: x coordinate of upper-left corner of rectangle to redraw
2423  * @y: y coordinate of upper-left corner of rectangle to redraw
2424  * @width: width of region to draw
2425  * @height: height of region to draw
2426  * 
2427  * This function is no longer different from
2428  * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2429  * gtk_widget_queue_draw_area(). Originally
2430  * gtk_widget_queue_clear_area() would force a redraw of the
2431  * background for %GTK_NO_WINDOW widgets, and
2432  * gtk_widget_queue_draw_area() would not. Now both functions ensure
2433  * the background will be redrawn.
2434  * 
2435  * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2436  **/
2437 void       
2438 gtk_widget_queue_clear_area (GtkWidget *widget,
2439                              gint       x,
2440                              gint       y,
2441                              gint       width,
2442                              gint       height)
2443 {
2444   g_return_if_fail (GTK_IS_WIDGET (widget));
2445
2446   gtk_widget_queue_draw_area (widget, x, y, width, height);
2447 }
2448
2449 /**
2450  * gtk_widget_queue_clear:
2451  * @widget: a #GtkWidget
2452  * 
2453  * This function does the same as gtk_widget_queue_draw().
2454  *
2455  * @Deprecated: Use gtk_widget_queue_draw() instead.
2456  **/
2457 void       
2458 gtk_widget_queue_clear (GtkWidget *widget)
2459 {
2460   g_return_if_fail (GTK_IS_WIDGET (widget));
2461
2462   gtk_widget_queue_draw (widget);
2463 }
2464
2465 /**
2466  * gtk_widget_queue_resize:
2467  * @widget: a #GtkWidget
2468  *
2469  * This function is only for use in widget implementations.
2470  * Flags a widget to have its size renegotiated; should
2471  * be called when a widget for some reason has a new size request.
2472  * For example, when you change the text in a #GtkLabel, #GtkLabel
2473  * queues a resize to ensure there's enough space for the new text.
2474  **/
2475 void
2476 gtk_widget_queue_resize (GtkWidget *widget)
2477 {
2478   g_return_if_fail (GTK_IS_WIDGET (widget));
2479
2480   if (GTK_WIDGET_REALIZED (widget))
2481     gtk_widget_queue_shallow_draw (widget);
2482       
2483   _gtk_size_group_queue_resize (widget);
2484 }
2485
2486 /**
2487  * gtk_widget_queue_resize_no_redraw:
2488  * @widget: a #GtkWidget
2489  *
2490  * This function works like gtk_widget_queue_resize(), except that the
2491  * widget is not invalidated.
2492  *
2493  * Since: 2.4
2494  **/
2495 void
2496 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2497 {
2498   g_return_if_fail (GTK_IS_WIDGET (widget));
2499
2500   _gtk_size_group_queue_resize (widget);
2501 }
2502
2503 /**
2504  * gtk_widget_draw:
2505  * @widget: a #GtkWidget
2506  * @area: area to draw
2507  *
2508  * In GTK+ 1.2, this function would immediately render the
2509  * region @area of a widget, by invoking the virtual draw method of a
2510  * widget. In GTK+ 2.0, the draw method is gone, and instead
2511  * gtk_widget_draw() simply invalidates the specified region of the
2512  * widget, then updates the invalid region of the widget immediately.
2513  * Usually you don't want to update the region immediately for
2514  * performance reasons, so in general gtk_widget_queue_draw_area() is
2515  * a better choice if you want to draw a region of a widget.
2516  * 
2517  **/
2518 void
2519 gtk_widget_draw (GtkWidget    *widget,
2520                  GdkRectangle *area)
2521 {
2522   g_return_if_fail (GTK_IS_WIDGET (widget));
2523
2524   if (GTK_WIDGET_DRAWABLE (widget))
2525     {
2526       if (area)
2527         gtk_widget_queue_draw_area (widget,
2528                                     area->x, area->y,
2529                                     area->width, area->height);
2530       else
2531         gtk_widget_queue_draw (widget);
2532
2533       gdk_window_process_updates (widget->window, TRUE);
2534     }
2535 }
2536
2537 /**
2538  * gtk_widget_size_request:
2539  * @widget: a #GtkWidget
2540  * @requisition: a #GtkRequisition to be filled in
2541  * 
2542  * This function is typically used when implementing a #GtkContainer
2543  * subclass.  Obtains the preferred size of a widget. The container
2544  * uses this information to arrange its child widgets and decide what
2545  * size allocations to give them with gtk_widget_size_allocate().
2546  *
2547  * You can also call this function from an application, with some
2548  * caveats. Most notably, getting a size request requires the widget
2549  * to be associated with a screen, because font information may be
2550  * needed. Multihead-aware applications should keep this in mind.
2551  *
2552  * Also remember that the size request is not necessarily the size
2553  * a widget will actually be allocated.
2554  *
2555  * See also gtk_widget_get_child_requisition().
2556  **/
2557 void
2558 gtk_widget_size_request (GtkWidget      *widget,
2559                          GtkRequisition *requisition)
2560 {
2561   g_return_if_fail (GTK_IS_WIDGET (widget));
2562
2563 #ifdef G_ENABLE_DEBUG
2564   if (requisition == &widget->requisition)
2565     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.");
2566 #endif /* G_ENABLE_DEBUG */
2567
2568   _gtk_size_group_compute_requisition (widget, requisition);
2569 }
2570
2571 /**
2572  * gtk_widget_get_child_requisition:
2573  * @widget: a #GtkWidget
2574  * @requisition: a #GtkRequisition to be filled in
2575  * 
2576  * This function is only for use in widget implementations. Obtains
2577  * @widget->requisition, unless someone has forced a particular
2578  * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2579  * case it returns that geometry instead of the widget's requisition.
2580  *
2581  * This function differs from gtk_widget_size_request() in that
2582  * it retrieves the last size request value from @widget->requisition,
2583  * while gtk_widget_size_request() actually calls the "size_request" method
2584  * on @widget to compute the size request and fill in @widget->requisition,
2585  * and only then returns @widget->requisition.
2586  *
2587  * Because this function does not call the "size_request" method, it
2588  * can only be used when you know that @widget->requisition is
2589  * up-to-date, that is, gtk_widget_size_request() has been called
2590  * since the last time a resize was queued. In general, only container
2591  * implementations have this information; applications should use
2592  * gtk_widget_size_request().
2593  **/
2594 void
2595 gtk_widget_get_child_requisition (GtkWidget      *widget,
2596                                   GtkRequisition *requisition)
2597 {
2598   _gtk_size_group_get_child_requisition (widget, requisition);
2599 }
2600
2601 static gboolean
2602 invalidate_predicate (GdkWindow *window,
2603                       gpointer   data)
2604 {
2605   gpointer user_data;
2606
2607   gdk_window_get_user_data (window, &user_data);
2608
2609   return (user_data == data);
2610 }
2611
2612 /* Invalidate @region in widget->window and all children
2613  * of widget->window owned by widget. @region is in the
2614  * same coordinates as widget->allocation and will be
2615  * modified by this call.
2616  */
2617 static void
2618 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2619                                       GdkRegion *region)
2620 {
2621   if (!GTK_WIDGET_REALIZED (widget))
2622     return;
2623   
2624   if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2625     {
2626       int x, y;
2627       
2628       gdk_window_get_position (widget->window, &x, &y);
2629       gdk_region_offset (region, -x, -y);
2630     }
2631
2632   gdk_window_invalidate_maybe_recurse (widget->window, region,
2633                                        invalidate_predicate, widget);
2634 }
2635
2636 /**
2637  * gtk_widget_queue_shallow_draw:
2638  * @widget: a #GtkWidget
2639  *
2640  * Like gtk_widget_queue_draw(), but only windows owned
2641  * by @widget are invalidated.
2642  **/
2643 static void
2644 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2645 {
2646   GdkRegion *region;
2647   
2648   g_return_if_fail (GTK_IS_WIDGET (widget));
2649   
2650   region = gdk_region_rectangle (&widget->allocation);
2651   gtk_widget_invalidate_widget_windows (widget, region);
2652   gdk_region_destroy (region);
2653 }
2654
2655 /**
2656  * gtk_widget_size_allocate:
2657  * @widget: a #GtkWidget
2658  * @allocation: position and size to be allocated to @widget
2659  *
2660  * This function is only used by #GtkContainer subclasses, to assign a size
2661  * and position to their child widgets. 
2662  * 
2663  **/
2664 void
2665 gtk_widget_size_allocate (GtkWidget     *widget,
2666                           GtkAllocation *allocation)
2667 {
2668   GtkWidgetAuxInfo *aux_info;
2669   GdkRectangle real_allocation;
2670   GdkRectangle old_allocation;
2671   gboolean alloc_needed;
2672   gboolean size_changed;
2673   gboolean position_changed;
2674   
2675   g_return_if_fail (GTK_IS_WIDGET (widget));
2676  
2677 #ifdef G_ENABLE_DEBUG
2678   if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2679     {
2680       gint depth;
2681       GtkWidget *parent;
2682       const gchar *name;
2683
2684       depth = 0;
2685       parent = widget;
2686       while (parent)
2687         {
2688           depth++;
2689           parent = gtk_widget_get_parent (parent);
2690         }
2691       
2692       name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2693       g_print ("gtk_widget_size_allocate: %*s%s %d %d\n", 
2694                2 * depth, " ", name, 
2695                allocation->width, allocation->height);
2696     }
2697 #endif /* G_ENABLE_DEBUG */
2698  
2699   alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2700   if (!GTK_WIDGET_REQUEST_NEEDED (widget))      /* Preserve request/allocate ordering */
2701     GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2702
2703   old_allocation = widget->allocation;
2704   real_allocation = *allocation;
2705   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2706   
2707   if (aux_info)
2708     {
2709       if (aux_info->x_set)
2710         real_allocation.x = aux_info->x;
2711       if (aux_info->y_set)
2712         real_allocation.y = aux_info->y;
2713     }
2714
2715   if (real_allocation.width < 0 || real_allocation.height < 0)
2716     {
2717       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2718                  real_allocation.width,
2719                  real_allocation.height);
2720     }
2721   
2722   real_allocation.width = MAX (real_allocation.width, 1);
2723   real_allocation.height = MAX (real_allocation.height, 1);
2724
2725   size_changed = (old_allocation.width != real_allocation.width ||
2726                   old_allocation.height != real_allocation.height);
2727   position_changed = (old_allocation.x != real_allocation.x ||
2728                       old_allocation.y != real_allocation.y);
2729
2730   if (!alloc_needed && !size_changed && !position_changed)
2731     return;
2732   
2733   g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2734
2735   if (GTK_WIDGET_MAPPED (widget))
2736     {
2737       if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2738         {
2739           /* Invalidate union(old_allaction,widget->allocation) in widget->window
2740            */
2741           GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2742           gdk_region_union_with_rect (invalidate, &old_allocation);
2743
2744           gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2745           gdk_region_destroy (invalidate);
2746         }
2747       
2748       if (size_changed)
2749         {
2750           if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2751             {
2752               /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2753                */
2754               GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2755               gdk_region_union_with_rect (invalidate, &old_allocation);
2756
2757               gtk_widget_invalidate_widget_windows (widget, invalidate);
2758               gdk_region_destroy (invalidate);
2759             }
2760         }
2761     }
2762
2763   if ((size_changed || position_changed) && widget->parent &&
2764       GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2765     {
2766       GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2767       gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2768       gdk_region_destroy (invalidate);
2769     }
2770 }
2771
2772 /**
2773  * gtk_widget_common_ancestor:
2774  * @widget_a: a #GtkWidget
2775  * @widget_b: a #GtkWidget
2776  * 
2777  * Find the common ancestor of @widget_a and @widget_b that
2778  * is closest to the two widgets.
2779  * 
2780  * Return value: the closest common ancestor of @widget_a and
2781  *   @widget_b or %NULL if @widget_a and @widget_b do not
2782  *   share a common ancestor.
2783  **/
2784 static GtkWidget *
2785 gtk_widget_common_ancestor (GtkWidget *widget_a,
2786                             GtkWidget *widget_b)
2787 {
2788   GtkWidget *parent_a;
2789   GtkWidget *parent_b;
2790   gint depth_a = 0;
2791   gint depth_b = 0;
2792
2793   parent_a = widget_a;
2794   while (parent_a->parent)
2795     {
2796       parent_a = parent_a->parent;
2797       depth_a++;
2798     }
2799
2800   parent_b = widget_b;
2801   while (parent_b->parent)
2802     {
2803       parent_b = parent_b->parent;
2804       depth_b++;
2805     }
2806
2807   if (parent_a != parent_b)
2808     return NULL;
2809
2810   while (depth_a > depth_b)
2811     {
2812       widget_a = widget_a->parent;
2813       depth_a--;
2814     }
2815
2816   while (depth_b > depth_a)
2817     {
2818       widget_b = widget_b->parent;
2819       depth_b--;
2820     }
2821
2822   while (widget_a != widget_b)
2823     {
2824       widget_a = widget_a->parent;
2825       widget_b = widget_b->parent;
2826     }
2827
2828   return widget_a;
2829 }
2830
2831 /**
2832  * gtk_widget_translate_coordinates:
2833  * @src_widget:  a #GtkWidget
2834  * @dest_widget: a #GtkWidget
2835  * @src_x: X position relative to @src_widget
2836  * @src_y: Y position relative to @src_widget
2837  * @dest_x: location to store X position relative to @dest_widget
2838  * @dest_y: location to store Y position relative to @dest_widget
2839  * 
2840  * Translate coordinates relative to @src_widget's allocation to coordinates
2841  * relative to @dest_widget's allocations. In order to perform this
2842  * operation, both widgets must be realized, and must share a common
2843  * toplevel.
2844  * 
2845  * Return value: %FALSE if either widget was not realized, or there
2846  *   was no common ancestor. In this case, nothing is stored in
2847  *   *@dest_x and *@dest_y. Otherwise %TRUE.
2848  **/
2849 gboolean
2850 gtk_widget_translate_coordinates (GtkWidget  *src_widget,
2851                                   GtkWidget  *dest_widget,
2852                                   gint        src_x,
2853                                   gint        src_y,
2854                                   gint       *dest_x,
2855                                   gint       *dest_y)
2856 {
2857   GtkWidget *ancestor;
2858   GdkWindow *window;
2859
2860   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2861   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2862
2863   ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2864   if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2865     return FALSE;
2866
2867   /* Translate from allocation relative to window relative */
2868   if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2869     {
2870       gint wx, wy;
2871       gdk_window_get_position (src_widget->window, &wx, &wy);
2872
2873       src_x -= wx - src_widget->allocation.x;
2874       src_y -= wy - src_widget->allocation.y;
2875     }
2876   else
2877     {
2878       src_x += src_widget->allocation.x;
2879       src_y += src_widget->allocation.y;
2880     }
2881
2882   /* Translate to the common ancestor */
2883   window = src_widget->window;
2884   while (window != ancestor->window)
2885     {
2886       gint dx, dy;
2887       
2888       gdk_window_get_position (window, &dx, &dy);
2889       
2890       src_x += dx;
2891       src_y += dy;
2892       
2893       window = gdk_window_get_parent (window);
2894
2895       if (!window)              /* Handle GtkHandleBox */
2896         return FALSE;
2897     }
2898
2899   /* And back */
2900   window = dest_widget->window;
2901   while (window != ancestor->window)
2902     {
2903       gint dx, dy;
2904       
2905       gdk_window_get_position (window, &dx, &dy);
2906       
2907       src_x -= dx;
2908       src_y -= dy;
2909       
2910       window = gdk_window_get_parent (window);
2911       
2912       if (!window)              /* Handle GtkHandleBox */
2913         return FALSE;
2914     }
2915
2916   /* Translate from window relative to allocation relative */
2917   if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2918     {
2919       gint wx, wy;
2920       gdk_window_get_position (dest_widget->window, &wx, &wy);
2921
2922       src_x += wx - dest_widget->allocation.x;
2923       src_y += wy - dest_widget->allocation.y;
2924     }
2925   else
2926     {
2927       src_x -= dest_widget->allocation.x;
2928       src_y -= dest_widget->allocation.y;
2929     }
2930
2931   if (dest_x)
2932     *dest_x = src_x;
2933   if (dest_y)
2934     *dest_y = src_y;
2935
2936   return TRUE;
2937 }
2938
2939 static void
2940 gtk_widget_real_size_allocate (GtkWidget     *widget,
2941                                GtkAllocation *allocation)
2942 {
2943   widget->allocation = *allocation;
2944   
2945   if (GTK_WIDGET_REALIZED (widget) &&
2946       !GTK_WIDGET_NO_WINDOW (widget))
2947      {
2948         gdk_window_move_resize (widget->window,
2949                                 allocation->x, allocation->y,
2950                                 allocation->width, allocation->height);
2951      }
2952 }
2953
2954 static gboolean
2955 gtk_widget_real_can_activate_accel (GtkWidget *widget,
2956                                     guint      signal_id)
2957 {
2958   /* widgets must be onscreen for accels to take effect */
2959   return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
2960 }
2961
2962 /**
2963  * gtk_widget_can_activate_accel:
2964  * @widget: a #GtkWidget
2965  * @signal_id: the ID of a signal installed on @widget
2966  * 
2967  * Determines whether an accelerator that activates the signal
2968  * identified by @signal_id can currently be activated.
2969  * This is done by emitting the GtkWidget::can-activate-accel
2970  * signal on @widget; if the signal isn't overridden by a
2971  * handler or in a derived widget, then the default check is
2972  * that the widget must be sensitive, and the widget and all
2973  * its ancestors mapped.
2974  *
2975  * Return value: %TRUE if the accelerator can be activated.
2976  *
2977  * Since: 2.4
2978  **/
2979 gboolean
2980 gtk_widget_can_activate_accel (GtkWidget *widget,
2981                                guint      signal_id)
2982 {
2983   gboolean can_activate = FALSE;
2984   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2985   g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
2986   return can_activate;
2987 }
2988
2989 typedef struct {
2990   GClosure   closure;
2991   guint      signal_id;
2992 } AccelClosure;
2993
2994 static void
2995 closure_accel_activate (GClosure     *closure,
2996                         GValue       *return_value,
2997                         guint         n_param_values,
2998                         const GValue *param_values,
2999                         gpointer      invocation_hint,
3000                         gpointer      marshal_data)
3001 {
3002   AccelClosure *aclosure = (AccelClosure*) closure;
3003   gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3004
3005   if (can_activate)
3006     g_signal_emit (closure->data, aclosure->signal_id, 0);
3007
3008   /* whether accelerator was handled */
3009   g_value_set_boolean (return_value, can_activate);
3010 }
3011
3012 static void
3013 closures_destroy (gpointer data)
3014 {
3015   GSList *slist, *closures = data;
3016
3017   for (slist = closures; slist; slist = slist->next)
3018     {
3019       g_closure_invalidate (slist->data);
3020       g_closure_unref (slist->data);
3021     }
3022   g_slist_free (closures);
3023 }
3024
3025 static GClosure*
3026 widget_new_accel_closure (GtkWidget *widget,
3027                           guint      signal_id)
3028 {
3029   AccelClosure *aclosure;
3030   GClosure *closure = NULL;
3031   GSList *slist, *closures;
3032
3033   closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3034   for (slist = closures; slist; slist = slist->next)
3035     if (!gtk_accel_group_from_accel_closure (slist->data))
3036       {
3037         /* reuse this closure */
3038         closure = slist->data;
3039         break;
3040       }
3041   if (!closure)
3042     {
3043       closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3044       closures = g_slist_prepend (closures, g_closure_ref (closure));
3045       g_closure_sink (closure);
3046       g_closure_set_marshal (closure, closure_accel_activate);
3047     }
3048   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3049   
3050   aclosure = (AccelClosure*) closure;
3051   g_assert (closure->data == widget);
3052   g_assert (closure->marshal == closure_accel_activate);
3053   aclosure->signal_id = signal_id;
3054
3055   return closure;
3056 }
3057
3058 /**
3059  * gtk_widget_add_accelerator
3060  * @widget:       widget to install an accelerator on
3061  * @accel_signal: widget signal to emit on accelerator activation
3062  * @accel_group:  accel group for this widget, added to its toplevel
3063  * @accel_key:    GDK keyval of the accelerator
3064  * @accel_mods:   modifier key combination of the accelerator
3065  * @accel_flags:  flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3066  *
3067  * Installs an accelerator for this @widget in @accel_group that causes
3068  * @accel_signal to be emitted if the accelerator is activated.
3069  * The @accel_group needs to be added to the widget's toplevel via
3070  * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3071  * Accelerators added through this function are not user changeable during
3072  * runtime. If you want to support accelerators that can be changed by the
3073  * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3074  * gtk_menu_item_set_accel_path() instead.
3075  */
3076 void
3077 gtk_widget_add_accelerator (GtkWidget      *widget,
3078                             const gchar    *accel_signal,
3079                             GtkAccelGroup  *accel_group,
3080                             guint           accel_key,
3081                             GdkModifierType accel_mods,
3082                             GtkAccelFlags   accel_flags)
3083 {
3084   GClosure *closure;
3085   GSignalQuery query;
3086
3087   g_return_if_fail (GTK_IS_WIDGET (widget));
3088   g_return_if_fail (accel_signal != NULL);
3089   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3090
3091   g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3092   if (!query.signal_id ||
3093       !(query.signal_flags & G_SIGNAL_ACTION) ||
3094       query.return_type != G_TYPE_NONE ||
3095       query.n_params)
3096     {
3097       /* hmm, should be elaborate enough */
3098       g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3099                  G_OBJECT_TYPE_NAME (widget), accel_signal);
3100       return;
3101     }
3102
3103   closure = widget_new_accel_closure (widget, query.signal_id);
3104
3105   g_object_ref (widget);
3106
3107   /* install the accelerator. since we don't map this onto an accel_path,
3108    * the accelerator will automatically be locked.
3109    */
3110   gtk_accel_group_connect (accel_group,
3111                            accel_key,
3112                            accel_mods,
3113                            accel_flags | GTK_ACCEL_LOCKED,
3114                            closure);
3115
3116   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3117
3118   g_object_unref (widget);
3119 }
3120
3121 /**
3122  * gtk_widget_remove_accelerator:
3123  * @widget:       widget to install an accelerator on
3124  * @accel_group:  accel group for this widget
3125  * @accel_key:    GDK keyval of the accelerator
3126  * @accel_mods:   modifier key combination of the accelerator
3127  * @returns:      whether an accelerator was installed and could be removed
3128  *
3129  * Removes an accelerator from @widget, previously installed with
3130  * gtk_widget_add_accelerator().
3131  */
3132 gboolean
3133 gtk_widget_remove_accelerator (GtkWidget      *widget,
3134                                GtkAccelGroup  *accel_group,
3135                                guint           accel_key,
3136                                GdkModifierType accel_mods)
3137 {
3138   GtkAccelGroupEntry *ag_entry;
3139   GList *slist, *clist;
3140   guint n;
3141   
3142   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3143   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3144
3145   ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3146   clist = gtk_widget_list_accel_closures (widget);
3147   for (slist = clist; slist; slist = slist->next)
3148     {
3149       guint i;
3150
3151       for (i = 0; i < n; i++)
3152         if (slist->data == (gpointer) ag_entry[i].closure)
3153           {
3154             gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3155
3156             g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3157
3158             g_list_free (clist);
3159
3160             return is_removed;
3161           }
3162     }
3163   g_list_free (clist);
3164
3165   g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3166              accel_key, accel_mods, accel_group,
3167              G_OBJECT_TYPE_NAME (widget), widget);
3168
3169   return FALSE;
3170 }
3171
3172 /**
3173  * gtk_widget_list_accel_closures
3174  * @widget:  widget to list accelerator closures for
3175  * @returns: a newly allocated #GList of closures
3176  *
3177  * Lists the closures used by @widget for accelerator group connections
3178  * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3179  * The closures can be used to monitor accelerator changes on @widget,
3180  * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a 
3181  * closure which can be found out with gtk_accel_group_from_accel_closure().
3182  */
3183 GList*
3184 gtk_widget_list_accel_closures (GtkWidget *widget)
3185 {
3186   GSList *slist;
3187   GList *clist = NULL;
3188
3189   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3190
3191   for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3192     if (gtk_accel_group_from_accel_closure (slist->data))
3193       clist = g_list_prepend (clist, slist->data);
3194   return clist;
3195 }
3196
3197 typedef struct {
3198   GQuark         path_quark;
3199   GtkWidget     *widget;
3200   GtkAccelGroup *accel_group;
3201   GClosure      *closure;
3202 } AccelPath;
3203
3204 static void
3205 destroy_accel_path (gpointer data)
3206 {
3207   AccelPath *apath = data;
3208
3209   gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3210
3211   /* closures_destroy takes care of unrefing the closure */
3212   g_object_unref (apath->accel_group);
3213   
3214   g_free (apath);
3215 }
3216
3217
3218 /**
3219  * gtk_widget_set_accel_path:
3220  * @widget: a #GtkWidget
3221  * @accel_path: path used to look up the the accelerator
3222  * @accel_group: a #GtkAccelGroup.
3223  * 
3224  * Given an accelerator group, @accel_group, and an accelerator path,
3225  * @accel_path, sets up an accelerator in @accel_group so whenever the
3226  * key binding that is defined for @accel_path is pressed, @widget
3227  * will be activated.  This removes any accelerators (for any
3228  * accelerator group) installed by previous calls to
3229  * gtk_widget_set_accel_path(). Associating accelerators with
3230  * paths allows them to be modified by the user and the modifications
3231  * to be saved for future use. (See gtk_accel_map_save().)
3232  *
3233  * This function is a low level function that would most likely
3234  * be used by a menu creation system like #GtkItemFactory. If you
3235  * use #GtkItemFactory, setting up accelerator paths will be done
3236  * automatically.
3237  *
3238  * Even when you you aren't using #GtkItemFactory, if you only want to
3239  * set up accelerators on menu items gtk_menu_item_set_accel_path()
3240  * provides a somewhat more convenient interface.
3241  **/
3242 void
3243 gtk_widget_set_accel_path (GtkWidget     *widget,
3244                            const gchar   *accel_path,
3245                            GtkAccelGroup *accel_group)
3246 {
3247   AccelPath *apath;
3248
3249   g_return_if_fail (GTK_IS_WIDGET (widget));
3250   g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3251
3252   if (accel_path)
3253     {
3254       g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3255       g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3256
3257       gtk_accel_map_add_entry (accel_path, 0, 0);
3258       apath = g_new (AccelPath, 1);
3259       apath->widget = widget;
3260       apath->accel_group = g_object_ref (accel_group);
3261       apath->path_quark = g_quark_from_string (accel_path);
3262       apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3263     }
3264   else
3265     apath = NULL;
3266
3267   /* also removes possible old settings */
3268   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3269
3270   if (apath)
3271     gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3272
3273   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3274 }
3275
3276 const gchar*
3277 _gtk_widget_get_accel_path (GtkWidget *widget,
3278                             gboolean  *locked)
3279 {
3280   AccelPath *apath;
3281
3282   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3283
3284   apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3285   if (locked)
3286     *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3287   return apath ? g_quark_to_string (apath->path_quark) : NULL;
3288 }
3289
3290 gboolean
3291 gtk_widget_mnemonic_activate (GtkWidget *widget,
3292                               gboolean   group_cycling)
3293 {
3294   gboolean handled;
3295   
3296   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3297
3298   group_cycling = group_cycling != FALSE;
3299   if (!GTK_WIDGET_IS_SENSITIVE (widget))
3300     handled = TRUE;
3301   else
3302     g_signal_emit (widget,
3303                    widget_signals[MNEMONIC_ACTIVATE],
3304                    0,
3305                    group_cycling,
3306                    &handled);
3307   return handled;
3308 }
3309
3310 static gboolean
3311 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3312                                    gboolean   group_cycling)
3313 {
3314   if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3315     gtk_widget_activate (widget);
3316   else if (GTK_WIDGET_CAN_FOCUS (widget))
3317     gtk_widget_grab_focus (widget);
3318   else
3319     {
3320       g_warning ("widget `%s' isn't suitable for mnemonic activation",
3321                  G_OBJECT_TYPE_NAME (widget));
3322       gdk_display_beep (gtk_widget_get_display (widget));
3323     }
3324   return TRUE;
3325 }
3326
3327 static gboolean
3328 gtk_widget_real_key_press_event (GtkWidget         *widget,
3329                                  GdkEventKey       *event)
3330 {
3331   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3332 }
3333
3334 static gboolean
3335 gtk_widget_real_key_release_event (GtkWidget         *widget,
3336                                    GdkEventKey       *event)
3337 {
3338   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3339 }
3340
3341 static gboolean
3342 gtk_widget_real_focus_in_event (GtkWidget     *widget,
3343                                 GdkEventFocus *event)
3344 {
3345   gtk_widget_queue_shallow_draw (widget);
3346
3347   return FALSE;
3348 }
3349
3350 static gboolean
3351 gtk_widget_real_focus_out_event (GtkWidget     *widget,
3352                                  GdkEventFocus *event)
3353 {
3354   gtk_widget_queue_shallow_draw (widget);
3355
3356   return FALSE;
3357 }
3358
3359 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3360      (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3361
3362 /**
3363  * gtk_widget_event:
3364  * @widget: a #GtkWidget
3365  * @event: a #GdkEvent
3366  * 
3367  * Rarely-used function. This function is used to emit
3368  * the event signals on a widget (those signals should never
3369  * be emitted without using this function to do so).
3370  * If you want to synthesize an event though, don't use this function;
3371  * instead, use gtk_main_do_event() so the event will behave as if
3372  * it were in the event queue. Don't synthesize expose events; instead,
3373  * use gdk_window_invalidate_rect() to invalidate a region of the
3374  * window.
3375  * 
3376  * Return value: return from the event signal emission (%TRUE if the event was handled)
3377  **/
3378 gboolean
3379 gtk_widget_event (GtkWidget *widget,
3380                   GdkEvent  *event)
3381 {
3382   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3383   g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3384
3385   if (event->type == GDK_EXPOSE)
3386     {
3387       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3388                  "the same effect, call gdk_window_invalidate_rect/region(), "
3389                  "followed by gdk_window_process_updates().");
3390       return TRUE;
3391     }
3392   
3393   return gtk_widget_event_internal (widget, event);
3394 }
3395
3396
3397 /**
3398  * gtk_widget_send_expose:
3399  * @widget: a #GtkWidget
3400  * @event: a expose #GdkEvent
3401  * 
3402  * Very rarely-used function. This function is used to emit
3403  * an expose event signals on a widget. This function is not
3404  * normally used directly. The only time it is used is when
3405  * propagating an expose event to a child %NO_WINDOW widget, and
3406  * that is normally done using gtk_container_propagate_expose().
3407  *
3408  * If you want to force an area of a window to be redrawn, 
3409  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3410  * To cause the redraw to be done immediately, follow that call
3411  * with a call to gdk_window_process_updates().
3412  * 
3413  * Return value: return from the event signal emission (%TRUE if the event was handled)
3414  **/
3415 gint
3416 gtk_widget_send_expose (GtkWidget *widget,
3417                         GdkEvent  *event)
3418 {
3419   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3420   g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3421   g_return_val_if_fail (event != NULL, TRUE);
3422   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3423
3424   if (event->type != GDK_EXPOSE)
3425     return TRUE;
3426   
3427   return gtk_widget_event_internal (widget, event);
3428 }
3429
3430 static gboolean
3431 event_window_is_still_viewable (GdkEvent *event)
3432 {
3433   /* Some programs, such as gnome-theme-manager, fake widgets
3434    * into exposing onto a pixmap by sending expose events with
3435    * event->window pointing to a pixmap
3436    */
3437   if (GDK_IS_PIXMAP (event->any.window))
3438     return event->type == GDK_EXPOSE;
3439   
3440   /* Check that we think the event's window is viewable before
3441    * delivering the event, to prevent suprises. We do this here
3442    * at the last moment, since the event may have been queued
3443    * up behind other events, held over a recursive main loop, etc.
3444    */
3445   switch (event->type)
3446     {
3447     case GDK_EXPOSE:
3448     case GDK_MOTION_NOTIFY:
3449     case GDK_BUTTON_PRESS:
3450     case GDK_2BUTTON_PRESS:
3451     case GDK_3BUTTON_PRESS:
3452     case GDK_KEY_PRESS:
3453     case GDK_ENTER_NOTIFY:
3454     case GDK_PROXIMITY_IN:
3455     case GDK_SCROLL:
3456       return event->any.window && gdk_window_is_viewable (event->any.window);
3457
3458 #if 0
3459     /* The following events are the second half of paired events;
3460      * we always deliver them to deal with widgets that clean up
3461      * on the second half.
3462      */
3463     case GDK_BUTTON_RELEASE:
3464     case GDK_KEY_RELEASE:
3465     case GDK_LEAVE_NOTIFY:
3466     case GDK_PROXIMITY_OUT:
3467 #endif      
3468       
3469     default:
3470       /* Remaining events would make sense on an not-viewable window,
3471        * or don't have an associated window.
3472        */
3473       return TRUE;
3474     }
3475 }
3476
3477 static gint
3478 gtk_widget_event_internal (GtkWidget *widget,
3479                            GdkEvent  *event)
3480 {
3481   gboolean return_val = FALSE;
3482
3483   /* We check only once for is-still-visible; if someone
3484    * hides the window in on of the signals on the widget,
3485    * they are responsible for returning TRUE to terminate
3486    * handling.
3487    */
3488   if (!event_window_is_still_viewable (event))
3489     return TRUE;
3490
3491   g_object_ref (widget);
3492
3493   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3494   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3495   if (!return_val)
3496     {
3497       gint signal_num;
3498
3499       switch (event->type)
3500         {
3501         case GDK_NOTHING:
3502           signal_num = -1;
3503           break;
3504         case GDK_BUTTON_PRESS:
3505         case GDK_2BUTTON_PRESS:
3506         case GDK_3BUTTON_PRESS:
3507           signal_num = BUTTON_PRESS_EVENT;
3508           break;
3509         case GDK_SCROLL:
3510           signal_num = SCROLL_EVENT;
3511           break;
3512         case GDK_BUTTON_RELEASE:
3513           signal_num = BUTTON_RELEASE_EVENT;
3514           break;
3515         case GDK_MOTION_NOTIFY:
3516           signal_num = MOTION_NOTIFY_EVENT;
3517           break;
3518         case GDK_DELETE:
3519           signal_num = DELETE_EVENT;
3520           break;
3521         case GDK_DESTROY:
3522           signal_num = DESTROY_EVENT;
3523           break;
3524         case GDK_KEY_PRESS:
3525           signal_num = KEY_PRESS_EVENT;
3526           break;
3527         case GDK_KEY_RELEASE:
3528           signal_num = KEY_RELEASE_EVENT;
3529           break;
3530         case GDK_ENTER_NOTIFY:
3531           signal_num = ENTER_NOTIFY_EVENT;
3532           break;
3533         case GDK_LEAVE_NOTIFY:
3534           signal_num = LEAVE_NOTIFY_EVENT;
3535           break;
3536         case GDK_FOCUS_CHANGE:
3537           signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3538           break;
3539         case GDK_CONFIGURE:
3540           signal_num = CONFIGURE_EVENT;
3541           break;
3542         case GDK_MAP:
3543           signal_num = MAP_EVENT;
3544           break;
3545         case GDK_UNMAP:
3546           signal_num = UNMAP_EVENT;
3547           break;
3548         case GDK_WINDOW_STATE:
3549           signal_num = WINDOW_STATE_EVENT;
3550           break;
3551         case GDK_PROPERTY_NOTIFY:
3552           signal_num = PROPERTY_NOTIFY_EVENT;
3553           break;
3554         case GDK_SELECTION_CLEAR:
3555           signal_num = SELECTION_CLEAR_EVENT;
3556           break;
3557         case GDK_SELECTION_REQUEST:
3558           signal_num = SELECTION_REQUEST_EVENT;
3559           break;
3560         case GDK_SELECTION_NOTIFY:
3561           signal_num = SELECTION_NOTIFY_EVENT;
3562           break;
3563         case GDK_PROXIMITY_IN:
3564           signal_num = PROXIMITY_IN_EVENT;
3565           break;
3566         case GDK_PROXIMITY_OUT:
3567           signal_num = PROXIMITY_OUT_EVENT;
3568           break;
3569         case GDK_NO_EXPOSE:
3570           signal_num = NO_EXPOSE_EVENT;
3571           break;
3572         case GDK_CLIENT_EVENT:
3573           signal_num = CLIENT_EVENT;
3574           break;
3575         case GDK_EXPOSE:
3576           signal_num = EXPOSE_EVENT;
3577           break;
3578         case GDK_VISIBILITY_NOTIFY:
3579           signal_num = VISIBILITY_NOTIFY_EVENT;
3580           break;
3581         default:
3582           g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3583           signal_num = -1;
3584           break;
3585         }
3586       if (signal_num != -1)
3587         g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3588     }
3589   if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3590     g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3591   else
3592     return_val = TRUE;
3593
3594   g_object_unref (widget);
3595
3596   return return_val;
3597 }
3598
3599 /**
3600  * gtk_widget_activate:
3601  * @widget: a #GtkWidget that's activatable
3602  * 
3603  * For widgets that can be "activated" (buttons, menu items, etc.)
3604  * this function activates them. Activation is what happens when you
3605  * press Enter on a widget during key navigation. If @widget isn't 
3606  * activatable, the function returns %FALSE.
3607  * 
3608  * Return value: %TRUE if the widget was activatable
3609  **/
3610 gboolean
3611 gtk_widget_activate (GtkWidget *widget)
3612 {
3613   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3614   
3615   if (WIDGET_CLASS (widget)->activate_signal)
3616     {
3617       /* FIXME: we should eventually check the signals signature here */
3618       g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3619
3620       return TRUE;
3621     }
3622   else
3623     return FALSE;
3624 }
3625
3626 /**
3627  * gtk_widget_set_scroll_adjustments:
3628  * @widget: a #GtkWidget
3629  * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3630  * @vadjustment: an adjustment for vertical scrolling, or %NULL
3631  *
3632  * For widgets that support scrolling, sets the scroll adjustments and
3633  * returns %TRUE.  For widgets that don't support scrolling, does
3634  * nothing and returns %FALSE. Widgets that don't support scrolling
3635  * can be scrolled by placing them in a #GtkViewport, which does
3636  * support scrolling.
3637  * 
3638  * Return value: %TRUE if the widget supports scrolling
3639  **/
3640 gboolean
3641 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
3642                                    GtkAdjustment *hadjustment,
3643                                    GtkAdjustment *vadjustment)
3644 {
3645   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3646   if (hadjustment)
3647     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3648   if (vadjustment)
3649     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3650
3651   if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3652     {
3653       /* FIXME: we should eventually check the signals signature here */
3654       g_signal_emit (widget,
3655                      WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3656                      hadjustment, vadjustment);
3657       return TRUE;
3658     }
3659   else
3660     return FALSE;
3661 }
3662
3663 static void
3664 gtk_widget_reparent_subwindows (GtkWidget *widget,
3665                                 GdkWindow *new_window)
3666 {
3667   if (GTK_WIDGET_NO_WINDOW (widget))
3668     {
3669       GList *children = gdk_window_get_children (widget->window);
3670       GList *tmp_list;
3671
3672       for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3673         {
3674           GtkWidget *child;
3675           GdkWindow *window = tmp_list->data;
3676
3677           gdk_window_get_user_data (window, (void **)&child);
3678           while (child && child != widget)
3679             child = child->parent;
3680
3681           if (child)
3682             gdk_window_reparent (window, new_window, 0, 0);
3683         }
3684
3685       g_list_free (children);
3686     }
3687   else
3688     gdk_window_reparent (widget->window, new_window, 0, 0);
3689 }
3690
3691 static void
3692 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3693                                  gpointer   client_data)
3694 {
3695   g_return_if_fail (client_data != NULL);
3696   
3697   if (GTK_WIDGET_NO_WINDOW (widget))
3698     {
3699       if (widget->window)
3700         g_object_unref (widget->window);
3701       widget->window = (GdkWindow*) client_data;
3702       if (widget->window)
3703         g_object_ref (widget->window);
3704
3705       if (GTK_IS_CONTAINER (widget))
3706         gtk_container_forall (GTK_CONTAINER (widget),
3707                               gtk_widget_reparent_fixup_child,
3708                               client_data);
3709     }
3710 }
3711
3712 /**
3713  * gtk_widget_reparent:
3714  * @widget: a #GtkWidget
3715  * @new_parent: a #GtkContainer to move the widget into
3716  *
3717  * Moves a widget from one #GtkContainer to another, handling reference
3718  * count issues to avoid destroying the widget.
3719  * 
3720  **/
3721 void
3722 gtk_widget_reparent (GtkWidget *widget,
3723                      GtkWidget *new_parent)
3724 {
3725   g_return_if_fail (GTK_IS_WIDGET (widget));
3726   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3727   g_return_if_fail (widget->parent != NULL);
3728   
3729   if (widget->parent != new_parent)
3730     {
3731       /* First try to see if we can get away without unrealizing
3732        * the widget as we reparent it. if so we set a flag so
3733        * that gtk_widget_unparent doesn't unrealize widget
3734        */
3735       if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3736         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3737       
3738       g_object_ref (widget);
3739       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3740       gtk_container_add (GTK_CONTAINER (new_parent), widget);
3741       g_object_unref (widget);
3742       
3743       if (GTK_WIDGET_IN_REPARENT (widget))
3744         {
3745           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3746
3747           gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3748           gtk_widget_reparent_fixup_child (widget,
3749                                            gtk_widget_get_parent_window (widget));
3750         }
3751
3752       g_object_notify (G_OBJECT (widget), "parent");
3753     }
3754 }
3755
3756 /**
3757  * gtk_widget_intersect:
3758  * @widget: a #GtkWidget
3759  * @area: a rectangle
3760  * @intersection: rectangle to store intersection of @widget and @area
3761  * 
3762  * Computes the intersection of a @widget's area and @area, storing
3763  * the intersection in @intersection, and returns %TRUE if there was
3764  * an intersection.  @intersection may be %NULL if you're only
3765  * interested in whether there was an intersection.
3766  * 
3767  * Return value: %TRUE if there was an intersection
3768  **/
3769 gboolean
3770 gtk_widget_intersect (GtkWidget    *widget,
3771                       GdkRectangle *area,
3772                       GdkRectangle *intersection)
3773 {
3774   GdkRectangle *dest;
3775   GdkRectangle tmp;
3776   gint return_val;
3777   
3778   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3779   g_return_val_if_fail (area != NULL, FALSE);
3780   
3781   if (intersection)
3782     dest = intersection;
3783   else
3784     dest = &tmp;
3785   
3786   return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3787   
3788   if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3789     {
3790       intersection->x -= widget->allocation.x;
3791       intersection->y -= widget->allocation.y;
3792     }
3793   
3794   return return_val;
3795 }
3796
3797 /**
3798  * gtk_widget_region_intersect:
3799  * @widget: a #GtkWidget
3800  * @region: a #GdkRegion, in the same coordinate system as 
3801  *          @widget->allocation. That is, relative to @widget->window
3802  *          for %NO_WINDOW widgets; relative to the parent window
3803  *          of @widget->window for widgets with their own window.
3804  * @returns: A newly allocated region holding the intersection of @widget
3805  *           and @region. The coordinates of the return value are
3806  *           relative to @widget->window for %NO_WINDOW widgets, and
3807  *           relative to the parent window of @widget->window for
3808  *           widgets with their own window.
3809  * 
3810  * Computes the intersection of a @widget's area and @region, returning
3811  * the intersection. The result may be empty, use gdk_region_empty() to
3812  * check.
3813  **/
3814 GdkRegion *
3815 gtk_widget_region_intersect (GtkWidget *widget,
3816                              GdkRegion *region)
3817 {
3818   GdkRegion *dest;
3819   
3820   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3821   g_return_val_if_fail (region != NULL, NULL);
3822   
3823   dest = gdk_region_rectangle (&widget->allocation);
3824  
3825   gdk_region_intersect (dest, region);
3826
3827   return dest;
3828 }
3829
3830 /**
3831  * _gtk_widget_grab_notify:
3832  * @widget: a #GtkWidget
3833  * @was_grabbed: whether a grab is now in effect
3834  * 
3835  * Emits the signal "grab_notify" on @widget.
3836  * 
3837  * Since: 2.6
3838  **/
3839 void
3840 _gtk_widget_grab_notify (GtkWidget *widget,
3841                          gboolean   was_grabbed)
3842 {
3843   g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
3844 }
3845
3846 /**
3847  * gtk_widget_grab_focus:
3848  * @widget: a #GtkWidget
3849  * 
3850  * Causes @widget to have the keyboard focus for the #GtkWindow it's
3851  * inside. @widget must be a focusable widget, such as a #GtkEntry;
3852  * something like #GtkFrame won't work. (More precisely, it must have the
3853  * %GTK_CAN_FOCUS flag set.)
3854  * 
3855  **/
3856 void
3857 gtk_widget_grab_focus (GtkWidget *widget)
3858 {
3859   g_return_if_fail (GTK_IS_WIDGET (widget));
3860
3861   if (!GTK_WIDGET_IS_SENSITIVE (widget))
3862     return;
3863   
3864   g_object_ref (widget);
3865   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3866   g_object_notify (G_OBJECT (widget), "has_focus");
3867   g_object_unref (widget);
3868 }
3869
3870 static void
3871 reset_focus_recurse (GtkWidget *widget,
3872                      gpointer   data)
3873 {
3874   if (GTK_IS_CONTAINER (widget))
3875     {
3876       GtkContainer *container;
3877
3878       container = GTK_CONTAINER (widget);
3879       gtk_container_set_focus_child (container, NULL);
3880
3881       gtk_container_foreach (container,
3882                              reset_focus_recurse,
3883                              NULL);
3884     }
3885 }
3886
3887 static void
3888 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3889 {
3890   if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3891     {
3892       GtkWidget *toplevel;
3893       GtkWidget *widget;
3894       
3895       /* clear the current focus setting, break if the current widget
3896        * is the focus widget's parent, since containers above that will
3897        * be set by the next loop.
3898        */
3899       toplevel = gtk_widget_get_toplevel (focus_widget);
3900       if (GTK_WIDGET_TOPLEVEL (toplevel))
3901         {
3902           widget = GTK_WINDOW (toplevel)->focus_widget;
3903           
3904           if (widget == focus_widget)
3905             {
3906               /* We call _gtk_window_internal_set_focus() here so that the
3907                * toplevel window can request the focus if necessary.
3908                * This is needed when the toplevel is a GtkPlug
3909                */
3910               if (!GTK_WIDGET_HAS_FOCUS (widget))
3911                 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3912
3913               return;
3914             }
3915           
3916           if (widget)
3917             {
3918               while (widget->parent && widget->parent != focus_widget->parent)
3919                 {
3920                   widget = widget->parent;
3921                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3922                 }
3923             }
3924         }
3925       else if (toplevel != focus_widget)
3926         {
3927           /* gtk_widget_grab_focus() operates on a tree without window...
3928            * actually, this is very questionable behaviour.
3929            */
3930           
3931           gtk_container_foreach (GTK_CONTAINER (toplevel),
3932                                  reset_focus_recurse,
3933                                  NULL);
3934         }
3935
3936       /* now propagate the new focus up the widget tree and finally
3937        * set it on the window
3938        */
3939       widget = focus_widget;
3940       while (widget->parent)
3941         {
3942           gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3943           widget = widget->parent;
3944         }
3945       if (GTK_IS_WINDOW (widget))
3946         _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3947     }
3948 }
3949
3950 static gboolean
3951 gtk_widget_real_show_help (GtkWidget        *widget,
3952                            GtkWidgetHelpType help_type)
3953 {
3954   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3955     {
3956       _gtk_tooltips_toggle_keyboard_mode (widget);
3957       return TRUE;
3958     }
3959   else
3960     return FALSE;
3961 }
3962
3963 static gboolean
3964 gtk_widget_real_focus (GtkWidget         *widget,
3965                        GtkDirectionType   direction)
3966 {
3967   if (!GTK_WIDGET_CAN_FOCUS (widget))
3968     return FALSE;
3969   
3970   if (!gtk_widget_is_focus (widget))
3971     {
3972       gtk_widget_grab_focus (widget);
3973       return TRUE;
3974     }
3975   else
3976     return FALSE;
3977 }
3978
3979 /**
3980  * gtk_widget_is_focus:
3981  * @widget: a #GtkWidget
3982  * 
3983  * Determines if the widget is the focus widget within its
3984  * toplevel. (This does not mean that the %HAS_FOCUS flag is
3985  * necessarily set; %HAS_FOCUS will only be set if the
3986  * toplevel widget additionally has the global input focus.)
3987  * 
3988  * Return value: %TRUE if the widget is the focus widget.
3989  **/
3990 gboolean
3991 gtk_widget_is_focus (GtkWidget *widget)
3992 {
3993   GtkWidget *toplevel;
3994
3995   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3996
3997   toplevel = gtk_widget_get_toplevel (widget);
3998   
3999   if (GTK_IS_WINDOW (toplevel))
4000     return widget == GTK_WINDOW (toplevel)->focus_widget;
4001   else
4002     return FALSE;
4003 }
4004
4005 /**
4006  * gtk_widget_grab_default:
4007  * @widget: a #GtkWidget
4008  *
4009  * Causes @widget to become the default widget. @widget must have the
4010  * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4011  * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4012  * GTK_CAN_DEFAULT)</literal>.  The default widget is activated when the user
4013  * presses Enter in a window.  Default widgets must be activatable,
4014  * that is, gtk_widget_activate() should affect them.
4015  * 
4016  **/
4017 void
4018 gtk_widget_grab_default (GtkWidget *widget)
4019 {
4020   GtkWidget *window;
4021   
4022   g_return_if_fail (GTK_IS_WIDGET (widget));
4023   g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4024   
4025   window = gtk_widget_get_toplevel (widget);
4026   
4027   if (window && GTK_WIDGET_TOPLEVEL (window))
4028     gtk_window_set_default (GTK_WINDOW (window), widget);
4029   else
4030     g_warning (G_STRLOC ": widget not within a GtkWindow");
4031 }
4032
4033 /**
4034  * gtk_widget_set_name:
4035  * @widget: a #GtkWidget
4036  * @name: name for the widget
4037  *
4038  * Widgets can be named, which allows you to refer to them from a
4039  * gtkrc file. You can apply a style to widgets with a particular name
4040  * in the gtkrc file. See the documentation for gtkrc files (on the
4041  * same page as the docs for #GtkRcStyle).
4042  * 
4043  * Note that widget names are separated by periods in paths (see 
4044  * gtk_widget_path()), so names with embedded periods may cause confusion.
4045  **/
4046 void
4047 gtk_widget_set_name (GtkWidget   *widget,
4048                      const gchar *name)
4049 {
4050   gchar *new_name;
4051   
4052   g_return_if_fail (GTK_IS_WIDGET (widget));
4053
4054   new_name = g_strdup (name);
4055   g_free (widget->name);
4056   widget->name = new_name;
4057
4058   if (GTK_WIDGET_RC_STYLE (widget))
4059     gtk_widget_reset_rc_style (widget);
4060
4061   g_object_notify (G_OBJECT (widget), "name");
4062 }
4063
4064 /**
4065  * gtk_widget_get_name:
4066  * @widget: a #GtkWidget
4067  * 
4068  * Retrieves the name of a widget. See gtk_widget_set_name() for the
4069  * significance of widget names.
4070  * 
4071  * Return value: name of the widget. This string is owned by GTK+ and
4072  * should not be modified or freed
4073  **/
4074 G_CONST_RETURN gchar*
4075 gtk_widget_get_name (GtkWidget *widget)
4076 {
4077   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4078   
4079   if (widget->name)
4080     return widget->name;
4081   return g_type_name (GTK_WIDGET_TYPE (widget));
4082 }
4083
4084 /**
4085  * gtk_widget_set_state:
4086  * @widget: a #GtkWidget
4087  * @state: new state for @widget
4088  *
4089  * This function is for use in widget implementations. Sets the state
4090  * of a widget (insensitive, prelighted, etc.) Usually you should set
4091  * the state using wrapper functions such as gtk_widget_set_sensitive().
4092  * 
4093  **/
4094 void
4095 gtk_widget_set_state (GtkWidget           *widget,
4096                       GtkStateType         state)
4097 {
4098   g_return_if_fail (GTK_IS_WIDGET (widget));
4099
4100   if (state == GTK_WIDGET_STATE (widget))
4101     return;
4102
4103   if (state == GTK_STATE_INSENSITIVE)
4104     gtk_widget_set_sensitive (widget, FALSE);
4105   else
4106     {
4107       GtkStateData data;
4108
4109       data.state = state;
4110       data.state_restoration = FALSE;
4111       data.use_forall = FALSE;
4112       if (widget->parent)
4113         data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4114       else
4115         data.parent_sensitive = TRUE;
4116
4117       gtk_widget_propagate_state (widget, &data);
4118   
4119       if (GTK_WIDGET_DRAWABLE (widget))
4120         gtk_widget_queue_draw (widget);
4121     }
4122 }
4123
4124 void
4125 gtk_widget_set_app_paintable (GtkWidget *widget,
4126                               gboolean   app_paintable)
4127 {
4128   g_return_if_fail (GTK_IS_WIDGET (widget));
4129
4130   app_paintable = (app_paintable != FALSE);
4131
4132   if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4133     {
4134       if (app_paintable)
4135         GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4136       else
4137         GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4138
4139       if (GTK_WIDGET_DRAWABLE (widget))
4140         gtk_widget_queue_draw (widget);
4141
4142       g_object_notify (G_OBJECT (widget), "app_paintable");
4143     }
4144 }
4145
4146 /**
4147  * gtk_widget_set_double_buffered:
4148  * @widget: a #GtkWidget
4149  * @double_buffered: %TRUE to double-buffer a widget
4150  *
4151  * Widgets are double buffered by default; you can use this function
4152  * to turn off the buffering. "Double buffered" simply means that
4153  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4154  * automatically around expose events sent to the
4155  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4156  * window to an offscreen buffer, and gdk_window_end_paint() draws the
4157  * buffer to the screen. The result is that users see the window
4158  * update in one smooth step, and don't see individual graphics
4159  * primitives being rendered.
4160  *
4161  * In very simple terms, double buffered widgets don't flicker,
4162  * so you would only use this function to turn off double buffering
4163  * if you had special needs and really knew what you were doing.
4164  * 
4165  **/
4166 void
4167 gtk_widget_set_double_buffered (GtkWidget *widget,
4168                                 gboolean   double_buffered)
4169 {
4170   g_return_if_fail (GTK_IS_WIDGET (widget));
4171
4172   if (double_buffered)
4173     GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4174   else
4175     GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4176 }
4177
4178 /**
4179  * gtk_widget_set_redraw_on_allocate:
4180  * @widget: a #GtkWidget
4181  * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4182  *   when it is allocated to a new size. Otherwise, only the
4183  *   new portion of the widget will be redrawn.
4184  *
4185  * Sets whether a when a widgets size allocation changes, the entire
4186  * widget is queued for drawing. By default, this setting is %TRUE and
4187  * the entire widget is redrawn on every size change. If your widget
4188  * leaves the upper left unchanged when made bigger, turning this
4189  * setting on will improve performance.
4190
4191  * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4192  * off all allocation on resizing: the widget will not even redraw if
4193  * its position changes; this is to allow containers that don't draw
4194  * anything to avoid excess invalidations. If you set this flag on a
4195  * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window, 
4196  * you are responsible for invalidating both the old and new allocation 
4197  * of the widget when the widget is moved and responsible for invalidating
4198  * regions newly when the widget increases size.
4199  **/
4200 void
4201 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4202                                    gboolean   redraw_on_allocate)
4203 {
4204   g_return_if_fail (GTK_IS_WIDGET (widget));
4205
4206   if (redraw_on_allocate)
4207     GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4208   else
4209     GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4210 }
4211
4212 /**
4213  * gtk_widget_set_sensitive:
4214  * @widget: a #GtkWidget
4215  * @sensitive: %TRUE to make the widget sensitive
4216  *
4217  * Sets the sensitivity of a widget. A widget is sensitive if the user
4218  * can interact with it. Insensitive widgets are "grayed out" and the
4219  * user can't interact with them. Insensitive widgets are known as
4220  * "inactive", "disabled", or "ghosted" in some other toolkits.
4221  * 
4222  **/
4223 void
4224 gtk_widget_set_sensitive (GtkWidget *widget,
4225                           gboolean   sensitive)
4226 {
4227   GtkStateData data;
4228
4229   g_return_if_fail (GTK_IS_WIDGET (widget));
4230
4231   sensitive = (sensitive != FALSE);
4232
4233   if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4234     return;
4235
4236   if (sensitive)
4237     {
4238       GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4239       data.state = GTK_WIDGET_SAVED_STATE (widget);
4240     }
4241   else
4242     {
4243       GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4244       data.state = GTK_WIDGET_STATE (widget);
4245     }
4246   data.state_restoration = TRUE;
4247   data.use_forall = TRUE;
4248
4249   if (widget->parent)
4250     data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4251   else
4252     data.parent_sensitive = TRUE;
4253
4254   gtk_widget_propagate_state (widget, &data);
4255   if (GTK_WIDGET_DRAWABLE (widget))
4256     gtk_widget_queue_draw (widget);
4257
4258   g_object_notify (G_OBJECT (widget), "sensitive");
4259 }
4260
4261 /**
4262  * gtk_widget_set_parent:
4263  * @widget: a #GtkWidget
4264  * @parent: parent container
4265  *
4266  * This function is useful only when implementing subclasses of #GtkContainer.
4267  * Sets the container as the parent of @widget, and takes care of
4268  * some details such as updating the state and style of the child
4269  * to reflect its new location. The opposite function is
4270  * gtk_widget_unparent().
4271  * 
4272  **/
4273 void
4274 gtk_widget_set_parent (GtkWidget *widget,
4275                        GtkWidget *parent)
4276 {
4277   GtkStateData data;
4278   
4279   g_return_if_fail (GTK_IS_WIDGET (widget));
4280   g_return_if_fail (GTK_IS_WIDGET (parent));
4281   g_return_if_fail (widget != parent);
4282   if (widget->parent != NULL)
4283     {
4284       g_warning ("Can't set a parent on widget which has a parent\n");
4285       return;
4286     }
4287   if (GTK_WIDGET_TOPLEVEL (widget))
4288     {
4289       g_warning ("Can't set a parent on a toplevel widget\n");
4290       return;
4291     }
4292
4293   /* keep this function in sync with gtk_menu_attach_to_widget()
4294    */
4295
4296   g_object_ref (widget);
4297   gtk_object_sink (GTK_OBJECT (widget));
4298   widget->parent = parent;
4299
4300   if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4301     data.state = GTK_WIDGET_STATE (parent);
4302   else
4303     data.state = GTK_WIDGET_STATE (widget);
4304   data.state_restoration = FALSE;
4305   data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4306   data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4307
4308   gtk_widget_propagate_state (widget, &data);
4309   
4310   gtk_widget_reset_rc_styles (widget);
4311
4312   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4313   if (GTK_WIDGET_ANCHORED (widget->parent))
4314     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4315   g_object_notify (G_OBJECT (widget), "parent");
4316
4317   /* Enforce realized/mapped invariants
4318    */
4319   if (GTK_WIDGET_REALIZED (widget->parent))
4320     gtk_widget_realize (widget);
4321
4322   if (GTK_WIDGET_VISIBLE (widget->parent) &&
4323       GTK_WIDGET_VISIBLE (widget))
4324     {
4325       if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4326           GTK_WIDGET_MAPPED (widget->parent))
4327         gtk_widget_map (widget);
4328
4329       gtk_widget_queue_resize (widget);
4330     }
4331 }
4332
4333 /**
4334  * gtk_widget_get_parent:
4335  * @widget: a #GtkWidget
4336  *
4337  * Returns the parent container of @widget.
4338  *
4339  * Return value: the parent container of @widget, or %NULL
4340  **/
4341 GtkWidget *
4342 gtk_widget_get_parent (GtkWidget *widget)
4343 {
4344   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4345
4346   return widget->parent;
4347 }
4348
4349 /*****************************************
4350  * Widget styles
4351  * see docs/styles.txt
4352  *****************************************/
4353
4354 /**
4355  * gtk_widget_set_style:
4356  * @widget: a #GtkWidget
4357  * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4358  *         gtk_widget_set_style() and go back to the default style
4359  *
4360  * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4361  * want to use this function; it interacts badly with themes, because
4362  * themes work by replacing the #GtkStyle. Instead, use
4363  * gtk_widget_modify_style().
4364  * 
4365  **/
4366 void
4367 gtk_widget_set_style (GtkWidget *widget,
4368                       GtkStyle  *style)
4369 {
4370   g_return_if_fail (GTK_IS_WIDGET (widget));
4371
4372   if (style)
4373     {
4374       gboolean initial_emission;
4375
4376       initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4377       
4378       GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4379       GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4380       
4381       gtk_widget_set_style_internal (widget, style, initial_emission);
4382     }
4383   else
4384     {
4385       if (GTK_WIDGET_USER_STYLE (widget))
4386         gtk_widget_reset_rc_style (widget);
4387     }
4388 }
4389
4390 /**
4391  * gtk_widget_ensure_style:
4392  * @widget: a #GtkWidget
4393  *
4394  * Ensures that @widget has a style (@widget->style). Not a very useful
4395  * function; most of the time, if you want the style, the widget is
4396  * realized, and realized widgets are guaranteed to have a style
4397  * already.
4398  * 
4399  **/
4400 void
4401 gtk_widget_ensure_style (GtkWidget *widget)
4402 {
4403   g_return_if_fail (GTK_IS_WIDGET (widget));
4404
4405   if (!GTK_WIDGET_USER_STYLE (widget) &&
4406       !GTK_WIDGET_RC_STYLE (widget))
4407     gtk_widget_reset_rc_style (widget);
4408 }
4409
4410 /* Look up the RC style for this widget, unsetting any user style that
4411  * may be in effect currently
4412  **/
4413 static void
4414 gtk_widget_reset_rc_style (GtkWidget *widget)
4415 {
4416   GtkStyle *new_style = NULL;
4417   gboolean initial_emission;
4418   
4419   g_return_if_fail (GTK_IS_WIDGET (widget));
4420
4421   initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4422
4423   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4424   GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4425   
4426   if (gtk_widget_has_screen (widget))
4427     new_style = gtk_rc_get_style (widget);
4428   if (!new_style)
4429     new_style = gtk_widget_get_default_style ();
4430
4431   if (initial_emission || new_style != widget->style)
4432     gtk_widget_set_style_internal (widget, new_style, initial_emission);
4433 }
4434
4435 /**
4436  * gtk_widget_get_style:
4437  * @widget: a #GtkWidget
4438  * 
4439  * Simply an accessor function that returns @widget->style.
4440  * 
4441  * Return value: the widget's #GtkStyle
4442  **/
4443 GtkStyle*
4444 gtk_widget_get_style (GtkWidget *widget)
4445 {
4446   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4447   
4448   return widget->style;
4449 }
4450
4451 /**
4452  * gtk_widget_modify_style:
4453  * @widget: a #GtkWidget
4454  * @style: the #GtkRcStyle holding the style modifications
4455  * 
4456  * Modifies style values on the widget. Modifications made using this
4457  * technique take precedence over style values set via an RC file,
4458  * however, they will be overriden if a style is explicitely set on
4459  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4460  * is designed so each field can either be set or unset, so it is
4461  * possible, using this function, to modify some style values and
4462  * leave the others unchanged.
4463  *
4464  * Note that modifications made with this function are not cumulative
4465  * with previous calls to gtk_widget_modify_style() or with such
4466  * functions as gtk_widget_modify_fg(). If you wish to retain
4467  * previous values, you must first call gtk_widget_get_modifier_style(),
4468  * make your modifications to the returned style, then call
4469  * gtk_widget_modify_style() with that style. On the other hand,
4470  * if you first call gtk_widget_modify_style(), subsequent calls
4471  * to such functions gtk_widget_modify_fg() will have a cumulative
4472  * effect with the initial modifications.
4473  **/
4474 void       
4475 gtk_widget_modify_style (GtkWidget      *widget,
4476                          GtkRcStyle     *style)
4477 {
4478   GtkRcStyle *old_style;
4479
4480   g_return_if_fail (GTK_IS_WIDGET (widget));
4481   g_return_if_fail (GTK_IS_RC_STYLE (style));
4482   
4483   old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4484
4485   g_object_set_qdata_full (G_OBJECT (widget),
4486                            quark_rc_style,
4487                            gtk_rc_style_copy (style),
4488                            (GDestroyNotify) gtk_rc_style_unref);
4489
4490   /* note that "style" may be invalid here if it was the old
4491    * modifier style and the only reference was our own.
4492    */
4493   
4494   if (GTK_WIDGET_RC_STYLE (widget))
4495     gtk_widget_reset_rc_style (widget);
4496 }
4497
4498 /**
4499  * gtk_widget_get_modifier_style:
4500  * @widget: a #GtkWidget
4501  * 
4502  * Returns the current modifier style for the widget. (As set by
4503  * gtk_widget_modify_style().) If no style has previously set, a new
4504  * #GtkRcStyle will be created with all values unset, and set as the
4505  * modifier style for the widget. If you make changes to this rc
4506  * style, you must call gtk_widget_modify_style(), passing in the
4507  * returned rc style, to make sure that your changes take effect.
4508  *
4509  * Caution: passing the style back to gtk_widget_modify_style() will
4510  * normally end up destroying it, because gtk_widget_modify_style() copies
4511  * the passed-in style and sets the copy as the new modifier style,
4512  * thus dropping any reference to the old modifier style. Add a reference
4513  * to the modifier style if you want to keep it alive.
4514  * 
4515  * Return value: the modifier style for the widget. This rc style is
4516  *   owned by the widget. If you want to keep a pointer to value this
4517  *   around, you must add a refcount using gtk_rc_style_ref().
4518  **/
4519 GtkRcStyle *
4520 gtk_widget_get_modifier_style (GtkWidget      *widget)
4521 {
4522   GtkRcStyle *rc_style;
4523   
4524   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4525
4526   rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4527
4528   if (!rc_style)
4529     {
4530       rc_style = gtk_rc_style_new ();
4531       g_object_set_qdata_full (G_OBJECT (widget),
4532                                quark_rc_style,
4533                                rc_style,
4534                                (GDestroyNotify) gtk_rc_style_unref);
4535     }
4536
4537   return rc_style;
4538 }
4539
4540 static void
4541 gtk_widget_modify_color_component (GtkWidget      *widget,
4542                                    GtkRcFlags      component,
4543                                    GtkStateType    state,
4544                                    const GdkColor *color)
4545 {
4546   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
4547
4548   if (color)
4549     {
4550       switch (component)
4551         {
4552         case GTK_RC_FG:
4553           rc_style->fg[state] = *color;
4554           break;
4555         case GTK_RC_BG:
4556           rc_style->bg[state] = *color;
4557           break;
4558         case GTK_RC_TEXT:
4559           rc_style->text[state] = *color;
4560           break;
4561         case GTK_RC_BASE:
4562           rc_style->base[state] = *color;
4563           break;
4564         default:
4565           g_assert_not_reached();
4566         }
4567       
4568       rc_style->color_flags[state] |= component;
4569     }
4570   else
4571     rc_style->color_flags[state] &= ~component;
4572
4573   gtk_widget_modify_style (widget, rc_style);
4574 }
4575
4576 /**
4577  * gtk_widget_modify_fg:
4578  * @widget: a #GtkWidget.
4579  * @state: the state for which to set the foreground color.
4580  * @color: the color to assign (does not need to be allocated),
4581  *         or %NULL to undo the effect of previous calls to
4582  *         of gtk_widget_modify_fg().
4583  * 
4584  * Sets the foreground color for a widget in a particular state.  All
4585  * other style values are left untouched. See also
4586  * gtk_widget_modify_style().
4587  **/
4588 void
4589 gtk_widget_modify_fg (GtkWidget      *widget,
4590                       GtkStateType    state,
4591                       const GdkColor *color)
4592 {
4593   g_return_if_fail (GTK_IS_WIDGET (widget));
4594   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4595
4596   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4597 }
4598
4599 /**
4600  * gtk_widget_modify_bg:
4601  * @widget: a #GtkWidget.
4602  * @state: the state for which to set the background color.
4603  * @color: the color to assign (does not need to be allocated),
4604  *         or %NULL to undo the effect of previous calls to
4605  *         of gtk_widget_modify_bg().
4606  * 
4607  * Sets the background color for a widget in a particular state.  All
4608  * other style values are left untouched. See also
4609  * gtk_widget_modify_style().
4610  **/
4611 void
4612 gtk_widget_modify_bg (GtkWidget      *widget,
4613                       GtkStateType    state,
4614                       const GdkColor *color)
4615 {
4616   g_return_if_fail (GTK_IS_WIDGET (widget));
4617   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4618
4619   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4620 }
4621
4622 /**
4623  * gtk_widget_modify_text:
4624  * @widget: a #GtkWidget.
4625  * @state: the state for which to set the text color.
4626  * @color: the color to assign (does not need to be allocated),
4627  *         or %NULL to undo the effect of previous calls to
4628  *         of gtk_widget_modify_text().
4629  * 
4630  * Sets the text color for a widget in a particular state.  All other
4631  * style values are left untouched. The text color is the foreground
4632  * color used along with the base color (see gtk_widget_modify_base())
4633  * for widgets such as #GtkEntry and #GtkTextView. See also
4634  * gtk_widget_modify_style().
4635  **/
4636 void
4637 gtk_widget_modify_text (GtkWidget      *widget,
4638                         GtkStateType    state,
4639                         const GdkColor *color)
4640 {
4641   g_return_if_fail (GTK_IS_WIDGET (widget));
4642   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4643
4644   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4645 }
4646
4647 /**
4648  * gtk_widget_modify_base:
4649  * @widget: a #GtkWidget.
4650  * @state: the state for which to set the base color.
4651  * @color: the color to assign (does not need to be allocated),
4652  *         or %NULL to undo the effect of previous calls to
4653  *         of gtk_widget_modify_base().
4654  * 
4655  * Sets the base color for a widget in a particular state.
4656  * All other style values are left untouched. The base color
4657  * is the background color used along with the text color
4658  * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4659  * and #GtkTextView. See also gtk_widget_modify_style().
4660  **/
4661 void
4662 gtk_widget_modify_base (GtkWidget      *widget,
4663                         GtkStateType    state,
4664                         const GdkColor *color)
4665 {
4666   g_return_if_fail (GTK_IS_WIDGET (widget));
4667   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4668
4669   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4670 }
4671
4672 /**
4673  * gtk_widget_modify_font:
4674  * @widget: a #GtkWidget
4675  * @font_desc: the font description to use, or %NULL to undo
4676  *   the effect of previous calls to gtk_widget_modify_font().
4677  * 
4678  * Sets the font to use for a widget.  All other style values are left
4679  * untouched. See also gtk_widget_modify_style().
4680  **/
4681 void
4682 gtk_widget_modify_font (GtkWidget            *widget,
4683                         PangoFontDescription *font_desc)
4684 {
4685   GtkRcStyle *rc_style;
4686
4687   g_return_if_fail (GTK_IS_WIDGET (widget));
4688
4689   rc_style = gtk_widget_get_modifier_style (widget);  
4690
4691   if (rc_style->font_desc)
4692     pango_font_description_free (rc_style->font_desc);
4693
4694   if (font_desc)
4695     rc_style->font_desc = pango_font_description_copy (font_desc);
4696   else
4697     rc_style->font_desc = NULL;
4698   
4699   gtk_widget_modify_style (widget, rc_style);
4700 }
4701
4702 static void
4703 gtk_widget_direction_changed (GtkWidget        *widget,
4704                               GtkTextDirection  previous_direction)
4705 {
4706   gtk_widget_queue_resize (widget);
4707 }
4708
4709 static void
4710 gtk_widget_style_set (GtkWidget *widget,
4711                       GtkStyle  *previous_style)
4712 {
4713   if (GTK_WIDGET_REALIZED (widget) &&
4714       !GTK_WIDGET_NO_WINDOW (widget))
4715     gtk_style_set_background (widget->style, widget->window, widget->state);
4716 }
4717
4718 static void
4719 gtk_widget_set_style_internal (GtkWidget *widget,
4720                                GtkStyle  *style,
4721                                gboolean   initial_emission)
4722 {
4723   g_object_ref (widget);
4724   g_object_freeze_notify (G_OBJECT (widget));
4725
4726   if (widget->style != style || initial_emission)
4727     {
4728       PangoContext *context = gtk_widget_peek_pango_context (widget);
4729       if (context)
4730         pango_context_set_font_description (context, style->font_desc);
4731     }
4732   
4733   if (widget->style != style)
4734     {
4735       GtkStyle *previous_style;
4736
4737       if (GTK_WIDGET_REALIZED (widget))
4738         {
4739           gtk_widget_reset_shapes (widget);
4740           gtk_style_detach (widget->style);
4741         }
4742       
4743       previous_style = widget->style;
4744       widget->style = style;
4745       g_object_ref (widget->style);
4746       
4747       if (GTK_WIDGET_REALIZED (widget))
4748         widget->style = gtk_style_attach (widget->style, widget->window);
4749
4750       g_signal_emit (widget,
4751                      widget_signals[STYLE_SET],
4752                      0,
4753                      initial_emission ? NULL : previous_style);
4754       g_object_unref (previous_style);
4755
4756       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4757         gtk_widget_queue_resize (widget);
4758     }
4759   else if (initial_emission)
4760     g_signal_emit (widget,
4761                    widget_signals[STYLE_SET],
4762                    0,
4763                    NULL);
4764   g_object_notify (G_OBJECT (widget), "style");
4765   g_object_thaw_notify (G_OBJECT (widget));
4766   g_object_unref (widget);
4767 }
4768
4769 typedef struct {
4770   GtkWidget *previous_toplevel;
4771   GdkScreen *previous_screen;
4772   GdkScreen *new_screen;
4773 } HierarchyChangedInfo;
4774
4775 static void
4776 do_screen_change (GtkWidget *widget,
4777                   GdkScreen *old_screen,
4778                   GdkScreen *new_screen)
4779 {
4780   if (old_screen != new_screen)
4781     {
4782       if (old_screen)
4783         {
4784           PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4785           if (context)
4786             g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4787         }
4788       
4789       g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4790     }
4791 }
4792
4793 static void
4794 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4795                                                 gpointer   client_data)
4796 {
4797   gboolean new_anchored;
4798   HierarchyChangedInfo *info = client_data;
4799
4800   new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4801                  (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4802
4803   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4804     {
4805       g_object_ref (widget);
4806       
4807       if (new_anchored)
4808         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4809       else
4810         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4811       
4812       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4813       do_screen_change (widget, info->previous_screen, info->new_screen);
4814       
4815       if (GTK_IS_CONTAINER (widget))
4816         gtk_container_forall (GTK_CONTAINER (widget),
4817                               gtk_widget_propagate_hierarchy_changed_recurse,
4818                               client_data);
4819       
4820       g_object_unref (widget);
4821     }
4822 }
4823
4824 /**
4825  * _gtk_widget_propagate_hierarchy_changed:
4826  * @widget: a #GtkWidget
4827  * @previous_toplevel: Previous toplevel
4828  * 
4829  * Propagates changes in the anchored state to a widget and all
4830  * children, unsetting or setting the %ANCHORED flag, and
4831  * emitting ::hierarchy_changed.
4832  **/
4833 void
4834 _gtk_widget_propagate_hierarchy_changed (GtkWidget    *widget,
4835                                          GtkWidget    *previous_toplevel)
4836 {
4837   HierarchyChangedInfo info;
4838
4839   info.previous_toplevel = previous_toplevel;
4840   info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4841
4842   if (GTK_WIDGET_TOPLEVEL (widget) ||
4843       (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4844     info.new_screen = gtk_widget_get_screen (widget);
4845   else
4846     info.new_screen = NULL;
4847
4848   if (info.previous_screen)
4849     g_object_ref (info.previous_screen);
4850   if (previous_toplevel)
4851     g_object_ref (previous_toplevel);
4852
4853   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4854
4855   if (previous_toplevel)
4856     g_object_unref (previous_toplevel);
4857   if (info.previous_screen)
4858     g_object_unref (info.previous_screen);
4859 }
4860
4861 static void
4862 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4863                                              gpointer   client_data)
4864 {
4865   HierarchyChangedInfo *info = client_data;
4866
4867   g_object_ref (widget);
4868   
4869   do_screen_change (widget, info->previous_screen, info->new_screen);
4870   
4871   if (GTK_IS_CONTAINER (widget))
4872     gtk_container_forall (GTK_CONTAINER (widget),
4873                           gtk_widget_propagate_screen_changed_recurse,
4874                           client_data);
4875   
4876   g_object_unref (widget);
4877 }
4878
4879 /**
4880  * _gtk_widget_propagate_screen_changed:
4881  * @widget: a #GtkWidget
4882  * @previous_screen: Previous screen
4883  * 
4884  * Propagates changes in the screen for a widget to all
4885  * children, emitting ::screen_changed.
4886  **/
4887 void
4888 _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
4889                                       GdkScreen    *previous_screen)
4890 {
4891   HierarchyChangedInfo info;
4892
4893   info.previous_screen = previous_screen;
4894   info.new_screen = gtk_widget_get_screen (widget);
4895
4896   if (previous_screen)
4897     g_object_ref (previous_screen);
4898
4899   gtk_widget_propagate_screen_changed_recurse (widget, &info);
4900
4901   if (previous_screen)
4902     g_object_unref (previous_screen);
4903 }
4904
4905 static void
4906 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4907 {
4908   if (GTK_WIDGET_RC_STYLE (widget))
4909     gtk_widget_reset_rc_style (widget);
4910   
4911   if (GTK_IS_CONTAINER (widget))
4912     gtk_container_forall (GTK_CONTAINER (widget),
4913                           reset_rc_styles_recurse,
4914                           NULL);
4915 }
4916
4917 void
4918 gtk_widget_reset_rc_styles (GtkWidget *widget)
4919 {
4920   g_return_if_fail (GTK_IS_WIDGET (widget));
4921
4922   reset_rc_styles_recurse (widget, NULL);
4923 }
4924
4925 /**
4926  * gtk_widget_get_default_style:
4927  * 
4928  * Returns the default style used by all widgets initially.
4929  * 
4930  * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4931  * should not be modified or freed.
4932  */ 
4933 GtkStyle*
4934 gtk_widget_get_default_style (void)
4935 {
4936   if (!gtk_default_style)
4937     {
4938       gtk_default_style = gtk_style_new ();
4939       g_object_ref (gtk_default_style);
4940     }
4941   
4942   return gtk_default_style;
4943 }
4944
4945 static PangoContext *
4946 gtk_widget_peek_pango_context (GtkWidget *widget)
4947 {
4948   return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4949 }
4950
4951 /**
4952  * gtk_widget_get_pango_context:
4953  * @widget: a #GtkWidget
4954  * 
4955  * Gets a #PangoContext with the appropriate colormap, font description
4956  * and base direction for this widget. Unlike the context returned
4957  * by gtk_widget_create_pango_context(), this context is owned by
4958  * the widget (it can be used until the screen for the widget changes
4959  * or the widget is removed from its toplevel), and will be updated to
4960  * match any changes to the widget's attributes.
4961  *
4962  * If you create and keep a #PangoLayout using this context, you must
4963  * deal with changes to the context by calling pango_layout_context_changed()
4964  * on the layout in response to the ::style-set and ::direction-changed signals
4965  * for the widget.
4966  *
4967  * Return value: the #PangoContext for the widget.
4968  **/
4969 PangoContext *
4970 gtk_widget_get_pango_context (GtkWidget *widget)
4971 {
4972   PangoContext *context;
4973
4974   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4975   
4976   context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4977   if (!context)
4978     {
4979       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4980       g_object_set_qdata_full (G_OBJECT (widget),
4981                                quark_pango_context,
4982                                context,
4983                                g_object_unref);
4984     }
4985
4986   return context;
4987 }
4988
4989 /**
4990  * gtk_widget_create_pango_context:
4991  * @widget: a #GtkWidget
4992  * 
4993  * Creates a new #PangoContext with the appropriate colormap,
4994  * font description, and base direction for drawing text for
4995  * this widget. See also gtk_widget_get_pango_context().
4996  * 
4997  * Return value: the new #PangoContext
4998  **/
4999 PangoContext *
5000 gtk_widget_create_pango_context (GtkWidget *widget)
5001 {
5002   GdkScreen *screen;
5003   PangoContext *context;
5004
5005   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5006
5007   screen = gtk_widget_get_screen_unchecked (widget);
5008   if (!screen)
5009     {
5010       GTK_NOTE (MULTIHEAD,
5011                 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5012
5013       screen = gdk_screen_get_default ();
5014     }
5015
5016   context = gdk_pango_context_get_for_screen (screen);
5017
5018   pango_context_set_base_dir (context,
5019                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5020                                 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5021   pango_context_set_font_description (context, widget->style->font_desc);
5022   pango_context_set_language (context, gtk_get_default_language ());
5023
5024   return context;
5025 }
5026
5027 /**
5028  * gtk_widget_create_pango_layout:
5029  * @widget: a #GtkWidget
5030  * @text:   text to set on the layout (can be %NULL)
5031  * 
5032  * Creates a new #PangoLayout with the appropriate colormap,
5033  * font description, and base direction for drawing text for
5034  * this widget.
5035  *
5036  * If you keep a #PangoLayout created in this way around, in order
5037  * notify the layout of changes to the base direction or font of this
5038  * widget, you must call pango_layout_context_changed() in response to
5039  * the ::style-set and ::direction-changed signals for the widget.
5040  * 
5041  * Return value: the new #PangoLayout
5042  **/
5043 PangoLayout *
5044 gtk_widget_create_pango_layout (GtkWidget   *widget,
5045                                 const gchar *text)
5046 {
5047   PangoLayout *layout;
5048   PangoContext *context;
5049
5050   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5051
5052   context = gtk_widget_get_pango_context (widget);
5053   layout = pango_layout_new (context);
5054
5055   if (text)
5056     pango_layout_set_text (layout, text, -1);
5057
5058   return layout;
5059 }
5060
5061 /**
5062  * gtk_widget_render_icon:
5063  * @widget: a #GtkWidget
5064  * @stock_id: a stock ID
5065  * @size: a stock size. A size of (GtkIconSize)-1 means render at 
5066  *     the size of the source and don't scale (if there are multiple 
5067  *     source sizes, GTK+ picks one of the available sizes).
5068  * @detail: render detail to pass to theme engine
5069  * 
5070  * A convenience function that uses the theme engine and RC file
5071  * settings for @widget to look up @stock_id and render it to
5072  * a pixbuf. @stock_id should be a stock icon ID such as
5073  * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5074  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5075  * identifies the widget or code doing the rendering, so that
5076  * theme engines can special-case rendering for that widget or code.
5077  *
5078  * The pixels in the returned #GdkPixbuf are shared with the rest of
5079  * the application and should not be modified. The pixbuf should be freed
5080  * after use with g_object_unref().
5081  *
5082  * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5083  **/
5084 GdkPixbuf*
5085 gtk_widget_render_icon (GtkWidget      *widget,
5086                         const gchar    *stock_id,
5087                         GtkIconSize     size,
5088                         const gchar    *detail)
5089 {
5090   GtkIconSet *icon_set;
5091   GdkPixbuf *retval;
5092   
5093   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5094   g_return_val_if_fail (stock_id != NULL, NULL);
5095   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5096   
5097   gtk_widget_ensure_style (widget);
5098   
5099   icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5100
5101   if (icon_set == NULL)
5102     return NULL;
5103
5104   retval = gtk_icon_set_render_icon (icon_set,
5105                                      widget->style,
5106                                      gtk_widget_get_direction (widget),
5107                                      GTK_WIDGET_STATE (widget),
5108                                      size,
5109                                      widget,
5110                                      detail);
5111
5112   return retval;
5113 }
5114
5115 /**
5116  * gtk_widget_set_parent_window:
5117  * @widget: a #GtkWidget.
5118  * @parent_window: the new parent window.
5119  *  
5120  * Sets a non default parent window for @widget.
5121  **/
5122 void
5123 gtk_widget_set_parent_window   (GtkWidget           *widget,
5124                                 GdkWindow           *parent_window)
5125 {
5126   GdkWindow *old_parent_window;
5127
5128   g_return_if_fail (GTK_IS_WIDGET (widget));
5129   
5130   old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5131                                           quark_parent_window);
5132
5133   if (parent_window != old_parent_window)
5134     {
5135       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
5136                           parent_window);
5137       if (old_parent_window)
5138         g_object_unref (old_parent_window);
5139       if (parent_window)
5140         g_object_ref (parent_window);
5141     }
5142 }
5143
5144
5145 /**
5146  * gtk_widget_set_child_visible:
5147  * @widget: a #GtkWidget
5148  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5149  *
5150  * Sets whether @widget should be mapped along with its when its parent
5151  * is mapped and @widget has been shown with gtk_widget_show(). 
5152  *
5153  * The child visibility can be set for widget before it is added to
5154  * a container with gtk_widget_set_parent(), to avoid mapping
5155  * children unnecessary before immediately unmapping them. However
5156  * it will be reset to its default state of %TRUE when the widget
5157  * is removed from a container.
5158  * 
5159  * Note that changing the child visibility of a widget does not
5160  * queue a resize on the widget. Most of the time, the size of
5161  * a widget is computed from all visible children, whether or
5162  * not they are mapped. If this is not the case, the container
5163  * can queue a resize itself.
5164  *
5165  * This function is only useful for container implementations and
5166  * never should be called by an application.
5167  **/
5168 void
5169 gtk_widget_set_child_visible (GtkWidget *widget,
5170                               gboolean   is_visible)
5171 {
5172   g_return_if_fail (GTK_IS_WIDGET (widget));
5173   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5174
5175   g_object_ref (widget);
5176
5177   if (is_visible)
5178     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5179   else
5180     {
5181       GtkWidget *toplevel;
5182       
5183       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5184
5185       toplevel = gtk_widget_get_toplevel (widget);
5186       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5187         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5188     }
5189
5190   if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5191     {
5192       if (GTK_WIDGET_MAPPED (widget->parent) &&
5193           GTK_WIDGET_CHILD_VISIBLE (widget) &&
5194           GTK_WIDGET_VISIBLE (widget))
5195         gtk_widget_map (widget);
5196       else
5197         gtk_widget_unmap (widget);
5198     }
5199
5200   g_object_unref (widget);
5201 }
5202
5203 /**
5204  * gtk_widget_get_child_visible:
5205  * @widget: a #GtkWidget
5206  * 
5207  * Gets the value set with gtk_widget_set_child_visible().
5208  * If you feel a need to use this function, your code probably
5209  * needs reorganization. 
5210  *
5211  * This function is only useful for container implementations and
5212  * never should be called by an application.
5213  *
5214  * Return value: %TRUE if the widget is mapped with the parent.
5215  **/
5216 gboolean
5217 gtk_widget_get_child_visible (GtkWidget *widget)
5218 {
5219   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5220   
5221   return GTK_WIDGET_CHILD_VISIBLE (widget);
5222 }
5223
5224 static GdkScreen *
5225 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5226 {
5227   GtkWidget *toplevel;
5228   
5229   toplevel = gtk_widget_get_toplevel (widget);
5230
5231   if (GTK_WIDGET_TOPLEVEL (toplevel))
5232     {
5233       if (GTK_IS_WINDOW (toplevel))
5234         return GTK_WINDOW (toplevel)->screen;
5235       else if (GTK_IS_INVISIBLE (toplevel))
5236         return GTK_INVISIBLE (widget)->screen;
5237     }
5238
5239   return NULL;
5240 }
5241
5242 /**
5243  * gtk_widget_get_screen:
5244  * @widget: a #GtkWidget
5245  * 
5246  * Get the #GdkScreen from the toplevel window associated with
5247  * this widget. This function can only be called after the widget
5248  * has been added to a widget hierarchy with a #GtkWindow
5249  * at the top.
5250  *
5251  * In general, you should only create screen specific
5252  * resources when a widget has been realized, and you should
5253  * free those resources when the widget is unrealized.
5254  * 
5255  * Return value: the #GdkScreen for the toplevel for this widget.
5256  *
5257  * Since: 2.2
5258  **/
5259 GdkScreen*
5260 gtk_widget_get_screen (GtkWidget *widget)
5261 {
5262   GdkScreen *screen;
5263   
5264   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5265
5266   screen = gtk_widget_get_screen_unchecked (widget);
5267
5268   if (screen)
5269     return screen;
5270   else
5271     {
5272 #if 0
5273       g_warning (G_STRLOC ": Can't get associated screen"
5274                  " for a widget unless it is inside a toplevel GtkWindow\n"
5275                  " widget type is %s associated top level type is %s",
5276                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5277                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5278 #endif
5279       return gdk_screen_get_default ();
5280     }
5281 }
5282
5283 /**
5284  * gtk_widget_has_screen:
5285  * @widget: a #GtkWidget
5286  * 
5287  * Checks whether there is a #GdkScreen is associated with
5288  * this widget. All toplevel widgets have an associated
5289  * screen, and all widgets added into a heirarchy with a toplevel
5290  * window at the top.
5291  * 
5292  * Return value: %TRUE if there is a #GdkScreen associcated
5293  *   with the widget.
5294  *
5295  * Since: 2.2
5296  **/
5297 gboolean
5298 gtk_widget_has_screen (GtkWidget *widget)
5299 {
5300   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5301
5302   return (gtk_widget_get_screen_unchecked (widget) != NULL);
5303 }
5304
5305 /**
5306  * gtk_widget_get_display:
5307  * @widget: a #GtkWidget
5308  * 
5309  * Get the #GdkDisplay for the toplevel window associated with
5310  * this widget. This function can only be called after the widget
5311  * has been added to a widget hierarchy with a #GtkWindow at the top.
5312  *
5313  * In general, you should only create display specific
5314  * resources when a widget has been realized, and you should
5315  * free those resources when the widget is unrealized.
5316  * 
5317  * Return value: the #GdkDisplay for the toplevel for this widget.
5318  *
5319  * Since: 2.2
5320  **/
5321 GdkDisplay*
5322 gtk_widget_get_display (GtkWidget *widget)
5323 {
5324   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5325   
5326   return gdk_screen_get_display (gtk_widget_get_screen (widget));
5327 }
5328
5329 /**
5330  * gtk_widget_get_root_window:
5331  * @widget: a #GtkWidget
5332  * 
5333  * Get the root window where this widget is located. This function can
5334  * only be called after the widget has been added to a widget
5335  * heirarchy with #GtkWindow at the top.
5336  *
5337  * The root window is useful for such purposes as creating a popup
5338  * #GdkWindow associated with the window. In general, you should only
5339  * create display specific resources when a widget has been realized,
5340  * and you should free those resources when the widget is unrealized.
5341  * 
5342  * Return value: the #GdkWindow root window for the toplevel for this widget.
5343  *
5344  * Since: 2.2
5345  **/
5346 GdkWindow*
5347 gtk_widget_get_root_window (GtkWidget *widget)
5348 {
5349   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5350
5351   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5352 }
5353
5354 /**
5355  * gtk_widget_get_parent_window:
5356  * @widget: a #GtkWidget.
5357  * @returns: the parent window of @widget.
5358  * 
5359  * Gets @widget's parent window.
5360  **/
5361 GdkWindow *
5362 gtk_widget_get_parent_window   (GtkWidget           *widget)
5363 {
5364   GdkWindow *parent_window;
5365
5366   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5367   g_return_val_if_fail (widget->parent != NULL, NULL);
5368   
5369   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5370
5371   return (parent_window != NULL) ? parent_window : widget->parent->window;
5372 }
5373
5374 /**
5375  * gtk_widget_child_focus:
5376  * @widget: a #GtkWidget
5377  * @direction: direction of focus movement
5378  *
5379  * This function is used by custom widget implementations; if you're
5380  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5381  * to a particular widget, and gtk_container_set_focus_chain() to
5382  * change the focus tab order. So you may want to investigate those
5383  * functions instead.
5384  * 
5385  * gtk_widget_child_focus() is called by containers as the user moves
5386  * around the window using keyboard shortcuts. @direction indicates
5387  * what kind of motion is taking place (up, down, left, right, tab
5388  * forward, tab backward).  gtk_widget_child_focus() invokes the
5389  * "focus" signal on #GtkWidget; widgets override the default handler
5390  * for this signal in order to implement appropriate focus behavior.
5391  *
5392  * The "focus" default handler for a widget should return %TRUE if
5393  * moving in @direction left the focus on a focusable location inside
5394  * that widget, and %FALSE if moving in @direction moved the focus
5395  * outside the widget. If returning %TRUE, widgets normally
5396  * call gtk_widget_grab_focus() to place the focus accordingly;
5397  * if returning %FALSE, they don't modify the current focus location.
5398  * 
5399  * This function replaces gtk_container_focus() from GTK+ 1.2.  It was
5400  * necessary to check that the child was visible, sensitive, and
5401  * focusable before calling
5402  * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5403  * the widget is not currently in a focusable state, so there's no
5404  * need for those checks.
5405  * 
5406  * Return value: %TRUE if focus ended up inside @widget
5407  **/
5408 gboolean
5409 gtk_widget_child_focus (GtkWidget       *widget,
5410                         GtkDirectionType direction)
5411 {
5412   gboolean return_val;
5413
5414   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5415
5416   if (!GTK_WIDGET_VISIBLE (widget) ||
5417       !GTK_WIDGET_IS_SENSITIVE (widget))
5418     return FALSE;
5419
5420   /* child widgets must set CAN_FOCUS, containers
5421    * don't have to though.
5422    */
5423   if (!GTK_IS_CONTAINER (widget) &&
5424       !GTK_WIDGET_CAN_FOCUS (widget))
5425     return FALSE;
5426   
5427   g_signal_emit (widget,
5428                  widget_signals[FOCUS],
5429                  0,
5430                  direction, &return_val);
5431
5432   return return_val;
5433 }
5434
5435 /**
5436  * gtk_widget_set_uposition:
5437  * @widget: a #GtkWidget
5438  * @x: x position; -1 to unset x; -2 to leave x unchanged
5439  * @y: y position; -1 to unset y; -2 to leave y unchanged
5440  * 
5441  *
5442  * Sets the position of a widget. The funny "u" in the name comes from
5443  * the "user position" hint specified by the X Window System, and
5444  * exists for legacy reasons. This function doesn't work if a widget
5445  * is inside a container; it's only really useful on #GtkWindow.
5446  *
5447  * Don't use this function to center dialogs over the main application
5448  * window; most window managers will do the centering on your behalf
5449  * if you call gtk_window_set_transient_for(), and it's really not
5450  * possible to get the centering to work correctly in all cases from
5451  * application code. But if you insist, use gtk_window_set_position()
5452  * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5453  * manually.
5454  *
5455  * Note that although @x and @y can be individually unset, the position
5456  * is not honoured unless both @x and @y are set.
5457  **/
5458 void
5459 gtk_widget_set_uposition (GtkWidget *widget,
5460                           gint       x,
5461                           gint       y)
5462 {
5463   /* FIXME this function is the only place that aux_info->x and
5464    * aux_info->y are even used I believe, and this function is
5465    * deprecated. Should be cleaned up.
5466    *
5467    * (Actually, size_allocate uses them) -Yosh
5468    */
5469   
5470   GtkWidgetAuxInfo *aux_info;
5471   
5472   g_return_if_fail (GTK_IS_WIDGET (widget));
5473   
5474   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5475   
5476   if (x > -2)
5477     {
5478       if (x == -1)
5479         aux_info->x_set = FALSE;
5480       else
5481         {
5482           aux_info->x_set = TRUE;
5483           aux_info->x = x;
5484         }
5485     }
5486
5487   if (y > -2)
5488     {
5489       if (y == -1)
5490         aux_info->y_set = FALSE;
5491       else
5492         {
5493           aux_info->y_set = TRUE;
5494           aux_info->y = y;
5495         }
5496     }
5497
5498   if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5499     _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5500   
5501   if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5502     gtk_widget_size_allocate (widget, &widget->allocation);
5503 }
5504
5505 static void
5506 gtk_widget_set_usize_internal (GtkWidget *widget,
5507                                gint       width,
5508                                gint       height)
5509 {
5510   GtkWidgetAuxInfo *aux_info;
5511   gboolean changed = FALSE;
5512   
5513   g_return_if_fail (GTK_IS_WIDGET (widget));
5514   
5515   g_object_freeze_notify (G_OBJECT (widget));
5516
5517   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5518   
5519   if (width > -2 && aux_info->width != width)
5520     {
5521       g_object_notify (G_OBJECT (widget), "width_request");
5522       aux_info->width = width;
5523       changed = TRUE;
5524     }
5525   if (height > -2 && aux_info->height != height)
5526     {
5527       g_object_notify (G_OBJECT (widget), "height_request");  
5528       aux_info->height = height;
5529       changed = TRUE;
5530     }
5531   
5532   if (GTK_WIDGET_VISIBLE (widget) && changed)
5533     gtk_widget_queue_resize (widget);
5534
5535   g_object_thaw_notify (G_OBJECT (widget));
5536 }
5537
5538 /**
5539  * gtk_widget_set_usize:
5540  * @widget: a #GtkWidget
5541  * @width: minimum width, or -1 to unset
5542  * @height: minimum height, or -1 to unset
5543  *
5544  * Sets the minimum size of a widget; that is, the widget's size
5545  * request will be @width by @height. You can use this function to
5546  * force a widget to be either larger or smaller than it is. The
5547  * strange "usize" name dates from the early days of GTK+, and derives
5548  * from X Window System terminology. In many cases,
5549  * gtk_window_set_default_size() is a better choice for toplevel
5550  * windows than this function; setting the default size will still
5551  * allow users to shrink the window. Setting the usize will force them
5552  * to leave the window at least as large as the usize. When dealing
5553  * with window sizes, gtk_window_set_geometry_hints() can be a useful
5554  * function as well.
5555  * 
5556  * Note the inherent danger of setting any fixed size - themes,
5557  * translations into other languages, different fonts, and user action
5558  * can all change the appropriate size for a given widget. So, it's
5559  * basically impossible to hardcode a size that will always be
5560  * correct.
5561  * 
5562  * @Deprecated: Use gtk_widget_set_size_request() instead.
5563  **/
5564 void
5565 gtk_widget_set_usize (GtkWidget *widget,
5566                       gint       width,
5567                       gint       height)
5568 {
5569   g_return_if_fail (GTK_IS_WIDGET (widget));
5570   
5571   gtk_widget_set_usize_internal (widget, width, height);
5572 }
5573
5574 /**
5575  * gtk_widget_set_size_request:
5576  * @widget: a #GtkWidget
5577  * @width: width @widget should request, or -1 to unset
5578  * @height: height @widget should request, or -1 to unset
5579  *
5580  * Sets the minimum size of a widget; that is, the widget's size
5581  * request will be @width by @height. You can use this function to
5582  * force a widget to be either larger or smaller than it normally
5583  * would be.
5584  *
5585  * In most cases, gtk_window_set_default_size() is a better choice for
5586  * toplevel windows than this function; setting the default size will
5587  * still allow users to shrink the window. Setting the size request
5588  * will force them to leave the window at least as large as the size
5589  * request. When dealing with window sizes,
5590  * gtk_window_set_geometry_hints() can be a useful function as well.
5591  * 
5592  * Note the inherent danger of setting any fixed size - themes,
5593  * translations into other languages, different fonts, and user action
5594  * can all change the appropriate size for a given widget. So, it's
5595  * basically impossible to hardcode a size that will always be
5596  * correct.
5597  *
5598  * The size request of a widget is the smallest size a widget can
5599  * accept while still functioning well and drawing itself correctly.
5600  * However in some strange cases a widget may be allocated less than
5601  * its requested size, and in many cases a widget may be allocated more
5602  * space than it requested.
5603  *
5604  * If the size request in a given direction is -1 (unset), then
5605  * the "natural" size request of the widget will be used instead.
5606  *
5607  * Widgets can't actually be allocated a size less than 1 by 1, but
5608  * you can pass 0,0 to this function to mean "as small as possible."
5609  **/
5610 void
5611 gtk_widget_set_size_request (GtkWidget *widget,
5612                              gint       width,
5613                              gint       height)
5614 {
5615   g_return_if_fail (GTK_IS_WIDGET (widget));
5616   g_return_if_fail (width >= -1);
5617   g_return_if_fail (height >= -1);
5618
5619   if (width == 0)
5620     width = 1;
5621   if (height == 0)
5622     height = 1;
5623   
5624   gtk_widget_set_usize_internal (widget, width, height);
5625 }
5626
5627
5628 /**
5629  * gtk_widget_get_size_request:
5630  * @widget: a #GtkWidget
5631  * @width: return location for width, or %NULL
5632  * @height: return location for height, or %NULL
5633  *
5634  * Gets the size request that was explicitly set for the widget using
5635  * gtk_widget_set_size_request().  A value of -1 stored in @width or
5636  * @height indicates that that dimension has not been set explicitly
5637  * and the natural requisition of the widget will be used intead. See
5638  * gtk_widget_set_size_request(). To get the size a widget will
5639  * actually use, call gtk_widget_size_request() instead of
5640  * this function.
5641  * 
5642  **/
5643  
5644 void
5645 gtk_widget_get_size_request (GtkWidget *widget,
5646                              gint      *width,
5647                              gint      *height)
5648 {
5649   GtkWidgetAuxInfo *aux_info;
5650
5651   g_return_if_fail (GTK_IS_WIDGET (widget));
5652
5653   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5654
5655   if (width)
5656     *width = aux_info ? aux_info->width : -1;
5657
5658   if (height)
5659     *height = aux_info ? aux_info->height : -1;
5660 }
5661
5662 /**
5663  * gtk_widget_set_events:
5664  * @widget: a #GtkWidget
5665  * @events: event mask
5666  *
5667  * Sets the event mask (see #GdkEventMask) for a widget. The event
5668  * mask determines which events a widget will receive. Keep in mind
5669  * that different widgets have different default event masks, and by
5670  * changing the event mask you may disrupt a widget's functionality,
5671  * so be careful. This function must be called while a widget is
5672  * unrealized. Consider gtk_widget_add_events() for widgets that are
5673  * already realized, or if you want to preserve the existing event
5674  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5675  * to get events on those widgets, place them inside a #GtkEventBox
5676  * and receive events on the event box.
5677  * 
5678  **/
5679 void
5680 gtk_widget_set_events (GtkWidget *widget,
5681                        gint       events)
5682 {
5683   gint *eventp;
5684   
5685   g_return_if_fail (GTK_IS_WIDGET (widget));
5686   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5687   
5688   eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5689   
5690   if (events)
5691     {
5692       if (!eventp)
5693         eventp = g_new (gint, 1);
5694       
5695       *eventp = events;
5696       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5697     }
5698   else if (eventp)
5699     {
5700       g_free (eventp);
5701       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5702     }
5703
5704   g_object_notify (G_OBJECT (widget), "events");
5705 }
5706
5707 /**
5708  * gtk_widget_add_events:
5709  * @widget: a #GtkWidget
5710  * @events: an event mask, see #GdkEventMask
5711  *
5712  * Adds the events in the bitfield @events to the event mask for
5713  * @widget. See gtk_widget_set_events() for details.
5714  * 
5715  **/
5716 void
5717 gtk_widget_add_events (GtkWidget *widget,
5718                        gint       events)
5719 {
5720   gint *eventp;
5721   
5722   g_return_if_fail (GTK_IS_WIDGET (widget));
5723
5724   eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5725   
5726   if (events)
5727     {
5728       if (!eventp)
5729         {
5730           eventp = g_new (gint, 1);
5731           *eventp = 0;
5732         }
5733       
5734       *eventp |= events;
5735       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5736     }
5737   else if (eventp)
5738     {
5739       g_free (eventp);
5740       g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5741     }
5742
5743   if (GTK_WIDGET_REALIZED (widget))
5744     {
5745       if (GTK_WIDGET_NO_WINDOW (widget))
5746         {
5747           GList *children = gdk_window_get_children (widget->window);
5748           GList *tmp_list = children;
5749
5750           while (tmp_list)
5751             {
5752               GdkWindow *window = tmp_list->data;
5753               gpointer user_data;
5754
5755               gdk_window_get_user_data (window, &user_data);
5756               if (user_data == widget)
5757                 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5758               tmp_list = tmp_list->next;
5759             }
5760
5761           g_list_free (children);
5762         }
5763       else
5764         {
5765           gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5766         }
5767     }
5768
5769   g_object_notify (G_OBJECT (widget), "events");
5770 }
5771
5772 /**
5773  * gtk_widget_set_extension_events:
5774  * @widget: a #GtkWidget
5775  * @mode: bitfield of extension events to receive
5776  *
5777  * Sets the extension events mask to @mode. See #GdkExtensionMode
5778  * and gdk_input_set_extension_events().
5779  * 
5780  **/
5781 void
5782 gtk_widget_set_extension_events (GtkWidget *widget,
5783                                  GdkExtensionMode mode)
5784 {
5785   GdkExtensionMode *modep;
5786   
5787   g_return_if_fail (GTK_IS_WIDGET (widget));
5788   
5789   modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5790   
5791   if (!modep)
5792     modep = g_new (GdkExtensionMode, 1);
5793   
5794   *modep = mode;
5795   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5796   g_object_notify (G_OBJECT (widget), "extension_events");
5797 }
5798
5799 /**
5800  * gtk_widget_get_toplevel:
5801  * @widget: a #GtkWidget
5802  * 
5803  * This function returns the topmost widget in the container hierarchy
5804  * @widget is a part of. If @widget has no parent widgets, it will be
5805  * returned as the topmost widget. No reference will be added to the
5806  * returned widget; it should not be unreferenced.
5807  *
5808  * Note the difference in behavior vs. gtk_widget_get_ancestor();
5809  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
5810  * would return
5811  * %NULL if @widget wasn't inside a toplevel window, and if the
5812  * window was inside a #GtkWindow-derived widget which was in turn
5813  * inside the toplevel #GtkWindow. While the second case may
5814  * seem unlikely, it actually happens when a #GtkPlug is embedded
5815  * inside a #GtkSocket within the same application.
5816  * 
5817  * To reliably find the toplevel #GtkWindow, use
5818  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5819  * is set on the result.
5820  * <informalexample><programlisting>
5821  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5822  *  if (GTK_WIDGET_TOPLEVEL (toplevel))
5823  *    {
5824  *      [ Perform action on toplevel. ]
5825  *    }
5826  * </programlisting></informalexample>
5827  *
5828  * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5829  **/
5830 GtkWidget*
5831 gtk_widget_get_toplevel (GtkWidget *widget)
5832 {
5833   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5834   
5835   while (widget->parent)
5836     widget = widget->parent;
5837   
5838   return widget;
5839 }
5840
5841 /**
5842  * gtk_widget_get_ancestor:
5843  * @widget: a #GtkWidget
5844  * @widget_type: ancestor type
5845  * 
5846  * Gets the first ancestor of @widget with type @widget_type. For example,
5847  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the 
5848  * first #GtkBox that's
5849  * an ancestor of @widget. No reference will be added to the returned widget;
5850  * it should not be unreferenced. See note about checking for a toplevel
5851  * #GtkWindow in the docs for gtk_widget_get_toplevel().
5852  * 
5853  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
5854  * considers @widget to be an ancestor of itself.
5855  *
5856  * Return value: the ancestor widget, or %NULL if not found
5857  **/
5858 GtkWidget*
5859 gtk_widget_get_ancestor (GtkWidget *widget,
5860                          GType      widget_type)
5861 {
5862   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5863   
5864   while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5865     widget = widget->parent;
5866   
5867   if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5868     return NULL;
5869   
5870   return widget;
5871 }
5872
5873 /**
5874  * gtk_widget_get_colormap:
5875  * @widget: a #GtkWidget
5876  * 
5877  * Gets the colormap that will be used to render @widget. No reference will
5878  * be added to the returned colormap; it should not be unreferenced.
5879  * 
5880  * Return value: the colormap used by @widget
5881  **/
5882 GdkColormap*
5883 gtk_widget_get_colormap (GtkWidget *widget)
5884 {
5885   GdkColormap *colormap;
5886   GtkWidget *tmp_widget;
5887   
5888   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5889   
5890   if (widget->window)
5891     {
5892       colormap = gdk_drawable_get_colormap (widget->window);
5893       /* If window was destroyed previously, we'll get NULL here */
5894       if (colormap)
5895         return colormap;
5896     }
5897
5898   tmp_widget = widget;
5899   while (tmp_widget)
5900     {
5901       colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5902       if (colormap)
5903         return colormap;
5904
5905       tmp_widget= tmp_widget->parent;
5906     }
5907
5908   return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5909 }
5910
5911 /**
5912  * gtk_widget_get_visual:
5913  * @widget: a #GtkWidget
5914  * 
5915  * Gets the visual that will be used to render @widget.
5916  * 
5917  * Return value: the visual for @widget
5918  **/
5919 GdkVisual*
5920 gtk_widget_get_visual (GtkWidget *widget)
5921 {
5922   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5923
5924   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5925 }
5926
5927 /**
5928  * gtk_widget_get_settings:
5929  * @widget: a #GtkWidget
5930  * 
5931  * Gets the settings object holding the settings (global property
5932  * settings, RC file information, etc) used for this widget.
5933  *
5934  * Note that this function can only be called when the #GtkWidget
5935  * is attached to a toplevel, since the settings object is specific
5936  * to a particular #GdkScreen.
5937  * 
5938  * Return value: the relevant #GtkSettings object
5939  **/
5940 GtkSettings*
5941 gtk_widget_get_settings (GtkWidget *widget)
5942 {
5943   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5944   
5945   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
5946 }
5947
5948 /**
5949  * gtk_widget_set_colormap:
5950  * @widget: a #GtkWidget
5951  * @colormap: a colormap
5952  *
5953  * Sets the colormap for the widget to the given value. Widget must not
5954  * have been previously realized. This probably should only be used
5955  * from an <function>init()</function> function (i.e. from the constructor 
5956  * for the widget).
5957  * 
5958  **/
5959 void
5960 gtk_widget_set_colormap (GtkWidget   *widget,
5961                          GdkColormap *colormap)
5962 {
5963   g_return_if_fail (GTK_IS_WIDGET (widget));
5964   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5965   g_return_if_fail (GDK_IS_COLORMAP (colormap));
5966
5967   g_object_ref (colormap);
5968   
5969   g_object_set_qdata_full (G_OBJECT (widget), 
5970                            quark_colormap,
5971                            colormap,
5972                            g_object_unref);
5973 }
5974
5975 /**
5976  * gtk_widget_get_events:
5977  * @widget: a #GtkWidget
5978  * 
5979  * Returns the event mask for the widget (a bitfield containing flags
5980  * from the #GdkEventMask enumeration). These are the events that the widget
5981  * will receive.
5982  * 
5983  * Return value: event mask for @widget
5984  **/
5985 gint
5986 gtk_widget_get_events (GtkWidget *widget)
5987 {
5988   gint *events;
5989   
5990   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5991   
5992   events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5993   if (events)
5994     return *events;
5995   
5996   return 0;
5997 }
5998
5999 /**
6000  * gtk_widget_get_extension_events:
6001  * @widget: a #GtkWidget
6002  * 
6003  * Retrieves the extension events the widget will receive; see
6004  * gdk_input_set_extension_events().
6005  * 
6006  * Return value: extension events for @widget
6007  **/
6008 GdkExtensionMode
6009 gtk_widget_get_extension_events (GtkWidget *widget)
6010 {
6011   GdkExtensionMode *mode;
6012   
6013   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6014   
6015   mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6016   if (mode)
6017     return *mode;
6018   
6019   return 0;
6020 }
6021
6022 /**
6023  * gtk_widget_get_pointer:
6024  * @widget: a #GtkWidget
6025  * @x: return location for the X coordinate, or %NULL
6026  * @y: return location for the Y coordinate, or %NULL
6027  *
6028  * Obtains the location of the mouse pointer in widget coordinates.
6029  * Widget coordinates are a bit odd; for historical reasons, they are
6030  * defined as @widget->window coordinates for widgets that are not
6031  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6032  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6033  * 
6034  **/
6035 void
6036 gtk_widget_get_pointer (GtkWidget *widget,
6037                         gint      *x,
6038                         gint      *y)
6039 {
6040   g_return_if_fail (GTK_IS_WIDGET (widget));
6041   
6042   if (x)
6043     *x = -1;
6044   if (y)
6045     *y = -1;
6046   
6047   if (GTK_WIDGET_REALIZED (widget))
6048     {
6049       gdk_window_get_pointer (widget->window, x, y, NULL);
6050       
6051       if (GTK_WIDGET_NO_WINDOW (widget))
6052         {
6053           if (x)
6054             *x -= widget->allocation.x;
6055           if (y)
6056             *y -= widget->allocation.y;
6057         }
6058     }
6059 }
6060
6061 /**
6062  * gtk_widget_is_ancestor:
6063  * @widget: a #GtkWidget
6064  * @ancestor: another #GtkWidget
6065  * 
6066  * Determines whether @widget is somewhere inside @ancestor, possibly with
6067  * intermediate containers.
6068  * 
6069  * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6070  **/
6071 gboolean
6072 gtk_widget_is_ancestor (GtkWidget *widget,
6073                         GtkWidget *ancestor)
6074 {
6075   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6076   g_return_val_if_fail (ancestor != NULL, FALSE);
6077   
6078   while (widget)
6079     {
6080       if (widget->parent == ancestor)
6081         return TRUE;
6082       widget = widget->parent;
6083     }
6084   
6085   return FALSE;
6086 }
6087
6088 static GQuark quark_composite_name = 0;
6089
6090 /**
6091  * gtk_widget_set_composite_name:
6092  * @widget: a #GtkWidget.
6093  * @name: the name to set.
6094  * 
6095  * Sets a widgets composite name. The widget must be
6096  * a composite child of its parent; see gtk_widget_push_composite_child().
6097  **/
6098 void
6099 gtk_widget_set_composite_name (GtkWidget   *widget,
6100                                const gchar *name)
6101 {
6102   g_return_if_fail (GTK_IS_WIDGET (widget));
6103   g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6104   g_return_if_fail (name != NULL);
6105
6106   if (!quark_composite_name)
6107     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6108
6109   g_object_set_qdata_full (G_OBJECT (widget),
6110                            quark_composite_name,
6111                            g_strdup (name),
6112                            g_free);
6113 }
6114
6115 /**
6116  * gtk_widget_get_composite_name:
6117  * @widget: a #GtkWidget.
6118  * @returns: the composite name of @widget, or %NULL if @widget is not
6119  *   a composite child. The string should not be freed when it is no 
6120  *   longer needed.
6121  *
6122  * Obtains the composite name of a widget. 
6123  **/
6124 gchar*
6125 gtk_widget_get_composite_name (GtkWidget *widget)
6126 {
6127   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6128
6129   if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6130     return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6131                                                widget);
6132   else
6133     return NULL;
6134 }
6135
6136 /**
6137  * gtk_widget_push_composite_child:
6138  * 
6139  * Makes all newly-created widgets as composite children until
6140  * the corresponding gtk_widget_pop_composite_child() call.
6141  * 
6142  * A composite child is a child that's an implementation detail of the
6143  * container it's inside and should not be visible to people using the
6144  * container. Composite children aren't treated differently by GTK (but
6145  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
6146  * builders might want to treat them in a different way.
6147  * 
6148  * Here is a simple example:
6149  * <informalexample><programlisting>
6150  *   gtk_widget_push_composite_child (<!-- -->);
6151  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6152  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6153  *   gtk_widget_pop_composite_child (<!-- -->);
6154  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
6155  *                          GTK_WIDGET (scrolled_window));
6156  *   g_object_ref (scrolled_window->hscrollbar);
6157  * </programlisting></informalexample>
6158  **/
6159 void
6160 gtk_widget_push_composite_child (void)
6161 {
6162   composite_child_stack++;
6163 }
6164
6165 /**
6166  * gtk_widget_pop_composite_child:
6167  *
6168  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6169  **/ 
6170 void
6171 gtk_widget_pop_composite_child (void)
6172 {
6173   if (composite_child_stack)
6174     composite_child_stack--;
6175 }
6176
6177 /**
6178  * gtk_widget_push_colormap:
6179  * @cmap: a #GdkColormap
6180  *
6181  * Pushes @cmap onto a global stack of colormaps; the topmost
6182  * colormap on the stack will be used to create all widgets.
6183  * Remove @cmap with gtk_widget_pop_colormap(). There's little
6184  * reason to use this function.
6185  * 
6186  **/
6187 void
6188 gtk_widget_push_colormap (GdkColormap *cmap)
6189 {
6190   g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6191
6192   colormap_stack = g_slist_prepend (colormap_stack, cmap);
6193 }
6194
6195 /**
6196  * gtk_widget_pop_colormap:
6197  *
6198  * Removes a colormap pushed with gtk_widget_push_colormap().
6199  * 
6200  **/
6201 void
6202 gtk_widget_pop_colormap (void)
6203 {
6204   if (colormap_stack)
6205     colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6206 }
6207
6208 /**
6209  * gtk_widget_set_default_colormap:
6210  * @colormap: a #GdkColormap
6211  * 
6212  * Sets the default colormap to use when creating widgets.
6213  * gtk_widget_push_colormap() is a better function to use if
6214  * you only want to affect a few widgets, rather than all widgets.
6215  **/
6216 void
6217 gtk_widget_set_default_colormap (GdkColormap *colormap)
6218 {
6219   g_return_if_fail (GDK_IS_COLORMAP (colormap));
6220   
6221   gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6222                                    colormap);
6223 }
6224
6225 /**
6226  * gtk_widget_get_default_colormap:
6227  * 
6228  * Obtains the default colormap used to create widgets.
6229  * 
6230  * Return value: default widget colormap
6231  **/
6232 GdkColormap*
6233 gtk_widget_get_default_colormap (void)
6234 {
6235   return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6236 }
6237
6238 /**
6239  * gtk_widget_get_default_visual:
6240  * 
6241  * Obtains the visual of the default colormap. Not really useful;
6242  * used to be useful before gdk_colormap_get_visual() existed.
6243  * 
6244  * Return value: visual of the default colormap
6245  **/
6246 GdkVisual*
6247 gtk_widget_get_default_visual (void)
6248 {
6249   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6250 }
6251
6252 static void
6253 gtk_widget_emit_direction_changed (GtkWidget        *widget,
6254                                    GtkTextDirection  old_dir)
6255 {
6256   PangoContext *context = gtk_widget_peek_pango_context (widget);
6257
6258   if (context)
6259     pango_context_set_base_dir (context,
6260                                 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6261                                   PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6262   
6263   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6264 }
6265
6266 /**
6267  * gtk_widget_set_direction:
6268  * @widget: a #GtkWidget
6269  * @dir:    the new direction
6270  * 
6271  * Sets the reading direction on a particular widget. This direction
6272  * controls the primary direction for widgets containing text,
6273  * and also the direction in which the children of a container are
6274  * packed. The ability to set the direction is present in order
6275  * so that correct localization into languages with right-to-left
6276  * reading directions can be done. Generally, applications will
6277  * let the default reading direction present, except for containers
6278  * where the containers are arranged in an order that is explicitely
6279  * visual rather than logical (such as buttons for text justification).
6280  *
6281  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6282  * set by gtk_widget_set_default_direction() will be used.
6283  **/
6284 void
6285 gtk_widget_set_direction (GtkWidget        *widget,
6286                           GtkTextDirection  dir)
6287 {
6288   GtkTextDirection old_dir;
6289   
6290   g_return_if_fail (GTK_IS_WIDGET (widget));
6291   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6292
6293   old_dir = gtk_widget_get_direction (widget);
6294   
6295   if (dir == GTK_TEXT_DIR_NONE)
6296     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6297   else
6298     {
6299       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6300       if (dir == GTK_TEXT_DIR_LTR)
6301         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6302       else
6303         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6304     }
6305
6306   if (old_dir != gtk_widget_get_direction (widget))
6307     gtk_widget_emit_direction_changed (widget, old_dir);
6308 }
6309
6310 /**
6311  * gtk_widget_get_direction:
6312  * @widget: a #GtkWidget
6313  * 
6314  * Gets the reading direction for a particular widget. See
6315  * gtk_widget_set_direction().
6316  * 
6317  * Return value: the reading direction for the widget.
6318  **/
6319 GtkTextDirection
6320 gtk_widget_get_direction (GtkWidget *widget)
6321 {
6322   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6323   
6324   if (GTK_WIDGET_DIRECTION_SET (widget))
6325     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6326   else
6327     return gtk_default_direction;
6328 }
6329
6330 static void
6331 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6332 {
6333   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6334
6335   g_object_ref (widget);
6336   
6337   if (!GTK_WIDGET_DIRECTION_SET (widget))
6338     gtk_widget_emit_direction_changed (widget, old_dir);
6339   
6340   if (GTK_IS_CONTAINER (widget))
6341     gtk_container_forall (GTK_CONTAINER (widget),
6342                           gtk_widget_set_default_direction_recurse,
6343                           data);
6344
6345   g_object_unref (widget);
6346 }
6347
6348 /**
6349  * gtk_widget_set_default_direction:
6350  * @dir: the new default direction. This cannot be
6351  *        %GTK_TEXT_DIR_NONE.
6352  * 
6353  * Sets the default reading direction for widgets where the
6354  * direction has not been explicitly set by gtk_widget_set_direction().
6355  **/
6356 void
6357 gtk_widget_set_default_direction (GtkTextDirection dir)
6358 {
6359   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6360
6361   if (dir != gtk_default_direction)
6362     {
6363       GList *toplevels, *tmp_list;
6364       GtkTextDirection old_dir = gtk_default_direction;
6365       
6366       gtk_default_direction = dir;
6367
6368       tmp_list = toplevels = gtk_window_list_toplevels ();
6369       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6370       
6371       while (tmp_list)
6372         {
6373           gtk_widget_set_default_direction_recurse (tmp_list->data,
6374                                                     GUINT_TO_POINTER (old_dir));
6375           g_object_unref (tmp_list->data);
6376           tmp_list = tmp_list->next;
6377         }
6378
6379       g_list_free (toplevels);
6380     }
6381 }
6382
6383 /**
6384  * gtk_widget_get_default_direction:
6385  * 
6386  * Obtains the current default reading direction. See
6387  * gtk_widget_set_default_direction().
6388  *
6389  * Return value: the current default direction. 
6390  **/
6391 GtkTextDirection
6392 gtk_widget_get_default_direction (void)
6393 {
6394   return gtk_default_direction;
6395 }
6396
6397 static void
6398 gtk_widget_dispose (GObject *object)
6399 {
6400   GtkWidget *widget = GTK_WIDGET (object);
6401
6402   if (widget->parent)
6403     gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6404   else if (GTK_WIDGET_VISIBLE (widget))
6405     gtk_widget_hide (widget);
6406
6407   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6408   if (GTK_WIDGET_REALIZED (widget))
6409     gtk_widget_unrealize (widget);
6410   
6411   G_OBJECT_CLASS (parent_class)->dispose (object);
6412 }
6413
6414 static void
6415 gtk_widget_real_destroy (GtkObject *object)
6416 {
6417   /* gtk_object_destroy() will already hold a refcount on object */
6418   GtkWidget *widget = GTK_WIDGET (object);
6419
6420   /* wipe accelerator closures (keep order) */
6421   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6422   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6423
6424   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6425   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6426   
6427   gtk_grab_remove (widget);
6428   
6429   g_object_unref (widget->style);
6430   widget->style = gtk_widget_get_default_style ();
6431   g_object_ref (widget->style);
6432
6433   GTK_OBJECT_CLASS (parent_class)->destroy (object);
6434 }
6435
6436 static void
6437 gtk_widget_finalize (GObject *object)
6438 {
6439   GtkWidget *widget = GTK_WIDGET (object);
6440   GtkWidgetAuxInfo *aux_info;
6441   gint *events;
6442   GdkExtensionMode *mode;
6443   GtkAccessible *accessible;
6444   
6445   gtk_grab_remove (widget);
6446
6447   g_object_unref (widget->style);
6448   widget->style = NULL;
6449
6450   if (widget->name)
6451     g_free (widget->name);
6452   
6453   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6454   if (aux_info)
6455     gtk_widget_aux_info_destroy (aux_info);
6456   
6457   events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6458   if (events)
6459     g_free (events);
6460   
6461   mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6462   if (mode)
6463     g_free (mode);
6464
6465   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6466   if (accessible)
6467     g_object_unref (accessible);
6468
6469   G_OBJECT_CLASS (parent_class)->finalize (object);
6470 }
6471
6472 /*****************************************
6473  * gtk_widget_real_map:
6474  *
6475  *   arguments:
6476  *
6477  *   results:
6478  *****************************************/
6479
6480 static void
6481 gtk_widget_real_map (GtkWidget *widget)
6482 {
6483   g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6484   
6485   if (!GTK_WIDGET_MAPPED (widget))
6486     {
6487       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6488       
6489       if (!GTK_WIDGET_NO_WINDOW (widget))
6490         gdk_window_show (widget->window);
6491     }
6492 }
6493
6494 /*****************************************
6495  * gtk_widget_real_unmap:
6496  *
6497  *   arguments:
6498  *
6499  *   results:
6500  *****************************************/
6501
6502 static void
6503 gtk_widget_real_unmap (GtkWidget *widget)
6504 {
6505   if (GTK_WIDGET_MAPPED (widget))
6506     {
6507       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6508
6509       if (!GTK_WIDGET_NO_WINDOW (widget))
6510         gdk_window_hide (widget->window);
6511     }
6512 }
6513
6514 /*****************************************
6515  * gtk_widget_real_realize:
6516  *
6517  *   arguments:
6518  *
6519  *   results:
6520  *****************************************/
6521
6522 static void
6523 gtk_widget_real_realize (GtkWidget *widget)
6524 {
6525   g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6526   
6527   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6528   if (widget->parent)
6529     {
6530       widget->window = gtk_widget_get_parent_window (widget);
6531       g_object_ref (widget->window);
6532     }
6533   widget->style = gtk_style_attach (widget->style, widget->window);
6534 }
6535
6536 /*****************************************
6537  * gtk_widget_real_unrealize:
6538  *
6539  *   arguments:
6540  *
6541  *   results:
6542  *****************************************/
6543
6544 static void
6545 gtk_widget_real_unrealize (GtkWidget *widget)
6546 {
6547   if (GTK_WIDGET_MAPPED (widget))
6548     gtk_widget_real_unmap (widget);
6549
6550   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6551
6552   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6553    */
6554
6555    /* We must do unrealize child widget BEFORE container widget.
6556     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6557     * So, unrealizing container widget bofore its children causes the problem 
6558     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6559     */
6560
6561   if (GTK_IS_CONTAINER (widget))
6562     gtk_container_forall (GTK_CONTAINER (widget),
6563                           (GtkCallback) gtk_widget_unrealize,
6564                           NULL);
6565
6566   gtk_style_detach (widget->style);
6567   if (!GTK_WIDGET_NO_WINDOW (widget))
6568     {
6569       gdk_window_set_user_data (widget->window, NULL);
6570       gdk_window_destroy (widget->window);
6571       widget->window = NULL;
6572     }
6573   else
6574     {
6575       g_object_unref (widget->window);
6576       widget->window = NULL;
6577     }
6578
6579   gtk_selection_remove_all (widget);
6580   
6581   GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6582 }
6583
6584 static void
6585 gtk_widget_real_size_request (GtkWidget         *widget,
6586                               GtkRequisition    *requisition)
6587 {
6588   requisition->width = widget->requisition.width;
6589   requisition->height = widget->requisition.height;
6590 }
6591
6592 /**
6593  * _gtk_widget_peek_colormap:
6594  * 
6595  * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6596  * 
6597  * Return value: the currently pushed colormap, or %NULL if there is none.
6598  **/
6599 GdkColormap*
6600 _gtk_widget_peek_colormap (void)
6601 {
6602   if (colormap_stack)
6603     return (GdkColormap*) colormap_stack->data;
6604   return NULL;
6605 }
6606
6607 static void
6608 gtk_widget_propagate_state (GtkWidget           *widget,
6609                             GtkStateData        *data)
6610 {
6611   guint8 old_state;
6612
6613   /* don't call this function with state==GTK_STATE_INSENSITIVE,
6614    * parent_sensitive==TRUE on a sensitive widget
6615    */
6616
6617   old_state = GTK_WIDGET_STATE (widget);
6618
6619   if (data->parent_sensitive)
6620     {
6621       GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6622
6623       if (GTK_WIDGET_IS_SENSITIVE (widget))
6624         {
6625           if (data->state_restoration)
6626             GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6627           else
6628             GTK_WIDGET_STATE (widget) = data->state;
6629         }
6630       else
6631         {
6632           GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6633           if (!data->state_restoration &&
6634               data->state != GTK_STATE_INSENSITIVE)
6635             GTK_WIDGET_SAVED_STATE (widget) = data->state;
6636         }
6637     }
6638   else
6639     {
6640       GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6641       if (!data->state_restoration)
6642         {
6643           if (data->state != GTK_STATE_INSENSITIVE)
6644             GTK_WIDGET_SAVED_STATE (widget) = data->state;
6645         }
6646       else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6647         GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6648       GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6649     }
6650
6651   if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6652     {
6653       GtkWidget *window;
6654
6655       window = gtk_widget_get_toplevel (widget);
6656       if (window && GTK_WIDGET_TOPLEVEL (window))
6657         gtk_window_set_focus (GTK_WINDOW (window), NULL);
6658     }
6659
6660   if (old_state != GTK_WIDGET_STATE (widget))
6661     {
6662       g_object_ref (widget);
6663       
6664       if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6665         gtk_grab_remove (widget);
6666       
6667       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6668       
6669       if (GTK_IS_CONTAINER (widget))
6670         {
6671           data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6672           data->state = GTK_WIDGET_STATE (widget);
6673           if (data->use_forall)
6674             gtk_container_forall (GTK_CONTAINER (widget),
6675                                   (GtkCallback) gtk_widget_propagate_state,
6676                                   data);
6677           else
6678             gtk_container_foreach (GTK_CONTAINER (widget),
6679                                    (GtkCallback) gtk_widget_propagate_state,
6680                                    data);
6681         }
6682       g_object_unref (widget);
6683     }
6684 }
6685
6686 /**
6687  * _gtk_widget_get_aux_info:
6688  * @widget: a #GtkWidget
6689  * @create: if %TRUE, create the structure if it doesn't exist
6690  * 
6691  * Get the #GtkWidgetAuxInfo structure for the widget.
6692  * 
6693  * Return value: the #GtkAuxInfo structure for the widget, or
6694  *    %NULL if @create is %FALSE and one doesn't already exist.
6695  **/
6696 GtkWidgetAuxInfo*
6697 _gtk_widget_get_aux_info (GtkWidget *widget,
6698                           gboolean   create)
6699 {
6700   GtkWidgetAuxInfo *aux_info;
6701   
6702   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6703   if (!aux_info && create)
6704     {
6705       if (!aux_info_mem_chunk)
6706         aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6707                                               sizeof (GtkWidgetAuxInfo),
6708                                               1024, G_ALLOC_AND_FREE);
6709       aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6710
6711       aux_info->width = -1;
6712       aux_info->height = -1;
6713       aux_info->x = 0;
6714       aux_info->y = 0;
6715       aux_info->x_set = FALSE;
6716       aux_info->y_set = FALSE;
6717       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6718     }
6719   
6720   return aux_info;
6721 }
6722
6723 /*****************************************
6724  * gtk_widget_aux_info_destroy:
6725  *
6726  *   arguments:
6727  *
6728  *   results:
6729  *****************************************/
6730
6731 static void
6732 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6733 {
6734   g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6735 }
6736
6737 static void
6738 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6739 {
6740   g_object_unref (info->shape_mask);
6741   g_free (info);
6742 }
6743
6744 /**
6745  * gtk_widget_shape_combine_mask: 
6746  * @widget: a #GtkWidget.
6747  * @shape_mask: shape to be added, or %NULL to remove an existing shape. 
6748  * @offset_x: X position of shape mask with respect to @window.
6749  * @offset_y: Y position of shape mask with respect to @window.
6750  * 
6751  * Sets a shape for this widget's GDK window. This allows for
6752  * transparent windows etc., see gdk_window_shape_combine_mask()
6753  * for more information.
6754  **/
6755 void
6756 gtk_widget_shape_combine_mask (GtkWidget *widget,
6757                                GdkBitmap *shape_mask,
6758                                gint       offset_x,
6759                                gint       offset_y)
6760 {
6761   GtkWidgetShapeInfo* shape_info;
6762   
6763   g_return_if_fail (GTK_IS_WIDGET (widget));
6764   /*  set_shape doesn't work on widgets without gdk window */
6765   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6766
6767   if (!shape_mask)
6768     {
6769       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6770       
6771       if (widget->window)
6772         gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6773       
6774       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6775     }
6776   else
6777     {
6778       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6779       
6780       shape_info = g_new (GtkWidgetShapeInfo, 1);
6781       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6782                                (GDestroyNotify) gtk_widget_shape_info_destroy);
6783       
6784       shape_info->shape_mask = g_object_ref (shape_mask);
6785       shape_info->offset_x = offset_x;
6786       shape_info->offset_y = offset_y;
6787       
6788       /* set shape if widget has a gdk window allready.
6789        * otherwise the shape is scheduled to be set by gtk_widget_realize.
6790        */
6791       if (widget->window)
6792         gdk_window_shape_combine_mask (widget->window, shape_mask,
6793                                        offset_x, offset_y);
6794     }
6795 }
6796
6797 static void
6798 gtk_reset_shapes_recurse (GtkWidget *widget,
6799                           GdkWindow *window)
6800 {
6801   gpointer data;
6802   GList *list;
6803
6804   gdk_window_get_user_data (window, &data);
6805   if (data != widget)
6806     return;
6807
6808   gdk_window_shape_combine_mask (window, NULL, 0, 0);
6809   for (list = gdk_window_peek_children (window); list; list = list->next)
6810     gtk_reset_shapes_recurse (widget, list->data);
6811 }
6812
6813 /**
6814  * gtk_widget_reset_shapes:
6815  * @widget: a #GtkWidget.
6816  *
6817  * Recursively resets the shape on this widget and its descendants.
6818  **/
6819 void
6820 gtk_widget_reset_shapes (GtkWidget *widget)
6821 {
6822   g_return_if_fail (GTK_IS_WIDGET (widget));
6823   g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6824
6825   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6826     gtk_reset_shapes_recurse (widget, widget->window);
6827 }
6828
6829 /**
6830  * gtk_widget_ref:
6831  * @widget: a #GtkWidget
6832  * 
6833  * Adds a reference to a widget. This function is exactly the same
6834  * as calling g_object_ref(), and exists mostly for historical
6835  * reasons. It can still be convenient to avoid casting a widget
6836  * to a #GObject, it saves a small amount of typing.
6837  * 
6838  * Return value: the widget that was referenced
6839  **/
6840 GtkWidget*
6841 gtk_widget_ref (GtkWidget *widget)
6842 {
6843   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6844
6845   return (GtkWidget*) g_object_ref ((GObject*) widget);
6846 }
6847
6848 /**
6849  * gtk_widget_unref:
6850  * @widget: a #GtkWidget
6851  *
6852  * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6853  * 
6854  **/
6855 void
6856 gtk_widget_unref (GtkWidget *widget)
6857 {
6858   g_return_if_fail (GTK_IS_WIDGET (widget));
6859
6860   g_object_unref ((GObject*) widget);
6861 }
6862
6863
6864 /* style properties
6865  */
6866
6867 /**
6868  * gtk_widget_class_install_style_property_parser:
6869  * @klass: a #GtkWidgetClass
6870  * @pspec: the #GParamSpec for the style property
6871  * @parser: the parser for the style property
6872  * 
6873  * Installs a style property on a widget class. 
6874  **/
6875 void
6876 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
6877                                                 GParamSpec         *pspec,
6878                                                 GtkRcPropertyParser parser)
6879 {
6880   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6881   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6882   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6883   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6884   
6885   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
6886     {
6887       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6888                  G_OBJECT_CLASS_NAME (klass),
6889                  pspec->name);
6890       return;
6891     }
6892
6893   g_param_spec_ref (pspec);
6894   g_param_spec_sink (pspec);
6895   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6896   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
6897 }
6898
6899 /**
6900  * gtk_widget_class_install_style_property:
6901  * @klass: a #GtkWidgetClass
6902  * @pspec: the #GParamSpec for the property
6903  * 
6904  * Installs a style property on a widget class. The parser for the
6905  * style property is determined by the value type of @pspec.
6906  **/
6907 void
6908 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
6909                                          GParamSpec     *pspec)
6910 {
6911   GtkRcPropertyParser parser;
6912
6913   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6914   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6915
6916   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6917
6918   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
6919 }
6920
6921 /**
6922  * gtk_widget_class_find_style_property:
6923  * @klass: a #GtkWidgetClass
6924  * @property_name: the name of the style property to find
6925  * @returns: the #GParamSpec of the style property or %NULL if @class has no
6926  *   style property with that name.
6927  *
6928  * Finds a style property of a widget class by name.
6929  *
6930  * Since: 2.2
6931  */
6932 GParamSpec*
6933 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
6934                                       const gchar    *property_name)
6935 {
6936   g_return_val_if_fail (property_name != NULL, NULL);
6937
6938   return g_param_spec_pool_lookup (style_property_spec_pool,
6939                                    property_name,
6940                                    G_OBJECT_CLASS_TYPE (klass),
6941                                    TRUE);
6942 }
6943
6944 /**
6945  * gtk_widget_class_list_style_properties:
6946  * @klass: a #GtkWidgetClass
6947  * @n_properties: location to return the number of style properties found
6948  * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
6949  *
6950  * Returns all style properties of a widget class.
6951  *
6952  * Since: 2.2
6953  */
6954 GParamSpec**
6955 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
6956                                         guint          *n_properties)
6957 {
6958   GParamSpec **pspecs;
6959   guint n;
6960
6961   pspecs = g_param_spec_pool_list (style_property_spec_pool,
6962                                    G_OBJECT_CLASS_TYPE (klass),
6963                                    &n);
6964   if (n_properties)
6965     *n_properties = n;
6966
6967   return pspecs;
6968 }
6969
6970 /**
6971  * gtk_widget_style_get_property:
6972  * @widget: a #GtkWidget
6973  * @property_name: the name of a style property
6974  * @value: location to return the property value 
6975  *
6976  * Gets the value of a style property of @widget.
6977  */
6978 void
6979 gtk_widget_style_get_property (GtkWidget   *widget,
6980                                const gchar *property_name,
6981                                GValue      *value)
6982 {
6983   GParamSpec *pspec;
6984
6985   g_return_if_fail (GTK_IS_WIDGET (widget));
6986   g_return_if_fail (property_name != NULL);
6987   g_return_if_fail (G_IS_VALUE (value));
6988
6989   g_object_ref (widget);
6990   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6991                                     property_name,
6992                                     G_OBJECT_TYPE (widget),
6993                                     TRUE);
6994   if (!pspec)
6995     g_warning ("%s: widget class `%s' has no property named `%s'",
6996                G_STRLOC,
6997                G_OBJECT_TYPE_NAME (widget),
6998                property_name);
6999   else
7000     {
7001       const GValue *peek_value;
7002
7003       peek_value = _gtk_style_peek_property_value (widget->style,
7004                                                    G_OBJECT_TYPE (widget),
7005                                                    pspec,
7006                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7007       
7008       /* auto-conversion of the caller's value type
7009        */
7010       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7011         g_value_copy (peek_value, value);
7012       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7013         g_value_transform (peek_value, value);
7014       else
7015         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7016                    pspec->name,
7017                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7018                    G_VALUE_TYPE_NAME (value));
7019     }
7020   g_object_unref (widget);
7021 }
7022
7023 /**
7024  * gtk_widget_style_get_valist:
7025  * @widget: a #GtkWidget
7026  * @first_property_name: the name of the first property to get
7027  * @var_args: a <type>va_list</type> of pairs of property names and
7028  *     locations to return the property values, starting with the location
7029  *     for @first_property_name.
7030  * 
7031  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
7032  * bindings.
7033  */ 
7034 void
7035 gtk_widget_style_get_valist (GtkWidget   *widget,
7036                              const gchar *first_property_name,
7037                              va_list      var_args)
7038 {
7039   const gchar *name;
7040
7041   g_return_if_fail (GTK_IS_WIDGET (widget));
7042
7043   g_object_ref (widget);
7044
7045   name = first_property_name;
7046   while (name)
7047     {
7048       const GValue *peek_value;
7049       GParamSpec *pspec;
7050       gchar *error;
7051
7052       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7053                                         name,
7054                                         G_OBJECT_TYPE (widget),
7055                                         TRUE);
7056       if (!pspec)
7057         {
7058           g_warning ("%s: widget class `%s' has no property named `%s'",
7059                      G_STRLOC,
7060                      G_OBJECT_TYPE_NAME (widget),
7061                      name);
7062           break;
7063         }
7064       /* style pspecs are always readable so we can spare that check here */
7065
7066       peek_value = _gtk_style_peek_property_value (widget->style,
7067                                                    G_OBJECT_TYPE (widget),
7068                                                    pspec,
7069                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7070       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7071       if (error)
7072         {
7073           g_warning ("%s: %s", G_STRLOC, error);
7074           g_free (error);
7075           break;
7076         }
7077
7078       name = va_arg (var_args, gchar*);
7079     }
7080
7081   g_object_unref (widget);
7082 }
7083
7084 /**
7085  * gtk_widget_style_get:
7086  * @widget: a #GtkWidget
7087  * @first_property_name: the name of the first property to get
7088  * @Varargs: pairs of property names and locations to 
7089  *   return the property values, starting with the location for 
7090  *   @first_property_name, terminated by %NULL.
7091  *
7092  * Gets the values of a multiple style properties of @widget.
7093  */
7094 void
7095 gtk_widget_style_get (GtkWidget   *widget,
7096                       const gchar *first_property_name,
7097                       ...)
7098 {
7099   va_list var_args;
7100
7101   g_return_if_fail (GTK_IS_WIDGET (widget));
7102
7103   va_start (var_args, first_property_name);
7104   gtk_widget_style_get_valist (widget, first_property_name, var_args);
7105   va_end (var_args);
7106 }
7107
7108 /**
7109  * gtk_widget_path:
7110  * @widget: a #GtkWidget
7111  * @path_length: location to store length of the path, or %NULL
7112  * @path: location to store allocated path string, or %NULL 
7113  * @path_reversed: location to store allocated reverse path string, or %NULL
7114  *
7115  * Obtains the full path to @widget. The path is simply the name of a
7116  * widget and all its parents in the container hierarchy, separated by
7117  * periods. The name of a widget comes from
7118  * gtk_widget_get_name(). Paths are used to apply styles to a widget
7119  * in gtkrc configuration files.  Widget names are the type of the
7120  * widget by default (e.g. "GtkButton") or can be set to an
7121  * application-specific value with gtk_widget_set_name().  By setting
7122  * the name of a widget, you allow users or theme authors to apply
7123  * styles to that specific widget in their gtkrc
7124  * file. @path_reversed_p fills in the path in reverse order,
7125  * i.e. starting with @widget's name instead of starting with the name
7126  * of @widget's outermost ancestor.
7127  * 
7128  **/
7129 void
7130 gtk_widget_path (GtkWidget *widget,
7131                  guint     *path_length,
7132                  gchar    **path,
7133                  gchar    **path_reversed)
7134 {
7135   static gchar *rev_path = NULL;
7136   static guint tmp_path_len = 0;
7137   guint len;
7138   
7139   g_return_if_fail (GTK_IS_WIDGET (widget));
7140   
7141   len = 0;
7142   do
7143     {
7144       const gchar *string;
7145       const gchar *s;
7146       gchar *d;
7147       guint l;
7148       
7149       string = gtk_widget_get_name (widget);
7150       l = strlen (string);
7151       while (tmp_path_len <= len + l + 1)
7152         {
7153           tmp_path_len += INIT_PATH_SIZE;
7154           rev_path = g_realloc (rev_path, tmp_path_len);
7155         }
7156       s = string + l - 1;
7157       d = rev_path + len;
7158       while (s >= string)
7159         *(d++) = *(s--);
7160       len += l;
7161       
7162       widget = widget->parent;
7163       
7164       if (widget)
7165         rev_path[len++] = '.';
7166       else
7167         rev_path[len++] = 0;
7168     }
7169   while (widget);
7170   
7171   if (path_length)
7172     *path_length = len - 1;
7173   if (path_reversed)
7174     *path_reversed = g_strdup (rev_path);
7175   if (path)
7176     {
7177       *path = g_strdup (rev_path);
7178       g_strreverse (*path);
7179     }
7180 }
7181
7182 /**
7183  * gtk_widget_class_path:
7184  * @widget: a #GtkWidget
7185  * @path_length: location to store the length of the class path, or %NULL
7186  * @path: location to store the class path as an allocated string, or %NULL
7187  * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7188  *
7189  * Same as gtk_widget_path(), but always uses the name of a widget's type,
7190  * never uses a custom name set with gtk_widget_set_name().
7191  * 
7192  **/
7193 void
7194 gtk_widget_class_path (GtkWidget *widget,
7195                        guint     *path_length,
7196                        gchar    **path,
7197                        gchar    **path_reversed)
7198 {
7199   static gchar *rev_path = NULL;
7200   static guint tmp_path_len = 0;
7201   guint len;
7202   
7203   g_return_if_fail (GTK_IS_WIDGET (widget));
7204   
7205   len = 0;
7206   do
7207     {
7208       const gchar *string;
7209       const gchar *s;
7210       gchar *d;
7211       guint l;
7212       
7213       string = g_type_name (GTK_WIDGET_TYPE (widget));
7214       l = strlen (string);
7215       while (tmp_path_len <= len + l + 1)
7216         {
7217           tmp_path_len += INIT_PATH_SIZE;
7218           rev_path = g_realloc (rev_path, tmp_path_len);
7219         }
7220       s = string + l - 1;
7221       d = rev_path + len;
7222       while (s >= string)
7223         *(d++) = *(s--);
7224       len += l;
7225       
7226       widget = widget->parent;
7227       
7228       if (widget)
7229         rev_path[len++] = '.';
7230       else
7231         rev_path[len++] = 0;
7232     }
7233   while (widget);
7234   
7235   if (path_length)
7236     *path_length = len - 1;
7237   if (path_reversed)
7238     *path_reversed = g_strdup (rev_path);
7239   if (path)
7240     {
7241       *path = g_strdup (rev_path);
7242       g_strreverse (*path);
7243     }
7244 }
7245
7246 /**
7247  * gtk_requisition_copy:
7248  * @requisition: a #GtkRequisition.
7249  * @returns: a copy of @requisition.
7250  *
7251  * Copies a #GtkRequisition.
7252  **/
7253 GtkRequisition *
7254 gtk_requisition_copy (const GtkRequisition *requisition)
7255 {
7256   return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7257 }
7258
7259 /**
7260  * gtk_requisition_free:
7261  * @requisition: a #GtkRequisition.
7262  * 
7263  * Frees a #GtkRequisition.
7264  **/
7265 void
7266 gtk_requisition_free (GtkRequisition *requisition)
7267 {
7268   g_free (requisition);
7269 }
7270
7271 GType
7272 gtk_requisition_get_type (void)
7273 {
7274   static GType our_type = 0;
7275   
7276   if (our_type == 0)
7277     our_type = g_boxed_type_register_static ("GtkRequisition",
7278                                              (GBoxedCopyFunc) gtk_requisition_copy,
7279                                              (GBoxedFreeFunc) gtk_requisition_free);
7280
7281   return our_type;
7282 }
7283
7284 AtkObject* 
7285 gtk_widget_get_accessible (GtkWidget *widget)
7286 {
7287   GtkWidgetClass *klass;
7288
7289   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7290
7291   klass = GTK_WIDGET_GET_CLASS (widget);
7292
7293   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7294
7295   return klass->get_accessible (widget);
7296 }
7297
7298 static AtkObject* 
7299 gtk_widget_real_get_accessible (GtkWidget *widget)
7300 {
7301   AtkObject* accessible;
7302
7303   accessible = g_object_get_qdata (G_OBJECT (widget), 
7304                                    quark_accessible_object);
7305   if (!accessible)
7306   {
7307     AtkObjectFactory *factory;
7308     AtkRegistry *default_registry;
7309
7310     default_registry = atk_get_default_registry ();
7311     factory = atk_registry_get_factory (default_registry, 
7312                                         G_TYPE_FROM_INSTANCE (widget));
7313     accessible =
7314       atk_object_factory_create_accessible (factory,
7315                                             G_OBJECT (widget));
7316     g_object_set_qdata (G_OBJECT (widget), 
7317                         quark_accessible_object,
7318                         accessible);
7319   }
7320   return accessible;
7321 }
7322
7323 /*
7324  * Initialize a AtkImplementorIface instance's virtual pointers as
7325  * appropriate to this implementor's class (GtkWidget).
7326  */
7327 static void
7328 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7329 {
7330   iface->ref_accessible = gtk_widget_ref_accessible;
7331 }
7332
7333 static AtkObject*
7334 gtk_widget_ref_accessible (AtkImplementor *implementor)
7335 {
7336   AtkObject *accessible;
7337
7338   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7339   if (accessible)
7340     g_object_ref (accessible);
7341   return accessible;
7342 }
7343
7344 /**
7345  * gtk_widget_get_clipboard:
7346  * @widget: a #GtkWidget
7347  * @selection: a #GdkAtom which identifies the clipboard
7348  *             to use. %GDK_SELECTION_CLIPBOARD gives the
7349  *             default clipboard. Another common value
7350  *             is %GDK_SELECTION_PRIMARY, which gives
7351  *             the primary X selection. 
7352  * 
7353  * Returns the clipboard object for the given selection to
7354  * be used with @widget. @widget must have a #GdkDisplay
7355  * associated with it, so must be attached to a toplevel
7356  * window.
7357  * 
7358  * Return value: the appropriate clipboard object. If no
7359  *             clipboard already exists, a new one will
7360  *             be created. Once a clipboard object has
7361  *             been created, it is persistent for all time.
7362  *
7363  * Since: 2.2
7364  **/
7365 GtkClipboard *
7366 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7367 {
7368   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7369   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7370   
7371   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7372                                         selection);
7373 }
7374
7375 /**
7376  * gtk_widget_list_mnemonic_labels:
7377  * @widget: a #GtkWidget
7378  * 
7379  * Returns a newly allocated list of the widgets, normally labels, for 
7380  * which this widget is a the target of a mnemonic (see for example, 
7381  * gtk_label_set_mnemonic_widget()).
7382
7383  * The widgets in the list are not individually referenced. If you
7384  * want to iterate through the list and perform actions involving
7385  * callbacks that might destroy the widgets, you
7386  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7387  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7388  * widgets afterwards.
7389
7390  * Return value: the list of mnemonic labels; free this list
7391  *  with g_list_free() when you are done with it.
7392  *
7393  * Since: 2.4
7394  **/
7395 GList *
7396 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7397 {
7398   GList *list = NULL;
7399   GSList *l;
7400   
7401   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7402
7403   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7404     list = g_list_prepend (list, l->data);
7405
7406   return list;
7407 }
7408
7409 /**
7410  * gtk_widget_add_mnemonic_label:
7411  * @widget: a #GtkWidget
7412  * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7413  * 
7414  * Adds a widget to the list of mnemonic labels for
7415  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7416  * list of mnemonic labels for the widget is cleared when the
7417  * widget is destroyed, so the caller must make sure to update
7418  * it's internal state at this point as well, by using a connection
7419  * to the ::destroy signal or a weak notifier.
7420  *
7421  * Since: 2.4
7422  **/
7423 void
7424 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7425                                GtkWidget *label)
7426 {
7427   GSList *old_list, *new_list;
7428
7429   g_return_if_fail (GTK_IS_WIDGET (widget));
7430   g_return_if_fail (GTK_IS_WIDGET (label));
7431
7432   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7433   new_list = g_slist_prepend (old_list, label);
7434   
7435   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7436                            new_list, (GDestroyNotify) g_slist_free);
7437 }
7438
7439 /**
7440  * gtk_widget_remove_mnemonic_label:
7441  * @widget: a #GtkWidget
7442  * @label: a #GtkWidget that was previously set as a mnemnic label for
7443  *         @widget with gtk_widget_add_mnemonic_label().
7444  * 
7445  * Removes a widget from the list of mnemonic labels for
7446  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7447  * must have previously been added to the list with
7448  * gtk_widget_add_mnemonic_label().
7449  *
7450  * Since: 2.4
7451  **/
7452 void
7453 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7454                                   GtkWidget *label)
7455 {
7456   GSList *old_list, *new_list;
7457
7458   g_return_if_fail (GTK_IS_WIDGET (widget));
7459   g_return_if_fail (GTK_IS_WIDGET (label));
7460
7461   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7462   new_list = g_slist_remove (old_list, label);
7463
7464   if (new_list)
7465     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7466                              new_list, (GDestroyNotify) g_slist_free);
7467 }
7468
7469 /**
7470  * gtk_widget_get_no_show_all:
7471  * @widget: a #GtkWidget
7472  * 
7473  * Returns the current value of the "no_show_all" property, which determines
7474  * whether calls to gtk_widget_show_all() and gtk_widget_hide_all() 
7475  * will affect this widget. 
7476  * 
7477  * Return value: the current value of the "no_show_all" property.
7478  *
7479  * Since: 2.4
7480  **/
7481 gboolean
7482 gtk_widget_get_no_show_all (GtkWidget *widget)
7483 {
7484   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7485   
7486   return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7487 }
7488
7489 /**
7490  * gtk_widget_set_no_show_all:
7491  * @widget: a #GtkWidget
7492  * @no_show_all: the new value for the "no_show_all" property
7493  * 
7494  * Sets the "no_show_all" property, which determines whether calls to 
7495  * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget. 
7496  *
7497  * This is mostly for use in constructing widget hierarchies with externally
7498  * controlled visibility, see #GtkUIManager.
7499  * 
7500  * Since: 2.4
7501  **/
7502 void
7503 gtk_widget_set_no_show_all (GtkWidget *widget,
7504                             gboolean   no_show_all)
7505 {
7506   g_return_if_fail (GTK_IS_WIDGET (widget));
7507
7508   no_show_all = (no_show_all != FALSE);
7509
7510   if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7511     return;
7512
7513   if (no_show_all)
7514     GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7515   else
7516     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7517   
7518   g_object_notify (G_OBJECT (widget), "no_show_all");
7519 }