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