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