]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
Convert GtkArgs to GParams. Based on patch by John Margaglione. Also do
[~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 <stdarg.h>
28 #include <string.h>
29 #include <locale.h>
30 #include "gtkcontainer.h"
31 #include "gtkiconfactory.h"
32 #include "gtkintl.h"
33 #include "gtkmain.h"
34 #include "gtkrc.h"
35 #include "gtkselection.h"
36 #include "gtksettings.h"
37 #include "gtksizegroup.h"
38 #include "gtksignal.h"
39 #include "gtkwidget.h"
40 #include "gtkwindow.h"
41 #include "gtkbindings.h"
42 #include "gtkprivate.h"
43 #include "gdk/gdk.h"
44 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
45 #include "gobject/gvaluecollector.h"
46 #include "gdk/gdkkeysyms.h"
47 #include "gtkintl.h"
48 #include "gtkaccessible.h"
49
50 #define WIDGET_CLASS(w)  GTK_WIDGET_GET_CLASS (w)
51 #define INIT_PATH_SIZE  (512)
52
53
54 enum {
55   SHOW,
56   HIDE,
57   MAP,
58   UNMAP,
59   REALIZE,
60   UNREALIZE,
61   SIZE_REQUEST,
62   SIZE_ALLOCATE,
63   STATE_CHANGED,
64   PARENT_SET,
65   HIERARCHY_CHANGED,
66   STYLE_SET,
67   DIRECTION_CHANGED,
68   ADD_ACCELERATOR,
69   REMOVE_ACCELERATOR,
70   ACTIVATE_MNEMONIC,
71   GRAB_FOCUS,
72   EVENT,
73   BUTTON_PRESS_EVENT,
74   BUTTON_RELEASE_EVENT,
75   SCROLL_EVENT,
76   MOTION_NOTIFY_EVENT,
77   DELETE_EVENT,
78   DESTROY_EVENT,
79   EXPOSE_EVENT,
80   KEY_PRESS_EVENT,
81   KEY_RELEASE_EVENT,
82   ENTER_NOTIFY_EVENT,
83   LEAVE_NOTIFY_EVENT,
84   CONFIGURE_EVENT,
85   FOCUS_IN_EVENT,
86   FOCUS_OUT_EVENT,
87   MAP_EVENT,
88   UNMAP_EVENT,
89   PROPERTY_NOTIFY_EVENT,
90   SELECTION_CLEAR_EVENT,
91   SELECTION_REQUEST_EVENT,
92   SELECTION_NOTIFY_EVENT,
93   SELECTION_GET,
94   SELECTION_RECEIVED,
95   PROXIMITY_IN_EVENT,
96   PROXIMITY_OUT_EVENT,
97   DRAG_BEGIN,
98   DRAG_END,
99   DRAG_DATA_DELETE,
100   DRAG_LEAVE,
101   DRAG_MOTION,
102   DRAG_DROP,
103   DRAG_DATA_GET,
104   DRAG_DATA_RECEIVED,
105   CLIENT_EVENT,
106   NO_EXPOSE_EVENT,
107   VISIBILITY_NOTIFY_EVENT,
108   WINDOW_STATE_EVENT,
109   POPUP_MENU,
110   LAST_SIGNAL
111 };
112
113 enum {
114   PROP_0,
115   PROP_NAME,
116   PROP_PARENT,
117   PROP_X,
118   PROP_Y,
119   PROP_WIDTH,
120   PROP_HEIGHT,
121   PROP_VISIBLE,
122   PROP_SENSITIVE,
123   PROP_APP_PAINTABLE,
124   PROP_CAN_FOCUS,
125   PROP_HAS_FOCUS,
126   PROP_CAN_DEFAULT,
127   PROP_HAS_DEFAULT,
128   PROP_RECEIVES_DEFAULT,
129   PROP_COMPOSITE_CHILD,
130   PROP_STYLE,
131   PROP_EVENTS,
132   PROP_EXTENSION_EVENTS
133 };
134
135 typedef struct  _GtkStateData    GtkStateData;
136
137 struct _GtkStateData
138 {
139   GtkStateType  state;
140   guint         state_restoration : 1;
141   guint         parent_sensitive : 1;
142   guint         use_forall : 1;
143 };
144
145 static void gtk_widget_class_init                (GtkWidgetClass    *klass);
146 static void gtk_widget_init                      (GtkWidget         *widget);
147 static void gtk_widget_set_property              (GObject           *object,
148                                                   guint              prop_id,
149                                                   const GValue      *value,
150                                                   GParamSpec        *pspec);
151 static void gtk_widget_get_property              (GObject           *object,
152                                                   guint              prop_id,
153                                                   GValue            *value,
154                                                   GParamSpec        *pspec);
155 static void gtk_widget_shutdown                  (GObject           *object);
156 static void gtk_widget_real_destroy              (GtkObject         *object);
157 static void gtk_widget_finalize                  (GObject           *object);
158 static void gtk_widget_real_show                 (GtkWidget         *widget);
159 static void gtk_widget_real_hide                 (GtkWidget         *widget);
160 static void gtk_widget_real_map                  (GtkWidget         *widget);
161 static void gtk_widget_real_unmap                (GtkWidget         *widget);
162 static void gtk_widget_real_realize              (GtkWidget         *widget);
163 static void gtk_widget_real_unrealize            (GtkWidget         *widget);
164 static void gtk_widget_real_size_request         (GtkWidget         *widget,
165                                                   GtkRequisition    *requisition);
166 static void gtk_widget_real_size_allocate        (GtkWidget         *widget,
167                                                   GtkAllocation     *allocation);
168 static gboolean gtk_widget_real_key_press_event   (GtkWidget     *widget,
169                                                    GdkEventKey   *event);
170 static gboolean gtk_widget_real_key_release_event (GtkWidget     *widget,
171                                                    GdkEventKey   *event);
172 static gboolean gtk_widget_real_focus_in_event    (GtkWidget     *widget,
173                                                    GdkEventFocus *event);
174 static gboolean gtk_widget_real_focus_out_event   (GtkWidget     *widget,
175                                                    GdkEventFocus *event);
176
177 static void gtk_widget_style_set                 (GtkWidget         *widget,
178                                                   GtkStyle          *previous_style);
179 static void gtk_widget_direction_changed         (GtkWidget         *widget,
180                                                   GtkTextDirection   previous_direction);
181 static void gtk_widget_real_grab_focus           (GtkWidget         *focus_widget);
182
183 static GdkColormap*  gtk_widget_peek_colormap      (void);
184 static GtkStyle*     gtk_widget_peek_style         (void);
185 static PangoContext *gtk_widget_peek_pango_context (GtkWidget *widget);
186
187 static void gtk_widget_reparent_container_child  (GtkWidget     *widget,
188                                                   gpointer       client_data);
189 static void gtk_widget_propagate_state           (GtkWidget     *widget,
190                                                   GtkStateData  *data);
191 static void gtk_widget_set_style_internal        (GtkWidget     *widget,
192                                                   GtkStyle      *style,
193                                                   gboolean       initial_emission);
194 static void gtk_widget_set_style_recurse         (GtkWidget     *widget,
195                                                   gpointer       client_data);
196 static gint gtk_widget_event_internal            (GtkWidget     *widget,
197                                                   GdkEvent      *event);
198
199 static void gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
200                                                     gpointer   client_data);
201 static gboolean gtk_widget_real_mnemonic_activate  (GtkWidget *widget,
202                                                     gboolean   group_cycling);
203
204 static void              gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
205
206 static void  gtk_widget_do_uposition (GtkWidget *widget);
207
208 static AtkObject*        gtk_widget_real_get_accessible   (GtkWidget *widget);
209 static void              gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
210 static AtkObject *       gtk_widget_ref_accessible (AtkImplementor *implementor);
211
212 static gpointer         parent_class = NULL;
213 static guint            widget_signals[LAST_SIGNAL] = { 0 };
214
215 static GMemChunk       *aux_info_mem_chunk = NULL;
216 static GdkColormap     *default_colormap = NULL;
217 static GtkStyle        *gtk_default_style = NULL;
218 static GSList          *colormap_stack = NULL;
219 static GSList          *style_stack = NULL;
220 static guint            composite_child_stack = 0;
221 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
222 static GParamSpecPool  *style_property_spec_pool = NULL;
223
224 static GQuark quark_property_parser = 0;
225 static GQuark quark_aux_info = 0;
226 static GQuark quark_event_mask = 0;
227 static GQuark quark_extension_event_mode = 0;
228 static GQuark quark_parent_window = 0;
229 static GQuark quark_saved_default_style = 0;
230 static GQuark quark_shape_info = 0;
231 static GQuark quark_colormap = 0;
232 static GQuark quark_pango_context = 0;
233 static GQuark quark_rc_style = 0;
234 static GQuark quark_accessible_object = 0;
235
236
237 /*****************************************
238  * gtk_widget_get_type:
239  *
240  *   arguments:
241  *
242  *   results:
243  *****************************************/
244
245 GtkType
246 gtk_widget_get_type (void)
247 {
248   static GtkType widget_type = 0;
249   
250   if (!widget_type)
251     {
252       static const GtkTypeInfo widget_info =
253       {
254         "GtkWidget",
255         sizeof (GtkWidget),
256         sizeof (GtkWidgetClass),
257         (GtkClassInitFunc) gtk_widget_class_init,
258         (GtkObjectInitFunc) gtk_widget_init,
259         /* reserved_1 */ NULL,
260         /* reserved_2 */ NULL,
261         (GtkClassInitFunc) NULL,
262       };
263       
264       static const GInterfaceInfo accessibility_info =
265       {
266         (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
267         (GInterfaceFinalizeFunc) NULL,
268         NULL /* interface data */
269       };
270
271  
272       widget_type = gtk_type_unique (GTK_TYPE_OBJECT, &widget_info);
273
274       g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
275                                    &accessibility_info) ;
276
277     }
278   
279   return widget_type;
280 }
281
282 /*****************************************
283  * gtk_widget_class_init:
284  *
285  *   arguments:
286  *
287  *   results:
288  *****************************************/
289 static void
290 gtk_widget_class_init (GtkWidgetClass *klass)
291 {
292   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
293   GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
294   GtkBindingSet *binding_set;
295   
296   parent_class = gtk_type_class (GTK_TYPE_OBJECT);
297
298   gobject_class->shutdown = gtk_widget_shutdown;
299   gobject_class->finalize = gtk_widget_finalize;
300   gobject_class->set_property = gtk_widget_set_property;
301   gobject_class->get_property = gtk_widget_get_property;
302
303   object_class->destroy = gtk_widget_real_destroy;
304   
305   klass->activate_signal = 0;
306   klass->set_scroll_adjustments_signal = 0;
307   klass->show = gtk_widget_real_show;
308   klass->show_all = gtk_widget_show;
309   klass->hide = gtk_widget_real_hide;
310   klass->hide_all = gtk_widget_hide;
311   klass->map = gtk_widget_real_map;
312   klass->unmap = gtk_widget_real_unmap;
313   klass->realize = gtk_widget_real_realize;
314   klass->unrealize = gtk_widget_real_unrealize;
315   klass->size_request = gtk_widget_real_size_request;
316   klass->size_allocate = gtk_widget_real_size_allocate;
317   klass->state_changed = NULL;
318   klass->parent_set = NULL;
319   klass->hierarchy_changed = NULL;
320   klass->style_set = gtk_widget_style_set;
321   klass->direction_changed = gtk_widget_direction_changed;
322   klass->add_accelerator = (void*) gtk_accel_group_handle_add;
323   klass->remove_accelerator = (void*) gtk_accel_group_handle_remove;
324   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
325   klass->grab_focus = gtk_widget_real_grab_focus;
326   klass->event = NULL;
327   klass->button_press_event = NULL;
328   klass->button_release_event = NULL;
329   klass->motion_notify_event = NULL;
330   klass->delete_event = NULL;
331   klass->destroy_event = NULL;
332   klass->expose_event = NULL;
333   klass->key_press_event = gtk_widget_real_key_press_event;
334   klass->key_release_event = gtk_widget_real_key_release_event;
335   klass->enter_notify_event = NULL;
336   klass->leave_notify_event = NULL;
337   klass->configure_event = NULL;
338   klass->focus_in_event = gtk_widget_real_focus_in_event;
339   klass->focus_out_event = gtk_widget_real_focus_out_event;
340   klass->map_event = NULL;
341   klass->unmap_event = NULL;
342   klass->window_state_event = NULL;
343   klass->property_notify_event = gtk_selection_property_notify;
344   klass->selection_clear_event = gtk_selection_clear;
345   klass->selection_request_event = gtk_selection_request;
346   klass->selection_notify_event = gtk_selection_notify;
347   klass->selection_received = NULL;
348   klass->proximity_in_event = NULL;
349   klass->proximity_out_event = NULL;
350   klass->drag_begin = NULL;
351   klass->drag_end = NULL;
352   klass->drag_data_delete = NULL;
353   klass->drag_leave = NULL;
354   klass->drag_motion = NULL;
355   klass->drag_drop = NULL;
356   klass->drag_data_received = NULL;
357
358   /* Accessibility support */
359   klass->get_accessible = gtk_widget_real_get_accessible;
360
361   klass->no_expose_event = NULL;
362
363   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
364   quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
365   quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
366   quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
367   quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
368   quark_saved_default_style = g_quark_from_static_string ("gtk-saved-default-style");
369   quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
370   quark_colormap = g_quark_from_static_string ("gtk-colormap");
371   quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
372   quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
373   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
374
375   style_property_spec_pool = g_param_spec_pool_new (FALSE);
376
377   g_object_class_install_property (gobject_class,
378                                    PROP_NAME,
379                                    g_param_spec_string ("name",
380                                                         _("Widget name"),
381                                                         _("The name of the widget"),
382                                                         NULL,
383                                                         G_PARAM_READWRITE));
384   
385   g_object_class_install_property (gobject_class,
386                                    PROP_PARENT,
387                                    g_param_spec_object ("parent",
388                                                         _("Parent widget"),
389                                                         _("The parent widget of this widget. Must be a Container widget."),
390                                                         GTK_TYPE_CONTAINER,
391                                                         G_PARAM_READWRITE));
392  
393   g_object_class_install_property (gobject_class,
394                                    PROP_X,
395                                    g_param_spec_int ("x",
396                                                      _("x coordinate"),
397                                                      _("The x coordinate of the top-left corner of the widget, or -1 if not set"),
398                                                      -G_MAXINT,
399                                                      G_MAXINT,
400                                                      -1,
401                                                      G_PARAM_READWRITE));
402  
403   g_object_class_install_property (gobject_class,
404                                    PROP_Y,
405                                    g_param_spec_int ("y",
406                                                      _("y coordinate"),
407                                                      _("The y coordinate of the top-left corner of the widget, or -1 if not set"),
408                                                      -G_MAXINT,
409                                                      G_MAXINT,
410                                                      -1,
411                                                      G_PARAM_READWRITE));
412  
413   g_object_class_install_property (gobject_class,
414                                    PROP_WIDTH,
415                                    g_param_spec_int ("width",
416                                                      _("Width"),
417                                                      _("The width of the widget, or -1 if unset."),
418                                                      -1,
419                                                      G_MAXINT,
420                                                      -1,
421                                                      G_PARAM_READWRITE));
422  
423   g_object_class_install_property (gobject_class,
424                                    PROP_HEIGHT,
425                                    g_param_spec_int ("height",
426                                                      _("Height"),
427                                                      _("The height of the widget, or -1 if unset."),
428                                                      -1,
429                                                      G_MAXINT,
430                                                      -1,
431                                                      G_PARAM_READWRITE));
432  
433   g_object_class_install_property (gobject_class,
434                                    PROP_VISIBLE,
435                                    g_param_spec_boolean ("visible",
436                                                          _("Visible"),
437                                                          _("Whether the widget is visible"),
438                                                          FALSE,
439                                                          G_PARAM_READWRITE));
440  
441   g_object_class_install_property (gobject_class,
442                                    PROP_SENSITIVE,
443                                    g_param_spec_boolean ("sensitive",
444                                                          _("Sensitive"),
445                                                          _("Whether the widget responds to input"),
446                                                          TRUE,
447                                                          G_PARAM_READWRITE));
448  
449   g_object_class_install_property (gobject_class,
450                                    PROP_APP_PAINTABLE,
451                                    g_param_spec_boolean ("app_paintable",
452                                                          _("Application paintable"),
453                                                          _("Whether the application will paint directly on the widget"),
454                                                          FALSE,
455                                                          G_PARAM_READWRITE));
456  
457   g_object_class_install_property (gobject_class,
458                                    PROP_CAN_FOCUS,
459                                    g_param_spec_boolean ("can_focus",
460                                                          _("Can focus"),
461                                                          _("Whether the widget can accept the input focus"),
462                                                          FALSE,
463                                                          G_PARAM_READWRITE));
464  
465   g_object_class_install_property (gobject_class,
466                                    PROP_HAS_FOCUS,
467                                    g_param_spec_boolean ("has_focus",
468                                                          _("Has focus"),
469                                                          _("Whether the widget has the input focus"),
470                                                          FALSE,
471                                                          G_PARAM_READWRITE));
472  
473   g_object_class_install_property (gobject_class,
474                                    PROP_CAN_DEFAULT,
475                                    g_param_spec_boolean ("can_default",
476                                                          _("Can default"),
477                                                          _("Whether the widget can be the default widget"),
478                                                          FALSE,
479                                                          G_PARAM_READWRITE));
480  
481   g_object_class_install_property (gobject_class,
482                                    PROP_HAS_DEFAULT,
483                                    g_param_spec_boolean ("has_default",
484                                                          _("Has default"),
485                                                          _("Whether the widget is the default widget"),
486                                                          FALSE,
487                                                          G_PARAM_READWRITE));
488  
489   g_object_class_install_property (gobject_class,
490                                    PROP_RECEIVES_DEFAULT,
491                                    g_param_spec_boolean ("receives_default",
492                                                          _("Receives default"),
493                                                          _("If TRUE, the widget will receive the default action when it is focused."),
494                                                          FALSE,
495                                                          G_PARAM_READWRITE));
496  
497   g_object_class_install_property (gobject_class,
498                                    PROP_COMPOSITE_CHILD,
499                                    g_param_spec_boolean ("composite_child",
500                                                          _("Composite child"),
501                                                          _("Whether the widget is composed of other widgets"),
502                                                          FALSE,
503                                                          G_PARAM_READWRITE));
504  
505  
506   g_object_class_install_property (gobject_class,
507                                    PROP_STYLE,
508                                    g_param_spec_object ("style",
509                                                         _("Style"),
510                                                         _("The style of the widget, which contains information about how it will look (colors etc)."),
511                                                         GTK_TYPE_STYLE,
512                                                         G_PARAM_READWRITE));
513  
514   g_object_class_install_property (gobject_class,
515                                    PROP_EVENTS,
516                                    g_param_spec_flags ("events",
517                                                        _("Events"),
518                                                        _("The event mask that decides what kind of GdkEvents this widget gets."),
519                                                        GDK_TYPE_EVENT_MASK,
520                                                        GDK_STRUCTURE_MASK,
521                                                        G_PARAM_READWRITE));
522  
523   g_object_class_install_property (gobject_class,
524                                    PROP_EXTENSION_EVENTS,
525                                    g_param_spec_enum ("extension_events",
526                                                       _("Extension events"),
527                                                       _("The mask that decides what kind of extension events this widget gets."),
528                                                       GDK_TYPE_EXTENSION_MODE,
529                                                       GDK_EXTENSION_EVENTS_NONE,
530                                                       G_PARAM_READWRITE));
531
532
533   widget_signals[SHOW] =
534     gtk_signal_new ("show",
535                     GTK_RUN_FIRST,
536                     GTK_CLASS_TYPE (object_class),
537                     GTK_SIGNAL_OFFSET (GtkWidgetClass, show),
538                     gtk_marshal_VOID__VOID,
539                     GTK_TYPE_NONE, 0);
540   widget_signals[HIDE] =
541     gtk_signal_new ("hide",
542                     GTK_RUN_FIRST,
543                     GTK_CLASS_TYPE (object_class),
544                     GTK_SIGNAL_OFFSET (GtkWidgetClass, hide),
545                     gtk_marshal_VOID__VOID,
546                     GTK_TYPE_NONE, 0);
547   widget_signals[MAP] =
548     gtk_signal_new ("map",
549                     GTK_RUN_FIRST,
550                     GTK_CLASS_TYPE (object_class),
551                     GTK_SIGNAL_OFFSET (GtkWidgetClass, map),
552                     gtk_marshal_VOID__VOID,
553                     GTK_TYPE_NONE, 0);
554   widget_signals[UNMAP] =
555     gtk_signal_new ("unmap",
556                     GTK_RUN_FIRST,
557                     GTK_CLASS_TYPE (object_class),
558                     GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap),
559                     gtk_marshal_VOID__VOID,
560                     GTK_TYPE_NONE, 0);
561   widget_signals[REALIZE] =
562     gtk_signal_new ("realize",
563                     GTK_RUN_FIRST,
564                     GTK_CLASS_TYPE (object_class),
565                     GTK_SIGNAL_OFFSET (GtkWidgetClass, realize),
566                     gtk_marshal_VOID__VOID,
567                     GTK_TYPE_NONE, 0);
568   widget_signals[UNREALIZE] =
569     gtk_signal_new ("unrealize",
570                     GTK_RUN_FIRST,
571                     GTK_CLASS_TYPE (object_class),
572                     GTK_SIGNAL_OFFSET (GtkWidgetClass, unrealize),
573                     gtk_marshal_VOID__VOID,
574                     GTK_TYPE_NONE, 0);
575   widget_signals[SIZE_REQUEST] =
576     g_signal_newc ("size_request",
577                    G_OBJECT_CLASS_TYPE (object_class),
578                    G_SIGNAL_RUN_FIRST,
579                    G_STRUCT_OFFSET (GtkWidgetClass, size_request),
580                    NULL, NULL,
581                    gtk_marshal_VOID__BOXED,
582                    GTK_TYPE_NONE, 1,
583                    GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
584   widget_signals[SIZE_ALLOCATE] = 
585     gtk_signal_new ("size_allocate",
586                     GTK_RUN_FIRST,
587                     GTK_CLASS_TYPE (object_class),
588                     GTK_SIGNAL_OFFSET (GtkWidgetClass, size_allocate),
589                     gtk_marshal_VOID__POINTER,
590                     GTK_TYPE_NONE, 1,
591                     GTK_TYPE_POINTER);
592   widget_signals[STATE_CHANGED] =
593     gtk_signal_new ("state_changed",
594                     GTK_RUN_FIRST,
595                     GTK_CLASS_TYPE (object_class),
596                     GTK_SIGNAL_OFFSET (GtkWidgetClass, state_changed),
597                     gtk_marshal_VOID__ENUM,
598                     GTK_TYPE_NONE, 1,
599                     GTK_TYPE_STATE_TYPE);
600   widget_signals[PARENT_SET] =
601     gtk_signal_new ("parent_set",
602                     GTK_RUN_FIRST,
603                     GTK_CLASS_TYPE (object_class),
604                     GTK_SIGNAL_OFFSET (GtkWidgetClass, parent_set),
605                     gtk_marshal_VOID__OBJECT,
606                     GTK_TYPE_NONE, 1,
607                     GTK_TYPE_OBJECT);
608   widget_signals[HIERARCHY_CHANGED] =
609     gtk_signal_new ("hierarchy_changed",
610                     GTK_RUN_LAST,
611                     GTK_CLASS_TYPE (object_class),
612                     GTK_SIGNAL_OFFSET (GtkWidgetClass, hierarchy_changed),
613                     gtk_marshal_NONE__NONE,
614                     GTK_TYPE_NONE, 0);
615   widget_signals[STYLE_SET] =
616     gtk_signal_new ("style_set",
617                     GTK_RUN_FIRST,
618                     GTK_CLASS_TYPE (object_class),
619                     GTK_SIGNAL_OFFSET (GtkWidgetClass, style_set),
620                     gtk_marshal_VOID__OBJECT,
621                     GTK_TYPE_NONE, 1,
622                     GTK_TYPE_STYLE);
623   widget_signals[DIRECTION_CHANGED] =
624     gtk_signal_new ("direction_changed",
625                     GTK_RUN_FIRST,
626                     GTK_CLASS_TYPE (object_class),
627                     GTK_SIGNAL_OFFSET (GtkWidgetClass, direction_changed),
628                     gtk_marshal_VOID__ENUM,
629                     GTK_TYPE_NONE, 1,
630                     GTK_TYPE_TEXT_DIRECTION);
631   widget_signals[ADD_ACCELERATOR] =
632     gtk_accel_group_create_add (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
633                                 GTK_SIGNAL_OFFSET (GtkWidgetClass, add_accelerator));
634   widget_signals[REMOVE_ACCELERATOR] =
635     gtk_accel_group_create_remove (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
636                                    GTK_SIGNAL_OFFSET (GtkWidgetClass, remove_accelerator));
637   widget_signals[ACTIVATE_MNEMONIC] =
638     g_signal_newc ("mnemonic_activate",
639                    GTK_CLASS_TYPE (object_class),
640                    GTK_RUN_LAST,
641                    GTK_SIGNAL_OFFSET (GtkWidgetClass, mnemonic_activate),
642                    _gtk_boolean_handled_accumulator, NULL,
643                    gtk_marshal_BOOLEAN__BOOLEAN,
644                    GTK_TYPE_BOOL, 1,
645                    GTK_TYPE_BOOL);
646   widget_signals[GRAB_FOCUS] =
647     gtk_signal_new ("grab_focus",
648                     GTK_RUN_LAST | GTK_RUN_ACTION,
649                     GTK_CLASS_TYPE (object_class),
650                     GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_focus),
651                     gtk_marshal_VOID__VOID,
652                     GTK_TYPE_NONE, 0);
653   widget_signals[EVENT] =
654     g_signal_newc ("event",
655                    G_TYPE_FROM_CLASS(object_class),
656                    G_SIGNAL_RUN_LAST,
657                    G_STRUCT_OFFSET(GtkWidgetClass, event),
658                    _gtk_boolean_handled_accumulator, NULL,
659                    gtk_marshal_BOOLEAN__BOXED,
660                    G_TYPE_BOOLEAN, 1,
661                    GDK_TYPE_EVENT);
662   widget_signals[BUTTON_PRESS_EVENT] =
663     g_signal_newc ("button_press_event",
664                    G_TYPE_FROM_CLASS(object_class),
665                    G_SIGNAL_RUN_LAST,
666                    G_STRUCT_OFFSET(GtkWidgetClass, button_press_event),
667                    _gtk_boolean_handled_accumulator, NULL,
668                    gtk_marshal_BOOLEAN__BOXED,
669                    G_TYPE_BOOLEAN, 1,
670                    GDK_TYPE_EVENT);
671   widget_signals[BUTTON_RELEASE_EVENT] =
672     g_signal_newc ("button_release_event",
673                    G_TYPE_FROM_CLASS(object_class),
674                    G_SIGNAL_RUN_LAST,
675                    G_STRUCT_OFFSET(GtkWidgetClass, button_release_event),
676                    _gtk_boolean_handled_accumulator, NULL,
677                    gtk_marshal_BOOLEAN__BOXED,
678                    G_TYPE_BOOLEAN, 1,
679                    GDK_TYPE_EVENT);
680   widget_signals[SCROLL_EVENT] =
681     g_signal_newc ("scroll_event",
682                    G_TYPE_FROM_CLASS(object_class),
683                    G_SIGNAL_RUN_LAST,
684                    G_STRUCT_OFFSET(GtkWidgetClass, scroll_event),
685                    _gtk_boolean_handled_accumulator, NULL,
686                    gtk_marshal_BOOLEAN__BOXED,
687                    G_TYPE_BOOLEAN, 1,
688                    GDK_TYPE_EVENT);
689   widget_signals[MOTION_NOTIFY_EVENT] =
690     g_signal_newc ("motion_notify_event",
691                    G_TYPE_FROM_CLASS(object_class),
692                    G_SIGNAL_RUN_LAST,
693                    G_STRUCT_OFFSET(GtkWidgetClass, motion_notify_event),
694                    _gtk_boolean_handled_accumulator, NULL,
695                    gtk_marshal_BOOLEAN__BOXED,
696                    G_TYPE_BOOLEAN, 1,
697                    GDK_TYPE_EVENT);
698   widget_signals[DELETE_EVENT] =
699     g_signal_newc ("delete_event",
700                    G_TYPE_FROM_CLASS(object_class),
701                    G_SIGNAL_RUN_LAST,
702                    G_STRUCT_OFFSET(GtkWidgetClass, delete_event),
703                    _gtk_boolean_handled_accumulator, NULL,
704                    gtk_marshal_BOOLEAN__BOXED,
705                    G_TYPE_BOOLEAN, 1,
706                    GDK_TYPE_EVENT);
707   widget_signals[DESTROY_EVENT] =
708     g_signal_newc ("destroy_event",
709                    G_TYPE_FROM_CLASS(object_class),
710                    G_SIGNAL_RUN_LAST,
711                    G_STRUCT_OFFSET(GtkWidgetClass, destroy_event),
712                    _gtk_boolean_handled_accumulator, NULL,
713                    gtk_marshal_BOOLEAN__BOXED,
714                    G_TYPE_BOOLEAN, 1,
715                    GDK_TYPE_EVENT);
716   widget_signals[EXPOSE_EVENT] =
717     g_signal_newc ("expose_event",
718                    G_TYPE_FROM_CLASS(object_class),
719                    G_SIGNAL_RUN_LAST,
720                    G_STRUCT_OFFSET(GtkWidgetClass, expose_event),
721                    _gtk_boolean_handled_accumulator, NULL,
722                    gtk_marshal_BOOLEAN__BOXED,
723                    G_TYPE_BOOLEAN, 1,
724                    GDK_TYPE_EVENT);
725   widget_signals[KEY_PRESS_EVENT] =
726     g_signal_newc ("key_press_event",
727                    G_TYPE_FROM_CLASS(object_class),
728                    G_SIGNAL_RUN_LAST,
729                    G_STRUCT_OFFSET(GtkWidgetClass, key_press_event),
730                    _gtk_boolean_handled_accumulator, NULL,
731                    gtk_marshal_BOOLEAN__BOXED,
732                    G_TYPE_BOOLEAN, 1,
733                    GDK_TYPE_EVENT);
734   widget_signals[KEY_RELEASE_EVENT] =
735     g_signal_newc ("key_release_event",
736                    G_TYPE_FROM_CLASS(object_class),
737                    G_SIGNAL_RUN_LAST,
738                    G_STRUCT_OFFSET(GtkWidgetClass, key_release_event),
739                    _gtk_boolean_handled_accumulator, NULL,
740                    gtk_marshal_BOOLEAN__BOXED,
741                    G_TYPE_BOOLEAN, 1,
742                    GDK_TYPE_EVENT);
743   widget_signals[ENTER_NOTIFY_EVENT] =
744     g_signal_newc ("enter_notify_event",
745                    G_TYPE_FROM_CLASS(object_class),
746                    G_SIGNAL_RUN_LAST,
747                    G_STRUCT_OFFSET(GtkWidgetClass, enter_notify_event),
748                    _gtk_boolean_handled_accumulator, NULL,
749                    gtk_marshal_BOOLEAN__BOXED,
750                    G_TYPE_BOOLEAN, 1,
751                    GDK_TYPE_EVENT);
752   widget_signals[LEAVE_NOTIFY_EVENT] =
753     g_signal_newc ("leave_notify_event",
754                    G_TYPE_FROM_CLASS(object_class),
755                    G_SIGNAL_RUN_LAST,
756                    G_STRUCT_OFFSET(GtkWidgetClass, leave_notify_event),
757                    _gtk_boolean_handled_accumulator, NULL,
758                    gtk_marshal_BOOLEAN__BOXED,
759                    G_TYPE_BOOLEAN, 1,
760                    GDK_TYPE_EVENT);
761   widget_signals[CONFIGURE_EVENT] =
762     g_signal_newc ("configure_event",
763                    G_TYPE_FROM_CLASS(object_class),
764                    G_SIGNAL_RUN_LAST,
765                    G_STRUCT_OFFSET(GtkWidgetClass, configure_event),
766                    _gtk_boolean_handled_accumulator, NULL,
767                    gtk_marshal_BOOLEAN__BOXED,
768                    G_TYPE_BOOLEAN, 1,
769                    GDK_TYPE_EVENT);
770   widget_signals[FOCUS_IN_EVENT] =
771     g_signal_newc ("focus_in_event",
772                   G_TYPE_FROM_CLASS(object_class),
773                   G_SIGNAL_RUN_LAST,
774                   G_STRUCT_OFFSET(GtkWidgetClass, focus_in_event),
775                   _gtk_boolean_handled_accumulator, NULL,
776                   gtk_marshal_BOOLEAN__BOXED,
777                   G_TYPE_BOOLEAN, 1,
778                   GDK_TYPE_EVENT);
779   widget_signals[FOCUS_OUT_EVENT] =
780     g_signal_newc ("focus_out_event",
781                   G_TYPE_FROM_CLASS(object_class),
782                   G_SIGNAL_RUN_LAST,
783                   G_STRUCT_OFFSET(GtkWidgetClass, focus_out_event),
784                   _gtk_boolean_handled_accumulator, NULL,
785                   gtk_marshal_BOOLEAN__BOXED,
786                   G_TYPE_BOOLEAN, 1,
787                   GDK_TYPE_EVENT);
788   widget_signals[MAP_EVENT] =
789     g_signal_newc ("map_event",
790                   G_TYPE_FROM_CLASS(object_class),
791                   G_SIGNAL_RUN_LAST,
792                   G_STRUCT_OFFSET(GtkWidgetClass, map_event),
793                   _gtk_boolean_handled_accumulator, NULL,
794                   gtk_marshal_BOOLEAN__BOXED,
795                   G_TYPE_BOOLEAN, 1,
796                   GDK_TYPE_EVENT);
797   widget_signals[UNMAP_EVENT] =
798     g_signal_newc ("unmap_event",
799                   G_TYPE_FROM_CLASS(object_class),
800                   G_SIGNAL_RUN_LAST,
801                   G_STRUCT_OFFSET(GtkWidgetClass, unmap_event),
802                   _gtk_boolean_handled_accumulator, NULL,
803                   gtk_marshal_BOOLEAN__BOXED,
804                   G_TYPE_BOOLEAN, 1,
805                   GDK_TYPE_EVENT);
806   widget_signals[PROPERTY_NOTIFY_EVENT] =
807     g_signal_newc ("property_notify_event",
808                   G_TYPE_FROM_CLASS(object_class),
809                   G_SIGNAL_RUN_LAST,
810                   G_STRUCT_OFFSET(GtkWidgetClass, property_notify_event),
811                   _gtk_boolean_handled_accumulator, NULL,
812                   gtk_marshal_BOOLEAN__BOXED,
813                   G_TYPE_BOOLEAN, 1,
814                   GDK_TYPE_EVENT);
815   widget_signals[SELECTION_CLEAR_EVENT] =
816     g_signal_newc ("selection_clear_event",
817                   G_TYPE_FROM_CLASS(object_class),
818                   G_SIGNAL_RUN_LAST,
819                   G_STRUCT_OFFSET(GtkWidgetClass, selection_clear_event),
820                   _gtk_boolean_handled_accumulator, NULL,
821                   gtk_marshal_BOOLEAN__BOXED,
822                   G_TYPE_BOOLEAN, 1,
823                   GDK_TYPE_EVENT);
824   widget_signals[SELECTION_REQUEST_EVENT] =
825     g_signal_newc ("selection_request_event",
826                   G_TYPE_FROM_CLASS(object_class),
827                   G_SIGNAL_RUN_LAST,
828                   G_STRUCT_OFFSET(GtkWidgetClass, selection_request_event),
829                   _gtk_boolean_handled_accumulator, NULL,
830                   gtk_marshal_BOOLEAN__BOXED,
831                   G_TYPE_BOOLEAN, 1,
832                   GDK_TYPE_EVENT);
833   widget_signals[SELECTION_NOTIFY_EVENT] =
834     g_signal_newc ("selection_notify_event",
835                   G_TYPE_FROM_CLASS(object_class),
836                   G_SIGNAL_RUN_LAST,
837                   G_STRUCT_OFFSET(GtkWidgetClass, selection_notify_event),
838                   _gtk_boolean_handled_accumulator, NULL,
839                   gtk_marshal_BOOLEAN__BOXED,
840                   G_TYPE_BOOLEAN, 1,
841                   GDK_TYPE_EVENT);
842   widget_signals[SELECTION_RECEIVED] =
843     gtk_signal_new ("selection_received",
844                     GTK_RUN_LAST,
845                     GTK_CLASS_TYPE (object_class),
846                     GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_received),
847                     gtk_marshal_VOID__BOXED_UINT,
848                     GTK_TYPE_NONE, 2,
849                     GTK_TYPE_SELECTION_DATA,
850                     GTK_TYPE_UINT);
851   widget_signals[SELECTION_GET] =
852     gtk_signal_new ("selection_get",
853                     GTK_RUN_LAST,
854                     GTK_CLASS_TYPE (object_class),
855                     GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_get),
856                     gtk_marshal_VOID__BOXED_UINT_UINT,
857                     GTK_TYPE_NONE, 3,
858                     GTK_TYPE_SELECTION_DATA,
859                     GTK_TYPE_UINT,
860                     GTK_TYPE_UINT);
861   widget_signals[PROXIMITY_IN_EVENT] =
862     g_signal_newc ("proximity_in_event",
863                   G_TYPE_FROM_CLASS(object_class),
864                   G_SIGNAL_RUN_LAST,
865                   G_STRUCT_OFFSET(GtkWidgetClass, proximity_in_event),
866                   _gtk_boolean_handled_accumulator, NULL,
867                   gtk_marshal_BOOLEAN__BOXED,
868                   G_TYPE_BOOLEAN, 1,
869                   GDK_TYPE_EVENT);
870   widget_signals[PROXIMITY_OUT_EVENT] =
871     g_signal_newc ("proximity_out_event",
872                   G_TYPE_FROM_CLASS(object_class),
873                   G_SIGNAL_RUN_LAST,
874                   G_STRUCT_OFFSET(GtkWidgetClass, proximity_out_event),
875                   _gtk_boolean_handled_accumulator, NULL,
876                   gtk_marshal_BOOLEAN__BOXED,
877                   G_TYPE_BOOLEAN, 1,
878                   GDK_TYPE_EVENT);
879   widget_signals[DRAG_LEAVE] =
880     gtk_signal_new ("drag_leave",
881                     GTK_RUN_LAST,
882                     GTK_CLASS_TYPE (object_class),
883                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_leave),
884                     gtk_marshal_VOID__OBJECT_UINT,
885                     GTK_TYPE_NONE, 2,
886                     GDK_TYPE_DRAG_CONTEXT,
887                     GTK_TYPE_UINT);
888   widget_signals[DRAG_BEGIN] =
889     gtk_signal_new ("drag_begin",
890                     GTK_RUN_LAST,
891                     GTK_CLASS_TYPE (object_class),
892                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin),
893                     gtk_marshal_VOID__OBJECT,
894                     GTK_TYPE_NONE, 1,
895                     GDK_TYPE_DRAG_CONTEXT);
896   widget_signals[DRAG_END] =
897     gtk_signal_new ("drag_end",
898                     GTK_RUN_LAST,
899                     GTK_CLASS_TYPE (object_class),
900                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end),
901                     gtk_marshal_VOID__OBJECT,
902                     GTK_TYPE_NONE, 1,
903                     GDK_TYPE_DRAG_CONTEXT);
904   widget_signals[DRAG_DATA_DELETE] =
905     gtk_signal_new ("drag_data_delete",
906                     GTK_RUN_LAST,
907                     GTK_CLASS_TYPE (object_class),
908                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_delete),
909                     gtk_marshal_VOID__OBJECT,
910                     GTK_TYPE_NONE, 1,
911                     GDK_TYPE_DRAG_CONTEXT);
912   widget_signals[DRAG_MOTION] =
913     g_signal_newc ("drag_motion",
914                   G_TYPE_FROM_CLASS(object_class),
915                   G_SIGNAL_RUN_LAST,
916                   G_STRUCT_OFFSET(GtkWidgetClass, drag_motion),
917                   _gtk_boolean_handled_accumulator, NULL,
918                   gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
919                   G_TYPE_BOOLEAN, 4,
920                   GDK_TYPE_DRAG_CONTEXT,
921                   G_TYPE_INT,
922                   G_TYPE_INT,
923                   G_TYPE_UINT);
924   widget_signals[DRAG_DROP] =
925     g_signal_newc ("drag_drop",
926                   G_TYPE_FROM_CLASS(object_class),
927                   G_SIGNAL_RUN_LAST,
928                   G_STRUCT_OFFSET(GtkWidgetClass, drag_drop),
929                   _gtk_boolean_handled_accumulator, NULL,
930                   gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
931                   G_TYPE_BOOLEAN, 4,
932                   GDK_TYPE_DRAG_CONTEXT,
933                   G_TYPE_INT,
934                   G_TYPE_INT,
935                   G_TYPE_UINT);
936   widget_signals[DRAG_DATA_GET] =
937     gtk_signal_new ("drag_data_get",
938                     GTK_RUN_LAST,
939                     GTK_CLASS_TYPE (object_class),
940                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_get),
941                     gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
942                     GTK_TYPE_NONE, 4,
943                     GDK_TYPE_DRAG_CONTEXT,
944                     GTK_TYPE_SELECTION_DATA,
945                     GTK_TYPE_UINT,
946                     GTK_TYPE_UINT);
947   widget_signals[DRAG_DATA_RECEIVED] =
948     gtk_signal_new ("drag_data_received",
949                     GTK_RUN_LAST,
950                     GTK_CLASS_TYPE (object_class),
951                     GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_received),
952                     gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
953                     GTK_TYPE_NONE, 6,
954                     GDK_TYPE_DRAG_CONTEXT,
955                     GTK_TYPE_INT,
956                     GTK_TYPE_INT,
957                     GTK_TYPE_SELECTION_DATA,
958                     GTK_TYPE_UINT,
959                     GTK_TYPE_UINT);
960   widget_signals[VISIBILITY_NOTIFY_EVENT] =
961     g_signal_newc ("visibility_notify_event",
962                   G_TYPE_FROM_CLASS(object_class),
963                   G_SIGNAL_RUN_LAST,
964                   G_STRUCT_OFFSET(GtkWidgetClass, visibility_notify_event),
965                   _gtk_boolean_handled_accumulator, NULL,
966                   gtk_marshal_BOOLEAN__BOXED,
967                   G_TYPE_BOOLEAN, 1,
968                   GDK_TYPE_EVENT);
969   widget_signals[CLIENT_EVENT] =
970     g_signal_newc ("client_event",
971                   G_TYPE_FROM_CLASS(object_class),
972                   G_SIGNAL_RUN_LAST,
973                   G_STRUCT_OFFSET(GtkWidgetClass, client_event),
974                   _gtk_boolean_handled_accumulator, NULL,
975                   gtk_marshal_BOOLEAN__BOXED,
976                   G_TYPE_BOOLEAN, 1,
977                   GDK_TYPE_EVENT);
978   widget_signals[NO_EXPOSE_EVENT] =
979     g_signal_newc ("no_expose_event",
980                   G_TYPE_FROM_CLASS(object_class),
981                   G_SIGNAL_RUN_LAST,
982                   G_STRUCT_OFFSET(GtkWidgetClass, no_expose_event),
983                   _gtk_boolean_handled_accumulator, NULL,
984                   gtk_marshal_BOOLEAN__BOXED,
985                   G_TYPE_BOOLEAN, 1,
986                   GDK_TYPE_EVENT);
987   widget_signals[WINDOW_STATE_EVENT] =
988     g_signal_newc ("window_state_event",
989                   G_TYPE_FROM_CLASS(object_class),
990                   G_SIGNAL_RUN_LAST,
991                   G_STRUCT_OFFSET(GtkWidgetClass, window_state_event),
992                   _gtk_boolean_handled_accumulator, NULL,
993                   gtk_marshal_BOOLEAN__BOXED,
994                   G_TYPE_BOOLEAN, 1,
995                   GDK_TYPE_EVENT);
996   widget_signals[POPUP_MENU] =
997     gtk_signal_new ("popup_menu",
998                     GTK_RUN_LAST | GTK_RUN_ACTION,
999                     GTK_CLASS_TYPE (object_class),
1000                     GTK_SIGNAL_OFFSET (GtkWidgetClass, popup_menu),
1001                     gtk_marshal_NONE__NONE,
1002                     GTK_TYPE_NONE, 0);
1003   
1004   binding_set = gtk_binding_set_by_class (klass);
1005
1006   gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1007                                 "popup_menu", 0);
1008
1009   gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1010                                 "popup_menu", 0);  
1011
1012   gtk_widget_class_install_style_property (klass,
1013                                            g_param_spec_boolean ("interior_focus",
1014                                                                  _("Interior Focus"),
1015                                                                  _("Whether to draw the focus indicator inside widgets."),
1016                                                                  TRUE,
1017                                                                  G_PARAM_READABLE));
1018 }
1019
1020 static void
1021 gtk_widget_set_property (GObject         *object,
1022                          guint            prop_id,
1023                          const GValue    *value,
1024                          GParamSpec      *pspec)
1025 {
1026   GtkWidget *widget;
1027   GtkWidgetAuxInfo *aux_info;
1028
1029   widget = GTK_WIDGET (object);
1030
1031   switch (prop_id)
1032     {
1033       guint32 saved_flags;
1034       
1035     case PROP_NAME:
1036       gtk_widget_set_name (widget, g_value_get_string (value));
1037       break;
1038     case PROP_PARENT:
1039       gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1040       break;
1041     case PROP_X:
1042       aux_info = _gtk_widget_get_aux_info (widget, TRUE);
1043       if (g_value_get_int (value) == -1)
1044         aux_info->x_set = FALSE;
1045       else
1046         {
1047           aux_info->x_set = TRUE;
1048           aux_info->x = g_value_get_int (value);
1049         }
1050       gtk_widget_do_uposition (widget);
1051       break;
1052     case PROP_Y:
1053       aux_info = _gtk_widget_get_aux_info (widget, TRUE);
1054       if (g_value_get_int (value) == -1)
1055         aux_info->y_set = FALSE;
1056       else
1057         {
1058           aux_info->y_set = TRUE;
1059           aux_info->y = g_value_get_int (value);
1060         }
1061       gtk_widget_do_uposition (widget);
1062       break;
1063     case PROP_WIDTH:
1064       gtk_widget_set_usize (widget, g_value_get_int (value), -2);
1065       break;
1066     case PROP_HEIGHT:
1067       gtk_widget_set_usize (widget, -2, g_value_get_int (value));
1068       break;
1069     case PROP_VISIBLE:
1070       if (g_value_get_boolean (value))
1071         gtk_widget_show (widget);
1072       else
1073         gtk_widget_hide (widget);
1074       break;
1075     case PROP_SENSITIVE:
1076       gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1077       break;
1078     case PROP_APP_PAINTABLE:
1079       gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1080       break;
1081     case PROP_CAN_FOCUS:
1082       saved_flags = GTK_WIDGET_FLAGS (widget);
1083       if (g_value_get_boolean (value))
1084         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1085       else
1086         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1087       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1088         gtk_widget_queue_resize (widget);
1089       break;
1090     case PROP_HAS_FOCUS:
1091       if (g_value_get_boolean (value))
1092         gtk_widget_grab_focus (widget);
1093       break;
1094     case PROP_CAN_DEFAULT:
1095       saved_flags = GTK_WIDGET_FLAGS (widget);
1096       if (g_value_get_boolean (value))
1097         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1098       else
1099         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1100       if (saved_flags != GTK_WIDGET_FLAGS (widget))
1101         gtk_widget_queue_resize (widget);
1102       break;
1103     case PROP_HAS_DEFAULT:
1104       if (g_value_get_boolean (value))
1105         gtk_widget_grab_default (widget);
1106       break;
1107     case PROP_RECEIVES_DEFAULT:
1108       if (g_value_get_boolean (value))
1109         GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1110       else
1111         GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1112       break;
1113     case PROP_COMPOSITE_CHILD:
1114       if (g_value_get_boolean (value))
1115         GTK_WIDGET_SET_FLAGS (widget, GTK_COMPOSITE_CHILD);
1116       else
1117         GTK_WIDGET_UNSET_FLAGS (widget, GTK_COMPOSITE_CHILD);
1118       break;
1119     case PROP_STYLE:
1120       gtk_widget_set_style (widget, g_value_get_object (value));
1121       break;
1122     case PROP_EVENTS:
1123       if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1124         gtk_widget_set_events (widget, g_value_get_flags (value));
1125       break;
1126     case PROP_EXTENSION_EVENTS:
1127       gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1128       break;
1129     default:
1130       break;
1131     }
1132 }
1133
1134 /*****************************************
1135  * gtk_widget_get_property:
1136  *
1137  *   arguments:
1138  *
1139  *   results:
1140  *****************************************/
1141
1142 static void
1143 gtk_widget_get_property (GObject         *object,
1144                          guint            prop_id,
1145                          GValue          *value,
1146                          GParamSpec      *pspec)
1147 {
1148   GtkWidget *widget;
1149
1150   widget = GTK_WIDGET (object);
1151   
1152   switch (prop_id)
1153     {
1154       GtkWidgetAuxInfo *aux_info;
1155       gint *eventp;
1156       GdkExtensionMode *modep;
1157
1158     case PROP_NAME:
1159       if (widget->name)
1160         g_value_set_string (value, widget->name);
1161       else
1162         g_value_set_string (value, "");
1163       break;
1164     case PROP_PARENT:
1165       if (widget->parent)
1166         g_value_set_object (value, G_OBJECT (widget->parent));
1167       else
1168         g_value_set_object (value, NULL);
1169       break;
1170     case PROP_X:
1171       aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1172       if (!aux_info || !aux_info->x_set)
1173         g_value_set_int (value, -1);
1174       else
1175         g_value_set_int (value, aux_info->x);
1176       break;
1177     case PROP_Y:
1178       aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1179       if (!aux_info || !aux_info->y_set)
1180         g_value_set_int (value, -1);
1181       else
1182         g_value_set_int (value, aux_info->y);
1183       break;
1184     case PROP_WIDTH:
1185       aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1186       if (!aux_info)
1187         g_value_set_int (value, -1);
1188       else
1189         g_value_set_int (value, aux_info->width);
1190       break;
1191     case PROP_HEIGHT:
1192       aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1193       if (!aux_info)
1194         g_value_set_int (value, -1);
1195       else
1196         g_value_set_int (value, aux_info->height);
1197       break;
1198     case PROP_VISIBLE:
1199       g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1200       break;
1201     case PROP_SENSITIVE:
1202       g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1203       break;
1204     case PROP_APP_PAINTABLE:
1205       g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1206       break;
1207     case PROP_CAN_FOCUS:
1208       g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1209       break;
1210     case PROP_HAS_FOCUS:
1211       g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1212       break;
1213     case PROP_CAN_DEFAULT:
1214       g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1215       break;
1216     case PROP_HAS_DEFAULT:
1217       g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1218       break;
1219     case PROP_RECEIVES_DEFAULT:
1220       g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1221       break;
1222     case PROP_COMPOSITE_CHILD:
1223       g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1224       break;
1225     case PROP_STYLE:
1226       g_value_set_object (value, G_OBJECT (gtk_widget_get_style (widget)));
1227       break;
1228     case PROP_EVENTS:
1229       eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
1230       if (!eventp)
1231         g_value_set_int (value, 0);
1232       else
1233         g_value_set_int (value, *eventp);
1234       break;
1235     case PROP_EXTENSION_EVENTS:
1236       modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
1237       if (!modep)
1238         g_value_set_enum (value, 0);
1239       else
1240         g_value_set_enum (value, (GdkExtensionMode) *modep);
1241       break;
1242     default:
1243       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1244       break;
1245     }
1246 }
1247
1248 /*****************************************
1249  * gtk_widget_init:
1250  *
1251  *   arguments:
1252  *
1253  *   results:
1254  *****************************************/
1255
1256 static void
1257 gtk_widget_init (GtkWidget *widget)
1258 {
1259   GdkColormap *colormap;
1260   
1261   GTK_PRIVATE_FLAGS (widget) = 0;
1262   widget->state = GTK_STATE_NORMAL;
1263   widget->saved_state = GTK_STATE_NORMAL;
1264   widget->name = NULL;
1265   widget->requisition.width = 0;
1266   widget->requisition.height = 0;
1267   widget->allocation.x = -1;
1268   widget->allocation.y = -1;
1269   widget->allocation.width = 1;
1270   widget->allocation.height = 1;
1271   widget->window = NULL;
1272   widget->parent = NULL;
1273
1274   GTK_WIDGET_SET_FLAGS (widget,
1275                         GTK_SENSITIVE |
1276                         GTK_PARENT_SENSITIVE |
1277                         (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1278                         GTK_DOUBLE_BUFFERED);
1279
1280   widget->style = gtk_widget_peek_style ();
1281   gtk_style_ref (widget->style);
1282   
1283   colormap = gtk_widget_peek_colormap ();
1284   
1285   if (colormap != gtk_widget_get_default_colormap ())
1286     gtk_widget_set_colormap (widget, colormap);
1287 }
1288
1289
1290 /**
1291  * gtk_widget_new:
1292  * @type: type ID of the widget to create
1293  * @first_property_name: name of first property to set
1294  * @Varargs: value of first property, followed by more properties, NULL-terminated
1295  * 
1296  * This is a convenience function for creating a widget and setting
1297  * its properties in one go. For example you might write:
1298  * gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1299  * 0.0, NULL) to create a left-aligned label. Equivalent to
1300  * gtk_object_new(), but returns a widget so you don't have to
1301  * cast the object yourself.
1302  * 
1303  * Return value: a new #GtkWidget of type @widget_type
1304  **/
1305 GtkWidget*
1306 gtk_widget_new (GtkType      type,
1307                 const gchar *first_property_name,
1308                 ...)
1309 {
1310   GtkWidget *widget;
1311   va_list var_args;
1312   
1313   g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1314   
1315   va_start (var_args, first_property_name);
1316   widget = g_object_new_valist (type, first_property_name, var_args);
1317   va_end (var_args);
1318
1319   return widget;
1320 }
1321
1322 /**
1323  * gtk_widget_set:
1324  * @widget: a #GtkWidget
1325  * @first_property_name: name of first property to set
1326  * @Varargs: value of first property, followed by more properties, NULL-terminated
1327  * 
1328  * Like gtk_object_set() - there's no reason to use this instead of
1329  * gtk_object_set().
1330  **/
1331 void
1332 gtk_widget_set (GtkWidget   *widget,
1333                 const gchar *first_property_name,
1334                 ...)
1335 {
1336   va_list var_args;
1337
1338   g_return_if_fail (GTK_IS_WIDGET (widget));
1339
1340   va_start (var_args, first_property_name);
1341   g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1342   va_end (var_args);
1343 }
1344
1345 static inline void         
1346 gtk_widget_queue_clear_child (GtkWidget *widget)
1347 {
1348   GtkWidget *parent;
1349
1350   parent = widget->parent;
1351   if (parent && GTK_WIDGET_DRAWABLE (parent))
1352     gtk_widget_queue_clear_area (parent,
1353                                  widget->allocation.x,
1354                                  widget->allocation.y,
1355                                  widget->allocation.width,
1356                                  widget->allocation.height);
1357 }
1358
1359 /**
1360  * gtk_widget_unparent:
1361  * @widget: a #GtkWidget
1362  * 
1363  * This function is only for use in widget implementations.
1364  * Should be called by implementations of the remove method
1365  * on #GtkContainer, to dissociate a child from the container.
1366  **/
1367 void
1368 gtk_widget_unparent (GtkWidget *widget)
1369 {
1370   GtkWidget *toplevel;
1371   GtkWidget *old_parent;
1372   
1373   g_return_if_fail (widget != NULL);
1374   g_return_if_fail (GTK_IS_WIDGET (widget));
1375   if (widget->parent == NULL)
1376     return;
1377   
1378   /* keep this function in sync with gtk_menu_detach()
1379    */
1380
1381   g_object_freeze_notify (G_OBJECT (widget));
1382
1383   /* unset focused and default children properly, this code
1384    * should eventually move into some gtk_window_unparent_branch() or
1385    * similar function.
1386    */
1387   
1388   toplevel = gtk_widget_get_toplevel (widget);
1389   if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1390     {
1391       gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1392
1393       if (GTK_IS_WINDOW (toplevel))
1394         {
1395           GtkWidget *child;
1396       
1397           child = GTK_WINDOW (toplevel)->focus_widget;
1398           
1399           while (child && child != widget)
1400             child = child->parent;
1401           
1402           if (child == widget)
1403             gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1404         }
1405     }
1406   if (GTK_IS_WINDOW (toplevel))
1407     {
1408       GtkWidget *child;
1409       
1410       child = GTK_WINDOW (toplevel)->default_widget;
1411       
1412       while (child && child != widget)
1413         child = child->parent;
1414       
1415       if (child == widget)
1416         gtk_window_set_default (GTK_WINDOW (toplevel), NULL);
1417     }
1418
1419   if (GTK_IS_RESIZE_CONTAINER (widget))
1420     gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
1421   
1422   /* Remove the widget and all its children from any ->resize_widgets list
1423    * of all the parents in our branch. This code should move into gtkcontainer.c
1424    * somwhen, since we mess around with ->resize_widgets, which is
1425    * actually not of our business.
1426    *
1427    * Two ways to make this prettier:
1428    *   Write a g_slist_conditional_remove (GSList, gboolean (*)(gpointer))
1429    *   Change resize_widgets to a GList
1430    */
1431   toplevel = widget->parent;
1432   while (toplevel)
1433     {
1434       GSList *slist;
1435       GSList *prev;
1436
1437       if (!GTK_CONTAINER (toplevel)->resize_widgets)
1438         {
1439           toplevel = toplevel->parent;
1440           continue;
1441         }
1442
1443       prev = NULL;
1444       slist = GTK_CONTAINER (toplevel)->resize_widgets;
1445       while (slist)
1446         {
1447           GtkWidget *child;
1448           GtkWidget *parent;
1449           GSList *last;
1450
1451           last = slist;
1452           slist = last->next;
1453           child = last->data;
1454           
1455           parent = child;
1456           while (parent && (parent != widget))
1457             parent = parent->parent;
1458           
1459           if (parent == widget)
1460             {
1461               GTK_PRIVATE_UNSET_FLAG (child, GTK_RESIZE_NEEDED);
1462               
1463               if (prev)
1464                 prev->next = slist;
1465               else
1466                 GTK_CONTAINER (toplevel)->resize_widgets = slist;
1467               
1468               g_slist_free_1 (last);
1469             }
1470           else
1471             prev = last;
1472         }
1473
1474       toplevel = toplevel->parent;
1475     }
1476
1477   gtk_widget_queue_clear_child (widget);
1478
1479   /* Reset the width and height here, to force reallocation if we
1480    * get added back to a new parent. This won't work if our new
1481    * allocation is smaller than 1x1 and we actually want a size of 1x1...
1482    * (would 0x0 be OK here?)
1483    */
1484   widget->allocation.width = 1;
1485   widget->allocation.height = 1;
1486   
1487   if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1488     gtk_widget_unrealize (widget);
1489
1490   old_parent = widget->parent;
1491   widget->parent = NULL;
1492   gtk_widget_set_parent_window (widget, NULL);
1493   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], old_parent);
1494   gtk_widget_propagate_hierarchy_changed (widget, NULL);
1495   g_object_notify (G_OBJECT (widget), "parent");
1496   g_object_thaw_notify (G_OBJECT (widget));
1497   gtk_widget_unref (widget);
1498 }
1499
1500 /**
1501  * gtk_widget_destroy:
1502  * @widget: a #GtkWidget
1503  *
1504  * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1505  * you don't have to cast the widget to #GtkObject. When a widget is
1506  * destroyed, it will break any references it holds to other objects.
1507  * If the widget is inside a container, the widget will be removed
1508  * from the container. If the widget is a toplevel (derived from
1509  * #GtkWindow), it will be removed from the list of toplevels, and the
1510  * reference GTK+ holds to it will be removed. Removing a
1511  * widget from its container or the list of toplevels results in the
1512  * widget being finalized, unless you've added additional references
1513  * to the widget with gtk_object_ref().
1514  *
1515  * In most cases, only toplevel widgets (windows) require explicit
1516  * destruction, because when you destroy a toplevel its children will
1517  * be destroyed as well.
1518  * 
1519  **/
1520 void
1521 gtk_widget_destroy (GtkWidget *widget)
1522 {
1523   g_return_if_fail (widget != NULL);
1524   g_return_if_fail (GTK_IS_WIDGET (widget));
1525
1526   gtk_object_destroy ((GtkObject*) widget);
1527 }
1528
1529 /**
1530  * gtk_widget_destroyed:
1531  * @widget: a #GtkWidget
1532  * @widget_pointer: address of a variable that contains @widget
1533  *
1534  * This function sets *@widget_pointer to NULL if @widget_pointer !=
1535  * NULL.  It's intended to be used as a callback connected to the
1536  * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1537  * as a signal handler, and pass the address of your widget variable
1538  * as user data. Then when the widget is destroyed, the variable will
1539  * be set to NULL. Useful for example to avoid multiple copies
1540  * of the same dialog.
1541  * 
1542  **/
1543 void
1544 gtk_widget_destroyed (GtkWidget      *widget,
1545                       GtkWidget      **widget_pointer)
1546 {
1547   /* Don't make any assumptions about the
1548    *  value of widget!
1549    *  Even check widget_pointer.
1550    */
1551   if (widget_pointer)
1552     *widget_pointer = NULL;
1553 }
1554
1555 /**
1556  * gtk_widget_show:
1557  * @widget: a #GtkWidget
1558  * 
1559  * Flags a widget to be displayed. Any widget that isn't shown will
1560  * not appear on the screen. If you want to show all the widgets in a
1561  * container, it's easier to call gtk_widget_show_all() on the
1562  * container, instead of individually showing the widgets.
1563  *
1564  * Remember that you have to show the containers containing a widget,
1565  * in addition to the widget itself, before it will appear onscreen.
1566  *
1567  * When a toplevel container is shown, it is immediately realized and
1568  * mapped; other shown widgets are realized and mapped when their
1569  * toplevel container is realized and mapped.
1570  * 
1571  **/
1572 void
1573 gtk_widget_show (GtkWidget *widget)
1574 {
1575   g_return_if_fail (widget != NULL);
1576   g_return_if_fail (GTK_IS_WIDGET (widget));
1577   
1578   if (!GTK_WIDGET_VISIBLE (widget))
1579     {
1580       g_object_ref (G_OBJECT (widget));
1581       if (!GTK_WIDGET_TOPLEVEL (widget))
1582         gtk_widget_queue_resize (widget);
1583       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SHOW]);
1584       g_object_notify (G_OBJECT (widget), "visible");
1585       g_object_unref (G_OBJECT (widget));
1586     }
1587 }
1588
1589 static void
1590 gtk_widget_real_show (GtkWidget *widget)
1591 {
1592   g_return_if_fail (widget != NULL);
1593   g_return_if_fail (GTK_IS_WIDGET (widget));
1594   
1595   if (!GTK_WIDGET_VISIBLE (widget))
1596     {
1597       GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1598
1599       if (widget->parent &&
1600           GTK_WIDGET_MAPPED (widget->parent) &&
1601           !GTK_WIDGET_MAPPED (widget))
1602         gtk_widget_map (widget);
1603     }
1604 }
1605
1606 static void
1607 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1608 {
1609   *flag = TRUE;
1610   gtk_signal_disconnect_by_data (GTK_OBJECT (widget), flag);
1611 }
1612
1613 /**
1614  * gtk_widget_show_now:
1615  * @widget: a #GtkWidget
1616  * 
1617  * Shows a widget. If the widget is an unmapped toplevel widget
1618  * (i.e. a #GtkWindow that has not yet been shown), enter the main
1619  * loop and wait for the window to actually be mapped. Be careful;
1620  * because the main loop is running, anything can happen during
1621  * this function.
1622  **/
1623 void
1624 gtk_widget_show_now (GtkWidget *widget)
1625 {
1626   gint flag = FALSE;
1627   
1628   g_return_if_fail (widget != NULL);
1629   g_return_if_fail (GTK_IS_WIDGET (widget));
1630
1631   /* make sure we will get event */
1632   if (!GTK_WIDGET_MAPPED (widget) &&
1633       GTK_WIDGET_TOPLEVEL (widget))
1634     {
1635       gtk_widget_show (widget);
1636
1637       gtk_signal_connect (GTK_OBJECT (widget), "map_event",
1638                           GTK_SIGNAL_FUNC (gtk_widget_show_map_callback), 
1639                           &flag);
1640
1641       while (!flag)
1642         gtk_main_iteration();
1643     }
1644   else
1645     gtk_widget_show (widget);
1646 }
1647
1648 /**
1649  * gtk_widget_hide:
1650  * @widget: a #GtkWidget
1651  * 
1652  * Reverses the effects of gtk_widget_show(), causing the widget to be
1653  * hidden (invisible to the user).
1654  **/
1655 void
1656 gtk_widget_hide (GtkWidget *widget)
1657 {
1658   g_return_if_fail (widget != NULL);
1659   g_return_if_fail (GTK_IS_WIDGET (widget));
1660   
1661   if (GTK_WIDGET_VISIBLE (widget))
1662     {
1663       gtk_widget_ref (widget);
1664       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[HIDE]);
1665       if (!GTK_WIDGET_TOPLEVEL (widget) && !GTK_OBJECT_DESTROYED (widget))
1666         gtk_widget_queue_resize (widget);
1667       g_object_notify (G_OBJECT (widget), "visible");
1668       gtk_widget_unref (widget);
1669     }
1670 }
1671
1672 static void
1673 gtk_widget_real_hide (GtkWidget *widget)
1674 {
1675   g_return_if_fail (widget != NULL);
1676   g_return_if_fail (GTK_IS_WIDGET (widget));
1677   
1678   if (GTK_WIDGET_VISIBLE (widget))
1679     {
1680       GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1681       
1682       if (GTK_WIDGET_MAPPED (widget))
1683         gtk_widget_unmap (widget);
1684     }
1685 }
1686
1687 /**
1688  * gtk_widget_hide_on_delete:
1689  * @widget: a #GtkWidget
1690  * 
1691  * Utility function; intended to be connected to the "delete_event"
1692  * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
1693  * argument, then returns %TRUE. If connected to "delete_event",
1694  * the result is that clicking the window manager close button for
1695  * will hide but not destroy the window. By default, GTK+ destroys
1696  * windows when "delete_event" is received.
1697  * 
1698  * Return value: %TRUE
1699  **/
1700 gboolean
1701 gtk_widget_hide_on_delete (GtkWidget      *widget)
1702 {
1703   g_return_val_if_fail (widget != NULL, FALSE);
1704   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1705   
1706   gtk_widget_hide (widget);
1707   
1708   return TRUE;
1709 }
1710
1711 /**
1712  * gtk_widget_show_all:
1713  * @widget: a #GtkWidget
1714  * 
1715  * Recursively shows a widget, and any child widgets (if the widget is
1716  * a container).
1717  **/
1718 void
1719 gtk_widget_show_all (GtkWidget *widget)
1720 {
1721   GtkWidgetClass *class;
1722
1723   g_return_if_fail (widget != NULL);
1724   g_return_if_fail (GTK_IS_WIDGET (widget));
1725
1726   class = GTK_WIDGET_GET_CLASS (widget);
1727
1728   if (class->show_all)
1729     class->show_all (widget);
1730 }
1731
1732 /**
1733  * gtk_widget_hide_all:
1734  * @widget: a #GtkWidget
1735  * 
1736  * Recursively hides a widget and any child widgets.
1737  **/
1738 void
1739 gtk_widget_hide_all (GtkWidget *widget)
1740 {
1741   GtkWidgetClass *class;
1742
1743   g_return_if_fail (widget != NULL);
1744   g_return_if_fail (GTK_IS_WIDGET (widget));
1745
1746   class = GTK_WIDGET_GET_CLASS (widget);
1747
1748   if (class->hide_all)
1749     class->hide_all (widget);
1750 }
1751
1752 /**
1753  * gtk_widget_map:
1754  * @widget: a #GtkWidget
1755  * 
1756  * This function is only for use in widget implementations. Causes
1757  * a widget to be mapped if it isn't already.
1758  * 
1759  **/
1760 void
1761 gtk_widget_map (GtkWidget *widget)
1762 {
1763   g_return_if_fail (GTK_IS_WIDGET (widget));
1764   g_return_if_fail (GTK_WIDGET_VISIBLE (widget) == TRUE);
1765   
1766   if (!GTK_WIDGET_MAPPED (widget))
1767     {
1768       if (!GTK_WIDGET_REALIZED (widget))
1769         gtk_widget_realize (widget);
1770
1771       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[MAP]);
1772
1773       if (GTK_WIDGET_NO_WINDOW (widget))
1774         gtk_widget_queue_draw (widget);
1775     }
1776 }
1777
1778 /**
1779  * gtk_widget_unmap:
1780  * @widget: a #GtkWidget
1781  *
1782  * This function is only for use in widget implementations. Causes
1783  * a widget to be unmapped if it's currently mapped.
1784  * 
1785  **/
1786 void
1787 gtk_widget_unmap (GtkWidget *widget)
1788 {
1789   g_return_if_fail (widget != NULL);
1790   g_return_if_fail (GTK_IS_WIDGET (widget));
1791   
1792   if (GTK_WIDGET_MAPPED (widget))
1793     {
1794       if (GTK_WIDGET_NO_WINDOW (widget))
1795         gtk_widget_queue_clear_child (widget);
1796       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNMAP]);
1797     }
1798 }
1799
1800 /**
1801  * gtk_widget_realize:
1802  * @widget: a #GtkWidget
1803  * 
1804  * Creates the GDK (windowing system) resources associated with a
1805  * widget.  For example, widget->window will be created when a widget
1806  * is realized.  Normally realization happens implicitly; if you show
1807  * a widget and all its parent containers, then the widget will be
1808  * realized and mapped automatically.
1809  * 
1810  * Realizing a widget requires all
1811  * the widget's parent widgets to be realized; calling
1812  * gtk_widget_realize() realizes the widget's parents in addition to
1813  * @widget itself. If a widget is not yet inside a toplevel window
1814  * when you realize it, bad things will happen.
1815  *
1816  * This function is primarily used in widget implementations, and
1817  * isn't very useful otherwise. Many times when you think you might
1818  * need it, a better approach is to connect to a signal that will be
1819  * called after the widget is realized automatically, such as
1820  * "expose_event". Or simply gtk_signal_connect_after() to the
1821  * "realize" signal.
1822  *  
1823  **/
1824 void
1825 gtk_widget_realize (GtkWidget *widget)
1826 {
1827   gint events;
1828   GdkExtensionMode mode;
1829   GtkWidgetShapeInfo *shape_info;
1830   
1831   g_return_if_fail (widget != NULL);
1832   g_return_if_fail (GTK_IS_WIDGET (widget));
1833   
1834   if (!GTK_WIDGET_REALIZED (widget))
1835     {
1836       /*
1837         if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1838           g_message ("gtk_widget_realize(%s)", gtk_type_name (GTK_WIDGET_TYPE (widget)));
1839       */
1840
1841       if (widget->parent == NULL &&
1842           !GTK_WIDGET_TOPLEVEL (widget))
1843         g_warning ("Calling gtk_widget_realize() on a widget that isn't "
1844                    "inside a toplevel window is not going to work very well. "
1845                    "Widgets must be inside a toplevel container before realizing them.");
1846       
1847       if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
1848         gtk_widget_realize (widget->parent);
1849
1850       gtk_widget_ensure_style (widget);
1851       
1852       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[REALIZE]);
1853       
1854       if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1855         {
1856           shape_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_shape_info);
1857           gdk_window_shape_combine_mask (widget->window,
1858                                          shape_info->shape_mask,
1859                                          shape_info->offset_x,
1860                                          shape_info->offset_y);
1861         }
1862       
1863       if (!GTK_WIDGET_NO_WINDOW (widget))
1864         {
1865           mode = gtk_widget_get_extension_events (widget);
1866           if (mode != GDK_EXTENSION_EVENTS_NONE)
1867             {
1868               events = gtk_widget_get_events (widget);
1869               gdk_input_set_extension_events (widget->window, events, mode);
1870             }
1871         }
1872       
1873     }
1874 }
1875
1876 /**
1877  * gtk_widget_unrealize:
1878  * @widget: a #GtkWidget
1879  *
1880  * This function is only useful in widget implementations.
1881  * Causes a widget to be unrealized (frees all GDK resources
1882  * associated with the widget, such as widget->window).
1883  * 
1884  **/
1885 void
1886 gtk_widget_unrealize (GtkWidget *widget)
1887 {
1888   g_return_if_fail (widget != NULL);
1889   g_return_if_fail (GTK_IS_WIDGET (widget));
1890
1891   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1892     gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
1893
1894   if (GTK_WIDGET_REALIZED (widget))
1895     {
1896       gtk_widget_ref (widget);
1897       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNREALIZE]);
1898       GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
1899       gtk_widget_unref (widget);
1900     }
1901 }
1902
1903 /*****************************************
1904  * Draw queueing.
1905  *****************************************/
1906
1907 /**
1908  * gtk_widget_queue_draw_area:
1909  * @widget: a #GtkWidget
1910  * @x: x coordinate of upper-left corner of rectangle to redraw
1911  * @y: y coordinate of upper-left corner of rectangle to redraw
1912  * @width: width of region to draw
1913  * @height: height of region to draw
1914  *
1915  * Invalidates the rectangular area of @widget defined by @x, @y,
1916  * @width and @height by calling gdk_window_invalidate_rect() on the
1917  * widget's window and all its child windows.  Once the main loop
1918  * becomes idle (after the current batch of events has been processed,
1919  * roughly), the window will receive expose events for the union of
1920  * all regions that have been invalidated.
1921  *
1922  * Normally you would only use this function in widget
1923  * implementations. You might also use it, or
1924  * gdk_window_invalidate_rect() directly, to schedule a redraw of a
1925  * #GtkDrawingArea or some portion thereof.
1926  *
1927  * Frequently you can just call gdk_window_invalidate_rect() or
1928  * gdk_window_invalidate_region() instead of this function. Those
1929  * functions will invalidate only a single window, instead of the
1930  * widget and all its children.
1931  *
1932  * The advantage of adding to the invalidated region compared to
1933  * simply drawing immediately is efficiency; using an invalid region
1934  * ensures that you only have to redraw one time.
1935  * 
1936  **/
1937 void       
1938 gtk_widget_queue_draw_area (GtkWidget *widget,
1939                             gint       x,
1940                             gint       y,
1941                             gint       width,
1942                             gint       height)
1943 {
1944   g_return_if_fail (widget != NULL);
1945   g_return_if_fail (GTK_IS_WIDGET (widget));
1946
1947   gtk_widget_queue_clear_area (widget, x, y, width, height);
1948 }
1949
1950 /**
1951  * gtk_widget_queue_draw:
1952  * @widget: a #GtkWidget
1953  *
1954  * Equivalent to calling gtk_widget_queue_draw_area() for the
1955  * entire area of a widget.
1956  * 
1957  **/
1958 void       
1959 gtk_widget_queue_draw (GtkWidget *widget)
1960 {
1961   g_return_if_fail (widget != NULL);
1962   g_return_if_fail (GTK_IS_WIDGET (widget));
1963
1964   gtk_widget_queue_clear (widget);
1965 }
1966
1967 /* Invalidates the given area (allocation-relative-coordinates)
1968  * in all of the widget's windows
1969  */
1970 /**
1971  * gtk_widget_queue_clear_area:
1972  * @widget: a #GtkWidget
1973  * @x: x coordinate of upper-left corner of rectangle to redraw
1974  * @y: y coordinate of upper-left corner of rectangle to redraw
1975  * @width: width of region to draw
1976  * @height: height of region to draw
1977  * 
1978  * DEPRECATED. This function is no longer different from
1979  * gtk_widget_queue_draw_area(), though it once was. Now it just calls
1980  * gtk_widget_queue_draw_area(). Originally
1981  * gtk_widget_queue_clear_area() would force a redraw of the
1982  * background for GTK_NO_WINDOW widgets, and
1983  * gtk_widget_queue_draw_area() would not. Now both functions ensure
1984  * the background will be redrawn.
1985  * 
1986  **/
1987 void       
1988 gtk_widget_queue_clear_area (GtkWidget *widget,
1989                              gint       x,
1990                              gint       y,
1991                              gint       width,
1992                              gint       height)
1993 {
1994   GdkRectangle invalid_rect;
1995   
1996   g_return_if_fail (widget != NULL);
1997   g_return_if_fail (GTK_IS_WIDGET (widget));
1998
1999   if (!(widget->window && gdk_window_is_viewable (widget->window)))
2000     return;
2001
2002   /* Find the correct widget */
2003
2004   if (!GTK_WIDGET_NO_WINDOW (widget))
2005     {
2006       if (widget->parent)
2007         {
2008           /* Translate widget relative to window-relative */
2009
2010           gint wx, wy, wwidth, wheight;
2011           
2012           gdk_window_get_position (widget->window, &wx, &wy);
2013           x -= wx - widget->allocation.x;
2014           y -= wy - widget->allocation.y;
2015           
2016           gdk_window_get_size (widget->window, &wwidth, &wheight);
2017
2018           if (x + width <= 0 || y + height <= 0 ||
2019               x >= wwidth || y >= wheight)
2020             return;
2021           
2022           if (x < 0)
2023             {
2024               width += x;  x = 0;
2025             }
2026           if (y < 0)
2027             {
2028               height += y; y = 0;
2029             }
2030           if (x + width > wwidth)
2031             width = wwidth - x;
2032           if (y + height > wheight)
2033             height = wheight - y;
2034         }
2035     }
2036
2037   invalid_rect.x = x;
2038   invalid_rect.y = y;
2039   invalid_rect.width = width;
2040   invalid_rect.height = height;
2041   
2042   gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2043 }
2044
2045 /**
2046  * gtk_widget_queue_clear:
2047  * @widget: a #GtkWidget
2048  * 
2049  * DEPRECATED. Use gtk_widget_queue_draw() instead.
2050  **/
2051 void       
2052 gtk_widget_queue_clear (GtkWidget *widget)
2053 {
2054   g_return_if_fail (widget != NULL);
2055   g_return_if_fail (GTK_IS_WIDGET (widget));
2056
2057   if (widget->allocation.width || widget->allocation.height)
2058     {
2059       if (GTK_WIDGET_NO_WINDOW (widget))
2060         gtk_widget_queue_clear_area (widget, widget->allocation.x,
2061                                      widget->allocation.y,
2062                                      widget->allocation.width, 
2063                                      widget->allocation.height);
2064       else
2065         gtk_widget_queue_clear_area (widget, 0, 0, 
2066                                      widget->allocation.width, 
2067                                      widget->allocation.height);
2068     }
2069 }
2070
2071 /**
2072  * gtk_widget_queue_resize:
2073  * @widget: a #GtkWidget
2074  *
2075  * This function is only for use in widget implementations.
2076  * Flags a widget to have its size renegotiated; should
2077  * be called when a widget for some reason has a new size request.
2078  * For example, when you change the text in a #GtkLabel, #GtkLabel
2079  * queues a resize to ensure there's enough space for the new text.
2080  * 
2081  **/
2082 void
2083 gtk_widget_queue_resize (GtkWidget *widget)
2084 {
2085   g_return_if_fail (widget != NULL);
2086   g_return_if_fail (GTK_IS_WIDGET (widget));
2087
2088   gtk_widget_queue_clear (widget);
2089
2090   _gtk_size_group_queue_resize (widget);
2091 }
2092
2093 /**
2094  * gtk_widget_draw:
2095  * @widget: a #GtkWidget
2096  * @area: area to draw
2097  *
2098  * DEPRECATED. In GTK+ 1.2, this function would immediately render the
2099  * region @area of a widget, by invoking the virtual draw method of a
2100  * widget. In GTK+ 2.0, the draw method is gone, and instead
2101  * gtk_widget_draw() simply invalidates the specified region of the
2102  * widget, then updates the invalid region of the widget immediately.
2103  * Usually you don't want to update the region immediately for
2104  * performance reasons, so in general gtk_widget_queue_draw_area() is
2105  * a better choice if you want to draw a region of a widget.
2106  * 
2107  **/
2108 void
2109 gtk_widget_draw (GtkWidget    *widget,
2110                  GdkRectangle *area)
2111 {
2112   g_return_if_fail (widget != NULL);
2113   g_return_if_fail (GTK_IS_WIDGET (widget));
2114
2115   if (GTK_WIDGET_DRAWABLE (widget))
2116     {
2117       if (area)
2118         gtk_widget_queue_draw_area (widget,
2119                                     area->x, area->y,
2120                                     area->width, area->height);
2121       else
2122         gtk_widget_queue_draw (widget);
2123
2124       gdk_window_process_updates (widget->window, TRUE);
2125     }
2126 }
2127
2128 /**
2129  * gtk_widget_size_request:
2130  * @widget: a #GtkWidget
2131  * @requisition: a #GtkRequisition to be filled in
2132  * 
2133  * This function is only used when implementing a #GtkContainer subclass.
2134  * Obtains the preferred size of a widget. The container uses this
2135  * information to arrange its child widgets and decide what size allocations
2136  * to give them with gtk_widget_size_allocate().
2137  **/
2138 void
2139 gtk_widget_size_request (GtkWidget      *widget,
2140                          GtkRequisition *requisition)
2141 {
2142   g_return_if_fail (widget != NULL);
2143   g_return_if_fail (GTK_IS_WIDGET (widget));
2144
2145 #ifdef G_ENABLE_DEBUG
2146   if (requisition == &widget->requisition)
2147     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.");
2148 #endif /* G_ENABLE_DEBUG */
2149
2150   _gtk_size_group_compute_requisition (widget, requisition);
2151
2152 #if 0  
2153   if (requisition)
2154     gtk_widget_get_child_requisition (widget, requisition);
2155
2156   gtk_widget_unref (widget);
2157 #endif  
2158 }
2159
2160 /**
2161  * gtk_widget_get_child_requisition:
2162  * @widget: a #GtkWidget
2163  * @requisition: a #GtkRequisition to be filled in
2164  * 
2165  * This function is only for use in widget implementations. Obtains
2166  * @widget->requisition, unless someone has forced a particular
2167  * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2168  * case it returns that geometry instead of the widget's requisition.
2169  **/
2170 void
2171 gtk_widget_get_child_requisition (GtkWidget      *widget,
2172                                   GtkRequisition *requisition)
2173 {
2174   _gtk_size_group_get_child_requisition (widget, requisition);
2175 }
2176
2177 /**
2178  * gtk_widget_size_allocate:
2179  * @widget: a #GtkWidget
2180  * @allocation: position and size to be allocated to @widget
2181  *
2182  * This function is only used by #GtkContainer subclasses, to assign a size
2183  * and position to their child widgets. 
2184  * 
2185  **/
2186 void
2187 gtk_widget_size_allocate (GtkWidget     *widget,
2188                           GtkAllocation *allocation)
2189 {
2190   GtkWidgetAuxInfo *aux_info;
2191   GtkAllocation real_allocation;
2192   gboolean needs_draw = FALSE;
2193   
2194   g_return_if_fail (widget != NULL);
2195   g_return_if_fail (GTK_IS_WIDGET (widget));
2196   
2197   real_allocation = *allocation;
2198   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2199   
2200   if (aux_info)
2201     {
2202       if (aux_info->x_set)
2203         real_allocation.x = aux_info->x;
2204       if (aux_info->y_set)
2205         real_allocation.y = aux_info->y;
2206     }
2207
2208   real_allocation.width = MAX (real_allocation.width, 1);
2209   real_allocation.height = MAX (real_allocation.height, 1);
2210
2211   if (real_allocation.width < 0 || real_allocation.height < 0)
2212     {
2213       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2214                  real_allocation.width,
2215                  real_allocation.height);
2216       real_allocation.width = 1;
2217       real_allocation.height = 1;
2218     }
2219   
2220   if (GTK_WIDGET_NO_WINDOW (widget))
2221     {
2222       if (widget->allocation.x != real_allocation.x ||
2223           widget->allocation.y != real_allocation.y ||
2224           widget->allocation.width != real_allocation.width ||
2225           widget->allocation.height != real_allocation.height)
2226         {
2227           gtk_widget_queue_clear_child (widget);
2228           needs_draw = TRUE;
2229         }
2230     }
2231   else if (widget->allocation.width != real_allocation.width ||
2232            widget->allocation.height != real_allocation.height)
2233     {
2234       needs_draw = TRUE;
2235     }
2236
2237   if (GTK_IS_RESIZE_CONTAINER (widget))
2238     gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
2239
2240   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE], &real_allocation);
2241
2242   if (needs_draw)
2243     {
2244       gtk_widget_queue_draw (widget);
2245       if (widget->parent && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2246         gtk_widget_queue_draw (widget->parent);
2247     }
2248 }
2249
2250 static void
2251 gtk_widget_real_size_allocate (GtkWidget     *widget,
2252                                GtkAllocation *allocation)
2253 {
2254   g_return_if_fail (widget != NULL);
2255   g_return_if_fail (GTK_IS_WIDGET (widget));
2256
2257   widget->allocation = *allocation;
2258   
2259   if (GTK_WIDGET_REALIZED (widget) &&
2260       !GTK_WIDGET_NO_WINDOW (widget))
2261      {
2262         gdk_window_move_resize (widget->window,
2263                                 allocation->x, allocation->y,
2264                                 allocation->width, allocation->height);
2265      }
2266 }
2267
2268 static void
2269 gtk_widget_stop_add_accelerator (GtkWidget *widget)
2270 {
2271   g_return_if_fail (widget != NULL);
2272   g_return_if_fail (GTK_IS_WIDGET (widget));
2273
2274   gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[ADD_ACCELERATOR]);
2275 }
2276
2277 static void
2278 gtk_widget_stop_remove_accelerator (GtkWidget *widget)
2279 {
2280   g_return_if_fail (widget != NULL);
2281   g_return_if_fail (GTK_IS_WIDGET (widget));
2282
2283   gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[REMOVE_ACCELERATOR]);
2284 }
2285
2286 void
2287 gtk_widget_lock_accelerators (GtkWidget *widget)
2288 {
2289   g_return_if_fail (widget != NULL);
2290   g_return_if_fail (GTK_IS_WIDGET (widget));
2291   
2292   if (!gtk_widget_accelerators_locked (widget))
2293     {
2294       gtk_signal_connect (GTK_OBJECT (widget),
2295                           "add_accelerator",
2296                           GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2297                           NULL);
2298       gtk_signal_connect (GTK_OBJECT (widget),
2299                           "remove_accelerator",
2300                           GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2301                           NULL);
2302     }
2303 }
2304
2305 void
2306 gtk_widget_unlock_accelerators (GtkWidget *widget)
2307 {
2308   g_return_if_fail (widget != NULL);
2309   g_return_if_fail (GTK_IS_WIDGET (widget));
2310   
2311   if (gtk_widget_accelerators_locked (widget))
2312     {
2313       gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2314                                      GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2315                                      NULL);
2316       gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2317                                      GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2318                                      NULL);
2319     }
2320 }
2321
2322 gboolean
2323 gtk_widget_accelerators_locked (GtkWidget *widget)
2324 {
2325   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2326   
2327   return gtk_signal_handler_pending_by_func (GTK_OBJECT (widget),
2328                                              widget_signals[ADD_ACCELERATOR],
2329                                              TRUE,
2330                                              GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2331                                              NULL) > 0;
2332 }
2333
2334 void
2335 gtk_widget_add_accelerator (GtkWidget           *widget,
2336                             const gchar         *accel_signal,
2337                             GtkAccelGroup       *accel_group,
2338                             guint                accel_key,
2339                             guint                accel_mods,
2340                             GtkAccelFlags        accel_flags)
2341 {
2342   g_return_if_fail (widget != NULL);
2343   g_return_if_fail (GTK_IS_WIDGET (widget));
2344   g_return_if_fail (accel_group != NULL);
2345
2346   gtk_accel_group_add (accel_group,
2347                        accel_key,
2348                        accel_mods,
2349                        accel_flags,
2350                        (GtkObject*) widget,
2351                        accel_signal);
2352 }
2353
2354 void
2355 gtk_widget_remove_accelerator (GtkWidget           *widget,
2356                                GtkAccelGroup       *accel_group,
2357                                guint                accel_key,
2358                                guint                accel_mods)
2359 {
2360   g_return_if_fail (widget != NULL);
2361   g_return_if_fail (GTK_IS_WIDGET (widget));
2362   g_return_if_fail (accel_group != NULL);
2363
2364   gtk_accel_group_remove (accel_group,
2365                           accel_key,
2366                           accel_mods,
2367                           (GtkObject*) widget);
2368 }
2369
2370 void
2371 gtk_widget_remove_accelerators (GtkWidget           *widget,
2372                                 const gchar         *accel_signal,
2373                                 gboolean             visible_only)
2374 {
2375   GSList *slist;
2376   guint signal_id;
2377   
2378   g_return_if_fail (widget != NULL);
2379   g_return_if_fail (GTK_IS_WIDGET (widget));
2380   g_return_if_fail (accel_signal != NULL);
2381   
2382   signal_id = gtk_signal_lookup (accel_signal, GTK_OBJECT_TYPE (widget));
2383   g_return_if_fail (signal_id != 0);
2384   
2385   slist = gtk_accel_group_entries_from_object (GTK_OBJECT (widget));
2386   while (slist)
2387     {
2388       GtkAccelEntry *ac_entry;
2389       
2390       ac_entry = slist->data;
2391       slist = slist->next;
2392       if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE &&
2393           ac_entry->signal_id == signal_id)
2394         gtk_widget_remove_accelerator (GTK_WIDGET (widget),
2395                                        ac_entry->accel_group,
2396                                        ac_entry->accelerator_key,
2397                                        ac_entry->accelerator_mods);
2398     }
2399 }
2400
2401 guint
2402 gtk_widget_accelerator_signal (GtkWidget           *widget,
2403                                GtkAccelGroup       *accel_group,
2404                                guint                accel_key,
2405                                guint                accel_mods)
2406 {
2407   GtkAccelEntry *ac_entry;
2408
2409   g_return_val_if_fail (widget != NULL, 0);
2410   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
2411   g_return_val_if_fail (accel_group != NULL, 0);
2412
2413   ac_entry = gtk_accel_group_get_entry (accel_group, accel_key, accel_mods);
2414
2415   if (ac_entry && ac_entry->object == (GtkObject*) widget)
2416     return ac_entry->signal_id;
2417   return 0;
2418 }
2419
2420 gboolean
2421 gtk_widget_mnemonic_activate (GtkWidget *widget,
2422                               gboolean   group_cycling)
2423 {
2424   gboolean handled;
2425   
2426   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2427
2428   group_cycling = group_cycling != FALSE;
2429   if (!GTK_WIDGET_IS_SENSITIVE (widget))
2430     handled = TRUE;
2431   else
2432     gtk_signal_emit (GTK_OBJECT (widget),
2433                      widget_signals[ACTIVATE_MNEMONIC],
2434                      group_cycling,
2435                      &handled);
2436   return handled;
2437 }
2438
2439 static gboolean
2440 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
2441                                    gboolean   group_cycling)
2442 {
2443   if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
2444     gtk_widget_activate (widget);
2445   else if (GTK_WIDGET_CAN_FOCUS (widget))
2446     gtk_widget_grab_focus (widget);
2447   else
2448     {
2449       g_warning ("widget `%s' isn't suitable for mnemonic activation",
2450                  G_OBJECT_TYPE_NAME (widget));
2451       gdk_beep ();
2452     }
2453   return TRUE;
2454 }
2455
2456 static gboolean
2457 gtk_widget_real_key_press_event (GtkWidget         *widget,
2458                                  GdkEventKey       *event)
2459 {
2460   gboolean handled = FALSE;
2461
2462   g_return_val_if_fail (widget != NULL, handled);
2463   g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2464   g_return_val_if_fail (event != NULL, handled);
2465
2466   if (!handled)
2467     handled = gtk_bindings_activate (GTK_OBJECT (widget),
2468                                      event->keyval,
2469                                      event->state);
2470
2471   return handled;
2472 }
2473
2474 static gboolean
2475 gtk_widget_real_key_release_event (GtkWidget         *widget,
2476                                    GdkEventKey       *event)
2477 {
2478   gboolean handled = FALSE;
2479
2480   g_return_val_if_fail (widget != NULL, handled);
2481   g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2482   g_return_val_if_fail (event != NULL, handled);
2483
2484   if (!handled)
2485     handled = gtk_bindings_activate (GTK_OBJECT (widget),
2486                                      event->keyval,
2487                                      event->state | GDK_RELEASE_MASK);
2488
2489   return handled;
2490 }
2491
2492 static gboolean
2493 gtk_widget_real_focus_in_event (GtkWidget     *widget,
2494                                 GdkEventFocus *event)
2495 {
2496   GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
2497   gtk_widget_queue_draw (widget);
2498
2499   return FALSE;
2500 }
2501
2502 static gboolean
2503 gtk_widget_real_focus_out_event (GtkWidget     *widget,
2504                                  GdkEventFocus *event)
2505 {
2506   GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
2507   gtk_widget_queue_draw (widget);
2508
2509   return FALSE;
2510 }
2511
2512 /**
2513  * gtk_widget_event:
2514  * @widget: a #GtkWidget
2515  * @event: a #GdkEvent
2516  * 
2517  * Rarely-used function. This function is used to emit
2518  * the event signals on a widget (those signals should never
2519  * be emitted without using this function to do so).
2520  * If you want to synthesize an event though, don't use this function;
2521  * instead, use gtk_main_do_event() so the event will behave as if
2522  * it were in the event queue. Don't synthesize expose events; instead,
2523  * use gdk_window_invalidate_rect() to invalidate a region of the
2524  * window.
2525  * 
2526  * Return value: return from the event signal emission (%TRUE if the event was handled)
2527  **/
2528 gboolean
2529 gtk_widget_event (GtkWidget *widget,
2530                   GdkEvent  *event)
2531 {
2532   g_return_val_if_fail (widget != NULL, TRUE);
2533   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2534
2535   if (event->type == GDK_EXPOSE)
2536     {
2537       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
2538                  "the same effect, call gdk_window_invalidate_rect/region(), "
2539                  "followed by gdk_window_process_updates().");
2540       return TRUE;
2541     }
2542   
2543   return gtk_widget_event_internal (widget, event);
2544 }
2545
2546
2547 /**
2548  * gtk_widget_send_expose:
2549  * @widget: a #GtkWidget
2550  * @event: a expose #GdkEvent
2551  * 
2552  * Very rarely-used function. This function is used to emit
2553  * an expose event signals on a widget. This function is not
2554  * normally used directly. The only time it is used is when
2555  * propagating an expose event to a child NO_WINDOW widget, and
2556  * that is normally done using gtk_container_propagate_expose.
2557  *
2558  * If you want to force an area of a window to be redrawn, 
2559  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
2560  * To cause the redraw to be done immediately, follow that call
2561  * with a call to gdk_window_procss_updates().
2562  * 
2563  * Return value: return from the event signal emission (%TRUE if the event was handled)
2564  **/
2565 gint
2566 gtk_widget_send_expose (GtkWidget *widget,
2567                         GdkEvent  *event)
2568 {
2569   g_return_val_if_fail (widget != NULL, TRUE);
2570   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2571   g_return_val_if_fail (event != NULL, TRUE);
2572   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
2573
2574   if (event->type != GDK_EXPOSE)
2575     return TRUE;
2576   
2577   return gtk_widget_event_internal (widget, event);
2578 }
2579
2580 static gint
2581 gtk_widget_event_internal (GtkWidget *widget,
2582                            GdkEvent  *event)
2583 {
2584   gboolean return_val;
2585   gint signal_num;
2586
2587   gtk_widget_ref (widget);
2588   return_val = FALSE;
2589   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT], event,
2590                    &return_val);
2591   if (return_val || GTK_OBJECT_DESTROYED (widget))
2592     goto out;
2593
2594   switch (event->type)
2595     {
2596     case GDK_NOTHING:
2597       signal_num = -1;
2598       break;
2599     case GDK_BUTTON_PRESS:
2600     case GDK_2BUTTON_PRESS:
2601     case GDK_3BUTTON_PRESS:
2602       signal_num = BUTTON_PRESS_EVENT;
2603       break;
2604     case GDK_SCROLL:
2605       signal_num = SCROLL_EVENT;
2606       break;
2607     case GDK_BUTTON_RELEASE:
2608       signal_num = BUTTON_RELEASE_EVENT;
2609       break;
2610     case GDK_MOTION_NOTIFY:
2611       signal_num = MOTION_NOTIFY_EVENT;
2612       break;
2613     case GDK_DELETE:
2614       signal_num = DELETE_EVENT;
2615       break;
2616     case GDK_DESTROY:
2617       signal_num = DESTROY_EVENT;
2618       break;
2619     case GDK_KEY_PRESS:
2620       signal_num = KEY_PRESS_EVENT;
2621       break;
2622     case GDK_KEY_RELEASE:
2623       signal_num = KEY_RELEASE_EVENT;
2624       break;
2625     case GDK_ENTER_NOTIFY:
2626       signal_num = ENTER_NOTIFY_EVENT;
2627       break;
2628     case GDK_LEAVE_NOTIFY:
2629       signal_num = LEAVE_NOTIFY_EVENT;
2630       break;
2631     case GDK_FOCUS_CHANGE:
2632       if (event->focus_change.in)
2633         signal_num = FOCUS_IN_EVENT;
2634       else
2635         signal_num = FOCUS_OUT_EVENT;
2636       break;
2637     case GDK_CONFIGURE:
2638       signal_num = CONFIGURE_EVENT;
2639       break;
2640     case GDK_MAP:
2641       signal_num = MAP_EVENT;
2642       break;
2643     case GDK_UNMAP:
2644       signal_num = UNMAP_EVENT;
2645       break;
2646     case GDK_WINDOW_STATE:
2647       signal_num = WINDOW_STATE_EVENT;
2648       break;
2649     case GDK_PROPERTY_NOTIFY:
2650       signal_num = PROPERTY_NOTIFY_EVENT;
2651       break;
2652     case GDK_SELECTION_CLEAR:
2653       signal_num = SELECTION_CLEAR_EVENT;
2654       break;
2655     case GDK_SELECTION_REQUEST:
2656       signal_num = SELECTION_REQUEST_EVENT;
2657       break;
2658     case GDK_SELECTION_NOTIFY:
2659       signal_num = SELECTION_NOTIFY_EVENT;
2660       break;
2661     case GDK_PROXIMITY_IN:
2662       signal_num = PROXIMITY_IN_EVENT;
2663       break;
2664     case GDK_PROXIMITY_OUT:
2665       signal_num = PROXIMITY_OUT_EVENT;
2666       break;
2667     case GDK_NO_EXPOSE:
2668       signal_num = NO_EXPOSE_EVENT;
2669       break;
2670     case GDK_CLIENT_EVENT:
2671       signal_num = CLIENT_EVENT;
2672       break;
2673     case GDK_EXPOSE:
2674       if (!event->any.window)   /* Why is this necessary */
2675         goto out;
2676
2677       signal_num = EXPOSE_EVENT;
2678       break;
2679     case GDK_VISIBILITY_NOTIFY:
2680       signal_num = VISIBILITY_NOTIFY_EVENT;
2681       break;
2682     default:
2683       g_warning ("could not determine signal number for event: %d", event->type);
2684       goto out;
2685     }
2686   
2687   if (signal_num != -1)
2688     gtk_signal_emit (GTK_OBJECT (widget), widget_signals[signal_num], event, &return_val);
2689
2690   return_val |= GTK_OBJECT_DESTROYED (widget);
2691
2692  out:
2693   gtk_widget_unref (widget);
2694
2695   return return_val;
2696 }
2697
2698 /**
2699  * gtk_widget_activate:
2700  * @widget: a #GtkWidget that's activatable
2701  * 
2702  * For widgets that can be "activated" (buttons, menu items, etc.)
2703  * this function activates them. Activation is what happens when you
2704  * press Enter on a widget during key navigation; clicking a button,
2705  * selecting a menu item, etc. If @widget isn't activatable,
2706  * the function returns %FALSE.
2707  * 
2708  * Return value: %TRUE if the widget was activatable
2709  **/
2710 gboolean
2711 gtk_widget_activate (GtkWidget *widget)
2712 {
2713   g_return_val_if_fail (widget != NULL, FALSE);
2714   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2715   
2716   if (WIDGET_CLASS (widget)->activate_signal)
2717     {
2718       /* FIXME: we should eventually check the signals signature here */
2719       gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal);
2720
2721       return TRUE;
2722     }
2723   else
2724     return FALSE;
2725 }
2726
2727 /**
2728  * gtk_widget_set_scroll_adjustments:
2729  * @widget: a #GtkWidget
2730  * @hadjustment: an adjustment for horizontal scrolling, or %NULL
2731  * @vadjustment: an adjustment for vertical scrolling, or %NULL
2732  *
2733  * For widgets that support scrolling, sets the scroll adjustments and
2734  * returns %TRUE.  For widgets that don't support scrolling, does
2735  * nothing and returns %FALSE. Widgets that don't support scrolling
2736  * can be scrolled by placing them in a #GtkViewport, which does
2737  * support scrolling.
2738  * 
2739  * Return value: %TRUE if the widget supports scrolling
2740  **/
2741 gboolean
2742 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
2743                                    GtkAdjustment *hadjustment,
2744                                    GtkAdjustment *vadjustment)
2745 {
2746   g_return_val_if_fail (widget != NULL, FALSE);
2747   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2748   if (hadjustment)
2749     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
2750   if (vadjustment)
2751     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
2752
2753   if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
2754     {
2755       /* FIXME: we should eventually check the signals signature here */
2756       gtk_signal_emit (GTK_OBJECT (widget),
2757                        WIDGET_CLASS (widget)->set_scroll_adjustments_signal,
2758                        hadjustment, vadjustment);
2759       return TRUE;
2760     }
2761   else
2762     return FALSE;
2763 }
2764
2765 /*****************************************
2766  * gtk_widget_reparent_container_child:
2767  *   assistent function to gtk_widget_reparent
2768  *
2769  *   arguments:
2770  *
2771  *   results:
2772  *****************************************/
2773
2774 static void
2775 gtk_widget_reparent_container_child (GtkWidget *widget,
2776                                      gpointer   client_data)
2777 {
2778   g_return_if_fail (widget != NULL);
2779   g_return_if_fail (GTK_IS_WIDGET (widget));
2780   g_return_if_fail (client_data != NULL);
2781   
2782   if (GTK_WIDGET_NO_WINDOW (widget))
2783     {
2784       if (widget->window)
2785         gdk_window_unref (widget->window);
2786       widget->window = (GdkWindow*) client_data;
2787       if (widget->window)
2788         gdk_window_ref (widget->window);
2789
2790       if (GTK_IS_CONTAINER (widget))
2791         gtk_container_forall (GTK_CONTAINER (widget),
2792                               gtk_widget_reparent_container_child,
2793                               client_data);
2794     }
2795   else
2796     gdk_window_reparent (widget->window, 
2797                          (GdkWindow*) client_data, 0, 0);
2798 }
2799
2800 /**
2801  * gtk_widget_reparent:
2802  * @widget: a #GtkWidget
2803  * @new_parent: a #GtkContainer to move the widget into
2804  *
2805  * Moves a widget from one #GtkContainer to another, handling reference
2806  * count issues to avoid destroying the widget.
2807  * 
2808  **/
2809 void
2810 gtk_widget_reparent (GtkWidget *widget,
2811                      GtkWidget *new_parent)
2812 {
2813   g_return_if_fail (widget != NULL);
2814   g_return_if_fail (GTK_IS_WIDGET (widget));
2815   g_return_if_fail (new_parent != NULL);
2816   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
2817   g_return_if_fail (widget->parent != NULL);
2818   
2819   if (widget->parent != new_parent)
2820     {
2821       /* First try to see if we can get away without unrealizing
2822        * the widget as we reparent it. if so we set a flag so
2823        * that gtk_widget_unparent doesn't unrealize widget
2824        */
2825       if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
2826         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
2827       
2828       gtk_widget_ref (widget);
2829       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
2830       gtk_container_add (GTK_CONTAINER (new_parent), widget);
2831       gtk_widget_unref (widget);
2832       
2833       if (GTK_WIDGET_IN_REPARENT (widget))
2834         {
2835           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
2836           
2837           gtk_widget_reparent_container_child (widget,
2838                                                gtk_widget_get_parent_window (widget));
2839         }
2840     }
2841 }
2842
2843 /**
2844  * gtk_widget_intersect:
2845  * @widget: a #GtkWidget
2846  * @area: a rectangle
2847  * @intersection: rectangle to store intersection of @widget and @area
2848  * 
2849  * Computes the intersection of a @widget's area and @area, storing
2850  * the intersection in @intersection, and returns %TRUE if there was
2851  * an intersection.  @intersection may be %NULL if you're only
2852  * interested in whether there was an intersection.
2853  * 
2854  * Return value: %TRUE if there was an intersection
2855  **/
2856 gboolean
2857 gtk_widget_intersect (GtkWidget    *widget,
2858                       GdkRectangle *area,
2859                       GdkRectangle *intersection)
2860 {
2861   GdkRectangle *dest;
2862   GdkRectangle tmp;
2863   gint return_val;
2864   
2865   g_return_val_if_fail (widget != NULL, FALSE);
2866   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2867   g_return_val_if_fail (area != NULL, FALSE);
2868   
2869   if (intersection)
2870     dest = intersection;
2871   else
2872     dest = &tmp;
2873   
2874   return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
2875   
2876   if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
2877     {
2878       intersection->x -= widget->allocation.x;
2879       intersection->y -= widget->allocation.y;
2880     }
2881   
2882   return return_val;
2883 }
2884
2885 /**
2886  * gtk_widget_region_intersect:
2887  * @widget: a #GtkWidget
2888  * @region: a #GdkRegion, in the same coordinate system as 
2889  *          widget->allocation. That is, relative to widget->window
2890  *          for NO_WINDOW widgets; relative to the parent window
2891  *          of widget->window for widgets with their own window.
2892  * @returns: A newly allocated region holding the intersection of @widget
2893  *           and @region. The coordinates of the return value are
2894  *           relative to widget->window for NO_WINDOW widgets, and
2895  *           relative to the parent window of widget->window for
2896  *           widgets with their own window.
2897  * 
2898  * Computes the intersection of a @widget's area and @region, returning
2899  * the intersection. The result may be empty, use #gdk_region_empty to
2900  * check.
2901  **/
2902 GdkRegion *
2903 gtk_widget_region_intersect (GtkWidget *widget,
2904                              GdkRegion *region)
2905 {
2906   GdkRegion *dest;
2907   
2908   g_return_val_if_fail (widget != NULL, NULL);
2909   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2910   g_return_val_if_fail (region != NULL, NULL);
2911   
2912   dest = gdk_region_rectangle (&widget->allocation);
2913  
2914   gdk_region_intersect (dest, region);
2915
2916   return dest;
2917 }
2918
2919 /**
2920  * gtk_widget_grab_focus:
2921  * @widget: a #GtkWidget
2922  * 
2923  * Causes @widget to have the keyboard focus for the #GtkWindow it's
2924  * inside. @widget must be a focusable widget, such as a #GtkEntry;
2925  * something like #GtkFrame won't work. (More precisely, it must have the
2926  * #GTK_CAN_FOCUS flag set.)
2927  * 
2928  **/
2929 void
2930 gtk_widget_grab_focus (GtkWidget *widget)
2931 {
2932   g_return_if_fail (widget != NULL);
2933   g_return_if_fail (GTK_IS_WIDGET (widget));
2934
2935   g_object_ref (G_OBJECT (widget));
2936   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]);
2937   g_object_notify (G_OBJECT (widget), "has_focus");
2938   g_object_unref (G_OBJECT (widget));
2939 }
2940
2941 static void
2942 reset_focus_recurse (GtkWidget *widget,
2943                      gpointer   data)
2944 {
2945   if (GTK_IS_CONTAINER (widget))
2946     {
2947       GtkContainer *container;
2948
2949       container = GTK_CONTAINER (widget);
2950       gtk_container_set_focus_child (container, NULL);
2951
2952       gtk_container_foreach (container,
2953                              reset_focus_recurse,
2954                              NULL);
2955     }
2956 }
2957
2958 static void
2959 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
2960 {
2961   g_return_if_fail (focus_widget != NULL);
2962   g_return_if_fail (GTK_IS_WIDGET (focus_widget));
2963   
2964   if (GTK_WIDGET_CAN_FOCUS (focus_widget))
2965     {
2966       GtkWidget *toplevel;
2967       GtkWidget *widget;
2968       
2969       /* clear the current focus setting, break if the current widget
2970        * is the focus widget's parent, since containers above that will
2971        * be set by the next loop.
2972        */
2973       toplevel = gtk_widget_get_toplevel (focus_widget);
2974       if (GTK_IS_WINDOW (toplevel))
2975         {
2976           widget = GTK_WINDOW (toplevel)->focus_widget;
2977           
2978           if (widget == focus_widget)
2979             {
2980               /* We call gtk_window_set_focus() here so that the
2981                * toplevel window can request the focus if necessary.
2982                * This is needed when the toplevel is a GtkPlug
2983                */
2984               if (!GTK_WIDGET_HAS_FOCUS (widget))
2985                 gtk_window_set_focus (GTK_WINDOW (toplevel), focus_widget);
2986
2987               return;
2988             }
2989           
2990           if (widget)
2991             {
2992               while (widget->parent && widget->parent != focus_widget->parent)
2993                 {
2994                   widget = widget->parent;
2995                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
2996                 }
2997             }
2998         }
2999       else if (toplevel != focus_widget)
3000         {
3001           /* gtk_widget_grab_focus() operates on a tree without window...
3002            * actually, this is very questionable behaviour.
3003            */
3004           
3005           gtk_container_foreach (GTK_CONTAINER (toplevel),
3006                                  reset_focus_recurse,
3007                                  NULL);
3008         }
3009
3010       /* now propagate the new focus up the widget tree and finally
3011        * set it on the window
3012        */
3013       widget = focus_widget;
3014       while (widget->parent)
3015         {
3016           gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3017           widget = widget->parent;
3018         }
3019       if (GTK_IS_WINDOW (widget))
3020         gtk_window_set_focus (GTK_WINDOW (widget), focus_widget);
3021     }
3022 }
3023
3024 /**
3025  * gtk_widget_is_focus:
3026  * @widget: a #GtkWidget
3027  * 
3028  * Determines if the widget is the focus widget within its
3029  * toplevel. (This does not mean that the HAS_FOCUS flag is
3030  * necessarily set; HAS_FOCUS will only be set if the
3031  * toplevel widget additionally has the global input focus.)
3032  * 
3033  * Return value: %TRUE if the widget is the focus widget.
3034  **/
3035 gboolean
3036 gtk_widget_is_focus (GtkWidget *widget)
3037 {
3038   GtkWidget *toplevel;
3039
3040   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3041
3042   toplevel = gtk_widget_get_toplevel (widget);
3043   
3044   if (GTK_IS_WINDOW (toplevel))
3045     return widget == GTK_WINDOW (toplevel)->focus_widget;
3046   else
3047     return FALSE;
3048 }
3049
3050 /**
3051  * gtk_widget_grab_default:
3052  * @widget: a #GtkWidget
3053  *
3054  * Causes @widget to become the default widget. @widget must have the
3055  * #GTK_CAN_DEFAULT flag set; typically you have to set this flag
3056  * yourself by calling GTK_WIDGET_SET_FLAGS (@widget,
3057  * GTK_CAN_DEFAULT).  The default widget is activated when the user
3058  * presses Enter in a window.  Default widgets must be activatable,
3059  * that is, gtk_widget_activate() should affect them.
3060  * 
3061  **/
3062 void
3063 gtk_widget_grab_default (GtkWidget *widget)
3064 {
3065   GtkWidget *window;
3066   GtkType window_type;
3067   
3068   g_return_if_fail (widget != NULL);
3069   g_return_if_fail (GTK_IS_WIDGET (widget));
3070   g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3071   
3072   window_type = GTK_TYPE_WINDOW;
3073   window = widget->parent;
3074   
3075   while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3076     window = window->parent;
3077   
3078   if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3079     {
3080       gtk_window_set_default (GTK_WINDOW (window), widget);
3081       g_object_notify (G_OBJECT (widget), "has_default");
3082     }
3083   else
3084     g_warning (G_STRLOC ": widget not within a GtkWindow");
3085 }
3086
3087 /**
3088  * gtk_widget_set_name:
3089  * @widget: a #GtkWidget
3090  * @name: name for the widget
3091  *
3092  * Widgets can be named, which allows you to refer to them from a
3093  * gtkrc file. You can apply a style to widgets with a particular name
3094  * in the gtkrc file. See the documentation for gtkrc files (on the
3095  * same page as the docs for #GtkRcStyle).
3096  * 
3097  **/
3098 void
3099 gtk_widget_set_name (GtkWidget   *widget,
3100                      const gchar *name)
3101 {
3102   g_return_if_fail (widget != NULL);
3103   g_return_if_fail (GTK_IS_WIDGET (widget));
3104   
3105   if (widget->name)
3106     g_free (widget->name);
3107   widget->name = g_strdup (name);
3108
3109   if (GTK_WIDGET_RC_STYLE (widget))
3110     gtk_widget_set_rc_style (widget);
3111
3112   g_object_notify (G_OBJECT (widget), "name");
3113 }
3114
3115 /**
3116  * gtk_widget_get_name:
3117  * @widget: a #GtkWidget
3118  * 
3119  * Retrieves the name of a widget. The return value should not be
3120  * freed. See gtk_widget_set_name() for the significance of widget
3121  * names.
3122  * 
3123  * Return value: name of the widget
3124  **/
3125 G_CONST_RETURN gchar*
3126 gtk_widget_get_name (GtkWidget *widget)
3127 {
3128   g_return_val_if_fail (widget != NULL, NULL);
3129   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3130   
3131   if (widget->name)
3132     return widget->name;
3133   return gtk_type_name (GTK_WIDGET_TYPE (widget));
3134 }
3135
3136 /**
3137  * gtk_widget_set_state:
3138  * @widget: a #GtkWidget
3139  * @state: new state for @widget
3140  *
3141  * This function is for use in widget implementations. Sets the state
3142  * of a widget (insensitive, prelighted, etc.) Usually you should set
3143  * the state using wrapper functions such as gtk_widget_set_sensitive().
3144  * 
3145  **/
3146 void
3147 gtk_widget_set_state (GtkWidget           *widget,
3148                       GtkStateType         state)
3149 {
3150   g_return_if_fail (widget != NULL);
3151   g_return_if_fail (GTK_IS_WIDGET (widget));
3152
3153   if (state == GTK_WIDGET_STATE (widget))
3154     return;
3155
3156   if (state == GTK_STATE_INSENSITIVE)
3157     gtk_widget_set_sensitive (widget, FALSE);
3158   else
3159     {
3160       GtkStateData data;
3161
3162       data.state = state;
3163       data.state_restoration = FALSE;
3164       data.use_forall = FALSE;
3165       if (widget->parent)
3166         data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3167       else
3168         data.parent_sensitive = TRUE;
3169
3170       gtk_widget_propagate_state (widget, &data);
3171   
3172       if (GTK_WIDGET_DRAWABLE (widget))
3173         gtk_widget_queue_clear (widget);
3174     }
3175 }
3176
3177 void
3178 gtk_widget_set_app_paintable (GtkWidget *widget,
3179                               gboolean   app_paintable)
3180 {
3181   g_return_if_fail (widget != NULL);
3182   g_return_if_fail (GTK_IS_WIDGET (widget));
3183
3184   app_paintable = (app_paintable != FALSE);
3185
3186   if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
3187     {
3188       if (app_paintable)
3189         GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
3190       else
3191         GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
3192
3193       if (GTK_WIDGET_DRAWABLE (widget))
3194         gtk_widget_queue_clear (widget);
3195
3196       g_object_notify (G_OBJECT (widget), "app_paintable");
3197     }
3198 }
3199
3200 /**
3201  * gtk_widget_set_double_buffered:
3202  * @widget: a #GtkWidget
3203  * @double_buffered: %TRUE to double-buffer a widget
3204  *
3205  * Widgets are double buffered by default; you can use this function
3206  * to turn off the buffering. "Double buffered" simply means that
3207  * gdk_window_begin_paint() and gdk_window_end_paint() are called
3208  * automatically around expose events sent to the
3209  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
3210  * window to an offscreen buffer, and gdk_window_end_paint() draws the
3211  * buffer to the screen. The result is that users see the window
3212  * update in one smooth step, and don't see individual graphics
3213  * primitives being rendered.
3214  *
3215  * In very simple terms, double buffered widgets don't flicker,
3216  * so you would only use this function to turn off double buffering
3217  * if you had special needs and really knew what you were doing.
3218  * 
3219  **/
3220 void
3221 gtk_widget_set_double_buffered (GtkWidget *widget,
3222                                 gboolean   double_buffered)
3223 {
3224   g_return_if_fail (widget != NULL);
3225   g_return_if_fail (GTK_IS_WIDGET (widget));
3226
3227   if (double_buffered)
3228     GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3229   else
3230     GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3231 }
3232
3233 /**
3234  * gtk_widget_set_sensitive:
3235  * @widget: a @widget
3236  * @sensitive: %TRUE to make the widget sensitive
3237  *
3238  * Sets the sensitivity of a widget. A widget is sensitive if the user
3239  * can interact with it. Insensitive widgets are "grayed out" and the
3240  * user can't interact with them. Insensitive widgets are known as
3241  * "inactive" in some other toolkits.
3242  * 
3243  **/
3244 void
3245 gtk_widget_set_sensitive (GtkWidget *widget,
3246                           gboolean   sensitive)
3247 {
3248   GtkStateData data;
3249
3250   g_return_if_fail (widget != NULL);
3251   g_return_if_fail (GTK_IS_WIDGET (widget));
3252
3253   sensitive = (sensitive != FALSE);
3254
3255   if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
3256     return;
3257
3258   if (sensitive)
3259     {
3260       GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
3261       data.state = GTK_WIDGET_SAVED_STATE (widget);
3262     }
3263   else
3264     {
3265       GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
3266       data.state = GTK_WIDGET_STATE (widget);
3267     }
3268   data.state_restoration = TRUE;
3269   data.use_forall = TRUE;
3270
3271   if (widget->parent)
3272     data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3273   else
3274     data.parent_sensitive = TRUE;
3275
3276   gtk_widget_propagate_state (widget, &data);
3277   if (GTK_WIDGET_DRAWABLE (widget))
3278     gtk_widget_queue_clear (widget);
3279
3280   g_object_notify (G_OBJECT (widget), "sensitive");
3281 }
3282
3283 /**
3284  * gtk_widget_set_parent:
3285  * @widget: a #GtkWidget
3286  * @parent: parent container
3287  *
3288  * This function is useful only when implementing subclasses of #GtkContainer.
3289  * Sets the container as the parent of @widget, and takes care of
3290  * some details such as updating the state and style of the child
3291  * to reflect its new location. The opposite function is
3292  * gtk_widget_unparent().
3293  * 
3294  **/
3295 void
3296 gtk_widget_set_parent (GtkWidget *widget,
3297                        GtkWidget *parent)
3298 {
3299   GtkStateData data;
3300   
3301   g_return_if_fail (widget != NULL);
3302   g_return_if_fail (GTK_IS_WIDGET (widget));
3303   g_return_if_fail (widget->parent == NULL);
3304   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
3305   g_return_if_fail (parent != NULL);
3306   g_return_if_fail (GTK_IS_WIDGET (parent));
3307   g_return_if_fail (widget != parent);
3308
3309   /* keep this function in sync with gtk_menu_attach_to_widget()
3310    */
3311
3312   gtk_widget_ref (widget);
3313   gtk_object_sink (GTK_OBJECT (widget));
3314   widget->parent = parent;
3315
3316   if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
3317     data.state = GTK_WIDGET_STATE (parent);
3318   else
3319     data.state = GTK_WIDGET_STATE (widget);
3320   data.state_restoration = FALSE;
3321   data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
3322   data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
3323
3324   gtk_widget_propagate_state (widget, &data);
3325   
3326   gtk_widget_set_style_recurse (widget, NULL);
3327
3328   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], NULL);
3329   gtk_widget_propagate_hierarchy_changed (widget, NULL);
3330   g_object_notify (G_OBJECT (widget), "parent");
3331 }
3332
3333 /*****************************************
3334  * Widget styles
3335  * see docs/styles.txt
3336  *****************************************/
3337
3338 /**
3339  * gtk_widget_set_style:
3340  * @widget: a #GtkWidget
3341  * @style: a #GtkStyle
3342  *
3343  * Sets the #GtkStyle for a widget (widget->style). You probably don't
3344  * want to use this function; it interacts badly with themes, because
3345  * themes work by replacing the #GtkStyle. Instead, use
3346  * gtk_widget_modify_style().
3347  * 
3348  **/
3349 void
3350 gtk_widget_set_style (GtkWidget *widget,
3351                       GtkStyle  *style)
3352 {
3353   GtkStyle *default_style;
3354   gboolean initial_emission;
3355
3356   g_return_if_fail (widget != NULL);
3357   g_return_if_fail (GTK_IS_WIDGET (widget));
3358   g_return_if_fail (style != NULL);
3359
3360   initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3361
3362   GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
3363   GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
3364
3365   default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3366   if (!default_style)
3367     {
3368       gtk_style_ref (widget->style);
3369       gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_saved_default_style, widget->style);
3370     }
3371
3372   gtk_widget_set_style_internal (widget, style, initial_emission);
3373 }
3374
3375 /**
3376  * gtk_widget_ensure_style:
3377  * @widget: a #GtkWidget
3378  *
3379  * Ensures that @widget has a style (widget->style). Not a very useful
3380  * function; most of the time, if you want the style, the widget is
3381  * realized, and realized widgets are guaranteed to have a style
3382  * already.
3383  * 
3384  **/
3385 void
3386 gtk_widget_ensure_style (GtkWidget *widget)
3387 {
3388   g_return_if_fail (widget != NULL);
3389   g_return_if_fail (GTK_IS_WIDGET (widget));
3390
3391   if (!GTK_WIDGET_USER_STYLE (widget) &&
3392       !GTK_WIDGET_RC_STYLE (widget))
3393     gtk_widget_set_rc_style (widget);
3394 }
3395
3396 /**
3397  * gtk_widget_set_rc_style:
3398  * @widget: a #GtkWidget
3399  * 
3400  * 
3401  **/
3402 void
3403 gtk_widget_set_rc_style (GtkWidget *widget)
3404 {
3405   GtkStyle *saved_style;
3406   GtkStyle *new_style;
3407   gboolean initial_emission;
3408   
3409   g_return_if_fail (widget != NULL);
3410   g_return_if_fail (GTK_IS_WIDGET (widget));
3411
3412   initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3413
3414   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3415   GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
3416
3417   saved_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3418   new_style = gtk_rc_get_style (widget);
3419   if (new_style)
3420     {
3421       if (!saved_style)
3422         {
3423           gtk_style_ref (widget->style);
3424           gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_saved_default_style, widget->style);
3425         }
3426       gtk_widget_set_style_internal (widget, new_style, initial_emission);
3427     }
3428   else
3429     {
3430       if (saved_style)
3431         {
3432           g_assert (initial_emission == FALSE); /* FIXME: remove this line */
3433
3434           gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3435           gtk_widget_set_style_internal (widget, saved_style, initial_emission);
3436           gtk_style_unref (saved_style);
3437         }
3438       else
3439         {
3440           if (initial_emission)
3441             gtk_widget_set_style_internal (widget, widget->style, TRUE);
3442         }
3443     }
3444 }
3445
3446 void
3447 gtk_widget_restore_default_style (GtkWidget *widget)
3448 {
3449   GtkStyle *default_style;
3450
3451   g_return_if_fail (widget != NULL);
3452   g_return_if_fail (GTK_IS_WIDGET (widget));
3453
3454   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3455
3456   default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3457   if (default_style)
3458     {
3459       gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3460       gtk_widget_set_style_internal (widget, default_style, FALSE);
3461       gtk_style_unref (default_style);
3462     }
3463 }
3464
3465 /**
3466  * gtk_widget_get_style:
3467  * @widget: a #GtkWidget
3468  * 
3469  * Simply an accessor function that returns widget->style.
3470  * 
3471  * Return value: the widget's #GtkStyle
3472  **/
3473 GtkStyle*
3474 gtk_widget_get_style (GtkWidget *widget)
3475 {
3476   g_return_val_if_fail (widget != NULL, NULL);
3477   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3478   
3479   return widget->style;
3480 }
3481
3482 /**
3483  * gtk_widget_modify_style:
3484  * @widget: a #GtkWidget
3485  * @style: the #GtkRcStyle holding the style modifications
3486  * 
3487  * Modify style values on the widget. Modifications made using this
3488  * technique take precendence over style values set via an RC file,
3489  * however, they will be overriden if a style is explicitely set on
3490  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
3491  * is designed so each field can either be set or unset, so it is
3492  * possible, using this function, to modify some style values and
3493  * leave the others unchanged.
3494  *
3495  * Note that modifications made with this function are not cumulative
3496  * with previous calls to gtk_widget_modify_style() or with such
3497  * functions as gtk_widget_modify_fg(). If you wish to retain
3498  * previous values, you must first call gtk_widget_get_modifier_style(),
3499  * make your modifications to the returned style, then call
3500  * gtk_widget_modify_style() with that style. On the other hand,
3501  * if you first call gtk_widget_modify_style(), subsequent calls
3502  * to such functions gtk_widget_modify_fg() will be have a cumulative
3503  * effect with the inital modifications.
3504  **/
3505 void       
3506 gtk_widget_modify_style (GtkWidget      *widget,
3507                          GtkRcStyle     *style)
3508 {
3509   GtkRcStyle *old_style;
3510
3511   g_return_if_fail (GTK_IS_RC_STYLE (style));
3512   
3513   old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3514                                          quark_rc_style);
3515
3516   gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3517                                   quark_rc_style,
3518                                   gtk_rc_style_copy (style),
3519                                   (GtkDestroyNotify)gtk_rc_style_unref);
3520
3521   /* note that "style" may be invalid here if it was the old
3522    * modifier style and the only reference was our own.
3523    */
3524   
3525   if (GTK_WIDGET_RC_STYLE (widget))
3526     gtk_widget_set_rc_style (widget);
3527 }
3528
3529 /**
3530  * gtk_widget_get_modifier_style:
3531  * @widget: a #GtkWidget
3532  * 
3533  * Return the current modifier style for the widget. (As set by
3534  * gtk_widget_modify_style().) If no style has previously set, a new
3535  * #GtkRcStyle will be created with all values unset, and set as the
3536  * modifier style for the widget. If you make changes to this rc
3537  * style, you must call gtk_widget_modify_style(), passing in the
3538  * returned rc style, to make sure that your changes take effect.
3539  *
3540  * Caution: passing the style back to gtk_widget_modify_style() will
3541  * normally end up destroying it, because gtk_widget_modify_style() copies
3542  * the passed-in style and sets the copy as the new modifier style,
3543  * thus dropping any reference to the old modifier style. Add a reference
3544  * to the modifier style if you want to keep it alive.
3545  * 
3546  * Return value: the modifier style for the widget. This rc style is
3547  *   owned by the widget. If you want to keep a pointer to value this
3548  *   around, you must add a refcount using gtk_rc_style_ref().
3549  **/
3550 GtkRcStyle *
3551 gtk_widget_get_modifier_style (GtkWidget      *widget)
3552 {
3553   GtkRcStyle *rc_style;
3554   
3555   rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3556                                         quark_rc_style);
3557
3558   if (!rc_style)
3559     {
3560       rc_style = gtk_rc_style_new();
3561       gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3562                                       quark_rc_style,
3563                                       rc_style,
3564                                       (GtkDestroyNotify)gtk_rc_style_unref);
3565     }
3566
3567   return rc_style;
3568 }
3569
3570 static void
3571 gtk_widget_modify_color_component (GtkWidget     *widget,
3572                                    GtkRcFlags     component,
3573                                    GtkStateType   state,
3574                                    GdkColor      *color)
3575 {
3576   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
3577
3578   switch (component)
3579     {
3580     case GTK_RC_FG:
3581       rc_style->fg[state] = *color;
3582       break;
3583     case GTK_RC_BG:
3584       rc_style->bg[state] = *color;
3585       break;
3586     case GTK_RC_TEXT:
3587       rc_style->text[state] = *color;
3588        break;
3589     case GTK_RC_BASE:
3590       rc_style->base[state] = *color;
3591       break;
3592     default:
3593       g_assert_not_reached();
3594     }
3595
3596   rc_style->color_flags[state] |= component;
3597
3598   gtk_widget_modify_style (widget, rc_style);
3599 }
3600
3601 /**
3602  * gtk_widget_modify_fg:
3603  * @widget: a #GtkWidget
3604  * @state: the state for which to set the foreground color.
3605  * @color: the color to assign (does not need to be allocated)
3606  * 
3607  * Set the foreground color for a widget in a particular state.  All
3608  * other style values are left untouched. See also
3609  * gtk_widget_modify_style().
3610  **/
3611 void
3612 gtk_widget_modify_fg (GtkWidget   *widget,
3613                       GtkStateType state,
3614                       GdkColor    *color)
3615 {
3616   g_return_if_fail (GTK_IS_WIDGET (widget));
3617   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3618   g_return_if_fail (color != NULL);
3619
3620   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
3621 }
3622
3623 /**
3624  * gtk_widget_modify_bg:
3625  * @widget: a #GtkWidget
3626  * @state: the state for which to set the foreground color.
3627  * @color: the color to assign (does not need to be allocated)
3628  * 
3629  * Set the background color for a widget in a particular state.  All
3630  * other style values are left untouched. See also
3631  * gtk_widget_modify_style().
3632  **/
3633 void
3634 gtk_widget_modify_bg (GtkWidget   *widget,
3635                       GtkStateType state,
3636                       GdkColor    *color)
3637 {
3638   g_return_if_fail (GTK_IS_WIDGET (widget));
3639   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3640   g_return_if_fail (color != NULL);
3641
3642   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
3643 }
3644
3645 /**
3646  * gtk_widget_modify_base:
3647  * @widget: a #GtkWidget
3648  * @state: the state for which to set the foreground color.
3649  * @color: the color to assign (does not need to be allocated)
3650  * 
3651  * Set the text color for a widget in a particular state.  All other
3652  * style values are left untouched. The text color is the foreground
3653  * color used along with the base color (see gtk_widget_modify_base)
3654  * for widgets such as #GtkEntry and #GtkTextView. See also
3655  * gtk_widget_modify_style().
3656  **/
3657 void
3658 gtk_widget_modify_text (GtkWidget   *widget,
3659                         GtkStateType state,
3660                         GdkColor    *color)
3661 {
3662   g_return_if_fail (GTK_IS_WIDGET (widget));
3663   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3664   g_return_if_fail (color != NULL);
3665
3666   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
3667 }
3668
3669 /**
3670  * gtk_widget_modify_base:
3671  * @widget: a #GtkWidget
3672  * @state: the state for which to set the foreground color.
3673  * @color: the color to assign (does not need to be allocated)
3674  * 
3675  * Set the text color for a widget in a particular state.
3676  * All other style values are left untouched. The base color
3677  * is the background color used along with the text color
3678  * (see gtk_widget_modify_text) for widgets such as #GtkEntry
3679  * and #GtkTextView. See also gtk_widget_modify_style().
3680  **/
3681 void
3682 gtk_widget_modify_base (GtkWidget  *widget,
3683                         GtkStateType state,
3684                         GdkColor    *color)
3685 {
3686   g_return_if_fail (GTK_IS_WIDGET (widget));
3687   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3688   g_return_if_fail (color != NULL);
3689
3690   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
3691 }
3692
3693 /**
3694  * gtk_widget_modify_font:
3695  * @widget: a #GtkWidget
3696  * @font_desc: the font description to use
3697  * 
3698  * Set the font to use for a widget.  All other style values are left
3699  * untouched. See also gtk_widget_modify_style().
3700  **/
3701 void
3702 gtk_widget_modify_font (GtkWidget            *widget,
3703                         PangoFontDescription *font_desc)
3704 {
3705   GtkRcStyle *rc_style;
3706
3707   g_return_if_fail (GTK_IS_WIDGET (widget));
3708   g_return_if_fail (font_desc != NULL);
3709
3710   rc_style = gtk_widget_get_modifier_style (widget);  
3711
3712   if (rc_style->font_desc)
3713     pango_font_description_free (rc_style->font_desc);
3714   
3715   rc_style->font_desc = pango_font_description_copy (font_desc);
3716
3717   gtk_widget_modify_style (widget, rc_style);
3718 }
3719
3720 static void
3721 gtk_widget_direction_changed (GtkWidget        *widget,
3722                               GtkTextDirection  previous_direction)
3723 {
3724   gtk_widget_queue_resize (widget);
3725 }
3726
3727 static void
3728 gtk_widget_style_set (GtkWidget *widget,
3729                       GtkStyle  *previous_style)
3730 {
3731   if (GTK_WIDGET_REALIZED (widget) &&
3732       !GTK_WIDGET_NO_WINDOW (widget))
3733     gtk_style_set_background (widget->style, widget->window, widget->state);
3734 }
3735
3736 static void
3737 gtk_widget_set_style_internal (GtkWidget *widget,
3738                                GtkStyle  *style,
3739                                gboolean   initial_emission)
3740 {
3741   g_return_if_fail (widget != NULL);
3742   g_return_if_fail (GTK_IS_WIDGET (widget));
3743   g_return_if_fail (style != NULL);
3744
3745   g_object_ref (G_OBJECT (widget));
3746   g_object_freeze_notify (G_OBJECT (widget));
3747
3748   if (widget->style != style || initial_emission)
3749     {
3750       PangoContext *context = gtk_widget_peek_pango_context (widget);
3751       if (context)
3752         pango_context_set_font_description (context, style->font_desc);
3753     }
3754   
3755   if (widget->style != style)
3756     {
3757       GtkStyle *previous_style;
3758
3759       if (GTK_WIDGET_REALIZED (widget))
3760         {
3761           gtk_widget_reset_shapes (widget);
3762           gtk_style_detach (widget->style);
3763         }
3764       
3765       previous_style = widget->style;
3766       widget->style = style;
3767       gtk_style_ref (widget->style);
3768       
3769       if (GTK_WIDGET_REALIZED (widget))
3770         widget->style = gtk_style_attach (widget->style, widget->window);
3771
3772       gtk_signal_emit (GTK_OBJECT (widget),
3773                        widget_signals[STYLE_SET],
3774                        initial_emission ? NULL : previous_style);
3775       gtk_style_unref (previous_style);
3776
3777       if (widget->parent && !initial_emission)
3778         {
3779           GtkRequisition old_requisition;
3780           
3781           old_requisition = widget->requisition;
3782           gtk_widget_size_request (widget, NULL);
3783           
3784           if ((old_requisition.width != widget->requisition.width) ||
3785               (old_requisition.height != widget->requisition.height))
3786             gtk_widget_queue_resize (widget);
3787           else if (GTK_WIDGET_DRAWABLE (widget))
3788             gtk_widget_queue_clear (widget);
3789         }
3790     }
3791   else if (initial_emission)
3792     gtk_signal_emit (GTK_OBJECT (widget),
3793                      widget_signals[STYLE_SET],
3794                      NULL);
3795   g_object_notify (G_OBJECT (widget), "style");
3796   g_object_thaw_notify (G_OBJECT (widget));
3797   g_object_unref (G_OBJECT (widget));
3798 }
3799
3800 static void
3801 gtk_widget_set_style_recurse (GtkWidget *widget,
3802                               gpointer   client_data)
3803 {
3804   if (GTK_WIDGET_RC_STYLE (widget))
3805     gtk_widget_set_rc_style (widget);
3806   
3807   if (GTK_IS_CONTAINER (widget))
3808     gtk_container_forall (GTK_CONTAINER (widget),
3809                           gtk_widget_set_style_recurse,
3810                           NULL);
3811 }
3812
3813 static void
3814 gtk_widget_propagate_hierarchy_changed (GtkWidget       *widget,
3815                                         gpointer         client_data)
3816 {
3817   gboolean new_anchored;
3818
3819   new_anchored = widget->parent && GTK_WIDGET_ANCHORED (widget->parent);
3820
3821   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
3822     {
3823       gtk_widget_ref (widget);
3824       
3825       if (new_anchored)
3826         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
3827       else
3828         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
3829       
3830       g_signal_emit (GTK_OBJECT (widget), widget_signals[HIERARCHY_CHANGED], 0);
3831   
3832       if (GTK_IS_CONTAINER (widget))
3833         gtk_container_forall (GTK_CONTAINER (widget),
3834                               gtk_widget_propagate_hierarchy_changed,
3835                               NULL);
3836       
3837       gtk_widget_unref (widget);
3838     }
3839 }
3840
3841 void
3842 gtk_widget_reset_rc_styles (GtkWidget *widget)
3843 {
3844   g_return_if_fail (widget != NULL);
3845   g_return_if_fail (GTK_IS_WIDGET (widget));
3846
3847   gtk_widget_set_style_recurse (widget, NULL);
3848 }
3849
3850 void
3851 gtk_widget_set_default_style (GtkStyle *style)
3852 {
3853   if (style != gtk_default_style)
3854      {
3855        if (gtk_default_style)
3856          gtk_style_unref (gtk_default_style);
3857        gtk_default_style = style;
3858        if (gtk_default_style)
3859          gtk_style_ref (gtk_default_style);
3860      }
3861 }
3862
3863 GtkStyle*
3864 gtk_widget_get_default_style (void)
3865 {
3866   if (!gtk_default_style)
3867     {
3868       gtk_default_style = gtk_style_new ();
3869       gtk_style_ref (gtk_default_style);
3870     }
3871   
3872   return gtk_default_style;
3873 }
3874
3875 void
3876 gtk_widget_push_style (GtkStyle *style)
3877 {
3878   g_return_if_fail (style != NULL);
3879
3880   gtk_style_ref (style);
3881   style_stack = g_slist_prepend (style_stack, style);
3882 }
3883
3884 static GtkStyle*
3885 gtk_widget_peek_style (void)
3886 {
3887   if (style_stack)
3888     return (GtkStyle*) style_stack->data;
3889   else
3890     return gtk_widget_get_default_style ();
3891 }
3892
3893 void
3894 gtk_widget_pop_style (void)
3895 {
3896   GSList *tmp;
3897   
3898   if (style_stack)
3899     {
3900       tmp = style_stack;
3901       style_stack = style_stack->next;
3902       gtk_style_unref ((GtkStyle*) tmp->data);
3903       g_slist_free_1 (tmp);
3904     }
3905 }
3906
3907 static PangoContext *
3908 gtk_widget_peek_pango_context (GtkWidget *widget)
3909 {
3910   return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
3911 }
3912
3913 /**
3914  * gtk_widget_get_pango_context:
3915  * @widget: a #GtkWidget
3916  * 
3917  * Get a #PangoContext with the appropriate colormap, font description
3918  * and base direction for this widget. Unlike the context returned
3919  * by gtk_widget_create_pango_context(), this context is owned by
3920  * the widget (it can be used as long as widget exists), and will
3921  * be updated to match any changes to the widget's attributes.
3922  *
3923  * If you create and keep a #PangoLayout using this context, you must
3924  * deal with changes to the context by calling pango_layout_context_changed()
3925  * on the layout in response to the ::style_set and ::direction_set signals
3926  * for the widget.
3927  *
3928  * Return value: the #PangoContext for the widget.
3929  **/
3930 PangoContext *
3931 gtk_widget_get_pango_context (GtkWidget *widget)
3932 {
3933   PangoContext *context;
3934
3935   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3936   
3937   context = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
3938   if (!context)
3939     {
3940       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
3941       gtk_object_set_data_by_id_full (GTK_OBJECT (widget), quark_pango_context, context,
3942                                       (GDestroyNotify) g_object_unref);
3943     }
3944
3945   return context;
3946 }
3947
3948 /**
3949  * gtk_widget_create_pango_context:
3950  * @widget: a #PangoWidget
3951  * 
3952  * Create a new pango context with the appropriate colormap,
3953  * font description, and base direction for drawing text for
3954  * this widget. See also gtk_widget_get_pango_context()
3955  * 
3956  * Return value: the new #PangoContext
3957  **/
3958 PangoContext *
3959 gtk_widget_create_pango_context (GtkWidget *widget)
3960 {
3961   PangoContext *context;
3962   char *lang;
3963
3964   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3965
3966   context = gdk_pango_context_get ();
3967
3968   gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
3969   pango_context_set_base_dir (context,
3970                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
3971                                 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
3972   pango_context_set_font_description (context, widget->style->font_desc);
3973
3974   lang = gtk_get_default_language ();  
3975   pango_context_set_lang (context, lang);
3976   g_free (lang);
3977
3978   return context;
3979 }
3980
3981 /**
3982  * gtk_widget_create_pango_layout:
3983  * @widget: a #PangoWidget
3984  * @text:   text to set on the layout (can be %NULL)
3985  * 
3986  * Create a new #PangoLayout with the appropriate colormap,
3987  * font description, and base direction for drawing text for
3988  * this widget.
3989  *
3990  * If you keep a #PangoLayout created in this way around, in order
3991  * notify the layout of changes to the base direction or font of this
3992  * widget, you must call pango_layout_context_changed() in response to
3993  * the ::style_set and ::direction_set signals for the widget.
3994  * 
3995  * Return value: the new #PangoLayout
3996  **/
3997 PangoLayout *
3998 gtk_widget_create_pango_layout (GtkWidget   *widget,
3999                                 const gchar *text)
4000 {
4001   PangoLayout *layout;
4002   PangoContext *context;
4003
4004   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4005
4006   context = gtk_widget_get_pango_context (widget);
4007   layout = pango_layout_new (context);
4008
4009   if (text)
4010     pango_layout_set_text (layout, text, -1);
4011
4012   return layout;
4013 }
4014
4015 /**
4016  * gtk_widget_render_icon:
4017  * @widget: a #GtkWidget
4018  * @stock_id: a stock ID
4019  * @size: a stock size
4020  * @detail: render detail to pass to theme engine
4021  * 
4022  * A convenience function that uses the theme engine and RC file
4023  * settings for @widget to look up @stock_id and render it to
4024  * a pixbuf. @stock_id should be a stock icon ID such as
4025  * #GTK_STOCK_OPEN or #GTK_STOCK_BUTTON_OK. @size should be a size
4026  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
4027  * identifies the widget or code doing the rendering, so that
4028  * theme engines can special-case rendering for that widget or code.
4029  * 
4030  * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
4031  **/
4032 GdkPixbuf*
4033 gtk_widget_render_icon (GtkWidget      *widget,
4034                         const gchar    *stock_id,
4035                         GtkIconSize     size,
4036                         const gchar    *detail)
4037 {
4038   GtkIconSet *icon_set;
4039   GdkPixbuf *retval;
4040   
4041   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4042   g_return_val_if_fail (stock_id != NULL, NULL);
4043   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
4044   
4045   gtk_widget_ensure_style (widget);
4046   
4047   icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
4048
4049   if (icon_set == NULL)
4050     return NULL;
4051
4052   retval = gtk_icon_set_render_icon (icon_set,
4053                                      widget->style,
4054                                      gtk_widget_get_direction (widget),
4055                                      GTK_WIDGET_STATE (widget),
4056                                      size,
4057                                      widget,
4058                                      detail);
4059
4060   return retval;
4061 }
4062
4063 /*************************************************************
4064  * gtk_widget_set_parent_window:
4065  *     Set a non default parent window for widget
4066  *
4067  *   arguments:
4068  *     widget:
4069  *     parent_window 
4070  *     
4071  *   results:
4072  *************************************************************/
4073
4074 void
4075 gtk_widget_set_parent_window   (GtkWidget           *widget,
4076                                 GdkWindow           *parent_window)
4077 {
4078   GdkWindow *old_parent_window;
4079
4080   g_return_if_fail (widget != NULL);
4081   g_return_if_fail (GTK_IS_WIDGET (widget));
4082   
4083   old_parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4084                                                  quark_parent_window);
4085
4086   if (parent_window != old_parent_window)
4087     {
4088       gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_parent_window, 
4089                                  parent_window);
4090       if (old_parent_window)
4091         gdk_window_unref (old_parent_window);
4092       if (parent_window)
4093         gdk_window_ref (parent_window);
4094     }
4095 }
4096
4097 /*************************************************************
4098  * gtk_widget_get_parent_window:
4099  *     Get widget's parent window
4100  *
4101  *   arguments:
4102  *     widget:
4103  *     
4104  *   results:
4105  *     parent window
4106  *************************************************************/
4107
4108 GdkWindow *
4109 gtk_widget_get_parent_window   (GtkWidget           *widget)
4110 {
4111   GdkWindow *parent_window;
4112
4113   g_return_val_if_fail (widget != NULL, NULL);
4114   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4115   g_return_val_if_fail (widget->parent != NULL, NULL);
4116   
4117   parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4118                                              quark_parent_window);
4119
4120   return (parent_window != NULL) ? parent_window : widget->parent->window;
4121 }
4122
4123 /* Update the position from aux_info. Used from gtk_widget_set_uposition
4124  * and gtk_widget_set_property().
4125  */
4126 static void
4127 gtk_widget_do_uposition (GtkWidget *widget)
4128 {
4129   GtkWidgetAuxInfo *aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4130
4131   if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
4132     _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
4133   
4134   if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
4135     gtk_widget_size_allocate (widget, &widget->allocation);
4136
4137   g_object_freeze_notify (G_OBJECT (widget));
4138   if (aux_info->x_set)
4139     g_object_notify (G_OBJECT (widget), "x");
4140   if (aux_info->y_set)
4141     g_object_notify (G_OBJECT (widget), "y");
4142   g_object_thaw_notify (G_OBJECT (widget));
4143 }
4144
4145 /**
4146  * gtk_widget_set_uposition:
4147  * @widget: a #GtkWidget
4148  * @x: x position; -1 to unset x; -2 to leave x unchanged
4149  * @y: y position; -1 to unset y; -2 to leave y unchanged
4150  * 
4151  *
4152  * Sets the position of a widget. The funny "u" in the name comes from
4153  * the "user position" hint specified by the X window system, and
4154  * exists for legacy reasons. This function doesn't work if a widget
4155  * is inside a container; it's only really useful on #GtkWindow.
4156  *
4157  * Don't use this function to center dialogs over the main application
4158  * window; most window managers will do the centering on your behalf
4159  * if you call gtk_window_set_transient_for(), and it's really not
4160  * possible to get the centering to work correctly in all cases from
4161  * application code. But if you insist, use gtk_window_set_position()
4162  * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
4163  * manually.
4164  *
4165  * Note that although x and y can be individually unset, the position
4166  * is not honoured unless both x and y are set.
4167  **/
4168 void
4169 gtk_widget_set_uposition (GtkWidget *widget,
4170                           gint       x,
4171                           gint       y)
4172 {
4173   GtkWidgetAuxInfo *aux_info;
4174   
4175   g_return_if_fail (widget != NULL);
4176   g_return_if_fail (GTK_IS_WIDGET (widget));
4177   
4178   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4179   
4180   if (x > -2)
4181     {
4182       if (x == -1)
4183         aux_info->x_set = FALSE;
4184       else
4185         {
4186           aux_info->x_set = TRUE;
4187           aux_info->x = x;
4188         }
4189     }
4190
4191   if (y > -2)
4192     {
4193       if (y == -1)
4194         aux_info->y_set = FALSE;
4195       else
4196         {
4197           aux_info->y_set = TRUE;
4198           aux_info->y = y;
4199         }
4200     }
4201
4202   gtk_widget_do_uposition (widget);
4203 }
4204
4205 /**
4206  * gtk_widget_set_usize:
4207  * @widget: a #GtkWidget
4208  * @width: minimum width, or -1 to unset
4209  * @height: minimum height, or -1 to unset
4210  *
4211  * Sets the minimum size of a widget; that is, the widget's size
4212  * request will be @width by @height. You can use this function to
4213  * force a widget to be either larger or smaller than it is. The
4214  * strange "usize" name dates from the early days of GTK+, and derives
4215  * from X Window System terminology. In many cases,
4216  * gtk_window_set_default_size() is a better choice for toplevel
4217  * windows than this function; setting the default size will still
4218  * allow users to shrink the window. Setting the usize will force them
4219  * to leave the window at least as large as the usize. When dealing
4220  * with window sizes, gtk_window_set_geometry_hints() can be a useful
4221  * function as well.
4222  * 
4223  * Note the inherent danger of setting any fixed size - themes,
4224  * translations into other languages, different fonts, and user action
4225  * can all change the appropriate size for a given widget. So, it's
4226  * basically impossible to hardcode a size that will always be
4227  * correct.
4228  * 
4229  **/
4230 void
4231 gtk_widget_set_usize (GtkWidget *widget,
4232                       gint       width,
4233                       gint       height)
4234 {
4235   GtkWidgetAuxInfo *aux_info;
4236   
4237   g_return_if_fail (widget != NULL);
4238   g_return_if_fail (GTK_IS_WIDGET (widget));
4239   
4240   g_object_freeze_notify (G_OBJECT (widget));
4241
4242   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4243   
4244   if (width > -2)
4245     {
4246       g_object_notify (G_OBJECT (widget), "width");
4247       aux_info->width = width;
4248     }
4249   if (height > -2)
4250     {
4251       g_object_notify (G_OBJECT (widget), "height");  
4252       aux_info->height = height;
4253     }
4254   
4255   if (GTK_WIDGET_VISIBLE (widget))
4256     gtk_widget_queue_resize (widget);
4257
4258   g_object_thaw_notify (G_OBJECT (widget));
4259 }
4260
4261 /**
4262  * gtk_widget_set_events:
4263  * @widget: a #GtkWidget
4264  * @events: event mask
4265  *
4266  * Sets the event mask (see #GdkEventMask) for a widget. The event
4267  * mask determines which events a widget will receive. Keep in mind
4268  * that different widgets have different default event masks, and by
4269  * changing the event mask you may disrupt a widget's functionality,
4270  * so be careful. This function must be called while a widget is
4271  * unrealized. Consider gtk_widget_add_events() for widgets that are
4272  * already realized, or if you want to preserve the existing event
4273  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
4274  * to get events on those widgets, place them inside a #GtkEventBox
4275  * and receive events on the event box.
4276  * 
4277  **/
4278 void
4279 gtk_widget_set_events (GtkWidget *widget,
4280                        gint       events)
4281 {
4282   gint *eventp;
4283   
4284   g_return_if_fail (widget != NULL);
4285   g_return_if_fail (GTK_IS_WIDGET (widget));
4286   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4287   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4288   
4289   eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4290   
4291   if (events)
4292     {
4293       if (!eventp)
4294         eventp = g_new (gint, 1);
4295       
4296       *eventp = events;
4297       gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4298     }
4299   else if (eventp)
4300     {
4301       g_free (eventp);
4302       gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4303     }
4304
4305   g_object_notify (G_OBJECT (widget), "events");
4306 }
4307
4308 /**
4309  * gtk_widget_add_events:
4310  * @widget: a #GtkWidget
4311  * @events: an event mask, see #GdkEventMask
4312  *
4313  * Adds the events in the bitfield @events to the event mask for
4314  * @widget. See gtk_widget_set_events() for details.
4315  * 
4316  **/
4317 void
4318 gtk_widget_add_events (GtkWidget *widget,
4319                        gint       events)
4320 {
4321   gint *eventp;
4322   
4323   g_return_if_fail (widget != NULL);
4324   g_return_if_fail (GTK_IS_WIDGET (widget));
4325   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4326   
4327   eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4328   
4329   if (events)
4330     {
4331       if (!eventp)
4332         {
4333           eventp = g_new (gint, 1);
4334           *eventp = 0;
4335         }
4336       
4337       *eventp |= events;
4338       gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4339     }
4340   else if (eventp)
4341     {
4342       g_free (eventp);
4343       gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4344     }
4345
4346   if (GTK_WIDGET_REALIZED (widget))
4347     {
4348       gdk_window_set_events (widget->window,
4349                              gdk_window_get_events (widget->window) | events);
4350     }
4351
4352   g_object_notify (G_OBJECT (widget), "events");
4353 }
4354
4355 /**
4356  * gtk_widget_set_extension_events:
4357  * @widget: a #GtkWidget
4358  * @mode: bitfield of extension events to receive
4359  *
4360  * Sets the extension events mask to @mode. See #GdkExtensionMode
4361  * and gdk_input_set_extension_events().
4362  * 
4363  **/
4364 void
4365 gtk_widget_set_extension_events (GtkWidget *widget,
4366                                  GdkExtensionMode mode)
4367 {
4368   GdkExtensionMode *modep;
4369   
4370   g_return_if_fail (widget != NULL);
4371   g_return_if_fail (GTK_IS_WIDGET (widget));
4372   
4373   modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4374   
4375   if (!modep)
4376     modep = g_new (GdkExtensionMode, 1);
4377   
4378   *modep = mode;
4379   gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode, modep);
4380   g_object_notify (G_OBJECT (widget), "extension_events");
4381 }
4382
4383 /**
4384  * gtk_widget_get_toplevel:
4385  * @widget: a #GtkWidget
4386  * 
4387  * This function returns the topmost widget in the container hierarchy
4388  * @widget is a part of. If @widget has no parent widgets, it will be
4389  * returned as the topmost widget. No reference will be added to the
4390  * returned widget; it should not be unreferenced.
4391  *
4392  * Note the difference in behavior vs. gtk_widget_get_ancestor();
4393  * gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW) would return
4394  * %NULL if @widget wasn't inside a toplevel window.
4395  * 
4396  * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor
4397  **/
4398 GtkWidget*
4399 gtk_widget_get_toplevel (GtkWidget *widget)
4400 {
4401   g_return_val_if_fail (widget != NULL, NULL);
4402   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4403   
4404   while (widget->parent)
4405     widget = widget->parent;
4406   
4407   return widget;
4408 }
4409
4410 /**
4411  * gtk_widget_get_ancestor:
4412  * @widget: a #GtkWidget
4413  * @widget_type: ancestor type
4414  * 
4415  * Gets the first ancestor of @widget with type @widget_type. For example,
4416  * gtk_widget_get_ancestor (widget, GTK_TYPE_BOX) gets the first #GtkBox that's
4417  * an ancestor of @widget. No reference will be added to the returned widget;
4418  * it should not be unreferenced.
4419  * 
4420  * Return value: the ancestor widget, or %NULL if not found
4421  **/
4422 GtkWidget*
4423 gtk_widget_get_ancestor (GtkWidget *widget,
4424                          GtkType    widget_type)
4425 {
4426   g_return_val_if_fail (widget != NULL, NULL);
4427   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4428   
4429   while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
4430     widget = widget->parent;
4431   
4432   if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
4433     return NULL;
4434   
4435   return widget;
4436 }
4437
4438 /**
4439  * gtk_widget_get_colormap:
4440  * @widget: a #GtkWidget
4441  * 
4442  * Gets the colormap that will be used to render @widget. No reference will
4443  * be added to the returned colormap; it should not be unreferenced.
4444  * 
4445  * Return value: the colormap used by @widget
4446  **/
4447 GdkColormap*
4448 gtk_widget_get_colormap (GtkWidget *widget)
4449 {
4450   GdkColormap *colormap;
4451   
4452   g_return_val_if_fail (widget != NULL, NULL);
4453   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4454   
4455   if (widget->window)
4456     {
4457       colormap = gdk_window_get_colormap (widget->window);
4458       /* If window was destroyed previously, we'll get NULL here */
4459       if (colormap)
4460         return colormap;
4461     }
4462   
4463   colormap = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_colormap);
4464   if (colormap)
4465     return colormap;
4466
4467   return gtk_widget_get_default_colormap ();
4468 }
4469
4470 /**
4471  * gtk_widget_get_visual:
4472  * @widget: a #GtkWidget
4473  * 
4474  * Gets the visual that will be used to render @widget.
4475  * 
4476  * Return value: the visual for @widget
4477  **/
4478 GdkVisual*
4479 gtk_widget_get_visual (GtkWidget *widget)
4480 {
4481   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4482
4483   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
4484 }
4485
4486
4487 /**
4488  * gtk_widget_set_colormap:
4489  * @widget: a #GtkWidget
4490  * @colormap: a colormap
4491  *
4492  * Set the colormap for the widget to the given value. Widget must not
4493  * have been previously realized. This probably should only be used
4494  * from an init() function (i.e. from the constructor for the widget).
4495  * 
4496  **/
4497 void
4498 gtk_widget_set_colormap (GtkWidget   *widget,
4499                          GdkColormap *colormap)
4500 {
4501   g_return_if_fail (widget != NULL);
4502   g_return_if_fail (GTK_IS_WIDGET (widget));
4503   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4504   g_return_if_fail (GDK_IS_COLORMAP (colormap));
4505
4506   g_object_ref (G_OBJECT (colormap));
4507   
4508   g_object_set_qdata_full (G_OBJECT (widget), 
4509                            quark_colormap,
4510                            colormap,
4511                            (GtkDestroyNotify) g_object_unref);
4512 }
4513
4514 /**
4515  * gtk_widget_get_events:
4516  * @widget: a #GtkWidget
4517  * 
4518  * Returns the event mask for the widget (a bitfield containing flags
4519  * from the #GdkEventMask enumeration). These are the events that the widget
4520  * will receive.
4521  * 
4522  * Return value: event mask for @widget
4523  **/
4524 gint
4525 gtk_widget_get_events (GtkWidget *widget)
4526 {
4527   gint *events;
4528   
4529   g_return_val_if_fail (widget != NULL, 0);
4530   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4531   
4532   events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4533   if (events)
4534     return *events;
4535   
4536   return 0;
4537 }
4538
4539 /**
4540  * gtk_widget_get_extension_events:
4541  * @widget: a #GtkWidget
4542  * 
4543  * Retrieves the extension events the widget will receive; see
4544  * gdk_input_set_extension_events().
4545  * 
4546  * Return value: extension events for @widget
4547  **/
4548 GdkExtensionMode
4549 gtk_widget_get_extension_events (GtkWidget *widget)
4550 {
4551   GdkExtensionMode *mode;
4552   
4553   g_return_val_if_fail (widget != NULL, 0);
4554   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4555   
4556   mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4557   if (mode)
4558     return *mode;
4559   
4560   return 0;
4561 }
4562
4563 /**
4564  * gtk_widget_get_pointer:
4565  * @widget: a #GtkWidget
4566  * @x: return location for the X coordinate, or %NULL
4567  * @y: return location for the Y coordinate, or %NULL
4568  *
4569  * Obtains the location of the mouse pointer in widget coordinates.
4570  * Widget coordinates are a bit odd; for historical reasons, they are
4571  * defined as widget->window coordinates for widgets that are not
4572  * #GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
4573  * widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4574  * 
4575  **/
4576 void
4577 gtk_widget_get_pointer (GtkWidget *widget,
4578                         gint      *x,
4579                         gint      *y)
4580 {
4581   g_return_if_fail (widget != NULL);
4582   g_return_if_fail (GTK_IS_WIDGET (widget));
4583   
4584   if (x)
4585     *x = -1;
4586   if (y)
4587     *y = -1;
4588   
4589   if (GTK_WIDGET_REALIZED (widget))
4590     {
4591       gdk_window_get_pointer (widget->window, x, y, NULL);
4592       
4593       if (GTK_WIDGET_NO_WINDOW (widget))
4594         {
4595           if (x)
4596             *x -= widget->allocation.x;
4597           if (y)
4598             *y -= widget->allocation.y;
4599         }
4600     }
4601 }
4602
4603 /**
4604  * gtk_widget_is_ancestor:
4605  * @widget: a #GtkWidget
4606  * @ancestor: another #GtkWidget
4607  * 
4608  * Determines whether @widget is somewhere inside @ancestor, possibly with
4609  * intermediate containers.
4610  * 
4611  * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
4612  **/
4613 gboolean
4614 gtk_widget_is_ancestor (GtkWidget *widget,
4615                         GtkWidget *ancestor)
4616 {
4617   g_return_val_if_fail (widget != NULL, FALSE);
4618   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4619   g_return_val_if_fail (ancestor != NULL, FALSE);
4620   
4621   while (widget)
4622     {
4623       if (widget->parent == ancestor)
4624         return TRUE;
4625       widget = widget->parent;
4626     }
4627   
4628   return FALSE;
4629 }
4630
4631 static GQuark quark_composite_name = 0;
4632
4633 void
4634 gtk_widget_set_composite_name (GtkWidget   *widget,
4635                                const gchar *name)
4636 {
4637   g_return_if_fail (widget != NULL);
4638   g_return_if_fail (GTK_IS_WIDGET (widget));
4639   g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
4640   g_return_if_fail (name != NULL);
4641
4642   if (!quark_composite_name)
4643     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
4644
4645   gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
4646                                   quark_composite_name,
4647                                   g_strdup (name),
4648                                   g_free);
4649 }
4650
4651 gchar*
4652 gtk_widget_get_composite_name (GtkWidget *widget)
4653 {
4654   g_return_val_if_fail (widget != NULL, NULL);
4655   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4656
4657   if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
4658     return gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
4659                                                widget);
4660   else
4661     return NULL;
4662 }
4663
4664 void
4665 gtk_widget_push_composite_child (void)
4666 {
4667   composite_child_stack++;
4668 }
4669
4670 void
4671 gtk_widget_pop_composite_child (void)
4672 {
4673   if (composite_child_stack)
4674     composite_child_stack--;
4675 }
4676
4677 /**
4678  * gtk_widget_push_colormap:
4679  * @cmap: a #GdkColormap
4680  *
4681  * Pushes @cmap onto a global stack of colormaps; the topmost
4682  * colormap on the stack will be used to create all widgets.
4683  * Remove @cmap with gtk_widget_pop_colormap(). There's little
4684  * reason to use this function.
4685  * 
4686  **/
4687 void
4688 gtk_widget_push_colormap (GdkColormap *cmap)
4689 {
4690   g_return_if_fail (cmap != NULL);
4691
4692   colormap_stack = g_slist_prepend (colormap_stack, cmap);
4693 }
4694
4695 /**
4696  * gtk_widget_pop_colormap:
4697  *
4698  * Removes a colormap pushed with gtk_widget_push_colormap().
4699  * 
4700  **/
4701 void
4702 gtk_widget_pop_colormap (void)
4703 {
4704   GSList *tmp;
4705   
4706   if (colormap_stack)
4707     {
4708       tmp = colormap_stack;
4709       colormap_stack = colormap_stack->next;
4710       g_slist_free_1 (tmp);
4711     }
4712 }
4713
4714 /**
4715  * gtk_widget_set_default_colormap:
4716  * @colormap: a #GdkColormap
4717  * 
4718  * Sets the default colormap to use when creating widgets.
4719  * gtk_widget_push_colormap() is a better function to use if
4720  * you only want to affect a few widgets, rather than all widgets.
4721  * 
4722  **/
4723 void
4724 gtk_widget_set_default_colormap (GdkColormap *colormap)
4725 {
4726   if (default_colormap != colormap)
4727     {
4728       if (default_colormap)
4729         gdk_colormap_unref (default_colormap);
4730       default_colormap = colormap;
4731       if (default_colormap)
4732         gdk_colormap_ref (default_colormap);
4733     }
4734 }
4735
4736 /**
4737  * gtk_widget_get_default_colormap:
4738  * 
4739  * Obtains the default colormap used to create widgets.
4740  * 
4741  * Return value: default widget colormap
4742  **/
4743 GdkColormap*
4744 gtk_widget_get_default_colormap (void)
4745 {
4746   if (!default_colormap)
4747     gtk_widget_set_default_colormap (gdk_colormap_get_system ());
4748   
4749   return default_colormap;
4750 }
4751
4752 /**
4753  * gtk_widget_get_default_visual:
4754  * 
4755  * Obtains the visual of the default colormap. Not really useful;
4756  * used to be useful before gdk_colormap_get_visual() existed.
4757  * 
4758  * Return value: visual of the default colormap
4759  **/
4760 GdkVisual*
4761 gtk_widget_get_default_visual (void)
4762 {
4763   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
4764 }
4765
4766 static void
4767 gtk_widget_emit_direction_changed (GtkWidget        *widget,
4768                                    GtkTextDirection  old_dir)
4769 {
4770   PangoContext *context = gtk_widget_peek_pango_context (widget);
4771
4772   if (context)
4773     pango_context_set_base_dir (context,
4774                                 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4775                                   PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4776   
4777   gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
4778 }
4779
4780 /**
4781  * gtk_widget_set_direction:
4782  * @widget: a #GtkWidget
4783  * @dir:    the new direction
4784  * 
4785  * Set the reading direction on a particular widget. This direction
4786  * controls the primary direction for widgets containing text,
4787  * and also the direction in which the children of a container are
4788  * packed. The ability to set the direction is present in order
4789  * so that correct localization into languages with right-to-left
4790  * reading directions can be done. Generally, applications will
4791  * let the default reading direction present, except for containers
4792  * where the containers are arranged in an order that is explicitely
4793  * visual rather than logical (such as buttons for text justificiation).
4794  *
4795  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
4796  * set by gtk_widget_set_default_direction() will be used.
4797  **/
4798 void
4799 gtk_widget_set_direction (GtkWidget        *widget,
4800                           GtkTextDirection  dir)
4801 {
4802   GtkTextDirection old_dir;
4803   
4804   g_return_if_fail (widget != NULL);
4805   g_return_if_fail (GTK_IS_WIDGET (widget));
4806   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
4807
4808   old_dir = gtk_widget_get_direction (widget);
4809   
4810   if (dir == GTK_TEXT_DIR_NONE)
4811     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
4812   else
4813     {
4814       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
4815       if (dir == GTK_TEXT_DIR_LTR)
4816         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
4817       else
4818         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
4819     }
4820
4821   if (old_dir != gtk_widget_get_direction (widget))
4822     gtk_widget_emit_direction_changed (widget, old_dir);
4823 }
4824
4825 /**
4826  * gtk_widget_get_direction:
4827  * @widget: a #GtkWidget
4828  * 
4829  * Get the reading direction for a particular widget. See
4830  * gtk_widget_set_direction().
4831  * 
4832  * Return value: the reading direction for the widget.
4833  **/
4834 GtkTextDirection
4835 gtk_widget_get_direction (GtkWidget *widget)
4836 {
4837   g_return_val_if_fail (widget != NULL, GTK_TEXT_DIR_LTR);
4838   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
4839   
4840   if (GTK_WIDGET_DIRECTION_SET (widget))
4841     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
4842   else
4843     return gtk_default_direction;
4844 }
4845
4846 static void
4847 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
4848 {
4849   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
4850
4851   g_object_ref (G_OBJECT (widget));
4852   
4853   if (!GTK_WIDGET_DIRECTION_SET (widget))
4854     gtk_widget_emit_direction_changed (widget, old_dir);
4855   
4856   if (GTK_IS_CONTAINER (widget))
4857     gtk_container_forall (GTK_CONTAINER (widget),
4858                           gtk_widget_set_default_direction_recurse,
4859                           data);
4860
4861   g_object_unref (G_OBJECT (widget));
4862 }
4863
4864 /**
4865  * gtk_widget_set_default_direction:
4866  * @dir: the new default direction. This cannot be
4867  *        %GTK_TEXT_DIR_NONE.
4868  * 
4869  * Set the default reading direction for widgets where the
4870  * direction has not been explicitly set by gtk_widget_set_direction().
4871  **/
4872 void
4873 gtk_widget_set_default_direction (GtkTextDirection dir)
4874 {
4875   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
4876
4877   if (dir != gtk_default_direction)
4878     {
4879       GList *toplevels, *tmp_list;
4880       GtkTextDirection old_dir = gtk_default_direction;
4881       
4882       gtk_default_direction = dir;
4883
4884       tmp_list = toplevels = gtk_window_list_toplevels ();
4885       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
4886       
4887       while (tmp_list)
4888         {
4889           gtk_widget_set_default_direction_recurse (tmp_list->data,
4890                                                     GUINT_TO_POINTER (old_dir));
4891           g_object_unref (tmp_list->data);
4892           tmp_list = tmp_list->next;
4893         }
4894
4895       g_list_free (toplevels);
4896     }
4897 }
4898
4899 /**
4900  * gtk_widget_get_default_direction:
4901  * 
4902  * Return value: the current default direction. See
4903  * gtk_widget_set_direction().
4904  **/
4905 GtkTextDirection
4906 gtk_widget_get_default_direction (void)
4907 {
4908   return gtk_default_direction;
4909 }
4910
4911 static void
4912 gtk_widget_shutdown (GObject *object)
4913 {
4914   GtkWidget *widget = GTK_WIDGET (object);
4915
4916   if (widget->parent)
4917     gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4918
4919   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
4920   if (GTK_WIDGET_REALIZED (widget))
4921     gtk_widget_unrealize (widget);
4922   
4923   G_OBJECT_CLASS (parent_class)->shutdown (object);
4924 }
4925
4926 static void
4927 gtk_widget_real_destroy (GtkObject *object)
4928 {
4929   GtkWidget *widget;
4930   GtkStyle *saved_style;
4931
4932   /* gtk_object_destroy() will already hold a refcount on object
4933    */
4934   widget = GTK_WIDGET (object);
4935
4936   gtk_grab_remove (widget);
4937   gtk_selection_remove_all (widget);
4938   
4939   saved_style = gtk_object_get_data_by_id (object, quark_saved_default_style);
4940   if (saved_style)
4941     {
4942       gtk_style_unref (saved_style);
4943       gtk_object_remove_data_by_id (object, quark_saved_default_style);
4944     }
4945
4946   gtk_style_unref (widget->style);
4947   widget->style = gtk_widget_peek_style ();
4948   gtk_style_ref (widget->style);
4949
4950   GTK_OBJECT_CLASS (parent_class)->destroy (object);
4951 }
4952
4953 static void
4954 gtk_widget_finalize (GObject *object)
4955 {
4956   GtkWidget *widget = GTK_WIDGET (object);
4957   GtkWidgetAuxInfo *aux_info;
4958   gint *events;
4959   GdkExtensionMode *mode;
4960   GtkStyle *saved_style;
4961   GtkAccessible *accessible;
4962   
4963   gtk_grab_remove (widget);
4964   gtk_selection_remove_all (widget);
4965
4966   saved_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
4967   if (saved_style)
4968     {
4969       gtk_style_unref (saved_style);
4970       gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
4971     }
4972
4973   gtk_style_unref (widget->style);
4974   widget->style = NULL;
4975
4976   if (widget->name)
4977     g_free (widget->name);
4978   
4979   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4980   if (aux_info)
4981     gtk_widget_aux_info_destroy (aux_info);
4982   
4983   events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4984   if (events)
4985     g_free (events);
4986   
4987   mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4988   if (mode)
4989     g_free (mode);
4990
4991   accessible = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accessible_object);
4992   if (accessible)
4993     g_object_unref (G_OBJECT (accessible));
4994
4995   G_OBJECT_CLASS (parent_class)->finalize (object);
4996 }
4997
4998 /*****************************************
4999  * gtk_widget_real_map:
5000  *
5001  *   arguments:
5002  *
5003  *   results:
5004  *****************************************/
5005
5006 static void
5007 gtk_widget_real_map (GtkWidget *widget)
5008 {
5009   g_return_if_fail (GTK_IS_WIDGET (widget));
5010   g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
5011   
5012   if (!GTK_WIDGET_MAPPED (widget))
5013     {
5014       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
5015       
5016       if (!GTK_WIDGET_NO_WINDOW (widget))
5017         gdk_window_show (widget->window);
5018     }
5019 }
5020
5021 /*****************************************
5022  * gtk_widget_real_unmap:
5023  *
5024  *   arguments:
5025  *
5026  *   results:
5027  *****************************************/
5028
5029 static void
5030 gtk_widget_real_unmap (GtkWidget *widget)
5031 {
5032   g_return_if_fail (widget != NULL);
5033   g_return_if_fail (GTK_IS_WIDGET (widget));
5034   
5035   if (GTK_WIDGET_MAPPED (widget))
5036     {
5037       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5038
5039       if (!GTK_WIDGET_NO_WINDOW (widget))
5040         gdk_window_hide (widget->window);
5041     }
5042 }
5043
5044 /*****************************************
5045  * gtk_widget_real_realize:
5046  *
5047  *   arguments:
5048  *
5049  *   results:
5050  *****************************************/
5051
5052 static void
5053 gtk_widget_real_realize (GtkWidget *widget)
5054 {
5055   g_return_if_fail (widget != NULL);
5056   g_return_if_fail (GTK_IS_WIDGET (widget));
5057   g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
5058   
5059   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
5060   if (widget->parent)
5061     {
5062       widget->window = gtk_widget_get_parent_window (widget);
5063       gdk_window_ref (widget->window);
5064     }
5065   widget->style = gtk_style_attach (widget->style, widget->window);
5066 }
5067
5068 /*****************************************
5069  * gtk_widget_real_unrealize:
5070  *
5071  *   arguments:
5072  *
5073  *   results:
5074  *****************************************/
5075
5076 static void
5077 gtk_widget_real_unrealize (GtkWidget *widget)
5078 {
5079   g_return_if_fail (widget != NULL);
5080   g_return_if_fail (GTK_IS_WIDGET (widget));
5081
5082   if (GTK_WIDGET_MAPPED (widget))
5083     gtk_widget_real_unmap (widget);
5084
5085   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5086
5087   /* printf ("unrealizing %s\n", gtk_type_name (GTK_OBJECT (widget)->klass->type));
5088    */
5089
5090    /* We must do unrealize child widget BEFORE container widget.
5091     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
5092     * So, unrealizing container widget bofore its children causes the problem 
5093     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
5094     */
5095
5096   if (GTK_IS_CONTAINER (widget))
5097     gtk_container_forall (GTK_CONTAINER (widget),
5098                           (GtkCallback) gtk_widget_unrealize,
5099                           NULL);
5100
5101   gtk_style_detach (widget->style);
5102   if (!GTK_WIDGET_NO_WINDOW (widget))
5103     {
5104       gdk_window_set_user_data (widget->window, NULL);
5105       gdk_window_destroy (widget->window);
5106       widget->window = NULL;
5107     }
5108   else
5109     {
5110       gdk_window_unref (widget->window);
5111       widget->window = NULL;
5112     }
5113
5114   GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
5115 }
5116
5117 static void
5118 gtk_widget_real_size_request (GtkWidget         *widget,
5119                               GtkRequisition    *requisition)
5120 {
5121   g_return_if_fail (widget != NULL);
5122   g_return_if_fail (GTK_IS_WIDGET (widget));
5123
5124   requisition->width = widget->requisition.width;
5125   requisition->height = widget->requisition.height;
5126 }
5127
5128 /*****************************************
5129  * gtk_widget_peek_colormap:
5130  *
5131  *   arguments:
5132  *
5133  *   results:
5134  *****************************************/
5135
5136 static GdkColormap*
5137 gtk_widget_peek_colormap (void)
5138 {
5139   if (colormap_stack)
5140     return (GdkColormap*) colormap_stack->data;
5141   return gtk_widget_get_default_colormap ();
5142 }
5143
5144 static void
5145 gtk_widget_propagate_state (GtkWidget           *widget,
5146                             GtkStateData        *data)
5147 {
5148   guint8 old_state;
5149
5150   /* don't call this function with state==GTK_STATE_INSENSITIVE,
5151    * parent_sensitive==TRUE on a sensitive widget
5152    */
5153
5154   old_state = GTK_WIDGET_STATE (widget);
5155
5156   if (data->parent_sensitive)
5157     {
5158       GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5159
5160       if (GTK_WIDGET_IS_SENSITIVE (widget))
5161         {
5162           if (data->state_restoration)
5163             GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
5164           else
5165             GTK_WIDGET_STATE (widget) = data->state;
5166         }
5167       else
5168         {
5169           GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5170           if (!data->state_restoration &&
5171               data->state != GTK_STATE_INSENSITIVE)
5172             GTK_WIDGET_SAVED_STATE (widget) = data->state;
5173         }
5174     }
5175   else
5176     {
5177       GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5178       if (!data->state_restoration)
5179         {
5180           if (data->state != GTK_STATE_INSENSITIVE)
5181             GTK_WIDGET_SAVED_STATE (widget) = data->state;
5182         }
5183       else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
5184         GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
5185       GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5186     }
5187
5188   if (GTK_WIDGET_HAS_FOCUS (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
5189     {
5190       GtkWidget *window;
5191
5192       window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
5193       if (window)
5194         gtk_window_set_focus (GTK_WINDOW (window), NULL);
5195     }
5196
5197   if (old_state != GTK_WIDGET_STATE (widget))
5198     {
5199       gtk_widget_ref (widget);
5200       gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STATE_CHANGED], old_state);
5201       
5202       if (GTK_IS_CONTAINER (widget))
5203         {
5204           data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
5205           data->state = GTK_WIDGET_STATE (widget);
5206           if (data->use_forall)
5207             gtk_container_forall (GTK_CONTAINER (widget),
5208                                   (GtkCallback) gtk_widget_propagate_state,
5209                                   data);
5210           else
5211             gtk_container_foreach (GTK_CONTAINER (widget),
5212                                    (GtkCallback) gtk_widget_propagate_state,
5213                                    data);
5214         }
5215       gtk_widget_unref (widget);
5216     }
5217 }
5218
5219 /**
5220  * _gtk_widget_get_aux_info:
5221  * @widget: a #GtkWidget
5222  * @create: if %TRUE, create the structure if it doesn't exist
5223  * 
5224  * Get the #GtkWidgetAuxInfo structure for the widget.
5225  * 
5226  * Return value: the #GtkAuxInfo structure for the widget, or
5227  *    %NULL if @create is %FALSE and one doesn't already exist.
5228  **/
5229 GtkWidgetAuxInfo*
5230 _gtk_widget_get_aux_info (GtkWidget *widget,
5231                           gboolean   create)
5232 {
5233   GtkWidgetAuxInfo *aux_info;
5234   
5235   aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_aux_info);
5236   if (!aux_info && create)
5237     {
5238       if (!aux_info_mem_chunk)
5239         aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
5240                                               sizeof (GtkWidgetAuxInfo),
5241                                               1024, G_ALLOC_AND_FREE);
5242       aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
5243
5244       aux_info->width = -1;
5245       aux_info->height = -1;
5246       aux_info->x = 0;
5247       aux_info->y = 0;
5248       aux_info->x_set = FALSE;
5249       aux_info->y_set = FALSE;
5250       gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_aux_info, aux_info);
5251     }
5252   
5253   return aux_info;
5254 }
5255
5256 /*****************************************
5257  * gtk_widget_aux_info_destroy:
5258  *
5259  *   arguments:
5260  *
5261  *   results:
5262  *****************************************/
5263
5264 static void
5265 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
5266 {
5267   g_return_if_fail (aux_info != NULL);
5268   
5269   g_mem_chunk_free (aux_info_mem_chunk, aux_info);
5270 }
5271
5272 static void
5273 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
5274 {
5275   gdk_drawable_unref (info->shape_mask);
5276   g_free (info);
5277 }
5278
5279 /*****************************************
5280  * gtk_widget_shape_combine_mask: 
5281  *   set a shape for this widgets' gdk window, this allows for
5282  *   transparent windows etc., see gdk_window_shape_combine_mask
5283  *   for more information
5284  *
5285  *   arguments:
5286  *
5287  *   results:
5288  *****************************************/
5289 void
5290 gtk_widget_shape_combine_mask (GtkWidget *widget,
5291                                GdkBitmap *shape_mask,
5292                                gint       offset_x,
5293                                gint       offset_y)
5294 {
5295   GtkWidgetShapeInfo* shape_info;
5296   
5297   g_return_if_fail (widget != NULL);
5298   g_return_if_fail (GTK_IS_WIDGET (widget));
5299   /*  set_shape doesn't work on widgets without gdk window */
5300   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
5301
5302   if (!shape_mask)
5303     {
5304       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5305       
5306       if (widget->window)
5307         gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
5308       
5309       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
5310     }
5311   else
5312     {
5313       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5314       
5315       shape_info = g_new (GtkWidgetShapeInfo, 1);
5316       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
5317                                (GDestroyNotify) gtk_widget_shape_info_destroy);
5318       
5319       shape_info->shape_mask = gdk_drawable_ref (shape_mask);
5320       shape_info->offset_x = offset_x;
5321       shape_info->offset_y = offset_y;
5322       
5323       /* set shape if widget has a gdk window allready.
5324        * otherwise the shape is scheduled to be set by gtk_widget_realize.
5325        */
5326       if (widget->window)
5327         gdk_window_shape_combine_mask (widget->window, shape_mask,
5328                                        offset_x, offset_y);
5329     }
5330 }
5331
5332 static void
5333 gtk_reset_shapes_recurse (GtkWidget *widget,
5334                           GdkWindow *window)
5335 {
5336   gpointer data;
5337   GList *list;
5338
5339   gdk_window_get_user_data (window, &data);
5340   if (data != widget)
5341     return;
5342
5343   gdk_window_shape_combine_mask (window, NULL, 0, 0);
5344   for (list = gdk_window_peek_children (window); list; list = list->next)
5345     gtk_reset_shapes_recurse (widget, list->data);
5346 }
5347
5348 void
5349 gtk_widget_reset_shapes (GtkWidget *widget)
5350 {
5351   g_return_if_fail (widget != NULL);
5352   g_return_if_fail (GTK_IS_WIDGET (widget));
5353   g_return_if_fail (GTK_WIDGET_REALIZED (widget));
5354
5355   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
5356     gtk_reset_shapes_recurse (widget, widget->window);
5357 }
5358
5359 /**
5360  * gtk_widget_ref:
5361  * @widget: a #GtkWidget
5362  * 
5363  * Adds a reference to a widget. This function is exactly the same
5364  * as calling g_object_ref(), and exists mostly for historical
5365  * reasons. It can still be convenient to avoid casting a widget
5366  * to a #GObject, it saves a small amount of typing.
5367  * 
5368  * Return value: the widget that was referenced
5369  **/
5370 GtkWidget*
5371 gtk_widget_ref (GtkWidget *widget)
5372 {
5373   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5374
5375   return (GtkWidget*) g_object_ref ((GObject*) widget);
5376 }
5377
5378 /**
5379  * gtk_widget_unref:
5380  * @widget: a #GtkWidget
5381  *
5382  * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
5383  * 
5384  **/
5385 void
5386 gtk_widget_unref (GtkWidget *widget)
5387 {
5388   g_return_if_fail (GTK_IS_WIDGET (widget));
5389
5390   g_object_unref ((GObject*) widget);
5391 }
5392
5393
5394 /* style properties
5395  */
5396
5397 void
5398 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *class,
5399                                                 GParamSpec         *pspec,
5400                                                 GtkRcPropertyParser parser)
5401 {
5402   g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5403   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5404   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
5405   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
5406   
5407   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
5408     {
5409       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
5410                  G_OBJECT_CLASS_NAME (class),
5411                  pspec->name);
5412       return;
5413     }
5414
5415   g_param_spec_ref (pspec);
5416   g_param_spec_sink (pspec);
5417   g_param_spec_set_qdata (pspec, quark_property_parser, parser);
5418   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
5419 }
5420
5421 void
5422 gtk_widget_class_install_style_property (GtkWidgetClass *class,
5423                                          GParamSpec     *pspec)
5424 {
5425   GtkRcPropertyParser parser;
5426
5427   g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5428   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5429
5430   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
5431
5432   gtk_widget_class_install_style_property_parser (class, pspec, parser);
5433 }
5434
5435 void
5436 gtk_widget_style_get_property (GtkWidget   *widget,
5437                                const gchar *property_name,
5438                                GValue      *value)
5439 {
5440   GParamSpec *pspec;
5441
5442   g_return_if_fail (GTK_IS_WIDGET (widget));
5443   g_return_if_fail (property_name != NULL);
5444   g_return_if_fail (G_IS_VALUE (value));
5445
5446   g_object_ref (widget);
5447   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5448                                     property_name,
5449                                     G_OBJECT_TYPE (widget),
5450                                     TRUE);
5451   if (!pspec)
5452     g_warning ("%s: widget class `%s' has no property named `%s'",
5453                G_STRLOC,
5454                G_OBJECT_TYPE_NAME (widget),
5455                property_name);
5456   else
5457     {
5458       const GValue *peek_value;
5459
5460       peek_value = _gtk_style_peek_property_value (widget->style,
5461                                                    G_OBJECT_TYPE (widget),
5462                                                    pspec,
5463                                                    g_param_spec_get_qdata (pspec, quark_property_parser));
5464       
5465       /* auto-conversion of the caller's value type
5466        */
5467       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
5468         g_value_copy (peek_value, value);
5469       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
5470         g_value_transform (peek_value, value);
5471       else
5472         g_warning ("can't retrive style property `%s' of type `%s' as value of type `%s'",
5473                    pspec->name,
5474                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
5475                    G_VALUE_TYPE_NAME (value));
5476     }
5477   g_object_unref (widget);
5478 }
5479
5480 void
5481 gtk_widget_style_get_valist (GtkWidget   *widget,
5482                              const gchar *first_property_name,
5483                              va_list      var_args)
5484 {
5485   const gchar *name;
5486
5487   g_return_if_fail (GTK_IS_WIDGET (widget));
5488
5489   g_object_ref (widget);
5490
5491   name = first_property_name;
5492   while (name)
5493     {
5494       const GValue *peek_value;
5495       GParamSpec *pspec;
5496       gchar *error;
5497
5498       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5499                                         name,
5500                                         G_OBJECT_TYPE (widget),
5501                                         TRUE);
5502       if (!pspec)
5503         {
5504           g_warning ("%s: widget class `%s' has no property named `%s'",
5505                      G_STRLOC,
5506                      G_OBJECT_TYPE_NAME (widget),
5507                      name);
5508           break;
5509         }
5510       /* style pspecs are always readable so we can spare that check here */
5511
5512       peek_value = _gtk_style_peek_property_value (widget->style,
5513                                                    G_OBJECT_TYPE (widget),
5514                                                    pspec,
5515                                                    g_param_spec_get_qdata (pspec, quark_property_parser));
5516       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
5517       if (error)
5518         {
5519           g_warning ("%s: %s", G_STRLOC, error);
5520           g_free (error);
5521           break;
5522         }
5523
5524       name = va_arg (var_args, gchar*);
5525     }
5526
5527   g_object_unref (widget);
5528 }
5529
5530 void
5531 gtk_widget_style_get (GtkWidget   *widget,
5532                       const gchar *first_property_name,
5533                       ...)
5534 {
5535   va_list var_args;
5536
5537   g_return_if_fail (GTK_IS_WIDGET (widget));
5538
5539   va_start (var_args, first_property_name);
5540   gtk_widget_style_get_valist (widget, first_property_name, var_args);
5541   va_end (var_args);
5542 }
5543
5544 /**
5545  * gtk_widget_path:
5546  * @widget: a #GtkWidget
5547  * @path_length: location to store length of the path
5548  * @path: location to store allocated path string 
5549  * @path_reversed: location to store allocated reverse path string
5550  *
5551  * Obtains the full path to @widget. The path is simply the name of a
5552  * widget and all its parents in the container hierarchy, separated by
5553  * periods. The name of a widget comes from
5554  * gtk_widget_get_name(). Paths are used to apply styles to a widget
5555  * in gtkrc configuration files.  Widget names are the type of the
5556  * widget by default (e.g. "GtkButton") or can be set to an
5557  * application-specific value with gtk_widget_set_name().  By setting
5558  * the name of a widget, you allow users or theme authors to apply
5559  * styles to that specific widget in their gtkrc
5560  * file. @path_reversed_p fills in the path in reverse order,
5561  * i.e. starting with @widget's name instead of starting with the name
5562  * of @widget's outermost ancestor.
5563  * 
5564  **/
5565 void
5566 gtk_widget_path (GtkWidget *widget,
5567                  guint     *path_length_p,
5568                  gchar    **path_p,
5569                  gchar    **path_reversed_p)
5570 {
5571   static gchar *rev_path = NULL;
5572   static guint  path_len = 0;
5573   guint len;
5574   
5575   g_return_if_fail (widget != NULL);
5576   g_return_if_fail (GTK_IS_WIDGET (widget));
5577   
5578   len = 0;
5579   do
5580     {
5581       const gchar *string;
5582       const gchar *s;
5583       gchar *d;
5584       guint l;
5585       
5586       string = gtk_widget_get_name (widget);
5587       l = strlen (string);
5588       while (path_len <= len + l + 1)
5589         {
5590           path_len += INIT_PATH_SIZE;
5591           rev_path = g_realloc (rev_path, path_len);
5592         }
5593       s = string + l - 1;
5594       d = rev_path + len;
5595       while (s >= string)
5596         *(d++) = *(s--);
5597       len += l;
5598       
5599       widget = widget->parent;
5600       
5601       if (widget)
5602         rev_path[len++] = '.';
5603       else
5604         rev_path[len++] = 0;
5605     }
5606   while (widget);
5607   
5608   if (path_length_p)
5609     *path_length_p = len - 1;
5610   if (path_reversed_p)
5611     *path_reversed_p = g_strdup (rev_path);
5612   if (path_p)
5613     {
5614       *path_p = g_strdup (rev_path);
5615       g_strreverse (*path_p);
5616     }
5617 }
5618
5619 /**
5620  * gtk_widget_class_path:
5621  * @widget: a #GtkWidget
5622  * @path_length: location to store the length of the class path
5623  * @path: location to store the class path as an allocated string
5624  * @path_reversed: location to store the reverse class path as an allocated string
5625  *
5626  * Same as gtk_widget_path(), but always uses the name of a widget's type,
5627  * never uses a custom name set with gtk_widget_set_name().
5628  * 
5629  **/
5630 void
5631 gtk_widget_class_path (GtkWidget *widget,
5632                        guint     *path_length_p,
5633                        gchar    **path_p,
5634                        gchar    **path_reversed_p)
5635 {
5636   static gchar *rev_path = NULL;
5637   static guint  path_len = 0;
5638   guint len;
5639   
5640   g_return_if_fail (widget != NULL);
5641   g_return_if_fail (GTK_IS_WIDGET (widget));
5642   
5643   len = 0;
5644   do
5645     {
5646       const gchar *string;
5647       const gchar *s;
5648       gchar *d;
5649       guint l;
5650       
5651       string = gtk_type_name (GTK_WIDGET_TYPE (widget));
5652       l = strlen (string);
5653       while (path_len <= len + l + 1)
5654         {
5655           path_len += INIT_PATH_SIZE;
5656           rev_path = g_realloc (rev_path, path_len);
5657         }
5658       s = string + l - 1;
5659       d = rev_path + len;
5660       while (s >= string)
5661         *(d++) = *(s--);
5662       len += l;
5663       
5664       widget = widget->parent;
5665       
5666       if (widget)
5667         rev_path[len++] = '.';
5668       else
5669         rev_path[len++] = 0;
5670     }
5671   while (widget);
5672   
5673   if (path_length_p)
5674     *path_length_p = len - 1;
5675   if (path_reversed_p)
5676     *path_reversed_p = g_strdup (rev_path);
5677   if (path_p)
5678     {
5679       *path_p = g_strdup (rev_path);
5680       g_strreverse (*path_p);
5681     }
5682 }
5683
5684 GtkRequisition *
5685 gtk_requisition_copy (const GtkRequisition *requisition)
5686 {
5687   return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
5688 }
5689
5690 void
5691 gtk_requisition_free (GtkRequisition *requisition)
5692 {
5693   g_free (requisition);
5694 }
5695
5696 AtkObject* gtk_widget_get_accessible (GtkWidget *widget)
5697 {
5698   GtkWidgetClass *klass;
5699
5700   g_return_val_if_fail (widget != NULL, NULL);
5701   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5702
5703   klass = GTK_WIDGET_GET_CLASS (widget);
5704
5705   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
5706
5707   return klass->get_accessible(widget);
5708 }
5709
5710 AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget)
5711 {
5712   AtkObject* accessible;
5713
5714   accessible = g_object_get_qdata (G_OBJECT (widget), 
5715                                    quark_accessible_object);
5716   if (!accessible)
5717   {
5718     AtkObjectFactory *factory;
5719     AtkRegistry *default_registry;
5720
5721     default_registry = atk_get_default_registry ();
5722     factory = atk_registry_get_factory (default_registry, 
5723                                         GTK_OBJECT_TYPE (widget));
5724     accessible =
5725       atk_object_factory_create_accessible (factory,
5726                                                G_OBJECT(widget));
5727     g_object_set_qdata (G_OBJECT (widget), 
5728                         quark_accessible_object,
5729                         accessible);
5730   }
5731   return accessible;
5732 }
5733
5734 /*
5735  * Initialize a AtkImplementorIface instance's virtual pointers as
5736  * appropriate to this implementor's class (GtkWidget).
5737  */
5738 static void
5739 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
5740 {
5741   iface->ref_accessible = gtk_widget_ref_accessible;
5742 }
5743
5744 static AtkObject*
5745 gtk_widget_ref_accessible(AtkImplementor *implementor)
5746 {
5747   AtkObject *accessible;
5748
5749   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
5750   if (accessible)
5751     g_object_ref (G_OBJECT (accessible));
5752   return accessible;
5753 }