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