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