]> Pileus Git - ~andy/gtk/blob - gtk/gtkwidget.c
gtk_widget_set_property(): use gtk_widget_set_visible()
[~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 "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
56 #include "gtkalias.h"
57
58 #define WIDGET_CLASS(w)  GTK_WIDGET_GET_CLASS (w)
59 #define INIT_PATH_SIZE  (512)
60
61
62 enum {
63   SHOW,
64   HIDE,
65   MAP,
66   UNMAP,
67   REALIZE,
68   UNREALIZE,
69   SIZE_REQUEST,
70   SIZE_ALLOCATE,
71   STATE_CHANGED,
72   PARENT_SET,
73   HIERARCHY_CHANGED,
74   STYLE_SET,
75   DIRECTION_CHANGED,
76   GRAB_NOTIFY,
77   CHILD_NOTIFY,
78   MNEMONIC_ACTIVATE,
79   GRAB_FOCUS,
80   FOCUS,
81   MOVE_FOCUS,
82   EVENT,
83   EVENT_AFTER,
84   BUTTON_PRESS_EVENT,
85   BUTTON_RELEASE_EVENT,
86   SCROLL_EVENT,
87   MOTION_NOTIFY_EVENT,
88   DELETE_EVENT,
89   DESTROY_EVENT,
90   EXPOSE_EVENT,
91   KEY_PRESS_EVENT,
92   KEY_RELEASE_EVENT,
93   ENTER_NOTIFY_EVENT,
94   LEAVE_NOTIFY_EVENT,
95   CONFIGURE_EVENT,
96   FOCUS_IN_EVENT,
97   FOCUS_OUT_EVENT,
98   MAP_EVENT,
99   UNMAP_EVENT,
100   PROPERTY_NOTIFY_EVENT,
101   SELECTION_CLEAR_EVENT,
102   SELECTION_REQUEST_EVENT,
103   SELECTION_NOTIFY_EVENT,
104   SELECTION_GET,
105   SELECTION_RECEIVED,
106   PROXIMITY_IN_EVENT,
107   PROXIMITY_OUT_EVENT,
108   DRAG_BEGIN,
109   DRAG_END,
110   DRAG_DATA_DELETE,
111   DRAG_LEAVE,
112   DRAG_MOTION,
113   DRAG_DROP,
114   DRAG_DATA_GET,
115   DRAG_DATA_RECEIVED,
116   CLIENT_EVENT,
117   NO_EXPOSE_EVENT,
118   VISIBILITY_NOTIFY_EVENT,
119   WINDOW_STATE_EVENT,
120   POPUP_MENU,
121   SHOW_HELP,
122   ACCEL_CLOSURES_CHANGED,
123   SCREEN_CHANGED,
124   CAN_ACTIVATE_ACCEL,
125   GRAB_BROKEN,
126   COMPOSITED_CHANGED,
127   QUERY_TOOLTIP,
128   KEYNAV_FAILED,
129   DRAG_FAILED,
130   DAMAGE_EVENT,
131   LAST_SIGNAL
132 };
133
134 enum {
135   PROP_0,
136   PROP_NAME,
137   PROP_PARENT,
138   PROP_WIDTH_REQUEST,
139   PROP_HEIGHT_REQUEST,
140   PROP_VISIBLE,
141   PROP_SENSITIVE,
142   PROP_APP_PAINTABLE,
143   PROP_CAN_FOCUS,
144   PROP_HAS_FOCUS,
145   PROP_IS_FOCUS,
146   PROP_CAN_DEFAULT,
147   PROP_HAS_DEFAULT,
148   PROP_RECEIVES_DEFAULT,
149   PROP_COMPOSITE_CHILD,
150   PROP_STYLE,
151   PROP_EVENTS,
152   PROP_EXTENSION_EVENTS,
153   PROP_NO_SHOW_ALL,
154   PROP_HAS_TOOLTIP,
155   PROP_TOOLTIP_MARKUP,
156   PROP_TOOLTIP_TEXT,
157   PROP_WINDOW,
158   PROP_DOUBLE_BUFFERED
159 };
160
161 typedef struct  _GtkStateData    GtkStateData;
162
163 struct _GtkStateData
164 {
165   GtkStateType  state;
166   guint         state_restoration : 1;
167   guint         parent_sensitive : 1;
168   guint         use_forall : 1;
169 };
170
171 /* --- prototypes --- */
172 static void     gtk_widget_class_init           (GtkWidgetClass     *klass);
173 static void     gtk_widget_base_class_finalize  (GtkWidgetClass     *klass);
174 static void     gtk_widget_init                 (GtkWidget          *widget);
175 static void     gtk_widget_set_property          (GObject           *object,
176                                                   guint              prop_id,
177                                                   const GValue      *value,
178                                                   GParamSpec        *pspec);
179 static void     gtk_widget_get_property          (GObject           *object,
180                                                   guint              prop_id,
181                                                   GValue            *value,
182                                                   GParamSpec        *pspec);
183 static void     gtk_widget_dispose               (GObject           *object);
184 static void     gtk_widget_real_destroy          (GtkObject         *object);
185 static void     gtk_widget_finalize              (GObject           *object);
186 static void     gtk_widget_real_show             (GtkWidget         *widget);
187 static void     gtk_widget_real_hide             (GtkWidget         *widget);
188 static void     gtk_widget_real_map              (GtkWidget         *widget);
189 static void     gtk_widget_real_unmap            (GtkWidget         *widget);
190 static void     gtk_widget_real_realize          (GtkWidget         *widget);
191 static void     gtk_widget_real_unrealize        (GtkWidget         *widget);
192 static void     gtk_widget_real_size_request     (GtkWidget         *widget,
193                                                   GtkRequisition    *requisition);
194 static void     gtk_widget_real_size_allocate    (GtkWidget         *widget,
195                                                   GtkAllocation     *allocation);
196 static void     gtk_widget_real_style_set        (GtkWidget         *widget,
197                                                   GtkStyle          *previous_style);
198 static void     gtk_widget_real_direction_changed(GtkWidget         *widget,
199                                                   GtkTextDirection   previous_direction);
200
201 static void     gtk_widget_real_grab_focus       (GtkWidget         *focus_widget);
202 static gboolean gtk_widget_real_query_tooltip    (GtkWidget         *widget,
203                                                   gint               x,
204                                                   gint               y,
205                                                   gboolean           keyboard_tip,
206                                                   GtkTooltip        *tooltip);
207 static gboolean gtk_widget_real_show_help        (GtkWidget         *widget,
208                                                   GtkWidgetHelpType  help_type);
209
210 static void     gtk_widget_dispatch_child_properties_changed    (GtkWidget        *object,
211                                                                  guint             n_pspecs,
212                                                                  GParamSpec      **pspecs);
213 static gboolean         gtk_widget_real_key_press_event         (GtkWidget        *widget,
214                                                                  GdkEventKey      *event);
215 static gboolean         gtk_widget_real_key_release_event       (GtkWidget        *widget,
216                                                                  GdkEventKey      *event);
217 static gboolean         gtk_widget_real_focus_in_event           (GtkWidget       *widget,
218                                                                   GdkEventFocus   *event);
219 static gboolean         gtk_widget_real_focus_out_event         (GtkWidget        *widget,
220                                                                  GdkEventFocus    *event);
221 static gboolean         gtk_widget_real_focus                   (GtkWidget        *widget,
222                                                                  GtkDirectionType  direction);
223 static void             gtk_widget_real_move_focus              (GtkWidget        *widget,
224                                                                  GtkDirectionType  direction);
225 static gboolean         gtk_widget_real_keynav_failed           (GtkWidget        *widget,
226                                                                  GtkDirectionType  direction);
227 static PangoContext*    gtk_widget_peek_pango_context           (GtkWidget        *widget);
228 static void             gtk_widget_update_pango_context         (GtkWidget        *widget);
229 static void             gtk_widget_propagate_state              (GtkWidget        *widget,
230                                                                  GtkStateData     *data);
231 static void             gtk_widget_reset_rc_style               (GtkWidget        *widget);
232 static void             gtk_widget_set_style_internal           (GtkWidget        *widget,
233                                                                  GtkStyle         *style,
234                                                                  gboolean          initial_emission);
235 static gint             gtk_widget_event_internal               (GtkWidget        *widget,
236                                                                  GdkEvent         *event);
237 static gboolean         gtk_widget_real_mnemonic_activate       (GtkWidget        *widget,
238                                                                  gboolean          group_cycling);
239 static void             gtk_widget_aux_info_destroy             (GtkWidgetAuxInfo *aux_info);
240 static AtkObject*       gtk_widget_real_get_accessible          (GtkWidget        *widget);
241 static void             gtk_widget_accessible_interface_init    (AtkImplementorIface *iface);
242 static AtkObject*       gtk_widget_ref_accessible               (AtkImplementor *implementor);
243 static void             gtk_widget_invalidate_widget_windows    (GtkWidget        *widget,
244                                                                  GdkRegion        *region);
245 static GdkScreen *      gtk_widget_get_screen_unchecked         (GtkWidget        *widget);
246 static void             gtk_widget_queue_shallow_draw           (GtkWidget        *widget);
247 static gboolean         gtk_widget_real_can_activate_accel      (GtkWidget *widget,
248                                                                  guint      signal_id);
249
250 static void             gtk_widget_real_set_has_tooltip         (GtkWidget *widget,
251                                                                  gboolean   has_tooltip,
252                                                                  gboolean   force);
253 static void             gtk_widget_buildable_interface_init     (GtkBuildableIface *iface);
254 static void             gtk_widget_buildable_set_name           (GtkBuildable     *buildable,
255                                                                  const gchar      *name);
256 static const gchar *    gtk_widget_buildable_get_name           (GtkBuildable     *buildable);
257 static GObject *        gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
258                                                                  GtkBuilder   *builder,
259                                                                  const gchar  *childname);
260 static void             gtk_widget_buildable_set_buildable_property (GtkBuildable     *buildable,
261                                                                      GtkBuilder       *builder,
262                                                                      const gchar      *name,
263                                                                      const GValue     *value);
264 static gboolean         gtk_widget_buildable_custom_tag_start   (GtkBuildable     *buildable,
265                                                                  GtkBuilder       *builder,
266                                                                  GObject          *child,
267                                                                  const gchar      *tagname,
268                                                                  GMarkupParser    *parser,
269                                                                  gpointer         *data);
270 static void             gtk_widget_buildable_custom_finished    (GtkBuildable     *buildable,
271                                                                  GtkBuilder       *builder,
272                                                                  GObject          *child,
273                                                                  const gchar      *tagname,
274                                                                  gpointer          data);
275 static void             gtk_widget_buildable_parser_finished    (GtkBuildable     *buildable,
276                                                                  GtkBuilder       *builder);
277
278 static void             gtk_widget_queue_tooltip_query          (GtkWidget *widget);
279      
280 static void gtk_widget_set_usize_internal (GtkWidget *widget,
281                                            gint       width,
282                                            gint       height);
283 static void gtk_widget_get_draw_rectangle (GtkWidget    *widget,
284                                            GdkRectangle *rect);
285
286
287 /* --- variables --- */
288 static gpointer         gtk_widget_parent_class = NULL;
289 static guint            widget_signals[LAST_SIGNAL] = { 0 };
290 static GtkStyle        *gtk_default_style = NULL;
291 static GSList          *colormap_stack = NULL;
292 static guint            composite_child_stack = 0;
293 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
294 static GParamSpecPool  *style_property_spec_pool = NULL;
295
296 static GQuark           quark_property_parser = 0;
297 static GQuark           quark_aux_info = 0;
298 static GQuark           quark_accel_path = 0;
299 static GQuark           quark_accel_closures = 0;
300 static GQuark           quark_event_mask = 0;
301 static GQuark           quark_extension_event_mode = 0;
302 static GQuark           quark_parent_window = 0;
303 static GQuark           quark_pointer_window = 0;
304 static GQuark           quark_shape_info = 0;
305 static GQuark           quark_input_shape_info = 0;
306 static GQuark           quark_colormap = 0;
307 static GQuark           quark_pango_context = 0;
308 static GQuark           quark_rc_style = 0;
309 static GQuark           quark_accessible_object = 0;
310 static GQuark           quark_mnemonic_labels = 0;
311 static GQuark           quark_tooltip_markup = 0;
312 static GQuark           quark_has_tooltip = 0;
313 static GQuark           quark_tooltip_window = 0;
314 GParamSpecPool         *_gtk_widget_child_property_pool = NULL;
315 GObjectNotifyContext   *_gtk_widget_child_property_notify_context = NULL;
316
317 /* --- functions --- */
318 GType
319 gtk_widget_get_type (void)
320 {
321   static GType widget_type = 0;
322
323   if (G_UNLIKELY (widget_type == 0))
324     {
325       const GTypeInfo widget_info =
326       {
327         sizeof (GtkWidgetClass),
328         NULL,           /* base_init */
329         (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
330         (GClassInitFunc) gtk_widget_class_init,
331         NULL,           /* class_finalize */
332         NULL,           /* class_init */
333         sizeof (GtkWidget),
334         0,              /* n_preallocs */
335         (GInstanceInitFunc) gtk_widget_init,
336         NULL,           /* value_table */
337       };
338
339       const GInterfaceInfo accessibility_info =
340       {
341         (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
342         (GInterfaceFinalizeFunc) NULL,
343         NULL /* interface data */
344       };
345
346       const GInterfaceInfo buildable_info =
347       {
348         (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
349         (GInterfaceFinalizeFunc) NULL,
350         NULL /* interface data */
351       };
352
353       widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
354                                            &widget_info, G_TYPE_FLAG_ABSTRACT);
355
356       g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
357                                    &accessibility_info) ;
358       g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
359                                    &buildable_info) ;
360
361     }
362
363   return widget_type;
364 }
365
366 static void
367 child_property_notify_dispatcher (GObject     *object,
368                                   guint        n_pspecs,
369                                   GParamSpec **pspecs)
370 {
371   GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
372 }
373
374 static void
375 gtk_widget_class_init (GtkWidgetClass *klass)
376 {
377   static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
378   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
379   GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
380   GtkBindingSet *binding_set;
381
382   gtk_widget_parent_class = g_type_class_peek_parent (klass);
383
384   quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
385   quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
386   quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
387   quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
388   quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
389   quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
390   quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
391   quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
392   quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
393   quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
394   quark_colormap = g_quark_from_static_string ("gtk-colormap");
395   quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
396   quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
397   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
398   quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
399   quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
400   quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
401   quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
402
403   style_property_spec_pool = g_param_spec_pool_new (FALSE);
404   _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
405   cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
406   cpn_context.dispatcher = child_property_notify_dispatcher;
407   _gtk_widget_child_property_notify_context = &cpn_context;
408
409   gobject_class->dispose = gtk_widget_dispose;
410   gobject_class->finalize = gtk_widget_finalize;
411   gobject_class->set_property = gtk_widget_set_property;
412   gobject_class->get_property = gtk_widget_get_property;
413
414   object_class->destroy = gtk_widget_real_destroy;
415   
416   klass->activate_signal = 0;
417   klass->set_scroll_adjustments_signal = 0;
418   klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
419   klass->show = gtk_widget_real_show;
420   klass->show_all = gtk_widget_show;
421   klass->hide = gtk_widget_real_hide;
422   klass->hide_all = gtk_widget_hide;
423   klass->map = gtk_widget_real_map;
424   klass->unmap = gtk_widget_real_unmap;
425   klass->realize = gtk_widget_real_realize;
426   klass->unrealize = gtk_widget_real_unrealize;
427   klass->size_request = gtk_widget_real_size_request;
428   klass->size_allocate = gtk_widget_real_size_allocate;
429   klass->state_changed = NULL;
430   klass->parent_set = NULL;
431   klass->hierarchy_changed = NULL;
432   klass->style_set = gtk_widget_real_style_set;
433   klass->direction_changed = gtk_widget_real_direction_changed;
434   klass->grab_notify = NULL;
435   klass->child_notify = NULL;
436   klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
437   klass->grab_focus = gtk_widget_real_grab_focus;
438   klass->focus = gtk_widget_real_focus;
439   klass->event = NULL;
440   klass->button_press_event = NULL;
441   klass->button_release_event = NULL;
442   klass->motion_notify_event = NULL;
443   klass->delete_event = NULL;
444   klass->destroy_event = NULL;
445   klass->expose_event = NULL;
446   klass->key_press_event = gtk_widget_real_key_press_event;
447   klass->key_release_event = gtk_widget_real_key_release_event;
448   klass->enter_notify_event = NULL;
449   klass->leave_notify_event = NULL;
450   klass->configure_event = NULL;
451   klass->focus_in_event = gtk_widget_real_focus_in_event;
452   klass->focus_out_event = gtk_widget_real_focus_out_event;
453   klass->map_event = NULL;
454   klass->unmap_event = NULL;
455   klass->window_state_event = NULL;
456   klass->property_notify_event = _gtk_selection_property_notify;
457   klass->selection_clear_event = gtk_selection_clear;
458   klass->selection_request_event = _gtk_selection_request;
459   klass->selection_notify_event = _gtk_selection_notify;
460   klass->selection_received = NULL;
461   klass->proximity_in_event = NULL;
462   klass->proximity_out_event = NULL;
463   klass->drag_begin = NULL;
464   klass->drag_end = NULL;
465   klass->drag_data_delete = NULL;
466   klass->drag_leave = NULL;
467   klass->drag_motion = NULL;
468   klass->drag_drop = NULL;
469   klass->drag_data_received = NULL;
470   klass->screen_changed = NULL;
471   klass->can_activate_accel = gtk_widget_real_can_activate_accel;
472   klass->grab_broken_event = NULL;
473   klass->query_tooltip = gtk_widget_real_query_tooltip;
474
475   klass->show_help = gtk_widget_real_show_help;
476   
477   /* Accessibility support */
478   klass->get_accessible = gtk_widget_real_get_accessible;
479
480   klass->no_expose_event = NULL;
481
482   g_object_class_install_property (gobject_class,
483                                    PROP_NAME,
484                                    g_param_spec_string ("name",
485                                                         P_("Widget name"),
486                                                         P_("The name of the widget"),
487                                                         NULL,
488                                                         GTK_PARAM_READWRITE));
489   g_object_class_install_property (gobject_class,
490                                    PROP_PARENT,
491                                    g_param_spec_object ("parent",
492                                                         P_("Parent widget"), 
493                                                         P_("The parent widget of this widget. Must be a Container widget"),
494                                                         GTK_TYPE_CONTAINER,
495                                                         GTK_PARAM_READWRITE));
496
497   g_object_class_install_property (gobject_class,
498                                    PROP_WIDTH_REQUEST,
499                                    g_param_spec_int ("width-request",
500                                                      P_("Width request"),
501                                                      P_("Override for width request of the widget, or -1 if natural request should be used"),
502                                                      -1,
503                                                      G_MAXINT,
504                                                      -1,
505                                                      GTK_PARAM_READWRITE));
506   g_object_class_install_property (gobject_class,
507                                    PROP_HEIGHT_REQUEST,
508                                    g_param_spec_int ("height-request",
509                                                      P_("Height request"),
510                                                      P_("Override for height request of the widget, or -1 if natural request should be used"),
511                                                      -1,
512                                                      G_MAXINT,
513                                                      -1,
514                                                      GTK_PARAM_READWRITE));
515   g_object_class_install_property (gobject_class,
516                                    PROP_VISIBLE,
517                                    g_param_spec_boolean ("visible",
518                                                          P_("Visible"),
519                                                          P_("Whether the widget is visible"),
520                                                          FALSE,
521                                                          GTK_PARAM_READWRITE));
522   g_object_class_install_property (gobject_class,
523                                    PROP_SENSITIVE,
524                                    g_param_spec_boolean ("sensitive",
525                                                          P_("Sensitive"),
526                                                          P_("Whether the widget responds to input"),
527                                                          TRUE,
528                                                          GTK_PARAM_READWRITE));
529   g_object_class_install_property (gobject_class,
530                                    PROP_APP_PAINTABLE,
531                                    g_param_spec_boolean ("app-paintable",
532                                                          P_("Application paintable"),
533                                                          P_("Whether the application will paint directly on the widget"),
534                                                          FALSE,
535                                                          GTK_PARAM_READWRITE));
536   g_object_class_install_property (gobject_class,
537                                    PROP_CAN_FOCUS,
538                                    g_param_spec_boolean ("can-focus",
539                                                          P_("Can focus"),
540                                                          P_("Whether the widget can accept the input focus"),
541                                                          FALSE,
542                                                          GTK_PARAM_READWRITE));
543   g_object_class_install_property (gobject_class,
544                                    PROP_HAS_FOCUS,
545                                    g_param_spec_boolean ("has-focus",
546                                                          P_("Has focus"),
547                                                          P_("Whether the widget has the input focus"),
548                                                          FALSE,
549                                                          GTK_PARAM_READWRITE));
550   g_object_class_install_property (gobject_class,
551                                    PROP_IS_FOCUS,
552                                    g_param_spec_boolean ("is-focus",
553                                                          P_("Is focus"),
554                                                          P_("Whether the widget is the focus widget within the toplevel"),
555                                                          FALSE,
556                                                          GTK_PARAM_READWRITE));
557   g_object_class_install_property (gobject_class,
558                                    PROP_CAN_DEFAULT,
559                                    g_param_spec_boolean ("can-default",
560                                                          P_("Can default"),
561                                                          P_("Whether the widget can be the default widget"),
562                                                          FALSE,
563                                                          GTK_PARAM_READWRITE));
564   g_object_class_install_property (gobject_class,
565                                    PROP_HAS_DEFAULT,
566                                    g_param_spec_boolean ("has-default",
567                                                          P_("Has default"),
568                                                          P_("Whether the widget is the default widget"),
569                                                          FALSE,
570                                                          GTK_PARAM_READWRITE));
571   g_object_class_install_property (gobject_class,
572                                    PROP_RECEIVES_DEFAULT,
573                                    g_param_spec_boolean ("receives-default",
574                                                          P_("Receives default"),
575                                                          P_("If TRUE, the widget will receive the default action when it is focused"),
576                                                          FALSE,
577                                                          GTK_PARAM_READWRITE));
578   g_object_class_install_property (gobject_class,
579                                    PROP_COMPOSITE_CHILD,
580                                    g_param_spec_boolean ("composite-child",
581                                                          P_("Composite child"),
582                                                          P_("Whether the widget is part of a composite widget"),
583                                                          FALSE,
584                                                          GTK_PARAM_READABLE));
585   g_object_class_install_property (gobject_class,
586                                    PROP_STYLE,
587                                    g_param_spec_object ("style",
588                                                         P_("Style"),
589                                                         P_("The style of the widget, which contains information about how it will look (colors etc)"),
590                                                         GTK_TYPE_STYLE,
591                                                         GTK_PARAM_READWRITE));
592   g_object_class_install_property (gobject_class,
593                                    PROP_EVENTS,
594                                    g_param_spec_flags ("events",
595                                                        P_("Events"),
596                                                        P_("The event mask that decides what kind of GdkEvents this widget gets"),
597                                                        GDK_TYPE_EVENT_MASK,
598                                                        GDK_STRUCTURE_MASK,
599                                                        GTK_PARAM_READWRITE));
600   g_object_class_install_property (gobject_class,
601                                    PROP_EXTENSION_EVENTS,
602                                    g_param_spec_enum ("extension-events",
603                                                       P_("Extension events"),
604                                                       P_("The mask that decides what kind of extension events this widget gets"),
605                                                       GDK_TYPE_EXTENSION_MODE,
606                                                       GDK_EXTENSION_EVENTS_NONE,
607                                                       GTK_PARAM_READWRITE));
608   g_object_class_install_property (gobject_class,
609                                    PROP_NO_SHOW_ALL,
610                                    g_param_spec_boolean ("no-show-all",
611                                                          P_("No show all"),
612                                                          P_("Whether gtk_widget_show_all() should not affect this widget"),
613                                                          FALSE,
614                                                          GTK_PARAM_READWRITE));
615
616 /**
617  * GtkWidget:has-tooltip:
618  *
619  * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.  
620  * A value of %TRUE indicates that @widget can have a tooltip, in this case
621  * the widget will be queried using #GtkWidget::query-tooltip to determine
622  * whether it will provide a tooltip or not.
623  *
624  * Note that setting this property to %TRUE for the first time will change
625  * the event masks of the GdkWindows of this widget to include leave-notify
626  * and motion-notify events.  This cannot and will not be undone when the
627  * property is set to %FALSE again.
628  *
629  * Since: 2.12
630  */
631   g_object_class_install_property (gobject_class,
632                                    PROP_HAS_TOOLTIP,
633                                    g_param_spec_boolean ("has-tooltip",
634                                                          P_("Has tooltip"),
635                                                          P_("Whether this widget has a tooltip"),
636                                                          FALSE,
637                                                          GTK_PARAM_READWRITE));
638   /**
639    * GtkWidget:tooltip-text:
640    *
641    * Sets the text of tooltip to be the given string.
642    *
643    * Also see gtk_tooltip_set_text().
644    *
645    * This is a convenience property which will take care of getting the
646    * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
647    * will automatically be set to %TRUE and there will be taken care of
648    * #GtkWidget::query-tooltip in the default signal handler.
649    *
650    * Since: 2.12
651    */
652   g_object_class_install_property (gobject_class,
653                                    PROP_TOOLTIP_TEXT,
654                                    g_param_spec_string ("tooltip-text",
655                                                         P_("Tooltip Text"),
656                                                         P_("The contents of the tooltip for this widget"),
657                                                         NULL,
658                                                         GTK_PARAM_READWRITE));
659   /**
660    * GtkWidget:tooltip-markup:
661    *
662    * Sets the text of tooltip to be the given string, which is marked up
663    * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
664    * Also see gtk_tooltip_set_markup().
665    *
666    * This is a convenience property which will take care of getting the
667    * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
668    * will automatically be set to %TRUE and there will be taken care of
669    * #GtkWidget::query-tooltip in the default signal handler.
670    *
671    * Since: 2.12
672    */
673   g_object_class_install_property (gobject_class,
674                                    PROP_TOOLTIP_MARKUP,
675                                    g_param_spec_string ("tooltip-markup",
676                                                         P_("Tooltip markup"),
677                                                         P_("The contents of the tooltip for this widget"),
678                                                         NULL,
679                                                         GTK_PARAM_READWRITE));
680
681   /**
682    * GtkWidget:window:
683    *
684    * The widget's window if it is realized, %NULL otherwise.
685    *
686    * Since: 2.14
687    */
688   g_object_class_install_property (gobject_class,
689                                    PROP_WINDOW,
690                                    g_param_spec_object ("window",
691                                                         P_("Window"),
692                                                         P_("The widget's window if it is realized"),
693                                                         GDK_TYPE_WINDOW,
694                                                         GTK_PARAM_READABLE));
695
696   /**
697    * GtkWidget:double-buffered
698    *
699    * Whether or not the widget is double buffered.
700    *
701    * Since: 2.18
702    */
703   g_object_class_install_property (gobject_class,
704                                    PROP_DOUBLE_BUFFERED,
705                                    g_param_spec_boolean ("double-buffered",
706                                                          P_("Double Buffered"),
707                                                          P_("Whether or not the widget is double buffered"),
708                                                          TRUE,
709                                                          GTK_PARAM_READWRITE));
710
711   widget_signals[SHOW] =
712     g_signal_new (I_("show"),
713                   G_TYPE_FROM_CLASS (gobject_class),
714                   G_SIGNAL_RUN_FIRST,
715                   G_STRUCT_OFFSET (GtkWidgetClass, show),
716                   NULL, NULL,
717                   _gtk_marshal_VOID__VOID,
718                   G_TYPE_NONE, 0);
719   widget_signals[HIDE] =
720     g_signal_new (I_("hide"),
721                   G_TYPE_FROM_CLASS (gobject_class),
722                   G_SIGNAL_RUN_FIRST,
723                   G_STRUCT_OFFSET (GtkWidgetClass, hide),
724                   NULL, NULL,
725                   _gtk_marshal_VOID__VOID,
726                   G_TYPE_NONE, 0);
727   widget_signals[MAP] =
728     g_signal_new (I_("map"),
729                   G_TYPE_FROM_CLASS (gobject_class),
730                   G_SIGNAL_RUN_FIRST,
731                   G_STRUCT_OFFSET (GtkWidgetClass, map),
732                   NULL, NULL,
733                   _gtk_marshal_VOID__VOID,
734                   G_TYPE_NONE, 0);
735   widget_signals[UNMAP] =
736     g_signal_new (I_("unmap"),
737                   G_TYPE_FROM_CLASS (gobject_class),
738                   G_SIGNAL_RUN_FIRST,
739                   G_STRUCT_OFFSET (GtkWidgetClass, unmap),
740                   NULL, NULL,
741                   _gtk_marshal_VOID__VOID,
742                   G_TYPE_NONE, 0);
743   widget_signals[REALIZE] =
744     g_signal_new (I_("realize"),
745                   G_TYPE_FROM_CLASS (gobject_class),
746                   G_SIGNAL_RUN_FIRST,
747                   G_STRUCT_OFFSET (GtkWidgetClass, realize),
748                   NULL, NULL,
749                   _gtk_marshal_VOID__VOID,
750                   G_TYPE_NONE, 0);
751   widget_signals[UNREALIZE] =
752     g_signal_new (I_("unrealize"),
753                   G_TYPE_FROM_CLASS (gobject_class),
754                   G_SIGNAL_RUN_LAST,
755                   G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
756                   NULL, NULL,
757                   _gtk_marshal_VOID__VOID,
758                   G_TYPE_NONE, 0);
759   widget_signals[SIZE_REQUEST] =
760     g_signal_new (I_("size-request"),
761                   G_TYPE_FROM_CLASS (gobject_class),
762                   G_SIGNAL_RUN_FIRST,
763                   G_STRUCT_OFFSET (GtkWidgetClass, size_request),
764                   NULL, NULL,
765                   _gtk_marshal_VOID__BOXED,
766                   G_TYPE_NONE, 1,
767                   GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
768   widget_signals[SIZE_ALLOCATE] = 
769     g_signal_new (I_("size-allocate"),
770                   G_TYPE_FROM_CLASS (gobject_class),
771                   G_SIGNAL_RUN_FIRST,
772                   G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
773                   NULL, NULL,
774                   _gtk_marshal_VOID__BOXED,
775                   G_TYPE_NONE, 1,
776                   GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
777
778   widget_signals[STATE_CHANGED] =
779     g_signal_new (I_("state-changed"),
780                   G_TYPE_FROM_CLASS (gobject_class),
781                   G_SIGNAL_RUN_FIRST,
782                   G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
783                   NULL, NULL,
784                   _gtk_marshal_VOID__ENUM,
785                   G_TYPE_NONE, 1,
786                   GTK_TYPE_STATE_TYPE);
787
788   /**
789    * GtkWidget::parent-set:
790    * @widget: the object on which the signal is emitted
791    * @old_parent: the previous parent, or %NULL if the widget 
792    *   just got its initial parent.
793    *
794    * The ::parent-set signal is emitted when a new parent 
795    * has been set on a widget. 
796    */
797   widget_signals[PARENT_SET] =
798     g_signal_new (I_("parent-set"),
799                   G_TYPE_FROM_CLASS (gobject_class),
800                   G_SIGNAL_RUN_FIRST,
801                   G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
802                   NULL, NULL,
803                   _gtk_marshal_VOID__OBJECT,
804                   G_TYPE_NONE, 1,
805                   GTK_TYPE_WIDGET);
806
807   /**
808    * GtkWidget::hierarchy-changed:
809    * @widget: the object on which the signal is emitted
810    * @previous_toplevel: the previous toplevel ancestor, or %NULL
811    *   if the widget was previously unanchored
812    *
813    * The ::hierarchy-changed signal is emitted when the
814    * anchored state of a widget changes. A widget is
815    * <firstterm>anchored</firstterm> when its toplevel
816    * ancestor is a #GtkWindow. This signal is emitted when
817    * a widget changes from un-anchored to anchored or vice-versa.
818    */
819   widget_signals[HIERARCHY_CHANGED] =
820     g_signal_new (I_("hierarchy-changed"),
821                   G_TYPE_FROM_CLASS (gobject_class),
822                   G_SIGNAL_RUN_LAST,
823                   G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
824                   NULL, NULL,
825                   _gtk_marshal_VOID__OBJECT,
826                   G_TYPE_NONE, 1,
827                   GTK_TYPE_WIDGET);
828
829   /**
830    * GtkWidget::style-set:
831    * @widget: the object on which the signal is emitted
832    * @previous_style: the previous style, or %NULL if the widget 
833    *   just got its initial style 
834    *
835    * The ::style-set signal is emitted when a new style has been set 
836    * on a widget. Note that style-modifying functions like 
837    * gtk_widget_modify_base() also cause this signal to be emitted.
838    */
839   widget_signals[STYLE_SET] =
840     g_signal_new (I_("style-set"),
841                   G_TYPE_FROM_CLASS (gobject_class),
842                   G_SIGNAL_RUN_FIRST,
843                   G_STRUCT_OFFSET (GtkWidgetClass, style_set),
844                   NULL, NULL,
845                   _gtk_marshal_VOID__OBJECT,
846                   G_TYPE_NONE, 1,
847                   GTK_TYPE_STYLE);
848 /**
849  * GtkWidget::direction-changed:
850  * @widget: the object on which the signal is emitted
851  * @previous_direction: the previous text direction of @widget
852  *
853  * The ::direction-changed signal is emitted when the text direction
854  * of a widget changes.
855  */
856   widget_signals[DIRECTION_CHANGED] =
857     g_signal_new (I_("direction-changed"),
858                   G_TYPE_FROM_CLASS (gobject_class),
859                   G_SIGNAL_RUN_FIRST,
860                   G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
861                   NULL, NULL,
862                   _gtk_marshal_VOID__ENUM,
863                   G_TYPE_NONE, 1,
864                   GTK_TYPE_TEXT_DIRECTION);
865
866   /**
867    * GtkWidget::grab-notify:
868    * @widget: the object which received the signal
869    * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
870    *               if it becomes unshadowed
871    *
872    * The ::grab-notify signal is emitted when a widget becomes
873    * shadowed by a GTK+ grab (not a pointer or keyboard grab) on 
874    * another widget, or when it becomes unshadowed due to a grab 
875    * being removed.
876    * 
877    * A widget is shadowed by a gtk_grab_add() when the topmost 
878    * grab widget in the grab stack of its window group is not 
879    * its ancestor.
880    */
881   widget_signals[GRAB_NOTIFY] =
882     g_signal_new (I_("grab-notify"),
883                   G_TYPE_FROM_CLASS (gobject_class),
884                   G_SIGNAL_RUN_FIRST,
885                   G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
886                   NULL, NULL,
887                   _gtk_marshal_VOID__BOOLEAN,
888                   G_TYPE_NONE, 1,
889                   G_TYPE_BOOLEAN);
890
891 /**
892  * GtkWidget::child-notify:
893  * @widget: the object which received the signal
894  * @pspec: the #GParamSpec of the changed child property
895  *
896  * The ::child-notify signal is emitted for each 
897  * <link linkend="child-properties">child property</link>  that has
898  * changed on an object. The signal's detail holds the property name. 
899  */
900   widget_signals[CHILD_NOTIFY] =
901     g_signal_new (I_("child-notify"),
902                    G_TYPE_FROM_CLASS (gobject_class),
903                    G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
904                    G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
905                    NULL, NULL,
906                    g_cclosure_marshal_VOID__PARAM,
907                    G_TYPE_NONE, 1,
908                    G_TYPE_PARAM);
909   widget_signals[MNEMONIC_ACTIVATE] =
910     g_signal_new (I_("mnemonic-activate"),
911                   G_TYPE_FROM_CLASS (gobject_class),
912                   G_SIGNAL_RUN_LAST,
913                   G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
914                   _gtk_boolean_handled_accumulator, NULL,
915                   _gtk_marshal_BOOLEAN__BOOLEAN,
916                   G_TYPE_BOOLEAN, 1,
917                   G_TYPE_BOOLEAN);
918   widget_signals[GRAB_FOCUS] =
919     g_signal_new (I_("grab-focus"),
920                   G_TYPE_FROM_CLASS (gobject_class),
921                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922                   G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
923                   NULL, NULL,
924                   _gtk_marshal_VOID__VOID,
925                   G_TYPE_NONE, 0);
926   widget_signals[FOCUS] =
927     g_signal_new (I_("focus"),
928                   G_TYPE_FROM_CLASS (object_class),
929                   G_SIGNAL_RUN_LAST,
930                   G_STRUCT_OFFSET (GtkWidgetClass, focus),
931                   _gtk_boolean_handled_accumulator, NULL,
932                   _gtk_marshal_BOOLEAN__ENUM,
933                   G_TYPE_BOOLEAN, 1,
934                   GTK_TYPE_DIRECTION_TYPE);
935   widget_signals[MOVE_FOCUS] =
936     g_signal_new_class_handler (I_("move-focus"),
937                                 G_TYPE_FROM_CLASS (object_class),
938                                 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
939                                 G_CALLBACK (gtk_widget_real_move_focus),
940                                 NULL, NULL,
941                                 _gtk_marshal_VOID__ENUM,
942                                 G_TYPE_NONE,
943                                 1,
944                                 GTK_TYPE_DIRECTION_TYPE);
945   /**
946    * GtkWidget::event:
947    * @widget: the object which received the signal.
948    * @event: the #GdkEvent which triggered this signal
949    *
950    * The GTK+ main loop will emit three signals for each GDK event delivered
951    * to a widget: one generic ::event signal, another, more specific,
952    * signal that matches the type of event delivered (e.g. 
953    * #GtkWidget::key-press-event) and finally a generic 
954    * #GtkWidget::event-after signal.
955    *
956    * Returns: %TRUE to stop other handlers from being invoked for the event 
957    * and to cancel the emission of the second specific ::event signal.
958    *   %FALSE to propagate the event further and to allow the emission of 
959    *   the second signal. The ::event-after signal is emitted regardless of
960    *   the return value.
961    */
962   widget_signals[EVENT] =
963     g_signal_new (I_("event"),
964                   G_TYPE_FROM_CLASS (gobject_class),
965                   G_SIGNAL_RUN_LAST,
966                   G_STRUCT_OFFSET (GtkWidgetClass, event),
967                   _gtk_boolean_handled_accumulator, NULL,
968                   _gtk_marshal_BOOLEAN__BOXED,
969                   G_TYPE_BOOLEAN, 1,
970                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
971
972   /**
973    * GtkWidget::event-after:
974    * @widget: the object which received the signal.
975    * @event: the #GdkEvent which triggered this signal
976    *
977    * After the emission of the #GtkWidget::event signal and (optionally) 
978    * the second more specific signal, ::event-after will be emitted 
979    * regardless of the previous two signals handlers return values.
980    *
981    */
982   widget_signals[EVENT_AFTER] =
983     g_signal_new (I_("event-after"),
984                   G_TYPE_FROM_CLASS (gobject_class),
985                   0,
986                   0,
987                   NULL, NULL,
988                   _gtk_marshal_VOID__BOXED,
989                   G_TYPE_NONE, 1,
990                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
991
992   /**
993    * GtkWidget::button-press-event:
994    * @widget: the object which received the signal.
995    * @event: the #GdkEventButton which triggered this signal
996    *
997    * The ::button-press-event signal will be emitted when a button
998    * (typically from a mouse) is pressed.
999    *
1000    * To receive this signal, the #GdkWindow associated to the 
1001    * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1002    *
1003    * This signal will be sent to the grab widget if there is one.
1004    *
1005    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1006    *   %FALSE to propagate the event further.
1007    */
1008   widget_signals[BUTTON_PRESS_EVENT] =
1009     g_signal_new (I_("button-press-event"),
1010                   G_TYPE_FROM_CLASS (gobject_class),
1011                   G_SIGNAL_RUN_LAST,
1012                   G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1013                   _gtk_boolean_handled_accumulator, NULL,
1014                   _gtk_marshal_BOOLEAN__BOXED,
1015                   G_TYPE_BOOLEAN, 1,
1016                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1017
1018   /**
1019    * GtkWidget::button-release-event:
1020    * @widget: the object which received the signal.
1021    * @event: the #GdkEventButton which triggered this signal
1022    *
1023    * The ::button-release-event signal will be emitted when a button
1024    * (typically from a mouse) is released.
1025    *
1026    * To receive this signal, the #GdkWindow associated to the 
1027    * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1028    *
1029    * This signal will be sent to the grab widget if there is one.
1030    *
1031    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1032    *   %FALSE to propagate the event further.
1033    */
1034   widget_signals[BUTTON_RELEASE_EVENT] =
1035     g_signal_new (I_("button-release-event"),
1036                   G_TYPE_FROM_CLASS (gobject_class),
1037                   G_SIGNAL_RUN_LAST,
1038                   G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1039                   _gtk_boolean_handled_accumulator, NULL,
1040                   _gtk_marshal_BOOLEAN__BOXED,
1041                   G_TYPE_BOOLEAN, 1,
1042                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1043
1044   /**
1045    * GtkWidget::scroll-event:
1046    * @widget: the object which received the signal.
1047    * @event: the #GdkEventScroll which triggered this signal
1048    *
1049    * The ::scroll-event signal is emitted when a button in the 4 to 7
1050    * range is pressed. Wheel mice are usually configured to generate 
1051    * button press events for buttons 4 and 5 when the wheel is turned.
1052    *
1053    * To receive this signal, the #GdkWindow associated to the widget needs
1054    * to enable the #GDK_BUTTON_PRESS_MASK mask.
1055    *
1056    * This signal will be sent to the grab widget if there is one.
1057    *
1058    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1059    *   %FALSE to propagate the event further.
1060    */
1061   widget_signals[SCROLL_EVENT] =
1062     g_signal_new (I_("scroll-event"),
1063                   G_TYPE_FROM_CLASS (gobject_class),
1064                   G_SIGNAL_RUN_LAST,
1065                   G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1066                   _gtk_boolean_handled_accumulator, NULL,
1067                   _gtk_marshal_BOOLEAN__BOXED,
1068                   G_TYPE_BOOLEAN, 1,
1069                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1070   /**
1071    * GtkWidget::motion-notify-event:
1072    * @widget: the object which received the signal.
1073    * @event: the #GdkEventMotion which triggered this signal
1074    *
1075    * The ::motion-notify-event signal is emitted when the pointer moves 
1076    * over the widget's #GdkWindow.
1077    *
1078    * To receive this signal, the #GdkWindow associated to the widget 
1079    * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1080    *
1081    * This signal will be sent to the grab widget if there is one.
1082    *
1083    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1084    *   %FALSE to propagate the event further.
1085    */
1086   widget_signals[MOTION_NOTIFY_EVENT] =
1087     g_signal_new (I_("motion-notify-event"),
1088                   G_TYPE_FROM_CLASS (gobject_class),
1089                   G_SIGNAL_RUN_LAST,
1090                   G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1091                   _gtk_boolean_handled_accumulator, NULL,
1092                   _gtk_marshal_BOOLEAN__BOXED,
1093                   G_TYPE_BOOLEAN, 1,
1094                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1095
1096   /**
1097    * GtkWidget::composited-changed:
1098    * @widget: the object on which the signal is emitted
1099    *
1100    * The ::composited-changed signal is emitted when the composited
1101    * status of @widget<!-- -->s screen changes. 
1102    * See gdk_screen_is_composited().
1103    */
1104   widget_signals[COMPOSITED_CHANGED] =
1105     g_signal_new (I_("composited-changed"),
1106                   G_TYPE_FROM_CLASS (gobject_class),
1107                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1108                   G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1109                   NULL, NULL,
1110                   _gtk_marshal_VOID__VOID,
1111                   G_TYPE_NONE, 0);
1112
1113   /**
1114    * GtkWidget::keynav-failed:
1115    * @widget: the object which received the signal
1116    * @direction: the direction of movement
1117    *
1118    * Gets emitted if keyboard navigation fails. 
1119    * See gtk_widget_keynav_failed() for details.
1120    *
1121    * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1122    *          if the emitting widget should try to handle the keyboard
1123    *          navigation attempt in its parent container(s).
1124    *
1125    * Since: 2.12
1126    **/
1127   widget_signals[KEYNAV_FAILED] =
1128     g_signal_new_class_handler (I_("keynav-failed"),
1129                                 G_TYPE_FROM_CLASS (gobject_class),
1130                                 G_SIGNAL_RUN_LAST,
1131                                 G_CALLBACK (gtk_widget_real_keynav_failed),
1132                                 _gtk_boolean_handled_accumulator, NULL,
1133                                 _gtk_marshal_BOOLEAN__ENUM,
1134                                 G_TYPE_BOOLEAN, 1,
1135                                 GTK_TYPE_DIRECTION_TYPE);
1136
1137   /**
1138    * GtkWidget::delete-event:
1139    * @widget: the object which received the signal
1140    * @event: the event which triggered this signal
1141    *
1142    * The ::delete-event signal is emitted if a user requests that
1143    * a toplevel window is closed. The default handler for this signal
1144    * destroys the window. Connecting gtk_widget_hide_on_delete() to
1145    * this signal will cause the window to be hidden instead, so that
1146    * it can later be shown again without reconstructing it.
1147    *
1148    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1149    *   %FALSE to propagate the event further.
1150    */
1151   widget_signals[DELETE_EVENT] =
1152     g_signal_new (I_("delete-event"),
1153                   G_TYPE_FROM_CLASS (gobject_class),
1154                   G_SIGNAL_RUN_LAST,
1155                   G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1156                   _gtk_boolean_handled_accumulator, NULL,
1157                   _gtk_marshal_BOOLEAN__BOXED,
1158                   G_TYPE_BOOLEAN, 1,
1159                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1160
1161   /**
1162    * GtkWidget::destroy-event:
1163    * @widget: the object which received the signal.
1164    * @event: the event which triggered this signal
1165    *
1166    * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1167    * You rarely get this signal, because most widgets disconnect themselves 
1168    * from their window before they destroy it, so no widget owns the 
1169    * window at destroy time.
1170    * 
1171    * To receive this signal, the #GdkWindow associated to the widget needs
1172    * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1173    * automatically for all new windows.
1174    *
1175    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1176    *   %FALSE to propagate the event further.
1177    */
1178   widget_signals[DESTROY_EVENT] =
1179     g_signal_new (I_("destroy-event"),
1180                   G_TYPE_FROM_CLASS (gobject_class),
1181                   G_SIGNAL_RUN_LAST,
1182                   G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1183                   _gtk_boolean_handled_accumulator, NULL,
1184                   _gtk_marshal_BOOLEAN__BOXED,
1185                   G_TYPE_BOOLEAN, 1,
1186                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1187
1188   /**
1189    * GtkWidget::expose-event:
1190    * @widget: the object which received the signal.
1191    * @event: the #GdkEventExpose which triggered this signal
1192    *
1193    * The ::expose-event signal is emitted when an area of a previously
1194    * obscured #GdkWindow is made visible and needs to be redrawn.
1195    * #GTK_NO_WINDOW widgets will get a synthesized event from their parent 
1196    * widget.
1197    *
1198    * To receive this signal, the #GdkWindow associated to the widget needs
1199    * to enable the #GDK_EXPOSURE_MASK mask.
1200    * 
1201    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1202    *   %FALSE to propagate the event further.
1203    */
1204   widget_signals[EXPOSE_EVENT] =
1205     g_signal_new (I_("expose-event"),
1206                   G_TYPE_FROM_CLASS (gobject_class),
1207                   G_SIGNAL_RUN_LAST,
1208                   G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1209                   _gtk_boolean_handled_accumulator, NULL,
1210                   _gtk_marshal_BOOLEAN__BOXED,
1211                   G_TYPE_BOOLEAN, 1,
1212                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1213
1214   /**
1215    * GtkWidget::key-press-event:
1216    * @widget: the object which received the signal
1217    * @event: the #GdkEventKey which triggered this signal
1218    *
1219    * The ::key-press-event signal is emitted when a key is pressed.
1220    *
1221    * To receive this signal, the #GdkWindow associated to the widget needs
1222    * to enable the #GDK_KEY_PRESS_MASK mask.
1223    *
1224    * This signal will be sent to the grab widget if there is one.
1225    *
1226    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1227    *   %FALSE to propagate the event further.
1228    */
1229   widget_signals[KEY_PRESS_EVENT] =
1230     g_signal_new (I_("key-press-event"),
1231                   G_TYPE_FROM_CLASS (gobject_class),
1232                   G_SIGNAL_RUN_LAST,
1233                   G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1234                   _gtk_boolean_handled_accumulator, NULL,
1235                   _gtk_marshal_BOOLEAN__BOXED,
1236                   G_TYPE_BOOLEAN, 1,
1237                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1238
1239   /**
1240    * GtkWidget::key-release-event:
1241    * @widget: the object which received the signal
1242    * @event: the #GdkEventKey which triggered this signal
1243    *
1244    * The ::key-release-event signal is emitted when a key is pressed.
1245    *
1246    * To receive this signal, the #GdkWindow associated to the widget needs
1247    * to enable the #GDK_KEY_RELEASE_MASK mask.
1248    *
1249    * This signal will be sent to the grab widget if there is one.
1250    *
1251    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1252    *   %FALSE to propagate the event further.
1253    */
1254   widget_signals[KEY_RELEASE_EVENT] =
1255     g_signal_new (I_("key-release-event"),
1256                   G_TYPE_FROM_CLASS (gobject_class),
1257                   G_SIGNAL_RUN_LAST,
1258                   G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1259                   _gtk_boolean_handled_accumulator, NULL,
1260                   _gtk_marshal_BOOLEAN__BOXED,
1261                   G_TYPE_BOOLEAN, 1,
1262                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1263
1264   /**
1265    * GtkWidget::enter-notify-event:
1266    * @widget: the object which received the signal
1267    * @event: the #GdkEventCrossing which triggered this signal
1268    *
1269    * The ::enter-notify-event will be emitted when the pointer enters
1270    * the @widget's window.
1271    *
1272    * To receive this signal, the #GdkWindow associated to the widget needs
1273    * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1274    *
1275    * This signal will be sent to the grab widget if there is one.
1276    *
1277    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1278    *   %FALSE to propagate the event further.
1279    */
1280   widget_signals[ENTER_NOTIFY_EVENT] =
1281     g_signal_new (I_("enter-notify-event"),
1282                   G_TYPE_FROM_CLASS (gobject_class),
1283                   G_SIGNAL_RUN_LAST,
1284                   G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1285                   _gtk_boolean_handled_accumulator, NULL,
1286                   _gtk_marshal_BOOLEAN__BOXED,
1287                   G_TYPE_BOOLEAN, 1,
1288                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1289
1290   /**
1291    * GtkWidget::leave-notify-event:
1292    * @widget: the object which received the signal
1293    * @event: the #GdkEventCrossing which triggered this signal
1294    *
1295    * The ::leave-notify-event will be emitted when the pointer leaves
1296    * the @widget's window.
1297    *
1298    * To receive this signal, the #GdkWindow associated to the widget needs
1299    * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1300    *
1301    * This signal will be sent to the grab widget if there is one.
1302    *
1303    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1304    *   %FALSE to propagate the event further.
1305    */
1306   widget_signals[LEAVE_NOTIFY_EVENT] =
1307     g_signal_new (I_("leave-notify-event"),
1308                   G_TYPE_FROM_CLASS (gobject_class),
1309                   G_SIGNAL_RUN_LAST,
1310                   G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1311                   _gtk_boolean_handled_accumulator, NULL,
1312                   _gtk_marshal_BOOLEAN__BOXED,
1313                   G_TYPE_BOOLEAN, 1,
1314                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1315
1316   /**
1317    * GtkWidget::configure-event
1318    * @widget: the object which received the signal
1319    * @event: the #GdkEventConfigure which triggered this signal
1320    *
1321    * The ::configure-event signal will be emitted when the size, position or
1322    * stacking of the @widget's window has changed.
1323    *
1324    * To receive this signal, the #GdkWindow associated to the widget needs
1325    * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1326    * automatically for all new windows.
1327    *
1328    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1329    *   %FALSE to propagate the event further.
1330    */
1331   widget_signals[CONFIGURE_EVENT] =
1332     g_signal_new (I_("configure-event"),
1333                   G_TYPE_FROM_CLASS (gobject_class),
1334                   G_SIGNAL_RUN_LAST,
1335                   G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1336                   _gtk_boolean_handled_accumulator, NULL,
1337                   _gtk_marshal_BOOLEAN__BOXED,
1338                   G_TYPE_BOOLEAN, 1,
1339                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1340
1341   /**
1342    * GtkWidget::focus-in-event
1343    * @widget: the object which received the signal
1344    * @event: the #GdkEventFocus which triggered this signal
1345    *
1346    * The ::focus-in-event signal will be emitted when the keyboard focus
1347    * enters the @widget's window.
1348    *
1349    * To receive this signal, the #GdkWindow associated to the widget needs
1350    * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1351    *
1352    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1353    *   %FALSE to propagate the event further.
1354    */
1355   widget_signals[FOCUS_IN_EVENT] =
1356     g_signal_new (I_("focus-in-event"),
1357                   G_TYPE_FROM_CLASS (gobject_class),
1358                   G_SIGNAL_RUN_LAST,
1359                   G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1360                   _gtk_boolean_handled_accumulator, NULL,
1361                   _gtk_marshal_BOOLEAN__BOXED,
1362                   G_TYPE_BOOLEAN, 1,
1363                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1364
1365   /**
1366    * GtkWidget::focus-out-event
1367    * @widget: the object which received the signal
1368    * @event: the #GdkEventFocus which triggered this signal
1369    *
1370    * The ::focus-out-event signal will be emitted when the keyboard focus
1371    * leaves the @widget's window.
1372    *
1373    * To receive this signal, the #GdkWindow associated to the widget needs
1374    * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1375    *
1376    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1377    *   %FALSE to propagate the event further.
1378    */
1379   widget_signals[FOCUS_OUT_EVENT] =
1380     g_signal_new (I_("focus-out-event"),
1381                   G_TYPE_FROM_CLASS (gobject_class),
1382                   G_SIGNAL_RUN_LAST,
1383                   G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1384                   _gtk_boolean_handled_accumulator, NULL,
1385                   _gtk_marshal_BOOLEAN__BOXED,
1386                   G_TYPE_BOOLEAN, 1,
1387                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1388
1389   /**
1390    * GtkWidget::map-event
1391    * @widget: the object which received the signal
1392    * @event: the #GdkEventAny which triggered this signal
1393    *
1394    * The ::map-event signal will be emitted when the @widget's window is
1395    * mapped. A window is mapped when it becomes visible on the screen.
1396    *
1397    * To receive this signal, the #GdkWindow associated to the widget needs
1398    * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1399    * automatically for all new windows.
1400    *
1401    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1402    *   %FALSE to propagate the event further.
1403    */
1404   widget_signals[MAP_EVENT] =
1405     g_signal_new (I_("map-event"),
1406                   G_TYPE_FROM_CLASS (gobject_class),
1407                   G_SIGNAL_RUN_LAST,
1408                   G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1409                   _gtk_boolean_handled_accumulator, NULL,
1410                   _gtk_marshal_BOOLEAN__BOXED,
1411                   G_TYPE_BOOLEAN, 1,
1412                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1413
1414   /**
1415    * GtkWidget::unmap-event
1416    * @widget: the object which received the signal
1417    * @event: the #GdkEventAny which triggered this signal
1418    *
1419    * The ::unmap-event signal will be emitted when the @widget's window is
1420    * unmapped. A window is unmapped when it becomes invisible on the screen.
1421    *
1422    * To receive this signal, the #GdkWindow associated to the widget needs
1423    * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1424    * automatically for all new windows.
1425    *
1426    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1427    *   %FALSE to propagate the event further.
1428    */
1429   widget_signals[UNMAP_EVENT] =
1430     g_signal_new (I_("unmap-event"),
1431                   G_TYPE_FROM_CLASS (gobject_class),
1432                   G_SIGNAL_RUN_LAST,
1433                   G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1434                   _gtk_boolean_handled_accumulator, NULL,
1435                   _gtk_marshal_BOOLEAN__BOXED,
1436                   G_TYPE_BOOLEAN, 1,
1437                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1438
1439   /**
1440    * GtkWidget::property-notify-event
1441    * @widget: the object which received the signal
1442    * @event: the #GdkEventProperty which triggered this signal
1443    *
1444    * The ::property-notify-event signal will be emitted when a property on
1445    * the @widget's window has been changed or deleted.
1446    *
1447    * To receive this signal, the #GdkWindow associated to the widget needs
1448    * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1449    *
1450    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1451    *   %FALSE to propagate the event further.
1452    */
1453   widget_signals[PROPERTY_NOTIFY_EVENT] =
1454     g_signal_new (I_("property-notify-event"),
1455                   G_TYPE_FROM_CLASS (gobject_class),
1456                   G_SIGNAL_RUN_LAST,
1457                   G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1458                   _gtk_boolean_handled_accumulator, NULL,
1459                   _gtk_marshal_BOOLEAN__BOXED,
1460                   G_TYPE_BOOLEAN, 1,
1461                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1462
1463   /**
1464    * GtkWidget::selection-clear-event
1465    * @widget: the object which received the signal
1466    * @event: the #GdkEventSelection which triggered this signal
1467    *
1468    * The ::selection-clear-event signal will be emitted when the
1469    * the @widget's window has lost ownership of a selection.
1470    *
1471    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1472    *   %FALSE to propagate the event further.
1473    */
1474   widget_signals[SELECTION_CLEAR_EVENT] =
1475     g_signal_new (I_("selection-clear-event"),
1476                   G_TYPE_FROM_CLASS (gobject_class),
1477                   G_SIGNAL_RUN_LAST,
1478                   G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1479                   _gtk_boolean_handled_accumulator, NULL,
1480                   _gtk_marshal_BOOLEAN__BOXED,
1481                   G_TYPE_BOOLEAN, 1,
1482                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1483
1484   /**
1485    * GtkWidget::selection-request-event
1486    * @widget: the object which received the signal
1487    * @event: the #GdkEventSelection which triggered this signal
1488    *
1489    * The ::selection-request-event signal will be emitted when
1490    * another client requests ownership of the selection owned by
1491    * the @widget's window.
1492    *
1493    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1494    *   %FALSE to propagate the event further.
1495    */
1496   widget_signals[SELECTION_REQUEST_EVENT] =
1497     g_signal_new (I_("selection-request-event"),
1498                   G_TYPE_FROM_CLASS (gobject_class),
1499                   G_SIGNAL_RUN_LAST,
1500                   G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1501                   _gtk_boolean_handled_accumulator, NULL,
1502                   _gtk_marshal_BOOLEAN__BOXED,
1503                   G_TYPE_BOOLEAN, 1,
1504                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1505
1506   widget_signals[SELECTION_NOTIFY_EVENT] =
1507     g_signal_new (I_("selection-notify-event"),
1508                   G_TYPE_FROM_CLASS (gobject_class),
1509                   G_SIGNAL_RUN_LAST,
1510                   G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1511                   _gtk_boolean_handled_accumulator, NULL,
1512                   _gtk_marshal_BOOLEAN__BOXED,
1513                   G_TYPE_BOOLEAN, 1,
1514                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1515
1516   widget_signals[SELECTION_RECEIVED] =
1517     g_signal_new (I_("selection-received"),
1518                   G_TYPE_FROM_CLASS (gobject_class),
1519                   G_SIGNAL_RUN_LAST,
1520                   G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1521                   NULL, NULL,
1522                   _gtk_marshal_VOID__BOXED_UINT,
1523                   G_TYPE_NONE, 2,
1524                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1525                   G_TYPE_UINT);
1526
1527   widget_signals[SELECTION_GET] =
1528     g_signal_new (I_("selection-get"),
1529                   G_TYPE_FROM_CLASS (gobject_class),
1530                   G_SIGNAL_RUN_LAST,
1531                   G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1532                   NULL, NULL,
1533                   _gtk_marshal_VOID__BOXED_UINT_UINT,
1534                   G_TYPE_NONE, 3,
1535                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1536                   G_TYPE_UINT,
1537                   G_TYPE_UINT);
1538
1539   /**
1540    * GtkWidget::proximity-in-event
1541    * @widget: the object which received the signal
1542    * @event: the #GdkEventProximity which triggered this signal
1543    *
1544    * To receive this signal the #GdkWindow associated to the widget needs
1545    * to enable the #GDK_PROXIMITY_IN_MASK mask.
1546    *
1547    * This signal will be sent to the grab widget if there is one.
1548    *
1549    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1550    *   %FALSE to propagate the event further.
1551    */
1552   widget_signals[PROXIMITY_IN_EVENT] =
1553     g_signal_new (I_("proximity-in-event"),
1554                   G_TYPE_FROM_CLASS (gobject_class),
1555                   G_SIGNAL_RUN_LAST,
1556                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1557                   _gtk_boolean_handled_accumulator, NULL,
1558                   _gtk_marshal_BOOLEAN__BOXED,
1559                   G_TYPE_BOOLEAN, 1,
1560                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1561
1562   /**
1563    * GtkWidget::proximity-out-event
1564    * @widget: the object which received the signal
1565    * @event: the #GdkEventProximity which triggered this signal
1566    *
1567    * To receive this signal the #GdkWindow associated to the widget needs
1568    * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1569    *
1570    * This signal will be sent to the grab widget if there is one.
1571    *
1572    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1573    *   %FALSE to propagate the event further.
1574    */
1575   widget_signals[PROXIMITY_OUT_EVENT] =
1576     g_signal_new (I_("proximity-out-event"),
1577                   G_TYPE_FROM_CLASS (gobject_class),
1578                   G_SIGNAL_RUN_LAST,
1579                   G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1580                   _gtk_boolean_handled_accumulator, NULL,
1581                   _gtk_marshal_BOOLEAN__BOXED,
1582                   G_TYPE_BOOLEAN, 1,
1583                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1584
1585   /**
1586    * GtkWidget::drag-leave:
1587    * @widget: the object which received the signal.
1588    * @drag_context: the drag context
1589    * @time: the timestamp of the motion event
1590    *
1591    * The ::drag-leave signal is emitted on the drop site when the cursor 
1592    * leaves the widget. A typical reason to connect to this signal is to 
1593    * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting 
1594    * with gtk_drag_unhighlight()
1595    */
1596   widget_signals[DRAG_LEAVE] =
1597     g_signal_new (I_("drag-leave"),
1598                   G_TYPE_FROM_CLASS (gobject_class),
1599                   G_SIGNAL_RUN_LAST,
1600                   G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1601                   NULL, NULL,
1602                   _gtk_marshal_VOID__OBJECT_UINT,
1603                   G_TYPE_NONE, 2,
1604                   GDK_TYPE_DRAG_CONTEXT,
1605                   G_TYPE_UINT);
1606
1607   /**
1608    * GtkWidget::drag-begin:
1609    * @widget: the object which received the signal
1610    * @drag_context: the drag context
1611    *
1612    * The ::drag-begin signal is emitted on the drag source when a drag is 
1613    * started. A typical reason to connect to this signal is to set up a 
1614    * custom drag icon with gtk_drag_source_set_icon().
1615    *
1616    * Note that some widgets set up a drag icon in the default handler of
1617    * this signal, so you may have to use g_signal_connect_after() to
1618    * override what the default handler did.
1619    */
1620   widget_signals[DRAG_BEGIN] =
1621     g_signal_new (I_("drag-begin"),
1622                   G_TYPE_FROM_CLASS (gobject_class),
1623                   G_SIGNAL_RUN_LAST,
1624                   G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1625                   NULL, NULL,
1626                   _gtk_marshal_VOID__OBJECT,
1627                   G_TYPE_NONE, 1,
1628                   GDK_TYPE_DRAG_CONTEXT);
1629
1630   /**
1631    * GtkWidget::drag-end:
1632    * @widget: the object which received the signal
1633    * @drag_context: the drag context
1634    *
1635    * The ::drag-end signal is emitted on the drag source when a drag is 
1636    * finished.  A typical reason to connect to this signal is to undo 
1637    * things done in #GtkWidget::drag-begin.
1638    */
1639   widget_signals[DRAG_END] =
1640     g_signal_new (I_("drag-end"),
1641                   G_TYPE_FROM_CLASS (gobject_class),
1642                   G_SIGNAL_RUN_LAST,
1643                   G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1644                   NULL, NULL,
1645                   _gtk_marshal_VOID__OBJECT,
1646                   G_TYPE_NONE, 1,
1647                   GDK_TYPE_DRAG_CONTEXT);
1648
1649   /**
1650    * GtkWidget::drag-data-delete:
1651    * @widget: the object which received the signal
1652    * @drag_context: the drag context
1653    *
1654    * The ::drag-data-delete signal is emitted on the drag source when a drag 
1655    * with the action %GDK_ACTION_MOVE is successfully completed. The signal 
1656    * handler is responsible for deleting the data that has been dropped. What 
1657    * "delete" means depends on the context of the drag operation. 
1658    */
1659   widget_signals[DRAG_DATA_DELETE] =
1660     g_signal_new (I_("drag-data-delete"),
1661                   G_TYPE_FROM_CLASS (gobject_class),
1662                   G_SIGNAL_RUN_LAST,
1663                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1664                   NULL, NULL,
1665                   _gtk_marshal_VOID__OBJECT,
1666                   G_TYPE_NONE, 1,
1667                   GDK_TYPE_DRAG_CONTEXT);
1668
1669   /**
1670    * GtkWidget::drag-failed:
1671    * @widget: the object which received the signal
1672    * @drag_context: the drag context
1673    * @result: the result of the drag operation
1674    *
1675    * The ::drag-failed signal is emitted on the drag source when a drag has
1676    * failed. The signal handler may hook custom code to handle a failed DND
1677    * operation based on the type of error, it returns %TRUE is the failure has
1678    * been already handled (not showing the default "drag operation failed"
1679    * animation), otherwise it returns %FALSE.
1680    *
1681    * Return value: %TRUE if the failed drag operation has been already handled.
1682    *
1683    * Since: 2.12
1684    */
1685   widget_signals[DRAG_FAILED] =
1686     g_signal_new (I_("drag-failed"),
1687                   G_TYPE_FROM_CLASS (gobject_class),
1688                   G_SIGNAL_RUN_LAST,
1689                   0, _gtk_boolean_handled_accumulator, NULL,
1690                   _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1691                   G_TYPE_BOOLEAN, 2,
1692                   GDK_TYPE_DRAG_CONTEXT,
1693                   GTK_TYPE_DRAG_RESULT);
1694
1695   /**
1696    * GtkWidget::drag-motion:
1697    * @widget: the object which received the signal
1698    * @drag_context: the drag context
1699    * @x: the x coordinate of the current cursor position
1700    * @y: the y coordinate of the current cursor position
1701    * @time: the timestamp of the motion event
1702    * @returns: whether the cursor position is in a drop zone
1703    *
1704    * The drag-motion signal is emitted on the drop site when the user
1705    * moves the cursor over the widget during a drag. The signal handler
1706    * must determine whether the cursor position is in a drop zone or not.
1707    * If it is not in a drop zone, it returns %FALSE and no further processing
1708    * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1709    * handler is responsible for providing the necessary information for
1710    * displaying feedback to the user, by calling gdk_drag_status().
1711    *
1712    * If the decision whether the drop will be accepted or rejected can't be
1713    * made based solely on the cursor position and the type of the data, the
1714    * handler may inspect the dragged data by calling gtk_drag_get_data() and
1715    * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1716    * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1717    * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1718    * when using the drag-motion signal that way.
1719    *
1720    * Also note that there is no drag-enter signal. The drag receiver has to
1721    * keep track of whether he has received any drag-motion signals since the
1722    * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1723    * an "enter" signal. Upon an "enter", the handler will typically highlight
1724    * the drop site with gtk_drag_highlight().
1725    * |[
1726    * static void
1727    * drag_motion (GtkWidget *widget,
1728    *              GdkDragContext *context,
1729    *              gint x,
1730    *              gint y,
1731    *              guint time)
1732    * {
1733    *   GdkAtom target;
1734    *  
1735    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1736    *  
1737    *   if (!private_data->drag_highlight) 
1738    *    {
1739    *      private_data->drag_highlight = 1;
1740    *      gtk_drag_highlight (widget);
1741    *    }
1742    *  
1743    *   target = gtk_drag_dest_find_target (widget, context, NULL);
1744    *   if (target == GDK_NONE)
1745    *     gdk_drag_status (context, 0, time);
1746    *   else 
1747    *    {
1748    *      private_data->pending_status = context->suggested_action;
1749    *      gtk_drag_get_data (widget, context, target, time);
1750    *    }
1751    *  
1752    *   return TRUE;
1753    * }
1754    *   
1755    * static void
1756    * drag_data_received (GtkWidget        *widget,
1757    *                     GdkDragContext   *context,
1758    *                     gint              x,
1759    *                     gint              y,
1760    *                     GtkSelectionData *selection_data,
1761    *                     guint             info,
1762    *                     guint             time)
1763    * {
1764    *   PrivateData *private_data = GET_PRIVATE_DATA (widget);
1765    *   
1766    *   if (private_data->suggested_action) 
1767    *    {
1768    *      private_data->suggested_action = 0;
1769    *      
1770    *     /&ast; We are getting this data due to a request in drag_motion,
1771    *      * rather than due to a request in drag_drop, so we are just
1772    *      * supposed to call gdk_drag_status (), not actually paste in 
1773    *      * the data.
1774    *      &ast;/
1775    *      str = gtk_selection_data_get_text (selection_data);
1776    *      if (!data_is_acceptable (str)) 
1777    *        gdk_drag_status (context, 0, time);
1778    *      else
1779    *        gdk_drag_status (context, private_data->suggested_action, time);
1780    *    }
1781    *   else
1782    *    {
1783    *      /&ast; accept the drop &ast;/
1784    *    }
1785    * }
1786    * ]|
1787    */
1788   widget_signals[DRAG_MOTION] =
1789     g_signal_new (I_("drag-motion"),
1790                   G_TYPE_FROM_CLASS (gobject_class),
1791                   G_SIGNAL_RUN_LAST,
1792                   G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1793                   _gtk_boolean_handled_accumulator, NULL,
1794                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1795                   G_TYPE_BOOLEAN, 4,
1796                   GDK_TYPE_DRAG_CONTEXT,
1797                   G_TYPE_INT,
1798                   G_TYPE_INT,
1799                   G_TYPE_UINT);
1800
1801   /**
1802    * GtkWidget::drag-drop:
1803    * @widget: the object which received the signal
1804    * @drag_context: the drag context
1805    * @x: the x coordinate of the current cursor position
1806    * @y: the y coordinate of the current cursor position
1807    * @time: the timestamp of the motion event
1808    * @returns: whether the cursor position is in a drop zone
1809    *
1810    * The ::drag-drop signal is emitted on the drop site when the user drops 
1811    * the data onto the widget. The signal handler must determine whether 
1812    * the cursor position is in a drop zone or not. If it is not in a drop 
1813    * zone, it returns %FALSE and no further processing is necessary. 
1814    * Otherwise, the handler returns %TRUE. In this case, the handler must 
1815    * ensure that gtk_drag_finish() is called to let the source know that 
1816    * the drop is done. The call to gtk_drag_finish() can be done either 
1817    * directly or in a #GtkWidget::drag-data-received handler which gets 
1818    * triggered by calling gtk_drag_get_data() to receive the data for one 
1819    * or more of the supported targets.
1820    */
1821   widget_signals[DRAG_DROP] =
1822     g_signal_new (I_("drag-drop"),
1823                   G_TYPE_FROM_CLASS (gobject_class),
1824                   G_SIGNAL_RUN_LAST,
1825                   G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1826                   _gtk_boolean_handled_accumulator, NULL,
1827                   _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1828                   G_TYPE_BOOLEAN, 4,
1829                   GDK_TYPE_DRAG_CONTEXT,
1830                   G_TYPE_INT,
1831                   G_TYPE_INT,
1832                   G_TYPE_UINT);
1833
1834   /** 
1835    * GtkWidget::drag-data-get:
1836    * @widget: the object which received the signal
1837    * @drag_context: the drag context
1838    * @data: the #GtkSelectionData to be filled with the dragged data
1839    * @info: the info that has been registered with the target in the 
1840    *        #GtkTargetList
1841    * @time: the timestamp at which the data was requested
1842    *
1843    * The ::drag-data-get signal is emitted on the drag source when the drop 
1844    * site requests the data which is dragged. It is the responsibility of 
1845    * the signal handler to fill @data with the data in the format which 
1846    * is indicated by @info. See gtk_selection_data_set() and 
1847    * gtk_selection_data_set_text().
1848    */
1849   widget_signals[DRAG_DATA_GET] =
1850     g_signal_new (I_("drag-data-get"),
1851                   G_TYPE_FROM_CLASS (gobject_class),
1852                   G_SIGNAL_RUN_LAST,
1853                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1854                   NULL, NULL,
1855                   _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1856                   G_TYPE_NONE, 4,
1857                   GDK_TYPE_DRAG_CONTEXT,
1858                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1859                   G_TYPE_UINT,
1860                   G_TYPE_UINT);
1861
1862   /**
1863    * GtkWidget::drag-data-received:
1864    * @widget: the object which received the signal
1865    * @drag_context: the drag context
1866    * @x: where the drop happened
1867    * @y: where the drop happened
1868    * @data: the received data
1869    * @info: the info that has been registered with the target in the 
1870    *        #GtkTargetList
1871    * @time: the timestamp at which the data was received
1872    *
1873    * The ::drag-data-received signal is emitted on the drop site when the 
1874    * dragged data has been received. If the data was received in order to 
1875    * determine whether the drop will be accepted, the handler is expected 
1876    * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag. 
1877    * If the data was received in response to a #GtkWidget::drag-drop signal 
1878    * (and this is the last target to be received), the handler for this 
1879    * signal is expected to process the received data and then call 
1880    * gtk_drag_finish(), setting the @success parameter depending on whether 
1881    * the data was processed successfully. 
1882    * 
1883    * The handler may inspect and modify @drag_context->action before calling 
1884    * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the 
1885    * following example:
1886    * |[
1887    * void  
1888    * drag_data_received (GtkWidget          *widget,
1889    *                     GdkDragContext     *drag_context,
1890    *                     gint                x,
1891    *                     gint                y,
1892    *                     GtkSelectionData   *data,
1893    *                     guint               info,
1894    *                     guint               time)
1895    * {
1896    *   if ((data->length >= 0) && (data->format == 8))
1897    *     {
1898    *       if (drag_context->action == GDK_ACTION_ASK) 
1899    *         {
1900    *           GtkWidget *dialog;
1901    *           gint response;
1902    *           
1903    *           dialog = gtk_message_dialog_new (NULL,
1904    *                                            GTK_DIALOG_MODAL | 
1905    *                                            GTK_DIALOG_DESTROY_WITH_PARENT,
1906    *                                            GTK_MESSAGE_INFO,
1907    *                                            GTK_BUTTONS_YES_NO,
1908    *                                            "Move the data ?\n");
1909    *           response = gtk_dialog_run (GTK_DIALOG (dialog));
1910    *           gtk_widget_destroy (dialog);
1911    *             
1912    *           if (response == GTK_RESPONSE_YES)
1913    *             drag_context->action = GDK_ACTION_MOVE;
1914    *           else
1915    *             drag_context->action = GDK_ACTION_COPY;
1916    *          }
1917    *          
1918    *       gtk_drag_finish (drag_context, TRUE, FALSE, time);
1919    *       return;
1920    *     }
1921    *       
1922    *    gtk_drag_finish (drag_context, FALSE, FALSE, time);
1923    *  }
1924    * ]|
1925    */
1926   widget_signals[DRAG_DATA_RECEIVED] =
1927     g_signal_new (I_("drag-data-received"),
1928                   G_TYPE_FROM_CLASS (gobject_class),
1929                   G_SIGNAL_RUN_LAST,
1930                   G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1931                   NULL, NULL,
1932                   _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1933                   G_TYPE_NONE, 6,
1934                   GDK_TYPE_DRAG_CONTEXT,
1935                   G_TYPE_INT,
1936                   G_TYPE_INT,
1937                   GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1938                   G_TYPE_UINT,
1939                   G_TYPE_UINT);
1940   
1941   /**
1942    * GtkWidget::visibility-notify-event:
1943    * @widget: the object which received the signal
1944    * @event: the #GdkEventVisibility which triggered this signal
1945    *
1946    * The ::visibility-notify-event will be emitted when the @widget's window
1947    * is obscured or unobscured.
1948    *
1949    * To receive this signal the #GdkWindow associated to the widget needs
1950    * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1951    *
1952    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1953    *   %FALSE to propagate the event further.
1954    */
1955   widget_signals[VISIBILITY_NOTIFY_EVENT] =
1956     g_signal_new (I_("visibility-notify-event"),
1957                   G_TYPE_FROM_CLASS (gobject_class),
1958                   G_SIGNAL_RUN_LAST,
1959                   G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1960                   _gtk_boolean_handled_accumulator, NULL,
1961                   _gtk_marshal_BOOLEAN__BOXED,
1962                   G_TYPE_BOOLEAN, 1,
1963                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1964
1965   /**
1966    * GtkWidget::client-event:
1967    * @widget: the object which received the signal
1968    * @event: the #GdkEventClient which triggered this signal
1969    *
1970    * The ::client-event will be emitted when the @widget's window
1971    * receives a message (via a ClientMessage event) from another
1972    * application.
1973    *
1974    * Returns: %TRUE to stop other handlers from being invoked for 
1975    *   the event. %FALSE to propagate the event further.
1976    */
1977   widget_signals[CLIENT_EVENT] =
1978     g_signal_new (I_("client-event"),
1979                   G_TYPE_FROM_CLASS (gobject_class),
1980                   G_SIGNAL_RUN_LAST,
1981                   G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1982                   _gtk_boolean_handled_accumulator, NULL,
1983                   _gtk_marshal_BOOLEAN__BOXED,
1984                   G_TYPE_BOOLEAN, 1,
1985                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1986
1987   /**
1988    * GtkWidget::no-expose-event:
1989    * @widget: the object which received the signal
1990    * @event: the #GdkEventNoExpose which triggered this signal
1991    *
1992    * The ::no-expose-event will be emitted when the @widget's window is 
1993    * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1994    * gdk_window_copy_area()) which was completely unobscured. If the source
1995    * window was partially obscured #GdkEventExpose events will be generated
1996    * for those areas.
1997    *
1998    * Returns: %TRUE to stop other handlers from being invoked for the event. 
1999    *   %FALSE to propagate the event further.
2000    */
2001   widget_signals[NO_EXPOSE_EVENT] =
2002     g_signal_new (I_("no-expose-event"),
2003                   G_TYPE_FROM_CLASS (gobject_class),
2004                   G_SIGNAL_RUN_LAST,
2005                   G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2006                   _gtk_boolean_handled_accumulator, NULL,
2007                   _gtk_marshal_BOOLEAN__BOXED,
2008                   G_TYPE_BOOLEAN, 1,
2009                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2010
2011   /**
2012    * GtkWidget::window-state-event:
2013    * @widget: the object which received the signal
2014    * @event: the #GdkEventWindowState which triggered this signal
2015    *
2016    * The ::window-state-event will be emitted when the state of the 
2017    * toplevel window associated to the @widget changes.
2018    *
2019    * To receive this signal the #GdkWindow associated to the widget 
2020    * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable 
2021    * this mask automatically for all new windows.
2022    *
2023    * Returns: %TRUE to stop other handlers from being invoked for the 
2024    *   event. %FALSE to propagate the event further.
2025    */
2026   widget_signals[WINDOW_STATE_EVENT] =
2027     g_signal_new (I_("window-state-event"),
2028                   G_TYPE_FROM_CLASS (gobject_class),
2029                   G_SIGNAL_RUN_LAST,
2030                   G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2031                   _gtk_boolean_handled_accumulator, NULL,
2032                   _gtk_marshal_BOOLEAN__BOXED,
2033                   G_TYPE_BOOLEAN, 1,
2034                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2035
2036   /**
2037    * GtkWidget::damage-event:
2038    * @widget: the object which received the signal
2039    * @event: the #GdkEventExpose event
2040    *
2041    * Emitted when a redirected window belonging to @widget gets drawn into.
2042    * The region/area members of the event shows what area of the redirected
2043    * drawable was drawn into.
2044    *
2045    * Returns: %TRUE to stop other handlers from being invoked for the event.
2046    *   %FALSE to propagate the event further.
2047    *
2048    * Since: 2.14
2049    */
2050   widget_signals[DAMAGE_EVENT] =
2051     g_signal_new (I_("damage-event"),
2052                   G_TYPE_FROM_CLASS (gobject_class),
2053                   G_SIGNAL_RUN_LAST,
2054                   0,
2055                   _gtk_boolean_handled_accumulator, NULL,
2056                   _gtk_marshal_BOOLEAN__BOXED,
2057                   G_TYPE_BOOLEAN, 1,
2058                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2059 /**
2060    * GtkWidget::grab-broken-event:
2061    * @widget: the object which received the signal
2062    * @event: the #GdkEventGrabBroken event
2063    *
2064    * Emitted when a pointer or keyboard grab on a window belonging 
2065    * to @widget gets broken. 
2066    * 
2067    * On X11, this happens when the grab window becomes unviewable 
2068    * (i.e. it or one of its ancestors is unmapped), or if the same 
2069    * application grabs the pointer or keyboard again.
2070    *
2071    * Returns: %TRUE to stop other handlers from being invoked for 
2072    *   the event. %FALSE to propagate the event further.
2073    *
2074    * Since: 2.8
2075    */
2076   widget_signals[GRAB_BROKEN] =
2077     g_signal_new (I_("grab-broken-event"),
2078                   G_TYPE_FROM_CLASS (gobject_class),
2079                   G_SIGNAL_RUN_LAST,
2080                   G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2081                   _gtk_boolean_handled_accumulator, NULL,
2082                   _gtk_marshal_BOOLEAN__BOXED,
2083                   G_TYPE_BOOLEAN, 1,
2084                   GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2085   /**
2086    * GtkWidget::query-tooltip:
2087    * @widget: the object which received the signal
2088    * @x: the x coordinate of the cursor position where the request has 
2089    *     been emitted, relative to @widget->window
2090    * @y: the y coordinate of the cursor position where the request has 
2091    *     been emitted, relative to @widget->window
2092    * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2093    * @tooltip: a #GtkTooltip
2094    *
2095    * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout 
2096    * has expired with the cursor hovering "above" @widget; or emitted when @widget got 
2097    * focus in keyboard mode.
2098    *
2099    * Using the given coordinates, the signal handler should determine
2100    * whether a tooltip should be shown for @widget. If this is the case
2101    * %TRUE should be returned, %FALSE otherwise.  Note that if
2102    * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2103    * should not be used.
2104    *
2105    * The signal handler is free to manipulate @tooltip with the therefore
2106    * destined function calls.
2107    *
2108    * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2109    *
2110    * Since: 2.12
2111    */
2112   widget_signals[QUERY_TOOLTIP] =
2113     g_signal_new (I_("query-tooltip"),
2114                   G_TYPE_FROM_CLASS (gobject_class),
2115                   G_SIGNAL_RUN_LAST,
2116                   G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2117                   _gtk_boolean_handled_accumulator, NULL,
2118                   _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2119                   G_TYPE_BOOLEAN, 4,
2120                   G_TYPE_INT,
2121                   G_TYPE_INT,
2122                   G_TYPE_BOOLEAN,
2123                   GTK_TYPE_TOOLTIP);
2124
2125   /**
2126    * GtkWidget::popup-menu
2127    * @widget: the object which received the signal
2128    *
2129    * This signal gets emitted whenever a widget should pop up a context 
2130    * menu. This usually happens through the standard key binding mechanism; 
2131    * by pressing a certain key while a widget is focused, the user can cause 
2132    * the widget to pop up a menu.  For example, the #GtkEntry widget creates 
2133    * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/> 
2134    * for an example of how to use this signal.
2135    *
2136    * Returns: %TRUE if a menu was activated
2137    */
2138   widget_signals[POPUP_MENU] =
2139     g_signal_new (I_("popup-menu"),
2140                   G_TYPE_FROM_CLASS (gobject_class),
2141                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2142                   G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2143                   _gtk_boolean_handled_accumulator, NULL,
2144                   _gtk_marshal_BOOLEAN__VOID,
2145                   G_TYPE_BOOLEAN, 0);
2146   widget_signals[SHOW_HELP] =
2147     g_signal_new (I_("show-help"),
2148                   G_TYPE_FROM_CLASS (gobject_class),
2149                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2150                   G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2151                   _gtk_boolean_handled_accumulator, NULL,
2152                   _gtk_marshal_BOOLEAN__ENUM,
2153                   G_TYPE_BOOLEAN, 1,
2154                   GTK_TYPE_WIDGET_HELP_TYPE);
2155   widget_signals[ACCEL_CLOSURES_CHANGED] =
2156     g_signal_new (I_("accel-closures-changed"),
2157                   G_TYPE_FROM_CLASS (gobject_class),
2158                   0,
2159                   0,
2160                   NULL, NULL,
2161                   _gtk_marshal_VOID__VOID,
2162                   G_TYPE_NONE, 0);
2163
2164   /**
2165    * GtkWidget::screen-changed:
2166    * @widget: the object on which the signal is emitted
2167    * @previous_screen: the previous screen, or %NULL if the
2168    *   widget was not associated with a screen before
2169    *
2170    * The ::screen-changed signal gets emitted when the
2171    * screen of a widget has changed.
2172    */
2173   widget_signals[SCREEN_CHANGED] =
2174     g_signal_new (I_("screen-changed"),
2175                   G_TYPE_FROM_CLASS (gobject_class),
2176                   G_SIGNAL_RUN_LAST,
2177                   G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2178                   NULL, NULL,
2179                   _gtk_marshal_VOID__OBJECT,
2180                   G_TYPE_NONE, 1,
2181                   GDK_TYPE_SCREEN);
2182   /**
2183    * GtkWidget::can-activate-accel:
2184    * @widget: the object which received the signal
2185    * @signal_id: the ID of a signal installed on @widget
2186    *
2187    * Determines whether an accelerator that activates the signal
2188    * identified by @signal_id can currently be activated.
2189    * This signal is present to allow applications and derived
2190    * widgets to override the default #GtkWidget handling
2191    * for determining whether an accelerator can be activated.
2192    *
2193    * Returns: %TRUE if the signal can be activated.
2194    */
2195   widget_signals[CAN_ACTIVATE_ACCEL] =
2196      g_signal_new (I_("can-activate-accel"),
2197                   G_TYPE_FROM_CLASS (gobject_class),
2198                   G_SIGNAL_RUN_LAST,
2199                   G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2200                   _gtk_boolean_handled_accumulator, NULL,
2201                   _gtk_marshal_BOOLEAN__UINT,
2202                   G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2203
2204   binding_set = gtk_binding_set_by_class (klass);
2205   gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2206                                 "popup-menu", 0);
2207   gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2208                                 "popup-menu", 0);  
2209
2210   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2211                                 "show-help", 1,
2212                                 GTK_TYPE_WIDGET_HELP_TYPE,
2213                                 GTK_WIDGET_HELP_TOOLTIP);
2214   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2215                                 "show-help", 1,
2216                                 GTK_TYPE_WIDGET_HELP_TYPE,
2217                                 GTK_WIDGET_HELP_TOOLTIP);
2218   gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2219                                 "show-help", 1,
2220                                 GTK_TYPE_WIDGET_HELP_TYPE,
2221                                 GTK_WIDGET_HELP_WHATS_THIS);  
2222   gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2223                                 "show-help", 1,
2224                                 GTK_TYPE_WIDGET_HELP_TYPE,
2225                                 GTK_WIDGET_HELP_WHATS_THIS);
2226
2227   gtk_widget_class_install_style_property (klass,
2228                                            g_param_spec_boolean ("interior-focus",
2229                                                                  P_("Interior Focus"),
2230                                                                  P_("Whether to draw the focus indicator inside widgets"),
2231                                                                  TRUE,
2232                                                                  GTK_PARAM_READABLE));
2233
2234   gtk_widget_class_install_style_property (klass,
2235                                            g_param_spec_int ("focus-line-width",
2236                                                              P_("Focus linewidth"),
2237                                                              P_("Width, in pixels, of the focus indicator line"),
2238                                                              0, G_MAXINT, 1,
2239                                                              GTK_PARAM_READABLE));
2240
2241   gtk_widget_class_install_style_property (klass,
2242                                            g_param_spec_string ("focus-line-pattern",
2243                                                                 P_("Focus line dash pattern"),
2244                                                                 P_("Dash pattern used to draw the focus indicator"),
2245                                                                 "\1\1",
2246                                                                 GTK_PARAM_READABLE));
2247   gtk_widget_class_install_style_property (klass,
2248                                            g_param_spec_int ("focus-padding",
2249                                                              P_("Focus padding"),
2250                                                              P_("Width, in pixels, between focus indicator and the widget 'box'"),
2251                                                              0, G_MAXINT, 1,
2252                                                              GTK_PARAM_READABLE));
2253   gtk_widget_class_install_style_property (klass,
2254                                            g_param_spec_boxed ("cursor-color",
2255                                                                P_("Cursor color"),
2256                                                                P_("Color with which to draw insertion cursor"),
2257                                                                GDK_TYPE_COLOR,
2258                                                                GTK_PARAM_READABLE));
2259   gtk_widget_class_install_style_property (klass,
2260                                            g_param_spec_boxed ("secondary-cursor-color",
2261                                                                P_("Secondary cursor color"),
2262                                                                P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2263                                                                GDK_TYPE_COLOR,
2264                                                                GTK_PARAM_READABLE));
2265   gtk_widget_class_install_style_property (klass,
2266                                            g_param_spec_float ("cursor-aspect-ratio",
2267                                                                P_("Cursor line aspect ratio"),
2268                                                                P_("Aspect ratio with which to draw insertion cursor"),
2269                                                                0.0, 1.0, 0.04,
2270                                                                GTK_PARAM_READABLE));
2271
2272   /**
2273    * GtkWidget:draw-border:
2274    *
2275    * The "draw-border" style property defines the size of areas outside 
2276    * the widget's allocation to draw.
2277    *
2278    * Since: 2.8
2279    */
2280   gtk_widget_class_install_style_property (klass,
2281                                            g_param_spec_boxed ("draw-border",
2282                                                                P_("Draw Border"),
2283                                                                P_("Size of areas outside the widget's allocation to draw"),
2284                                                                GTK_TYPE_BORDER,
2285                                                                GTK_PARAM_READABLE));
2286
2287   /**
2288    * GtkWidget:link-color:
2289    *
2290    * The "link-color" style property defines the color of unvisited links.
2291    *
2292    * Since: 2.10
2293    */
2294   gtk_widget_class_install_style_property (klass,
2295                                            g_param_spec_boxed ("link-color",
2296                                                                P_("Unvisited Link Color"),
2297                                                                P_("Color of unvisited links"),
2298                                                                GDK_TYPE_COLOR,
2299                                                                GTK_PARAM_READABLE));
2300
2301   /**
2302    * GtkWidget:visited-link-color:
2303    *
2304    * The "visited-link-color" style property defines the color of visited links.
2305    *
2306    * Since: 2.10
2307    */
2308   gtk_widget_class_install_style_property (klass,
2309                                            g_param_spec_boxed ("visited-link-color",
2310                                                                P_("Visited Link Color"),
2311                                                                P_("Color of visited links"),
2312                                                                GDK_TYPE_COLOR,
2313                                                                GTK_PARAM_READABLE));
2314
2315   /**
2316    * GtkWidget:wide-separators:
2317    *
2318    * The "wide-separators" style property defines whether separators have 
2319    * configurable width and should be drawn using a box instead of a line.
2320    *
2321    * Since: 2.10
2322    */
2323   gtk_widget_class_install_style_property (klass,
2324                                            g_param_spec_boolean ("wide-separators",
2325                                                                  P_("Wide Separators"),
2326                                                                  P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2327                                                                  FALSE,
2328                                                                  GTK_PARAM_READABLE));
2329
2330   /**
2331    * GtkWidget:separator-width:
2332    *
2333    * The "separator-width" style property defines the width of separators.
2334    * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2335    *
2336    * Since: 2.10
2337    */
2338   gtk_widget_class_install_style_property (klass,
2339                                            g_param_spec_int ("separator-width",
2340                                                              P_("Separator Width"),
2341                                                              P_("The width of separators if wide-separators is TRUE"),
2342                                                              0, G_MAXINT, 0,
2343                                                              GTK_PARAM_READABLE));
2344
2345   /**
2346    * GtkWidget:separator-height:
2347    *
2348    * The "separator-height" style property defines the height of separators.
2349    * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2350    *
2351    * Since: 2.10
2352    */
2353   gtk_widget_class_install_style_property (klass,
2354                                            g_param_spec_int ("separator-height",
2355                                                              P_("Separator Height"),
2356                                                              P_("The height of separators if \"wide-separators\" is TRUE"),
2357                                                              0, G_MAXINT, 0,
2358                                                              GTK_PARAM_READABLE));
2359
2360   /**
2361    * GtkWidget:scroll-arrow-hlength:
2362    *
2363    * The "scroll-arrow-hlength" style property defines the length of 
2364    * horizontal scroll arrows.
2365    *
2366    * Since: 2.10
2367    */
2368   gtk_widget_class_install_style_property (klass,
2369                                            g_param_spec_int ("scroll-arrow-hlength",
2370                                                              P_("Horizontal Scroll Arrow Length"),
2371                                                              P_("The length of horizontal scroll arrows"),
2372                                                              1, G_MAXINT, 16,
2373                                                              GTK_PARAM_READABLE));
2374
2375   /**
2376    * GtkWidget:scroll-arrow-vlength:
2377    *
2378    * The "scroll-arrow-vlength" style property defines the length of 
2379    * vertical scroll arrows.
2380    *
2381    * Since: 2.10
2382    */
2383   gtk_widget_class_install_style_property (klass,
2384                                            g_param_spec_int ("scroll-arrow-vlength",
2385                                                              P_("Vertical Scroll Arrow Length"),
2386                                                              P_("The length of vertical scroll arrows"),
2387                                                              1, G_MAXINT, 16,
2388                                                              GTK_PARAM_READABLE));
2389 }
2390
2391 static void
2392 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2393 {
2394   GList *list, *node;
2395
2396   list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2397   for (node = list; node; node = node->next)
2398     {
2399       GParamSpec *pspec = node->data;
2400
2401       g_param_spec_pool_remove (style_property_spec_pool, pspec);
2402       g_param_spec_unref (pspec);
2403     }
2404   g_list_free (list);
2405 }
2406
2407 static void
2408 gtk_widget_set_property (GObject         *object,
2409                          guint            prop_id,
2410                          const GValue    *value,
2411                          GParamSpec      *pspec)
2412 {
2413   GtkWidget *widget = GTK_WIDGET (object);
2414
2415   switch (prop_id)
2416     {
2417       gboolean tmp;
2418       guint32 saved_flags;
2419       gchar *tooltip_markup;
2420       const gchar *tooltip_text;
2421       GtkWindow *tooltip_window;
2422       
2423     case PROP_NAME:
2424       gtk_widget_set_name (widget, g_value_get_string (value));
2425       break;
2426     case PROP_PARENT:
2427       gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2428       break;
2429     case PROP_WIDTH_REQUEST:
2430       gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2431       break;
2432     case PROP_HEIGHT_REQUEST:
2433       gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2434       break;
2435     case PROP_VISIBLE:
2436       gtk_widget_set_visible (widget, g_value_get_boolean (value));
2437       break;
2438     case PROP_SENSITIVE:
2439       gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2440       break;
2441     case PROP_APP_PAINTABLE:
2442       gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2443       break;
2444     case PROP_CAN_FOCUS:
2445       saved_flags = GTK_WIDGET_FLAGS (widget);
2446       if (g_value_get_boolean (value))
2447         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2448       else
2449         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2450       if (saved_flags != GTK_WIDGET_FLAGS (widget))
2451         gtk_widget_queue_resize (widget);
2452       break;
2453     case PROP_HAS_FOCUS:
2454       if (g_value_get_boolean (value))
2455         gtk_widget_grab_focus (widget);
2456       break;
2457     case PROP_IS_FOCUS:
2458       if (g_value_get_boolean (value))
2459         gtk_widget_grab_focus (widget);
2460       break;
2461     case PROP_CAN_DEFAULT:
2462       saved_flags = GTK_WIDGET_FLAGS (widget);
2463       if (g_value_get_boolean (value))
2464         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2465       else
2466         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2467       if (saved_flags != GTK_WIDGET_FLAGS (widget))
2468         gtk_widget_queue_resize (widget);
2469       break;
2470     case PROP_HAS_DEFAULT:
2471       if (g_value_get_boolean (value))
2472         gtk_widget_grab_default (widget);
2473       break;
2474     case PROP_RECEIVES_DEFAULT:
2475       if (g_value_get_boolean (value))
2476         GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2477       else
2478         GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2479       break;
2480     case PROP_STYLE:
2481       gtk_widget_set_style (widget, g_value_get_object (value));
2482       break;
2483     case PROP_EVENTS:
2484       if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2485         gtk_widget_set_events (widget, g_value_get_flags (value));
2486       break;
2487     case PROP_EXTENSION_EVENTS:
2488       gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2489       break;
2490     case PROP_NO_SHOW_ALL:
2491       gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2492       break;
2493     case PROP_HAS_TOOLTIP:
2494       gtk_widget_real_set_has_tooltip (widget,
2495                                        g_value_get_boolean (value), FALSE);
2496       break;
2497     case PROP_TOOLTIP_MARKUP:
2498       tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2499       tooltip_markup = g_value_dup_string (value);
2500
2501       /* Treat an empty string as a NULL string, 
2502        * because an empty string would be useless for a tooltip:
2503        */
2504       if (tooltip_markup && (strlen (tooltip_markup) == 0))
2505         {
2506           g_free (tooltip_markup);
2507           tooltip_markup = NULL;
2508         }
2509
2510       g_object_set_qdata_full (object, quark_tooltip_markup,
2511                                tooltip_markup, g_free);
2512
2513       tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2514       gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2515       if (GTK_WIDGET_VISIBLE (widget))
2516         gtk_widget_queue_tooltip_query (widget);
2517       break;
2518     case PROP_TOOLTIP_TEXT:
2519       tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2520
2521       tooltip_text = g_value_get_string (value);
2522
2523       /* Treat an empty string as a NULL string, 
2524        * because an empty string would be useless for a tooltip:
2525        */
2526       if (tooltip_text && (strlen (tooltip_text) == 0))
2527         tooltip_text = NULL;
2528
2529       tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2530
2531       g_object_set_qdata_full (object, quark_tooltip_markup,
2532                                tooltip_markup, g_free);
2533
2534       tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2535       gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2536       if (GTK_WIDGET_VISIBLE (widget))
2537         gtk_widget_queue_tooltip_query (widget);
2538       break;
2539     case PROP_DOUBLE_BUFFERED:
2540       gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2541       break;
2542     default:
2543       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2544       break;
2545     }
2546 }
2547
2548 static void
2549 gtk_widget_get_property (GObject         *object,
2550                          guint            prop_id,
2551                          GValue          *value,
2552                          GParamSpec      *pspec)
2553 {
2554   GtkWidget *widget = GTK_WIDGET (object);
2555   
2556   switch (prop_id)
2557     {
2558       gpointer *eventp;
2559       gpointer *modep;
2560
2561     case PROP_NAME:
2562       if (widget->name)
2563         g_value_set_string (value, widget->name);
2564       else
2565         g_value_set_static_string (value, "");
2566       break;
2567     case PROP_PARENT:
2568       g_value_set_object (value, widget->parent);
2569       break;
2570     case PROP_WIDTH_REQUEST:
2571       {
2572         int w;
2573         gtk_widget_get_size_request (widget, &w, NULL);
2574         g_value_set_int (value, w);
2575       }
2576       break;
2577     case PROP_HEIGHT_REQUEST:
2578       {
2579         int h;
2580         gtk_widget_get_size_request (widget, NULL, &h);
2581         g_value_set_int (value, h);
2582       }
2583       break;
2584     case PROP_VISIBLE:
2585       g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2586       break;
2587     case PROP_SENSITIVE:
2588       g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2589       break;
2590     case PROP_APP_PAINTABLE:
2591       g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2592       break;
2593     case PROP_CAN_FOCUS:
2594       g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2595       break;
2596     case PROP_HAS_FOCUS:
2597       g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2598       break;
2599     case PROP_IS_FOCUS:
2600       g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2601       break;
2602     case PROP_CAN_DEFAULT:
2603       g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2604       break;
2605     case PROP_HAS_DEFAULT:
2606       g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2607       break;
2608     case PROP_RECEIVES_DEFAULT:
2609       g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2610       break;
2611     case PROP_COMPOSITE_CHILD:
2612       g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2613       break;
2614     case PROP_STYLE:
2615       g_value_set_object (value, gtk_widget_get_style (widget));
2616       break;
2617     case PROP_EVENTS:
2618       eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2619       g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2620       break;
2621     case PROP_EXTENSION_EVENTS:
2622       modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2623       g_value_set_enum (value, GPOINTER_TO_INT (modep));
2624       break;
2625     case PROP_NO_SHOW_ALL:
2626       g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2627       break;
2628     case PROP_HAS_TOOLTIP:
2629       g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2630       break;
2631     case PROP_TOOLTIP_TEXT:
2632       {
2633         gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2634         gchar *text = NULL;
2635
2636         if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2637           g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2638
2639         g_value_set_string (value, text);
2640         g_free (text);
2641       }
2642       break;
2643     case PROP_TOOLTIP_MARKUP:
2644       g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2645       break;
2646     case PROP_WINDOW:
2647       g_value_set_object (value, gtk_widget_get_window (widget));
2648       break;
2649     case PROP_DOUBLE_BUFFERED:
2650       g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2651       break;
2652     default:
2653       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2654       break;
2655     }
2656 }
2657
2658 static void
2659 gtk_widget_init (GtkWidget *widget)
2660 {
2661   GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2662   widget->state = GTK_STATE_NORMAL;
2663   widget->saved_state = GTK_STATE_NORMAL;
2664   widget->name = NULL;
2665   widget->requisition.width = 0;
2666   widget->requisition.height = 0;
2667   widget->allocation.x = -1;
2668   widget->allocation.y = -1;
2669   widget->allocation.width = 1;
2670   widget->allocation.height = 1;
2671   widget->window = NULL;
2672   widget->parent = NULL;
2673
2674   GTK_WIDGET_SET_FLAGS (widget,
2675                         GTK_SENSITIVE |
2676                         GTK_PARENT_SENSITIVE |
2677                         (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2678                         GTK_DOUBLE_BUFFERED);
2679
2680   GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2681   GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2682   GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2683
2684   widget->style = gtk_widget_get_default_style ();
2685   g_object_ref (widget->style);
2686 }
2687
2688
2689 static void
2690 gtk_widget_dispatch_child_properties_changed (GtkWidget   *widget,
2691                                               guint        n_pspecs,
2692                                               GParamSpec **pspecs)
2693 {
2694   GtkWidget *container = widget->parent;
2695   guint i;
2696
2697   for (i = 0; widget->parent == container && i < n_pspecs; i++)
2698     g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2699 }
2700
2701 /**
2702  * gtk_widget_freeze_child_notify:
2703  * @widget: a #GtkWidget
2704  * 
2705  * Stops emission of #GtkWidget::child-notify signals on @widget. The 
2706  * signals are queued until gtk_widget_thaw_child_notify() is called 
2707  * on @widget. 
2708  *
2709  * This is the analogue of g_object_freeze_notify() for child properties.
2710  **/
2711 void
2712 gtk_widget_freeze_child_notify (GtkWidget *widget)
2713 {
2714   g_return_if_fail (GTK_IS_WIDGET (widget));
2715
2716   if (!G_OBJECT (widget)->ref_count)
2717     return;
2718
2719   g_object_ref (widget);
2720   g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2721   g_object_unref (widget);
2722 }
2723
2724 /**
2725  * gtk_widget_child_notify:
2726  * @widget: a #GtkWidget
2727  * @child_property: the name of a child property installed on the 
2728  *                  class of @widget<!-- -->'s parent
2729  * 
2730  * Emits a #GtkWidget::child-notify signal for the 
2731  * <link linkend="child-properties">child property</link> @child_property 
2732  * on @widget.
2733  *
2734  * This is the analogue of g_object_notify() for child properties.
2735  **/
2736 void
2737 gtk_widget_child_notify (GtkWidget    *widget,
2738                          const gchar  *child_property)
2739 {
2740   GParamSpec *pspec;
2741
2742   g_return_if_fail (GTK_IS_WIDGET (widget));
2743   g_return_if_fail (child_property != NULL);
2744   if (!G_OBJECT (widget)->ref_count || !widget->parent)
2745     return;
2746
2747   g_object_ref (widget);
2748   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2749                                     child_property,
2750                                     G_OBJECT_TYPE (widget->parent),
2751                                     TRUE);
2752   if (!pspec)
2753     g_warning ("%s: container class `%s' has no child property named `%s'",
2754                G_STRLOC,
2755                G_OBJECT_TYPE_NAME (widget->parent),
2756                child_property);
2757   else
2758     {
2759       GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2760
2761       g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2762       g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2763     }
2764   g_object_unref (widget);
2765 }
2766
2767 /**
2768  * gtk_widget_thaw_child_notify:
2769  * @widget: a #GtkWidget
2770  *
2771  * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2772  * This causes all queued #GtkWidget::child-notify signals on @widget to be 
2773  * emitted.
2774  */ 
2775 void
2776 gtk_widget_thaw_child_notify (GtkWidget *widget)
2777 {
2778   GObjectNotifyQueue *nqueue;
2779
2780   g_return_if_fail (GTK_IS_WIDGET (widget));
2781
2782   if (!G_OBJECT (widget)->ref_count)
2783     return;
2784
2785   g_object_ref (widget);
2786   nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2787   if (!nqueue || !nqueue->freeze_count)
2788     g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2789                G_OBJECT_TYPE_NAME (widget), widget);
2790   else
2791     g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2792   g_object_unref (widget);
2793 }
2794
2795
2796 /**
2797  * gtk_widget_new:
2798  * @type: type ID of the widget to create
2799  * @first_property_name: name of first property to set
2800  * @Varargs: value of first property, followed by more properties, 
2801  *           %NULL-terminated
2802  * 
2803  * This is a convenience function for creating a widget and setting
2804  * its properties in one go. For example you might write:
2805  * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2806  * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2807  * g_object_new(), but returns a widget so you don't have to
2808  * cast the object yourself.
2809  * 
2810  * Return value: a new #GtkWidget of type @widget_type
2811  **/
2812 GtkWidget*
2813 gtk_widget_new (GType        type,
2814                 const gchar *first_property_name,
2815                 ...)
2816 {
2817   GtkWidget *widget;
2818   va_list var_args;
2819   
2820   g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2821   
2822   va_start (var_args, first_property_name);
2823   widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2824   va_end (var_args);
2825
2826   return widget;
2827 }
2828
2829 /**
2830  * gtk_widget_set:
2831  * @widget: a #GtkWidget
2832  * @first_property_name: name of first property to set
2833  * @Varargs: value of first property, followed by more properties, 
2834  *           %NULL-terminated
2835  * 
2836  * Precursor of g_object_set().
2837  *
2838  * Deprecated: 2.0: Use g_object_set() instead.
2839  **/
2840 void
2841 gtk_widget_set (GtkWidget   *widget,
2842                 const gchar *first_property_name,
2843                 ...)
2844 {
2845   va_list var_args;
2846
2847   g_return_if_fail (GTK_IS_WIDGET (widget));
2848
2849   va_start (var_args, first_property_name);
2850   g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2851   va_end (var_args);
2852 }
2853
2854 static inline void         
2855 gtk_widget_queue_draw_child (GtkWidget *widget)
2856 {
2857   GtkWidget *parent;
2858
2859   parent = widget->parent;
2860   if (parent && GTK_WIDGET_DRAWABLE (parent))
2861     gtk_widget_queue_draw_area (parent,
2862                                 widget->allocation.x,
2863                                 widget->allocation.y,
2864                                 widget->allocation.width,
2865                                 widget->allocation.height);
2866 }
2867
2868 /**
2869  * gtk_widget_unparent:
2870  * @widget: a #GtkWidget
2871  * 
2872  * This function is only for use in widget implementations.
2873  * Should be called by implementations of the remove method
2874  * on #GtkContainer, to dissociate a child from the container.
2875  **/
2876 void
2877 gtk_widget_unparent (GtkWidget *widget)
2878 {
2879   GObjectNotifyQueue *nqueue;
2880   GtkWidget *toplevel;
2881   GtkWidget *old_parent;
2882   
2883   g_return_if_fail (GTK_IS_WIDGET (widget));
2884   if (widget->parent == NULL)
2885     return;
2886   
2887   /* keep this function in sync with gtk_menu_detach()
2888    */
2889
2890   g_object_freeze_notify (G_OBJECT (widget));
2891   nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2892
2893   toplevel = gtk_widget_get_toplevel (widget);
2894   if (GTK_WIDGET_TOPLEVEL (toplevel))
2895     _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2896
2897   if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2898     gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2899
2900   /* If we are unanchoring the child, we save around the toplevel
2901    * to emit hierarchy changed
2902    */
2903   if (GTK_WIDGET_ANCHORED (widget->parent))
2904     g_object_ref (toplevel);
2905   else
2906     toplevel = NULL;
2907
2908   gtk_widget_queue_draw_child (widget);
2909
2910   /* Reset the width and height here, to force reallocation if we
2911    * get added back to a new parent. This won't work if our new
2912    * allocation is smaller than 1x1 and we actually want a size of 1x1...
2913    * (would 0x0 be OK here?)
2914    */
2915   widget->allocation.width = 1;
2916   widget->allocation.height = 1;
2917   
2918   if (GTK_WIDGET_REALIZED (widget)) 
2919     {
2920       if (GTK_WIDGET_IN_REPARENT (widget))
2921         gtk_widget_unmap (widget);
2922       else
2923         gtk_widget_unrealize (widget);
2924     }
2925
2926   /* Removing a widget from a container restores the child visible
2927    * flag to the default state, so it doesn't affect the child
2928    * in the next parent.
2929    */
2930   GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2931     
2932   old_parent = widget->parent;
2933   widget->parent = NULL;
2934   gtk_widget_set_parent_window (widget, NULL);
2935   g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2936   if (toplevel)
2937     {
2938       _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2939       g_object_unref (toplevel);
2940     }
2941       
2942   g_object_notify (G_OBJECT (widget), "parent");
2943   g_object_thaw_notify (G_OBJECT (widget));
2944   if (!widget->parent)
2945     g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2946   g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2947   g_object_unref (widget);
2948 }
2949
2950 /**
2951  * gtk_widget_destroy:
2952  * @widget: a #GtkWidget
2953  *
2954  * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2955  * you don't have to cast the widget to #GtkObject. When a widget is
2956  * destroyed, it will break any references it holds to other objects.
2957  * If the widget is inside a container, the widget will be removed
2958  * from the container. If the widget is a toplevel (derived from
2959  * #GtkWindow), it will be removed from the list of toplevels, and the
2960  * reference GTK+ holds to it will be removed. Removing a
2961  * widget from its container or the list of toplevels results in the
2962  * widget being finalized, unless you've added additional references
2963  * to the widget with g_object_ref().
2964  *
2965  * In most cases, only toplevel widgets (windows) require explicit
2966  * destruction, because when you destroy a toplevel its children will
2967  * be destroyed as well.
2968  **/
2969 void
2970 gtk_widget_destroy (GtkWidget *widget)
2971 {
2972   g_return_if_fail (GTK_IS_WIDGET (widget));
2973
2974   gtk_object_destroy ((GtkObject*) widget);
2975 }
2976
2977 /**
2978  * gtk_widget_destroyed:
2979  * @widget: a #GtkWidget
2980  * @widget_pointer: address of a variable that contains @widget
2981  *
2982  * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2983  * %NULL.  It's intended to be used as a callback connected to the
2984  * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2985  * as a signal handler, and pass the address of your widget variable
2986  * as user data. Then when the widget is destroyed, the variable will
2987  * be set to %NULL. Useful for example to avoid multiple copies
2988  * of the same dialog.
2989  **/
2990 void
2991 gtk_widget_destroyed (GtkWidget      *widget,
2992                       GtkWidget      **widget_pointer)
2993 {
2994   /* Don't make any assumptions about the
2995    *  value of widget!
2996    *  Even check widget_pointer.
2997    */
2998   if (widget_pointer)
2999     *widget_pointer = NULL;
3000 }
3001
3002 /**
3003  * gtk_widget_show:
3004  * @widget: a #GtkWidget
3005  * 
3006  * Flags a widget to be displayed. Any widget that isn't shown will
3007  * not appear on the screen. If you want to show all the widgets in a
3008  * container, it's easier to call gtk_widget_show_all() on the
3009  * container, instead of individually showing the widgets.
3010  *
3011  * Remember that you have to show the containers containing a widget,
3012  * in addition to the widget itself, before it will appear onscreen.
3013  *
3014  * When a toplevel container is shown, it is immediately realized and
3015  * mapped; other shown widgets are realized and mapped when their
3016  * toplevel container is realized and mapped.
3017  **/
3018 void
3019 gtk_widget_show (GtkWidget *widget)
3020 {
3021   g_return_if_fail (GTK_IS_WIDGET (widget));
3022
3023   if (!GTK_WIDGET_VISIBLE (widget))
3024     {
3025       g_object_ref (widget);
3026       if (!GTK_WIDGET_TOPLEVEL (widget))
3027         gtk_widget_queue_resize (widget);
3028       g_signal_emit (widget, widget_signals[SHOW], 0);
3029       g_object_notify (G_OBJECT (widget), "visible");
3030       g_object_unref (widget);
3031     }
3032 }
3033
3034 static void
3035 gtk_widget_real_show (GtkWidget *widget)
3036 {
3037   if (!GTK_WIDGET_VISIBLE (widget))
3038     {
3039       GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3040
3041       if (widget->parent &&
3042           GTK_WIDGET_MAPPED (widget->parent) &&
3043           GTK_WIDGET_CHILD_VISIBLE (widget) &&
3044           !GTK_WIDGET_MAPPED (widget))
3045         gtk_widget_map (widget);
3046     }
3047 }
3048
3049 static void
3050 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3051 {
3052   *flag = TRUE;
3053   g_signal_handlers_disconnect_by_func (widget,
3054                                         gtk_widget_show_map_callback, 
3055                                         flag);
3056 }
3057
3058 /**
3059  * gtk_widget_show_now:
3060  * @widget: a #GtkWidget
3061  * 
3062  * Shows a widget. If the widget is an unmapped toplevel widget
3063  * (i.e. a #GtkWindow that has not yet been shown), enter the main
3064  * loop and wait for the window to actually be mapped. Be careful;
3065  * because the main loop is running, anything can happen during
3066  * this function.
3067  **/
3068 void
3069 gtk_widget_show_now (GtkWidget *widget)
3070 {
3071   gint flag = FALSE;
3072   
3073   g_return_if_fail (GTK_IS_WIDGET (widget));
3074
3075   /* make sure we will get event */
3076   if (!GTK_WIDGET_MAPPED (widget) &&
3077       GTK_WIDGET_TOPLEVEL (widget))
3078     {
3079       gtk_widget_show (widget);
3080
3081       g_signal_connect (widget, "map-event",
3082                         G_CALLBACK (gtk_widget_show_map_callback), 
3083                         &flag);
3084
3085       while (!flag)
3086         gtk_main_iteration ();
3087     }
3088   else
3089     gtk_widget_show (widget);
3090 }
3091
3092 /**
3093  * gtk_widget_hide:
3094  * @widget: a #GtkWidget
3095  * 
3096  * Reverses the effects of gtk_widget_show(), causing the widget to be
3097  * hidden (invisible to the user).
3098  **/
3099 void
3100 gtk_widget_hide (GtkWidget *widget)
3101 {
3102   g_return_if_fail (GTK_IS_WIDGET (widget));
3103   
3104   if (GTK_WIDGET_VISIBLE (widget))
3105     {
3106       GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3107       
3108       g_object_ref (widget);
3109       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3110         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3111
3112       g_signal_emit (widget, widget_signals[HIDE], 0);
3113       if (!GTK_WIDGET_TOPLEVEL (widget))
3114         gtk_widget_queue_resize (widget);
3115       g_object_notify (G_OBJECT (widget), "visible");
3116       g_object_unref (widget);
3117     }
3118 }
3119
3120 static void
3121 gtk_widget_real_hide (GtkWidget *widget)
3122 {
3123   if (GTK_WIDGET_VISIBLE (widget))
3124     {
3125       GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3126       
3127       if (GTK_WIDGET_MAPPED (widget))
3128         gtk_widget_unmap (widget);
3129     }
3130 }
3131
3132 /**
3133  * gtk_widget_hide_on_delete:
3134  * @widget: a #GtkWidget
3135  * 
3136  * Utility function; intended to be connected to the #GtkWidget::delete-event
3137  * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3138  * argument, then returns %TRUE. If connected to ::delete-event, the
3139  * result is that clicking the close button for a window (on the
3140  * window frame, top right corner usually) will hide but not destroy
3141  * the window. By default, GTK+ destroys windows when ::delete-event
3142  * is received.
3143  * 
3144  * Return value: %TRUE
3145  **/
3146 gboolean
3147 gtk_widget_hide_on_delete (GtkWidget *widget)
3148 {
3149   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3150   
3151   gtk_widget_hide (widget);
3152   
3153   return TRUE;
3154 }
3155
3156 /**
3157  * gtk_widget_show_all:
3158  * @widget: a #GtkWidget
3159  * 
3160  * Recursively shows a widget, and any child widgets (if the widget is
3161  * a container).
3162  **/
3163 void
3164 gtk_widget_show_all (GtkWidget *widget)
3165 {
3166   GtkWidgetClass *class;
3167
3168   g_return_if_fail (GTK_IS_WIDGET (widget));
3169
3170   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3171     return;
3172
3173   class = GTK_WIDGET_GET_CLASS (widget);
3174
3175   if (class->show_all)
3176     class->show_all (widget);
3177 }
3178
3179 /**
3180  * gtk_widget_hide_all:
3181  * @widget: a #GtkWidget
3182  * 
3183  * Recursively hides a widget and any child widgets.
3184  **/
3185 void
3186 gtk_widget_hide_all (GtkWidget *widget)
3187 {
3188   GtkWidgetClass *class;
3189
3190   g_return_if_fail (GTK_IS_WIDGET (widget));
3191
3192   if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3193     return;
3194
3195   class = GTK_WIDGET_GET_CLASS (widget);
3196
3197   if (class->hide_all)
3198     class->hide_all (widget);
3199 }
3200
3201 /**
3202  * gtk_widget_map:
3203  * @widget: a #GtkWidget
3204  * 
3205  * This function is only for use in widget implementations. Causes
3206  * a widget to be mapped if it isn't already.
3207  **/
3208 void
3209 gtk_widget_map (GtkWidget *widget)
3210 {
3211   g_return_if_fail (GTK_IS_WIDGET (widget));
3212   g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3213   g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3214   
3215   if (!GTK_WIDGET_MAPPED (widget))
3216     {
3217       if (!GTK_WIDGET_REALIZED (widget))
3218         gtk_widget_realize (widget);
3219
3220       g_signal_emit (widget, widget_signals[MAP], 0);
3221
3222       if (GTK_WIDGET_NO_WINDOW (widget))
3223         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3224     }
3225 }
3226
3227 /**
3228  * gtk_widget_unmap:
3229  * @widget: a #GtkWidget
3230  *
3231  * This function is only for use in widget implementations. Causes
3232  * a widget to be unmapped if it's currently mapped.
3233  **/
3234 void
3235 gtk_widget_unmap (GtkWidget *widget)
3236 {
3237   g_return_if_fail (GTK_IS_WIDGET (widget));
3238   
3239   if (GTK_WIDGET_MAPPED (widget))
3240     {
3241       if (GTK_WIDGET_NO_WINDOW (widget))
3242         gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3243       _gtk_tooltip_hide (widget);
3244       g_signal_emit (widget, widget_signals[UNMAP], 0);
3245     }
3246 }
3247
3248 static void
3249 gtk_widget_set_extension_events_internal (GtkWidget        *widget,
3250                                           GdkExtensionMode  mode,
3251                                           GList            *window_list)
3252 {
3253   GList *free_list = NULL;
3254   GList *l;
3255
3256   if (window_list == NULL)
3257     {
3258       if (!GTK_WIDGET_NO_WINDOW (widget))
3259         window_list = g_list_prepend (NULL, widget->window);
3260       else
3261         window_list = gdk_window_get_children (widget->window);
3262
3263       free_list = window_list;
3264     }
3265
3266   for (l = window_list; l != NULL; l = l->next)
3267     {
3268       GdkWindow *window = l->data;
3269       gpointer user_data;
3270
3271       gdk_window_get_user_data (window, &user_data);
3272       if (user_data == widget)
3273         {
3274           GList *children;
3275
3276           gdk_input_set_extension_events (window,
3277                                           gdk_window_get_events (window),
3278                                           mode);
3279
3280           children = gdk_window_get_children (window);
3281           if (children)
3282             {
3283               gtk_widget_set_extension_events_internal (widget, mode, children);
3284               g_list_free (children);
3285             }
3286         }
3287     }
3288
3289   if (free_list)
3290     g_list_free (free_list);
3291 }
3292
3293 /**
3294  * gtk_widget_realize:
3295  * @widget: a #GtkWidget
3296  * 
3297  * Creates the GDK (windowing system) resources associated with a
3298  * widget.  For example, @widget->window will be created when a widget
3299  * is realized.  Normally realization happens implicitly; if you show
3300  * a widget and all its parent containers, then the widget will be
3301  * realized and mapped automatically.
3302  * 
3303  * Realizing a widget requires all
3304  * the widget's parent widgets to be realized; calling
3305  * gtk_widget_realize() realizes the widget's parents in addition to
3306  * @widget itself. If a widget is not yet inside a toplevel window
3307  * when you realize it, bad things will happen.
3308  *
3309  * This function is primarily used in widget implementations, and
3310  * isn't very useful otherwise. Many times when you think you might
3311  * need it, a better approach is to connect to a signal that will be
3312  * called after the widget is realized automatically, such as
3313  * GtkWidget::expose-event. Or simply g_signal_connect () to the
3314  * GtkWidget::realize signal.
3315  **/
3316 void
3317 gtk_widget_realize (GtkWidget *widget)
3318 {
3319   GdkExtensionMode mode;
3320   GtkWidgetShapeInfo *shape_info;
3321   
3322   g_return_if_fail (GTK_IS_WIDGET (widget));
3323   g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3324                     GTK_IS_INVISIBLE (widget));
3325   
3326   if (!GTK_WIDGET_REALIZED (widget))
3327     {
3328       /*
3329         if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3330           g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3331       */
3332
3333       if (widget->parent == NULL &&
3334           !GTK_WIDGET_TOPLEVEL (widget))
3335         g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3336                    "inside a toplevel window is not going to work very well. "
3337                    "Widgets must be inside a toplevel container before realizing them.");
3338       
3339       if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3340         gtk_widget_realize (widget->parent);
3341
3342       gtk_widget_ensure_style (widget);
3343       
3344       g_signal_emit (widget, widget_signals[REALIZE], 0);
3345
3346       gtk_widget_real_set_has_tooltip (widget,
3347                                        GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3348                                        TRUE);
3349
3350       if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3351         {
3352           shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3353           gdk_window_shape_combine_mask (widget->window,
3354                                          shape_info->shape_mask,
3355                                          shape_info->offset_x,
3356                                          shape_info->offset_y);
3357         }
3358       
3359       shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3360       if (shape_info)
3361         gdk_window_input_shape_combine_mask (widget->window,
3362                                              shape_info->shape_mask,
3363                                              shape_info->offset_x,
3364                                              shape_info->offset_y);
3365
3366       mode = gtk_widget_get_extension_events (widget);
3367       if (mode != GDK_EXTENSION_EVENTS_NONE)
3368         gtk_widget_set_extension_events_internal (widget, mode, NULL);
3369     }
3370 }
3371
3372 /**
3373  * gtk_widget_unrealize:
3374  * @widget: a #GtkWidget
3375  *
3376  * This function is only useful in widget implementations.
3377  * Causes a widget to be unrealized (frees all GDK resources
3378  * associated with the widget, such as @widget->window).
3379  **/
3380 void
3381 gtk_widget_unrealize (GtkWidget *widget)
3382 {
3383   g_return_if_fail (GTK_IS_WIDGET (widget));
3384
3385   if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3386     gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3387
3388   if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3389     gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3390
3391   if (GTK_WIDGET_REALIZED (widget))
3392     {
3393       g_object_ref (widget);
3394       _gtk_tooltip_hide (widget);
3395       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3396       GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3397       g_object_unref (widget);
3398     }
3399 }
3400
3401 /*****************************************
3402  * Draw queueing.
3403  *****************************************/
3404
3405 /**
3406  * gtk_widget_queue_draw_area:
3407  * @widget: a #GtkWidget
3408  * @x: x coordinate of upper-left corner of rectangle to redraw
3409  * @y: y coordinate of upper-left corner of rectangle to redraw
3410  * @width: width of region to draw
3411  * @height: height of region to draw
3412  *
3413  * Invalidates the rectangular area of @widget defined by @x, @y,
3414  * @width and @height by calling gdk_window_invalidate_rect() on the
3415  * widget's window and all its child windows. Once the main loop
3416  * becomes idle (after the current batch of events has been processed,
3417  * roughly), the window will receive expose events for the union of
3418  * all regions that have been invalidated.
3419  *
3420  * Normally you would only use this function in widget
3421  * implementations. You might also use it, or
3422  * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3423  * #GtkDrawingArea or some portion thereof.
3424  *
3425  * Frequently you can just call gdk_window_invalidate_rect() or
3426  * gdk_window_invalidate_region() instead of this function. Those
3427  * functions will invalidate only a single window, instead of the
3428  * widget and all its children.
3429  *
3430  * The advantage of adding to the invalidated region compared to
3431  * simply drawing immediately is efficiency; using an invalid region
3432  * ensures that you only have to redraw one time.
3433  **/
3434 void       
3435 gtk_widget_queue_draw_area (GtkWidget *widget,
3436                             gint       x,
3437                             gint       y,
3438                             gint       width,
3439                             gint       height)
3440 {
3441   GdkRectangle invalid_rect;
3442   GtkWidget *w;
3443   
3444   g_return_if_fail (GTK_IS_WIDGET (widget));
3445
3446   if (!GTK_WIDGET_REALIZED (widget))
3447     return;
3448   
3449   /* Just return if the widget or one of its ancestors isn't mapped */
3450   for (w = widget; w != NULL; w = w->parent)
3451     if (!GTK_WIDGET_MAPPED (w))
3452       return;
3453
3454   /* Find the correct widget */
3455
3456   if (!GTK_WIDGET_NO_WINDOW (widget))
3457     {
3458       if (widget->parent)
3459         {
3460           /* Translate widget relative to window-relative */
3461
3462           gint wx, wy, wwidth, wheight;
3463           
3464           gdk_window_get_position (widget->window, &wx, &wy);
3465           x -= wx - widget->allocation.x;
3466           y -= wy - widget->allocation.y;
3467           
3468           gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3469
3470           if (x + width <= 0 || y + height <= 0 ||
3471               x >= wwidth || y >= wheight)
3472             return;
3473           
3474           if (x < 0)
3475             {
3476               width += x;  x = 0;
3477             }
3478           if (y < 0)
3479             {
3480               height += y; y = 0;
3481             }
3482           if (x + width > wwidth)
3483             width = wwidth - x;
3484           if (y + height > wheight)
3485             height = wheight - y;
3486         }
3487     }
3488
3489   invalid_rect.x = x;
3490   invalid_rect.y = y;
3491   invalid_rect.width = width;
3492   invalid_rect.height = height;
3493   
3494   gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3495 }
3496
3497 static void
3498 widget_add_child_draw_rectangle (GtkWidget    *widget,
3499                                  GdkRectangle *rect)
3500 {
3501   GdkRectangle child_rect;
3502   
3503   if (!GTK_WIDGET_MAPPED (widget) ||
3504       widget->window != widget->parent->window)
3505     return;
3506
3507   gtk_widget_get_draw_rectangle (widget, &child_rect);
3508   gdk_rectangle_union (rect, &child_rect, rect);
3509 }
3510
3511 static void
3512 gtk_widget_get_draw_rectangle (GtkWidget    *widget,
3513                                GdkRectangle *rect)
3514 {
3515   if (GTK_WIDGET_NO_WINDOW (widget))
3516     {
3517       GtkBorder *draw_border = NULL;
3518
3519       *rect = widget->allocation;
3520
3521       gtk_widget_style_get (widget,
3522                             "draw-border", &draw_border,
3523                             NULL);
3524       if (draw_border)
3525         {
3526           rect->x -= draw_border->left;
3527           rect->y -= draw_border->top;
3528           rect->width += draw_border->left + draw_border->right;
3529           rect->height += draw_border->top + draw_border->bottom;
3530
3531           gtk_border_free (draw_border);
3532         }
3533
3534       if (GTK_IS_CONTAINER (widget))
3535         gtk_container_forall (GTK_CONTAINER (widget),
3536                               (GtkCallback)widget_add_child_draw_rectangle,
3537                               rect);
3538     }
3539   else
3540     {
3541       rect->x = 0;
3542       rect->y = 0;
3543       rect->width = widget->allocation.width;
3544       rect->height = widget->allocation.height;
3545     }
3546 }
3547
3548 /**
3549  * gtk_widget_queue_draw:
3550  * @widget: a #GtkWidget
3551  *
3552  * Equivalent to calling gtk_widget_queue_draw_area() for the
3553  * entire area of a widget.
3554  **/
3555 void       
3556 gtk_widget_queue_draw (GtkWidget *widget)
3557 {
3558   GdkRectangle rect;
3559   
3560   g_return_if_fail (GTK_IS_WIDGET (widget));
3561
3562   gtk_widget_get_draw_rectangle (widget, &rect);
3563
3564   gtk_widget_queue_draw_area (widget,
3565                               rect.x, rect.y,
3566                               rect.width, rect.height);
3567 }
3568
3569 /* Invalidates the given area (allocation-relative-coordinates)
3570  * in all of the widget's windows
3571  */
3572 /**
3573  * gtk_widget_queue_clear_area:
3574  * @widget: a #GtkWidget
3575  * @x: x coordinate of upper-left corner of rectangle to redraw
3576  * @y: y coordinate of upper-left corner of rectangle to redraw
3577  * @width: width of region to draw
3578  * @height: height of region to draw
3579  * 
3580  * This function is no longer different from
3581  * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3582  * gtk_widget_queue_draw_area(). Originally
3583  * gtk_widget_queue_clear_area() would force a redraw of the
3584  * background for %GTK_NO_WINDOW widgets, and
3585  * gtk_widget_queue_draw_area() would not. Now both functions ensure
3586  * the background will be redrawn.
3587  * 
3588  * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3589  **/
3590 void       
3591 gtk_widget_queue_clear_area (GtkWidget *widget,
3592                              gint       x,
3593                              gint       y,
3594                              gint       width,
3595                              gint       height)
3596 {
3597   g_return_if_fail (GTK_IS_WIDGET (widget));
3598
3599   gtk_widget_queue_draw_area (widget, x, y, width, height);
3600 }
3601
3602 /**
3603  * gtk_widget_queue_clear:
3604  * @widget: a #GtkWidget
3605  * 
3606  * This function does the same as gtk_widget_queue_draw().
3607  *
3608  * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3609  **/
3610 void       
3611 gtk_widget_queue_clear (GtkWidget *widget)
3612 {
3613   g_return_if_fail (GTK_IS_WIDGET (widget));
3614
3615   gtk_widget_queue_draw (widget);
3616 }
3617
3618 /**
3619  * gtk_widget_queue_resize:
3620  * @widget: a #GtkWidget
3621  *
3622  * This function is only for use in widget implementations.
3623  * Flags a widget to have its size renegotiated; should
3624  * be called when a widget for some reason has a new size request.
3625  * For example, when you change the text in a #GtkLabel, #GtkLabel
3626  * queues a resize to ensure there's enough space for the new text.
3627  **/
3628 void
3629 gtk_widget_queue_resize (GtkWidget *widget)
3630 {
3631   g_return_if_fail (GTK_IS_WIDGET (widget));
3632
3633   if (GTK_WIDGET_REALIZED (widget))
3634     gtk_widget_queue_shallow_draw (widget);
3635       
3636   _gtk_size_group_queue_resize (widget);
3637 }
3638
3639 /**
3640  * gtk_widget_queue_resize_no_redraw:
3641  * @widget: a #GtkWidget
3642  *
3643  * This function works like gtk_widget_queue_resize(), 
3644  * except that the widget is not invalidated.
3645  *
3646  * Since: 2.4
3647  **/
3648 void
3649 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3650 {
3651   g_return_if_fail (GTK_IS_WIDGET (widget));
3652
3653   _gtk_size_group_queue_resize (widget);
3654 }
3655
3656 /**
3657  * gtk_widget_draw:
3658  * @widget: a #GtkWidget
3659  * @area: area to draw
3660  *
3661  * In GTK+ 1.2, this function would immediately render the
3662  * region @area of a widget, by invoking the virtual draw method of a
3663  * widget. In GTK+ 2.0, the draw method is gone, and instead
3664  * gtk_widget_draw() simply invalidates the specified region of the
3665  * widget, then updates the invalid region of the widget immediately.
3666  * Usually you don't want to update the region immediately for
3667  * performance reasons, so in general gtk_widget_queue_draw_area() is
3668  * a better choice if you want to draw a region of a widget.
3669  **/
3670 void
3671 gtk_widget_draw (GtkWidget          *widget,
3672                  const GdkRectangle *area)
3673 {
3674   g_return_if_fail (GTK_IS_WIDGET (widget));
3675
3676   if (GTK_WIDGET_DRAWABLE (widget))
3677     {
3678       if (area)
3679         gtk_widget_queue_draw_area (widget,
3680                                     area->x, area->y,
3681                                     area->width, area->height);
3682       else
3683         gtk_widget_queue_draw (widget);
3684
3685       gdk_window_process_updates (widget->window, TRUE);
3686     }
3687 }
3688
3689 /**
3690  * gtk_widget_size_request:
3691  * @widget: a #GtkWidget
3692  * @requisition: a #GtkRequisition to be filled in
3693  * 
3694  * This function is typically used when implementing a #GtkContainer
3695  * subclass.  Obtains the preferred size of a widget. The container
3696  * uses this information to arrange its child widgets and decide what
3697  * size allocations to give them with gtk_widget_size_allocate().
3698  *
3699  * You can also call this function from an application, with some
3700  * caveats. Most notably, getting a size request requires the widget
3701  * to be associated with a screen, because font information may be
3702  * needed. Multihead-aware applications should keep this in mind.
3703  *
3704  * Also remember that the size request is not necessarily the size
3705  * a widget will actually be allocated.
3706  *
3707  * See also gtk_widget_get_child_requisition().
3708  **/
3709 void
3710 gtk_widget_size_request (GtkWidget      *widget,
3711                          GtkRequisition *requisition)
3712 {
3713   g_return_if_fail (GTK_IS_WIDGET (widget));
3714
3715 #ifdef G_ENABLE_DEBUG
3716   if (requisition == &widget->requisition)
3717     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.");
3718 #endif /* G_ENABLE_DEBUG */
3719
3720   _gtk_size_group_compute_requisition (widget, requisition);
3721 }
3722
3723 /**
3724  * gtk_widget_get_child_requisition:
3725  * @widget: a #GtkWidget
3726  * @requisition: a #GtkRequisition to be filled in
3727  * 
3728  * This function is only for use in widget implementations. Obtains
3729  * @widget->requisition, unless someone has forced a particular
3730  * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3731  * in which case it returns that geometry instead of the widget's
3732  * requisition.
3733  *
3734  * This function differs from gtk_widget_size_request() in that
3735  * it retrieves the last size request value from @widget->requisition,
3736  * while gtk_widget_size_request() actually calls the "size_request" method
3737  * on @widget to compute the size request and fill in @widget->requisition,
3738  * and only then returns @widget->requisition.
3739  *
3740  * Because this function does not call the "size_request" method, it
3741  * can only be used when you know that @widget->requisition is
3742  * up-to-date, that is, gtk_widget_size_request() has been called
3743  * since the last time a resize was queued. In general, only container
3744  * implementations have this information; applications should use
3745  * gtk_widget_size_request().
3746  **/
3747 void
3748 gtk_widget_get_child_requisition (GtkWidget      *widget,
3749                                   GtkRequisition *requisition)
3750 {
3751   _gtk_size_group_get_child_requisition (widget, requisition);
3752 }
3753
3754 static gboolean
3755 invalidate_predicate (GdkWindow *window,
3756                       gpointer   data)
3757 {
3758   gpointer user_data;
3759
3760   gdk_window_get_user_data (window, &user_data);
3761
3762   return (user_data == data);
3763 }
3764
3765 /* Invalidate @region in widget->window and all children
3766  * of widget->window owned by widget. @region is in the
3767  * same coordinates as widget->allocation and will be
3768  * modified by this call.
3769  */
3770 static void
3771 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3772                                       GdkRegion *region)
3773 {
3774   if (!GTK_WIDGET_REALIZED (widget))
3775     return;
3776   
3777   if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3778     {
3779       int x, y;
3780       
3781       gdk_window_get_position (widget->window, &x, &y);
3782       gdk_region_offset (region, -x, -y);
3783     }
3784
3785   gdk_window_invalidate_maybe_recurse (widget->window, region,
3786                                        invalidate_predicate, widget);
3787 }
3788
3789 /**
3790  * gtk_widget_queue_shallow_draw:
3791  * @widget: a #GtkWidget
3792  *
3793  * Like gtk_widget_queue_draw(), but only windows owned
3794  * by @widget are invalidated.
3795  **/
3796 static void
3797 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3798 {
3799   GdkRectangle rect;
3800   GdkRegion *region;
3801   
3802   if (!GTK_WIDGET_REALIZED (widget))
3803     return;
3804
3805   gtk_widget_get_draw_rectangle (widget, &rect);
3806
3807   /* get_draw_rectangle() gives us window coordinates, we
3808    * need to convert to the coordinates that widget->allocation
3809    * is in.
3810    */
3811   if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3812     {
3813       int wx, wy;
3814       
3815       gdk_window_get_position (widget->window, &wx, &wy);
3816       
3817       rect.x += wx;
3818       rect.y += wy;
3819     }
3820   
3821   region = gdk_region_rectangle (&rect);
3822   gtk_widget_invalidate_widget_windows (widget, region);
3823   gdk_region_destroy (region);
3824 }
3825
3826 /**
3827  * gtk_widget_size_allocate:
3828  * @widget: a #GtkWidget
3829  * @allocation: position and size to be allocated to @widget
3830  *
3831  * This function is only used by #GtkContainer subclasses, to assign a size
3832  * and position to their child widgets. 
3833  **/
3834 void
3835 gtk_widget_size_allocate (GtkWidget     *widget,
3836                           GtkAllocation *allocation)
3837 {
3838   GtkWidgetAuxInfo *aux_info;
3839   GdkRectangle real_allocation;
3840   GdkRectangle old_allocation;
3841   gboolean alloc_needed;
3842   gboolean size_changed;
3843   gboolean position_changed;
3844   
3845   g_return_if_fail (GTK_IS_WIDGET (widget));
3846  
3847 #ifdef G_ENABLE_DEBUG
3848   if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3849     {
3850       gint depth;
3851       GtkWidget *parent;
3852       const gchar *name;
3853
3854       depth = 0;
3855       parent = widget;
3856       while (parent)
3857         {
3858           depth++;
3859           parent = gtk_widget_get_parent (parent);
3860         }
3861       
3862       name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3863       g_print ("gtk_widget_size_allocate: %*s%s %d %d\n", 
3864                2 * depth, " ", name, 
3865                allocation->width, allocation->height);
3866     }
3867 #endif /* G_ENABLE_DEBUG */
3868  
3869   alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3870   if (!GTK_WIDGET_REQUEST_NEEDED (widget))      /* Preserve request/allocate ordering */
3871     GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3872
3873   old_allocation = widget->allocation;
3874   real_allocation = *allocation;
3875   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3876   
3877   if (aux_info)
3878     {
3879       if (aux_info->x_set)
3880         real_allocation.x = aux_info->x;
3881       if (aux_info->y_set)
3882         real_allocation.y = aux_info->y;
3883     }
3884
3885   if (real_allocation.width < 0 || real_allocation.height < 0)
3886     {
3887       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3888                  real_allocation.width,
3889                  real_allocation.height);
3890     }
3891   
3892   real_allocation.width = MAX (real_allocation.width, 1);
3893   real_allocation.height = MAX (real_allocation.height, 1);
3894
3895   size_changed = (old_allocation.width != real_allocation.width ||
3896                   old_allocation.height != real_allocation.height);
3897   position_changed = (old_allocation.x != real_allocation.x ||
3898                       old_allocation.y != real_allocation.y);
3899
3900   if (!alloc_needed && !size_changed && !position_changed)
3901     return;
3902   
3903   g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3904
3905   if (GTK_WIDGET_MAPPED (widget))
3906     {
3907       if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3908         {
3909           /* Invalidate union(old_allaction,widget->allocation) in widget->window
3910            */
3911           GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3912           gdk_region_union_with_rect (invalidate, &old_allocation);
3913
3914           gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3915           gdk_region_destroy (invalidate);
3916         }
3917       
3918       if (size_changed)
3919         {
3920           if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3921             {
3922               /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3923                */
3924               GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3925               gdk_region_union_with_rect (invalidate, &old_allocation);
3926
3927               gtk_widget_invalidate_widget_windows (widget, invalidate);
3928               gdk_region_destroy (invalidate);
3929             }
3930         }
3931     }
3932
3933   if ((size_changed || position_changed) && widget->parent &&
3934       GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3935     {
3936       GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3937       gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3938       gdk_region_destroy (invalidate);
3939     }
3940 }
3941
3942 /**
3943  * gtk_widget_common_ancestor:
3944  * @widget_a: a #GtkWidget
3945  * @widget_b: a #GtkWidget
3946  * 
3947  * Find the common ancestor of @widget_a and @widget_b that
3948  * is closest to the two widgets.
3949  * 
3950  * Return value: the closest common ancestor of @widget_a and
3951  *   @widget_b or %NULL if @widget_a and @widget_b do not
3952  *   share a common ancestor.
3953  **/
3954 static GtkWidget *
3955 gtk_widget_common_ancestor (GtkWidget *widget_a,
3956                             GtkWidget *widget_b)
3957 {
3958   GtkWidget *parent_a;
3959   GtkWidget *parent_b;
3960   gint depth_a = 0;
3961   gint depth_b = 0;
3962
3963   parent_a = widget_a;
3964   while (parent_a->parent)
3965     {
3966       parent_a = parent_a->parent;
3967       depth_a++;
3968     }
3969
3970   parent_b = widget_b;
3971   while (parent_b->parent)
3972     {
3973       parent_b = parent_b->parent;
3974       depth_b++;
3975     }
3976
3977   if (parent_a != parent_b)
3978     return NULL;
3979
3980   while (depth_a > depth_b)
3981     {
3982       widget_a = widget_a->parent;
3983       depth_a--;
3984     }
3985
3986   while (depth_b > depth_a)
3987     {
3988       widget_b = widget_b->parent;
3989       depth_b--;
3990     }
3991
3992   while (widget_a != widget_b)
3993     {
3994       widget_a = widget_a->parent;
3995       widget_b = widget_b->parent;
3996     }
3997
3998   return widget_a;
3999 }
4000
4001 /**
4002  * gtk_widget_translate_coordinates:
4003  * @src_widget:  a #GtkWidget
4004  * @dest_widget: a #GtkWidget
4005  * @src_x: X position relative to @src_widget
4006  * @src_y: Y position relative to @src_widget
4007  * @dest_x: location to store X position relative to @dest_widget
4008  * @dest_y: location to store Y position relative to @dest_widget
4009  * 
4010  * Translate coordinates relative to @src_widget's allocation to coordinates
4011  * relative to @dest_widget's allocations. In order to perform this
4012  * operation, both widgets must be realized, and must share a common
4013  * toplevel.
4014  * 
4015  * Return value: %FALSE if either widget was not realized, or there
4016  *   was no common ancestor. In this case, nothing is stored in
4017  *   *@dest_x and *@dest_y. Otherwise %TRUE.
4018  **/
4019 gboolean
4020 gtk_widget_translate_coordinates (GtkWidget  *src_widget,
4021                                   GtkWidget  *dest_widget,
4022                                   gint        src_x,
4023                                   gint        src_y,
4024                                   gint       *dest_x,
4025                                   gint       *dest_y)
4026 {
4027   GtkWidget *ancestor;
4028   GdkWindow *window;
4029
4030   g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4031   g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4032
4033   ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4034   if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4035     return FALSE;
4036
4037   /* Translate from allocation relative to window relative */
4038   if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4039     {
4040       gint wx, wy;
4041       gdk_window_get_position (src_widget->window, &wx, &wy);
4042
4043       src_x -= wx - src_widget->allocation.x;
4044       src_y -= wy - src_widget->allocation.y;
4045     }
4046   else
4047     {
4048       src_x += src_widget->allocation.x;
4049       src_y += src_widget->allocation.y;
4050     }
4051
4052   /* Translate to the common ancestor */
4053   window = src_widget->window;
4054   while (window != ancestor->window)
4055     {
4056       gint dx, dy;
4057       
4058       gdk_window_get_position (window, &dx, &dy);
4059       
4060       src_x += dx;
4061       src_y += dy;
4062       
4063       window = gdk_window_get_parent (window);
4064
4065       if (!window)              /* Handle GtkHandleBox */
4066         return FALSE;
4067     }
4068
4069   /* And back */
4070   window = dest_widget->window;
4071   while (window != ancestor->window)
4072     {
4073       gint dx, dy;
4074       
4075       gdk_window_get_position (window, &dx, &dy);
4076       
4077       src_x -= dx;
4078       src_y -= dy;
4079       
4080       window = gdk_window_get_parent (window);
4081       
4082       if (!window)              /* Handle GtkHandleBox */
4083         return FALSE;
4084     }
4085
4086   /* Translate from window relative to allocation relative */
4087   if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4088     {
4089       gint wx, wy;
4090       gdk_window_get_position (dest_widget->window, &wx, &wy);
4091
4092       src_x += wx - dest_widget->allocation.x;
4093       src_y += wy - dest_widget->allocation.y;
4094     }
4095   else
4096     {
4097       src_x -= dest_widget->allocation.x;
4098       src_y -= dest_widget->allocation.y;
4099     }
4100
4101   if (dest_x)
4102     *dest_x = src_x;
4103   if (dest_y)
4104     *dest_y = src_y;
4105
4106   return TRUE;
4107 }
4108
4109 static void
4110 gtk_widget_real_size_allocate (GtkWidget     *widget,
4111                                GtkAllocation *allocation)
4112 {
4113   widget->allocation = *allocation;
4114   
4115   if (GTK_WIDGET_REALIZED (widget) &&
4116       !GTK_WIDGET_NO_WINDOW (widget))
4117      {
4118         gdk_window_move_resize (widget->window,
4119                                 allocation->x, allocation->y,
4120                                 allocation->width, allocation->height);
4121      }
4122 }
4123
4124 static gboolean
4125 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4126                                     guint      signal_id)
4127 {
4128   /* widgets must be onscreen for accels to take effect */
4129   return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4130 }
4131
4132 /**
4133  * gtk_widget_can_activate_accel:
4134  * @widget: a #GtkWidget
4135  * @signal_id: the ID of a signal installed on @widget
4136  * 
4137  * Determines whether an accelerator that activates the signal
4138  * identified by @signal_id can currently be activated.
4139  * This is done by emitting the #GtkWidget::can-activate-accel
4140  * signal on @widget; if the signal isn't overridden by a
4141  * handler or in a derived widget, then the default check is
4142  * that the widget must be sensitive, and the widget and all
4143  * its ancestors mapped.
4144  *
4145  * Return value: %TRUE if the accelerator can be activated.
4146  *
4147  * Since: 2.4
4148  **/
4149 gboolean
4150 gtk_widget_can_activate_accel (GtkWidget *widget,
4151                                guint      signal_id)
4152 {
4153   gboolean can_activate = FALSE;
4154   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4155   g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4156   return can_activate;
4157 }
4158
4159 typedef struct {
4160   GClosure   closure;
4161   guint      signal_id;
4162 } AccelClosure;
4163
4164 static void
4165 closure_accel_activate (GClosure     *closure,
4166                         GValue       *return_value,
4167                         guint         n_param_values,
4168                         const GValue *param_values,
4169                         gpointer      invocation_hint,
4170                         gpointer      marshal_data)
4171 {
4172   AccelClosure *aclosure = (AccelClosure*) closure;
4173   gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4174
4175   if (can_activate)
4176     g_signal_emit (closure->data, aclosure->signal_id, 0);
4177
4178   /* whether accelerator was handled */
4179   g_value_set_boolean (return_value, can_activate);
4180 }
4181
4182 static void
4183 closures_destroy (gpointer data)
4184 {
4185   GSList *slist, *closures = data;
4186
4187   for (slist = closures; slist; slist = slist->next)
4188     {
4189       g_closure_invalidate (slist->data);
4190       g_closure_unref (slist->data);
4191     }
4192   g_slist_free (closures);
4193 }
4194
4195 static GClosure*
4196 widget_new_accel_closure (GtkWidget *widget,
4197                           guint      signal_id)
4198 {
4199   AccelClosure *aclosure;
4200   GClosure *closure = NULL;
4201   GSList *slist, *closures;
4202
4203   closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4204   for (slist = closures; slist; slist = slist->next)
4205     if (!gtk_accel_group_from_accel_closure (slist->data))
4206       {
4207         /* reuse this closure */
4208         closure = slist->data;
4209         break;
4210       }
4211   if (!closure)
4212     {
4213       closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4214       closures = g_slist_prepend (closures, g_closure_ref (closure));
4215       g_closure_sink (closure);
4216       g_closure_set_marshal (closure, closure_accel_activate);
4217     }
4218   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4219   
4220   aclosure = (AccelClosure*) closure;
4221   g_assert (closure->data == widget);
4222   g_assert (closure->marshal == closure_accel_activate);
4223   aclosure->signal_id = signal_id;
4224
4225   return closure;
4226 }
4227
4228 /**
4229  * gtk_widget_add_accelerator
4230  * @widget:       widget to install an accelerator on
4231  * @accel_signal: widget signal to emit on accelerator activation
4232  * @accel_group:  accel group for this widget, added to its toplevel
4233  * @accel_key:    GDK keyval of the accelerator
4234  * @accel_mods:   modifier key combination of the accelerator
4235  * @accel_flags:  flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4236  *
4237  * Installs an accelerator for this @widget in @accel_group that causes
4238  * @accel_signal to be emitted if the accelerator is activated.
4239  * The @accel_group needs to be added to the widget's toplevel via
4240  * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4241  * Accelerators added through this function are not user changeable during
4242  * runtime. If you want to support accelerators that can be changed by the
4243  * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4244  * gtk_menu_item_set_accel_path() instead.
4245  */
4246 void
4247 gtk_widget_add_accelerator (GtkWidget      *widget,
4248                             const gchar    *accel_signal,
4249                             GtkAccelGroup  *accel_group,
4250                             guint           accel_key,
4251                             GdkModifierType accel_mods,
4252                             GtkAccelFlags   accel_flags)
4253 {
4254   GClosure *closure;
4255   GSignalQuery query;
4256
4257   g_return_if_fail (GTK_IS_WIDGET (widget));
4258   g_return_if_fail (accel_signal != NULL);
4259   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4260
4261   g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4262   if (!query.signal_id ||
4263       !(query.signal_flags & G_SIGNAL_ACTION) ||
4264       query.return_type != G_TYPE_NONE ||
4265       query.n_params)
4266     {
4267       /* hmm, should be elaborate enough */
4268       g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4269                  G_OBJECT_TYPE_NAME (widget), accel_signal);
4270       return;
4271     }
4272
4273   closure = widget_new_accel_closure (widget, query.signal_id);
4274
4275   g_object_ref (widget);
4276
4277   /* install the accelerator. since we don't map this onto an accel_path,
4278    * the accelerator will automatically be locked.
4279    */
4280   gtk_accel_group_connect (accel_group,
4281                            accel_key,
4282                            accel_mods,
4283                            accel_flags | GTK_ACCEL_LOCKED,
4284                            closure);
4285
4286   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4287
4288   g_object_unref (widget);
4289 }
4290
4291 /**
4292  * gtk_widget_remove_accelerator:
4293  * @widget:       widget to install an accelerator on
4294  * @accel_group:  accel group for this widget
4295  * @accel_key:    GDK keyval of the accelerator
4296  * @accel_mods:   modifier key combination of the accelerator
4297  * @returns:      whether an accelerator was installed and could be removed
4298  *
4299  * Removes an accelerator from @widget, previously installed with
4300  * gtk_widget_add_accelerator().
4301  */
4302 gboolean
4303 gtk_widget_remove_accelerator (GtkWidget      *widget,
4304                                GtkAccelGroup  *accel_group,
4305                                guint           accel_key,
4306                                GdkModifierType accel_mods)
4307 {
4308   GtkAccelGroupEntry *ag_entry;
4309   GList *slist, *clist;
4310   guint n;
4311   
4312   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4313   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4314
4315   ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4316   clist = gtk_widget_list_accel_closures (widget);
4317   for (slist = clist; slist; slist = slist->next)
4318     {
4319       guint i;
4320
4321       for (i = 0; i < n; i++)
4322         if (slist->data == (gpointer) ag_entry[i].closure)
4323           {
4324             gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4325
4326             g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4327
4328             g_list_free (clist);
4329
4330             return is_removed;
4331           }
4332     }
4333   g_list_free (clist);
4334
4335   g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4336              accel_key, accel_mods, accel_group,
4337              G_OBJECT_TYPE_NAME (widget), widget);
4338
4339   return FALSE;
4340 }
4341
4342 /**
4343  * gtk_widget_list_accel_closures
4344  * @widget:  widget to list accelerator closures for
4345  * @returns: a newly allocated #GList of closures
4346  *
4347  * Lists the closures used by @widget for accelerator group connections
4348  * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4349  * The closures can be used to monitor accelerator changes on @widget,
4350  * by connecting to the @GtkAccelGroup::accel-changed signal of the 
4351  * #GtkAccelGroup of a closure which can be found out with 
4352  * gtk_accel_group_from_accel_closure().
4353  */
4354 GList*
4355 gtk_widget_list_accel_closures (GtkWidget *widget)
4356 {
4357   GSList *slist;
4358   GList *clist = NULL;
4359
4360   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4361
4362   for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4363     if (gtk_accel_group_from_accel_closure (slist->data))
4364       clist = g_list_prepend (clist, slist->data);
4365   return clist;
4366 }
4367
4368 typedef struct {
4369   GQuark         path_quark;
4370   GtkAccelGroup *accel_group;
4371   GClosure      *closure;
4372 } AccelPath;
4373
4374 static void
4375 destroy_accel_path (gpointer data)
4376 {
4377   AccelPath *apath = data;
4378
4379   gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4380
4381   /* closures_destroy takes care of unrefing the closure */
4382   g_object_unref (apath->accel_group);
4383   
4384   g_slice_free (AccelPath, apath);
4385 }
4386
4387
4388 /**
4389  * gtk_widget_set_accel_path:
4390  * @widget: a #GtkWidget
4391  * @accel_path: path used to look up the accelerator
4392  * @accel_group: a #GtkAccelGroup.
4393  * 
4394  * Given an accelerator group, @accel_group, and an accelerator path,
4395  * @accel_path, sets up an accelerator in @accel_group so whenever the
4396  * key binding that is defined for @accel_path is pressed, @widget
4397  * will be activated.  This removes any accelerators (for any
4398  * accelerator group) installed by previous calls to
4399  * gtk_widget_set_accel_path(). Associating accelerators with
4400  * paths allows them to be modified by the user and the modifications
4401  * to be saved for future use. (See gtk_accel_map_save().)
4402  *
4403  * This function is a low level function that would most likely
4404  * be used by a menu creation system like #GtkUIManager. If you
4405  * use #GtkUIManager, setting up accelerator paths will be done
4406  * automatically.
4407  *
4408  * Even when you you aren't using #GtkUIManager, if you only want to
4409  * set up accelerators on menu items gtk_menu_item_set_accel_path()
4410  * provides a somewhat more convenient interface.
4411  * 
4412  * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4413  * pass a static string, you can save some memory by interning it first with 
4414  * g_intern_static_string().
4415  **/
4416 void
4417 gtk_widget_set_accel_path (GtkWidget     *widget,
4418                            const gchar   *accel_path,
4419                            GtkAccelGroup *accel_group)
4420 {
4421   AccelPath *apath;
4422
4423   g_return_if_fail (GTK_IS_WIDGET (widget));
4424   g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4425
4426   if (accel_path)
4427     {
4428       g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4429       g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4430
4431       gtk_accel_map_add_entry (accel_path, 0, 0);
4432       apath = g_slice_new (AccelPath);
4433       apath->accel_group = g_object_ref (accel_group);
4434       apath->path_quark = g_quark_from_string (accel_path);
4435       apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4436     }
4437   else
4438     apath = NULL;
4439
4440   /* also removes possible old settings */
4441   g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4442
4443   if (apath)
4444     gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4445
4446   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4447 }
4448
4449 const gchar*
4450 _gtk_widget_get_accel_path (GtkWidget *widget,
4451                             gboolean  *locked)
4452 {
4453   AccelPath *apath;
4454
4455   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4456
4457   apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4458   if (locked)
4459     *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4460   return apath ? g_quark_to_string (apath->path_quark) : NULL;
4461 }
4462
4463 /**
4464  * gtk_widget_mnemonic_activate:
4465  * @widget: a #GtkWidget
4466  * @group_cycling:  %TRUE if there are other widgets with the same mnemonic
4467  *
4468  * Emits the #GtkWidget::mnemonic-activate signal.
4469  * 
4470  * The default handler for this signal activates the @widget if
4471  * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4472  * is %TRUE.
4473  *
4474  * Returns: %TRUE if the signal has been handled
4475  */
4476 gboolean
4477 gtk_widget_mnemonic_activate (GtkWidget *widget,
4478                               gboolean   group_cycling)
4479 {
4480   gboolean handled;
4481   
4482   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4483
4484   group_cycling = group_cycling != FALSE;
4485   if (!GTK_WIDGET_IS_SENSITIVE (widget))
4486     handled = TRUE;
4487   else
4488     g_signal_emit (widget,
4489                    widget_signals[MNEMONIC_ACTIVATE],
4490                    0,
4491                    group_cycling,
4492                    &handled);
4493   return handled;
4494 }
4495
4496 static gboolean
4497 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4498                                    gboolean   group_cycling)
4499 {
4500   if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4501     gtk_widget_activate (widget);
4502   else if (GTK_WIDGET_CAN_FOCUS (widget))
4503     gtk_widget_grab_focus (widget);
4504   else
4505     {
4506       g_warning ("widget `%s' isn't suitable for mnemonic activation",
4507                  G_OBJECT_TYPE_NAME (widget));
4508       gtk_widget_error_bell (widget);
4509     }
4510   return TRUE;
4511 }
4512
4513 static gboolean
4514 gtk_widget_real_key_press_event (GtkWidget         *widget,
4515                                  GdkEventKey       *event)
4516 {
4517   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4518 }
4519
4520 static gboolean
4521 gtk_widget_real_key_release_event (GtkWidget         *widget,
4522                                    GdkEventKey       *event)
4523 {
4524   return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4525 }
4526
4527 static gboolean
4528 gtk_widget_real_focus_in_event (GtkWidget     *widget,
4529                                 GdkEventFocus *event)
4530 {
4531   gtk_widget_queue_shallow_draw (widget);
4532
4533   return FALSE;
4534 }
4535
4536 static gboolean
4537 gtk_widget_real_focus_out_event (GtkWidget     *widget,
4538                                  GdkEventFocus *event)
4539 {
4540   gtk_widget_queue_shallow_draw (widget);
4541
4542   return FALSE;
4543 }
4544
4545 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4546      (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4547
4548 /**
4549  * gtk_widget_event:
4550  * @widget: a #GtkWidget
4551  * @event: a #GdkEvent
4552  * 
4553  * Rarely-used function. This function is used to emit
4554  * the event signals on a widget (those signals should never
4555  * be emitted without using this function to do so).
4556  * If you want to synthesize an event though, don't use this function;
4557  * instead, use gtk_main_do_event() so the event will behave as if
4558  * it were in the event queue. Don't synthesize expose events; instead,
4559  * use gdk_window_invalidate_rect() to invalidate a region of the
4560  * window.
4561  * 
4562  * Return value: return from the event signal emission (%TRUE if 
4563  *               the event was handled)
4564  **/
4565 gboolean
4566 gtk_widget_event (GtkWidget *widget,
4567                   GdkEvent  *event)
4568 {
4569   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4570   g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4571
4572   if (event->type == GDK_EXPOSE)
4573     {
4574       g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4575                  "the same effect, call gdk_window_invalidate_rect/region(), "
4576                  "followed by gdk_window_process_updates().");
4577       return TRUE;
4578     }
4579   
4580   return gtk_widget_event_internal (widget, event);
4581 }
4582
4583
4584 /**
4585  * gtk_widget_send_expose:
4586  * @widget: a #GtkWidget
4587  * @event: a expose #GdkEvent
4588  * 
4589  * Very rarely-used function. This function is used to emit
4590  * an expose event signals on a widget. This function is not
4591  * normally used directly. The only time it is used is when
4592  * propagating an expose event to a child %NO_WINDOW widget, and
4593  * that is normally done using gtk_container_propagate_expose().
4594  *
4595  * If you want to force an area of a window to be redrawn, 
4596  * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4597  * To cause the redraw to be done immediately, follow that call
4598  * with a call to gdk_window_process_updates().
4599  * 
4600  * Return value: return from the event signal emission (%TRUE if 
4601  *               the event was handled)
4602  **/
4603 gint
4604 gtk_widget_send_expose (GtkWidget *widget,
4605                         GdkEvent  *event)
4606 {
4607   g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4608   g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4609   g_return_val_if_fail (event != NULL, TRUE);
4610   g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4611
4612   return gtk_widget_event_internal (widget, event);
4613 }
4614
4615 static gboolean
4616 event_window_is_still_viewable (GdkEvent *event)
4617 {
4618   /* Some programs, such as gnome-theme-manager, fake widgets
4619    * into exposing onto a pixmap by sending expose events with
4620    * event->window pointing to a pixmap
4621    */
4622   if (GDK_IS_PIXMAP (event->any.window))
4623     return event->type == GDK_EXPOSE;
4624   
4625   /* Check that we think the event's window is viewable before
4626    * delivering the event, to prevent suprises. We do this here
4627    * at the last moment, since the event may have been queued
4628    * up behind other events, held over a recursive main loop, etc.
4629    */
4630   switch (event->type)
4631     {
4632     case GDK_EXPOSE:
4633     case GDK_MOTION_NOTIFY:
4634     case GDK_BUTTON_PRESS:
4635     case GDK_2BUTTON_PRESS:
4636     case GDK_3BUTTON_PRESS:
4637     case GDK_KEY_PRESS:
4638     case GDK_ENTER_NOTIFY:
4639     case GDK_PROXIMITY_IN:
4640     case GDK_SCROLL:
4641       return event->any.window && gdk_window_is_viewable (event->any.window);
4642
4643 #if 0
4644     /* The following events are the second half of paired events;
4645      * we always deliver them to deal with widgets that clean up
4646      * on the second half.
4647      */
4648     case GDK_BUTTON_RELEASE:
4649     case GDK_KEY_RELEASE:
4650     case GDK_LEAVE_NOTIFY:
4651     case GDK_PROXIMITY_OUT:
4652 #endif      
4653       
4654     default:
4655       /* Remaining events would make sense on an not-viewable window,
4656        * or don't have an associated window.
4657        */
4658       return TRUE;
4659     }
4660 }
4661
4662 static gint
4663 gtk_widget_event_internal (GtkWidget *widget,
4664                            GdkEvent  *event)
4665 {
4666   gboolean return_val = FALSE;
4667
4668   /* We check only once for is-still-visible; if someone
4669    * hides the window in on of the signals on the widget,
4670    * they are responsible for returning TRUE to terminate
4671    * handling.
4672    */
4673   if (!event_window_is_still_viewable (event))
4674     return TRUE;
4675
4676   g_object_ref (widget);
4677
4678   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4679   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4680   if (!return_val)
4681     {
4682       gint signal_num;
4683
4684       switch (event->type)
4685         {
4686         case GDK_NOTHING:
4687           signal_num = -1;
4688           break;
4689         case GDK_BUTTON_PRESS:
4690         case GDK_2BUTTON_PRESS:
4691         case GDK_3BUTTON_PRESS:
4692           signal_num = BUTTON_PRESS_EVENT;
4693           break;
4694         case GDK_SCROLL:
4695           signal_num = SCROLL_EVENT;
4696           break;
4697         case GDK_BUTTON_RELEASE:
4698           signal_num = BUTTON_RELEASE_EVENT;
4699           break;
4700         case GDK_MOTION_NOTIFY:
4701           signal_num = MOTION_NOTIFY_EVENT;
4702           break;
4703         case GDK_DELETE:
4704           signal_num = DELETE_EVENT;
4705           break;
4706         case GDK_DESTROY:
4707           signal_num = DESTROY_EVENT;
4708           _gtk_tooltip_hide (widget);
4709           break;
4710         case GDK_KEY_PRESS:
4711           signal_num = KEY_PRESS_EVENT;
4712           break;
4713         case GDK_KEY_RELEASE:
4714           signal_num = KEY_RELEASE_EVENT;
4715           break;
4716         case GDK_ENTER_NOTIFY:
4717           signal_num = ENTER_NOTIFY_EVENT;
4718           break;
4719         case GDK_LEAVE_NOTIFY:
4720           signal_num = LEAVE_NOTIFY_EVENT;
4721           break;
4722         case GDK_FOCUS_CHANGE:
4723           signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4724           if (event->focus_change.in)
4725             _gtk_tooltip_focus_in (widget);
4726           else
4727             _gtk_tooltip_focus_out (widget);
4728           break;
4729         case GDK_CONFIGURE:
4730           signal_num = CONFIGURE_EVENT;
4731           break;
4732         case GDK_MAP:
4733           signal_num = MAP_EVENT;
4734           break;
4735         case GDK_UNMAP:
4736           signal_num = UNMAP_EVENT;
4737           break;
4738         case GDK_WINDOW_STATE:
4739           signal_num = WINDOW_STATE_EVENT;
4740           break;
4741         case GDK_PROPERTY_NOTIFY:
4742           signal_num = PROPERTY_NOTIFY_EVENT;
4743           break;
4744         case GDK_SELECTION_CLEAR:
4745           signal_num = SELECTION_CLEAR_EVENT;
4746           break;
4747         case GDK_SELECTION_REQUEST:
4748           signal_num = SELECTION_REQUEST_EVENT;
4749           break;
4750         case GDK_SELECTION_NOTIFY:
4751           signal_num = SELECTION_NOTIFY_EVENT;
4752           break;
4753         case GDK_PROXIMITY_IN:
4754           signal_num = PROXIMITY_IN_EVENT;
4755           break;
4756         case GDK_PROXIMITY_OUT:
4757           signal_num = PROXIMITY_OUT_EVENT;
4758           break;
4759         case GDK_NO_EXPOSE:
4760           signal_num = NO_EXPOSE_EVENT;
4761           break;
4762         case GDK_CLIENT_EVENT:
4763           signal_num = CLIENT_EVENT;
4764           break;
4765         case GDK_EXPOSE:
4766           signal_num = EXPOSE_EVENT;
4767           break;
4768         case GDK_VISIBILITY_NOTIFY:
4769           signal_num = VISIBILITY_NOTIFY_EVENT;
4770           break;
4771         case GDK_GRAB_BROKEN:
4772           signal_num = GRAB_BROKEN;
4773           break;
4774         case GDK_DAMAGE:
4775           signal_num = DAMAGE_EVENT;
4776           break;
4777         default:
4778           g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4779           signal_num = -1;
4780           break;
4781         }
4782       if (signal_num != -1)
4783         g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4784     }
4785   if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4786     g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4787   else
4788     return_val = TRUE;
4789
4790   g_object_unref (widget);
4791
4792   return return_val;
4793 }
4794
4795 /**
4796  * gtk_widget_activate:
4797  * @widget: a #GtkWidget that's activatable
4798  * 
4799  * For widgets that can be "activated" (buttons, menu items, etc.)
4800  * this function activates them. Activation is what happens when you
4801  * press Enter on a widget during key navigation. If @widget isn't 
4802  * activatable, the function returns %FALSE.
4803  * 
4804  * Return value: %TRUE if the widget was activatable
4805  **/
4806 gboolean
4807 gtk_widget_activate (GtkWidget *widget)
4808 {
4809   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4810   
4811   if (WIDGET_CLASS (widget)->activate_signal)
4812     {
4813       /* FIXME: we should eventually check the signals signature here */
4814       g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4815
4816       return TRUE;
4817     }
4818   else
4819     return FALSE;
4820 }
4821
4822 /**
4823  * gtk_widget_set_scroll_adjustments:
4824  * @widget: a #GtkWidget
4825  * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4826  * @vadjustment: an adjustment for vertical scrolling, or %NULL
4827  *
4828  * For widgets that support scrolling, sets the scroll adjustments and
4829  * returns %TRUE.  For widgets that don't support scrolling, does
4830  * nothing and returns %FALSE. Widgets that don't support scrolling
4831  * can be scrolled by placing them in a #GtkViewport, which does
4832  * support scrolling.
4833  * 
4834  * Return value: %TRUE if the widget supports scrolling
4835  **/
4836 gboolean
4837 gtk_widget_set_scroll_adjustments (GtkWidget     *widget,
4838                                    GtkAdjustment *hadjustment,
4839                                    GtkAdjustment *vadjustment)
4840 {
4841   guint signal_id;
4842   GSignalQuery query;
4843
4844   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4845
4846   if (hadjustment)
4847     g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4848   if (vadjustment)
4849     g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4850
4851   signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
4852   if (!signal_id)
4853     return FALSE;
4854
4855   g_signal_query (signal_id, &query);
4856   if (!query.signal_id ||
4857       !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
4858       query.return_type != G_TYPE_NONE ||
4859       query.n_params != 2 ||
4860       query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
4861       query.param_types[1] != GTK_TYPE_ADJUSTMENT)
4862     {
4863       g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
4864                  G_OBJECT_TYPE_NAME (widget), query.signal_name);
4865       return FALSE;
4866     }
4867       
4868   g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
4869   return TRUE;
4870 }
4871
4872 static void
4873 gtk_widget_reparent_subwindows (GtkWidget *widget,
4874                                 GdkWindow *new_window)
4875 {
4876   if (GTK_WIDGET_NO_WINDOW (widget))
4877     {
4878       GList *children = gdk_window_get_children (widget->window);
4879       GList *tmp_list;
4880
4881       for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4882         {
4883           GdkWindow *window = tmp_list->data;
4884           gpointer child;
4885
4886           gdk_window_get_user_data (window, &child);
4887           while (child && child != widget)
4888             child = ((GtkWidget*) child)->parent;
4889
4890           if (child)
4891             gdk_window_reparent (window, new_window, 0, 0);
4892         }
4893
4894       g_list_free (children);
4895     }
4896   else
4897    {
4898      GdkWindow *parent;
4899      GList *tmp_list, *children;
4900
4901      parent = gdk_window_get_parent (widget->window);
4902
4903      if (parent == NULL)
4904        gdk_window_reparent (widget->window, new_window, 0, 0);
4905      else
4906        {
4907          children = gdk_window_get_children (parent);
4908          
4909          for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4910            {
4911              GdkWindow *window = tmp_list->data;
4912              gpointer child;
4913
4914              gdk_window_get_user_data (window, &child);
4915
4916              if (child == widget)
4917                gdk_window_reparent (window, new_window, 0, 0);
4918            }
4919          
4920          g_list_free (children);
4921        }
4922    }
4923 }
4924
4925 static void
4926 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4927                                  gpointer   client_data)
4928 {
4929   g_assert (client_data != NULL);
4930   
4931   if (GTK_WIDGET_NO_WINDOW (widget))
4932     {
4933       if (widget->window)
4934         g_object_unref (widget->window);
4935       widget->window = (GdkWindow*) client_data;
4936       if (widget->window)
4937         g_object_ref (widget->window);
4938
4939       if (GTK_IS_CONTAINER (widget))
4940         gtk_container_forall (GTK_CONTAINER (widget),
4941                               gtk_widget_reparent_fixup_child,
4942                               client_data);
4943     }
4944 }
4945
4946 /**
4947  * gtk_widget_reparent:
4948  * @widget: a #GtkWidget
4949  * @new_parent: a #GtkContainer to move the widget into
4950  *
4951  * Moves a widget from one #GtkContainer to another, handling reference
4952  * count issues to avoid destroying the widget.
4953  **/
4954 void
4955 gtk_widget_reparent (GtkWidget *widget,
4956                      GtkWidget *new_parent)
4957 {
4958   g_return_if_fail (GTK_IS_WIDGET (widget));
4959   g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4960   g_return_if_fail (widget->parent != NULL);
4961   
4962   if (widget->parent != new_parent)
4963     {
4964       /* First try to see if we can get away without unrealizing
4965        * the widget as we reparent it. if so we set a flag so
4966        * that gtk_widget_unparent doesn't unrealize widget
4967        */
4968       if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4969         GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4970       
4971       g_object_ref (widget);
4972       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4973       gtk_container_add (GTK_CONTAINER (new_parent), widget);
4974       g_object_unref (widget);
4975       
4976       if (GTK_WIDGET_IN_REPARENT (widget))
4977         {
4978           GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4979
4980           gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4981           gtk_widget_reparent_fixup_child (widget,
4982                                            gtk_widget_get_parent_window (widget));
4983         }
4984
4985       g_object_notify (G_OBJECT (widget), "parent");
4986     }
4987 }
4988
4989 /**
4990  * gtk_widget_intersect:
4991  * @widget: a #GtkWidget
4992  * @area: a rectangle
4993  * @intersection: rectangle to store intersection of @widget and @area
4994  * 
4995  * Computes the intersection of a @widget's area and @area, storing
4996  * the intersection in @intersection, and returns %TRUE if there was
4997  * an intersection.  @intersection may be %NULL if you're only
4998  * interested in whether there was an intersection.
4999  * 
5000  * Return value: %TRUE if there was an intersection
5001  **/
5002 gboolean
5003 gtk_widget_intersect (GtkWidget          *widget,
5004                       const GdkRectangle *area,
5005                       GdkRectangle       *intersection)
5006 {
5007   GdkRectangle *dest;
5008   GdkRectangle tmp;
5009   gint return_val;
5010   
5011   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5012   g_return_val_if_fail (area != NULL, FALSE);
5013   
5014   if (intersection)
5015     dest = intersection;
5016   else
5017     dest = &tmp;
5018   
5019   return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5020   
5021   if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
5022     {
5023       intersection->x -= widget->allocation.x;
5024       intersection->y -= widget->allocation.y;
5025     }
5026   
5027   return return_val;
5028 }
5029
5030 /**
5031  * gtk_widget_region_intersect:
5032  * @widget: a #GtkWidget
5033  * @region: a #GdkRegion, in the same coordinate system as 
5034  *          @widget->allocation. That is, relative to @widget->window
5035  *          for %NO_WINDOW widgets; relative to the parent window
5036  *          of @widget->window for widgets with their own window.
5037  * @returns: A newly allocated region holding the intersection of @widget
5038  *           and @region. The coordinates of the return value are
5039  *           relative to @widget->window for %NO_WINDOW widgets, and
5040  *           relative to the parent window of @widget->window for
5041  *           widgets with their own window.
5042  * 
5043  * Computes the intersection of a @widget's area and @region, returning
5044  * the intersection. The result may be empty, use gdk_region_empty() to
5045  * check.
5046  **/
5047 GdkRegion *
5048 gtk_widget_region_intersect (GtkWidget       *widget,
5049                              const GdkRegion *region)
5050 {
5051   GdkRectangle rect;
5052   GdkRegion *dest;
5053   
5054   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5055   g_return_val_if_fail (region != NULL, NULL);
5056
5057   gtk_widget_get_draw_rectangle (widget, &rect);
5058   
5059   dest = gdk_region_rectangle (&rect);
5060  
5061   gdk_region_intersect (dest, region);
5062
5063   return dest;
5064 }
5065
5066 /**
5067  * _gtk_widget_grab_notify:
5068  * @widget: a #GtkWidget
5069  * @was_grabbed: whether a grab is now in effect
5070  * 
5071  * Emits the #GtkWidget::grab-notify signal on @widget.
5072  * 
5073  * Since: 2.6
5074  **/
5075 void
5076 _gtk_widget_grab_notify (GtkWidget *widget,
5077                          gboolean   was_grabbed)
5078 {
5079   g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5080 }
5081
5082 /**
5083  * gtk_widget_grab_focus:
5084  * @widget: a #GtkWidget
5085  * 
5086  * Causes @widget to have the keyboard focus for the #GtkWindow it's
5087  * inside. @widget must be a focusable widget, such as a #GtkEntry;
5088  * something like #GtkFrame won't work.
5089  *
5090  * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5091  * gtk_widget_set_can_focus() to modify that flag.
5092  **/
5093 void
5094 gtk_widget_grab_focus (GtkWidget *widget)
5095 {
5096   g_return_if_fail (GTK_IS_WIDGET (widget));
5097
5098   if (!GTK_WIDGET_IS_SENSITIVE (widget))
5099     return;
5100   
5101   g_object_ref (widget);
5102   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5103   g_object_notify (G_OBJECT (widget), "has-focus");
5104   g_object_unref (widget);
5105 }
5106
5107 static void
5108 reset_focus_recurse (GtkWidget *widget,
5109                      gpointer   data)
5110 {
5111   if (GTK_IS_CONTAINER (widget))
5112     {
5113       GtkContainer *container;
5114
5115       container = GTK_CONTAINER (widget);
5116       gtk_container_set_focus_child (container, NULL);
5117
5118       gtk_container_foreach (container,
5119                              reset_focus_recurse,
5120                              NULL);
5121     }
5122 }
5123
5124 static void
5125 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5126 {
5127   if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5128     {
5129       GtkWidget *toplevel;
5130       GtkWidget *widget;
5131       
5132       /* clear the current focus setting, break if the current widget
5133        * is the focus widget's parent, since containers above that will
5134        * be set by the next loop.
5135        */
5136       toplevel = gtk_widget_get_toplevel (focus_widget);
5137       if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
5138         {
5139           widget = GTK_WINDOW (toplevel)->focus_widget;
5140           
5141           if (widget == focus_widget)
5142             {
5143               /* We call _gtk_window_internal_set_focus() here so that the
5144                * toplevel window can request the focus if necessary.
5145                * This is needed when the toplevel is a GtkPlug
5146                */
5147               if (!GTK_WIDGET_HAS_FOCUS (widget))
5148                 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5149
5150               return;
5151             }
5152           
5153           if (widget)
5154             {
5155               while (widget->parent && widget->parent != focus_widget->parent)
5156                 {
5157                   widget = widget->parent;
5158                   gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5159                 }
5160             }
5161         }
5162       else if (toplevel != focus_widget)
5163         {
5164           /* gtk_widget_grab_focus() operates on a tree without window...
5165            * actually, this is very questionable behaviour.
5166            */
5167           
5168           gtk_container_foreach (GTK_CONTAINER (toplevel),
5169                                  reset_focus_recurse,
5170                                  NULL);
5171         }
5172
5173       /* now propagate the new focus up the widget tree and finally
5174        * set it on the window
5175        */
5176       widget = focus_widget;
5177       while (widget->parent)
5178         {
5179           gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5180           widget = widget->parent;
5181         }
5182       if (GTK_IS_WINDOW (widget))
5183         _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5184     }
5185 }
5186
5187 static gboolean
5188 gtk_widget_real_query_tooltip (GtkWidget  *widget,
5189                                gint        x,
5190                                gint        y,
5191                                gboolean    keyboard_tip,
5192                                GtkTooltip *tooltip)
5193 {
5194   gchar *tooltip_markup;
5195   gboolean has_tooltip;
5196
5197   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5198   has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5199
5200   if (has_tooltip && tooltip_markup)
5201     {
5202       gtk_tooltip_set_markup (tooltip, tooltip_markup);
5203       return TRUE;
5204     }
5205
5206   return FALSE;
5207 }
5208
5209 static gboolean
5210 gtk_widget_real_show_help (GtkWidget        *widget,
5211                            GtkWidgetHelpType help_type)
5212 {
5213   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5214     {
5215       _gtk_tooltip_toggle_keyboard_mode (widget);
5216
5217       return TRUE;
5218     }
5219   else
5220     return FALSE;
5221 }
5222
5223 static gboolean
5224 gtk_widget_real_focus (GtkWidget         *widget,
5225                        GtkDirectionType   direction)
5226 {
5227   if (!GTK_WIDGET_CAN_FOCUS (widget))
5228     return FALSE;
5229   
5230   if (!gtk_widget_is_focus (widget))
5231     {
5232       gtk_widget_grab_focus (widget);
5233       return TRUE;
5234     }
5235   else
5236     return FALSE;
5237 }
5238
5239 static void
5240 gtk_widget_real_move_focus (GtkWidget         *widget,
5241                             GtkDirectionType   direction)
5242 {
5243   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5244
5245   if (GTK_IS_WINDOW (toplevel) &&
5246       GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5247     {
5248       GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5249                                                    direction);
5250     }
5251 }
5252
5253 static gboolean
5254 gtk_widget_real_keynav_failed (GtkWidget        *widget,
5255                                GtkDirectionType  direction)
5256 {
5257   gboolean cursor_only;
5258
5259   switch (direction)
5260     {
5261     case GTK_DIR_TAB_FORWARD:
5262     case GTK_DIR_TAB_BACKWARD:
5263       return FALSE;
5264
5265     case GTK_DIR_UP:
5266     case GTK_DIR_DOWN:
5267     case GTK_DIR_LEFT:
5268     case GTK_DIR_RIGHT:
5269       g_object_get (gtk_widget_get_settings (widget),
5270                     "gtk-keynav-cursor-only", &cursor_only,
5271                     NULL);
5272       if (cursor_only)
5273         return FALSE;
5274       break;
5275     }
5276
5277   gtk_widget_error_bell (widget);
5278
5279   return TRUE;
5280 }
5281
5282 /**
5283  * gtk_widget_set_can_focus:
5284  * @widget: a #GtkWidget
5285  * @can_focus: whether or not @widget can own the input focus.
5286  *
5287  * Specifies whether @widget can own the input focus. See
5288  * gtk_widget_grab_focus() for actually setting the input focus on a
5289  * widget.
5290  *
5291  * Since: 2.18
5292  **/
5293 void
5294 gtk_widget_set_can_focus (GtkWidget *widget,
5295                           gboolean   can_focus)
5296 {
5297   g_return_if_fail (GTK_IS_WIDGET (widget));
5298
5299   if (can_focus != GTK_WIDGET_CAN_FOCUS (widget))
5300     {
5301       if (can_focus)
5302         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
5303       else
5304         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
5305
5306       gtk_widget_queue_resize (widget);
5307       g_object_notify (G_OBJECT (widget), "can-focus");
5308     }
5309 }
5310
5311 /**
5312  * gtk_widget_get_can_focus:
5313  * @widget: a #GtkWidget
5314  *
5315  * Determines whether @widget can own the input focus. See
5316  * gtk_widget_set_can_focus().
5317  *
5318  * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5319  *
5320  * Since: 2.18
5321  **/
5322 gboolean
5323 gtk_widget_get_can_focus (GtkWidget *widget)
5324 {
5325   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5326
5327   return GTK_WIDGET_CAN_FOCUS (widget);
5328 }
5329
5330 /**
5331  * gtk_widget_has_focus:
5332  * @widget: a #GtkWidget
5333  *
5334  * Determines if the widget has the global input focus. See
5335  * gtk_widget_is_focus() for the difference between having the global
5336  * input focus, and only having the focus within a toplevel.
5337  *
5338  * Return value: %TRUE if the widget has the global input focus.
5339  *
5340  * Since: 2.18
5341  **/
5342 gboolean
5343 gtk_widget_has_focus (GtkWidget *widget)
5344 {
5345   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5346
5347   return GTK_WIDGET_HAS_FOCUS (widget);
5348 }
5349
5350 /**
5351  * gtk_widget_is_focus:
5352  * @widget: a #GtkWidget
5353  * 
5354  * Determines if the widget is the focus widget within its
5355  * toplevel. (This does not mean that the %HAS_FOCUS flag is
5356  * necessarily set; %HAS_FOCUS will only be set if the
5357  * toplevel widget additionally has the global input focus.)
5358  * 
5359  * Return value: %TRUE if the widget is the focus widget.
5360  **/
5361 gboolean
5362 gtk_widget_is_focus (GtkWidget *widget)
5363 {
5364   GtkWidget *toplevel;
5365
5366   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5367
5368   toplevel = gtk_widget_get_toplevel (widget);
5369   
5370   if (GTK_IS_WINDOW (toplevel))
5371     return widget == GTK_WINDOW (toplevel)->focus_widget;
5372   else
5373     return FALSE;
5374 }
5375
5376 /**
5377  * gtk_widget_set_can_default:
5378  * @widget: a #GtkWidget
5379  * @can_default: whether or not @widget can be a default widget.
5380  *
5381  * Specifies whether @widget can be a default widget. See
5382  * gtk_widget_grab_default() for details about the meaning of
5383  * "default".
5384  *
5385  * Since: 2.18
5386  **/
5387 void
5388 gtk_widget_set_can_default (GtkWidget *widget,
5389                             gboolean   can_default)
5390 {
5391   g_return_if_fail (GTK_IS_WIDGET (widget));
5392
5393   if (can_default != GTK_WIDGET_CAN_DEFAULT (widget))
5394     {
5395       if (can_default)
5396         GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
5397       else
5398         GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
5399
5400       gtk_widget_queue_resize (widget);
5401       g_object_notify (G_OBJECT (widget), "can-default");
5402     }
5403 }
5404
5405 /**
5406  * gtk_widget_get_can_default:
5407  * @widget: a #GtkWidget
5408  *
5409  * Determines whether @widget can be a default widget. See
5410  * gtk_widget_set_can_default().
5411  *
5412  * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5413  *
5414  * Since: 2.18
5415  **/
5416 gboolean
5417 gtk_widget_get_can_default (GtkWidget *widget)
5418 {
5419   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5420
5421   return GTK_WIDGET_CAN_DEFAULT (widget);
5422 }
5423
5424 /**
5425  * gtk_widget_has_default:
5426  * @widget: a #GtkWidget
5427  *
5428  * Determines whether @widget is the current default widget within its
5429  * toplevel. See gtk_widget_set_can_default().
5430  *
5431  * Return value: %TRUE if @widget is the current default widget within
5432  *     its toplevel, %FALSE otherwise
5433  *
5434  * Since: 2.18
5435  */
5436 gboolean
5437 gtk_widget_has_default (GtkWidget *widget)
5438 {
5439   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5440
5441   return GTK_WIDGET_HAS_DEFAULT (widget);
5442 }
5443
5444 /**
5445  * gtk_widget_grab_default:
5446  * @widget: a #GtkWidget
5447  *
5448  * Causes @widget to become the default widget. @widget must have the
5449  * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5450  * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5451  * %TRUE)</literal>. The default widget is activated when 
5452  * the user presses Enter in a window. Default widgets must be 
5453  * activatable, that is, gtk_widget_activate() should affect them.
5454  **/
5455 void
5456 gtk_widget_grab_default (GtkWidget *widget)
5457 {
5458   GtkWidget *window;
5459   
5460   g_return_if_fail (GTK_IS_WIDGET (widget));
5461   g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5462   
5463   window = gtk_widget_get_toplevel (widget);
5464   
5465   if (window && GTK_WIDGET_TOPLEVEL (window))
5466     gtk_window_set_default (GTK_WINDOW (window), widget);
5467   else
5468     g_warning (G_STRLOC ": widget not within a GtkWindow");
5469 }
5470
5471 /**
5472  * gtk_widget_set_receives_default:
5473  * @widget: a #GtkWidget
5474  * @receives_default: whether or not @widget can be a default widget.
5475  *
5476  * Specifies whether @widget will be treated as the default widget
5477  * within its toplevel when it has the focus, even if another widget
5478  * is the default.
5479  *
5480  * See gtk_widget_grab_default() for details about the meaning of
5481  * "default".
5482  *
5483  * Since: 2.18
5484  **/
5485 void
5486 gtk_widget_set_receives_default (GtkWidget *widget,
5487                                  gboolean   receives_default)
5488 {
5489   g_return_if_fail (GTK_IS_WIDGET (widget));
5490
5491   if (receives_default != gtk_widget_get_receives_default (widget))
5492     {
5493       if (receives_default)
5494         GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5495       else
5496         GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5497
5498       g_object_notify (G_OBJECT (widget), "receives-default");
5499     }
5500 }
5501
5502 /**
5503  * gtk_widget_get_receives_default:
5504  * @widget: a #GtkWidget
5505  *
5506  * Determines whether @widget is alyways treated as default widget
5507  * withing its toplevel when it has the focus, even if another widget
5508  * is the default.
5509  *
5510  * See gtk_widget_set_receives_default().
5511  *
5512  * Return value: %TRUE if @widget acts as default widget when focussed,
5513  *               %FALSE otherwise
5514  *
5515  * Since: 2.18
5516  **/
5517 gboolean
5518 gtk_widget_get_receives_default (GtkWidget *widget)
5519 {
5520   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5521
5522   return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5523 }
5524
5525 /**
5526  * gtk_widget_has_grab:
5527  * @widget: a #GtkWidget
5528  *
5529  * Determines whether the widget is currently grabbing events, so it
5530  * is the only widget receiving input events (keyboard and mouse).
5531  *
5532  * See also gtk_grab_add().
5533  *
5534  * Return value: %TRUE if the widget is in the grab_widgets stack
5535  *
5536  * Since: 2.18
5537  **/
5538 gboolean
5539 gtk_widget_has_grab (GtkWidget *widget)
5540 {
5541   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5542
5543   return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5544 }
5545
5546 /**
5547  * gtk_widget_set_name:
5548  * @widget: a #GtkWidget
5549  * @name: name for the widget
5550  *
5551  * Widgets can be named, which allows you to refer to them from a
5552  * gtkrc file. You can apply a style to widgets with a particular name
5553  * in the gtkrc file. See the documentation for gtkrc files (on the
5554  * same page as the docs for #GtkRcStyle).
5555  * 
5556  * Note that widget names are separated by periods in paths (see 
5557  * gtk_widget_path()), so names with embedded periods may cause confusion.
5558  **/
5559 void
5560 gtk_widget_set_name (GtkWidget   *widget,
5561                      const gchar *name)
5562 {
5563   gchar *new_name;
5564   
5565   g_return_if_fail (GTK_IS_WIDGET (widget));
5566
5567   new_name = g_strdup (name);
5568   g_free (widget->name);
5569   widget->name = new_name;
5570
5571   if (GTK_WIDGET_RC_STYLE (widget))
5572     gtk_widget_reset_rc_style (widget);
5573
5574   g_object_notify (G_OBJECT (widget), "name");
5575 }
5576
5577 /**
5578  * gtk_widget_get_name:
5579  * @widget: a #GtkWidget
5580  * 
5581  * Retrieves the name of a widget. See gtk_widget_set_name() for the
5582  * significance of widget names.
5583  * 
5584  * Return value: name of the widget. This string is owned by GTK+ and
5585  * should not be modified or freed
5586  **/
5587 G_CONST_RETURN gchar*
5588 gtk_widget_get_name (GtkWidget *widget)
5589 {
5590   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5591   
5592   if (widget->name)
5593     return widget->name;
5594   return g_type_name (GTK_WIDGET_TYPE (widget));
5595 }
5596
5597 /**
5598  * gtk_widget_set_state:
5599  * @widget: a #GtkWidget
5600  * @state: new state for @widget
5601  *
5602  * This function is for use in widget implementations. Sets the state
5603  * of a widget (insensitive, prelighted, etc.) Usually you should set
5604  * the state using wrapper functions such as gtk_widget_set_sensitive().
5605  **/
5606 void
5607 gtk_widget_set_state (GtkWidget           *widget,
5608                       GtkStateType         state)
5609 {
5610   g_return_if_fail (GTK_IS_WIDGET (widget));
5611
5612   if (state == GTK_WIDGET_STATE (widget))
5613     return;
5614
5615   if (state == GTK_STATE_INSENSITIVE)
5616     gtk_widget_set_sensitive (widget, FALSE);
5617   else
5618     {
5619       GtkStateData data;
5620
5621       data.state = state;
5622       data.state_restoration = FALSE;
5623       data.use_forall = FALSE;
5624       if (widget->parent)
5625         data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5626       else
5627         data.parent_sensitive = TRUE;
5628
5629       gtk_widget_propagate_state (widget, &data);
5630   
5631       if (GTK_WIDGET_DRAWABLE (widget))
5632         gtk_widget_queue_draw (widget);
5633     }
5634 }
5635
5636 /**
5637  * gtk_widget_get_state:
5638  * @widget: a #GtkWidget
5639  *
5640  * Returns the widget's state. See gtk_widget_set_state().
5641  *
5642  * Returns: the state of @widget.
5643  *
5644  * Since: 2.18
5645  */
5646 GtkStateType
5647 gtk_widget_get_state (GtkWidget *widget)
5648 {
5649   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5650
5651   return widget->state;
5652 }
5653
5654 /**
5655  * gtk_widget_set_visible:
5656  * @widget: a #GtkWidget
5657  * @visible: whether the widget should be shown or not
5658  *
5659  * Sets the visibility state of @widget. Note that setting this to
5660  * %TRUE doesn't mean the widget is actually viewable, see
5661  * gtk_widget_get_visible().
5662  *
5663  * This function simply calls gtk_widget_show() or gtk_widget_hide()
5664  * but is nicer to use when the visibility of the widget depends on
5665  * some condition.
5666  *
5667  * Since: 2.18
5668  **/
5669 void
5670 gtk_widget_set_visible (GtkWidget *widget,
5671                         gboolean   visible)
5672 {
5673   g_return_if_fail (GTK_IS_WIDGET (widget));
5674
5675   if (visible != GTK_WIDGET_VISIBLE (widget))
5676     {
5677       if (visible)
5678         gtk_widget_show (widget);
5679       else
5680         gtk_widget_hide (widget);
5681     }
5682 }
5683
5684 /**
5685  * gtk_widget_get_visible:
5686  * @widget: a #GtkWidget
5687  *
5688  * Determines whether the widget is visible. Note that this doesn't
5689  * take into account whether the widget's parent is also visible
5690  * or the widget is obscured in any way.
5691  *
5692  * See gtk_widget_set_visible().
5693  *
5694  * Return value: %TRUE if the widget is visible
5695  *
5696  * Since: 2.18
5697  **/
5698 gboolean
5699 gtk_widget_get_visible (GtkWidget *widget)
5700 {
5701   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5702
5703   return (GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0;
5704 }
5705
5706 /**
5707  * gtk_widget_set_has_window:
5708  * @widget: a #GtkWidget
5709  * @has_window: whether or not @widget has a window.
5710  *
5711  * Specifies whether @widget has a #GdkWindow of its own. Note that
5712  * all realized widgets have a non-%NULL "window" pointer
5713  * (gtk_widget_get_window() never returns a %NULL window when a widget
5714  * is realized), but for many of them it's actually the #GdkWindow of
5715  * one of its parent widgets. Widgets that create a %window for
5716  * themselves in GtkWidget::realize() however must announce this by
5717  * calling this function with @has_window = %TRUE.
5718  *
5719  * This function should only be called by widget implementations,
5720  * and they should call it in their init() function.
5721  *
5722  * Since: 2.18
5723  **/
5724 void
5725 gtk_widget_set_has_window (GtkWidget *widget,
5726                            gboolean   has_window)
5727 {
5728   g_return_if_fail (GTK_IS_WIDGET (widget));
5729
5730   if (has_window)
5731     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
5732   else
5733     GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
5734 }
5735
5736 /**
5737  * gtk_widget_get_has_window:
5738  * @widget: a #GtkWidget
5739  *
5740  * Determines whether @widget has a #GdkWindow of its own. See
5741  * gtk_widget_set_has_window().
5742  *
5743  * Return value: %TRUE if @widget has a window, %FALSE otherwise
5744  *
5745  * Since: 2.18
5746  **/
5747 gboolean
5748 gtk_widget_get_has_window (GtkWidget *widget)
5749 {
5750   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5751
5752   return !GTK_WIDGET_NO_WINDOW (widget);
5753 }
5754
5755 /**
5756  * gtk_widget_is_toplevel:
5757  * @widget: a #GtkWidget
5758  *
5759  * Determines whether @widget is a toplevel widget. Currently only
5760  * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5761  * widgets have no parent widget.
5762  *
5763  * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5764  *
5765  * Since: 2.18
5766  **/
5767 gboolean
5768 gtk_widget_is_toplevel (GtkWidget *widget)
5769 {
5770   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5771
5772   return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5773 }
5774
5775 /**
5776  * gtk_widget_is_drawable:
5777  * @widget: a #GtkWidget
5778  *
5779  * Determines whether @widget can be drawn to. A widget can be drawn
5780  * to if it is mapped and visible.
5781  *
5782  * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5783  *
5784  * Since: 2.18
5785  **/
5786 gboolean
5787 gtk_widget_is_drawable (GtkWidget *widget)
5788 {
5789   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5790
5791   return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 &&
5792           (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0);
5793 }
5794
5795 /**
5796  * gtk_widget_set_app_paintable:
5797  * @widget: a #GtkWidget
5798  * @app_paintable: %TRUE if the application will paint on the widget
5799  *
5800  * Sets whether the application intends to draw on the widget in
5801  * an #GtkWidget::expose-event handler. 
5802  *
5803  * This is a hint to the widget and does not affect the behavior of 
5804  * the GTK+ core; many widgets ignore this flag entirely. For widgets 
5805  * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow, 
5806  * the effect is to suppress default themed drawing of the widget's 
5807  * background. (Children of the widget will still be drawn.) The application 
5808  * is then entirely responsible for drawing the widget background.
5809  *
5810  * Note that the background is still drawn when the widget is mapped.
5811  * If this is not suitable (e.g. because you want to make a transparent
5812  * window using an RGBA visual), you can work around this by doing:
5813  * |[
5814  *  gtk_widget_realize (window);
5815  *  gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5816  *  gtk_widget_show (window);
5817  * ]|
5818  **/
5819 void
5820 gtk_widget_set_app_paintable (GtkWidget *widget,
5821                               gboolean   app_paintable)
5822 {
5823   g_return_if_fail (GTK_IS_WIDGET (widget));
5824
5825   app_paintable = (app_paintable != FALSE);
5826
5827   if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5828     {
5829       if (app_paintable)
5830         GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5831       else
5832         GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5833
5834       if (GTK_WIDGET_DRAWABLE (widget))
5835         gtk_widget_queue_draw (widget);
5836
5837       g_object_notify (G_OBJECT (widget), "app-paintable");
5838     }
5839 }
5840
5841 /**
5842  * gtk_widget_get_app_paintable:
5843  * @widget: a #GtkWidget
5844  *
5845  * Determines whether the application intends to draw on the widget in
5846  * an #GtkWidget::expose-event handler.
5847  *
5848  * See gtk_widget_set_app_paintable()
5849  *
5850  * Return value: %TRUE if the widget is app paintable
5851  *
5852  * Since: 2.18
5853  **/
5854 gboolean
5855 gtk_widget_get_app_paintable (GtkWidget *widget)
5856 {
5857   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5858
5859   return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
5860 }
5861
5862 /**
5863  * gtk_widget_set_double_buffered:
5864  * @widget: a #GtkWidget
5865  * @double_buffered: %TRUE to double-buffer a widget
5866  *
5867  * Widgets are double buffered by default; you can use this function
5868  * to turn off the buffering. "Double buffered" simply means that
5869  * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5870  * automatically around expose events sent to the
5871  * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5872  * window to an offscreen buffer, and gdk_window_end_paint() draws the
5873  * buffer to the screen. The result is that users see the window
5874  * update in one smooth step, and don't see individual graphics
5875  * primitives being rendered.
5876  *
5877  * In very simple terms, double buffered widgets don't flicker,
5878  * so you would only use this function to turn off double buffering
5879  * if you had special needs and really knew what you were doing.
5880  * 
5881  * Note: if you turn off double-buffering, you have to handle
5882  * expose events, since even the clearing to the background color or 
5883  * pixmap will not happen automatically (as it is done in 
5884  * gdk_window_begin_paint()).
5885  **/
5886 void
5887 gtk_widget_set_double_buffered (GtkWidget *widget,
5888                                 gboolean   double_buffered)
5889 {
5890   g_return_if_fail (GTK_IS_WIDGET (widget));
5891
5892   if (double_buffered != GTK_WIDGET_DOUBLE_BUFFERED (widget))
5893     {
5894       if (double_buffered)
5895         GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5896       else
5897         GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5898
5899       g_object_notify (G_OBJECT (widget), "double-buffered");
5900     }
5901 }
5902
5903 /**
5904  * gtk_widget_get_double_buffered:
5905  * @widget: a #GtkWidget
5906  *
5907  * Determines whether the widget is double buffered.
5908  *
5909  * See gtk_widget_set_double_buffered()
5910  *
5911  * Return value: %TRUE if the widget is double buffered
5912  *
5913  * Since: 2.18
5914  **/
5915 gboolean
5916 gtk_widget_get_double_buffered (GtkWidget *widget)
5917 {
5918   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5919
5920   return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
5921 }
5922
5923 /**
5924  * gtk_widget_set_redraw_on_allocate:
5925  * @widget: a #GtkWidget
5926  * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5927  *   when it is allocated to a new size. Otherwise, only the
5928  *   new portion of the widget will be redrawn.
5929  *
5930  * Sets whether the entire widget is queued for drawing when its size 
5931  * allocation changes. By default, this setting is %TRUE and
5932  * the entire widget is redrawn on every size change. If your widget
5933  * leaves the upper left unchanged when made bigger, turning this
5934  * setting off will improve performance.
5935
5936  * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5937  * off all allocation on resizing: the widget will not even redraw if
5938  * its position changes; this is to allow containers that don't draw
5939  * anything to avoid excess invalidations. If you set this flag on a
5940  * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window, 
5941  * you are responsible for invalidating both the old and new allocation 
5942  * of the widget when the widget is moved and responsible for invalidating
5943  * regions newly when the widget increases size.
5944  **/
5945 void
5946 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5947                                    gboolean   redraw_on_allocate)
5948 {
5949   g_return_if_fail (GTK_IS_WIDGET (widget));
5950
5951   if (redraw_on_allocate)
5952     GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5953   else
5954     GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5955 }
5956
5957 /**
5958  * gtk_widget_set_sensitive:
5959  * @widget: a #GtkWidget
5960  * @sensitive: %TRUE to make the widget sensitive
5961  *
5962  * Sets the sensitivity of a widget. A widget is sensitive if the user
5963  * can interact with it. Insensitive widgets are "grayed out" and the
5964  * user can't interact with them. Insensitive widgets are known as
5965  * "inactive", "disabled", or "ghosted" in some other toolkits.
5966  **/
5967 void
5968 gtk_widget_set_sensitive (GtkWidget *widget,
5969                           gboolean   sensitive)
5970 {
5971   GtkStateData data;
5972
5973   g_return_if_fail (GTK_IS_WIDGET (widget));
5974
5975   sensitive = (sensitive != FALSE);
5976
5977   if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5978     return;
5979
5980   if (sensitive)
5981     {
5982       GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5983       data.state = GTK_WIDGET_SAVED_STATE (widget);
5984     }
5985   else
5986     {
5987       GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5988       data.state = GTK_WIDGET_STATE (widget);
5989     }
5990   data.state_restoration = TRUE;
5991   data.use_forall = TRUE;
5992
5993   if (widget->parent)
5994     data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5995   else
5996     data.parent_sensitive = TRUE;
5997
5998   gtk_widget_propagate_state (widget, &data);
5999   if (GTK_WIDGET_DRAWABLE (widget))
6000     gtk_widget_queue_draw (widget);
6001
6002   g_object_notify (G_OBJECT (widget), "sensitive");
6003 }
6004
6005 /**
6006  * gtk_widget_get_sensitive:
6007  * @widget: a #GtkWidget
6008  *
6009  * Returns the widget's sensitivity (in the sense of returning
6010  * the value that has been set using gtk_widget_set_sensitive()).
6011  *
6012  * The effective sensitivity of a widget is however determined by both its
6013  * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6014  *
6015  * Returns: %TRUE if the widget is sensitive
6016  *
6017  * Since: 2.18
6018  */
6019 gboolean
6020 gtk_widget_get_sensitive (GtkWidget *widget)
6021 {
6022   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6023
6024   return GTK_WIDGET_SENSITIVE (widget);
6025 }
6026
6027 /**
6028  * gtk_widget_is_sensitive:
6029  * @widget: a #GtkWidget
6030  *
6031  * Returns the widget's effective sensitivity, which means
6032  * it is sensitive itself and also its parent widget is sensntive
6033  *
6034  * Returns: %TRUE if the widget is effectively sensitive
6035  *
6036  * Since: 2.18
6037  */
6038 gboolean
6039 gtk_widget_is_sensitive (GtkWidget *widget)
6040 {
6041   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6042
6043   return GTK_WIDGET_IS_SENSITIVE (widget);
6044 }
6045
6046 /**
6047  * gtk_widget_set_parent:
6048  * @widget: a #GtkWidget
6049  * @parent: parent container
6050  *
6051  * This function is useful only when implementing subclasses of 
6052  * #GtkContainer.
6053  * Sets the container as the parent of @widget, and takes care of
6054  * some details such as updating the state and style of the child
6055  * to reflect its new location. The opposite function is
6056  * gtk_widget_unparent().
6057  **/
6058 void
6059 gtk_widget_set_parent (GtkWidget *widget,
6060                        GtkWidget *parent)
6061 {
6062   GtkStateData data;
6063   
6064   g_return_if_fail (GTK_IS_WIDGET (widget));
6065   g_return_if_fail (GTK_IS_WIDGET (parent));
6066   g_return_if_fail (widget != parent);
6067   if (widget->parent != NULL)
6068     {
6069       g_warning ("Can't set a parent on widget which has a parent\n");
6070       return;
6071     }
6072   if (GTK_WIDGET_TOPLEVEL (widget))
6073     {
6074       g_warning ("Can't set a parent on a toplevel widget\n");
6075       return;
6076     }
6077
6078   /* keep this function in sync with gtk_menu_attach_to_widget()
6079    */
6080
6081   g_object_ref_sink (widget);
6082   widget->parent = parent;
6083
6084   if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
6085     data.state = GTK_WIDGET_STATE (parent);
6086   else
6087     data.state = GTK_WIDGET_STATE (widget);
6088   data.state_restoration = FALSE;
6089   data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
6090   data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
6091
6092   gtk_widget_propagate_state (widget, &data);
6093   
6094   gtk_widget_reset_rc_styles (widget);
6095
6096   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6097   if (GTK_WIDGET_ANCHORED (widget->parent))
6098     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6099   g_object_notify (G_OBJECT (widget), "parent");
6100
6101   /* Enforce realized/mapped invariants
6102    */
6103   if (GTK_WIDGET_REALIZED (widget->parent))
6104     gtk_widget_realize (widget);
6105
6106   if (GTK_WIDGET_VISIBLE (widget->parent) &&
6107       GTK_WIDGET_VISIBLE (widget))
6108     {
6109       if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6110           GTK_WIDGET_MAPPED (widget->parent))
6111         gtk_widget_map (widget);
6112
6113       gtk_widget_queue_resize (widget);
6114     }
6115 }
6116
6117 /**
6118  * gtk_widget_get_parent:
6119  * @widget: a #GtkWidget
6120  *
6121  * Returns the parent container of @widget.
6122  *
6123  * Return value: the parent container of @widget, or %NULL
6124  **/
6125 GtkWidget *
6126 gtk_widget_get_parent (GtkWidget *widget)
6127 {
6128   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6129
6130   return widget->parent;
6131 }
6132
6133 /*****************************************
6134  * Widget styles
6135  * see docs/styles.txt
6136  *****************************************/
6137
6138 /**
6139  * gtk_widget_set_style:
6140  * @widget: a #GtkWidget
6141  * @style: a #GtkStyle, or %NULL to remove the effect of a previous
6142  *         gtk_widget_set_style() and go back to the default style
6143  *
6144  * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6145  * want to use this function; it interacts badly with themes, because
6146  * themes work by replacing the #GtkStyle. Instead, use
6147  * gtk_widget_modify_style().
6148  **/
6149 void
6150 gtk_widget_set_style (GtkWidget *widget,
6151                       GtkStyle  *style)
6152 {
6153   g_return_if_fail (GTK_IS_WIDGET (widget));
6154
6155   if (style)
6156     {
6157       gboolean initial_emission;
6158
6159       initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6160       
6161       GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
6162       GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6163       
6164       gtk_widget_set_style_internal (widget, style, initial_emission);
6165     }
6166   else
6167     {
6168       if (GTK_WIDGET_USER_STYLE (widget))
6169         gtk_widget_reset_rc_style (widget);
6170     }
6171 }
6172
6173 /**
6174  * gtk_widget_ensure_style:
6175  * @widget: a #GtkWidget
6176  *
6177  * Ensures that @widget has a style (@widget->style). Not a very useful
6178  * function; most of the time, if you want the style, the widget is
6179  * realized, and realized widgets are guaranteed to have a style
6180  * already.
6181  **/
6182 void
6183 gtk_widget_ensure_style (GtkWidget *widget)
6184 {
6185   g_return_if_fail (GTK_IS_WIDGET (widget));
6186
6187   if (!GTK_WIDGET_USER_STYLE (widget) &&
6188       !GTK_WIDGET_RC_STYLE (widget))
6189     gtk_widget_reset_rc_style (widget);
6190 }
6191
6192 /* Look up the RC style for this widget, unsetting any user style that
6193  * may be in effect currently
6194  **/
6195 static void
6196 gtk_widget_reset_rc_style (GtkWidget *widget)
6197 {
6198   GtkStyle *new_style = NULL;
6199   gboolean initial_emission;
6200   
6201   initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6202
6203   GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6204   GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
6205   
6206   if (gtk_widget_has_screen (widget))
6207     new_style = gtk_rc_get_style (widget);
6208   if (!new_style)
6209     new_style = gtk_widget_get_default_style ();
6210
6211   if (initial_emission || new_style != widget->style)
6212     gtk_widget_set_style_internal (widget, new_style, initial_emission);
6213 }
6214
6215 /**
6216  * gtk_widget_get_style:
6217  * @widget: a #GtkWidget
6218  * 
6219  * Simply an accessor function that returns @widget->style.
6220  * 
6221  * Return value: the widget's #GtkStyle
6222  **/
6223 GtkStyle*
6224 gtk_widget_get_style (GtkWidget *widget)
6225 {
6226   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6227   
6228   return widget->style;
6229 }
6230
6231 /**
6232  * gtk_widget_modify_style:
6233  * @widget: a #GtkWidget
6234  * @style: the #GtkRcStyle holding the style modifications
6235  * 
6236  * Modifies style values on the widget. Modifications made using this
6237  * technique take precedence over style values set via an RC file,
6238  * however, they will be overriden if a style is explicitely set on
6239  * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6240  * is designed so each field can either be set or unset, so it is
6241  * possible, using this function, to modify some style values and
6242  * leave the others unchanged.
6243  *
6244  * Note that modifications made with this function are not cumulative
6245  * with previous calls to gtk_widget_modify_style() or with such
6246  * functions as gtk_widget_modify_fg(). If you wish to retain
6247  * previous values, you must first call gtk_widget_get_modifier_style(),
6248  * make your modifications to the returned style, then call
6249  * gtk_widget_modify_style() with that style. On the other hand,
6250  * if you first call gtk_widget_modify_style(), subsequent calls
6251  * to such functions gtk_widget_modify_fg() will have a cumulative
6252  * effect with the initial modifications.
6253  **/
6254 void       
6255 gtk_widget_modify_style (GtkWidget      *widget,
6256                          GtkRcStyle     *style)
6257 {
6258   g_return_if_fail (GTK_IS_WIDGET (widget));
6259   g_return_if_fail (GTK_IS_RC_STYLE (style));
6260   
6261   g_object_set_qdata_full (G_OBJECT (widget),
6262                            quark_rc_style,
6263                            gtk_rc_style_copy (style),
6264                            (GDestroyNotify) g_object_unref);
6265
6266   /* note that "style" may be invalid here if it was the old
6267    * modifier style and the only reference was our own.
6268    */
6269   
6270   if (GTK_WIDGET_RC_STYLE (widget))
6271     gtk_widget_reset_rc_style (widget);
6272 }
6273
6274 /**
6275  * gtk_widget_get_modifier_style:
6276  * @widget: a #GtkWidget
6277  * 
6278  * Returns the current modifier style for the widget. (As set by
6279  * gtk_widget_modify_style().) If no style has previously set, a new
6280  * #GtkRcStyle will be created with all values unset, and set as the
6281  * modifier style for the widget. If you make changes to this rc
6282  * style, you must call gtk_widget_modify_style(), passing in the
6283  * returned rc style, to make sure that your changes take effect.
6284  *
6285  * Caution: passing the style back to gtk_widget_modify_style() will
6286  * normally end up destroying it, because gtk_widget_modify_style() copies
6287  * the passed-in style and sets the copy as the new modifier style,
6288  * thus dropping any reference to the old modifier style. Add a reference
6289  * to the modifier style if you want to keep it alive.
6290  * 
6291  * Return value: the modifier style for the widget. This rc style is
6292  *   owned by the widget. If you want to keep a pointer to value this
6293  *   around, you must add a refcount using g_object_ref().
6294  **/
6295 GtkRcStyle *
6296 gtk_widget_get_modifier_style (GtkWidget      *widget)
6297 {
6298   GtkRcStyle *rc_style;
6299   
6300   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6301
6302   rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6303
6304   if (!rc_style)
6305     {
6306       rc_style = gtk_rc_style_new ();
6307       g_object_set_qdata_full (G_OBJECT (widget),
6308                                quark_rc_style,
6309                                rc_style,
6310                                (GDestroyNotify) g_object_unref);
6311     }
6312
6313   return rc_style;
6314 }
6315
6316 static void
6317 gtk_widget_modify_color_component (GtkWidget      *widget,
6318                                    GtkRcFlags      component,
6319                                    GtkStateType    state,
6320                                    const GdkColor *color)
6321 {
6322   GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);  
6323
6324   if (color)
6325     {
6326       switch (component)
6327         {
6328         case GTK_RC_FG:
6329           rc_style->fg[state] = *color;
6330           break;
6331         case GTK_RC_BG:
6332           rc_style->bg[state] = *color;
6333           break;
6334         case GTK_RC_TEXT:
6335           rc_style->text[state] = *color;
6336           break;
6337         case GTK_RC_BASE:
6338           rc_style->base[state] = *color;
6339           break;
6340         default:
6341           g_assert_not_reached();
6342         }
6343       
6344       rc_style->color_flags[state] |= component;
6345     }
6346   else
6347     rc_style->color_flags[state] &= ~component;
6348
6349   gtk_widget_modify_style (widget, rc_style);
6350 }
6351
6352 /**
6353  * gtk_widget_modify_fg:
6354  * @widget: a #GtkWidget
6355  * @state: the state for which to set the foreground color
6356  * @color: the color to assign (does not need to be allocated),
6357  *         or %NULL to undo the effect of previous calls to
6358  *         of gtk_widget_modify_fg().
6359  * 
6360  * Sets the foreground color for a widget in a particular state.  
6361  * All other style values are left untouched. See also
6362  * gtk_widget_modify_style().
6363  **/
6364 void
6365 gtk_widget_modify_fg (GtkWidget      *widget,
6366                       GtkStateType    state,
6367                       const GdkColor *color)
6368 {
6369   g_return_if_fail (GTK_IS_WIDGET (widget));
6370   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6371
6372   gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6373 }
6374
6375 /**
6376  * gtk_widget_modify_bg:
6377  * @widget: a #GtkWidget
6378  * @state: the state for which to set the background color
6379  * @color: the color to assign (does not need to be allocated),
6380  *         or %NULL to undo the effect of previous calls to
6381  *         of gtk_widget_modify_bg().
6382  * 
6383  * Sets the background color for a widget in a particular state.  
6384  * All other style values are left untouched. See also
6385  * gtk_widget_modify_style(). 
6386  *
6387  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6388  * draw on their parent container's window and thus may not draw any 
6389  * background themselves. This is the case for e.g. #GtkLabel. To modify 
6390  * the background of such widgets, you have to set the background color 
6391  * on their parent; if you want to set the background of a rectangular 
6392  * area around a label, try placing the label in a #GtkEventBox widget 
6393  * and setting the background color on that.
6394  **/
6395 void
6396 gtk_widget_modify_bg (GtkWidget      *widget,
6397                       GtkStateType    state,
6398                       const GdkColor *color)
6399 {
6400   g_return_if_fail (GTK_IS_WIDGET (widget));
6401   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6402
6403   gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6404 }
6405
6406 /**
6407  * gtk_widget_modify_text:
6408  * @widget: a #GtkWidget
6409  * @state: the state for which to set the text color
6410  * @color: the color to assign (does not need to be allocated),
6411  *         or %NULL to undo the effect of previous calls to
6412  *         of gtk_widget_modify_text().
6413  * 
6414  * Sets the text color for a widget in a particular state.  All other
6415  * style values are left untouched. The text color is the foreground
6416  * color used along with the base color (see gtk_widget_modify_base())
6417  * for widgets such as #GtkEntry and #GtkTextView. See also
6418  * gtk_widget_modify_style().
6419  **/
6420 void
6421 gtk_widget_modify_text (GtkWidget      *widget,
6422                         GtkStateType    state,
6423                         const GdkColor *color)
6424 {
6425   g_return_if_fail (GTK_IS_WIDGET (widget));
6426   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6427
6428   gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6429 }
6430
6431 /**
6432  * gtk_widget_modify_base:
6433  * @widget: a #GtkWidget
6434  * @state: the state for which to set the base color
6435  * @color: the color to assign (does not need to be allocated),
6436  *         or %NULL to undo the effect of previous calls to
6437  *         of gtk_widget_modify_base().
6438  * 
6439  * Sets the base color for a widget in a particular state.
6440  * All other style values are left untouched. The base color
6441  * is the background color used along with the text color
6442  * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6443  * and #GtkTextView. See also gtk_widget_modify_style().
6444  *
6445  * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6446  * draw on their parent container's window and thus may not draw any 
6447  * background themselves. This is the case for e.g. #GtkLabel. To modify 
6448  * the background of such widgets, you have to set the base color on their 
6449  * parent; if you want to set the background of a rectangular area around 
6450  * a label, try placing the label in a #GtkEventBox widget and setting 
6451  * the base color on that.
6452  **/
6453 void
6454 gtk_widget_modify_base (GtkWidget      *widget,
6455                         GtkStateType    state,
6456                         const GdkColor *color)
6457 {
6458   g_return_if_fail (GTK_IS_WIDGET (widget));
6459   g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6460
6461   gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6462 }
6463
6464 static void
6465 modify_color_property (GtkWidget      *widget,
6466                        GtkRcStyle     *rc_style,
6467                        const char     *name,
6468                        const GdkColor *color)
6469 {
6470   GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6471   GQuark property_name = g_quark_from_string (name);
6472
6473   if (color)
6474     {
6475       GtkRcProperty rc_property = {0};
6476       char *color_name;
6477
6478       rc_property.type_name = type_name;
6479       rc_property.property_name = property_name;
6480       rc_property.origin = NULL;
6481
6482       color_name = gdk_color_to_string (color);
6483       g_value_init (&rc_property.value, G_TYPE_STRING);
6484       g_value_take_string (&rc_property.value, color_name);
6485
6486       _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6487
6488       g_value_unset (&rc_property.value);
6489     }
6490   else
6491     _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6492 }
6493
6494 /**
6495  * gtk_widget_modify_cursor:
6496  * @widget: a #GtkWidget
6497  * @primary: the color to use for primary cursor (does not need to be
6498  *           allocated), or %NULL to undo the effect of previous calls to
6499  *           of gtk_widget_modify_cursor().
6500  * @secondary: the color to use for secondary cursor (does not need to be
6501  *             allocated), or %NULL to undo the effect of previous calls to
6502  *             of gtk_widget_modify_cursor().
6503  *
6504  * Sets the cursor color to use in a widget, overriding the
6505  * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6506  * style properties. All other style values are left untouched. 
6507  * See also gtk_widget_modify_style().
6508  *
6509  * Since: 2.12
6510  **/
6511 void
6512 gtk_widget_modify_cursor (GtkWidget      *widget,
6513                           const GdkColor *primary,
6514                           const GdkColor *secondary)
6515 {
6516   GtkRcStyle *rc_style;
6517
6518   g_return_if_fail (GTK_IS_WIDGET (widget));
6519
6520   rc_style = gtk_widget_get_modifier_style (widget);
6521
6522   modify_color_property (widget, rc_style, "cursor-color", primary);
6523   modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6524
6525   gtk_widget_modify_style (widget, rc_style);
6526 }
6527
6528 /**
6529  * gtk_widget_modify_font:
6530  * @widget: a #GtkWidget
6531  * @font_desc: the font description to use, or %NULL to undo
6532  *   the effect of previous calls to gtk_widget_modify_font().
6533  * 
6534  * Sets the font to use for a widget.  All other style values are left
6535  * untouched. See also gtk_widget_modify_style().
6536  **/
6537 void
6538 gtk_widget_modify_font (GtkWidget            *widget,
6539                         PangoFontDescription *font_desc)
6540 {
6541   GtkRcStyle *rc_style;
6542
6543   g_return_if_fail (GTK_IS_WIDGET (widget));
6544
6545   rc_style = gtk_widget_get_modifier_style (widget);  
6546
6547   if (rc_style->font_desc)
6548     pango_font_description_free (rc_style->font_desc);
6549
6550   if (font_desc)
6551     rc_style->font_desc = pango_font_description_copy (font_desc);
6552   else
6553     rc_style->font_desc = NULL;
6554   
6555   gtk_widget_modify_style (widget, rc_style);
6556 }
6557
6558 static void
6559 gtk_widget_real_direction_changed (GtkWidget        *widget,
6560                                    GtkTextDirection  previous_direction)
6561 {
6562   gtk_widget_queue_resize (widget);
6563 }
6564
6565 static void
6566 gtk_widget_real_style_set (GtkWidget *widget,
6567                            GtkStyle  *previous_style)
6568 {
6569   if (GTK_WIDGET_REALIZED (widget) &&
6570       !GTK_WIDGET_NO_WINDOW (widget))
6571     gtk_style_set_background (widget->style, widget->window, widget->state);
6572 }
6573
6574 static void
6575 gtk_widget_set_style_internal (GtkWidget *widget,
6576                                GtkStyle  *style,
6577                                gboolean   initial_emission)
6578 {
6579   g_object_ref (widget);
6580   g_object_freeze_notify (G_OBJECT (widget));
6581
6582   if (widget->style != style)
6583     {
6584       GtkStyle *previous_style;
6585
6586       if (GTK_WIDGET_REALIZED (widget))
6587         {
6588           gtk_widget_reset_shapes (widget);
6589           gtk_style_detach (widget->style);
6590         }
6591       
6592       previous_style = widget->style;
6593       widget->style = style;
6594       g_object_ref (widget->style);
6595       
6596       if (GTK_WIDGET_REALIZED (widget))
6597         widget->style = gtk_style_attach (widget->style, widget->window);
6598
6599       gtk_widget_update_pango_context (widget);
6600       g_signal_emit (widget,
6601                      widget_signals[STYLE_SET],
6602                      0,
6603                      initial_emission ? NULL : previous_style);
6604       g_object_unref (previous_style);
6605
6606       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6607         gtk_widget_queue_resize (widget);
6608     }
6609   else if (initial_emission)
6610     {
6611       gtk_widget_update_pango_context (widget);
6612       g_signal_emit (widget,
6613                      widget_signals[STYLE_SET],
6614                      0,
6615                      NULL);
6616     }
6617   g_object_notify (G_OBJECT (widget), "style");
6618   g_object_thaw_notify (G_OBJECT (widget));
6619   g_object_unref (widget);
6620 }
6621
6622 typedef struct {
6623   GtkWidget *previous_toplevel;
6624   GdkScreen *previous_screen;
6625   GdkScreen *new_screen;
6626 } HierarchyChangedInfo;
6627
6628 static void
6629 do_screen_change (GtkWidget *widget,
6630                   GdkScreen *old_screen,
6631                   GdkScreen *new_screen)
6632 {
6633   if (old_screen != new_screen)
6634     {
6635       if (old_screen)
6636         {
6637           PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6638           if (context)
6639             g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6640         }
6641       
6642       _gtk_tooltip_hide (widget);
6643       g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6644     }
6645 }
6646
6647 static void
6648 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6649                                                 gpointer   client_data)
6650 {
6651   HierarchyChangedInfo *info = client_data;
6652   gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6653                  (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6654
6655   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6656     {
6657       g_object_ref (widget);
6658       
6659       if (new_anchored)
6660         GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6661       else
6662         GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6663       
6664       g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6665       do_screen_change (widget, info->previous_screen, info->new_screen);
6666       
6667       if (GTK_IS_CONTAINER (widget))
6668         gtk_container_forall (GTK_CONTAINER (widget),
6669                               gtk_widget_propagate_hierarchy_changed_recurse,
6670                               client_data);
6671       
6672       g_object_unref (widget);
6673     }
6674 }
6675
6676 /**
6677  * _gtk_widget_propagate_hierarchy_changed:
6678  * @widget: a #GtkWidget
6679  * @previous_toplevel: Previous toplevel
6680  * 
6681  * Propagates changes in the anchored state to a widget and all
6682  * children, unsetting or setting the %ANCHORED flag, and
6683  * emitting #GtkWidget::hierarchy-changed.
6684  **/
6685 void
6686 _gtk_widget_propagate_hierarchy_changed (GtkWidget    *widget,
6687                                          GtkWidget    *previous_toplevel)
6688 {
6689   HierarchyChangedInfo info;
6690
6691   info.previous_toplevel = previous_toplevel;
6692   info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6693
6694   if (GTK_WIDGET_TOPLEVEL (widget) ||
6695       (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6696     info.new_screen = gtk_widget_get_screen (widget);
6697   else
6698     info.new_screen = NULL;
6699
6700   if (info.previous_screen)
6701     g_object_ref (info.previous_screen);
6702   if (previous_toplevel)
6703     g_object_ref (previous_toplevel);
6704
6705   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6706
6707   if (previous_toplevel)
6708     g_object_unref (previous_toplevel);
6709   if (info.previous_screen)
6710     g_object_unref (info.previous_screen);
6711 }
6712
6713 static void
6714 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6715                                              gpointer   client_data)
6716 {
6717   HierarchyChangedInfo *info = client_data;
6718
6719   g_object_ref (widget);
6720   
6721   do_screen_change (widget, info->previous_screen, info->new_screen);
6722   
6723   if (GTK_IS_CONTAINER (widget))
6724     gtk_container_forall (GTK_CONTAINER (widget),
6725                           gtk_widget_propagate_screen_changed_recurse,
6726                           client_data);
6727   
6728   g_object_unref (widget);
6729 }
6730
6731 /**
6732  * gtk_widget_is_composited:
6733  * @widget: a #GtkWidget
6734  * 
6735  * Whether @widget can rely on having its alpha channel
6736  * drawn correctly. On X11 this function returns whether a
6737  * compositing manager is running for @widget's screen.
6738  *
6739  * Please note that the semantics of this call will change
6740  * in the future if used on a widget that has a composited
6741  * window in its hierarchy (as set by gdk_window_set_composited()).
6742  * 
6743  * Return value: %TRUE if the widget can rely on its alpha
6744  * channel being drawn correctly.
6745  * 
6746  * Since: 2.10
6747  */
6748 gboolean
6749 gtk_widget_is_composited (GtkWidget *widget)
6750 {
6751   GdkScreen *screen;
6752
6753   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6754   
6755   screen = gtk_widget_get_screen (widget);
6756   
6757   return gdk_screen_is_composited (screen);
6758 }
6759
6760 static void
6761 propagate_composited_changed (GtkWidget *widget,
6762                               gpointer dummy)
6763 {
6764   if (GTK_IS_CONTAINER (widget))
6765     {
6766       gtk_container_forall (GTK_CONTAINER (widget),
6767                             propagate_composited_changed,
6768                             NULL);
6769     }
6770   
6771   g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6772 }
6773
6774 void
6775 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6776 {
6777   propagate_composited_changed (widget, NULL);
6778 }
6779
6780 /**
6781  * _gtk_widget_propagate_screen_changed:
6782  * @widget: a #GtkWidget
6783  * @previous_screen: Previous screen
6784  * 
6785  * Propagates changes in the screen for a widget to all
6786  * children, emitting #GtkWidget::screen-changed.
6787  **/
6788 void
6789 _gtk_widget_propagate_screen_changed (GtkWidget    *widget,
6790                                       GdkScreen    *previous_screen)
6791 {
6792   HierarchyChangedInfo info;
6793
6794   info.previous_screen = previous_screen;
6795   info.new_screen = gtk_widget_get_screen (widget);
6796
6797   if (previous_screen)
6798     g_object_ref (previous_screen);
6799
6800   gtk_widget_propagate_screen_changed_recurse (widget, &info);
6801
6802   if (previous_screen)
6803     g_object_unref (previous_screen);
6804 }
6805
6806 static void
6807 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6808 {
6809   if (GTK_WIDGET_RC_STYLE (widget))
6810     gtk_widget_reset_rc_style (widget);
6811   
6812   if (GTK_IS_CONTAINER (widget))
6813     gtk_container_forall (GTK_CONTAINER (widget),
6814                           reset_rc_styles_recurse,
6815                           NULL);
6816 }
6817
6818 void
6819 gtk_widget_reset_rc_styles (GtkWidget *widget)
6820 {
6821   g_return_if_fail (GTK_IS_WIDGET (widget));
6822
6823   reset_rc_styles_recurse (widget, NULL);
6824 }
6825
6826 /**
6827  * gtk_widget_get_default_style:
6828  * 
6829  * Returns the default style used by all widgets initially.
6830  * 
6831  * Returns: the default style. This #GtkStyle object is owned 
6832  *          by GTK+ and should not be modified or freed.
6833  */ 
6834 GtkStyle*
6835 gtk_widget_get_default_style (void)
6836 {
6837   if (!gtk_default_style)
6838     {
6839       gtk_default_style = gtk_style_new ();
6840       g_object_ref (gtk_default_style);
6841     }
6842   
6843   return gtk_default_style;
6844 }
6845
6846 static PangoContext *
6847 gtk_widget_peek_pango_context (GtkWidget *widget)
6848 {
6849   return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6850 }
6851
6852 /**
6853  * gtk_widget_get_pango_context:
6854  * @widget: a #GtkWidget
6855  * 
6856  * Gets a #PangoContext with the appropriate font map, font description,
6857  * and base direction for this widget. Unlike the context returned
6858  * by gtk_widget_create_pango_context(), this context is owned by
6859  * the widget (it can be used until the screen for the widget changes
6860  * or the widget is removed from its toplevel), and will be updated to
6861  * match any changes to the widget's attributes.
6862  *
6863  * If you create and keep a #PangoLayout using this context, you must
6864  * deal with changes to the context by calling pango_layout_context_changed()
6865  * on the layout in response to the #GtkWidget::style-set and 
6866  * #GtkWidget::direction-changed signals for the widget.
6867  *
6868  * Return value: the #PangoContext for the widget.
6869  **/
6870 PangoContext *
6871 gtk_widget_get_pango_context (GtkWidget *widget)
6872 {
6873   PangoContext *context;
6874
6875   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6876   
6877   context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6878   if (!context)
6879     {
6880       context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6881       g_object_set_qdata_full (G_OBJECT (widget),
6882                                quark_pango_context,
6883                                context,
6884                                g_object_unref);
6885     }
6886
6887   return context;
6888 }
6889
6890 static void
6891 update_pango_context (GtkWidget    *widget,
6892                       PangoContext *context)
6893 {
6894   pango_context_set_font_description (context, widget->style->font_desc);
6895   pango_context_set_base_dir (context,
6896                               gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6897                               PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6898 }
6899
6900 static void
6901 gtk_widget_update_pango_context (GtkWidget *widget)
6902 {
6903   PangoContext *context = gtk_widget_peek_pango_context (widget);
6904   
6905   if (context)
6906     {
6907       GdkScreen *screen;
6908
6909       update_pango_context (widget, context);
6910
6911       screen = gtk_widget_get_screen_unchecked (widget);
6912       if (screen)
6913         {
6914           pango_cairo_context_set_resolution (context,
6915                                               gdk_screen_get_resolution (screen));
6916           pango_cairo_context_set_font_options (context,
6917                                                 gdk_screen_get_font_options (screen));
6918         }
6919     }
6920 }
6921
6922 /**
6923  * gtk_widget_create_pango_context:
6924  * @widget: a #GtkWidget
6925  * 
6926  * Creates a new #PangoContext with the appropriate font map,
6927  * font description, and base direction for drawing text for
6928  * this widget. See also gtk_widget_get_pango_context().
6929  * 
6930  * Return value: the new #PangoContext
6931  **/
6932 PangoContext *
6933 gtk_widget_create_pango_context (GtkWidget *widget)
6934 {
6935   GdkScreen *screen;
6936   PangoContext *context;
6937
6938   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6939
6940   screen = gtk_widget_get_screen_unchecked (widget);
6941   if (!screen)
6942     {
6943       GTK_NOTE (MULTIHEAD,
6944                 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6945
6946       screen = gdk_screen_get_default ();
6947     }
6948
6949   context = gdk_pango_context_get_for_screen (screen);
6950
6951   update_pango_context (widget, context);
6952   pango_context_set_language (context, gtk_get_default_language ());
6953
6954   return context;
6955 }
6956
6957 /**
6958  * gtk_widget_create_pango_layout:
6959  * @widget: a #GtkWidget
6960  * @text: text to set on the layout (can be %NULL)
6961  * 
6962  * Creates a new #PangoLayout with the appropriate font map,
6963  * font description, and base direction for drawing text for
6964  * this widget.
6965  *
6966  * If you keep a #PangoLayout created in this way around, in order to
6967  * notify the layout of changes to the base direction or font of this
6968  * widget, you must call pango_layout_context_changed() in response to
6969  * the #GtkWidget::style-set and #GtkWidget::direction-changed signals 
6970  * for the widget.
6971  * 
6972  * Return value: the new #PangoLayout
6973  **/
6974 PangoLayout *
6975 gtk_widget_create_pango_layout (GtkWidget   *widget,
6976                                 const gchar *text)
6977 {
6978   PangoLayout *layout;
6979   PangoContext *context;
6980
6981   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6982
6983   context = gtk_widget_get_pango_context (widget);
6984   layout = pango_layout_new (context);
6985
6986   if (text)
6987     pango_layout_set_text (layout, text, -1);
6988
6989   return layout;
6990 }
6991
6992 /**
6993  * gtk_widget_render_icon:
6994  * @widget: a #GtkWidget
6995  * @stock_id: a stock ID
6996  * @size: a stock size. A size of (GtkIconSize)-1 means render at 
6997  *     the size of the source and don't scale (if there are multiple 
6998  *     source sizes, GTK+ picks one of the available sizes).
6999  * @detail: render detail to pass to theme engine
7000  * 
7001  * A convenience function that uses the theme engine and RC file
7002  * settings for @widget to look up @stock_id and render it to
7003  * a pixbuf. @stock_id should be a stock icon ID such as
7004  * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7005  * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7006  * identifies the widget or code doing the rendering, so that
7007  * theme engines can special-case rendering for that widget or code.
7008  *
7009  * The pixels in the returned #GdkPixbuf are shared with the rest of
7010  * the application and should not be modified. The pixbuf should be freed
7011  * after use with g_object_unref().
7012  *
7013  * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7014  **/
7015 GdkPixbuf*
7016 gtk_widget_render_icon (GtkWidget      *widget,
7017                         const gchar    *stock_id,
7018                         GtkIconSize     size,
7019                         const gchar    *detail)
7020 {
7021   GtkIconSet *icon_set;
7022   GdkPixbuf *retval;
7023   
7024   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7025   g_return_val_if_fail (stock_id != NULL, NULL);
7026   g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7027   
7028   gtk_widget_ensure_style (widget);
7029   
7030   icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7031
7032   if (icon_set == NULL)
7033     return NULL;
7034
7035   retval = gtk_icon_set_render_icon (icon_set,
7036                                      widget->style,
7037                                      gtk_widget_get_direction (widget),
7038                                      GTK_WIDGET_STATE (widget),
7039                                      size,
7040                                      widget,
7041                                      detail);
7042
7043   return retval;
7044 }
7045
7046 /**
7047  * gtk_widget_set_parent_window:
7048  * @widget: a #GtkWidget.
7049  * @parent_window: the new parent window.
7050  *  
7051  * Sets a non default parent window for @widget.
7052  **/
7053 void
7054 gtk_widget_set_parent_window   (GtkWidget           *widget,
7055                                 GdkWindow           *parent_window)
7056 {
7057   GdkWindow *old_parent_window;
7058
7059   g_return_if_fail (GTK_IS_WIDGET (widget));
7060   
7061   old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7062                                           quark_parent_window);
7063
7064   if (parent_window != old_parent_window)
7065     {
7066       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
7067                           parent_window);
7068       if (old_parent_window)
7069         g_object_unref (old_parent_window);
7070       if (parent_window)
7071         g_object_ref (parent_window);
7072     }
7073 }
7074
7075 /**
7076  * gtk_widget_get_parent_window:
7077  * @widget: a #GtkWidget.
7078  * @returns: the parent window of @widget.
7079  *
7080  * Gets @widget's parent window.
7081  **/
7082 GdkWindow *
7083 gtk_widget_get_parent_window (GtkWidget *widget)
7084 {
7085   GdkWindow *parent_window;
7086
7087   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7088
7089   parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7090
7091   return (parent_window != NULL) ? parent_window :
7092          (widget->parent != NULL) ? widget->parent->window : NULL;
7093 }
7094
7095
7096 /**
7097  * gtk_widget_set_child_visible:
7098  * @widget: a #GtkWidget
7099  * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7100  *
7101  * Sets whether @widget should be mapped along with its when its parent
7102  * is mapped and @widget has been shown with gtk_widget_show(). 
7103  *
7104  * The child visibility can be set for widget before it is added to
7105  * a container with gtk_widget_set_parent(), to avoid mapping
7106  * children unnecessary before immediately unmapping them. However
7107  * it will be reset to its default state of %TRUE when the widget
7108  * is removed from a container.
7109  * 
7110  * Note that changing the child visibility of a widget does not
7111  * queue a resize on the widget. Most of the time, the size of
7112  * a widget is computed from all visible children, whether or
7113  * not they are mapped. If this is not the case, the container
7114  * can queue a resize itself.
7115  *
7116  * This function is only useful for container implementations and
7117  * never should be called by an application.
7118  **/
7119 void
7120 gtk_widget_set_child_visible (GtkWidget *widget,
7121                               gboolean   is_visible)
7122 {
7123   g_return_if_fail (GTK_IS_WIDGET (widget));
7124   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
7125
7126   g_object_ref (widget);
7127
7128   if (is_visible)
7129     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7130   else
7131     {
7132       GtkWidget *toplevel;
7133       
7134       GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7135
7136       toplevel = gtk_widget_get_toplevel (widget);
7137       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
7138         _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7139     }
7140
7141   if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
7142     {
7143       if (GTK_WIDGET_MAPPED (widget->parent) &&
7144           GTK_WIDGET_CHILD_VISIBLE (widget) &&
7145           GTK_WIDGET_VISIBLE (widget))
7146         gtk_widget_map (widget);
7147       else
7148         gtk_widget_unmap (widget);
7149     }
7150
7151   g_object_unref (widget);
7152 }
7153
7154 /**
7155  * gtk_widget_get_child_visible:
7156  * @widget: a #GtkWidget
7157  * 
7158  * Gets the value set with gtk_widget_set_child_visible().
7159  * If you feel a need to use this function, your code probably
7160  * needs reorganization. 
7161  *
7162  * This function is only useful for container implementations and
7163  * never should be called by an application.
7164  *
7165  * Return value: %TRUE if the widget is mapped with the parent.
7166  **/
7167 gboolean
7168 gtk_widget_get_child_visible (GtkWidget *widget)
7169 {
7170   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7171   
7172   return GTK_WIDGET_CHILD_VISIBLE (widget);
7173 }
7174
7175 static GdkScreen *
7176 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7177 {
7178   GtkWidget *toplevel;
7179   
7180   toplevel = gtk_widget_get_toplevel (widget);
7181
7182   if (GTK_WIDGET_TOPLEVEL (toplevel))
7183     {
7184       if (GTK_IS_WINDOW (toplevel))
7185         return GTK_WINDOW (toplevel)->screen;
7186       else if (GTK_IS_INVISIBLE (toplevel))
7187         return GTK_INVISIBLE (widget)->screen;
7188     }
7189
7190   return NULL;
7191 }
7192
7193 /**
7194  * gtk_widget_get_screen:
7195  * @widget: a #GtkWidget
7196  * 
7197  * Get the #GdkScreen from the toplevel window associated with
7198  * this widget. This function can only be called after the widget
7199  * has been added to a widget hierarchy with a #GtkWindow
7200  * at the top.
7201  *
7202  * In general, you should only create screen specific
7203  * resources when a widget has been realized, and you should
7204  * free those resources when the widget is unrealized.
7205  * 
7206  * Return value: the #GdkScreen for the toplevel for this widget.
7207  *
7208  * Since: 2.2
7209  **/
7210 GdkScreen*
7211 gtk_widget_get_screen (GtkWidget *widget)
7212 {
7213   GdkScreen *screen;
7214   
7215   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7216
7217   screen = gtk_widget_get_screen_unchecked (widget);
7218
7219   if (screen)
7220     return screen;
7221   else
7222     {
7223 #if 0
7224       g_warning (G_STRLOC ": Can't get associated screen"
7225                  " for a widget unless it is inside a toplevel GtkWindow\n"
7226                  " widget type is %s associated top level type is %s",
7227                  g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7228                  g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7229 #endif
7230       return gdk_screen_get_default ();
7231     }
7232 }
7233
7234 /**
7235  * gtk_widget_has_screen:
7236  * @widget: a #GtkWidget
7237  * 
7238  * Checks whether there is a #GdkScreen is associated with
7239  * this widget. All toplevel widgets have an associated
7240  * screen, and all widgets added into a hierarchy with a toplevel
7241  * window at the top.
7242  * 
7243  * Return value: %TRUE if there is a #GdkScreen associcated
7244  *   with the widget.
7245  *
7246  * Since: 2.2
7247  **/
7248 gboolean
7249 gtk_widget_has_screen (GtkWidget *widget)
7250 {
7251   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7252
7253   return (gtk_widget_get_screen_unchecked (widget) != NULL);
7254 }
7255
7256 /**
7257  * gtk_widget_get_display:
7258  * @widget: a #GtkWidget
7259  * 
7260  * Get the #GdkDisplay for the toplevel window associated with
7261  * this widget. This function can only be called after the widget
7262  * has been added to a widget hierarchy with a #GtkWindow at the top.
7263  *
7264  * In general, you should only create display specific
7265  * resources when a widget has been realized, and you should
7266  * free those resources when the widget is unrealized.
7267  * 
7268  * Return value: the #GdkDisplay for the toplevel for this widget.
7269  *
7270  * Since: 2.2
7271  **/
7272 GdkDisplay*
7273 gtk_widget_get_display (GtkWidget *widget)
7274 {
7275   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7276   
7277   return gdk_screen_get_display (gtk_widget_get_screen (widget));
7278 }
7279
7280 /**
7281  * gtk_widget_get_root_window:
7282  * @widget: a #GtkWidget
7283  * 
7284  * Get the root window where this widget is located. This function can
7285  * only be called after the widget has been added to a widget
7286  * hierarchy with #GtkWindow at the top.
7287  *
7288  * The root window is useful for such purposes as creating a popup
7289  * #GdkWindow associated with the window. In general, you should only
7290  * create display specific resources when a widget has been realized,
7291  * and you should free those resources when the widget is unrealized.
7292  * 
7293  * Return value: the #GdkWindow root window for the toplevel for this widget.
7294  *
7295  * Since: 2.2
7296  **/
7297 GdkWindow*
7298 gtk_widget_get_root_window (GtkWidget *widget)
7299 {
7300   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7301
7302   return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7303 }
7304
7305 /**
7306  * gtk_widget_child_focus:
7307  * @widget: a #GtkWidget
7308  * @direction: direction of focus movement
7309  *
7310  * This function is used by custom widget implementations; if you're
7311  * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7312  * to a particular widget, and gtk_container_set_focus_chain() to
7313  * change the focus tab order. So you may want to investigate those
7314  * functions instead.
7315  * 
7316  * gtk_widget_child_focus() is called by containers as the user moves
7317  * around the window using keyboard shortcuts. @direction indicates
7318  * what kind of motion is taking place (up, down, left, right, tab
7319  * forward, tab backward). gtk_widget_child_focus() emits the
7320  * #GtkWidget::focus" signal; widgets override the default handler
7321  * for this signal in order to implement appropriate focus behavior.
7322  *
7323  * The default ::focus handler for a widget should return %TRUE if
7324  * moving in @direction left the focus on a focusable location inside
7325  * that widget, and %FALSE if moving in @direction moved the focus
7326  * outside the widget. If returning %TRUE, widgets normally
7327  * call gtk_widget_grab_focus() to place the focus accordingly;
7328  * if returning %FALSE, they don't modify the current focus location.
7329  * 
7330  * This function replaces gtk_container_focus() from GTK+ 1.2.  
7331  * It was necessary to check that the child was visible, sensitive, 
7332  * and focusable before calling gtk_container_focus(). 
7333  * gtk_widget_child_focus() returns %FALSE if the widget is not 
7334  * currently in a focusable state, so there's no need for those checks.
7335  * 
7336  * Return value: %TRUE if focus ended up inside @widget
7337  **/
7338 gboolean
7339 gtk_widget_child_focus (GtkWidget       *widget,
7340                         GtkDirectionType direction)
7341 {
7342   gboolean return_val;
7343
7344   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7345
7346   if (!GTK_WIDGET_VISIBLE (widget) ||
7347       !GTK_WIDGET_IS_SENSITIVE (widget))
7348     return FALSE;
7349
7350   /* child widgets must set CAN_FOCUS, containers
7351    * don't have to though.
7352    */
7353   if (!GTK_IS_CONTAINER (widget) &&
7354       !GTK_WIDGET_CAN_FOCUS (widget))
7355     return FALSE;
7356   
7357   g_signal_emit (widget,
7358                  widget_signals[FOCUS],
7359                  0,
7360                  direction, &return_val);
7361
7362   return return_val;
7363 }
7364
7365 /**
7366  * gtk_widget_keynav_failed:
7367  * @widget: a #GtkWidget
7368  * @direction: direction of focus movement
7369  *
7370  * This function should be called whenever keyboard navigation within
7371  * a single widget hits a boundary. The function emits the
7372  * #GtkWidget::keynav-failed signal on the widget and its return
7373  * value should be interpreted in a way similar to the return value of
7374  * gtk_widget_child_focus():
7375  *
7376  * When %TRUE is returned, stay in the widget, the failed keyboard
7377  * navigation is Ok and/or there is nowhere we can/should move the
7378  * focus to.
7379  *
7380  * When %FALSE is returned, the caller should continue with keyboard
7381  * navigation outside the widget, e.g. by calling
7382  * gtk_widget_child_focus() on the widget's toplevel.
7383  *
7384  * The default ::keynav-failed handler returns %TRUE for 
7385  * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other 
7386  * values of #GtkDirectionType, it looks at the 
7387  * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE 
7388  * if the setting is %TRUE. This way the entire user interface
7389  * becomes cursor-navigatable on input devices such as mobile phones
7390  * which only have cursor keys but no tab key.
7391  *
7392  * Whenever the default handler returns %TRUE, it also calls
7393  * gtk_widget_error_bell() to notify the user of the failed keyboard
7394  * navigation.
7395  *
7396  * A use case for providing an own implementation of ::keynav-failed 
7397  * (either by connecting to it or by overriding it) would be a row of
7398  * #GtkEntry widgets where the user should be able to navigate the
7399  * entire row with the cursor keys, as e.g. known from user interfaces 
7400  * that require entering license keys.
7401  *
7402  * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7403  *               if the emitting widget should try to handle the keyboard
7404  *               navigation attempt in its parent container(s).
7405  *
7406  * Since: 2.12
7407  **/
7408 gboolean
7409 gtk_widget_keynav_failed (GtkWidget        *widget,
7410                           GtkDirectionType  direction)
7411 {
7412   gboolean return_val;
7413
7414   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7415
7416   g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7417                  direction, &return_val);
7418
7419   return return_val;
7420 }
7421
7422 /**
7423  * gtk_widget_error_bell:
7424  * @widget: a #GtkWidget
7425  *
7426  * Notifies the user about an input-related error on this widget. 
7427  * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7428  * gdk_window_beep(), otherwise it does nothing.
7429  *
7430  * Note that the effect of gdk_window_beep() can be configured in many
7431  * ways, depending on the windowing backend and the desktop environment
7432  * or window manager that is used.
7433  *
7434  * Since: 2.12
7435  **/
7436 void
7437 gtk_widget_error_bell (GtkWidget *widget)
7438 {
7439   GtkSettings* settings;
7440   gboolean beep;
7441
7442   g_return_if_fail (GTK_IS_WIDGET (widget));
7443
7444   settings = gtk_widget_get_settings (widget);
7445   if (!settings)
7446     return;
7447
7448   g_object_get (settings,
7449                 "gtk-error-bell", &beep,
7450                 NULL);
7451
7452   if (beep && widget->window)
7453     gdk_window_beep (widget->window);
7454 }
7455
7456 /**
7457  * gtk_widget_set_uposition:
7458  * @widget: a #GtkWidget
7459  * @x: x position; -1 to unset x; -2 to leave x unchanged
7460  * @y: y position; -1 to unset y; -2 to leave y unchanged
7461  * 
7462  *
7463  * Sets the position of a widget. The funny "u" in the name comes from
7464  * the "user position" hint specified by the X Window System, and
7465  * exists for legacy reasons. This function doesn't work if a widget
7466  * is inside a container; it's only really useful on #GtkWindow.
7467  *
7468  * Don't use this function to center dialogs over the main application
7469  * window; most window managers will do the centering on your behalf
7470  * if you call gtk_window_set_transient_for(), and it's really not
7471  * possible to get the centering to work correctly in all cases from
7472  * application code. But if you insist, use gtk_window_set_position()
7473  * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7474  * manually.
7475  *
7476  * Note that although @x and @y can be individually unset, the position
7477  * is not honoured unless both @x and @y are set.
7478  **/
7479 void
7480 gtk_widget_set_uposition (GtkWidget *widget,
7481                           gint       x,
7482                           gint       y)
7483 {
7484   /* FIXME this function is the only place that aux_info->x and
7485    * aux_info->y are even used I believe, and this function is
7486    * deprecated. Should be cleaned up.
7487    *
7488    * (Actually, size_allocate uses them) -Yosh
7489    */
7490   
7491   GtkWidgetAuxInfo *aux_info;
7492   
7493   g_return_if_fail (GTK_IS_WIDGET (widget));
7494   
7495   aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7496   
7497   if (x > -2)
7498     {
7499       if (x == -1)
7500         aux_info->x_set = FALSE;
7501       else
7502         {
7503           aux_info->x_set = TRUE;
7504           aux_info->x = x;
7505         }
7506     }
7507
7508   if (y > -2)
7509     {
7510       if (y == -1)
7511         aux_info->y_set = FALSE;
7512       else
7513         {
7514           aux_info->y_set = TRUE;
7515           aux_info->y = y;
7516         }
7517     }
7518
7519   if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7520     _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7521   
7522   if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7523     gtk_widget_size_allocate (widget, &widget->allocation);
7524 }
7525
7526 static void
7527 gtk_widget_set_usize_internal (GtkWidget *widget,
7528                                gint       width,
7529                                gint       height)
7530 {
7531   GtkWidgetAuxInfo *aux_info;
7532   gboolean changed = FALSE;
7533   
7534   g_object_freeze_notify (G_OBJECT (widget));
7535
7536   aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7537   
7538   if (width > -2 && aux_info->width != width)
7539     {
7540       g_object_notify (G_OBJECT (widget), "width-request");
7541       aux_info->width = width;
7542       changed = TRUE;
7543     }
7544   if (height > -2 && aux_info->height != height)
7545     {
7546       g_object_notify (G_OBJECT (widget), "height-request");  
7547       aux_info->height = height;
7548       changed = TRUE;
7549     }
7550   
7551   if (GTK_WIDGET_VISIBLE (widget) && changed)
7552     gtk_widget_queue_resize (widget);
7553
7554   g_object_thaw_notify (G_OBJECT (widget));
7555 }
7556
7557 /**
7558  * gtk_widget_set_usize:
7559  * @widget: a #GtkWidget
7560  * @width: minimum width, or -1 to unset
7561  * @height: minimum height, or -1 to unset
7562  *
7563  * Sets the minimum size of a widget; that is, the widget's size
7564  * request will be @width by @height. You can use this function to
7565  * force a widget to be either larger or smaller than it is. The
7566  * strange "usize" name dates from the early days of GTK+, and derives
7567  * from X Window System terminology. In many cases,
7568  * gtk_window_set_default_size() is a better choice for toplevel
7569  * windows than this function; setting the default size will still
7570  * allow users to shrink the window. Setting the usize will force them
7571  * to leave the window at least as large as the usize. When dealing
7572  * with window sizes, gtk_window_set_geometry_hints() can be a useful
7573  * function as well.
7574  * 
7575  * Note the inherent danger of setting any fixed size - themes,
7576  * translations into other languages, different fonts, and user action
7577  * can all change the appropriate size for a given widget. So, it's
7578  * basically impossible to hardcode a size that will always be
7579  * correct.
7580  * 
7581  * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7582  **/
7583 void
7584 gtk_widget_set_usize (GtkWidget *widget,
7585                       gint       width,
7586                       gint       height)
7587 {
7588   g_return_if_fail (GTK_IS_WIDGET (widget));
7589   
7590   gtk_widget_set_usize_internal (widget, width, height);
7591 }
7592
7593 /**
7594  * gtk_widget_set_size_request:
7595  * @widget: a #GtkWidget
7596  * @width: width @widget should request, or -1 to unset
7597  * @height: height @widget should request, or -1 to unset
7598  *
7599  * Sets the minimum size of a widget; that is, the widget's size
7600  * request will be @width by @height. You can use this function to
7601  * force a widget to be either larger or smaller than it normally
7602  * would be.
7603  *
7604  * In most cases, gtk_window_set_default_size() is a better choice for
7605  * toplevel windows than this function; setting the default size will
7606  * still allow users to shrink the window. Setting the size request
7607  * will force them to leave the window at least as large as the size
7608  * request. When dealing with window sizes,
7609  * gtk_window_set_geometry_hints() can be a useful function as well.
7610  * 
7611  * Note the inherent danger of setting any fixed size - themes,
7612  * translations into other languages, different fonts, and user action
7613  * can all change the appropriate size for a given widget. So, it's
7614  * basically impossible to hardcode a size that will always be
7615  * correct.
7616  *
7617  * The size request of a widget is the smallest size a widget can
7618  * accept while still functioning well and drawing itself correctly.
7619  * However in some strange cases a widget may be allocated less than
7620  * its requested size, and in many cases a widget may be allocated more
7621  * space than it requested.
7622  *
7623  * If the size request in a given direction is -1 (unset), then
7624  * the "natural" size request of the widget will be used instead.
7625  *
7626  * Widgets can't actually be allocated a size less than 1 by 1, but
7627  * you can pass 0,0 to this function to mean "as small as possible."
7628  **/
7629 void
7630 gtk_widget_set_size_request (GtkWidget *widget,
7631                              gint       width,
7632                              gint       height)
7633 {
7634   g_return_if_fail (GTK_IS_WIDGET (widget));
7635   g_return_if_fail (width >= -1);
7636   g_return_if_fail (height >= -1);
7637
7638   if (width == 0)
7639     width = 1;
7640   if (height == 0)
7641     height = 1;
7642   
7643   gtk_widget_set_usize_internal (widget, width, height);
7644 }
7645
7646
7647 /**
7648  * gtk_widget_get_size_request:
7649  * @widget: a #GtkWidget
7650  * @width: return location for width, or %NULL
7651  * @height: return location for height, or %NULL
7652  *
7653  * Gets the size request that was explicitly set for the widget using
7654  * gtk_widget_set_size_request(). A value of -1 stored in @width or
7655  * @height indicates that that dimension has not been set explicitly
7656  * and the natural requisition of the widget will be used intead. See
7657  * gtk_widget_set_size_request(). To get the size a widget will
7658  * actually use, call gtk_widget_size_request() instead of
7659  * this function.
7660  **/
7661 void
7662 gtk_widget_get_size_request (GtkWidget *widget,
7663                              gint      *width,
7664                              gint      *height)
7665 {
7666   GtkWidgetAuxInfo *aux_info;
7667
7668   g_return_if_fail (GTK_IS_WIDGET (widget));
7669
7670   aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7671
7672   if (width)
7673     *width = aux_info ? aux_info->width : -1;
7674
7675   if (height)
7676     *height = aux_info ? aux_info->height : -1;
7677 }
7678
7679 /**
7680  * gtk_widget_set_events:
7681  * @widget: a #GtkWidget
7682  * @events: event mask
7683  *
7684  * Sets the event mask (see #GdkEventMask) for a widget. The event
7685  * mask determines which events a widget will receive. Keep in mind
7686  * that different widgets have different default event masks, and by
7687  * changing the event mask you may disrupt a widget's functionality,
7688  * so be careful. This function must be called while a widget is
7689  * unrealized. Consider gtk_widget_add_events() for widgets that are
7690  * already realized, or if you want to preserve the existing event
7691  * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7692  * to get events on those widgets, place them inside a #GtkEventBox
7693  * and receive events on the event box.
7694  **/
7695 void
7696 gtk_widget_set_events (GtkWidget *widget,
7697                        gint       events)
7698 {
7699   g_return_if_fail (GTK_IS_WIDGET (widget));
7700   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7701   
7702   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7703                       GINT_TO_POINTER (events));
7704   g_object_notify (G_OBJECT (widget), "events");
7705 }
7706
7707 static void
7708 gtk_widget_add_events_internal (GtkWidget *widget,
7709                                 gint       events,
7710                                 GList     *window_list)
7711 {
7712   GList *l;
7713
7714   for (l = window_list; l != NULL; l = l->next)
7715     {
7716       GdkWindow *window = l->data;
7717       gpointer user_data;
7718
7719       gdk_window_get_user_data (window, &user_data);
7720       if (user_data == widget)
7721         {
7722           GList *children;
7723
7724           gdk_window_set_events (window, gdk_window_get_events (window) | events);
7725
7726           children = gdk_window_get_children (window);
7727           gtk_widget_add_events_internal (widget, events, children);
7728           g_list_free (children);
7729         }
7730     }
7731 }
7732
7733 /**
7734  * gtk_widget_add_events:
7735  * @widget: a #GtkWidget
7736  * @events: an event mask, see #GdkEventMask
7737  *
7738  * Adds the events in the bitfield @events to the event mask for
7739  * @widget. See gtk_widget_set_events() for details.
7740  **/
7741 void
7742 gtk_widget_add_events (GtkWidget *widget,
7743                        gint       events)
7744 {
7745   gint old_events;
7746
7747   g_return_if_fail (GTK_IS_WIDGET (widget));
7748
7749   old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7750   g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7751                       GINT_TO_POINTER (old_events | events));
7752
7753   if (GTK_WIDGET_REALIZED (widget))
7754     {
7755       GList *window_list;
7756
7757       if (GTK_WIDGET_NO_WINDOW (widget))
7758         window_list = gdk_window_get_children (widget->window);
7759       else
7760         window_list = g_list_prepend (NULL, widget->window);
7761
7762       gtk_widget_add_events_internal (widget, events, window_list);
7763
7764       g_list_free (window_list);
7765     }
7766
7767   g_object_notify (G_OBJECT (widget), "events");
7768 }
7769
7770 /**
7771  * gtk_widget_set_extension_events:
7772  * @widget: a #GtkWidget
7773  * @mode: bitfield of extension events to receive
7774  *
7775  * Sets the extension events mask to @mode. See #GdkExtensionMode
7776  * and gdk_input_set_extension_events().
7777  **/
7778 void
7779 gtk_widget_set_extension_events (GtkWidget *widget,
7780                                  GdkExtensionMode mode)
7781 {
7782   g_return_if_fail (GTK_IS_WIDGET (widget));
7783
7784   if (GTK_WIDGET_REALIZED (widget))
7785     gtk_widget_set_extension_events_internal (widget, mode, NULL);
7786
7787   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7788                       GINT_TO_POINTER (mode));
7789   g_object_notify (G_OBJECT (widget), "extension-events");
7790 }
7791
7792 /**
7793  * gtk_widget_get_toplevel:
7794  * @widget: a #GtkWidget
7795  * 
7796  * This function returns the topmost widget in the container hierarchy
7797  * @widget is a part of. If @widget has no parent widgets, it will be
7798  * returned as the topmost widget. No reference will be added to the
7799  * returned widget; it should not be unreferenced.
7800  *
7801  * Note the difference in behavior vs. gtk_widget_get_ancestor();
7802  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal> 
7803  * would return
7804  * %NULL if @widget wasn't inside a toplevel window, and if the
7805  * window was inside a #GtkWindow-derived widget which was in turn
7806  * inside the toplevel #GtkWindow. While the second case may
7807  * seem unlikely, it actually happens when a #GtkPlug is embedded
7808  * inside a #GtkSocket within the same application.
7809  * 
7810  * To reliably find the toplevel #GtkWindow, use
7811  * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7812  * is set on the result.
7813  * |[
7814  *  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7815  *  if (GTK_WIDGET_TOPLEVEL (toplevel))
7816  *    {
7817  *      /&ast; Perform action on toplevel. &ast;/
7818  *    }
7819  * ]|
7820  *
7821  * Return value: the topmost ancestor of @widget, or @widget itself 
7822  *    if there's no ancestor.
7823  **/
7824 GtkWidget*
7825 gtk_widget_get_toplevel (GtkWidget *widget)
7826 {
7827   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7828   
7829   while (widget->parent)
7830     widget = widget->parent;
7831   
7832   return widget;
7833 }
7834
7835 /**
7836  * gtk_widget_get_ancestor:
7837  * @widget: a #GtkWidget
7838  * @widget_type: ancestor type
7839  * 
7840  * Gets the first ancestor of @widget with type @widget_type. For example,
7841  * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets 
7842  * the first #GtkBox that's an ancestor of @widget. No reference will be 
7843  * added to the returned widget; it should not be unreferenced. See note 
7844  * about checking for a toplevel #GtkWindow in the docs for 
7845  * gtk_widget_get_toplevel().
7846  * 
7847  * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor() 
7848  * considers @widget to be an ancestor of itself.
7849  *
7850  * Return value: the ancestor widget, or %NULL if not found
7851  **/
7852 GtkWidget*
7853 gtk_widget_get_ancestor (GtkWidget *widget,
7854                          GType      widget_type)
7855 {
7856   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7857   
7858   while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7859     widget = widget->parent;
7860   
7861   if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7862     return NULL;
7863   
7864   return widget;
7865 }
7866
7867 /**
7868  * gtk_widget_get_colormap:
7869  * @widget: a #GtkWidget
7870  * 
7871  * Gets the colormap that will be used to render @widget. No reference will
7872  * be added to the returned colormap; it should not be unreferenced.
7873  * 
7874  * Return value: the colormap used by @widget
7875  **/
7876 GdkColormap*
7877 gtk_widget_get_colormap (GtkWidget *widget)
7878 {
7879   GdkColormap *colormap;
7880   GtkWidget *tmp_widget;
7881   
7882   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7883   
7884   if (widget->window)
7885     {
7886       colormap = gdk_drawable_get_colormap (widget->window);
7887       /* If window was destroyed previously, we'll get NULL here */
7888       if (colormap)
7889         return colormap;
7890     }
7891
7892   tmp_widget = widget;
7893   while (tmp_widget)
7894     {
7895       colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7896       if (colormap)
7897         return colormap;
7898
7899       tmp_widget= tmp_widget->parent;
7900     }
7901
7902   return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7903 }
7904
7905 /**
7906  * gtk_widget_get_visual:
7907  * @widget: a #GtkWidget
7908  * 
7909  * Gets the visual that will be used to render @widget.
7910  * 
7911  * Return value: the visual for @widget
7912  **/
7913 GdkVisual*
7914 gtk_widget_get_visual (GtkWidget *widget)
7915 {
7916   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7917
7918   return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7919 }
7920
7921 /**
7922  * gtk_widget_get_settings:
7923  * @widget: a #GtkWidget
7924  * 
7925  * Gets the settings object holding the settings (global property
7926  * settings, RC file information, etc) used for this widget.
7927  *
7928  * Note that this function can only be called when the #GtkWidget
7929  * is attached to a toplevel, since the settings object is specific
7930  * to a particular #GdkScreen.
7931  * 
7932  * Return value: the relevant #GtkSettings object
7933  **/
7934 GtkSettings*
7935 gtk_widget_get_settings (GtkWidget *widget)
7936 {
7937   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7938   
7939   return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7940 }
7941
7942 /**
7943  * gtk_widget_set_colormap:
7944  * @widget: a #GtkWidget
7945  * @colormap: a colormap
7946  *
7947  * Sets the colormap for the widget to the given value. Widget must not
7948  * have been previously realized. This probably should only be used
7949  * from an <function>init()</function> function (i.e. from the constructor 
7950  * for the widget).
7951  **/
7952 void
7953 gtk_widget_set_colormap (GtkWidget   *widget,
7954                          GdkColormap *colormap)
7955 {
7956   g_return_if_fail (GTK_IS_WIDGET (widget));
7957   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7958   g_return_if_fail (GDK_IS_COLORMAP (colormap));
7959
7960   g_object_ref (colormap);
7961   
7962   g_object_set_qdata_full (G_OBJECT (widget), 
7963                            quark_colormap,
7964                            colormap,
7965                            g_object_unref);
7966 }
7967
7968 /**
7969  * gtk_widget_get_events:
7970  * @widget: a #GtkWidget
7971  * 
7972  * Returns the event mask for the widget (a bitfield containing flags
7973  * from the #GdkEventMask enumeration). These are the events that the widget
7974  * will receive.
7975  * 
7976  * Return value: event mask for @widget
7977  **/
7978 gint
7979 gtk_widget_get_events (GtkWidget *widget)
7980 {
7981   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7982
7983   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7984 }
7985
7986 /**
7987  * gtk_widget_get_extension_events:
7988  * @widget: a #GtkWidget
7989  * 
7990  * Retrieves the extension events the widget will receive; see
7991  * gdk_input_set_extension_events().
7992  * 
7993  * Return value: extension events for @widget
7994  **/
7995 GdkExtensionMode
7996 gtk_widget_get_extension_events (GtkWidget *widget)
7997 {
7998   g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7999
8000   return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8001 }
8002
8003 /**
8004  * gtk_widget_get_pointer:
8005  * @widget: a #GtkWidget
8006  * @x: return location for the X coordinate, or %NULL
8007  * @y: return location for the Y coordinate, or %NULL
8008  *
8009  * Obtains the location of the mouse pointer in widget coordinates.
8010  * Widget coordinates are a bit odd; for historical reasons, they are
8011  * defined as @widget->window coordinates for widgets that are not
8012  * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8013  * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8014  **/
8015 void
8016 gtk_widget_get_pointer (GtkWidget *widget,
8017                         gint      *x,
8018                         gint      *y)
8019 {
8020   g_return_if_fail (GTK_IS_WIDGET (widget));
8021   
8022   if (x)
8023     *x = -1;
8024   if (y)
8025     *y = -1;
8026   
8027   if (GTK_WIDGET_REALIZED (widget))
8028     {
8029       gdk_window_get_pointer (widget->window, x, y, NULL);
8030       
8031       if (GTK_WIDGET_NO_WINDOW (widget))
8032         {
8033           if (x)
8034             *x -= widget->allocation.x;
8035           if (y)
8036             *y -= widget->allocation.y;
8037         }
8038     }
8039 }
8040
8041 /**
8042  * gtk_widget_is_ancestor:
8043  * @widget: a #GtkWidget
8044  * @ancestor: another #GtkWidget
8045  * 
8046  * Determines whether @widget is somewhere inside @ancestor, possibly with
8047  * intermediate containers.
8048  * 
8049  * Return value: %TRUE if @ancestor contains @widget as a child, 
8050  *    grandchild, great grandchild, etc.
8051  **/
8052 gboolean
8053 gtk_widget_is_ancestor (GtkWidget *widget,
8054                         GtkWidget *ancestor)
8055 {
8056   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8057   g_return_val_if_fail (ancestor != NULL, FALSE);
8058   
8059   while (widget)
8060     {
8061       if (widget->parent == ancestor)
8062         return TRUE;
8063       widget = widget->parent;
8064     }
8065   
8066   return FALSE;
8067 }
8068
8069 static GQuark quark_composite_name = 0;
8070
8071 /**
8072  * gtk_widget_set_composite_name:
8073  * @widget: a #GtkWidget.
8074  * @name: the name to set
8075  * 
8076  * Sets a widgets composite name. The widget must be
8077  * a composite child of its parent; see gtk_widget_push_composite_child().
8078  **/
8079 void
8080 gtk_widget_set_composite_name (GtkWidget   *widget,
8081                                const gchar *name)
8082 {
8083   g_return_if_fail (GTK_IS_WIDGET (widget));
8084   g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
8085   g_return_if_fail (name != NULL);
8086
8087   if (!quark_composite_name)
8088     quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8089
8090   g_object_set_qdata_full (G_OBJECT (widget),
8091                            quark_composite_name,
8092                            g_strdup (name),
8093                            g_free);
8094 }
8095
8096 /**
8097  * gtk_widget_get_composite_name:
8098  * @widget: a #GtkWidget
8099  *
8100  * Obtains the composite name of a widget. 
8101  *
8102  * Returns: the composite name of @widget, or %NULL if @widget is not
8103  *   a composite child. The string should be freed when it is no 
8104  *   longer needed.
8105  **/
8106 gchar*
8107 gtk_widget_get_composite_name (GtkWidget *widget)
8108 {
8109   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8110
8111   if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
8112     return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8113                                                widget);
8114   else
8115     return NULL;
8116 }
8117
8118 /**
8119  * gtk_widget_push_composite_child:
8120  * 
8121  * Makes all newly-created widgets as composite children until
8122  * the corresponding gtk_widget_pop_composite_child() call.
8123  * 
8124  * A composite child is a child that's an implementation detail of the
8125  * container it's inside and should not be visible to people using the
8126  * container. Composite children aren't treated differently by GTK (but
8127  * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI 
8128  * builders might want to treat them in a different way.
8129  * 
8130  * Here is a simple example:
8131  * |[
8132  *   gtk_widget_push_composite_child ();
8133  *   scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8134  *   gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8135  *   gtk_widget_pop_composite_child ();
8136  *   gtk_widget_set_parent (scrolled_window->hscrollbar, 
8137  *                          GTK_WIDGET (scrolled_window));
8138  *   g_object_ref (scrolled_window->hscrollbar);
8139  * ]|
8140  **/
8141 void
8142 gtk_widget_push_composite_child (void)
8143 {
8144   composite_child_stack++;
8145 }
8146
8147 /**
8148  * gtk_widget_pop_composite_child:
8149  *
8150  * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8151  **/ 
8152 void
8153 gtk_widget_pop_composite_child (void)
8154 {
8155   if (composite_child_stack)
8156     composite_child_stack--;
8157 }
8158
8159 /**
8160  * gtk_widget_push_colormap:
8161  * @cmap: a #GdkColormap
8162  *
8163  * Pushes @cmap onto a global stack of colormaps; the topmost
8164  * colormap on the stack will be used to create all widgets.
8165  * Remove @cmap with gtk_widget_pop_colormap(). There's little
8166  * reason to use this function.
8167  **/
8168 void
8169 gtk_widget_push_colormap (GdkColormap *cmap)
8170 {
8171   g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8172
8173   colormap_stack = g_slist_prepend (colormap_stack, cmap);
8174 }
8175
8176 /**
8177  * gtk_widget_pop_colormap:
8178  *
8179  * Removes a colormap pushed with gtk_widget_push_colormap().
8180  **/
8181 void
8182 gtk_widget_pop_colormap (void)
8183 {
8184   if (colormap_stack)
8185     colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8186 }
8187
8188 /**
8189  * gtk_widget_set_default_colormap:
8190  * @colormap: a #GdkColormap
8191  * 
8192  * Sets the default colormap to use when creating widgets.
8193  * gtk_widget_push_colormap() is a better function to use if
8194  * you only want to affect a few widgets, rather than all widgets.
8195  **/
8196 void
8197 gtk_widget_set_default_colormap (GdkColormap *colormap)
8198 {
8199   g_return_if_fail (GDK_IS_COLORMAP (colormap));
8200   
8201   gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8202                                    colormap);
8203 }
8204
8205 /**
8206  * gtk_widget_get_default_colormap:
8207  * 
8208  * Obtains the default colormap used to create widgets.
8209  * 
8210  * Return value: default widget colormap
8211  **/
8212 GdkColormap*
8213 gtk_widget_get_default_colormap (void)
8214 {
8215   return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8216 }
8217
8218 /**
8219  * gtk_widget_get_default_visual:
8220  * 
8221  * Obtains the visual of the default colormap. Not really useful;
8222  * used to be useful before gdk_colormap_get_visual() existed.
8223  * 
8224  * Return value: visual of the default colormap
8225  **/
8226 GdkVisual*
8227 gtk_widget_get_default_visual (void)
8228 {
8229   return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8230 }
8231
8232 static void
8233 gtk_widget_emit_direction_changed (GtkWidget        *widget,
8234                                    GtkTextDirection  old_dir)
8235 {
8236   gtk_widget_update_pango_context (widget);
8237   
8238   g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8239 }
8240
8241 /**
8242  * gtk_widget_set_direction:
8243  * @widget: a #GtkWidget
8244  * @dir:    the new direction
8245  * 
8246  * Sets the reading direction on a particular widget. This direction
8247  * controls the primary direction for widgets containing text,
8248  * and also the direction in which the children of a container are
8249  * packed. The ability to set the direction is present in order
8250  * so that correct localization into languages with right-to-left
8251  * reading directions can be done. Generally, applications will
8252  * let the default reading direction present, except for containers
8253  * where the containers are arranged in an order that is explicitely
8254  * visual rather than logical (such as buttons for text justification).
8255  *
8256  * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8257  * set by gtk_widget_set_default_direction() will be used.
8258  **/
8259 void
8260 gtk_widget_set_direction (GtkWidget        *widget,
8261                           GtkTextDirection  dir)
8262 {
8263   GtkTextDirection old_dir;
8264   
8265   g_return_if_fail (GTK_IS_WIDGET (widget));
8266   g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8267
8268   old_dir = gtk_widget_get_direction (widget);
8269   
8270   if (dir == GTK_TEXT_DIR_NONE)
8271     GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8272   else
8273     {
8274       GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8275       if (dir == GTK_TEXT_DIR_LTR)
8276         GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8277       else
8278         GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8279     }
8280
8281   if (old_dir != gtk_widget_get_direction (widget))
8282     gtk_widget_emit_direction_changed (widget, old_dir);
8283 }
8284
8285 /**
8286  * gtk_widget_get_direction:
8287  * @widget: a #GtkWidget
8288  * 
8289  * Gets the reading direction for a particular widget. See
8290  * gtk_widget_set_direction().
8291  * 
8292  * Return value: the reading direction for the widget.
8293  **/
8294 GtkTextDirection
8295 gtk_widget_get_direction (GtkWidget *widget)
8296 {
8297   g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8298   
8299   if (GTK_WIDGET_DIRECTION_SET (widget))
8300     return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8301   else
8302     return gtk_default_direction;
8303 }
8304
8305 static void
8306 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8307 {
8308   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8309
8310   g_object_ref (widget);
8311   
8312   if (!GTK_WIDGET_DIRECTION_SET (widget))
8313     gtk_widget_emit_direction_changed (widget, old_dir);
8314   
8315   if (GTK_IS_CONTAINER (widget))
8316     gtk_container_forall (GTK_CONTAINER (widget),
8317                           gtk_widget_set_default_direction_recurse,
8318                           data);
8319
8320   g_object_unref (widget);
8321 }
8322
8323 /**
8324  * gtk_widget_set_default_direction:
8325  * @dir: the new default direction. This cannot be
8326  *        %GTK_TEXT_DIR_NONE.
8327  * 
8328  * Sets the default reading direction for widgets where the
8329  * direction has not been explicitly set by gtk_widget_set_direction().
8330  **/
8331 void
8332 gtk_widget_set_default_direction (GtkTextDirection dir)
8333 {
8334   g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8335
8336   if (dir != gtk_default_direction)
8337     {
8338       GList *toplevels, *tmp_list;
8339       GtkTextDirection old_dir = gtk_default_direction;
8340       
8341       gtk_default_direction = dir;
8342
8343       tmp_list = toplevels = gtk_window_list_toplevels ();
8344       g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8345       
8346       while (tmp_list)
8347         {
8348           gtk_widget_set_default_direction_recurse (tmp_list->data,
8349                                                     GUINT_TO_POINTER (old_dir));
8350           g_object_unref (tmp_list->data);
8351           tmp_list = tmp_list->next;
8352         }
8353
8354       g_list_free (toplevels);
8355     }
8356 }
8357
8358 /**
8359  * gtk_widget_get_default_direction:
8360  * 
8361  * Obtains the current default reading direction. See
8362  * gtk_widget_set_default_direction().
8363  *
8364  * Return value: the current default direction. 
8365  **/
8366 GtkTextDirection
8367 gtk_widget_get_default_direction (void)
8368 {
8369   return gtk_default_direction;
8370 }
8371
8372 static void
8373 gtk_widget_dispose (GObject *object)
8374 {
8375   GtkWidget *widget = GTK_WIDGET (object);
8376
8377   if (widget->parent)
8378     gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8379   else if (GTK_WIDGET_VISIBLE (widget))
8380     gtk_widget_hide (widget);
8381
8382   GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8383   if (GTK_WIDGET_REALIZED (widget))
8384     gtk_widget_unrealize (widget);
8385   
8386   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8387 }
8388
8389 static void
8390 gtk_widget_real_destroy (GtkObject *object)
8391 {
8392   /* gtk_object_destroy() will already hold a refcount on object */
8393   GtkWidget *widget = GTK_WIDGET (object);
8394
8395   /* wipe accelerator closures (keep order) */
8396   g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8397   g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8398
8399   /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8400   g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8401   
8402   gtk_grab_remove (widget);
8403   
8404   g_object_unref (widget->style);
8405   widget->style = gtk_widget_get_default_style ();
8406   g_object_ref (widget->style);
8407
8408   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8409 }
8410
8411 static void
8412 gtk_widget_finalize (GObject *object)
8413 {
8414   GtkWidget *widget = GTK_WIDGET (object);
8415   GtkWidgetAuxInfo *aux_info;
8416   GtkAccessible *accessible;
8417   
8418   gtk_grab_remove (widget);
8419
8420   g_object_unref (widget->style);
8421   widget->style = NULL;
8422
8423   g_free (widget->name);
8424   
8425   aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8426   if (aux_info)
8427     gtk_widget_aux_info_destroy (aux_info);
8428
8429   accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8430   if (accessible)
8431     g_object_unref (accessible);
8432
8433   G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8434 }
8435
8436 /*****************************************
8437  * gtk_widget_real_map:
8438  *
8439  *   arguments:
8440  *
8441  *   results:
8442  *****************************************/
8443
8444 static void
8445 gtk_widget_real_map (GtkWidget *widget)
8446 {
8447   g_assert (GTK_WIDGET_REALIZED (widget));
8448   
8449   if (!GTK_WIDGET_MAPPED (widget))
8450     {
8451       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
8452       
8453       if (!GTK_WIDGET_NO_WINDOW (widget))
8454         gdk_window_show (widget->window);
8455     }
8456 }
8457
8458 /*****************************************
8459  * gtk_widget_real_unmap:
8460  *
8461  *   arguments:
8462  *
8463  *   results:
8464  *****************************************/
8465
8466 static void
8467 gtk_widget_real_unmap (GtkWidget *widget)
8468 {
8469   if (GTK_WIDGET_MAPPED (widget))
8470     {
8471       GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8472
8473       if (!GTK_WIDGET_NO_WINDOW (widget))
8474         gdk_window_hide (widget->window);
8475     }
8476 }
8477
8478 /*****************************************
8479  * gtk_widget_real_realize:
8480  *
8481  *   arguments:
8482  *
8483  *   results:
8484  *****************************************/
8485
8486 static void
8487 gtk_widget_real_realize (GtkWidget *widget)
8488 {
8489   g_assert (GTK_WIDGET_NO_WINDOW (widget));
8490   
8491   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8492   if (widget->parent)
8493     {
8494       widget->window = gtk_widget_get_parent_window (widget);
8495       g_object_ref (widget->window);
8496     }
8497   widget->style = gtk_style_attach (widget->style, widget->window);
8498 }
8499
8500 /*****************************************
8501  * gtk_widget_real_unrealize:
8502  *
8503  *   arguments:
8504  *
8505  *   results:
8506  *****************************************/
8507
8508 static void
8509 gtk_widget_real_unrealize (GtkWidget *widget)
8510 {
8511   if (GTK_WIDGET_MAPPED (widget))
8512     gtk_widget_real_unmap (widget);
8513
8514   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8515
8516   /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8517    */
8518
8519    /* We must do unrealize child widget BEFORE container widget.
8520     * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8521     * So, unrealizing container widget bofore its children causes the problem 
8522     * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8523     */
8524
8525   if (GTK_IS_CONTAINER (widget))
8526     gtk_container_forall (GTK_CONTAINER (widget),
8527                           (GtkCallback) gtk_widget_unrealize,
8528                           NULL);
8529
8530   gtk_style_detach (widget->style);
8531   if (!GTK_WIDGET_NO_WINDOW (widget))
8532     {
8533       gdk_window_set_user_data (widget->window, NULL);
8534       gdk_window_destroy (widget->window);
8535       widget->window = NULL;
8536     }
8537   else
8538     {
8539       g_object_unref (widget->window);
8540       widget->window = NULL;
8541     }
8542
8543   gtk_selection_remove_all (widget);
8544   
8545   GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8546 }
8547
8548 static void
8549 gtk_widget_real_size_request (GtkWidget         *widget,
8550                               GtkRequisition    *requisition)
8551 {
8552   requisition->width = widget->requisition.width;
8553   requisition->height = widget->requisition.height;
8554 }
8555
8556 /**
8557  * _gtk_widget_peek_colormap:
8558  * 
8559  * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8560  * 
8561  * Return value: the currently pushed colormap, or %NULL if there is none.
8562  **/
8563 GdkColormap*
8564 _gtk_widget_peek_colormap (void)
8565 {
8566   if (colormap_stack)
8567     return (GdkColormap*) colormap_stack->data;
8568   return NULL;
8569 }
8570
8571 /*
8572  * _gtk_widget_set_pointer_window:
8573  * @widget: a #GtkWidget.
8574  * @pointer_window: the new pointer window.
8575  *
8576  * Sets pointer window for @widget.  Does not ref @pointer_window.
8577  * Actually stores it on the #GdkScreen, but you don't need to know that.
8578  */
8579 void
8580 _gtk_widget_set_pointer_window (GtkWidget *widget,
8581                                 GdkWindow *pointer_window)
8582 {
8583   g_return_if_fail (GTK_IS_WIDGET (widget));
8584
8585   if (GTK_WIDGET_REALIZED (widget))
8586     {
8587       GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8588
8589       g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8590                           pointer_window);
8591     }
8592 }
8593
8594 /*
8595  * _gtk_widget_get_pointer_window:
8596  * @widget: a #GtkWidget.
8597  *
8598  * Return value: the pointer window set on the #GdkScreen @widget is attached
8599  * to, or %NULL.
8600  */
8601 GdkWindow *
8602 _gtk_widget_get_pointer_window (GtkWidget *widget)
8603 {
8604   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8605
8606   if (GTK_WIDGET_REALIZED (widget))
8607     {
8608       GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8609
8610       return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8611     }
8612
8613   return NULL;
8614 }
8615
8616 static void
8617 synth_crossing (GtkWidget      *widget,
8618                 GdkEventType    type,
8619                 GdkWindow      *window,
8620                 GdkCrossingMode mode,
8621                 GdkNotifyType   detail)
8622 {
8623   GdkEvent *event;
8624   
8625   event = gdk_event_new (type);
8626
8627   event->crossing.window = g_object_ref (window);
8628   event->crossing.send_event = TRUE;
8629   event->crossing.subwindow = g_object_ref (window);
8630   event->crossing.time = GDK_CURRENT_TIME;
8631   event->crossing.x = event->crossing.y = 0;
8632   event->crossing.x_root = event->crossing.y_root = 0;
8633   event->crossing.mode = mode;
8634   event->crossing.detail = detail;
8635   event->crossing.focus = FALSE;
8636   event->crossing.state = 0;
8637
8638   if (!widget)
8639     widget = gtk_get_event_widget (event);
8640
8641   if (widget)
8642     gtk_widget_event_internal (widget, event);
8643
8644   gdk_event_free (event);
8645 }
8646
8647 /*
8648  * _gtk_widget_is_pointer_widget:
8649  * @widget: a #GtkWidget
8650  *
8651  * Returns %TRUE if the pointer window belongs to @widget.
8652  */
8653 gboolean
8654 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8655 {
8656   if (GTK_WIDGET_HAS_POINTER (widget))
8657     {
8658       GdkWindow *win;
8659       GtkWidget *wid;
8660
8661       win = _gtk_widget_get_pointer_window (widget);
8662       if (win)
8663         {
8664           gdk_window_get_user_data (win, (gpointer *)&wid);
8665           if (wid == widget)
8666             return TRUE;
8667         }
8668     }
8669
8670   return FALSE;
8671 }
8672
8673 /*
8674  * _gtk_widget_synthesize_crossing:
8675  * @from: the #GtkWidget the virtual pointer is leaving.
8676  * @to: the #GtkWidget the virtual pointer is moving to.
8677  * @mode: the #GdkCrossingMode to place on the synthesized events.
8678  *
8679  * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8680  *
8681  * The real pointer window is the window that most recently received an enter notify
8682  * event.  Windows that don't select for crossing events can't become the real
8683  * poiner window.  The real pointer widget that owns the real pointer window.  The
8684  * effective pointer window is the same as the real pointer window unless the real
8685  * pointer widget is either insensitive or there is a grab on a widget that is not
8686  * an ancestor of the real pointer widget (in which case the effective pointer
8687  * window should be the root window).
8688  *
8689  * When the effective pointer window is the same as the real poiner window, we
8690  * receive crossing events from the windowing system.  When the effective pointer
8691  * window changes to become different from the real pointer window we synthesize
8692  * crossing events, attempting to follow X protocol rules:
8693  *
8694  * When the root window becomes the effective pointer window:
8695  *   - leave notify on real pointer window, detail Ancestor
8696  *   - leave notify on all of its ancestors, detail Virtual
8697  *   - enter notify on root window, detail Inferior
8698  *
8699  * When the root window ceases to be the effective pointer window:
8700  *   - leave notify on root window, detail Inferior
8701  *   - enter notify on all ancestors of real pointer window, detail Virtual
8702  *   - enter notify on real pointer window, detail Ancestor
8703  */
8704 void
8705 _gtk_widget_synthesize_crossing (GtkWidget      *from,
8706                                  GtkWidget      *to,
8707                                  GdkCrossingMode mode)
8708 {
8709   GdkWindow *from_window = NULL, *to_window = NULL;
8710
8711   g_return_if_fail (from != NULL || to != NULL);
8712
8713   if (from != NULL)
8714     from_window = GTK_WIDGET_HAS_POINTER (from)
8715       ? _gtk_widget_get_pointer_window (from) : from->window;
8716   if (to != NULL)
8717     to_window = GTK_WIDGET_HAS_POINTER (to)
8718       ? _gtk_widget_get_pointer_window (to) : to->window;
8719
8720   if (from_window == NULL && to_window == NULL)
8721     ;
8722   else if (from_window != NULL && to_window == NULL)
8723     {
8724       GList *from_ancestors = NULL, *list;
8725       GdkWindow *from_ancestor = from_window;
8726
8727       while (from_ancestor != NULL)
8728         {
8729           from_ancestor = gdk_window_get_parent (from_ancestor);
8730           if (from_ancestor == NULL)
8731             break;
8732           from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8733         }
8734
8735       synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8736                       mode, GDK_NOTIFY_ANCESTOR);
8737       for (list = g_list_last (from_ancestors); list; list = list->prev)
8738         {
8739           synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8740                           mode, GDK_NOTIFY_VIRTUAL);
8741         }
8742
8743       /* XXX: enter/inferior on root window? */
8744
8745       g_list_free (from_ancestors);
8746     }
8747   else if (from_window == NULL && to_window != NULL)
8748     {
8749       GList *to_ancestors = NULL, *list;
8750       GdkWindow *to_ancestor = to_window;
8751
8752       while (to_ancestor != NULL)
8753         {
8754           to_ancestor = gdk_window_get_parent (to_ancestor);
8755           if (to_ancestor == NULL)
8756             break;
8757           to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8758         }
8759
8760       /* XXX: leave/inferior on root window? */
8761
8762       for (list = to_ancestors; list; list = list->next)
8763         {
8764           synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8765                           mode, GDK_NOTIFY_VIRTUAL);
8766         }
8767       synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8768                       mode, GDK_NOTIFY_ANCESTOR);
8769
8770       g_list_free (to_ancestors);
8771     }
8772   else if (from_window == to_window)
8773     ;
8774   else
8775     {
8776       GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8777       GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8778
8779       while (from_ancestor != NULL || to_ancestor != NULL)
8780         {
8781           if (from_ancestor != NULL)
8782             {
8783               from_ancestor = gdk_window_get_parent (from_ancestor);
8784               if (from_ancestor == to_window)
8785                 break;
8786               if (from_ancestor)
8787                 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8788             }
8789           if (to_ancestor != NULL)
8790             {
8791               to_ancestor = gdk_window_get_parent (to_ancestor);
8792               if (to_ancestor == from_window)
8793                 break;
8794               if (to_ancestor)
8795                 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8796             }
8797         }
8798       if (to_ancestor == from_window)
8799         {
8800           if (mode != GDK_CROSSING_GTK_UNGRAB)
8801             synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8802                             mode, GDK_NOTIFY_INFERIOR);
8803           for (list = to_ancestors; list; list = list->next)
8804             synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data, 
8805                             mode, GDK_NOTIFY_VIRTUAL);
8806           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8807                           mode, GDK_NOTIFY_ANCESTOR);
8808         }
8809       else if (from_ancestor == to_window)
8810         {
8811           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8812                           mode, GDK_NOTIFY_ANCESTOR);
8813           for (list = g_list_last (from_ancestors); list; list = list->prev)
8814             {
8815               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8816                               mode, GDK_NOTIFY_VIRTUAL);
8817             }
8818           if (mode != GDK_CROSSING_GTK_GRAB)
8819             synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8820                             mode, GDK_NOTIFY_INFERIOR);
8821         }
8822       else
8823         {
8824           while (from_ancestors != NULL && to_ancestors != NULL 
8825                  && from_ancestors->data == to_ancestors->data)
8826             {
8827               from_ancestors = g_list_delete_link (from_ancestors, 
8828                                                    from_ancestors);
8829               to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8830             }
8831
8832           synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8833                           mode, GDK_NOTIFY_NONLINEAR);
8834
8835           for (list = g_list_last (from_ancestors); list; list = list->prev)
8836             {
8837               synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8838                               mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8839             }
8840           for (list = to_ancestors; list; list = list->next)
8841             {
8842               synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8843                               mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8844             }
8845           synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8846                           mode, GDK_NOTIFY_NONLINEAR);
8847         }
8848       g_list_free (from_ancestors);
8849       g_list_free (to_ancestors);
8850     }
8851 }
8852
8853 static void
8854 gtk_widget_propagate_state (GtkWidget           *widget,
8855                             GtkStateData        *data)
8856 {
8857   guint8 old_state = GTK_WIDGET_STATE (widget);
8858   guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8859
8860   /* don't call this function with state==GTK_STATE_INSENSITIVE,
8861    * parent_sensitive==TRUE on a sensitive widget
8862    */
8863
8864
8865   if (data->parent_sensitive)
8866     GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8867   else
8868     GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8869
8870   if (GTK_WIDGET_IS_SENSITIVE (widget))
8871     {
8872       if (data->state_restoration)
8873         GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8874       else
8875         GTK_WIDGET_STATE (widget) = data->state;
8876     }
8877   else
8878     {
8879       if (!data->state_restoration)
8880         {
8881           if (data->state != GTK_STATE_INSENSITIVE)
8882             GTK_WIDGET_SAVED_STATE (widget) = data->state;
8883         }
8884       else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8885         GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8886       GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8887     }
8888
8889   if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8890     {
8891       GtkWidget *window;
8892
8893       window = gtk_widget_get_toplevel (widget);
8894       if (window && GTK_WIDGET_TOPLEVEL (window))
8895         gtk_window_set_focus (GTK_WINDOW (window), NULL);
8896     }
8897
8898   if (old_state != GTK_WIDGET_STATE (widget) ||
8899       old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8900     {
8901       g_object_ref (widget);
8902
8903       if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8904         gtk_grab_remove (widget);
8905
8906       g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8907
8908       if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
8909         {
8910           if (!GTK_WIDGET_IS_SENSITIVE (widget))
8911             _gtk_widget_synthesize_crossing (widget, NULL, 
8912                                              GDK_CROSSING_STATE_CHANGED);
8913           else if (old_state == GTK_STATE_INSENSITIVE)
8914             _gtk_widget_synthesize_crossing (NULL, widget, 
8915                                              GDK_CROSSING_STATE_CHANGED);
8916         }
8917
8918       if (GTK_IS_CONTAINER (widget))
8919         {
8920           data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8921           if (data->use_forall)
8922             gtk_container_forall (GTK_CONTAINER (widget),
8923                                   (GtkCallback) gtk_widget_propagate_state,
8924                                   data);
8925           else
8926             gtk_container_foreach (GTK_CONTAINER (widget),
8927                                    (GtkCallback) gtk_widget_propagate_state,
8928                                    data);
8929         }
8930       g_object_unref (widget);
8931     }
8932 }
8933
8934 /*
8935  * _gtk_widget_get_aux_info:
8936  * @widget: a #GtkWidget
8937  * @create: if %TRUE, create the structure if it doesn't exist
8938  * 
8939  * Get the #GtkWidgetAuxInfo structure for the widget.
8940  * 
8941  * Return value: the #GtkAuxInfo structure for the widget, or
8942  *    %NULL if @create is %FALSE and one doesn't already exist.
8943  */
8944 GtkWidgetAuxInfo*
8945 _gtk_widget_get_aux_info (GtkWidget *widget,
8946                           gboolean   create)
8947 {
8948   GtkWidgetAuxInfo *aux_info;
8949   
8950   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8951   if (!aux_info && create)
8952     {
8953       aux_info = g_slice_new (GtkWidgetAuxInfo);
8954
8955       aux_info->width = -1;
8956       aux_info->height = -1;
8957       aux_info->x = 0;
8958       aux_info->y = 0;
8959       aux_info->x_set = FALSE;
8960       aux_info->y_set = FALSE;
8961       g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8962     }
8963   
8964   return aux_info;
8965 }
8966
8967 /*****************************************
8968  * gtk_widget_aux_info_destroy:
8969  *
8970  *   arguments:
8971  *
8972  *   results:
8973  *****************************************/
8974
8975 static void
8976 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8977 {
8978   g_slice_free (GtkWidgetAuxInfo, aux_info);
8979 }
8980
8981 static void
8982 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8983 {
8984   g_object_unref (info->shape_mask);
8985   g_slice_free (GtkWidgetShapeInfo, info);
8986 }
8987
8988 /**
8989  * gtk_widget_shape_combine_mask: 
8990  * @widget: a #GtkWidget
8991  * @shape_mask: shape to be added, or %NULL to remove an existing shape
8992  * @offset_x: X position of shape mask with respect to @window
8993  * @offset_y: Y position of shape mask with respect to @window
8994  * 
8995  * Sets a shape for this widget's GDK window. This allows for
8996  * transparent windows etc., see gdk_window_shape_combine_mask()
8997  * for more information.
8998  **/
8999 void
9000 gtk_widget_shape_combine_mask (GtkWidget *widget,
9001                                GdkBitmap *shape_mask,
9002                                gint       offset_x,
9003                                gint       offset_y)
9004 {
9005   GtkWidgetShapeInfo* shape_info;
9006   
9007   g_return_if_fail (GTK_IS_WIDGET (widget));
9008   /*  set_shape doesn't work on widgets without gdk window */
9009   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9010
9011   if (!shape_mask)
9012     {
9013       GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9014       
9015       if (widget->window)
9016         gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9017       
9018       g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9019     }
9020   else
9021     {
9022       GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9023       
9024       shape_info = g_slice_new (GtkWidgetShapeInfo);
9025       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9026                                (GDestroyNotify) gtk_widget_shape_info_destroy);
9027       
9028       shape_info->shape_mask = g_object_ref (shape_mask);
9029       shape_info->offset_x = offset_x;
9030       shape_info->offset_y = offset_y;
9031       
9032       /* set shape if widget has a gdk window already.
9033        * otherwise the shape is scheduled to be set by gtk_widget_realize().
9034        */
9035       if (widget->window)
9036         gdk_window_shape_combine_mask (widget->window, shape_mask,
9037                                        offset_x, offset_y);
9038     }
9039 }
9040
9041 /**
9042  * gtk_widget_input_shape_combine_mask: 
9043  * @widget: a #GtkWidget
9044  * @shape_mask: shape to be added, or %NULL to remove an existing shape
9045  * @offset_x: X position of shape mask with respect to @window
9046  * @offset_y: Y position of shape mask with respect to @window
9047  * 
9048  * Sets an input shape for this widget's GDK window. This allows for
9049  * windows which react to mouse click in a nonrectangular region, see 
9050  * gdk_window_input_shape_combine_mask() for more information.
9051  *
9052  * Since: 2.10
9053  **/
9054 void
9055 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9056                                      GdkBitmap *shape_mask,
9057                                      gint       offset_x,
9058                                      gint       offset_y)
9059 {
9060   GtkWidgetShapeInfo* shape_info;
9061   
9062   g_return_if_fail (GTK_IS_WIDGET (widget));
9063   /*  set_shape doesn't work on widgets without gdk window */
9064   g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9065
9066   if (!shape_mask)
9067     {
9068       if (widget->window)
9069         gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9070       
9071       g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9072     }
9073   else
9074     {
9075       shape_info = g_slice_new (GtkWidgetShapeInfo);
9076       g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info, 
9077                                shape_info,
9078                                (GDestroyNotify) gtk_widget_shape_info_destroy);
9079       
9080       shape_info->shape_mask = g_object_ref (shape_mask);
9081       shape_info->offset_x = offset_x;
9082       shape_info->offset_y = offset_y;
9083       
9084       /* set shape if widget has a gdk window already.
9085        * otherwise the shape is scheduled to be set by gtk_widget_realize().
9086        */
9087       if (widget->window)
9088         gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9089                                              offset_x, offset_y);
9090     }
9091 }
9092
9093
9094 static void
9095 gtk_reset_shapes_recurse (GtkWidget *widget,
9096                           GdkWindow *window)
9097 {
9098   gpointer data;
9099   GList *list;
9100
9101   gdk_window_get_user_data (window, &data);
9102   if (data != widget)
9103     return;
9104
9105   gdk_window_shape_combine_mask (window, NULL, 0, 0);
9106   for (list = gdk_window_peek_children (window); list; list = list->next)
9107     gtk_reset_shapes_recurse (widget, list->data);
9108 }
9109
9110 /**
9111  * gtk_widget_reset_shapes:
9112  * @widget: a #GtkWidget
9113  *
9114  * Recursively resets the shape on this widget and its descendants.
9115  **/
9116 void
9117 gtk_widget_reset_shapes (GtkWidget *widget)
9118 {
9119   g_return_if_fail (GTK_IS_WIDGET (widget));
9120   g_return_if_fail (GTK_WIDGET_REALIZED (widget));
9121
9122   if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9123     gtk_reset_shapes_recurse (widget, widget->window);
9124 }
9125
9126 /**
9127  * gtk_widget_ref:
9128  * @widget: a #GtkWidget
9129  * 
9130  * Adds a reference to a widget. This function is exactly the same
9131  * as calling g_object_ref(), and exists mostly for historical
9132  * reasons. It can still be convenient to avoid casting a widget
9133  * to a #GObject, it saves a small amount of typing.
9134  * 
9135  * Return value: the widget that was referenced
9136  *
9137  * Deprecated: 2.12: Use g_object_ref() instead.
9138  **/
9139 GtkWidget*
9140 gtk_widget_ref (GtkWidget *widget)
9141 {
9142   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9143
9144   return (GtkWidget*) g_object_ref ((GObject*) widget);
9145 }
9146
9147 /**
9148  * gtk_widget_unref:
9149  * @widget: a #GtkWidget
9150  *
9151  * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9152  * 
9153  * Deprecated: 2.12: Use g_object_unref() instead.
9154  **/
9155 void
9156 gtk_widget_unref (GtkWidget *widget)
9157 {
9158   g_return_if_fail (GTK_IS_WIDGET (widget));
9159
9160   g_object_unref ((GObject*) widget);
9161 }
9162
9163 static void
9164 expose_window (GdkWindow *window)
9165 {
9166   GdkEvent event;
9167   GList *l, *children;
9168   gpointer user_data;
9169   gboolean is_double_buffered;
9170
9171   gdk_window_get_user_data (window, &user_data);
9172
9173   if (user_data)
9174     is_double_buffered = GTK_WIDGET_DOUBLE_BUFFERED (GTK_WIDGET (user_data));
9175   else
9176     is_double_buffered = FALSE;
9177   
9178   event.expose.type = GDK_EXPOSE;
9179   event.expose.window = g_object_ref (window);
9180   event.expose.send_event = FALSE;
9181   event.expose.count = 0;
9182   event.expose.area.x = 0;
9183   event.expose.area.y = 0;
9184   gdk_drawable_get_size (GDK_DRAWABLE (window),
9185                          &event.expose.area.width,
9186                          &event.expose.area.height);
9187   event.expose.region = gdk_region_rectangle (&event.expose.area);
9188
9189   /* If this is not double buffered, force a double buffer so that
9190      redirection works. */
9191   if (!is_double_buffered)
9192     gdk_window_begin_paint_region (window, event.expose.region);
9193   
9194   gtk_main_do_event (&event);
9195
9196   if (!is_double_buffered)
9197     gdk_window_end_paint (window);
9198   
9199   children = gdk_window_peek_children (window);
9200   for (l = children; l != NULL; l = l->next)
9201     {
9202       GdkWindow *child = l->data;
9203
9204       /* Don't expose input-only windows */
9205       if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9206         expose_window (l->data);
9207     }
9208   
9209   g_object_unref (window);
9210 }
9211
9212 /**
9213  * gtk_widget_get_snapshot:
9214  * @widget:    a #GtkWidget
9215  * @clip_rect: a #GdkRectangle or %NULL
9216  *
9217  * Create a #GdkPixmap of the contents of the widget and its children.
9218  *
9219  * Works even if the widget is obscured. The depth and visual of the
9220  * resulting pixmap is dependent on the widget being snapshot and likely
9221  * differs from those of a target widget displaying the pixmap.
9222  * The function gdk_pixbuf_get_from_drawable() can be used to convert
9223  * the pixmap to a visual independant representation.
9224  *
9225  * The snapshot area used by this function is the @widget's allocation plus
9226  * any extra space occupied by additional windows belonging to this widget
9227  * (such as the arrows of a spin button).
9228  * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9229  * 
9230  * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9231  * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9232  * interpreted widget relative. If width or height of @clip_rect are 0 or
9233  * negative, the width or height of the resulting pixmap will be shrunken
9234  * by the respective amount.
9235  * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9236  * chop off 5 pixels at each side of the snapshot pixmap.
9237  * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9238  * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9239  * can be used to preserve the auto-grown snapshot area and use @clip_rect
9240  * as a pure output parameter.
9241  *
9242  * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9243  *
9244  * Return value: #GdkPixmap snapshot of the widget
9245  * 
9246  * Since: 2.14
9247  **/
9248 GdkPixmap*
9249 gtk_widget_get_snapshot (GtkWidget    *widget,
9250                          GdkRectangle *clip_rect)
9251 {
9252   int x, y, width, height;
9253   GdkWindow *parent_window = NULL;
9254   GdkPixmap *pixmap;
9255   GList *windows = NULL, *list;
9256
9257   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9258   if (!GTK_WIDGET_VISIBLE (widget))
9259     return NULL;
9260
9261   /* the widget (and parent_window) must be realized to be drawable */
9262   if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
9263     gtk_widget_realize (widget->parent);
9264   if (!GTK_WIDGET_REALIZED (widget))
9265     gtk_widget_realize (widget);
9266
9267   /* determine snapshot rectangle */
9268   x = widget->allocation.x;
9269   y = widget->allocation.y;
9270   width = widget->allocation.width;
9271   height = widget->allocation.height;
9272
9273   if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
9274     {
9275       /* grow snapshot rectangle to cover all widget windows */
9276       parent_window = gtk_widget_get_parent_window (widget);
9277       for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9278         {
9279           GdkWindow *subwin = list->data;
9280           gpointer windata;
9281           int wx, wy, ww, wh;
9282           gdk_window_get_user_data (subwin, &windata);
9283           if (windata != widget)
9284             continue;
9285           windows = g_list_prepend (windows, subwin);
9286           gdk_window_get_position (subwin, &wx, &wy);
9287           gdk_drawable_get_size (subwin, &ww, &wh);
9288           /* grow snapshot rectangle by extra widget sub window */
9289           if (wx < x)
9290             {
9291               width += x - wx;
9292               x = wx;
9293             }
9294           if (wy < y)
9295             {
9296               height += y - wy;
9297               y = wy;
9298             }
9299           if (x + width < wx + ww)
9300             width += wx + ww - (x + width);
9301           if (y + height < wy + wh)
9302             height += wy + wh - (y + height);
9303         }
9304     }
9305   else if (!widget->parent)
9306     x = y = 0; /* toplevel */
9307
9308   /* at this point, (x,y,width,height) is the parent_window relative
9309    * snapshot area covering all of widget's windows.
9310    */
9311
9312   /* shrink snapshot size by clip_rectangle */
9313   if (clip_rect)
9314     {
9315       GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9316       clip.x = clip.x < 0 ? x : clip.x;
9317       clip.y = clip.y < 0 ? y : clip.y;
9318       clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9319       clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9320       if (widget->parent)
9321         {
9322           /* offset clip_rect, so it's parent_window relative */
9323           if (clip_rect->x >= 0)
9324             clip.x += widget->allocation.x;
9325           if (clip_rect->y >= 0)
9326             clip.y += widget->allocation.y;
9327         }
9328       if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9329         {
9330           g_list_free (windows);
9331           clip_rect->width = clip_rect->height = 0;
9332           return NULL; /* empty snapshot area */
9333         }
9334       x = snap.x;
9335       y = snap.y;
9336       width = snap.width;
9337       height = snap.height;
9338     }
9339
9340   /* render snapshot */
9341   pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9342   for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9343     {
9344       GdkWindow *subwin = list->data;
9345       int wx, wy;
9346       if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9347         continue; /* Input only window */
9348       gdk_window_get_position (subwin, &wx, &wy);
9349       gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9350                                        MAX (0, wx - x), MAX (0, wy - y), width, height);
9351
9352       expose_window (subwin);
9353     }
9354   if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9355     {
9356       gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9357       expose_window (widget->window);
9358     }
9359   for (list = windows; list; list = list->next)
9360     gdk_window_remove_redirection (list->data);
9361   if (!windows) /* NO_WINDOW || toplevel */
9362     gdk_window_remove_redirection (widget->window);
9363   g_list_free (windows);
9364
9365   /* return pixmap and snapshot rectangle coordinates */
9366   if (clip_rect)
9367     {
9368       clip_rect->x = x;
9369       clip_rect->y = y;
9370       clip_rect->width = width;
9371       clip_rect->height = height;
9372       if (widget->parent)
9373         {
9374           /* offset clip_rect from parent_window so it's widget relative */
9375           clip_rect->x -= widget->allocation.x;
9376           clip_rect->y -= widget->allocation.y;
9377         }
9378       if (0)
9379         g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9380                     G_OBJECT_TYPE_NAME (widget),
9381                     clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9382     }
9383   return pixmap;
9384 }
9385
9386 /* style properties
9387  */
9388
9389 /**
9390  * gtk_widget_class_install_style_property_parser:
9391  * @klass: a #GtkWidgetClass
9392  * @pspec: the #GParamSpec for the style property
9393  * @parser: the parser for the style property
9394  * 
9395  * Installs a style property on a widget class. 
9396  **/
9397 void
9398 gtk_widget_class_install_style_property_parser (GtkWidgetClass     *klass,
9399                                                 GParamSpec         *pspec,
9400                                                 GtkRcPropertyParser parser)
9401 {
9402   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9403   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9404   g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9405   g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9406   
9407   if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9408     {
9409       g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9410                  G_OBJECT_CLASS_NAME (klass),
9411                  pspec->name);
9412       return;
9413     }
9414
9415   g_param_spec_ref_sink (pspec);
9416   g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9417   g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9418 }
9419
9420 /**
9421  * gtk_widget_class_install_style_property:
9422  * @klass: a #GtkWidgetClass
9423  * @pspec: the #GParamSpec for the property
9424  * 
9425  * Installs a style property on a widget class. The parser for the
9426  * style property is determined by the value type of @pspec.
9427  **/
9428 void
9429 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9430                                          GParamSpec     *pspec)
9431 {
9432   GtkRcPropertyParser parser;
9433
9434   g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9435   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9436
9437   parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9438
9439   gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9440 }
9441
9442 /**
9443  * gtk_widget_class_find_style_property:
9444  * @klass: a #GtkWidgetClass
9445  * @property_name: the name of the style property to find
9446  * @returns: the #GParamSpec of the style property or %NULL if @class has no
9447  *   style property with that name.
9448  *
9449  * Finds a style property of a widget class by name.
9450  *
9451  * Since: 2.2
9452  */
9453 GParamSpec*
9454 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9455                                       const gchar    *property_name)
9456 {
9457   g_return_val_if_fail (property_name != NULL, NULL);
9458
9459   return g_param_spec_pool_lookup (style_property_spec_pool,
9460                                    property_name,
9461                                    G_OBJECT_CLASS_TYPE (klass),
9462                                    TRUE);
9463 }
9464
9465 /**
9466  * gtk_widget_class_list_style_properties:
9467  * @klass: a #GtkWidgetClass
9468  * @n_properties: location to return the number of style properties found
9469  * @returns: an newly allocated array of #GParamSpec*. The array must 
9470  *       be freed with g_free().
9471  *
9472  * Returns all style properties of a widget class.
9473  *
9474  * Since: 2.2
9475  */
9476 GParamSpec**
9477 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9478                                         guint          *n_properties)
9479 {
9480   GParamSpec **pspecs;
9481   guint n;
9482
9483   pspecs = g_param_spec_pool_list (style_property_spec_pool,
9484                                    G_OBJECT_CLASS_TYPE (klass),
9485                                    &n);
9486   if (n_properties)
9487     *n_properties = n;
9488
9489   return pspecs;
9490 }
9491
9492 /**
9493  * gtk_widget_style_get_property:
9494  * @widget: a #GtkWidget
9495  * @property_name: the name of a style property
9496  * @value: location to return the property value 
9497  *
9498  * Gets the value of a style property of @widget.
9499  */
9500 void
9501 gtk_widget_style_get_property (GtkWidget   *widget,
9502                                const gchar *property_name,
9503                                GValue      *value)
9504 {
9505   GParamSpec *pspec;
9506
9507   g_return_if_fail (GTK_IS_WIDGET (widget));
9508   g_return_if_fail (property_name != NULL);
9509   g_return_if_fail (G_IS_VALUE (value));
9510
9511   g_object_ref (widget);
9512   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9513                                     property_name,
9514                                     G_OBJECT_TYPE (widget),
9515                                     TRUE);
9516   if (!pspec)
9517     g_warning ("%s: widget class `%s' has no property named `%s'",
9518                G_STRLOC,
9519                G_OBJECT_TYPE_NAME (widget),
9520                property_name);
9521   else
9522     {
9523       const GValue *peek_value;
9524
9525       peek_value = _gtk_style_peek_property_value (widget->style,
9526                                                    G_OBJECT_TYPE (widget),
9527                                                    pspec,
9528                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9529       
9530       /* auto-conversion of the caller's value type
9531        */
9532       if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9533         g_value_copy (peek_value, value);
9534       else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9535         g_value_transform (peek_value, value);
9536       else
9537         g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9538                    pspec->name,
9539                    g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9540                    G_VALUE_TYPE_NAME (value));
9541     }
9542   g_object_unref (widget);
9543 }
9544
9545 /**
9546  * gtk_widget_style_get_valist:
9547  * @widget: a #GtkWidget
9548  * @first_property_name: the name of the first property to get
9549  * @var_args: a <type>va_list</type> of pairs of property names and
9550  *     locations to return the property values, starting with the location
9551  *     for @first_property_name.
9552  * 
9553  * Non-vararg variant of gtk_widget_style_get(). Used primarily by language 
9554  * bindings.
9555  */ 
9556 void
9557 gtk_widget_style_get_valist (GtkWidget   *widget,
9558                              const gchar *first_property_name,
9559                              va_list      var_args)
9560 {
9561   const gchar *name;
9562
9563   g_return_if_fail (GTK_IS_WIDGET (widget));
9564
9565   g_object_ref (widget);
9566
9567   name = first_property_name;
9568   while (name)
9569     {
9570       const GValue *peek_value;
9571       GParamSpec *pspec;
9572       gchar *error;
9573
9574       pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9575                                         name,
9576                                         G_OBJECT_TYPE (widget),
9577                                         TRUE);
9578       if (!pspec)
9579         {
9580           g_warning ("%s: widget class `%s' has no property named `%s'",
9581                      G_STRLOC,
9582                      G_OBJECT_TYPE_NAME (widget),
9583                      name);
9584           break;
9585         }
9586       /* style pspecs are always readable so we can spare that check here */
9587
9588       peek_value = _gtk_style_peek_property_value (widget->style,
9589                                                    G_OBJECT_TYPE (widget),
9590                                                    pspec,
9591                                                    (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9592       G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9593       if (error)
9594         {
9595           g_warning ("%s: %s", G_STRLOC, error);
9596           g_free (error);
9597           break;
9598         }
9599
9600       name = va_arg (var_args, gchar*);
9601     }
9602
9603   g_object_unref (widget);
9604 }
9605
9606 /**
9607  * gtk_widget_style_get:
9608  * @widget: a #GtkWidget
9609  * @first_property_name: the name of the first property to get
9610  * @Varargs: pairs of property names and locations to 
9611  *   return the property values, starting with the location for 
9612  *   @first_property_name, terminated by %NULL.
9613  *
9614  * Gets the values of a multiple style properties of @widget.
9615  */
9616 void
9617 gtk_widget_style_get (GtkWidget   *widget,
9618                       const gchar *first_property_name,
9619                       ...)
9620 {
9621   va_list var_args;
9622
9623   g_return_if_fail (GTK_IS_WIDGET (widget));
9624
9625   va_start (var_args, first_property_name);
9626   gtk_widget_style_get_valist (widget, first_property_name, var_args);
9627   va_end (var_args);
9628 }
9629
9630 /**
9631  * gtk_widget_path:
9632  * @widget: a #GtkWidget
9633  * @path_length: location to store length of the path, or %NULL
9634  * @path: location to store allocated path string, or %NULL 
9635  * @path_reversed: location to store allocated reverse path string, or %NULL
9636  *
9637  * Obtains the full path to @widget. The path is simply the name of a
9638  * widget and all its parents in the container hierarchy, separated by
9639  * periods. The name of a widget comes from
9640  * gtk_widget_get_name(). Paths are used to apply styles to a widget
9641  * in gtkrc configuration files. Widget names are the type of the
9642  * widget by default (e.g. "GtkButton") or can be set to an
9643  * application-specific value with gtk_widget_set_name(). By setting
9644  * the name of a widget, you allow users or theme authors to apply
9645  * styles to that specific widget in their gtkrc
9646  * file. @path_reversed_p fills in the path in reverse order,
9647  * i.e. starting with @widget's name instead of starting with the name
9648  * of @widget's outermost ancestor.
9649  **/
9650 void
9651 gtk_widget_path (GtkWidget *widget,
9652                  guint     *path_length,
9653                  gchar    **path,
9654                  gchar    **path_reversed)
9655 {
9656   static gchar *rev_path = NULL;
9657   static guint tmp_path_len = 0;
9658   guint len;
9659   
9660   g_return_if_fail (GTK_IS_WIDGET (widget));
9661   
9662   len = 0;
9663   do
9664     {
9665       const gchar *string;
9666       const gchar *s;
9667       gchar *d;
9668       guint l;
9669       
9670       string = gtk_widget_get_name (widget);
9671       l = strlen (string);
9672       while (tmp_path_len <= len + l + 1)
9673         {
9674           tmp_path_len += INIT_PATH_SIZE;
9675           rev_path = g_realloc (rev_path, tmp_path_len);
9676         }
9677       s = string + l - 1;
9678       d = rev_path + len;
9679       while (s >= string)
9680         *(d++) = *(s--);
9681       len += l;
9682       
9683       widget = widget->parent;
9684       
9685       if (widget)
9686         rev_path[len++] = '.';
9687       else
9688         rev_path[len++] = 0;
9689     }
9690   while (widget);
9691   
9692   if (path_length)
9693     *path_length = len - 1;
9694   if (path_reversed)
9695     *path_reversed = g_strdup (rev_path);
9696   if (path)
9697     {
9698       *path = g_strdup (rev_path);
9699       g_strreverse (*path);
9700     }
9701 }
9702
9703 /**
9704  * gtk_widget_class_path:
9705  * @widget: a #GtkWidget
9706  * @path_length: location to store the length of the class path, or %NULL
9707  * @path: location to store the class path as an allocated string, or %NULL
9708  * @path_reversed: location to store the reverse class path as an allocated 
9709  *    string, or %NULL
9710  *
9711  * Same as gtk_widget_path(), but always uses the name of a widget's type,
9712  * never uses a custom name set with gtk_widget_set_name().
9713  * 
9714  **/
9715 void
9716 gtk_widget_class_path (GtkWidget *widget,
9717                        guint     *path_length,
9718                        gchar    **path,
9719                        gchar    **path_reversed)
9720 {
9721   static gchar *rev_path = NULL;
9722   static guint tmp_path_len = 0;
9723   guint len;
9724   
9725   g_return_if_fail (GTK_IS_WIDGET (widget));
9726   
9727   len = 0;
9728   do
9729     {
9730       const gchar *string;
9731       const gchar *s;
9732       gchar *d;
9733       guint l;
9734       
9735       string = g_type_name (GTK_WIDGET_TYPE (widget));
9736       l = strlen (string);
9737       while (tmp_path_len <= len + l + 1)
9738         {
9739           tmp_path_len += INIT_PATH_SIZE;
9740           rev_path = g_realloc (rev_path, tmp_path_len);
9741         }
9742       s = string + l - 1;
9743       d = rev_path + len;
9744       while (s >= string)
9745         *(d++) = *(s--);
9746       len += l;
9747       
9748       widget = widget->parent;
9749       
9750       if (widget)
9751         rev_path[len++] = '.';
9752       else
9753         rev_path[len++] = 0;
9754     }
9755   while (widget);
9756   
9757   if (path_length)
9758     *path_length = len - 1;
9759   if (path_reversed)
9760     *path_reversed = g_strdup (rev_path);
9761   if (path)
9762     {
9763       *path = g_strdup (rev_path);
9764       g_strreverse (*path);
9765     }
9766 }
9767
9768 /**
9769  * gtk_requisition_copy:
9770  * @requisition: a #GtkRequisition
9771  *
9772  * Copies a #GtkRequisition.
9773  *
9774  * Returns: a copy of @requisition
9775  **/
9776 GtkRequisition *
9777 gtk_requisition_copy (const GtkRequisition *requisition)
9778 {
9779   return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9780 }
9781
9782 /**
9783  * gtk_requisition_free:
9784  * @requisition: a #GtkRequisition
9785  * 
9786  * Frees a #GtkRequisition.
9787  **/
9788 void
9789 gtk_requisition_free (GtkRequisition *requisition)
9790 {
9791   g_free (requisition);
9792 }
9793
9794 GType
9795 gtk_requisition_get_type (void)
9796 {
9797   static GType our_type = 0;
9798   
9799   if (our_type == 0)
9800     our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9801                                              (GBoxedCopyFunc) gtk_requisition_copy,
9802                                              (GBoxedFreeFunc) gtk_requisition_free);
9803
9804   return our_type;
9805 }
9806
9807 /**
9808  * gtk_widget_get_accessible:
9809  * @widget: a #GtkWidget
9810  *
9811  * Returns the accessible object that describes the widget to an
9812  * assistive technology. 
9813  * 
9814  * If no accessibility library is loaded (i.e. no ATK implementation library is 
9815  * loaded via <envar>GTK_MODULES</envar> or via another application library, 
9816  * such as libgnome), then this #AtkObject instance may be a no-op. Likewise, 
9817  * if no class-specific #AtkObject implementation is available for the widget 
9818  * instance in question, it will inherit an #AtkObject implementation from the 
9819  * first ancestor class for which such an implementation is defined.
9820  *
9821  * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9822  * library contains more information about accessible objects and their uses.
9823  * 
9824  * Returns: the #AtkObject associated with @widget
9825  */
9826 AtkObject* 
9827 gtk_widget_get_accessible (GtkWidget *widget)
9828 {
9829   GtkWidgetClass *klass;
9830
9831   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9832
9833   klass = GTK_WIDGET_GET_CLASS (widget);
9834
9835   g_return_val_if_fail (klass->get_accessible != NULL, NULL);
9836
9837   return klass->get_accessible (widget);
9838 }
9839
9840 static AtkObject* 
9841 gtk_widget_real_get_accessible (GtkWidget *widget)
9842 {
9843   AtkObject* accessible;
9844
9845   accessible = g_object_get_qdata (G_OBJECT (widget), 
9846                                    quark_accessible_object);
9847   if (!accessible)
9848   {
9849     AtkObjectFactory *factory;
9850     AtkRegistry *default_registry;
9851
9852     default_registry = atk_get_default_registry ();
9853     factory = atk_registry_get_factory (default_registry, 
9854                                         G_TYPE_FROM_INSTANCE (widget));
9855     accessible =
9856       atk_object_factory_create_accessible (factory,
9857                                             G_OBJECT (widget));
9858     g_object_set_qdata (G_OBJECT (widget), 
9859                         quark_accessible_object,
9860                         accessible);
9861   }
9862   return accessible;
9863 }
9864
9865 /*
9866  * Initialize a AtkImplementorIface instance's virtual pointers as
9867  * appropriate to this implementor's class (GtkWidget).
9868  */
9869 static void
9870 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9871 {
9872   iface->ref_accessible = gtk_widget_ref_accessible;
9873 }
9874
9875 static AtkObject*
9876 gtk_widget_ref_accessible (AtkImplementor *implementor)
9877 {
9878   AtkObject *accessible;
9879
9880   accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9881   if (accessible)
9882     g_object_ref (accessible);
9883   return accessible;
9884 }
9885
9886 /*
9887  * GtkBuildable implementation
9888  */
9889 static GQuark            quark_builder_has_default = 0;
9890 static GQuark            quark_builder_has_focus = 0;
9891 static GQuark            quark_builder_atk_relations = 0;
9892
9893 static void
9894 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9895 {
9896   quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9897   quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9898   quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9899
9900   iface->set_name = gtk_widget_buildable_set_name;
9901   iface->get_name = gtk_widget_buildable_get_name;
9902   iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9903   iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9904   iface->parser_finished = gtk_widget_buildable_parser_finished;
9905   iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9906   iface->custom_finished = gtk_widget_buildable_custom_finished;
9907 }
9908
9909 static void
9910 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9911                                const gchar  *name)
9912 {
9913   gtk_widget_set_name (GTK_WIDGET (buildable), name);
9914 }
9915
9916 static const gchar *
9917 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9918 {
9919   return gtk_widget_get_name (GTK_WIDGET (buildable));
9920 }
9921
9922 static GObject *
9923 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9924                                          GtkBuilder   *builder,
9925                                          const gchar  *childname)
9926 {
9927   if (strcmp (childname, "accessible") == 0)
9928     return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9929
9930   return NULL;
9931 }
9932
9933 static void
9934 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9935                                              GtkBuilder   *builder,
9936                                              const gchar  *name,
9937                                              const GValue *value)
9938 {
9939   if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9940       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9941                           GINT_TO_POINTER (TRUE));
9942   else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9943       g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9944                           GINT_TO_POINTER (TRUE));
9945   else
9946     g_object_set_property (G_OBJECT (buildable), name, value);
9947 }
9948
9949 typedef struct
9950 {
9951   gchar *action_name;
9952   GString *description;
9953   gchar *context;
9954   gboolean translatable;
9955 } AtkActionData;
9956
9957 typedef struct
9958 {
9959   gchar *target;
9960   gchar *type;
9961 } AtkRelationData;
9962
9963 static void
9964 free_action (AtkActionData *data, gpointer user_data)
9965 {
9966   g_free (data->action_name);
9967   g_string_free (data->description, TRUE);
9968   g_free (data->context);
9969   g_slice_free (AtkActionData, data);
9970 }
9971
9972 static void
9973 free_relation (AtkRelationData *data, gpointer user_data)
9974 {
9975   g_free (data->target);
9976   g_free (data->type);
9977   g_slice_free (AtkRelationData, data);
9978 }
9979
9980 static void
9981 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9982                                       GtkBuilder   *builder)
9983 {
9984   GSList *atk_relations;
9985
9986   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9987     gtk_widget_grab_default (GTK_WIDGET (buildable));
9988   if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9989     gtk_widget_grab_focus (GTK_WIDGET (buildable));
9990
9991   atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9992                                       quark_builder_atk_relations);
9993   if (atk_relations)
9994     {
9995       AtkObject *accessible;
9996       AtkRelationSet *relation_set;
9997       GSList *l;
9998       GObject *target;
9999       AtkRelationType relation_type;
10000       AtkObject *target_accessible;
10001
10002       accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10003       relation_set = atk_object_ref_relation_set (accessible);
10004
10005       for (l = atk_relations; l; l = l->next)
10006         {
10007           AtkRelationData *relation = (AtkRelationData*)l->data;
10008
10009           target = gtk_builder_get_object (builder, relation->target);
10010           if (!target)
10011             {
10012               g_warning ("Target object %s in <relation> does not exist",
10013                          relation->target);
10014               continue;
10015             }
10016           target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10017           g_assert (target_accessible != NULL);
10018
10019           relation_type = atk_relation_type_for_name (relation->type);
10020           if (relation_type == ATK_RELATION_NULL)
10021             {
10022               g_warning ("<relation> type %s not found",
10023                          relation->type);
10024               continue;
10025             }
10026           atk_relation_set_add_relation_by_type (relation_set, relation_type,
10027                                                  target_accessible);
10028         }
10029       g_object_unref (relation_set);
10030
10031       g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10032       g_slist_free (atk_relations);
10033       g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10034                           NULL);
10035     }
10036 }
10037
10038 typedef struct
10039 {
10040   GSList *actions;
10041   GSList *relations;
10042 } AccessibilitySubParserData;
10043
10044 static void
10045 accessibility_start_element (GMarkupParseContext  *context,
10046                              const gchar          *element_name,
10047                              const gchar         **names,
10048                              const gchar         **values,
10049                              gpointer              user_data,
10050                              GError              **error)
10051 {
10052   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10053   guint i;
10054   gint line_number, char_number;
10055
10056   if (strcmp (element_name, "relation") == 0)
10057     {
10058       gchar *target = NULL;
10059       gchar *type = NULL;
10060       AtkRelationData *relation;
10061
10062       for (i = 0; names[i]; i++)
10063         {
10064           if (strcmp (names[i], "target") == 0)
10065             target = g_strdup (values[i]);
10066           else if (strcmp (names[i], "type") == 0)
10067             type = g_strdup (values[i]);
10068           else
10069             {
10070               g_markup_parse_context_get_position (context,
10071                                                    &line_number,
10072                                                    &char_number);
10073               g_set_error (error,
10074                            GTK_BUILDER_ERROR,
10075                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10076                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10077                            "<input>",
10078                            line_number, char_number, names[i], "relation");
10079               g_free (target);
10080               g_free (type);
10081               return;
10082             }
10083         }
10084
10085       if (!target || !type)
10086         {
10087           g_markup_parse_context_get_position (context,
10088                                                &line_number,
10089                                                &char_number);
10090           g_set_error (error,
10091                        GTK_BUILDER_ERROR,
10092                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10093                        "%s:%d:%d <%s> requires attribute \"%s\"",
10094                        "<input>",
10095                        line_number, char_number, "relation",
10096                        type ? "target" : "type");
10097           g_free (target);
10098           g_free (type);
10099           return;
10100         }
10101
10102       relation = g_slice_new (AtkRelationData);
10103       relation->target = target;
10104       relation->type = type;
10105
10106       data->relations = g_slist_prepend (data->relations, relation);
10107     }
10108   else if (strcmp (element_name, "action") == 0)
10109     {
10110       const gchar *action_name = NULL;
10111       const gchar *description = NULL;
10112       const gchar *msg_context = NULL;
10113       gboolean translatable = FALSE;
10114       AtkActionData *action;
10115
10116       for (i = 0; names[i]; i++)
10117         {
10118           if (strcmp (names[i], "action_name") == 0)
10119             action_name = values[i];
10120           else if (strcmp (names[i], "description") == 0)
10121             description = values[i];
10122           else if (strcmp (names[i], "translatable") == 0)
10123             {
10124               if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10125                 return;
10126             }
10127           else if (strcmp (names[i], "comments") == 0)
10128             {
10129               /* do nothing, comments are for translators */
10130             }
10131           else if (strcmp (names[i], "context") == 0)
10132             msg_context = values[i];
10133           else
10134             {
10135               g_markup_parse_context_get_position (context,
10136                                                    &line_number,
10137                                                    &char_number);
10138               g_set_error (error,
10139                            GTK_BUILDER_ERROR,
10140                            GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10141                            "%s:%d:%d '%s' is not a valid attribute of <%s>",
10142                            "<input>",
10143                            line_number, char_number, names[i], "action");
10144               return;
10145             }
10146         }
10147
10148       if (!action_name)
10149         {
10150           g_markup_parse_context_get_position (context,
10151                                                &line_number,
10152                                                &char_number);
10153           g_set_error (error,
10154                        GTK_BUILDER_ERROR,
10155                        GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10156                        "%s:%d:%d <%s> requires attribute \"%s\"",
10157                        "<input>",
10158                        line_number, char_number, "action",
10159                        "action_name");
10160           return;
10161         }
10162
10163       action = g_slice_new (AtkActionData);
10164       action->action_name = g_strdup (action_name);
10165       action->description = g_string_new (description);
10166       action->context = g_strdup (msg_context);
10167       action->translatable = translatable;
10168
10169       data->actions = g_slist_prepend (data->actions, action);
10170     }
10171   else if (strcmp (element_name, "accessibility") == 0)
10172     ;
10173   else
10174     g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10175 }
10176
10177 static void
10178 accessibility_text (GMarkupParseContext  *context,
10179                     const gchar          *text,
10180                     gsize                 text_len,
10181                     gpointer              user_data,
10182                     GError              **error)
10183 {
10184   AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10185
10186   if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10187     {
10188       AtkActionData *action = data->actions->data;
10189
10190       g_string_append_len (action->description, text, text_len);
10191     }
10192 }
10193
10194 static const GMarkupParser accessibility_parser =
10195   {
10196     accessibility_start_element,
10197     NULL,
10198     accessibility_text,
10199   };
10200
10201 typedef struct
10202 {
10203   GObject *object;
10204   guint    key;
10205   guint    modifiers;
10206   gchar   *signal;
10207 } AccelGroupParserData;
10208
10209 static void
10210 accel_group_start_element (GMarkupParseContext  *context,
10211                            const gchar          *element_name,
10212                            const gchar         **names,
10213                            const gchar         **values,
10214                            gpointer              user_data,
10215                            GError              **error)
10216 {
10217   gint i;
10218   guint key = 0;
10219   guint modifiers = 0;
10220   gchar *signal = NULL;
10221   AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10222
10223   for (i = 0; names[i]; i++)
10224     {
10225       if (strcmp (names[i], "key") == 0)
10226         key = gdk_keyval_from_name (values[i]);
10227       else if (strcmp (names[i], "modifiers") == 0)
10228         {
10229           if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10230                                                values[i],
10231                                                &modifiers,
10232                                                error))
10233               return;
10234         }
10235       else if (strcmp (names[i], "signal") == 0)
10236         signal = g_strdup (values[i]);
10237     }
10238
10239   if (key == 0 || signal == NULL)
10240     {
10241       g_warning ("<accelerator> requires key and signal attributes");
10242       return;
10243     }
10244   parser_data->key = key;
10245   parser_data->modifiers = modifiers;
10246   parser_data->signal = signal;
10247 }
10248
10249 static const GMarkupParser accel_group_parser =
10250   {
10251     accel_group_start_element,
10252   };
10253
10254 static gboolean
10255 gtk_widget_buildable_custom_tag_start (GtkBuildable     *buildable,
10256                                        GtkBuilder       *builder,
10257                                        GObject          *child,
10258                                        const gchar      *tagname,
10259                                        GMarkupParser    *parser,
10260                                        gpointer         *data)
10261 {
10262   g_assert (buildable);
10263
10264   if (strcmp (tagname, "accelerator") == 0)
10265     {
10266       AccelGroupParserData *parser_data;
10267
10268       parser_data = g_slice_new0 (AccelGroupParserData);
10269       parser_data->object = g_object_ref (buildable);
10270       *parser = accel_group_parser;
10271       *data = parser_data;
10272       return TRUE;
10273     }
10274   if (strcmp (tagname, "accessibility") == 0)
10275     {
10276       AccessibilitySubParserData *parser_data;
10277
10278       parser_data = g_slice_new0 (AccessibilitySubParserData);
10279       *parser = accessibility_parser;
10280       *data = parser_data;
10281       return TRUE;
10282     }
10283   return FALSE;
10284 }
10285
10286 void
10287 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10288                                           GtkWidget *toplevel,
10289                                           gpointer   user_data)
10290 {
10291   AccelGroupParserData *accel_data;
10292   GSList *accel_groups;
10293   GtkAccelGroup *accel_group;
10294
10295   g_return_if_fail (GTK_IS_WIDGET (widget));
10296   g_return_if_fail (GTK_IS_WIDGET (toplevel));
10297   g_return_if_fail (user_data != NULL);
10298
10299   accel_data = (AccelGroupParserData*)user_data;
10300   accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10301   if (g_slist_length (accel_groups) == 0)
10302     {
10303       accel_group = gtk_accel_group_new ();
10304       gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10305     }
10306   else
10307     {
10308       g_assert (g_slist_length (accel_groups) == 1);
10309       accel_group = g_slist_nth_data (accel_groups, 0);
10310     }
10311
10312   gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10313                               accel_data->signal,
10314                               accel_group,
10315                               accel_data->key,
10316                               accel_data->modifiers,
10317                               GTK_ACCEL_VISIBLE);
10318
10319   g_object_unref (accel_data->object);
10320   g_free (accel_data->signal);
10321   g_slice_free (AccelGroupParserData, accel_data);
10322 }
10323
10324 static void
10325 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10326                                       GtkBuilder   *builder,
10327                                       GObject      *child,
10328                                       const gchar  *tagname,
10329                                       gpointer      user_data)
10330 {
10331   AccelGroupParserData *accel_data;
10332   AccessibilitySubParserData *a11y_data;
10333   GtkWidget *toplevel;
10334
10335   if (strcmp (tagname, "accelerator") == 0)
10336     {
10337       accel_data = (AccelGroupParserData*)user_data;
10338       g_assert (accel_data->object);
10339
10340       toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10341
10342       _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10343     }
10344   else if (strcmp (tagname, "accessibility") == 0)
10345     {
10346       a11y_data = (AccessibilitySubParserData*)user_data;
10347
10348       if (a11y_data->actions)
10349         {
10350           AtkObject *accessible;
10351           AtkAction *action;
10352           gint i, n_actions;
10353           GSList *l;
10354
10355           accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10356
10357           action = ATK_ACTION (accessible);
10358           n_actions = atk_action_get_n_actions (action);
10359
10360           for (l = a11y_data->actions; l; l = l->next)
10361             {
10362               AtkActionData *action_data = (AtkActionData*)l->data;
10363
10364               for (i = 0; i < n_actions; i++)
10365                 if (strcmp (atk_action_get_name (action, i),
10366                             action_data->action_name) == 0)
10367                   break;
10368
10369               if (i < n_actions)
10370                 {
10371                   gchar *description;
10372
10373                   if (action_data->translatable && action_data->description->len)
10374                     description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10375                                                                  action_data->context,
10376                                                                  action_data->description->str);
10377                   else
10378                     description = action_data->description->str;
10379
10380                   atk_action_set_description (action, i, description);
10381                 }
10382             }
10383
10384           g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10385           g_slist_free (a11y_data->actions);
10386         }
10387
10388       if (a11y_data->relations)
10389         g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10390                             a11y_data->relations);
10391
10392       g_slice_free (AccessibilitySubParserData, a11y_data);
10393     }
10394 }
10395
10396
10397 /**
10398  * gtk_widget_get_clipboard:
10399  * @widget: a #GtkWidget
10400  * @selection: a #GdkAtom which identifies the clipboard
10401  *             to use. %GDK_SELECTION_CLIPBOARD gives the
10402  *             default clipboard. Another common value
10403  *             is %GDK_SELECTION_PRIMARY, which gives
10404  *             the primary X selection. 
10405  * 
10406  * Returns the clipboard object for the given selection to
10407  * be used with @widget. @widget must have a #GdkDisplay
10408  * associated with it, so must be attached to a toplevel
10409  * window.
10410  * 
10411  * Return value: the appropriate clipboard object. If no
10412  *             clipboard already exists, a new one will
10413  *             be created. Once a clipboard object has
10414  *             been created, it is persistent for all time.
10415  *
10416  * Since: 2.2
10417  **/
10418 GtkClipboard *
10419 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10420 {
10421   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10422   g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10423   
10424   return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10425                                         selection);
10426 }
10427
10428 /**
10429  * gtk_widget_list_mnemonic_labels:
10430  * @widget: a #GtkWidget
10431  * 
10432  * Returns a newly allocated list of the widgets, normally labels, for 
10433  * which this widget is a the target of a mnemonic (see for example, 
10434  * gtk_label_set_mnemonic_widget()).
10435
10436  * The widgets in the list are not individually referenced. If you
10437  * want to iterate through the list and perform actions involving
10438  * callbacks that might destroy the widgets, you
10439  * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10440  * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10441  * widgets afterwards.
10442
10443  * Return value: the list of mnemonic labels; free this list
10444  *  with g_list_free() when you are done with it.
10445  *
10446  * Since: 2.4
10447  **/
10448 GList *
10449 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10450 {
10451   GList *list = NULL;
10452   GSList *l;
10453   
10454   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10455
10456   for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10457     list = g_list_prepend (list, l->data);
10458
10459   return list;
10460 }
10461
10462 /**
10463  * gtk_widget_add_mnemonic_label:
10464  * @widget: a #GtkWidget
10465  * @label: a #GtkWidget that acts as a mnemonic label for @widget
10466  * 
10467  * Adds a widget to the list of mnemonic labels for
10468  * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10469  * list of mnemonic labels for the widget is cleared when the
10470  * widget is destroyed, so the caller must make sure to update
10471  * its internal state at this point as well, by using a connection
10472  * to the #GtkWidget::destroy signal or a weak notifier.
10473  *
10474  * Since: 2.4
10475  **/
10476 void
10477 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10478                                GtkWidget *label)
10479 {
10480   GSList *old_list, *new_list;
10481
10482   g_return_if_fail (GTK_IS_WIDGET (widget));
10483   g_return_if_fail (GTK_IS_WIDGET (label));
10484
10485   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10486   new_list = g_slist_prepend (old_list, label);
10487   
10488   g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10489                            new_list, (GDestroyNotify) g_slist_free);
10490 }
10491
10492 /**
10493  * gtk_widget_remove_mnemonic_label:
10494  * @widget: a #GtkWidget
10495  * @label: a #GtkWidget that was previously set as a mnemnic label for
10496  *         @widget with gtk_widget_add_mnemonic_label().
10497  * 
10498  * Removes a widget from the list of mnemonic labels for
10499  * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10500  * must have previously been added to the list with
10501  * gtk_widget_add_mnemonic_label().
10502  *
10503  * Since: 2.4
10504  **/
10505 void
10506 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10507                                   GtkWidget *label)
10508 {
10509   GSList *old_list, *new_list;
10510
10511   g_return_if_fail (GTK_IS_WIDGET (widget));
10512   g_return_if_fail (GTK_IS_WIDGET (label));
10513
10514   old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10515   new_list = g_slist_remove (old_list, label);
10516
10517   if (new_list)
10518     g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10519                              new_list, (GDestroyNotify) g_slist_free);
10520 }
10521
10522 /**
10523  * gtk_widget_get_no_show_all:
10524  * @widget: a #GtkWidget
10525  * 
10526  * Returns the current value of the GtkWidget:no-show-all property, 
10527  * which determines whether calls to gtk_widget_show_all() and 
10528  * gtk_widget_hide_all() will affect this widget. 
10529  * 
10530  * Return value: the current value of the "no-show-all" property.
10531  *
10532  * Since: 2.4
10533  **/
10534 gboolean
10535 gtk_widget_get_no_show_all (GtkWidget *widget)
10536 {
10537   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10538   
10539   return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10540 }
10541
10542 /**
10543  * gtk_widget_set_no_show_all:
10544  * @widget: a #GtkWidget
10545  * @no_show_all: the new value for the "no-show-all" property
10546  * 
10547  * Sets the #GtkWidget:no-show-all property, which determines whether 
10548  * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect 
10549  * this widget. 
10550  *
10551  * This is mostly for use in constructing widget hierarchies with externally
10552  * controlled visibility, see #GtkUIManager.
10553  * 
10554  * Since: 2.4
10555  **/
10556 void
10557 gtk_widget_set_no_show_all (GtkWidget *widget,
10558                             gboolean   no_show_all)
10559 {
10560   g_return_if_fail (GTK_IS_WIDGET (widget));
10561
10562   no_show_all = (no_show_all != FALSE);
10563
10564   if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10565     return;
10566
10567   if (no_show_all)
10568     GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10569   else
10570     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10571   
10572   g_object_notify (G_OBJECT (widget), "no-show-all");
10573 }
10574
10575
10576 static void
10577 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10578                                  gboolean   has_tooltip,
10579                                  gboolean   force)
10580 {
10581   gboolean priv_has_tooltip;
10582
10583   priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10584                                        quark_has_tooltip));
10585
10586   if (priv_has_tooltip != has_tooltip || force)
10587     {
10588       priv_has_tooltip = has_tooltip;
10589
10590       if (priv_has_tooltip)
10591         {
10592           if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
10593             gdk_window_set_events (widget->window,
10594                                    gdk_window_get_events (widget->window) |
10595                                    GDK_LEAVE_NOTIFY_MASK |
10596                                    GDK_POINTER_MOTION_MASK |
10597                                    GDK_POINTER_MOTION_HINT_MASK);
10598
10599           if (!GTK_WIDGET_NO_WINDOW (widget))
10600               gtk_widget_add_events (widget,
10601                                      GDK_LEAVE_NOTIFY_MASK |
10602                                      GDK_POINTER_MOTION_MASK |
10603                                      GDK_POINTER_MOTION_HINT_MASK);
10604         }
10605
10606       g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10607                           GUINT_TO_POINTER (priv_has_tooltip));
10608     }
10609 }
10610
10611 /**
10612  * gtk_widget_set_tooltip_window:
10613  * @widget: a #GtkWidget
10614  * @custom_window: a #GtkWindow, or %NULL
10615  *
10616  * Replaces the default, usually yellow, window used for displaying
10617  * tooltips with @custom_window. GTK+ will take care of showing and
10618  * hiding @custom_window at the right moment, to behave likewise as
10619  * the default tooltip window. If @custom_window is %NULL, the default
10620  * tooltip window will be used.
10621  *
10622  * Since: 2.12
10623  */
10624 void
10625 gtk_widget_set_tooltip_window (GtkWidget *widget,
10626                                GtkWindow *custom_window)
10627 {
10628   gboolean has_tooltip;
10629   gchar *tooltip_markup;
10630
10631   g_return_if_fail (GTK_IS_WIDGET (widget));
10632   g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10633
10634   tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10635
10636   if (custom_window)
10637     g_object_ref (custom_window);
10638
10639   g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10640                            custom_window, g_object_unref);
10641
10642   has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10643   gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10644
10645   if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10646     gtk_widget_queue_tooltip_query (widget);
10647 }
10648
10649 /**
10650  * gtk_widget_get_tooltip_window:
10651  * @widget: a #GtkWidget
10652  *
10653  * Returns the #GtkWindow of the current tooltip. This can be the
10654  * GtkWindow created by default, or the custom tooltip window set
10655  * using gtk_widget_set_tooltip_window().
10656  *
10657  * Return value: The #GtkWindow of the current tooltip.
10658  *
10659  * Since: 2.12
10660  */
10661 GtkWindow *
10662 gtk_widget_get_tooltip_window (GtkWidget *widget)
10663 {
10664   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10665
10666   return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10667 }
10668
10669 /**
10670  * gtk_widget_trigger_tooltip_query:
10671  * @widget: a #GtkWidget
10672  *
10673  * Triggers a tooltip query on the display where the toplevel of @widget
10674  * is located. See gtk_tooltip_trigger_tooltip_query() for more
10675  * information.
10676  *
10677  * Since: 2.12
10678  */
10679 void
10680 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10681 {
10682   gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10683 }
10684
10685 static guint tooltip_query_id;
10686 static GSList *tooltip_query_displays;
10687
10688 static gboolean
10689 tooltip_query_idle (gpointer data)
10690 {
10691   g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
10692   g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
10693   g_slist_free (tooltip_query_displays);
10694
10695   tooltip_query_displays = NULL;
10696   tooltip_query_id = 0;
10697
10698   return FALSE;
10699 }
10700
10701 static void
10702 gtk_widget_queue_tooltip_query (GtkWidget *widget)
10703 {
10704   GdkDisplay *display;
10705
10706   display = gtk_widget_get_display (widget);
10707
10708   if (!g_slist_find (tooltip_query_displays, display))
10709     tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
10710
10711   if (tooltip_query_id == 0)
10712     tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
10713 }
10714
10715 /**
10716  * gtk_widget_set_tooltip_text:
10717  * @widget: a #GtkWidget
10718  * @text: the contents of the tooltip for @widget
10719  *
10720  * Sets @text as the contents of the tooltip. This function will take
10721  * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10722  * handler for the GtkWidget::query-tooltip signal.
10723  *
10724  * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10725  *
10726  * Since: 2.12
10727  */
10728 void
10729 gtk_widget_set_tooltip_text (GtkWidget   *widget,
10730                              const gchar *text)
10731 {
10732   g_return_if_fail (GTK_IS_WIDGET (widget));
10733
10734   g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10735 }
10736
10737 /**
10738  * gtk_widget_get_tooltip_text:
10739  * @widget: a #GtkWidget
10740  *
10741  * Gets the contents of the tooltip for @widget.
10742  *
10743  * Return value: the tooltip text, or %NULL. You should free the
10744  *   returned string with g_free() when done.
10745  *
10746  * Since: 2.12
10747  */
10748 gchar *
10749 gtk_widget_get_tooltip_text (GtkWidget *widget)
10750 {
10751   gchar *text = NULL;
10752
10753   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10754
10755   g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10756
10757   return text;
10758 }
10759
10760 /**
10761  * gtk_widget_set_tooltip_markup:
10762  * @widget: a #GtkWidget
10763  * @markup: the contents of the tooltip for @widget, or %NULL
10764  *
10765  * Sets @markup as the contents of the tooltip, which is marked up with
10766  *  the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10767  *
10768  * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10769  * and of the default handler for the GtkWidget::query-tooltip signal.
10770  *
10771  * See also the GtkWidget:tooltip-markup property and
10772  * gtk_tooltip_set_markup().
10773  *
10774  * Since: 2.12
10775  */
10776 void
10777 gtk_widget_set_tooltip_markup (GtkWidget   *widget,
10778                                const gchar *markup)
10779 {
10780   g_return_if_fail (GTK_IS_WIDGET (widget));
10781
10782   g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10783 }
10784
10785 /**
10786  * gtk_widget_get_tooltip_markup:
10787  * @widget: a #GtkWidget
10788  *
10789  * Gets the contents of the tooltip for @widget.
10790  *
10791  * Return value: the tooltip text, or %NULL. You should free the
10792  *   returned string with g_free() when done.
10793  *
10794  * Since: 2.12
10795  */
10796 gchar *
10797 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10798 {
10799   gchar *text = NULL;
10800
10801   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10802
10803   g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10804
10805   return text;
10806 }
10807
10808 /**
10809  * gtk_widget_set_has_tooltip:
10810  * @widget: a #GtkWidget
10811  * @has_tooltip: whether or not @widget has a tooltip.
10812  *
10813  * Sets the has-tooltip property on @widget to @has_tooltip.  See
10814  * GtkWidget:has-tooltip for more information.
10815  *
10816  * Since: 2.12
10817  */
10818 void
10819 gtk_widget_set_has_tooltip (GtkWidget *widget,
10820                             gboolean   has_tooltip)
10821 {
10822   g_return_if_fail (GTK_IS_WIDGET (widget));
10823
10824   g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
10825 }
10826
10827 /**
10828  * gtk_widget_get_has_tooltip:
10829  * @widget: a #GtkWidget
10830  *
10831  * Returns the current value of the has-tooltip property.  See
10832  * GtkWidget:has-tooltip for more information.
10833  *
10834  * Return value: current value of has-tooltip on @widget.
10835  *
10836  * Since: 2.12
10837  */
10838 gboolean
10839 gtk_widget_get_has_tooltip (GtkWidget *widget)
10840 {
10841   gboolean has_tooltip = FALSE;
10842
10843   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10844
10845   g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
10846
10847   return has_tooltip;
10848 }
10849
10850 /**
10851  * gtk_widget_get_allocation:
10852  * @widget: a #GtkWidget
10853  * @allocation: a pointer to a #GtkAllocation to copy to
10854  *
10855  * Retrieves the widget's allocation.
10856  *
10857  * Since: 2.18
10858  */
10859 void
10860 gtk_widget_get_allocation (GtkWidget     *widget,
10861                            GtkAllocation *allocation)
10862 {
10863   g_return_if_fail (GTK_IS_WIDGET (widget));
10864   g_return_if_fail (allocation != NULL);
10865
10866   *allocation = widget->allocation;
10867 }
10868
10869 /**
10870  * gtk_widget_set_allocation:
10871  * @widget: a #GtkWidget
10872  * @allocation: a pointer to a #GtkAllocation to copy from
10873  *
10874  * Sets the widget's allocation.  This should not be used
10875  * directly, but from within a widget's size_allocate method.
10876  *
10877  * Since: 2.18
10878  */
10879 void
10880 gtk_widget_set_allocation (GtkWidget           *widget,
10881                            const GtkAllocation *allocation)
10882 {
10883   g_return_if_fail (GTK_IS_WIDGET (widget));
10884   g_return_if_fail (allocation != NULL);
10885
10886   widget->allocation = *allocation;
10887 }
10888
10889 /**
10890  * gtk_widget_set_window:
10891  * @widget: a #GtkWidget
10892  * @window: a #GdkWindow
10893  *
10894  * Sets a widget's window. This function should only be used in a
10895  * widget's GtkWidget::realize() implementation. The %window passed is
10896  * usually either new window created with gdk_window_new(), or the
10897  * window of its parent widget as returned by
10898  * gtk_widget_get_parent_window().
10899  *
10900  * Widgets must indicate whether they will create their own #GdkWindow
10901  * by calling gtk_widget_set_has_window(). This is usually done in the
10902  * widget's init() function.
10903  *
10904  * Since: 2.18
10905  */
10906 void
10907 gtk_widget_set_window (GtkWidget *widget,
10908                        GdkWindow *window)
10909 {
10910   g_return_if_fail (GTK_IS_WIDGET (widget));
10911   g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10912
10913   if (widget->window != window)
10914     {
10915       widget->window = window;
10916       g_object_notify (G_OBJECT (widget), "window");
10917     }
10918 }
10919
10920 /**
10921  * gtk_widget_get_window:
10922  * @widget: a #GtkWidget
10923  *
10924  * Returns the widget's window if it is realized, %NULL otherwise
10925  *
10926  * Return value: @widget's window.
10927  *
10928  * Since: 2.14
10929  */
10930 GdkWindow*
10931 gtk_widget_get_window (GtkWidget *widget)
10932 {
10933   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10934
10935   return widget->window;
10936 }
10937
10938 #define __GTK_WIDGET_C__
10939 #include "gtkaliasdef.c"