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