1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
61 #include "gtkstylecontext.h"
62 #include "gtkcssprovider.h"
63 #include "gtkversion.h"
69 * @Short_description: Base class for all widgets
72 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
73 * widget lifecycle, states and style.
75 * <refsect2 id="geometry-management">
76 * <title>Height-for-width Geometry Management</title>
78 * GTK+ uses a height-for-width (and width-for-height) geometry management
79 * system. Height-for-width means that a widget can change how much
80 * vertical space it needs, depending on the amount of horizontal space
81 * that it is given (and similar for width-for-height). The most common
82 * example is a label that reflows to fill up the available width, wraps
83 * to fewer lines, and therefore needs less height.
85 * Height-for-width geometry management is implemented in GTK+ by way
86 * of five virtual methods:
88 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
95 * There are some important things to keep in mind when implementing
96 * height-for-width and when using it in container implementations.
98 * The geometry management system will query a widget hierarchy in
99 * only one orientation at a time. When widgets are initially queried
100 * for their minimum sizes it is generally done in two initial passes
101 * in the #GtkSizeRequestMode chosen by the toplevel.
103 * For example, when queried in the normal
104 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
105 * First, the default minimum and natural width for each widget
106 * in the interface will be computed using gtk_width_get_preferred_width().
107 * Because the preferred widths for each container depend on the preferred
108 * widths of their children, this information propagates up the hierarchy,
109 * and finally a minimum and natural width is determined for the entire
110 * toplevel. Next, the toplevel will use the minimum width to query for the
111 * minimum height contextual to that width using
112 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
113 * recursive operation. The minimum height for the minimum width is normally
114 * used to set the minimum size constraint on the toplevel
115 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
117 * After the toplevel window has initially requested its size in both
118 * dimensions it can go on to allocate itself a reasonable size (or a size
119 * previously specified with gtk_window_set_default_size()). During the
120 * recursive allocation process it's important to note that request cycles
121 * will be recursively executed while container widgets allocate their children.
122 * Each container widget, once allocated a size, will go on to first share the
123 * space in one orientation among its children and then request each child's
124 * height for its target allocated width or its width for allocated height,
125 * depending. In this way a #GtkWidget will typically be requested its size
126 * a number of times before actually being allocated a size. The size a
127 * widget is finally allocated can of course differ from the size it has
128 * requested. For this reason, #GtkWidget caches a small number of results
129 * to avoid re-querying for the same sizes in one allocation cycle.
131 * See <link linkend="container-geometry-management">GtkContainer's
132 * geometry management section</link>
133 * to learn more about how height-for-width allocations are performed
134 * by container widgets.
136 * If a widget does move content around to intelligently use up the
137 * allocated size then it must support the request in both
138 * #GtkSizeRequestModes even if the widget in question only
139 * trades sizes in a single orientation.
141 * For instance, a #GtkLabel that does height-for-width word wrapping
142 * will not expect to have #GtkWidgetClass.get_preferred_height() called
143 * because that call is specific to a width-for-height request. In this
144 * case the label must return the height required for its own minimum
145 * possible width. By following this rule any widget that handles
146 * height-for-width or width-for-height requests will always be allocated
147 * at least enough space to fit its own content.
149 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
150 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
152 * <programlisting><![CDATA[
154 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
156 * if (i_am_in_height_for_width_mode)
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
162 * min_height, nat_height);
166 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
167 * it will return the minimum and natural height for the rotated label here.
170 * ]]></programlisting>
172 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
173 * the minimum and natural width:
175 * <programlisting><![CDATA[
177 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
178 * gint *min_width, gint *nat_width)
180 * if (i_am_in_height_for_width_mode)
182 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
186 * ... again if a widget is sometimes operating in width-for-height mode
187 * (like a rotated GtkLabel) it can go ahead and do its real width for
188 * height calculation here.
191 * ]]></programlisting>
193 * Often a widget needs to get its own request during size request or
194 * allocation. For example, when computing height it may need to also
195 * compute width. Or when deciding how to use an allocation, the widget
196 * may need to know its natural size. In these cases, the widget should
197 * be careful to call its virtual methods directly, like this:
199 * <title>Widget calling its own size request method.</title>
201 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
206 * It will not work to use the wrapper functions, such as
207 * gtk_widget_get_preferred_width() inside your own size request
208 * implementation. These return a request adjusted by #GtkSizeGroup
209 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
210 * widget used the wrappers inside its virtual method implementations,
211 * then the adjustments (such as widget margins) would be applied
212 * twice. GTK+ therefore does not allow this and will warn if you try
215 * Of course if you are getting the size request for
216 * <emphasis>another</emphasis> widget, such as a child of a
217 * container, you <emphasis>must</emphasis> use the wrapper APIs.
218 * Otherwise, you would not properly consider widget margins,
219 * #GtkSizeGroup, and so forth.
222 * <refsect2 id="style-properties">
223 * <title>Style Properties</title>
225 * <structname>GtkWidget</structname> introduces <firstterm>style
226 * properties</firstterm> - these are basically object properties that are stored
227 * not on the object, but in the style object associated to the widget. Style
228 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
229 * This mechanism is used for configuring such things as the location of the
230 * scrollbar arrows through the theme, giving theme authors more control over the
231 * look of applications without the need to write a theme engine in C.
234 * Use gtk_widget_class_install_style_property() to install style properties for
235 * a widget class, gtk_widget_class_find_style_property() or
236 * gtk_widget_class_list_style_properties() to get information about existing
237 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
238 * gtk_widget_style_get_valist() to obtain the value of a style property.
241 * <refsect2 id="GtkWidget-BUILDER-UI">
242 * <title>GtkWidget as GtkBuildable</title>
244 * The GtkWidget implementation of the GtkBuildable interface supports a
245 * custom <accelerator> element, which has attributes named key,
246 * modifiers and signal and allows to specify accelerators.
249 * <title>A UI definition fragment specifying an accelerator</title>
250 * <programlisting><![CDATA[
251 * <object class="GtkButton">
252 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
254 * ]]></programlisting>
257 * In addition to accelerators, <structname>GtkWidget</structname> also support a
258 * custom <accessible> element, which supports actions and relations.
259 * Properties on the accessible implementation of an object can be set by accessing the
260 * internal child "accessible" of a <structname>GtkWidget</structname>.
263 * <title>A UI definition fragment specifying an accessible</title>
264 * <programlisting><![CDATA[
265 * <object class="GtkButton" id="label1"/>
266 * <property name="label">I am a Label for a Button</property>
268 * <object class="GtkButton" id="button1">
270 * <action action_name="click" translatable="yes">Click the button.</action>
271 * <relation target="label1" type="labelled-by"/>
273 * <child internal-child="accessible">
274 * <object class="AtkObject" id="a11y-button1">
275 * <property name="AtkObject::name">Clickable Button</property>
279 * ]]></programlisting>
284 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
285 #define INIT_PATH_SIZE (512)
287 struct _GtkWidgetPrivate
289 /* The state of the widget. There are actually only
290 * 5 widget states (defined in "gtkenums.h")
295 /* The saved state of the widget. When a widget's state
296 * is changed to GTK_STATE_INSENSITIVE via
297 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
298 * the old state is kept around in this field. The state
299 * will be restored once the widget gets sensitive again.
301 guint saved_state : 3;
305 guint in_destruction : 1;
308 guint composite_child : 1;
314 guint parent_sensitive : 1;
317 guint can_default : 1;
318 guint has_default : 1;
319 guint receives_default : 1;
323 guint user_style : 1;
324 guint app_paintable : 1;
325 guint double_buffered : 1;
326 guint redraw_on_alloc : 1;
327 guint no_show_all : 1;
328 guint child_visible : 1;
329 guint multidevice : 1;
330 guint has_shape_mask : 1;
331 guint in_reparent : 1;
332 guint resize_pending : 1;
333 guint alloc_needed : 1;
334 guint width_request_needed : 1;
335 guint height_request_needed : 1;
337 /* Expand-related flags */
338 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
339 guint computed_hexpand : 1; /* computed results (composite of child flags) */
340 guint computed_vexpand : 1;
341 guint hexpand : 1; /* application-forced expand */
343 guint hexpand_set : 1; /* whether to use application-forced */
344 guint vexpand_set : 1; /* instead of computing from children */
346 /* The widget's name. If the widget does not have a name
347 * (the name is NULL), then its name (as returned by
348 * "gtk_widget_get_name") is its class's name.
349 * Among other things, the widget name is used to determine
350 * the style to use for a widget.
354 /* The style for the widget. The style contains the
355 * colors the widget should be drawn in for each state
356 * along with graphics contexts used to draw with and
357 * the font to use for text.
361 /* The widget's allocated size.
363 GtkAllocation allocation;
365 /* The widget's requested sizes */
366 SizeRequestCache requests;
368 /* The widget's window or its parent window if it does
369 * not have a window. (Which will be indicated by the
370 * GTK_NO_WINDOW flag being set).
374 /* The widget's parent.
404 BUTTON_RELEASE_EVENT,
419 PROPERTY_NOTIFY_EVENT,
420 SELECTION_CLEAR_EVENT,
421 SELECTION_REQUEST_EVENT,
422 SELECTION_NOTIFY_EVENT,
428 VISIBILITY_NOTIFY_EVENT,
442 ACCEL_CLOSURES_CHANGED,
465 PROP_RECEIVES_DEFAULT,
466 PROP_COMPOSITE_CHILD,
469 PROP_EXTENSION_EVENTS,
475 PROP_DOUBLE_BUFFERED,
490 typedef struct _GtkStateData GtkStateData;
495 guint state_restoration : 1;
496 guint parent_sensitive : 1;
497 guint use_forall : 1;
500 /* --- prototypes --- */
501 static void gtk_widget_class_init (GtkWidgetClass *klass);
502 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
503 static void gtk_widget_init (GtkWidget *widget);
504 static void gtk_widget_set_property (GObject *object,
508 static void gtk_widget_get_property (GObject *object,
512 static void gtk_widget_dispose (GObject *object);
513 static void gtk_widget_real_destroy (GtkWidget *object);
514 static void gtk_widget_finalize (GObject *object);
515 static void gtk_widget_real_show (GtkWidget *widget);
516 static void gtk_widget_real_hide (GtkWidget *widget);
517 static void gtk_widget_real_map (GtkWidget *widget);
518 static void gtk_widget_real_unmap (GtkWidget *widget);
519 static void gtk_widget_real_realize (GtkWidget *widget);
520 static void gtk_widget_real_unrealize (GtkWidget *widget);
521 static void gtk_widget_real_size_allocate (GtkWidget *widget,
522 GtkAllocation *allocation);
523 static void gtk_widget_real_style_set (GtkWidget *widget,
524 GtkStyle *previous_style);
525 static void gtk_widget_real_direction_changed(GtkWidget *widget,
526 GtkTextDirection previous_direction);
528 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
529 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
532 gboolean keyboard_tip,
533 GtkTooltip *tooltip);
534 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
535 GtkWidgetHelpType help_type);
537 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
539 GParamSpec **pspecs);
540 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
542 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
544 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
545 GdkEventFocus *event);
546 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
547 GdkEventFocus *event);
548 static gboolean gtk_widget_real_focus (GtkWidget *widget,
549 GtkDirectionType direction);
550 static void gtk_widget_real_move_focus (GtkWidget *widget,
551 GtkDirectionType direction);
552 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
553 GtkDirectionType direction);
554 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
555 static void gtk_widget_update_pango_context (GtkWidget *widget);
556 static void gtk_widget_propagate_state (GtkWidget *widget,
558 static void gtk_widget_reset_rc_style (GtkWidget *widget);
559 static void gtk_widget_set_style_internal (GtkWidget *widget,
561 gboolean initial_emission);
562 static gint gtk_widget_event_internal (GtkWidget *widget,
564 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
565 gboolean group_cycling);
566 static void gtk_widget_real_get_width (GtkWidget *widget,
569 static void gtk_widget_real_get_height (GtkWidget *widget,
572 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
574 gint *minimum_height,
575 gint *natural_height);
576 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
579 gint *natural_width);
580 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
581 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
582 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
583 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
584 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
585 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
586 cairo_region_t *region);
587 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
588 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
589 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
592 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
593 gboolean has_tooltip,
595 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
596 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
598 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
599 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
601 const gchar *childname);
602 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
605 const GValue *value);
606 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
609 const gchar *tagname,
610 GMarkupParser *parser,
612 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
615 const gchar *tagname,
617 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
618 GtkBuilder *builder);
620 static void gtk_widget_real_get_width (GtkWidget *widget,
623 static void gtk_widget_real_get_height (GtkWidget *widget,
627 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
630 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
631 GtkOrientation orientation,
634 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
635 GtkOrientation orientation,
638 gint *allocated_size);
640 static void gtk_widget_set_usize_internal (GtkWidget *widget,
643 GtkQueueResizeFlags flags);
645 static void gtk_widget_add_events_internal (GtkWidget *widget,
649 /* --- variables --- */
650 static gpointer gtk_widget_parent_class = NULL;
651 static guint widget_signals[LAST_SIGNAL] = { 0 };
652 static GtkStyle *gtk_default_style = NULL;
653 static guint composite_child_stack = 0;
654 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
655 static GParamSpecPool *style_property_spec_pool = NULL;
657 static GQuark quark_property_parser = 0;
658 static GQuark quark_aux_info = 0;
659 static GQuark quark_accel_path = 0;
660 static GQuark quark_accel_closures = 0;
661 static GQuark quark_event_mask = 0;
662 static GQuark quark_device_event_mask = 0;
663 static GQuark quark_extension_event_mode = 0;
664 static GQuark quark_parent_window = 0;
665 static GQuark quark_pointer_window = 0;
666 static GQuark quark_shape_info = 0;
667 static GQuark quark_input_shape_info = 0;
668 static GQuark quark_pango_context = 0;
669 static GQuark quark_rc_style = 0;
670 static GQuark quark_accessible_object = 0;
671 static GQuark quark_mnemonic_labels = 0;
672 static GQuark quark_tooltip_markup = 0;
673 static GQuark quark_has_tooltip = 0;
674 static GQuark quark_tooltip_window = 0;
675 static GQuark quark_visual = 0;
676 static GQuark quark_style_context = 0;
677 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
678 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
680 /* --- functions --- */
682 gtk_widget_get_type (void)
684 static GType widget_type = 0;
686 if (G_UNLIKELY (widget_type == 0))
688 const GTypeInfo widget_info =
690 sizeof (GtkWidgetClass),
691 NULL, /* base_init */
692 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
693 (GClassInitFunc) gtk_widget_class_init,
694 NULL, /* class_finalize */
695 NULL, /* class_init */
698 (GInstanceInitFunc) gtk_widget_init,
699 NULL, /* value_table */
702 const GInterfaceInfo accessibility_info =
704 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
705 (GInterfaceFinalizeFunc) NULL,
706 NULL /* interface data */
709 const GInterfaceInfo buildable_info =
711 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
712 (GInterfaceFinalizeFunc) NULL,
713 NULL /* interface data */
716 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
717 &widget_info, G_TYPE_FLAG_ABSTRACT);
719 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
720 &accessibility_info) ;
721 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
729 child_property_notify_dispatcher (GObject *object,
733 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
736 /* We guard against the draw signal callbacks modifying the state of the
737 * cairo context by surounding it with save/restore.
738 * Maybe we should also cairo_new_path() just to be sure?
741 gtk_widget_draw_marshaller (GClosure *closure,
742 GValue *return_value,
743 guint n_param_values,
744 const GValue *param_values,
745 gpointer invocation_hint,
746 gpointer marshal_data)
748 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
752 _gtk_marshal_BOOLEAN__BOXED (closure,
763 gtk_widget_class_init (GtkWidgetClass *klass)
765 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
766 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
767 GtkBindingSet *binding_set;
769 gtk_widget_parent_class = g_type_class_peek_parent (klass);
771 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
772 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
773 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
774 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
775 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
776 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
777 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
778 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
779 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
780 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
781 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
782 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
783 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
784 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
785 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
786 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
787 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
788 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
789 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
790 quark_style_context = g_quark_from_static_string ("gtk-style-context");
792 style_property_spec_pool = g_param_spec_pool_new (FALSE);
793 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
794 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
795 cpn_context.dispatcher = child_property_notify_dispatcher;
796 _gtk_widget_child_property_notify_context = &cpn_context;
798 gobject_class->dispose = gtk_widget_dispose;
799 gobject_class->finalize = gtk_widget_finalize;
800 gobject_class->set_property = gtk_widget_set_property;
801 gobject_class->get_property = gtk_widget_get_property;
803 klass->destroy = gtk_widget_real_destroy;
805 klass->activate_signal = 0;
806 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
807 klass->show = gtk_widget_real_show;
808 klass->show_all = gtk_widget_show;
809 klass->hide = gtk_widget_real_hide;
810 klass->map = gtk_widget_real_map;
811 klass->unmap = gtk_widget_real_unmap;
812 klass->realize = gtk_widget_real_realize;
813 klass->unrealize = gtk_widget_real_unrealize;
814 klass->size_allocate = gtk_widget_real_size_allocate;
815 klass->get_preferred_width = gtk_widget_real_get_width;
816 klass->get_preferred_height = gtk_widget_real_get_height;
817 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
818 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
819 klass->state_changed = NULL;
820 klass->parent_set = NULL;
821 klass->hierarchy_changed = NULL;
822 klass->style_set = gtk_widget_real_style_set;
823 klass->direction_changed = gtk_widget_real_direction_changed;
824 klass->grab_notify = NULL;
825 klass->child_notify = NULL;
827 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
828 klass->grab_focus = gtk_widget_real_grab_focus;
829 klass->focus = gtk_widget_real_focus;
830 klass->move_focus = gtk_widget_real_move_focus;
831 klass->keynav_failed = gtk_widget_real_keynav_failed;
833 klass->button_press_event = NULL;
834 klass->button_release_event = NULL;
835 klass->motion_notify_event = NULL;
836 klass->delete_event = NULL;
837 klass->destroy_event = NULL;
838 klass->key_press_event = gtk_widget_real_key_press_event;
839 klass->key_release_event = gtk_widget_real_key_release_event;
840 klass->enter_notify_event = NULL;
841 klass->leave_notify_event = NULL;
842 klass->configure_event = NULL;
843 klass->focus_in_event = gtk_widget_real_focus_in_event;
844 klass->focus_out_event = gtk_widget_real_focus_out_event;
845 klass->map_event = NULL;
846 klass->unmap_event = NULL;
847 klass->window_state_event = NULL;
848 klass->property_notify_event = _gtk_selection_property_notify;
849 klass->selection_clear_event = _gtk_selection_clear;
850 klass->selection_request_event = _gtk_selection_request;
851 klass->selection_notify_event = _gtk_selection_notify;
852 klass->selection_received = NULL;
853 klass->proximity_in_event = NULL;
854 klass->proximity_out_event = NULL;
855 klass->drag_begin = NULL;
856 klass->drag_end = NULL;
857 klass->drag_data_delete = NULL;
858 klass->drag_leave = NULL;
859 klass->drag_motion = NULL;
860 klass->drag_drop = NULL;
861 klass->drag_data_received = NULL;
862 klass->screen_changed = NULL;
863 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
864 klass->grab_broken_event = NULL;
865 klass->query_tooltip = gtk_widget_real_query_tooltip;
867 klass->show_help = gtk_widget_real_show_help;
869 /* Accessibility support */
870 klass->get_accessible = gtk_widget_real_get_accessible;
872 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
873 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
875 g_object_class_install_property (gobject_class,
877 g_param_spec_string ("name",
879 P_("The name of the widget"),
881 GTK_PARAM_READWRITE));
882 g_object_class_install_property (gobject_class,
884 g_param_spec_object ("parent",
886 P_("The parent widget of this widget. Must be a Container widget"),
888 GTK_PARAM_READWRITE));
890 g_object_class_install_property (gobject_class,
892 g_param_spec_int ("width-request",
894 P_("Override for width request of the widget, or -1 if natural request should be used"),
898 GTK_PARAM_READWRITE));
899 g_object_class_install_property (gobject_class,
901 g_param_spec_int ("height-request",
902 P_("Height request"),
903 P_("Override for height request of the widget, or -1 if natural request should be used"),
907 GTK_PARAM_READWRITE));
908 g_object_class_install_property (gobject_class,
910 g_param_spec_boolean ("visible",
912 P_("Whether the widget is visible"),
914 GTK_PARAM_READWRITE));
915 g_object_class_install_property (gobject_class,
917 g_param_spec_boolean ("sensitive",
919 P_("Whether the widget responds to input"),
921 GTK_PARAM_READWRITE));
922 g_object_class_install_property (gobject_class,
924 g_param_spec_boolean ("app-paintable",
925 P_("Application paintable"),
926 P_("Whether the application will paint directly on the widget"),
928 GTK_PARAM_READWRITE));
929 g_object_class_install_property (gobject_class,
931 g_param_spec_boolean ("can-focus",
933 P_("Whether the widget can accept the input focus"),
935 GTK_PARAM_READWRITE));
936 g_object_class_install_property (gobject_class,
938 g_param_spec_boolean ("has-focus",
940 P_("Whether the widget has the input focus"),
942 GTK_PARAM_READWRITE));
943 g_object_class_install_property (gobject_class,
945 g_param_spec_boolean ("is-focus",
947 P_("Whether the widget is the focus widget within the toplevel"),
949 GTK_PARAM_READWRITE));
950 g_object_class_install_property (gobject_class,
952 g_param_spec_boolean ("can-default",
954 P_("Whether the widget can be the default widget"),
956 GTK_PARAM_READWRITE));
957 g_object_class_install_property (gobject_class,
959 g_param_spec_boolean ("has-default",
961 P_("Whether the widget is the default widget"),
963 GTK_PARAM_READWRITE));
964 g_object_class_install_property (gobject_class,
965 PROP_RECEIVES_DEFAULT,
966 g_param_spec_boolean ("receives-default",
967 P_("Receives default"),
968 P_("If TRUE, the widget will receive the default action when it is focused"),
970 GTK_PARAM_READWRITE));
971 g_object_class_install_property (gobject_class,
972 PROP_COMPOSITE_CHILD,
973 g_param_spec_boolean ("composite-child",
974 P_("Composite child"),
975 P_("Whether the widget is part of a composite widget"),
977 GTK_PARAM_READABLE));
978 g_object_class_install_property (gobject_class,
980 g_param_spec_object ("style",
982 P_("The style of the widget, which contains information about how it will look (colors etc)"),
984 GTK_PARAM_READWRITE));
985 g_object_class_install_property (gobject_class,
987 g_param_spec_flags ("events",
989 P_("The event mask that decides what kind of GdkEvents this widget gets"),
992 GTK_PARAM_READWRITE));
993 g_object_class_install_property (gobject_class,
994 PROP_EXTENSION_EVENTS,
995 g_param_spec_enum ("extension-events",
996 P_("Extension events"),
997 P_("The mask that decides what kind of extension events this widget gets"),
998 GDK_TYPE_EXTENSION_MODE,
999 GDK_EXTENSION_EVENTS_NONE,
1000 GTK_PARAM_READWRITE));
1001 g_object_class_install_property (gobject_class,
1003 g_param_spec_boolean ("no-show-all",
1005 P_("Whether gtk_widget_show_all() should not affect this widget"),
1007 GTK_PARAM_READWRITE));
1010 * GtkWidget:has-tooltip:
1012 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1013 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1014 * the widget will be queried using #GtkWidget::query-tooltip to determine
1015 * whether it will provide a tooltip or not.
1017 * Note that setting this property to %TRUE for the first time will change
1018 * the event masks of the GdkWindows of this widget to include leave-notify
1019 * and motion-notify events. This cannot and will not be undone when the
1020 * property is set to %FALSE again.
1024 g_object_class_install_property (gobject_class,
1026 g_param_spec_boolean ("has-tooltip",
1028 P_("Whether this widget has a tooltip"),
1030 GTK_PARAM_READWRITE));
1032 * GtkWidget:tooltip-text:
1034 * Sets the text of tooltip to be the given string.
1036 * Also see gtk_tooltip_set_text().
1038 * This is a convenience property which will take care of getting the
1039 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1040 * will automatically be set to %TRUE and there will be taken care of
1041 * #GtkWidget::query-tooltip in the default signal handler.
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_string ("tooltip-text",
1049 P_("The contents of the tooltip for this widget"),
1051 GTK_PARAM_READWRITE));
1053 * GtkWidget:tooltip-markup:
1055 * Sets the text of tooltip to be the given string, which is marked up
1056 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1057 * Also see gtk_tooltip_set_markup().
1059 * This is a convenience property which will take care of getting the
1060 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1061 * will automatically be set to %TRUE and there will be taken care of
1062 * #GtkWidget::query-tooltip in the default signal handler.
1066 g_object_class_install_property (gobject_class,
1067 PROP_TOOLTIP_MARKUP,
1068 g_param_spec_string ("tooltip-markup",
1069 P_("Tooltip markup"),
1070 P_("The contents of the tooltip for this widget"),
1072 GTK_PARAM_READWRITE));
1077 * The widget's window if it is realized, %NULL otherwise.
1081 g_object_class_install_property (gobject_class,
1083 g_param_spec_object ("window",
1085 P_("The widget's window if it is realized"),
1087 GTK_PARAM_READABLE));
1090 * GtkWidget:double-buffered
1092 * Whether the widget is double buffered.
1096 g_object_class_install_property (gobject_class,
1097 PROP_DOUBLE_BUFFERED,
1098 g_param_spec_boolean ("double-buffered",
1099 P_("Double Buffered"),
1100 P_("Whether the widget is double buffered"),
1102 GTK_PARAM_READWRITE));
1107 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1111 g_object_class_install_property (gobject_class,
1113 g_param_spec_enum ("halign",
1114 P_("Horizontal Alignment"),
1115 P_("How to position in extra horizontal space"),
1118 GTK_PARAM_READWRITE));
1123 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1127 g_object_class_install_property (gobject_class,
1129 g_param_spec_enum ("valign",
1130 P_("Vertical Alignment"),
1131 P_("How to position in extra vertical space"),
1134 GTK_PARAM_READWRITE));
1137 * GtkWidget:margin-left
1139 * Margin on left side of widget.
1141 * This property adds margin outside of the widget's normal size
1142 * request, the margin will be added in addition to the size from
1143 * gtk_widget_set_size_request() for example.
1147 g_object_class_install_property (gobject_class,
1149 g_param_spec_int ("margin-left",
1150 P_("Margin on Left"),
1151 P_("Pixels of extra space on the left side"),
1155 GTK_PARAM_READWRITE));
1158 * GtkWidget:margin-right
1160 * Margin on right side of widget.
1162 * This property adds margin outside of the widget's normal size
1163 * request, the margin will be added in addition to the size from
1164 * gtk_widget_set_size_request() for example.
1168 g_object_class_install_property (gobject_class,
1170 g_param_spec_int ("margin-right",
1171 P_("Margin on Right"),
1172 P_("Pixels of extra space on the right side"),
1176 GTK_PARAM_READWRITE));
1179 * GtkWidget:margin-top
1181 * Margin on top side of widget.
1183 * This property adds margin outside of the widget's normal size
1184 * request, the margin will be added in addition to the size from
1185 * gtk_widget_set_size_request() for example.
1189 g_object_class_install_property (gobject_class,
1191 g_param_spec_int ("margin-top",
1192 P_("Margin on Top"),
1193 P_("Pixels of extra space on the top side"),
1197 GTK_PARAM_READWRITE));
1200 * GtkWidget:margin-bottom
1202 * Margin on bottom side of widget.
1204 * This property adds margin outside of the widget's normal size
1205 * request, the margin will be added in addition to the size from
1206 * gtk_widget_set_size_request() for example.
1210 g_object_class_install_property (gobject_class,
1212 g_param_spec_int ("margin-bottom",
1213 P_("Margin on Bottom"),
1214 P_("Pixels of extra space on the bottom side"),
1218 GTK_PARAM_READWRITE));
1223 * Sets all four sides' margin at once. If read, returns max
1224 * margin on any side.
1228 g_object_class_install_property (gobject_class,
1230 g_param_spec_int ("margin",
1232 P_("Pixels of extra space on all four sides"),
1236 GTK_PARAM_READWRITE));
1239 * GtkWidget::destroy:
1240 * @object: the object which received the signal
1242 * Signals that all holders of a reference to the widget should release
1243 * the reference that they hold. May result in finalization of the widget
1244 * if all references are released.
1246 widget_signals[DESTROY] =
1247 g_signal_new (I_("destroy"),
1248 G_TYPE_FROM_CLASS (gobject_class),
1249 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1250 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1252 _gtk_marshal_VOID__VOID,
1258 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1262 g_object_class_install_property (gobject_class,
1264 g_param_spec_boolean ("hexpand",
1265 P_("Horizontal Expand"),
1266 P_("Whether widget wants more horizontal space"),
1268 GTK_PARAM_READWRITE));
1271 * GtkWidget:hexpand-set
1273 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1277 g_object_class_install_property (gobject_class,
1279 g_param_spec_boolean ("hexpand-set",
1280 P_("Horizontal Expand Set"),
1281 P_("Whether to use the hexpand property"),
1283 GTK_PARAM_READWRITE));
1288 * Whether to expand vertically. See gtk_widget_set_vexpand().
1292 g_object_class_install_property (gobject_class,
1294 g_param_spec_boolean ("vexpand",
1295 P_("Vertical Expand"),
1296 P_("Whether widget wants more vertical space"),
1298 GTK_PARAM_READWRITE));
1301 * GtkWidget:vexpand-set
1303 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1307 g_object_class_install_property (gobject_class,
1309 g_param_spec_boolean ("vexpand-set",
1310 P_("Vertical Expand Set"),
1311 P_("Whether to use the vexpand property"),
1313 GTK_PARAM_READWRITE));
1318 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1322 g_object_class_install_property (gobject_class,
1324 g_param_spec_boolean ("expand",
1326 P_("Whether widget wants to expand in both directions"),
1328 GTK_PARAM_READWRITE));
1332 * @widget: the object which received the signal.
1334 widget_signals[SHOW] =
1335 g_signal_new (I_("show"),
1336 G_TYPE_FROM_CLASS (gobject_class),
1338 G_STRUCT_OFFSET (GtkWidgetClass, show),
1340 _gtk_marshal_VOID__VOID,
1345 * @widget: the object which received the signal.
1347 widget_signals[HIDE] =
1348 g_signal_new (I_("hide"),
1349 G_TYPE_FROM_CLASS (gobject_class),
1351 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1353 _gtk_marshal_VOID__VOID,
1358 * @widget: the object which received the signal.
1360 widget_signals[MAP] =
1361 g_signal_new (I_("map"),
1362 G_TYPE_FROM_CLASS (gobject_class),
1364 G_STRUCT_OFFSET (GtkWidgetClass, map),
1366 _gtk_marshal_VOID__VOID,
1371 * @widget: the object which received the signal.
1373 widget_signals[UNMAP] =
1374 g_signal_new (I_("unmap"),
1375 G_TYPE_FROM_CLASS (gobject_class),
1377 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1379 _gtk_marshal_VOID__VOID,
1383 * GtkWidget::realize:
1384 * @widget: the object which received the signal.
1386 widget_signals[REALIZE] =
1387 g_signal_new (I_("realize"),
1388 G_TYPE_FROM_CLASS (gobject_class),
1390 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1392 _gtk_marshal_VOID__VOID,
1396 * GtkWidget::unrealize:
1397 * @widget: the object which received the signal.
1399 widget_signals[UNREALIZE] =
1400 g_signal_new (I_("unrealize"),
1401 G_TYPE_FROM_CLASS (gobject_class),
1403 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1405 _gtk_marshal_VOID__VOID,
1409 * GtkWidget::size-allocate:
1410 * @widget: the object which received the signal.
1413 widget_signals[SIZE_ALLOCATE] =
1414 g_signal_new (I_("size-allocate"),
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1419 _gtk_marshal_VOID__BOXED,
1421 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1424 * GtkWidget::state-changed:
1425 * @widget: the object which received the signal.
1426 * @state: the previous state
1428 * The ::state-changed signal is emitted when the widget state changes.
1429 * See gtk_widget_get_state().
1431 widget_signals[STATE_CHANGED] =
1432 g_signal_new (I_("state-changed"),
1433 G_TYPE_FROM_CLASS (gobject_class),
1435 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1437 _gtk_marshal_VOID__ENUM,
1439 GTK_TYPE_STATE_TYPE);
1442 * GtkWidget::parent-set:
1443 * @widget: the object on which the signal is emitted
1444 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1445 * just got its initial parent.
1447 * The ::parent-set signal is emitted when a new parent
1448 * has been set on a widget.
1450 widget_signals[PARENT_SET] =
1451 g_signal_new (I_("parent-set"),
1452 G_TYPE_FROM_CLASS (gobject_class),
1454 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1456 _gtk_marshal_VOID__OBJECT,
1461 * GtkWidget::hierarchy-changed:
1462 * @widget: the object on which the signal is emitted
1463 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1464 * if the widget was previously unanchored
1466 * The ::hierarchy-changed signal is emitted when the
1467 * anchored state of a widget changes. A widget is
1468 * <firstterm>anchored</firstterm> when its toplevel
1469 * ancestor is a #GtkWindow. This signal is emitted when
1470 * a widget changes from un-anchored to anchored or vice-versa.
1472 widget_signals[HIERARCHY_CHANGED] =
1473 g_signal_new (I_("hierarchy-changed"),
1474 G_TYPE_FROM_CLASS (gobject_class),
1476 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1478 _gtk_marshal_VOID__OBJECT,
1483 * GtkWidget::style-set:
1484 * @widget: the object on which the signal is emitted
1485 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1486 * just got its initial style
1488 * The ::style-set signal is emitted when a new style has been set
1489 * on a widget. Note that style-modifying functions like
1490 * gtk_widget_modify_base() also cause this signal to be emitted.
1492 widget_signals[STYLE_SET] =
1493 g_signal_new (I_("style-set"),
1494 G_TYPE_FROM_CLASS (gobject_class),
1496 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1498 _gtk_marshal_VOID__OBJECT,
1503 * GtkWidget::direction-changed:
1504 * @widget: the object on which the signal is emitted
1505 * @previous_direction: the previous text direction of @widget
1507 * The ::direction-changed signal is emitted when the text direction
1508 * of a widget changes.
1510 widget_signals[DIRECTION_CHANGED] =
1511 g_signal_new (I_("direction-changed"),
1512 G_TYPE_FROM_CLASS (gobject_class),
1514 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1516 _gtk_marshal_VOID__ENUM,
1518 GTK_TYPE_TEXT_DIRECTION);
1521 * GtkWidget::grab-notify:
1522 * @widget: the object which received the signal
1523 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1524 * if it becomes unshadowed
1526 * The ::grab-notify signal is emitted when a widget becomes
1527 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1528 * another widget, or when it becomes unshadowed due to a grab
1531 * A widget is shadowed by a gtk_grab_add() when the topmost
1532 * grab widget in the grab stack of its window group is not
1535 widget_signals[GRAB_NOTIFY] =
1536 g_signal_new (I_("grab-notify"),
1537 G_TYPE_FROM_CLASS (gobject_class),
1539 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1541 _gtk_marshal_VOID__BOOLEAN,
1546 * GtkWidget::child-notify:
1547 * @widget: the object which received the signal
1548 * @pspec: the #GParamSpec of the changed child property
1550 * The ::child-notify signal is emitted for each
1551 * <link linkend="child-properties">child property</link> that has
1552 * changed on an object. The signal's detail holds the property name.
1554 widget_signals[CHILD_NOTIFY] =
1555 g_signal_new (I_("child-notify"),
1556 G_TYPE_FROM_CLASS (gobject_class),
1557 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1558 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1560 g_cclosure_marshal_VOID__PARAM,
1566 * @widget: the object which received the signal
1567 * @cr: the cairo context to draw to
1569 * This signal is emitted when a widget is supposed to render itself.
1570 * The @widget's top left corner must be painted at the origin of
1571 * the passed in context and be sized to the values returned by
1572 * gtk_widget_get_allocated_width() and
1573 * gtk_widget_get_allocated_height().
1575 * Signal handlers connected to this signal can modify the cairo
1576 * context passed as @cr in any way they like and don't need to
1577 * restore it. The signal emission takes care of calling cairo_save()
1578 * before and cairo_restore() after invoking the handler.
1580 widget_signals[DRAW] =
1581 g_signal_new (I_("draw"),
1582 G_TYPE_FROM_CLASS (gobject_class),
1584 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1585 _gtk_boolean_handled_accumulator, NULL,
1586 gtk_widget_draw_marshaller,
1588 CAIRO_GOBJECT_TYPE_CONTEXT);
1591 * GtkWidget::mnemonic-activate:
1592 * @widget: the object which received the signal.
1595 widget_signals[MNEMONIC_ACTIVATE] =
1596 g_signal_new (I_("mnemonic-activate"),
1597 G_TYPE_FROM_CLASS (gobject_class),
1599 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1600 _gtk_boolean_handled_accumulator, NULL,
1601 _gtk_marshal_BOOLEAN__BOOLEAN,
1606 * GtkWidget::grab-focus:
1607 * @widget: the object which received the signal.
1609 widget_signals[GRAB_FOCUS] =
1610 g_signal_new (I_("grab-focus"),
1611 G_TYPE_FROM_CLASS (gobject_class),
1612 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1613 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1615 _gtk_marshal_VOID__VOID,
1620 * @widget: the object which received the signal.
1623 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1625 widget_signals[FOCUS] =
1626 g_signal_new (I_("focus"),
1627 G_TYPE_FROM_CLASS (klass),
1629 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1630 _gtk_boolean_handled_accumulator, NULL,
1631 _gtk_marshal_BOOLEAN__ENUM,
1633 GTK_TYPE_DIRECTION_TYPE);
1636 * GtkWidget::move-focus:
1637 * @widget: the object which received the signal.
1640 widget_signals[MOVE_FOCUS] =
1641 g_signal_new (I_("move-focus"),
1642 G_TYPE_FROM_CLASS (klass),
1643 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1644 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1646 _gtk_marshal_VOID__ENUM,
1649 GTK_TYPE_DIRECTION_TYPE);
1652 * GtkWidget::keynav-failed:
1653 * @widget: the object which received the signal
1654 * @direction: the direction of movement
1656 * Gets emitted if keyboard navigation fails.
1657 * See gtk_widget_keynav_failed() for details.
1659 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1660 * if the emitting widget should try to handle the keyboard
1661 * navigation attempt in its parent container(s).
1665 widget_signals[KEYNAV_FAILED] =
1666 g_signal_new (I_("keynav-failed"),
1667 G_TYPE_FROM_CLASS (klass),
1669 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1670 _gtk_boolean_handled_accumulator, NULL,
1671 _gtk_marshal_BOOLEAN__ENUM,
1673 GTK_TYPE_DIRECTION_TYPE);
1677 * @widget: the object which received the signal.
1678 * @event: the #GdkEvent which triggered this signal
1680 * The GTK+ main loop will emit three signals for each GDK event delivered
1681 * to a widget: one generic ::event signal, another, more specific,
1682 * signal that matches the type of event delivered (e.g.
1683 * #GtkWidget::key-press-event) and finally a generic
1684 * #GtkWidget::event-after signal.
1686 * Returns: %TRUE to stop other handlers from being invoked for the event
1687 * and to cancel the emission of the second specific ::event signal.
1688 * %FALSE to propagate the event further and to allow the emission of
1689 * the second signal. The ::event-after signal is emitted regardless of
1692 widget_signals[EVENT] =
1693 g_signal_new (I_("event"),
1694 G_TYPE_FROM_CLASS (klass),
1696 G_STRUCT_OFFSET (GtkWidgetClass, event),
1697 _gtk_boolean_handled_accumulator, NULL,
1698 _gtk_marshal_BOOLEAN__BOXED,
1700 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1703 * GtkWidget::event-after:
1704 * @widget: the object which received the signal.
1705 * @event: the #GdkEvent which triggered this signal
1707 * After the emission of the #GtkWidget::event signal and (optionally)
1708 * the second more specific signal, ::event-after will be emitted
1709 * regardless of the previous two signals handlers return values.
1712 widget_signals[EVENT_AFTER] =
1713 g_signal_new (I_("event-after"),
1714 G_TYPE_FROM_CLASS (klass),
1718 _gtk_marshal_VOID__BOXED,
1720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1723 * GtkWidget::button-press-event:
1724 * @widget: the object which received the signal.
1725 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1728 * The ::button-press-event signal will be emitted when a button
1729 * (typically from a mouse) is pressed.
1731 * To receive this signal, the #GdkWindow associated to the
1732 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1734 * This signal will be sent to the grab widget if there is one.
1736 * Returns: %TRUE to stop other handlers from being invoked for the event.
1737 * %FALSE to propagate the event further.
1739 widget_signals[BUTTON_PRESS_EVENT] =
1740 g_signal_new (I_("button-press-event"),
1741 G_TYPE_FROM_CLASS (klass),
1743 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1744 _gtk_boolean_handled_accumulator, NULL,
1745 _gtk_marshal_BOOLEAN__BOXED,
1747 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1750 * GtkWidget::button-release-event:
1751 * @widget: the object which received the signal.
1752 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1755 * The ::button-release-event signal will be emitted when a button
1756 * (typically from a mouse) is released.
1758 * To receive this signal, the #GdkWindow associated to the
1759 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1761 * This signal will be sent to the grab widget if there is one.
1763 * Returns: %TRUE to stop other handlers from being invoked for the event.
1764 * %FALSE to propagate the event further.
1766 widget_signals[BUTTON_RELEASE_EVENT] =
1767 g_signal_new (I_("button-release-event"),
1768 G_TYPE_FROM_CLASS (klass),
1770 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1771 _gtk_boolean_handled_accumulator, NULL,
1772 _gtk_marshal_BOOLEAN__BOXED,
1774 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1777 * GtkWidget::scroll-event:
1778 * @widget: the object which received the signal.
1779 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1782 * The ::scroll-event signal is emitted when a button in the 4 to 7
1783 * range is pressed. Wheel mice are usually configured to generate
1784 * button press events for buttons 4 and 5 when the wheel is turned.
1786 * To receive this signal, the #GdkWindow associated to the widget needs
1787 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1789 * This signal will be sent to the grab widget if there is one.
1791 * Returns: %TRUE to stop other handlers from being invoked for the event.
1792 * %FALSE to propagate the event further.
1794 widget_signals[SCROLL_EVENT] =
1795 g_signal_new (I_("scroll-event"),
1796 G_TYPE_FROM_CLASS (klass),
1798 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1799 _gtk_boolean_handled_accumulator, NULL,
1800 _gtk_marshal_BOOLEAN__BOXED,
1802 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1805 * GtkWidget::motion-notify-event:
1806 * @widget: the object which received the signal.
1807 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1810 * The ::motion-notify-event signal is emitted when the pointer moves
1811 * over the widget's #GdkWindow.
1813 * To receive this signal, the #GdkWindow associated to the widget
1814 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1816 * This signal will be sent to the grab widget if there is one.
1818 * Returns: %TRUE to stop other handlers from being invoked for the event.
1819 * %FALSE to propagate the event further.
1821 widget_signals[MOTION_NOTIFY_EVENT] =
1822 g_signal_new (I_("motion-notify-event"),
1823 G_TYPE_FROM_CLASS (klass),
1825 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1826 _gtk_boolean_handled_accumulator, NULL,
1827 _gtk_marshal_BOOLEAN__BOXED,
1829 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1832 * GtkWidget::composited-changed:
1833 * @widget: the object on which the signal is emitted
1835 * The ::composited-changed signal is emitted when the composited
1836 * status of @widget<!-- -->s screen changes.
1837 * See gdk_screen_is_composited().
1839 widget_signals[COMPOSITED_CHANGED] =
1840 g_signal_new (I_("composited-changed"),
1841 G_TYPE_FROM_CLASS (klass),
1842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1843 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1845 _gtk_marshal_VOID__VOID,
1849 * GtkWidget::delete-event:
1850 * @widget: the object which received the signal
1851 * @event: the event which triggered this signal
1853 * The ::delete-event signal is emitted if a user requests that
1854 * a toplevel window is closed. The default handler for this signal
1855 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1856 * this signal will cause the window to be hidden instead, so that
1857 * it can later be shown again without reconstructing it.
1859 * Returns: %TRUE to stop other handlers from being invoked for the event.
1860 * %FALSE to propagate the event further.
1862 widget_signals[DELETE_EVENT] =
1863 g_signal_new (I_("delete-event"),
1864 G_TYPE_FROM_CLASS (klass),
1866 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1867 _gtk_boolean_handled_accumulator, NULL,
1868 _gtk_marshal_BOOLEAN__BOXED,
1870 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1873 * GtkWidget::destroy-event:
1874 * @widget: the object which received the signal.
1875 * @event: the event which triggered this signal
1877 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1878 * You rarely get this signal, because most widgets disconnect themselves
1879 * from their window before they destroy it, so no widget owns the
1880 * window at destroy time.
1882 * To receive this signal, the #GdkWindow associated to the widget needs
1883 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1884 * automatically for all new windows.
1886 * Returns: %TRUE to stop other handlers from being invoked for the event.
1887 * %FALSE to propagate the event further.
1889 widget_signals[DESTROY_EVENT] =
1890 g_signal_new (I_("destroy-event"),
1891 G_TYPE_FROM_CLASS (klass),
1893 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1894 _gtk_boolean_handled_accumulator, NULL,
1895 _gtk_marshal_BOOLEAN__BOXED,
1897 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1900 * GtkWidget::key-press-event:
1901 * @widget: the object which received the signal
1902 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1904 * The ::key-press-event signal is emitted when a key is pressed.
1906 * To receive this signal, the #GdkWindow associated to the widget needs
1907 * to enable the #GDK_KEY_PRESS_MASK mask.
1909 * This signal will be sent to the grab widget if there is one.
1911 * Returns: %TRUE to stop other handlers from being invoked for the event.
1912 * %FALSE to propagate the event further.
1914 widget_signals[KEY_PRESS_EVENT] =
1915 g_signal_new (I_("key-press-event"),
1916 G_TYPE_FROM_CLASS (klass),
1918 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1919 _gtk_boolean_handled_accumulator, NULL,
1920 _gtk_marshal_BOOLEAN__BOXED,
1922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1925 * GtkWidget::key-release-event:
1926 * @widget: the object which received the signal
1927 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1929 * The ::key-release-event signal is emitted when a key is pressed.
1931 * To receive this signal, the #GdkWindow associated to the widget needs
1932 * to enable the #GDK_KEY_RELEASE_MASK mask.
1934 * This signal will be sent to the grab widget if there is one.
1936 * Returns: %TRUE to stop other handlers from being invoked for the event.
1937 * %FALSE to propagate the event further.
1939 widget_signals[KEY_RELEASE_EVENT] =
1940 g_signal_new (I_("key-release-event"),
1941 G_TYPE_FROM_CLASS (klass),
1943 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1944 _gtk_boolean_handled_accumulator, NULL,
1945 _gtk_marshal_BOOLEAN__BOXED,
1947 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1950 * GtkWidget::enter-notify-event:
1951 * @widget: the object which received the signal
1952 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1955 * The ::enter-notify-event will be emitted when the pointer enters
1956 * the @widget's window.
1958 * To receive this signal, the #GdkWindow associated to the widget needs
1959 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1961 * This signal will be sent to the grab widget if there is one.
1963 * Returns: %TRUE to stop other handlers from being invoked for the event.
1964 * %FALSE to propagate the event further.
1966 widget_signals[ENTER_NOTIFY_EVENT] =
1967 g_signal_new (I_("enter-notify-event"),
1968 G_TYPE_FROM_CLASS (klass),
1970 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1971 _gtk_boolean_handled_accumulator, NULL,
1972 _gtk_marshal_BOOLEAN__BOXED,
1974 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1977 * GtkWidget::leave-notify-event:
1978 * @widget: the object which received the signal
1979 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1982 * The ::leave-notify-event will be emitted when the pointer leaves
1983 * the @widget's window.
1985 * To receive this signal, the #GdkWindow associated to the widget needs
1986 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1988 * This signal will be sent to the grab widget if there is one.
1990 * Returns: %TRUE to stop other handlers from being invoked for the event.
1991 * %FALSE to propagate the event further.
1993 widget_signals[LEAVE_NOTIFY_EVENT] =
1994 g_signal_new (I_("leave-notify-event"),
1995 G_TYPE_FROM_CLASS (klass),
1997 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1998 _gtk_boolean_handled_accumulator, NULL,
1999 _gtk_marshal_BOOLEAN__BOXED,
2001 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2004 * GtkWidget::configure-event:
2005 * @widget: the object which received the signal
2006 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2009 * The ::configure-event signal will be emitted when the size, position or
2010 * stacking of the @widget's window has changed.
2012 * To receive this signal, the #GdkWindow associated to the widget needs
2013 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2014 * automatically for all new windows.
2016 * Returns: %TRUE to stop other handlers from being invoked for the event.
2017 * %FALSE to propagate the event further.
2019 widget_signals[CONFIGURE_EVENT] =
2020 g_signal_new (I_("configure-event"),
2021 G_TYPE_FROM_CLASS (klass),
2023 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2024 _gtk_boolean_handled_accumulator, NULL,
2025 _gtk_marshal_BOOLEAN__BOXED,
2027 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2030 * GtkWidget::focus-in-event:
2031 * @widget: the object which received the signal
2032 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2035 * The ::focus-in-event signal will be emitted when the keyboard focus
2036 * enters the @widget's window.
2038 * To receive this signal, the #GdkWindow associated to the widget needs
2039 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2041 * Returns: %TRUE to stop other handlers from being invoked for the event.
2042 * %FALSE to propagate the event further.
2044 widget_signals[FOCUS_IN_EVENT] =
2045 g_signal_new (I_("focus-in-event"),
2046 G_TYPE_FROM_CLASS (klass),
2048 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2049 _gtk_boolean_handled_accumulator, NULL,
2050 _gtk_marshal_BOOLEAN__BOXED,
2052 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2055 * GtkWidget::focus-out-event:
2056 * @widget: the object which received the signal
2057 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2060 * The ::focus-out-event signal will be emitted when the keyboard focus
2061 * leaves the @widget's window.
2063 * To receive this signal, the #GdkWindow associated to the widget needs
2064 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2066 * Returns: %TRUE to stop other handlers from being invoked for the event.
2067 * %FALSE to propagate the event further.
2069 widget_signals[FOCUS_OUT_EVENT] =
2070 g_signal_new (I_("focus-out-event"),
2071 G_TYPE_FROM_CLASS (klass),
2073 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2074 _gtk_boolean_handled_accumulator, NULL,
2075 _gtk_marshal_BOOLEAN__BOXED,
2077 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2080 * GtkWidget::map-event:
2081 * @widget: the object which received the signal
2082 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2084 * The ::map-event signal will be emitted when the @widget's window is
2085 * mapped. A window is mapped when it becomes visible on the screen.
2087 * To receive this signal, the #GdkWindow associated to the widget needs
2088 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2089 * automatically for all new windows.
2091 * Returns: %TRUE to stop other handlers from being invoked for the event.
2092 * %FALSE to propagate the event further.
2094 widget_signals[MAP_EVENT] =
2095 g_signal_new (I_("map-event"),
2096 G_TYPE_FROM_CLASS (klass),
2098 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2099 _gtk_boolean_handled_accumulator, NULL,
2100 _gtk_marshal_BOOLEAN__BOXED,
2102 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2105 * GtkWidget::unmap-event:
2106 * @widget: the object which received the signal
2107 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2109 * The ::unmap-event signal may be emitted when the @widget's window is
2110 * unmapped. A window is unmapped when it becomes invisible on the screen.
2112 * For performance reasons GTK+ may not emit ::unmap-event, so one
2113 * should always also implement ::unrealize in order to release
2114 * resources and disconnect signal handlers.
2116 * To receive this signal, the #GdkWindow associated to the widget needs
2117 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2118 * automatically for all new windows.
2120 * Returns: %TRUE to stop other handlers from being invoked for the event.
2121 * %FALSE to propagate the event further.
2123 widget_signals[UNMAP_EVENT] =
2124 g_signal_new (I_("unmap-event"),
2125 G_TYPE_FROM_CLASS (klass),
2127 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2128 _gtk_boolean_handled_accumulator, NULL,
2129 _gtk_marshal_BOOLEAN__BOXED,
2131 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2134 * GtkWidget::property-notify-event:
2135 * @widget: the object which received the signal
2136 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2139 * The ::property-notify-event signal will be emitted when a property on
2140 * the @widget's window has been changed or deleted.
2142 * To receive this signal, the #GdkWindow associated to the widget needs
2143 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2145 * Returns: %TRUE to stop other handlers from being invoked for the event.
2146 * %FALSE to propagate the event further.
2148 widget_signals[PROPERTY_NOTIFY_EVENT] =
2149 g_signal_new (I_("property-notify-event"),
2150 G_TYPE_FROM_CLASS (klass),
2152 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2153 _gtk_boolean_handled_accumulator, NULL,
2154 _gtk_marshal_BOOLEAN__BOXED,
2156 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2159 * GtkWidget::selection-clear-event:
2160 * @widget: the object which received the signal
2161 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2164 * The ::selection-clear-event signal will be emitted when the
2165 * the @widget's window has lost ownership of a selection.
2167 * Returns: %TRUE to stop other handlers from being invoked for the event.
2168 * %FALSE to propagate the event further.
2170 widget_signals[SELECTION_CLEAR_EVENT] =
2171 g_signal_new (I_("selection-clear-event"),
2172 G_TYPE_FROM_CLASS (klass),
2174 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2175 _gtk_boolean_handled_accumulator, NULL,
2176 _gtk_marshal_BOOLEAN__BOXED,
2178 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2181 * GtkWidget::selection-request-event:
2182 * @widget: the object which received the signal
2183 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2186 * The ::selection-request-event signal will be emitted when
2187 * another client requests ownership of the selection owned by
2188 * the @widget's window.
2190 * Returns: %TRUE to stop other handlers from being invoked for the event.
2191 * %FALSE to propagate the event further.
2193 widget_signals[SELECTION_REQUEST_EVENT] =
2194 g_signal_new (I_("selection-request-event"),
2195 G_TYPE_FROM_CLASS (klass),
2197 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2198 _gtk_boolean_handled_accumulator, NULL,
2199 _gtk_marshal_BOOLEAN__BOXED,
2201 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2204 * GtkWidget::selection-notify-event:
2205 * @widget: the object which received the signal.
2208 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2210 widget_signals[SELECTION_NOTIFY_EVENT] =
2211 g_signal_new (I_("selection-notify-event"),
2212 G_TYPE_FROM_CLASS (klass),
2214 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2215 _gtk_boolean_handled_accumulator, NULL,
2216 _gtk_marshal_BOOLEAN__BOXED,
2218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 * GtkWidget::selection-received:
2222 * @widget: the object which received the signal.
2226 widget_signals[SELECTION_RECEIVED] =
2227 g_signal_new (I_("selection-received"),
2228 G_TYPE_FROM_CLASS (klass),
2230 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2232 _gtk_marshal_VOID__BOXED_UINT,
2234 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2238 * GtkWidget::selection-get:
2239 * @widget: the object which received the signal.
2244 widget_signals[SELECTION_GET] =
2245 g_signal_new (I_("selection-get"),
2246 G_TYPE_FROM_CLASS (klass),
2248 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2250 _gtk_marshal_VOID__BOXED_UINT_UINT,
2252 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2257 * GtkWidget::proximity-in-event:
2258 * @widget: the object which received the signal
2259 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2262 * To receive this signal the #GdkWindow associated to the widget needs
2263 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2265 * This signal will be sent to the grab widget if there is one.
2267 * Returns: %TRUE to stop other handlers from being invoked for the event.
2268 * %FALSE to propagate the event further.
2270 widget_signals[PROXIMITY_IN_EVENT] =
2271 g_signal_new (I_("proximity-in-event"),
2272 G_TYPE_FROM_CLASS (klass),
2274 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2275 _gtk_boolean_handled_accumulator, NULL,
2276 _gtk_marshal_BOOLEAN__BOXED,
2278 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2281 * GtkWidget::proximity-out-event:
2282 * @widget: the object which received the signal
2283 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2286 * To receive this signal the #GdkWindow associated to the widget needs
2287 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2289 * This signal will be sent to the grab widget if there is one.
2291 * Returns: %TRUE to stop other handlers from being invoked for the event.
2292 * %FALSE to propagate the event further.
2294 widget_signals[PROXIMITY_OUT_EVENT] =
2295 g_signal_new (I_("proximity-out-event"),
2296 G_TYPE_FROM_CLASS (klass),
2298 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2299 _gtk_boolean_handled_accumulator, NULL,
2300 _gtk_marshal_BOOLEAN__BOXED,
2302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2305 * GtkWidget::drag-leave:
2306 * @widget: the object which received the signal.
2307 * @drag_context: the drag context
2308 * @time: the timestamp of the motion event
2310 * The ::drag-leave signal is emitted on the drop site when the cursor
2311 * leaves the widget. A typical reason to connect to this signal is to
2312 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2313 * with gtk_drag_unhighlight()
2315 widget_signals[DRAG_LEAVE] =
2316 g_signal_new (I_("drag-leave"),
2317 G_TYPE_FROM_CLASS (klass),
2319 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2321 _gtk_marshal_VOID__OBJECT_UINT,
2323 GDK_TYPE_DRAG_CONTEXT,
2327 * GtkWidget::drag-begin:
2328 * @widget: the object which received the signal
2329 * @drag_context: the drag context
2331 * The ::drag-begin signal is emitted on the drag source when a drag is
2332 * started. A typical reason to connect to this signal is to set up a
2333 * custom drag icon with gtk_drag_source_set_icon().
2335 * Note that some widgets set up a drag icon in the default handler of
2336 * this signal, so you may have to use g_signal_connect_after() to
2337 * override what the default handler did.
2339 widget_signals[DRAG_BEGIN] =
2340 g_signal_new (I_("drag-begin"),
2341 G_TYPE_FROM_CLASS (klass),
2343 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2345 _gtk_marshal_VOID__OBJECT,
2347 GDK_TYPE_DRAG_CONTEXT);
2350 * GtkWidget::drag-end:
2351 * @widget: the object which received the signal
2352 * @drag_context: the drag context
2354 * The ::drag-end signal is emitted on the drag source when a drag is
2355 * finished. A typical reason to connect to this signal is to undo
2356 * things done in #GtkWidget::drag-begin.
2358 widget_signals[DRAG_END] =
2359 g_signal_new (I_("drag-end"),
2360 G_TYPE_FROM_CLASS (klass),
2362 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2364 _gtk_marshal_VOID__OBJECT,
2366 GDK_TYPE_DRAG_CONTEXT);
2369 * GtkWidget::drag-data-delete:
2370 * @widget: the object which received the signal
2371 * @drag_context: the drag context
2373 * The ::drag-data-delete signal is emitted on the drag source when a drag
2374 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2375 * handler is responsible for deleting the data that has been dropped. What
2376 * "delete" means depends on the context of the drag operation.
2378 widget_signals[DRAG_DATA_DELETE] =
2379 g_signal_new (I_("drag-data-delete"),
2380 G_TYPE_FROM_CLASS (klass),
2382 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2384 _gtk_marshal_VOID__OBJECT,
2386 GDK_TYPE_DRAG_CONTEXT);
2389 * GtkWidget::drag-failed:
2390 * @widget: the object which received the signal
2391 * @drag_context: the drag context
2392 * @result: the result of the drag operation
2394 * The ::drag-failed signal is emitted on the drag source when a drag has
2395 * failed. The signal handler may hook custom code to handle a failed DND
2396 * operation based on the type of error, it returns %TRUE is the failure has
2397 * been already handled (not showing the default "drag operation failed"
2398 * animation), otherwise it returns %FALSE.
2400 * Return value: %TRUE if the failed drag operation has been already handled.
2404 widget_signals[DRAG_FAILED] =
2405 g_signal_new (I_("drag-failed"),
2406 G_TYPE_FROM_CLASS (klass),
2408 0, _gtk_boolean_handled_accumulator, NULL,
2409 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2411 GDK_TYPE_DRAG_CONTEXT,
2412 GTK_TYPE_DRAG_RESULT);
2415 * GtkWidget::drag-motion:
2416 * @widget: the object which received the signal
2417 * @drag_context: the drag context
2418 * @x: the x coordinate of the current cursor position
2419 * @y: the y coordinate of the current cursor position
2420 * @time: the timestamp of the motion event
2421 * @returns: whether the cursor position is in a drop zone
2423 * The drag-motion signal is emitted on the drop site when the user
2424 * moves the cursor over the widget during a drag. The signal handler
2425 * must determine whether the cursor position is in a drop zone or not.
2426 * If it is not in a drop zone, it returns %FALSE and no further processing
2427 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2428 * handler is responsible for providing the necessary information for
2429 * displaying feedback to the user, by calling gdk_drag_status().
2431 * If the decision whether the drop will be accepted or rejected can't be
2432 * made based solely on the cursor position and the type of the data, the
2433 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2434 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2435 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2436 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2437 * when using the drag-motion signal that way.
2439 * Also note that there is no drag-enter signal. The drag receiver has to
2440 * keep track of whether he has received any drag-motion signals since the
2441 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2442 * an "enter" signal. Upon an "enter", the handler will typically highlight
2443 * the drop site with gtk_drag_highlight().
2446 * drag_motion (GtkWidget *widget,
2447 * GdkDragContext *context,
2454 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2456 * if (!private_data->drag_highlight)
2458 * private_data->drag_highlight = 1;
2459 * gtk_drag_highlight (widget);
2462 * target = gtk_drag_dest_find_target (widget, context, NULL);
2463 * if (target == GDK_NONE)
2464 * gdk_drag_status (context, 0, time);
2467 * private_data->pending_status = context->suggested_action;
2468 * gtk_drag_get_data (widget, context, target, time);
2475 * drag_data_received (GtkWidget *widget,
2476 * GdkDragContext *context,
2479 * GtkSelectionData *selection_data,
2483 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2485 * if (private_data->suggested_action)
2487 * private_data->suggested_action = 0;
2489 * /* We are getting this data due to a request in drag_motion,
2490 * * rather than due to a request in drag_drop, so we are just
2491 * * supposed to call gdk_drag_status (), not actually paste in
2494 * str = gtk_selection_data_get_text (selection_data);
2495 * if (!data_is_acceptable (str))
2496 * gdk_drag_status (context, 0, time);
2498 * gdk_drag_status (context, private_data->suggested_action, time);
2502 * /* accept the drop */
2507 widget_signals[DRAG_MOTION] =
2508 g_signal_new (I_("drag-motion"),
2509 G_TYPE_FROM_CLASS (klass),
2511 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2512 _gtk_boolean_handled_accumulator, NULL,
2513 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2515 GDK_TYPE_DRAG_CONTEXT,
2521 * GtkWidget::drag-drop:
2522 * @widget: the object which received the signal
2523 * @drag_context: the drag context
2524 * @x: the x coordinate of the current cursor position
2525 * @y: the y coordinate of the current cursor position
2526 * @time: the timestamp of the motion event
2527 * @returns: whether the cursor position is in a drop zone
2529 * The ::drag-drop signal is emitted on the drop site when the user drops
2530 * the data onto the widget. The signal handler must determine whether
2531 * the cursor position is in a drop zone or not. If it is not in a drop
2532 * zone, it returns %FALSE and no further processing is necessary.
2533 * Otherwise, the handler returns %TRUE. In this case, the handler must
2534 * ensure that gtk_drag_finish() is called to let the source know that
2535 * the drop is done. The call to gtk_drag_finish() can be done either
2536 * directly or in a #GtkWidget::drag-data-received handler which gets
2537 * triggered by calling gtk_drag_get_data() to receive the data for one
2538 * or more of the supported targets.
2540 widget_signals[DRAG_DROP] =
2541 g_signal_new (I_("drag-drop"),
2542 G_TYPE_FROM_CLASS (klass),
2544 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2545 _gtk_boolean_handled_accumulator, NULL,
2546 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2548 GDK_TYPE_DRAG_CONTEXT,
2554 * GtkWidget::drag-data-get:
2555 * @widget: the object which received the signal
2556 * @drag_context: the drag context
2557 * @data: the #GtkSelectionData to be filled with the dragged data
2558 * @info: the info that has been registered with the target in the
2560 * @time: the timestamp at which the data was requested
2562 * The ::drag-data-get signal is emitted on the drag source when the drop
2563 * site requests the data which is dragged. It is the responsibility of
2564 * the signal handler to fill @data with the data in the format which
2565 * is indicated by @info. See gtk_selection_data_set() and
2566 * gtk_selection_data_set_text().
2568 widget_signals[DRAG_DATA_GET] =
2569 g_signal_new (I_("drag-data-get"),
2570 G_TYPE_FROM_CLASS (klass),
2572 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2574 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2576 GDK_TYPE_DRAG_CONTEXT,
2577 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2582 * GtkWidget::drag-data-received:
2583 * @widget: the object which received the signal
2584 * @drag_context: the drag context
2585 * @x: where the drop happened
2586 * @y: where the drop happened
2587 * @data: the received data
2588 * @info: the info that has been registered with the target in the
2590 * @time: the timestamp at which the data was received
2592 * The ::drag-data-received signal is emitted on the drop site when the
2593 * dragged data has been received. If the data was received in order to
2594 * determine whether the drop will be accepted, the handler is expected
2595 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2596 * If the data was received in response to a #GtkWidget::drag-drop signal
2597 * (and this is the last target to be received), the handler for this
2598 * signal is expected to process the received data and then call
2599 * gtk_drag_finish(), setting the @success parameter depending on whether
2600 * the data was processed successfully.
2602 * The handler may inspect and modify @drag_context->action before calling
2603 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2604 * following example:
2607 * drag_data_received (GtkWidget *widget,
2608 * GdkDragContext *drag_context,
2611 * GtkSelectionData *data,
2615 * if ((data->length >= 0) && (data->format == 8))
2617 * if (drag_context->action == GDK_ACTION_ASK)
2619 * GtkWidget *dialog;
2622 * dialog = gtk_message_dialog_new (NULL,
2623 * GTK_DIALOG_MODAL |
2624 * GTK_DIALOG_DESTROY_WITH_PARENT,
2626 * GTK_BUTTONS_YES_NO,
2627 * "Move the data ?\n");
2628 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2629 * gtk_widget_destroy (dialog);
2631 * if (response == GTK_RESPONSE_YES)
2632 * drag_context->action = GDK_ACTION_MOVE;
2634 * drag_context->action = GDK_ACTION_COPY;
2637 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2641 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2645 widget_signals[DRAG_DATA_RECEIVED] =
2646 g_signal_new (I_("drag-data-received"),
2647 G_TYPE_FROM_CLASS (klass),
2649 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2651 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2653 GDK_TYPE_DRAG_CONTEXT,
2656 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2661 * GtkWidget::visibility-notify-event:
2662 * @widget: the object which received the signal
2663 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2664 * triggered this signal.
2666 * The ::visibility-notify-event will be emitted when the @widget's window
2667 * is obscured or unobscured.
2669 * To receive this signal the #GdkWindow associated to the widget needs
2670 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2672 * Returns: %TRUE to stop other handlers from being invoked for the event.
2673 * %FALSE to propagate the event further.
2675 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2676 g_signal_new (I_("visibility-notify-event"),
2677 G_TYPE_FROM_CLASS (klass),
2679 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2680 _gtk_boolean_handled_accumulator, NULL,
2681 _gtk_marshal_BOOLEAN__BOXED,
2683 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2686 * GtkWidget::client-event:
2687 * @widget: the object which received the signal
2688 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2691 * The ::client-event will be emitted when the @widget's window
2692 * receives a message (via a ClientMessage event) from another
2695 * Returns: %TRUE to stop other handlers from being invoked for
2696 * the event. %FALSE to propagate the event further.
2698 widget_signals[CLIENT_EVENT] =
2699 g_signal_new (I_("client-event"),
2700 G_TYPE_FROM_CLASS (klass),
2702 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2703 _gtk_boolean_handled_accumulator, NULL,
2704 _gtk_marshal_BOOLEAN__BOXED,
2706 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2709 * GtkWidget::window-state-event:
2710 * @widget: the object which received the signal
2711 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2712 * triggered this signal.
2714 * The ::window-state-event will be emitted when the state of the
2715 * toplevel window associated to the @widget changes.
2717 * To receive this signal the #GdkWindow associated to the widget
2718 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2719 * this mask automatically for all new windows.
2721 * Returns: %TRUE to stop other handlers from being invoked for the
2722 * event. %FALSE to propagate the event further.
2724 widget_signals[WINDOW_STATE_EVENT] =
2725 g_signal_new (I_("window-state-event"),
2726 G_TYPE_FROM_CLASS (klass),
2728 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2729 _gtk_boolean_handled_accumulator, NULL,
2730 _gtk_marshal_BOOLEAN__BOXED,
2732 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2735 * GtkWidget::damage-event:
2736 * @widget: the object which received the signal
2737 * @event: the #GdkEventExpose event
2739 * Emitted when a redirected window belonging to @widget gets drawn into.
2740 * The region/area members of the event shows what area of the redirected
2741 * drawable was drawn into.
2743 * Returns: %TRUE to stop other handlers from being invoked for the event.
2744 * %FALSE to propagate the event further.
2748 widget_signals[DAMAGE_EVENT] =
2749 g_signal_new (I_("damage-event"),
2750 G_TYPE_FROM_CLASS (klass),
2752 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2753 _gtk_boolean_handled_accumulator, NULL,
2754 _gtk_marshal_BOOLEAN__BOXED,
2756 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2759 * GtkWidget::grab-broken-event:
2760 * @widget: the object which received the signal
2761 * @event: the #GdkEventGrabBroken event
2763 * Emitted when a pointer or keyboard grab on a window belonging
2764 * to @widget gets broken.
2766 * On X11, this happens when the grab window becomes unviewable
2767 * (i.e. it or one of its ancestors is unmapped), or if the same
2768 * application grabs the pointer or keyboard again.
2770 * Returns: %TRUE to stop other handlers from being invoked for
2771 * the event. %FALSE to propagate the event further.
2775 widget_signals[GRAB_BROKEN_EVENT] =
2776 g_signal_new (I_("grab-broken-event"),
2777 G_TYPE_FROM_CLASS (klass),
2779 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2780 _gtk_boolean_handled_accumulator, NULL,
2781 _gtk_marshal_BOOLEAN__BOXED,
2783 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2786 * GtkWidget::query-tooltip:
2787 * @widget: the object which received the signal
2788 * @x: the x coordinate of the cursor position where the request has
2789 * been emitted, relative to @widget->window
2790 * @y: the y coordinate of the cursor position where the request has
2791 * been emitted, relative to @widget->window
2792 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2793 * @tooltip: a #GtkTooltip
2795 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2796 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2797 * focus in keyboard mode.
2799 * Using the given coordinates, the signal handler should determine
2800 * whether a tooltip should be shown for @widget. If this is the case
2801 * %TRUE should be returned, %FALSE otherwise. Note that if
2802 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2803 * should not be used.
2805 * The signal handler is free to manipulate @tooltip with the therefore
2806 * destined function calls.
2808 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2812 widget_signals[QUERY_TOOLTIP] =
2813 g_signal_new (I_("query-tooltip"),
2814 G_TYPE_FROM_CLASS (klass),
2816 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2817 _gtk_boolean_handled_accumulator, NULL,
2818 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2826 * GtkWidget::popup-menu
2827 * @widget: the object which received the signal
2829 * This signal gets emitted whenever a widget should pop up a context
2830 * menu. This usually happens through the standard key binding mechanism;
2831 * by pressing a certain key while a widget is focused, the user can cause
2832 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2833 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2834 * for an example of how to use this signal.
2836 * Returns: %TRUE if a menu was activated
2838 widget_signals[POPUP_MENU] =
2839 g_signal_new (I_("popup-menu"),
2840 G_TYPE_FROM_CLASS (klass),
2841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2842 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2843 _gtk_boolean_handled_accumulator, NULL,
2844 _gtk_marshal_BOOLEAN__VOID,
2848 * GtkWidget::show-help:
2849 * @widget: the object which received the signal.
2852 widget_signals[SHOW_HELP] =
2853 g_signal_new (I_("show-help"),
2854 G_TYPE_FROM_CLASS (klass),
2855 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2856 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2857 _gtk_boolean_handled_accumulator, NULL,
2858 _gtk_marshal_BOOLEAN__ENUM,
2860 GTK_TYPE_WIDGET_HELP_TYPE);
2863 * GtkWidget::accel-closures-changed:
2864 * @widget: the object which received the signal.
2866 widget_signals[ACCEL_CLOSURES_CHANGED] =
2867 g_signal_new (I_("accel-closures-changed"),
2868 G_TYPE_FROM_CLASS (klass),
2872 _gtk_marshal_VOID__VOID,
2876 * GtkWidget::screen-changed:
2877 * @widget: the object on which the signal is emitted
2878 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2879 * widget was not associated with a screen before
2881 * The ::screen-changed signal gets emitted when the
2882 * screen of a widget has changed.
2884 widget_signals[SCREEN_CHANGED] =
2885 g_signal_new (I_("screen-changed"),
2886 G_TYPE_FROM_CLASS (klass),
2888 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2890 _gtk_marshal_VOID__OBJECT,
2895 * GtkWidget::can-activate-accel:
2896 * @widget: the object which received the signal
2897 * @signal_id: the ID of a signal installed on @widget
2899 * Determines whether an accelerator that activates the signal
2900 * identified by @signal_id can currently be activated.
2901 * This signal is present to allow applications and derived
2902 * widgets to override the default #GtkWidget handling
2903 * for determining whether an accelerator can be activated.
2905 * Returns: %TRUE if the signal can be activated.
2907 widget_signals[CAN_ACTIVATE_ACCEL] =
2908 g_signal_new (I_("can-activate-accel"),
2909 G_TYPE_FROM_CLASS (klass),
2911 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2912 _gtk_boolean_handled_accumulator, NULL,
2913 _gtk_marshal_BOOLEAN__UINT,
2914 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2916 binding_set = gtk_binding_set_by_class (klass);
2917 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2919 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2922 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2924 GTK_TYPE_WIDGET_HELP_TYPE,
2925 GTK_WIDGET_HELP_TOOLTIP);
2926 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2928 GTK_TYPE_WIDGET_HELP_TYPE,
2929 GTK_WIDGET_HELP_TOOLTIP);
2930 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2932 GTK_TYPE_WIDGET_HELP_TYPE,
2933 GTK_WIDGET_HELP_WHATS_THIS);
2934 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2936 GTK_TYPE_WIDGET_HELP_TYPE,
2937 GTK_WIDGET_HELP_WHATS_THIS);
2939 gtk_widget_class_install_style_property (klass,
2940 g_param_spec_boolean ("interior-focus",
2941 P_("Interior Focus"),
2942 P_("Whether to draw the focus indicator inside widgets"),
2944 GTK_PARAM_READABLE));
2946 gtk_widget_class_install_style_property (klass,
2947 g_param_spec_int ("focus-line-width",
2948 P_("Focus linewidth"),
2949 P_("Width, in pixels, of the focus indicator line"),
2951 GTK_PARAM_READABLE));
2953 gtk_widget_class_install_style_property (klass,
2954 g_param_spec_string ("focus-line-pattern",
2955 P_("Focus line dash pattern"),
2956 P_("Dash pattern used to draw the focus indicator"),
2958 GTK_PARAM_READABLE));
2959 gtk_widget_class_install_style_property (klass,
2960 g_param_spec_int ("focus-padding",
2961 P_("Focus padding"),
2962 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2964 GTK_PARAM_READABLE));
2965 gtk_widget_class_install_style_property (klass,
2966 g_param_spec_boxed ("cursor-color",
2968 P_("Color with which to draw insertion cursor"),
2970 GTK_PARAM_READABLE));
2971 gtk_widget_class_install_style_property (klass,
2972 g_param_spec_boxed ("secondary-cursor-color",
2973 P_("Secondary cursor color"),
2974 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2976 GTK_PARAM_READABLE));
2977 gtk_widget_class_install_style_property (klass,
2978 g_param_spec_float ("cursor-aspect-ratio",
2979 P_("Cursor line aspect ratio"),
2980 P_("Aspect ratio with which to draw insertion cursor"),
2982 GTK_PARAM_READABLE));
2984 gtk_widget_class_install_style_property (klass,
2985 g_param_spec_boolean ("window-dragging",
2986 P_("Window dragging"),
2987 P_("Whether windows can be dragged by clicking on empty areas"),
2989 GTK_PARAM_READABLE));
2992 * GtkWidget:link-color:
2994 * The "link-color" style property defines the color of unvisited links.
2998 gtk_widget_class_install_style_property (klass,
2999 g_param_spec_boxed ("link-color",
3000 P_("Unvisited Link Color"),
3001 P_("Color of unvisited links"),
3003 GTK_PARAM_READABLE));
3006 * GtkWidget:visited-link-color:
3008 * The "visited-link-color" style property defines the color of visited links.
3012 gtk_widget_class_install_style_property (klass,
3013 g_param_spec_boxed ("visited-link-color",
3014 P_("Visited Link Color"),
3015 P_("Color of visited links"),
3017 GTK_PARAM_READABLE));
3020 * GtkWidget:wide-separators:
3022 * The "wide-separators" style property defines whether separators have
3023 * configurable width and should be drawn using a box instead of a line.
3027 gtk_widget_class_install_style_property (klass,
3028 g_param_spec_boolean ("wide-separators",
3029 P_("Wide Separators"),
3030 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3032 GTK_PARAM_READABLE));
3035 * GtkWidget:separator-width:
3037 * The "separator-width" style property defines the width of separators.
3038 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3042 gtk_widget_class_install_style_property (klass,
3043 g_param_spec_int ("separator-width",
3044 P_("Separator Width"),
3045 P_("The width of separators if wide-separators is TRUE"),
3047 GTK_PARAM_READABLE));
3050 * GtkWidget:separator-height:
3052 * The "separator-height" style property defines the height of separators.
3053 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3057 gtk_widget_class_install_style_property (klass,
3058 g_param_spec_int ("separator-height",
3059 P_("Separator Height"),
3060 P_("The height of separators if \"wide-separators\" is TRUE"),
3062 GTK_PARAM_READABLE));
3065 * GtkWidget:scroll-arrow-hlength:
3067 * The "scroll-arrow-hlength" style property defines the length of
3068 * horizontal scroll arrows.
3072 gtk_widget_class_install_style_property (klass,
3073 g_param_spec_int ("scroll-arrow-hlength",
3074 P_("Horizontal Scroll Arrow Length"),
3075 P_("The length of horizontal scroll arrows"),
3077 GTK_PARAM_READABLE));
3080 * GtkWidget:scroll-arrow-vlength:
3082 * The "scroll-arrow-vlength" style property defines the length of
3083 * vertical scroll arrows.
3087 gtk_widget_class_install_style_property (klass,
3088 g_param_spec_int ("scroll-arrow-vlength",
3089 P_("Vertical Scroll Arrow Length"),
3090 P_("The length of vertical scroll arrows"),
3092 GTK_PARAM_READABLE));
3094 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3098 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3102 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3103 for (node = list; node; node = node->next)
3105 GParamSpec *pspec = node->data;
3107 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3108 g_param_spec_unref (pspec);
3114 gtk_widget_set_property (GObject *object,
3116 const GValue *value,
3119 GtkWidget *widget = GTK_WIDGET (object);
3124 gchar *tooltip_markup;
3125 const gchar *tooltip_text;
3126 GtkWindow *tooltip_window;
3129 gtk_widget_set_name (widget, g_value_get_string (value));
3132 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3134 case PROP_WIDTH_REQUEST:
3135 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3137 case PROP_HEIGHT_REQUEST:
3138 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3141 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3143 case PROP_SENSITIVE:
3144 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3146 case PROP_APP_PAINTABLE:
3147 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3149 case PROP_CAN_FOCUS:
3150 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3152 case PROP_HAS_FOCUS:
3153 if (g_value_get_boolean (value))
3154 gtk_widget_grab_focus (widget);
3157 if (g_value_get_boolean (value))
3158 gtk_widget_grab_focus (widget);
3160 case PROP_CAN_DEFAULT:
3161 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3163 case PROP_HAS_DEFAULT:
3164 if (g_value_get_boolean (value))
3165 gtk_widget_grab_default (widget);
3167 case PROP_RECEIVES_DEFAULT:
3168 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3171 gtk_widget_set_style (widget, g_value_get_object (value));
3174 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3175 gtk_widget_set_events (widget, g_value_get_flags (value));
3177 case PROP_EXTENSION_EVENTS:
3178 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3180 case PROP_NO_SHOW_ALL:
3181 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3183 case PROP_HAS_TOOLTIP:
3184 gtk_widget_real_set_has_tooltip (widget,
3185 g_value_get_boolean (value), FALSE);
3187 case PROP_TOOLTIP_MARKUP:
3188 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3189 tooltip_markup = g_value_dup_string (value);
3191 /* Treat an empty string as a NULL string,
3192 * because an empty string would be useless for a tooltip:
3194 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3196 g_free (tooltip_markup);
3197 tooltip_markup = NULL;
3200 g_object_set_qdata_full (object, quark_tooltip_markup,
3201 tooltip_markup, g_free);
3203 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3204 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3205 if (gtk_widget_get_visible (widget))
3206 gtk_widget_queue_tooltip_query (widget);
3208 case PROP_TOOLTIP_TEXT:
3209 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3211 tooltip_text = g_value_get_string (value);
3213 /* Treat an empty string as a NULL string,
3214 * because an empty string would be useless for a tooltip:
3216 if (tooltip_text && (strlen (tooltip_text) == 0))
3217 tooltip_text = NULL;
3219 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3221 g_object_set_qdata_full (object, quark_tooltip_markup,
3222 tooltip_markup, g_free);
3224 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3225 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3226 if (gtk_widget_get_visible (widget))
3227 gtk_widget_queue_tooltip_query (widget);
3229 case PROP_DOUBLE_BUFFERED:
3230 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3233 gtk_widget_set_halign (widget, g_value_get_enum (value));
3236 gtk_widget_set_valign (widget, g_value_get_enum (value));
3238 case PROP_MARGIN_LEFT:
3239 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3241 case PROP_MARGIN_RIGHT:
3242 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3244 case PROP_MARGIN_TOP:
3245 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3247 case PROP_MARGIN_BOTTOM:
3248 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3251 g_object_freeze_notify (G_OBJECT (widget));
3252 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3253 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3254 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3255 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3256 g_object_thaw_notify (G_OBJECT (widget));
3259 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3261 case PROP_HEXPAND_SET:
3262 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3265 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3267 case PROP_VEXPAND_SET:
3268 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3271 g_object_freeze_notify (G_OBJECT (widget));
3272 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3273 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3274 g_object_thaw_notify (G_OBJECT (widget));
3277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3283 gtk_widget_get_property (GObject *object,
3288 GtkWidget *widget = GTK_WIDGET (object);
3289 GtkWidgetPrivate *priv = widget->priv;
3298 g_value_set_string (value, priv->name);
3300 g_value_set_static_string (value, "");
3303 g_value_set_object (value, priv->parent);
3305 case PROP_WIDTH_REQUEST:
3308 gtk_widget_get_size_request (widget, &w, NULL);
3309 g_value_set_int (value, w);
3312 case PROP_HEIGHT_REQUEST:
3315 gtk_widget_get_size_request (widget, NULL, &h);
3316 g_value_set_int (value, h);
3320 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3322 case PROP_SENSITIVE:
3323 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3325 case PROP_APP_PAINTABLE:
3326 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3328 case PROP_CAN_FOCUS:
3329 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3331 case PROP_HAS_FOCUS:
3332 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3335 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3337 case PROP_CAN_DEFAULT:
3338 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3340 case PROP_HAS_DEFAULT:
3341 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3343 case PROP_RECEIVES_DEFAULT:
3344 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3346 case PROP_COMPOSITE_CHILD:
3347 g_value_set_boolean (value, widget->priv->composite_child);
3350 g_value_set_object (value, gtk_widget_get_style (widget));
3353 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3354 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3356 case PROP_EXTENSION_EVENTS:
3357 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3358 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3360 case PROP_NO_SHOW_ALL:
3361 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3363 case PROP_HAS_TOOLTIP:
3364 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3366 case PROP_TOOLTIP_TEXT:
3368 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3371 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3372 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3374 g_value_take_string (value, text);
3377 case PROP_TOOLTIP_MARKUP:
3378 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3381 g_value_set_object (value, gtk_widget_get_window (widget));
3383 case PROP_DOUBLE_BUFFERED:
3384 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3387 g_value_set_enum (value, gtk_widget_get_halign (widget));
3390 g_value_set_enum (value, gtk_widget_get_valign (widget));
3392 case PROP_MARGIN_LEFT:
3393 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3395 case PROP_MARGIN_RIGHT:
3396 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3398 case PROP_MARGIN_TOP:
3399 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3401 case PROP_MARGIN_BOTTOM:
3402 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3406 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3407 if (aux_info == NULL)
3409 g_value_set_int (value, 0);
3413 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3414 aux_info->margin.right),
3415 MAX (aux_info->margin.top,
3416 aux_info->margin.bottom)));
3421 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3423 case PROP_HEXPAND_SET:
3424 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3427 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3429 case PROP_VEXPAND_SET:
3430 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3433 g_value_set_boolean (value,
3434 gtk_widget_get_hexpand (widget) &&
3435 gtk_widget_get_vexpand (widget));
3438 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3444 gtk_widget_init (GtkWidget *widget)
3446 GtkWidgetPrivate *priv;
3448 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3451 priv = widget->priv;
3453 priv->child_visible = TRUE;
3454 priv->state = GTK_STATE_NORMAL;
3455 priv->saved_state = GTK_STATE_NORMAL;
3457 priv->allocation.x = -1;
3458 priv->allocation.y = -1;
3459 priv->allocation.width = 1;
3460 priv->allocation.height = 1;
3461 priv->window = NULL;
3462 priv->parent = NULL;
3464 priv->sensitive = TRUE;
3465 priv->parent_sensitive = TRUE;
3466 priv->composite_child = composite_child_stack != 0;
3467 priv->double_buffered = TRUE;
3468 priv->redraw_on_alloc = TRUE;
3469 priv->width_request_needed = TRUE;
3470 priv->height_request_needed = TRUE;
3471 priv->alloc_needed = TRUE;
3473 /* this will be set to TRUE if the widget gets a child or if the
3474 * expand flag is set on the widget, but until one of those happen
3475 * we know the expand is already properly FALSE.
3477 * We really want to default FALSE here to avoid computing expand
3478 * all over the place while initially building a widget tree.
3480 priv->need_compute_expand = FALSE;
3482 priv->style = gtk_widget_get_default_style ();
3483 g_object_ref (priv->style);
3488 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3490 GParamSpec **pspecs)
3492 GtkWidgetPrivate *priv = widget->priv;
3493 GtkWidget *container = priv->parent;
3496 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3497 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3501 * gtk_widget_freeze_child_notify:
3502 * @widget: a #GtkWidget
3504 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3505 * signals are queued until gtk_widget_thaw_child_notify() is called
3508 * This is the analogue of g_object_freeze_notify() for child properties.
3511 gtk_widget_freeze_child_notify (GtkWidget *widget)
3513 g_return_if_fail (GTK_IS_WIDGET (widget));
3515 if (!G_OBJECT (widget)->ref_count)
3518 g_object_ref (widget);
3519 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3520 g_object_unref (widget);
3524 * gtk_widget_child_notify:
3525 * @widget: a #GtkWidget
3526 * @child_property: the name of a child property installed on the
3527 * class of @widget<!-- -->'s parent
3529 * Emits a #GtkWidget::child-notify signal for the
3530 * <link linkend="child-properties">child property</link> @child_property
3533 * This is the analogue of g_object_notify() for child properties.
3536 gtk_widget_child_notify (GtkWidget *widget,
3537 const gchar *child_property)
3539 GtkWidgetPrivate *priv = widget->priv;
3542 g_return_if_fail (GTK_IS_WIDGET (widget));
3543 g_return_if_fail (child_property != NULL);
3544 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3547 g_object_ref (widget);
3548 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3550 G_OBJECT_TYPE (priv->parent),
3553 g_warning ("%s: container class `%s' has no child property named `%s'",
3555 G_OBJECT_TYPE_NAME (priv->parent),
3559 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3561 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3562 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3564 g_object_unref (widget);
3568 * gtk_widget_thaw_child_notify:
3569 * @widget: a #GtkWidget
3571 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3572 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3576 gtk_widget_thaw_child_notify (GtkWidget *widget)
3578 GObjectNotifyQueue *nqueue;
3580 g_return_if_fail (GTK_IS_WIDGET (widget));
3582 if (!G_OBJECT (widget)->ref_count)
3585 g_object_ref (widget);
3586 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3587 if (!nqueue || !nqueue->freeze_count)
3588 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3589 G_OBJECT_TYPE_NAME (widget), widget);
3591 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3592 g_object_unref (widget);
3598 * @type: type ID of the widget to create
3599 * @first_property_name: name of first property to set
3600 * @Varargs: value of first property, followed by more properties,
3603 * This is a convenience function for creating a widget and setting
3604 * its properties in one go. For example you might write:
3605 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3606 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3607 * g_object_new(), but returns a widget so you don't have to
3608 * cast the object yourself.
3610 * Return value: a new #GtkWidget of type @widget_type
3613 gtk_widget_new (GType type,
3614 const gchar *first_property_name,
3620 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3622 va_start (var_args, first_property_name);
3623 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3630 gtk_widget_queue_draw_child (GtkWidget *widget)
3632 GtkWidgetPrivate *priv = widget->priv;
3635 parent = priv->parent;
3636 if (parent && gtk_widget_is_drawable (parent))
3637 gtk_widget_queue_draw_area (parent,
3640 priv->allocation.width,
3641 priv->allocation.height);
3645 * gtk_widget_unparent:
3646 * @widget: a #GtkWidget
3648 * This function is only for use in widget implementations.
3649 * Should be called by implementations of the remove method
3650 * on #GtkContainer, to dissociate a child from the container.
3653 gtk_widget_unparent (GtkWidget *widget)
3655 GtkWidgetPrivate *priv;
3656 GObjectNotifyQueue *nqueue;
3657 GtkWidget *toplevel;
3658 GtkWidget *old_parent;
3660 g_return_if_fail (GTK_IS_WIDGET (widget));
3662 priv = widget->priv;
3664 if (priv->parent == NULL)
3667 /* keep this function in sync with gtk_menu_detach()
3670 g_object_freeze_notify (G_OBJECT (widget));
3671 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3673 toplevel = gtk_widget_get_toplevel (widget);
3674 if (gtk_widget_is_toplevel (toplevel))
3675 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3677 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3678 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3680 /* If we are unanchoring the child, we save around the toplevel
3681 * to emit hierarchy changed
3683 if (priv->parent->priv->anchored)
3684 g_object_ref (toplevel);
3688 gtk_widget_queue_draw_child (widget);
3690 /* Reset the width and height here, to force reallocation if we
3691 * get added back to a new parent. This won't work if our new
3692 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3693 * (would 0x0 be OK here?)
3695 priv->allocation.width = 1;
3696 priv->allocation.height = 1;
3698 if (gtk_widget_get_realized (widget))
3700 if (priv->in_reparent)
3701 gtk_widget_unmap (widget);
3703 gtk_widget_unrealize (widget);
3706 /* Removing a widget from a container restores the child visible
3707 * flag to the default state, so it doesn't affect the child
3708 * in the next parent.
3710 priv->child_visible = TRUE;
3712 old_parent = priv->parent;
3713 priv->parent = NULL;
3714 gtk_widget_set_parent_window (widget, NULL);
3716 /* parent may no longer expand if the removed
3717 * child was expand=TRUE and could therefore
3720 if (gtk_widget_get_visible (widget) &&
3721 (priv->need_compute_expand ||
3722 priv->computed_hexpand ||
3723 priv->computed_vexpand))
3725 gtk_widget_queue_compute_expand (old_parent);
3728 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3731 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3732 g_object_unref (toplevel);
3735 g_object_notify (G_OBJECT (widget), "parent");
3736 g_object_thaw_notify (G_OBJECT (widget));
3738 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3739 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3740 g_object_unref (widget);
3744 * gtk_widget_destroy:
3745 * @widget: a #GtkWidget
3747 * Destroys a widget.
3750 * destroyed, it will break any references it holds to other objects.
3751 * If the widget is inside a container, the widget will be removed
3752 * from the container. If the widget is a toplevel (derived from
3753 * #GtkWindow), it will be removed from the list of toplevels, and the
3754 * reference GTK+ holds to it will be removed. Removing a
3755 * widget from its container or the list of toplevels results in the
3756 * widget being finalized, unless you've added additional references
3757 * to the widget with g_object_ref().
3759 * In most cases, only toplevel widgets (windows) require explicit
3760 * destruction, because when you destroy a toplevel its children will
3761 * be destroyed as well.
3764 gtk_widget_destroy (GtkWidget *widget)
3766 g_return_if_fail (GTK_IS_WIDGET (widget));
3768 if (!widget->priv->in_destruction)
3769 g_object_run_dispose (G_OBJECT (widget));
3773 * gtk_widget_destroyed:
3774 * @widget: a #GtkWidget
3775 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3777 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3778 * %NULL. It's intended to be used as a callback connected to the
3779 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3780 * as a signal handler, and pass the address of your widget variable
3781 * as user data. Then when the widget is destroyed, the variable will
3782 * be set to %NULL. Useful for example to avoid multiple copies
3783 * of the same dialog.
3786 gtk_widget_destroyed (GtkWidget *widget,
3787 GtkWidget **widget_pointer)
3789 /* Don't make any assumptions about the
3791 * Even check widget_pointer.
3794 *widget_pointer = NULL;
3799 * @widget: a #GtkWidget
3801 * Flags a widget to be displayed. Any widget that isn't shown will
3802 * not appear on the screen. If you want to show all the widgets in a
3803 * container, it's easier to call gtk_widget_show_all() on the
3804 * container, instead of individually showing the widgets.
3806 * Remember that you have to show the containers containing a widget,
3807 * in addition to the widget itself, before it will appear onscreen.
3809 * When a toplevel container is shown, it is immediately realized and
3810 * mapped; other shown widgets are realized and mapped when their
3811 * toplevel container is realized and mapped.
3814 gtk_widget_show (GtkWidget *widget)
3816 g_return_if_fail (GTK_IS_WIDGET (widget));
3818 if (!gtk_widget_get_visible (widget))
3820 g_object_ref (widget);
3821 if (!gtk_widget_is_toplevel (widget))
3822 gtk_widget_queue_resize (widget);
3824 /* see comment in set_parent() for why this should and can be
3827 if (widget->priv->need_compute_expand ||
3828 widget->priv->computed_hexpand ||
3829 widget->priv->computed_vexpand)
3831 if (widget->priv->parent != NULL)
3832 gtk_widget_queue_compute_expand (widget->priv->parent);
3835 g_signal_emit (widget, widget_signals[SHOW], 0);
3836 g_object_notify (G_OBJECT (widget), "visible");
3837 g_object_unref (widget);
3842 gtk_widget_real_show (GtkWidget *widget)
3844 GtkWidgetPrivate *priv = widget->priv;
3846 if (!gtk_widget_get_visible (widget))
3848 priv->visible = TRUE;
3851 gtk_widget_get_mapped (priv->parent) &&
3852 gtk_widget_get_child_visible (widget) &&
3853 !gtk_widget_get_mapped (widget))
3854 gtk_widget_map (widget);
3859 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3862 g_signal_handlers_disconnect_by_func (widget,
3863 gtk_widget_show_map_callback,
3868 * gtk_widget_show_now:
3869 * @widget: a #GtkWidget
3871 * Shows a widget. If the widget is an unmapped toplevel widget
3872 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3873 * loop and wait for the window to actually be mapped. Be careful;
3874 * because the main loop is running, anything can happen during
3878 gtk_widget_show_now (GtkWidget *widget)
3882 g_return_if_fail (GTK_IS_WIDGET (widget));
3884 /* make sure we will get event */
3885 if (!gtk_widget_get_mapped (widget) &&
3886 gtk_widget_is_toplevel (widget))
3888 gtk_widget_show (widget);
3890 g_signal_connect (widget, "map-event",
3891 G_CALLBACK (gtk_widget_show_map_callback),
3895 gtk_main_iteration ();
3898 gtk_widget_show (widget);
3903 * @widget: a #GtkWidget
3905 * Reverses the effects of gtk_widget_show(), causing the widget to be
3906 * hidden (invisible to the user).
3909 gtk_widget_hide (GtkWidget *widget)
3911 g_return_if_fail (GTK_IS_WIDGET (widget));
3913 if (gtk_widget_get_visible (widget))
3915 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3917 g_object_ref (widget);
3918 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3919 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3921 /* a parent may now be expand=FALSE since we're hidden. */
3922 if (widget->priv->need_compute_expand ||
3923 widget->priv->computed_hexpand ||
3924 widget->priv->computed_vexpand)
3926 gtk_widget_queue_compute_expand (widget);
3929 g_signal_emit (widget, widget_signals[HIDE], 0);
3930 if (!gtk_widget_is_toplevel (widget))
3931 gtk_widget_queue_resize (widget);
3932 g_object_notify (G_OBJECT (widget), "visible");
3933 g_object_unref (widget);
3938 gtk_widget_real_hide (GtkWidget *widget)
3940 if (gtk_widget_get_visible (widget))
3942 widget->priv->visible = FALSE;
3944 if (gtk_widget_get_mapped (widget))
3945 gtk_widget_unmap (widget);
3950 * gtk_widget_hide_on_delete:
3951 * @widget: a #GtkWidget
3953 * Utility function; intended to be connected to the #GtkWidget::delete-event
3954 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3955 * argument, then returns %TRUE. If connected to ::delete-event, the
3956 * result is that clicking the close button for a window (on the
3957 * window frame, top right corner usually) will hide but not destroy
3958 * the window. By default, GTK+ destroys windows when ::delete-event
3961 * Return value: %TRUE
3964 gtk_widget_hide_on_delete (GtkWidget *widget)
3966 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3968 gtk_widget_hide (widget);
3974 * gtk_widget_show_all:
3975 * @widget: a #GtkWidget
3977 * Recursively shows a widget, and any child widgets (if the widget is
3981 gtk_widget_show_all (GtkWidget *widget)
3983 GtkWidgetClass *class;
3985 g_return_if_fail (GTK_IS_WIDGET (widget));
3987 if (gtk_widget_get_no_show_all (widget))
3990 class = GTK_WIDGET_GET_CLASS (widget);
3992 if (class->show_all)
3993 class->show_all (widget);
3998 * @widget: a #GtkWidget
4000 * This function is only for use in widget implementations. Causes
4001 * a widget to be mapped if it isn't already.
4004 gtk_widget_map (GtkWidget *widget)
4006 GtkWidgetPrivate *priv;
4008 g_return_if_fail (GTK_IS_WIDGET (widget));
4009 g_return_if_fail (gtk_widget_get_visible (widget));
4010 g_return_if_fail (gtk_widget_get_child_visible (widget));
4012 priv = widget->priv;
4014 if (!gtk_widget_get_mapped (widget))
4016 if (!gtk_widget_get_realized (widget))
4017 gtk_widget_realize (widget);
4019 g_signal_emit (widget, widget_signals[MAP], 0);
4021 if (!gtk_widget_get_has_window (widget))
4022 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4028 * @widget: a #GtkWidget
4030 * This function is only for use in widget implementations. Causes
4031 * a widget to be unmapped if it's currently mapped.
4034 gtk_widget_unmap (GtkWidget *widget)
4036 GtkWidgetPrivate *priv;
4038 g_return_if_fail (GTK_IS_WIDGET (widget));
4040 priv = widget->priv;
4042 if (gtk_widget_get_mapped (widget))
4044 if (!gtk_widget_get_has_window (widget))
4045 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4046 _gtk_tooltip_hide (widget);
4047 g_signal_emit (widget, widget_signals[UNMAP], 0);
4052 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4053 GdkExtensionMode mode,
4056 GtkWidgetPrivate *priv = widget->priv;
4057 GList *free_list = NULL;
4060 if (window_list == NULL)
4062 if (gtk_widget_get_has_window (widget))
4063 window_list = g_list_prepend (NULL, priv->window);
4065 window_list = gdk_window_get_children (priv->window);
4067 free_list = window_list;
4070 for (l = window_list; l != NULL; l = l->next)
4072 GdkWindow *window = l->data;
4075 gdk_window_get_user_data (window, &user_data);
4076 if (user_data == widget)
4080 gdk_input_set_extension_events (window,
4081 gdk_window_get_events (window),
4084 children = gdk_window_get_children (window);
4087 gtk_widget_set_extension_events_internal (widget, mode, children);
4088 g_list_free (children);
4094 g_list_free (free_list);
4098 _gtk_widget_enable_device_events (GtkWidget *widget)
4100 GHashTable *device_events;
4101 GHashTableIter iter;
4102 gpointer key, value;
4104 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4109 g_hash_table_iter_init (&iter, device_events);
4111 while (g_hash_table_iter_next (&iter, &key, &value))
4114 GdkEventMask event_mask;
4117 event_mask = GPOINTER_TO_UINT (value);
4118 gtk_widget_add_events_internal (widget, device, event_mask);
4123 * gtk_widget_realize:
4124 * @widget: a #GtkWidget
4126 * Creates the GDK (windowing system) resources associated with a
4127 * widget. For example, @widget->window will be created when a widget
4128 * is realized. Normally realization happens implicitly; if you show
4129 * a widget and all its parent containers, then the widget will be
4130 * realized and mapped automatically.
4132 * Realizing a widget requires all
4133 * the widget's parent widgets to be realized; calling
4134 * gtk_widget_realize() realizes the widget's parents in addition to
4135 * @widget itself. If a widget is not yet inside a toplevel window
4136 * when you realize it, bad things will happen.
4138 * This function is primarily used in widget implementations, and
4139 * isn't very useful otherwise. Many times when you think you might
4140 * need it, a better approach is to connect to a signal that will be
4141 * called after the widget is realized automatically, such as
4142 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4143 * #GtkWidget::realize signal.
4146 gtk_widget_realize (GtkWidget *widget)
4148 GtkWidgetPrivate *priv;
4149 GdkExtensionMode mode;
4150 cairo_region_t *region;
4151 GtkStyleContext *context;
4153 g_return_if_fail (GTK_IS_WIDGET (widget));
4154 g_return_if_fail (widget->priv->anchored ||
4155 GTK_IS_INVISIBLE (widget));
4157 priv = widget->priv;
4159 if (!gtk_widget_get_realized (widget))
4162 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4163 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4166 if (priv->parent == NULL &&
4167 !gtk_widget_is_toplevel (widget))
4168 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4169 "inside a toplevel window is not going to work very well. "
4170 "Widgets must be inside a toplevel container before realizing them.");
4172 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4173 gtk_widget_realize (priv->parent);
4175 gtk_widget_ensure_style (widget);
4177 g_signal_emit (widget, widget_signals[REALIZE], 0);
4179 gtk_widget_real_set_has_tooltip (widget,
4180 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4183 if (priv->has_shape_mask)
4185 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4186 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4189 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4191 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4193 mode = gtk_widget_get_extension_events (widget);
4194 if (mode != GDK_EXTENSION_EVENTS_NONE)
4195 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4197 if (priv->multidevice)
4198 gdk_window_set_support_multidevice (priv->window, TRUE);
4200 _gtk_widget_enable_device_events (widget);
4205 * gtk_widget_unrealize:
4206 * @widget: a #GtkWidget
4208 * This function is only useful in widget implementations.
4209 * Causes a widget to be unrealized (frees all GDK resources
4210 * associated with the widget, such as @widget->window).
4213 gtk_widget_unrealize (GtkWidget *widget)
4215 g_return_if_fail (GTK_IS_WIDGET (widget));
4217 if (widget->priv->has_shape_mask)
4218 gtk_widget_shape_combine_region (widget, NULL);
4220 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4221 gtk_widget_input_shape_combine_region (widget, NULL);
4223 if (gtk_widget_get_realized (widget))
4225 g_object_ref (widget);
4226 _gtk_tooltip_hide (widget);
4227 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4228 gtk_widget_set_realized (widget, FALSE);
4229 gtk_widget_set_mapped (widget, FALSE);
4230 g_object_unref (widget);
4234 /*****************************************
4236 *****************************************/
4239 * gtk_widget_queue_draw_region:
4240 * @widget: a #GtkWidget
4241 * @region: region to draw
4243 * Invalidates the rectangular area of @widget defined by @region by
4244 * calling gdk_window_invalidate_region() on the widget's window and
4245 * all its child windows. Once the main loop becomes idle (after the
4246 * current batch of events has been processed, roughly), the window
4247 * will receive expose events for the union of all regions that have
4250 * Normally you would only use this function in widget
4251 * implementations. You might also use it to schedule a redraw of a
4252 * #GtkDrawingArea or some portion thereof.
4255 gtk_widget_queue_draw_region (GtkWidget *widget,
4256 cairo_region_t *region)
4258 GtkWidgetPrivate *priv;
4261 g_return_if_fail (GTK_IS_WIDGET (widget));
4263 priv = widget->priv;
4265 if (!gtk_widget_get_realized (widget))
4268 /* Just return if the widget or one of its ancestors isn't mapped */
4269 for (w = widget; w != NULL; w = w->priv->parent)
4270 if (!gtk_widget_get_mapped (w))
4273 gdk_window_invalidate_region (priv->window, region, TRUE);
4277 * gtk_widget_queue_draw_area:
4278 * @widget: a #GtkWidget
4279 * @x: x coordinate of upper-left corner of rectangle to redraw
4280 * @y: y coordinate of upper-left corner of rectangle to redraw
4281 * @width: width of region to draw
4282 * @height: height of region to draw
4284 * Convenience function that calls gtk_widget_queue_draw_region() on
4285 * the region created from the given coordinates.
4288 gtk_widget_queue_draw_area (GtkWidget *widget,
4295 cairo_region_t *region;
4297 g_return_if_fail (GTK_IS_WIDGET (widget));
4302 rect.height = height;
4304 region = cairo_region_create_rectangle (&rect);
4305 gtk_widget_queue_draw_region (widget, region);
4306 cairo_region_destroy (region);
4310 * gtk_widget_queue_draw:
4311 * @widget: a #GtkWidget
4313 * Equivalent to calling gtk_widget_queue_draw_area() for the
4314 * entire area of a widget.
4317 gtk_widget_queue_draw (GtkWidget *widget)
4321 g_return_if_fail (GTK_IS_WIDGET (widget));
4323 gtk_widget_get_allocation (widget, &rect);
4325 if (!gtk_widget_get_has_window (widget))
4326 gtk_widget_queue_draw_area (widget,
4327 rect.x, rect.y, rect.width, rect.height);
4329 gtk_widget_queue_draw_area (widget,
4330 0, 0, rect.width, rect.height);
4334 * gtk_widget_queue_resize:
4335 * @widget: a #GtkWidget
4337 * This function is only for use in widget implementations.
4338 * Flags a widget to have its size renegotiated; should
4339 * be called when a widget for some reason has a new size request.
4340 * For example, when you change the text in a #GtkLabel, #GtkLabel
4341 * queues a resize to ensure there's enough space for the new text.
4343 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4344 * from inside it's implementation of the GtkWidgetClass::size_allocate
4345 * virtual method. Calls to gtk_widget_queue_resize() from inside
4346 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4349 gtk_widget_queue_resize (GtkWidget *widget)
4351 g_return_if_fail (GTK_IS_WIDGET (widget));
4353 if (gtk_widget_get_realized (widget))
4354 gtk_widget_queue_shallow_draw (widget);
4356 _gtk_size_group_queue_resize (widget, 0);
4360 * gtk_widget_queue_resize_no_redraw:
4361 * @widget: a #GtkWidget
4363 * This function works like gtk_widget_queue_resize(),
4364 * except that the widget is not invalidated.
4369 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4371 g_return_if_fail (GTK_IS_WIDGET (widget));
4373 _gtk_size_group_queue_resize (widget, 0);
4377 * gtk_widget_size_request:
4378 * @widget: a #GtkWidget
4379 * @requisition: (out): a #GtkRequisition to be filled in
4381 * This function is typically used when implementing a #GtkContainer
4382 * subclass. Obtains the preferred size of a widget. The container
4383 * uses this information to arrange its child widgets and decide what
4384 * size allocations to give them with gtk_widget_size_allocate().
4386 * You can also call this function from an application, with some
4387 * caveats. Most notably, getting a size request requires the widget
4388 * to be associated with a screen, because font information may be
4389 * needed. Multihead-aware applications should keep this in mind.
4391 * Also remember that the size request is not necessarily the size
4392 * a widget will actually be allocated.
4394 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4397 gtk_widget_size_request (GtkWidget *widget,
4398 GtkRequisition *requisition)
4400 g_return_if_fail (GTK_IS_WIDGET (widget));
4402 gtk_widget_get_preferred_size (widget, requisition, NULL);
4406 * gtk_widget_get_child_requisition:
4407 * @widget: a #GtkWidget
4408 * @requisition: (out): a #GtkRequisition to be filled in
4410 * This function is only for use in widget implementations. Obtains
4411 * @widget->requisition, unless someone has forced a particular
4412 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4413 * in which case it returns that geometry instead of the widget's
4416 * This function differs from gtk_widget_size_request() in that
4417 * it retrieves the last size request value from @widget->requisition,
4418 * while gtk_widget_size_request() actually calls the "size_request" method
4419 * on @widget to compute the size request and fill in @widget->requisition,
4420 * and only then returns @widget->requisition.
4422 * Because this function does not call the "size_request" method, it
4423 * can only be used when you know that @widget->requisition is
4424 * up-to-date, that is, gtk_widget_size_request() has been called
4425 * since the last time a resize was queued. In general, only container
4426 * implementations have this information; applications should use
4427 * gtk_widget_size_request().
4430 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4433 gtk_widget_get_child_requisition (GtkWidget *widget,
4434 GtkRequisition *requisition)
4436 gtk_widget_get_preferred_size (widget, requisition, NULL);
4440 invalidate_predicate (GdkWindow *window,
4445 gdk_window_get_user_data (window, &user_data);
4447 return (user_data == data);
4450 /* Invalidate @region in widget->window and all children
4451 * of widget->window owned by widget. @region is in the
4452 * same coordinates as widget->allocation and will be
4453 * modified by this call.
4456 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4457 cairo_region_t *region)
4459 GtkWidgetPrivate *priv = widget->priv;
4461 if (!gtk_widget_get_realized (widget))
4464 if (gtk_widget_get_has_window (widget) && priv->parent)
4468 gdk_window_get_position (priv->window, &x, &y);
4469 cairo_region_translate (region, -x, -y);
4472 gdk_window_invalidate_maybe_recurse (priv->window, region,
4473 invalidate_predicate, widget);
4477 * gtk_widget_queue_shallow_draw:
4478 * @widget: a #GtkWidget
4480 * Like gtk_widget_queue_draw(), but only windows owned
4481 * by @widget are invalidated.
4484 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4487 cairo_region_t *region;
4489 if (!gtk_widget_get_realized (widget))
4492 gtk_widget_get_allocation (widget, &rect);
4494 region = cairo_region_create_rectangle (&rect);
4495 gtk_widget_invalidate_widget_windows (widget, region);
4496 cairo_region_destroy (region);
4500 * gtk_widget_size_allocate:
4501 * @widget: a #GtkWidget
4502 * @allocation: (inout): position and size to be allocated to @widget
4504 * This function is only used by #GtkContainer subclasses, to assign a size
4505 * and position to their child widgets.
4507 * In this function, the allocation may be adjusted. It will be forced
4508 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4509 * method on the child will be used to adjust the allocation. Standard
4510 * adjustments include removing the widget's margins, and applying the
4511 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4514 gtk_widget_size_allocate (GtkWidget *widget,
4515 GtkAllocation *allocation)
4517 GtkWidgetPrivate *priv;
4518 GdkRectangle real_allocation;
4519 GdkRectangle old_allocation;
4520 GdkRectangle adjusted_allocation;
4521 gboolean alloc_needed;
4522 gboolean size_changed;
4523 gboolean position_changed;
4524 gint natural_width, natural_height;
4525 gint min_width, min_height;
4527 priv = widget->priv;
4529 g_return_if_fail (GTK_IS_WIDGET (widget));
4531 #ifdef G_ENABLE_DEBUG
4532 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4543 parent = gtk_widget_get_parent (parent);
4546 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4547 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4548 2 * depth, " ", name,
4549 allocation->width, allocation->height);
4551 #endif /* G_ENABLE_DEBUG */
4553 alloc_needed = priv->alloc_needed;
4554 if (!priv->width_request_needed && !priv->height_request_needed)
4555 /* Preserve request/allocate ordering */
4556 priv->alloc_needed = FALSE;
4558 old_allocation = priv->allocation;
4559 real_allocation = *allocation;
4561 adjusted_allocation = real_allocation;
4562 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4564 /* Go ahead and request the height for allocated width, note that the internals
4565 * of get_height_for_width will internally limit the for_size to natural size
4566 * when aligning implicitly.
4568 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4569 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4573 /* Go ahead and request the width for allocated height, note that the internals
4574 * of get_width_for_height will internally limit the for_size to natural size
4575 * when aligning implicitly.
4577 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4578 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4581 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4582 * allocated sizes and possibly limit them to the natural sizes */
4583 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4584 GTK_ORIENTATION_HORIZONTAL,
4586 &adjusted_allocation.x,
4587 &adjusted_allocation.width);
4588 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4589 GTK_ORIENTATION_VERTICAL,
4591 &adjusted_allocation.y,
4592 &adjusted_allocation.height);
4594 if (adjusted_allocation.x < real_allocation.x ||
4595 adjusted_allocation.y < real_allocation.y ||
4596 (adjusted_allocation.x + adjusted_allocation.width) >
4597 (real_allocation.x + real_allocation.width) ||
4598 (adjusted_allocation.y + adjusted_allocation.height >
4599 real_allocation.y + real_allocation.height))
4601 g_warning ("%s %p attempted to adjust its size allocation from %d,%d %dx%d to %d,%d %dx%d. adjust_size_allocation must keep allocation inside original bounds",
4602 G_OBJECT_TYPE_NAME (widget), widget,
4603 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4604 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4605 adjusted_allocation = real_allocation; /* veto it */
4609 real_allocation = adjusted_allocation;
4612 if (real_allocation.width < 0 || real_allocation.height < 0)
4614 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4615 real_allocation.width,
4616 real_allocation.height);
4619 real_allocation.width = MAX (real_allocation.width, 1);
4620 real_allocation.height = MAX (real_allocation.height, 1);
4622 size_changed = (old_allocation.width != real_allocation.width ||
4623 old_allocation.height != real_allocation.height);
4624 position_changed = (old_allocation.x != real_allocation.x ||
4625 old_allocation.y != real_allocation.y);
4627 if (!alloc_needed && !size_changed && !position_changed)
4630 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4632 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4633 priv->width_request_needed = FALSE;
4634 priv->height_request_needed = FALSE;
4635 priv->alloc_needed = FALSE;
4637 if (gtk_widget_get_mapped (widget))
4639 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4641 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4643 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4644 cairo_region_union_rectangle (invalidate, &old_allocation);
4646 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4647 cairo_region_destroy (invalidate);
4652 if (priv->redraw_on_alloc)
4654 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4656 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4657 cairo_region_union_rectangle (invalidate, &old_allocation);
4659 gtk_widget_invalidate_widget_windows (widget, invalidate);
4660 cairo_region_destroy (invalidate);
4665 if ((size_changed || position_changed) && priv->parent &&
4666 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4668 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4669 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4670 cairo_region_destroy (invalidate);
4675 * gtk_widget_common_ancestor:
4676 * @widget_a: a #GtkWidget
4677 * @widget_b: a #GtkWidget
4679 * Find the common ancestor of @widget_a and @widget_b that
4680 * is closest to the two widgets.
4682 * Return value: the closest common ancestor of @widget_a and
4683 * @widget_b or %NULL if @widget_a and @widget_b do not
4684 * share a common ancestor.
4687 gtk_widget_common_ancestor (GtkWidget *widget_a,
4688 GtkWidget *widget_b)
4690 GtkWidget *parent_a;
4691 GtkWidget *parent_b;
4695 parent_a = widget_a;
4696 while (parent_a->priv->parent)
4698 parent_a = parent_a->priv->parent;
4702 parent_b = widget_b;
4703 while (parent_b->priv->parent)
4705 parent_b = parent_b->priv->parent;
4709 if (parent_a != parent_b)
4712 while (depth_a > depth_b)
4714 widget_a = widget_a->priv->parent;
4718 while (depth_b > depth_a)
4720 widget_b = widget_b->priv->parent;
4724 while (widget_a != widget_b)
4726 widget_a = widget_a->priv->parent;
4727 widget_b = widget_b->priv->parent;
4734 * gtk_widget_translate_coordinates:
4735 * @src_widget: a #GtkWidget
4736 * @dest_widget: a #GtkWidget
4737 * @src_x: X position relative to @src_widget
4738 * @src_y: Y position relative to @src_widget
4739 * @dest_x: (out): location to store X position relative to @dest_widget
4740 * @dest_y: (out): location to store Y position relative to @dest_widget
4742 * Translate coordinates relative to @src_widget's allocation to coordinates
4743 * relative to @dest_widget's allocations. In order to perform this
4744 * operation, both widgets must be realized, and must share a common
4747 * Return value: %FALSE if either widget was not realized, or there
4748 * was no common ancestor. In this case, nothing is stored in
4749 * *@dest_x and *@dest_y. Otherwise %TRUE.
4752 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4753 GtkWidget *dest_widget,
4759 GtkWidgetPrivate *src_priv = src_widget->priv;
4760 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4761 GtkWidget *ancestor;
4763 GList *dest_list = NULL;
4765 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4766 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4768 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4769 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4772 /* Translate from allocation relative to window relative */
4773 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4776 gdk_window_get_position (src_priv->window, &wx, &wy);
4778 src_x -= wx - src_priv->allocation.x;
4779 src_y -= wy - src_priv->allocation.y;
4783 src_x += src_priv->allocation.x;
4784 src_y += src_priv->allocation.y;
4787 /* Translate to the common ancestor */
4788 window = src_priv->window;
4789 while (window != ancestor->priv->window)
4793 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4798 window = gdk_window_get_effective_parent (window);
4800 if (!window) /* Handle GtkHandleBox */
4805 window = dest_priv->window;
4806 while (window != ancestor->priv->window)
4808 dest_list = g_list_prepend (dest_list, window);
4810 window = gdk_window_get_effective_parent (window);
4812 if (!window) /* Handle GtkHandleBox */
4814 g_list_free (dest_list);
4823 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4828 dest_list = g_list_remove (dest_list, dest_list->data);
4831 /* Translate from window relative to allocation relative */
4832 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4835 gdk_window_get_position (dest_priv->window, &wx, &wy);
4837 src_x += wx - dest_priv->allocation.x;
4838 src_y += wy - dest_priv->allocation.y;
4842 src_x -= dest_priv->allocation.x;
4843 src_y -= dest_priv->allocation.y;
4855 gtk_widget_real_size_allocate (GtkWidget *widget,
4856 GtkAllocation *allocation)
4858 GtkWidgetPrivate *priv = widget->priv;
4860 priv->allocation = *allocation;
4862 if (gtk_widget_get_realized (widget) &&
4863 gtk_widget_get_has_window (widget))
4865 gdk_window_move_resize (priv->window,
4866 allocation->x, allocation->y,
4867 allocation->width, allocation->height);
4872 adjust_for_align(GtkAlign align,
4874 gint *allocated_pos,
4875 gint *allocated_size)
4879 case GTK_ALIGN_FILL:
4880 /* change nothing */
4882 case GTK_ALIGN_START:
4883 /* keep *allocated_pos where it is */
4884 *allocated_size = MIN (*allocated_size, *natural_size);
4887 if (*allocated_size > *natural_size)
4889 *allocated_pos += (*allocated_size - *natural_size);
4890 *allocated_size = *natural_size;
4893 case GTK_ALIGN_CENTER:
4894 if (*allocated_size > *natural_size)
4896 *allocated_pos += (*allocated_size - *natural_size) / 2;
4897 *allocated_size = MIN (*allocated_size, *natural_size);
4904 adjust_for_margin(gint start_margin,
4907 gint *allocated_pos,
4908 gint *allocated_size)
4910 *natural_size -= (start_margin + end_margin);
4911 *allocated_pos += start_margin;
4912 *allocated_size -= (start_margin + end_margin);
4916 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4917 GtkOrientation orientation,
4919 gint *allocated_pos,
4920 gint *allocated_size)
4922 const GtkWidgetAuxInfo *aux_info;
4924 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4926 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4928 adjust_for_margin (aux_info->margin.left,
4929 aux_info->margin.right,
4930 natural_size, allocated_pos, allocated_size);
4931 adjust_for_align (aux_info->halign,
4932 natural_size, allocated_pos, allocated_size);
4936 adjust_for_margin (aux_info->margin.top,
4937 aux_info->margin.bottom,
4938 natural_size, allocated_pos, allocated_size);
4939 adjust_for_align (aux_info->valign,
4940 natural_size, allocated_pos, allocated_size);
4945 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4948 GtkWidgetPrivate *priv = widget->priv;
4950 /* widgets must be onscreen for accels to take effect */
4951 return gtk_widget_is_sensitive (widget) &&
4952 gtk_widget_is_drawable (widget) &&
4953 gdk_window_is_viewable (priv->window);
4957 * gtk_widget_can_activate_accel:
4958 * @widget: a #GtkWidget
4959 * @signal_id: the ID of a signal installed on @widget
4961 * Determines whether an accelerator that activates the signal
4962 * identified by @signal_id can currently be activated.
4963 * This is done by emitting the #GtkWidget::can-activate-accel
4964 * signal on @widget; if the signal isn't overridden by a
4965 * handler or in a derived widget, then the default check is
4966 * that the widget must be sensitive, and the widget and all
4967 * its ancestors mapped.
4969 * Return value: %TRUE if the accelerator can be activated.
4974 gtk_widget_can_activate_accel (GtkWidget *widget,
4977 gboolean can_activate = FALSE;
4978 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4979 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4980 return can_activate;
4989 closure_accel_activate (GClosure *closure,
4990 GValue *return_value,
4991 guint n_param_values,
4992 const GValue *param_values,
4993 gpointer invocation_hint,
4994 gpointer marshal_data)
4996 AccelClosure *aclosure = (AccelClosure*) closure;
4997 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5000 g_signal_emit (closure->data, aclosure->signal_id, 0);
5002 /* whether accelerator was handled */
5003 g_value_set_boolean (return_value, can_activate);
5007 closures_destroy (gpointer data)
5009 GSList *slist, *closures = data;
5011 for (slist = closures; slist; slist = slist->next)
5013 g_closure_invalidate (slist->data);
5014 g_closure_unref (slist->data);
5016 g_slist_free (closures);
5020 widget_new_accel_closure (GtkWidget *widget,
5023 AccelClosure *aclosure;
5024 GClosure *closure = NULL;
5025 GSList *slist, *closures;
5027 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5028 for (slist = closures; slist; slist = slist->next)
5029 if (!gtk_accel_group_from_accel_closure (slist->data))
5031 /* reuse this closure */
5032 closure = slist->data;
5037 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5038 closures = g_slist_prepend (closures, g_closure_ref (closure));
5039 g_closure_sink (closure);
5040 g_closure_set_marshal (closure, closure_accel_activate);
5042 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5044 aclosure = (AccelClosure*) closure;
5045 g_assert (closure->data == widget);
5046 g_assert (closure->marshal == closure_accel_activate);
5047 aclosure->signal_id = signal_id;
5053 * gtk_widget_add_accelerator
5054 * @widget: widget to install an accelerator on
5055 * @accel_signal: widget signal to emit on accelerator activation
5056 * @accel_group: accel group for this widget, added to its toplevel
5057 * @accel_key: GDK keyval of the accelerator
5058 * @accel_mods: modifier key combination of the accelerator
5059 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5061 * Installs an accelerator for this @widget in @accel_group that causes
5062 * @accel_signal to be emitted if the accelerator is activated.
5063 * The @accel_group needs to be added to the widget's toplevel via
5064 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5065 * Accelerators added through this function are not user changeable during
5066 * runtime. If you want to support accelerators that can be changed by the
5067 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5068 * gtk_menu_item_set_accel_path() instead.
5071 gtk_widget_add_accelerator (GtkWidget *widget,
5072 const gchar *accel_signal,
5073 GtkAccelGroup *accel_group,
5075 GdkModifierType accel_mods,
5076 GtkAccelFlags accel_flags)
5081 g_return_if_fail (GTK_IS_WIDGET (widget));
5082 g_return_if_fail (accel_signal != NULL);
5083 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5085 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5086 if (!query.signal_id ||
5087 !(query.signal_flags & G_SIGNAL_ACTION) ||
5088 query.return_type != G_TYPE_NONE ||
5091 /* hmm, should be elaborate enough */
5092 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5093 G_OBJECT_TYPE_NAME (widget), accel_signal);
5097 closure = widget_new_accel_closure (widget, query.signal_id);
5099 g_object_ref (widget);
5101 /* install the accelerator. since we don't map this onto an accel_path,
5102 * the accelerator will automatically be locked.
5104 gtk_accel_group_connect (accel_group,
5107 accel_flags | GTK_ACCEL_LOCKED,
5110 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5112 g_object_unref (widget);
5116 * gtk_widget_remove_accelerator:
5117 * @widget: widget to install an accelerator on
5118 * @accel_group: accel group for this widget
5119 * @accel_key: GDK keyval of the accelerator
5120 * @accel_mods: modifier key combination of the accelerator
5121 * @returns: whether an accelerator was installed and could be removed
5123 * Removes an accelerator from @widget, previously installed with
5124 * gtk_widget_add_accelerator().
5127 gtk_widget_remove_accelerator (GtkWidget *widget,
5128 GtkAccelGroup *accel_group,
5130 GdkModifierType accel_mods)
5132 GtkAccelGroupEntry *ag_entry;
5133 GList *slist, *clist;
5136 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5137 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5139 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5140 clist = gtk_widget_list_accel_closures (widget);
5141 for (slist = clist; slist; slist = slist->next)
5145 for (i = 0; i < n; i++)
5146 if (slist->data == (gpointer) ag_entry[i].closure)
5148 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5150 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5152 g_list_free (clist);
5157 g_list_free (clist);
5159 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5160 accel_key, accel_mods, accel_group,
5161 G_OBJECT_TYPE_NAME (widget), widget);
5167 * gtk_widget_list_accel_closures:
5168 * @widget: widget to list accelerator closures for
5170 * Lists the closures used by @widget for accelerator group connections
5171 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5172 * The closures can be used to monitor accelerator changes on @widget,
5173 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5174 * #GtkAccelGroup of a closure which can be found out with
5175 * gtk_accel_group_from_accel_closure().
5177 * Return value: (transfer container) (element-type GClosure):
5178 * a newly allocated #GList of closures
5181 gtk_widget_list_accel_closures (GtkWidget *widget)
5184 GList *clist = NULL;
5186 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5188 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5189 if (gtk_accel_group_from_accel_closure (slist->data))
5190 clist = g_list_prepend (clist, slist->data);
5196 GtkAccelGroup *accel_group;
5201 destroy_accel_path (gpointer data)
5203 AccelPath *apath = data;
5205 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5207 /* closures_destroy takes care of unrefing the closure */
5208 g_object_unref (apath->accel_group);
5210 g_slice_free (AccelPath, apath);
5215 * gtk_widget_set_accel_path:
5216 * @widget: a #GtkWidget
5217 * @accel_path: (allow-none): path used to look up the accelerator
5218 * @accel_group: (allow-none): a #GtkAccelGroup.
5220 * Given an accelerator group, @accel_group, and an accelerator path,
5221 * @accel_path, sets up an accelerator in @accel_group so whenever the
5222 * key binding that is defined for @accel_path is pressed, @widget
5223 * will be activated. This removes any accelerators (for any
5224 * accelerator group) installed by previous calls to
5225 * gtk_widget_set_accel_path(). Associating accelerators with
5226 * paths allows them to be modified by the user and the modifications
5227 * to be saved for future use. (See gtk_accel_map_save().)
5229 * This function is a low level function that would most likely
5230 * be used by a menu creation system like #GtkUIManager. If you
5231 * use #GtkUIManager, setting up accelerator paths will be done
5234 * Even when you you aren't using #GtkUIManager, if you only want to
5235 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5236 * provides a somewhat more convenient interface.
5238 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5239 * pass a static string, you can save some memory by interning it first with
5240 * g_intern_static_string().
5243 gtk_widget_set_accel_path (GtkWidget *widget,
5244 const gchar *accel_path,
5245 GtkAccelGroup *accel_group)
5249 g_return_if_fail (GTK_IS_WIDGET (widget));
5250 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5254 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5255 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5257 gtk_accel_map_add_entry (accel_path, 0, 0);
5258 apath = g_slice_new (AccelPath);
5259 apath->accel_group = g_object_ref (accel_group);
5260 apath->path_quark = g_quark_from_string (accel_path);
5261 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5266 /* also removes possible old settings */
5267 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5270 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5272 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5276 _gtk_widget_get_accel_path (GtkWidget *widget,
5281 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5283 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5285 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5286 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5290 * gtk_widget_mnemonic_activate:
5291 * @widget: a #GtkWidget
5292 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5294 * Emits the #GtkWidget::mnemonic-activate signal.
5296 * The default handler for this signal activates the @widget if
5297 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5300 * Returns: %TRUE if the signal has been handled
5303 gtk_widget_mnemonic_activate (GtkWidget *widget,
5304 gboolean group_cycling)
5308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5310 group_cycling = group_cycling != FALSE;
5311 if (!gtk_widget_is_sensitive (widget))
5314 g_signal_emit (widget,
5315 widget_signals[MNEMONIC_ACTIVATE],
5323 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5324 gboolean group_cycling)
5326 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5327 gtk_widget_activate (widget);
5328 else if (gtk_widget_get_can_focus (widget))
5329 gtk_widget_grab_focus (widget);
5332 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5333 G_OBJECT_TYPE_NAME (widget));
5334 gtk_widget_error_bell (widget);
5339 static const cairo_user_data_key_t event_key;
5342 _gtk_cairo_get_event (cairo_t *cr)
5344 g_return_val_if_fail (cr != NULL, NULL);
5346 return cairo_get_user_data (cr, &event_key);
5350 gtk_cairo_set_event (cairo_t *cr,
5351 GdkEventExpose *event)
5353 cairo_set_user_data (cr, &event_key, event, NULL);
5357 * gtk_cairo_should_draw_window:
5358 * @cr: a cairo context
5359 * @window: the window to check
5361 * This function is supposed to be called in #GtkWidget::draw
5362 * implementations for widgets that support multiple windows.
5363 * @cr must be untransformed from invoking of the draw function.
5364 * This function will return %TRUE if the contents of the given
5365 * @window are supposed to be drawn and %FALSE otherwise. Note
5366 * that when the drawing was not initiated by the windowing
5367 * system this function will return %TRUE for all windows, so
5368 * you need to draw the bottommost window first. Also, do not
5369 * use "else if" statements to check which window should be drawn.
5371 * Returns: %TRUE if @window should be drawn
5374 gtk_cairo_should_draw_window (cairo_t *cr,
5377 GdkEventExpose *event;
5379 g_return_val_if_fail (cr != NULL, FALSE);
5380 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5382 event = _gtk_cairo_get_event (cr);
5384 return event == NULL ||
5385 event->window == window;
5388 /* code shared by gtk_container_propagate_draw() and
5392 _gtk_widget_draw_internal (GtkWidget *widget,
5394 gboolean clip_to_size)
5396 if (!gtk_widget_is_drawable (widget))
5401 cairo_rectangle (cr,
5403 widget->priv->allocation.width,
5404 widget->priv->allocation.height);
5408 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5412 g_signal_emit (widget, widget_signals[DRAW],
5420 * @widget: the widget to draw. It must be drawable (see
5421 * gtk_widget_is_drawable()) and a size must have been allocated.
5422 * @cr: a cairo context to draw to
5424 * Draws @widget to @cr. The top left corner of the widget will be
5425 * drawn to the currently set origin point of @cr.
5427 * You should pass a cairo context as @cr argument that is in an
5428 * original state. Otherwise the resulting drawing is undefined. For
5429 * example changing the operator using cairo_set_operator() or the
5430 * line width using cairo_set_line_width() might have unwanted side
5432 * You may however change the context's transform matrix - like with
5433 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5434 * region with cairo_clip() prior to calling this function. Also, it
5435 * is fine to modify the context with cairo_save() and
5436 * cairo_push_group() prior to calling this function.
5438 * <note><para>Special purpose widgets may contain special code for
5439 * rendering to the screen and might appear differently on screen
5440 * and when rendered using gtk_widget_draw().</para></note>
5443 gtk_widget_draw (GtkWidget *widget,
5446 GdkEventExpose *tmp_event;
5448 g_return_if_fail (GTK_IS_WIDGET (widget));
5449 g_return_if_fail (!widget->priv->alloc_needed);
5450 g_return_if_fail (cr != NULL);
5453 /* We have to reset the event here so that draw functions can call
5454 * gtk_widget_draw() on random other widgets and get the desired
5455 * effect: Drawing all contents, not just the current window.
5457 tmp_event = _gtk_cairo_get_event (cr);
5458 gtk_cairo_set_event (cr, NULL);
5460 _gtk_widget_draw_internal (widget, cr, TRUE);
5462 gtk_cairo_set_event (cr, tmp_event);
5467 gtk_widget_real_key_press_event (GtkWidget *widget,
5470 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5474 gtk_widget_real_key_release_event (GtkWidget *widget,
5477 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5481 gtk_widget_real_focus_in_event (GtkWidget *widget,
5482 GdkEventFocus *event)
5484 gtk_widget_queue_shallow_draw (widget);
5490 gtk_widget_real_focus_out_event (GtkWidget *widget,
5491 GdkEventFocus *event)
5493 gtk_widget_queue_shallow_draw (widget);
5498 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5499 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5503 * @widget: a #GtkWidget
5504 * @event: a #GdkEvent
5506 * Rarely-used function. This function is used to emit
5507 * the event signals on a widget (those signals should never
5508 * be emitted without using this function to do so).
5509 * If you want to synthesize an event though, don't use this function;
5510 * instead, use gtk_main_do_event() so the event will behave as if
5511 * it were in the event queue. Don't synthesize expose events; instead,
5512 * use gdk_window_invalidate_rect() to invalidate a region of the
5515 * Return value: return from the event signal emission (%TRUE if
5516 * the event was handled)
5519 gtk_widget_event (GtkWidget *widget,
5522 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5523 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5525 if (event->type == GDK_EXPOSE)
5527 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5528 "the same effect, call gdk_window_invalidate_rect/region(), "
5529 "followed by gdk_window_process_updates().");
5533 return gtk_widget_event_internal (widget, event);
5536 /* Returns TRUE if a translation should be done */
5538 gtk_widget_get_translation_to_window (GtkWidget *widget,
5543 GdkWindow *w, *widget_window;
5545 if (!gtk_widget_get_has_window (widget))
5547 *x = -widget->priv->allocation.x;
5548 *y = -widget->priv->allocation.y;
5556 widget_window = gtk_widget_get_window (widget);
5558 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5561 gdk_window_get_position (w, &wx, &wy);
5578 * gtk_cairo_transform_to_window:
5579 * @cr: the cairo context to transform
5580 * @widget: the widget the context is currently centered for
5581 * @window: the window to transform the context to
5583 * Transforms the given cairo context @cr that from @widget-relative
5584 * coordinates to @window-relative coordinates.
5585 * If the @widget's window is not an ancestor of @window, no
5586 * modification will be applied.
5588 * This is the inverse to the transformation GTK applies when
5589 * preparing an expose event to be emitted with the #GtkWidget::draw
5590 * signal. It is intended to help porting multiwindow widgets from
5591 * GTK+ 2 to the rendering architecture of GTK+ 3.
5594 gtk_cairo_transform_to_window (cairo_t *cr,
5600 g_return_if_fail (cr != NULL);
5601 g_return_if_fail (GTK_IS_WIDGET (widget));
5602 g_return_if_fail (GDK_IS_WINDOW (window));
5604 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5605 cairo_translate (cr, x, y);
5609 * gtk_widget_send_expose:
5610 * @widget: a #GtkWidget
5611 * @event: a expose #GdkEvent
5613 * Very rarely-used function. This function is used to emit
5614 * an expose event on a widget. This function is not normally used
5615 * directly. The only time it is used is when propagating an expose
5616 * event to a child %NO_WINDOW widget, and that is normally done
5617 * using gtk_container_propagate_draw().
5619 * If you want to force an area of a window to be redrawn,
5620 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5621 * To cause the redraw to be done immediately, follow that call
5622 * with a call to gdk_window_process_updates().
5624 * Return value: return from the event signal emission (%TRUE if
5625 * the event was handled)
5628 gtk_widget_send_expose (GtkWidget *widget,
5631 gboolean result = FALSE;
5636 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5637 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5638 g_return_val_if_fail (event != NULL, TRUE);
5639 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5641 cr = gdk_cairo_create (event->expose.window);
5642 gtk_cairo_set_event (cr, &event->expose);
5644 gdk_cairo_region (cr, event->expose.region);
5647 do_clip = gtk_widget_get_translation_to_window (widget,
5648 event->expose.window,
5650 cairo_translate (cr, -x, -y);
5652 _gtk_widget_draw_internal (widget, cr, do_clip);
5654 /* unset here, so if someone keeps a reference to cr we
5655 * don't leak the window. */
5656 gtk_cairo_set_event (cr, NULL);
5663 event_window_is_still_viewable (GdkEvent *event)
5665 /* Check that we think the event's window is viewable before
5666 * delivering the event, to prevent suprises. We do this here
5667 * at the last moment, since the event may have been queued
5668 * up behind other events, held over a recursive main loop, etc.
5670 switch (event->type)
5673 case GDK_MOTION_NOTIFY:
5674 case GDK_BUTTON_PRESS:
5675 case GDK_2BUTTON_PRESS:
5676 case GDK_3BUTTON_PRESS:
5678 case GDK_ENTER_NOTIFY:
5679 case GDK_PROXIMITY_IN:
5681 return event->any.window && gdk_window_is_viewable (event->any.window);
5684 /* The following events are the second half of paired events;
5685 * we always deliver them to deal with widgets that clean up
5686 * on the second half.
5688 case GDK_BUTTON_RELEASE:
5689 case GDK_KEY_RELEASE:
5690 case GDK_LEAVE_NOTIFY:
5691 case GDK_PROXIMITY_OUT:
5695 /* Remaining events would make sense on an not-viewable window,
5696 * or don't have an associated window.
5703 gtk_widget_event_internal (GtkWidget *widget,
5706 gboolean return_val = FALSE;
5708 /* We check only once for is-still-visible; if someone
5709 * hides the window in on of the signals on the widget,
5710 * they are responsible for returning TRUE to terminate
5713 if (!event_window_is_still_viewable (event))
5716 g_object_ref (widget);
5718 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5719 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5724 switch (event->type)
5729 case GDK_BUTTON_PRESS:
5730 case GDK_2BUTTON_PRESS:
5731 case GDK_3BUTTON_PRESS:
5732 signal_num = BUTTON_PRESS_EVENT;
5735 signal_num = SCROLL_EVENT;
5737 case GDK_BUTTON_RELEASE:
5738 signal_num = BUTTON_RELEASE_EVENT;
5740 case GDK_MOTION_NOTIFY:
5741 signal_num = MOTION_NOTIFY_EVENT;
5744 signal_num = DELETE_EVENT;
5747 signal_num = DESTROY_EVENT;
5748 _gtk_tooltip_hide (widget);
5751 signal_num = KEY_PRESS_EVENT;
5753 case GDK_KEY_RELEASE:
5754 signal_num = KEY_RELEASE_EVENT;
5756 case GDK_ENTER_NOTIFY:
5757 signal_num = ENTER_NOTIFY_EVENT;
5759 case GDK_LEAVE_NOTIFY:
5760 signal_num = LEAVE_NOTIFY_EVENT;
5762 case GDK_FOCUS_CHANGE:
5763 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5764 if (event->focus_change.in)
5765 _gtk_tooltip_focus_in (widget);
5767 _gtk_tooltip_focus_out (widget);
5770 signal_num = CONFIGURE_EVENT;
5773 signal_num = MAP_EVENT;
5776 signal_num = UNMAP_EVENT;
5778 case GDK_WINDOW_STATE:
5779 signal_num = WINDOW_STATE_EVENT;
5781 case GDK_PROPERTY_NOTIFY:
5782 signal_num = PROPERTY_NOTIFY_EVENT;
5784 case GDK_SELECTION_CLEAR:
5785 signal_num = SELECTION_CLEAR_EVENT;
5787 case GDK_SELECTION_REQUEST:
5788 signal_num = SELECTION_REQUEST_EVENT;
5790 case GDK_SELECTION_NOTIFY:
5791 signal_num = SELECTION_NOTIFY_EVENT;
5793 case GDK_PROXIMITY_IN:
5794 signal_num = PROXIMITY_IN_EVENT;
5796 case GDK_PROXIMITY_OUT:
5797 signal_num = PROXIMITY_OUT_EVENT;
5799 case GDK_CLIENT_EVENT:
5800 signal_num = CLIENT_EVENT;
5803 signal_num = EXPOSE_EVENT;
5805 case GDK_VISIBILITY_NOTIFY:
5806 signal_num = VISIBILITY_NOTIFY_EVENT;
5808 case GDK_GRAB_BROKEN:
5809 signal_num = GRAB_BROKEN_EVENT;
5812 signal_num = DAMAGE_EVENT;
5815 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5819 if (signal_num != -1)
5820 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5822 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5823 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5827 g_object_unref (widget);
5833 * gtk_widget_activate:
5834 * @widget: a #GtkWidget that's activatable
5836 * For widgets that can be "activated" (buttons, menu items, etc.)
5837 * this function activates them. Activation is what happens when you
5838 * press Enter on a widget during key navigation. If @widget isn't
5839 * activatable, the function returns %FALSE.
5841 * Return value: %TRUE if the widget was activatable
5844 gtk_widget_activate (GtkWidget *widget)
5846 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5848 if (WIDGET_CLASS (widget)->activate_signal)
5850 /* FIXME: we should eventually check the signals signature here */
5851 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5860 gtk_widget_reparent_subwindows (GtkWidget *widget,
5861 GdkWindow *new_window)
5863 GtkWidgetPrivate *priv = widget->priv;
5865 if (!gtk_widget_get_has_window (widget))
5867 GList *children = gdk_window_get_children (priv->window);
5870 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5872 GdkWindow *window = tmp_list->data;
5875 gdk_window_get_user_data (window, &child);
5876 while (child && child != widget)
5877 child = ((GtkWidget*) child)->priv->parent;
5880 gdk_window_reparent (window, new_window, 0, 0);
5883 g_list_free (children);
5888 GList *tmp_list, *children;
5890 parent = gdk_window_get_parent (priv->window);
5893 gdk_window_reparent (priv->window, new_window, 0, 0);
5896 children = gdk_window_get_children (parent);
5898 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5900 GdkWindow *window = tmp_list->data;
5903 gdk_window_get_user_data (window, &child);
5905 if (child == widget)
5906 gdk_window_reparent (window, new_window, 0, 0);
5909 g_list_free (children);
5915 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5916 gpointer client_data)
5918 GtkWidgetPrivate *priv = widget->priv;
5920 g_assert (client_data != NULL);
5922 if (!gtk_widget_get_has_window (widget))
5925 g_object_unref (priv->window);
5926 priv->window = (GdkWindow*) client_data;
5928 g_object_ref (priv->window);
5930 if (GTK_IS_CONTAINER (widget))
5931 gtk_container_forall (GTK_CONTAINER (widget),
5932 gtk_widget_reparent_fixup_child,
5938 * gtk_widget_reparent:
5939 * @widget: a #GtkWidget
5940 * @new_parent: a #GtkContainer to move the widget into
5942 * Moves a widget from one #GtkContainer to another, handling reference
5943 * count issues to avoid destroying the widget.
5946 gtk_widget_reparent (GtkWidget *widget,
5947 GtkWidget *new_parent)
5949 GtkWidgetPrivate *priv;
5951 g_return_if_fail (GTK_IS_WIDGET (widget));
5952 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5953 priv = widget->priv;
5954 g_return_if_fail (priv->parent != NULL);
5956 if (priv->parent != new_parent)
5958 /* First try to see if we can get away without unrealizing
5959 * the widget as we reparent it. if so we set a flag so
5960 * that gtk_widget_unparent doesn't unrealize widget
5962 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5963 priv->in_reparent = TRUE;
5965 g_object_ref (widget);
5966 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5967 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5968 g_object_unref (widget);
5970 if (priv->in_reparent)
5972 priv->in_reparent = FALSE;
5974 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5975 gtk_widget_reparent_fixup_child (widget,
5976 gtk_widget_get_parent_window (widget));
5979 g_object_notify (G_OBJECT (widget), "parent");
5984 * gtk_widget_intersect:
5985 * @widget: a #GtkWidget
5986 * @area: a rectangle
5987 * @intersection: rectangle to store intersection of @widget and @area
5989 * Computes the intersection of a @widget's area and @area, storing
5990 * the intersection in @intersection, and returns %TRUE if there was
5991 * an intersection. @intersection may be %NULL if you're only
5992 * interested in whether there was an intersection.
5994 * Return value: %TRUE if there was an intersection
5997 gtk_widget_intersect (GtkWidget *widget,
5998 const GdkRectangle *area,
5999 GdkRectangle *intersection)
6001 GtkWidgetPrivate *priv;
6006 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6007 g_return_val_if_fail (area != NULL, FALSE);
6009 priv = widget->priv;
6012 dest = intersection;
6016 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6018 if (return_val && intersection && gtk_widget_get_has_window (widget))
6020 intersection->x -= priv->allocation.x;
6021 intersection->y -= priv->allocation.y;
6028 * gtk_widget_region_intersect:
6029 * @widget: a #GtkWidget
6030 * @region: a #cairo_region_t, in the same coordinate system as
6031 * @widget->allocation. That is, relative to @widget->window
6032 * for %NO_WINDOW widgets; relative to the parent window
6033 * of @widget->window for widgets with their own window.
6034 * @returns: A newly allocated region holding the intersection of @widget
6035 * and @region. The coordinates of the return value are
6036 * relative to @widget->window for %NO_WINDOW widgets, and
6037 * relative to the parent window of @widget->window for
6038 * widgets with their own window.
6040 * Computes the intersection of a @widget's area and @region, returning
6041 * the intersection. The result may be empty, use cairo_region_is_empty() to
6045 gtk_widget_region_intersect (GtkWidget *widget,
6046 const cairo_region_t *region)
6049 cairo_region_t *dest;
6051 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6052 g_return_val_if_fail (region != NULL, NULL);
6054 gtk_widget_get_allocation (widget, &rect);
6056 dest = cairo_region_create_rectangle (&rect);
6058 cairo_region_intersect (dest, region);
6064 * _gtk_widget_grab_notify:
6065 * @widget: a #GtkWidget
6066 * @was_grabbed: whether a grab is now in effect
6068 * Emits the #GtkWidget::grab-notify signal on @widget.
6073 _gtk_widget_grab_notify (GtkWidget *widget,
6074 gboolean was_grabbed)
6076 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6080 * gtk_widget_grab_focus:
6081 * @widget: a #GtkWidget
6083 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6084 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6085 * something like #GtkFrame won't work.
6087 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6088 * gtk_widget_set_can_focus() to modify that flag.
6090 * The widget also needs to be realized and mapped. This is indicated by the
6091 * related signals. Grabbing the focus immediately after creating the widget
6092 * will likely fail and cause critical warnings.
6095 gtk_widget_grab_focus (GtkWidget *widget)
6097 g_return_if_fail (GTK_IS_WIDGET (widget));
6099 if (!gtk_widget_is_sensitive (widget))
6102 g_object_ref (widget);
6103 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6104 g_object_notify (G_OBJECT (widget), "has-focus");
6105 g_object_unref (widget);
6109 reset_focus_recurse (GtkWidget *widget,
6112 if (GTK_IS_CONTAINER (widget))
6114 GtkContainer *container;
6116 container = GTK_CONTAINER (widget);
6117 gtk_container_set_focus_child (container, NULL);
6119 gtk_container_foreach (container,
6120 reset_focus_recurse,
6126 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6128 if (gtk_widget_get_can_focus (focus_widget))
6130 GtkWidget *toplevel;
6133 /* clear the current focus setting, break if the current widget
6134 * is the focus widget's parent, since containers above that will
6135 * be set by the next loop.
6137 toplevel = gtk_widget_get_toplevel (focus_widget);
6138 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6140 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6142 if (widget == focus_widget)
6144 /* We call _gtk_window_internal_set_focus() here so that the
6145 * toplevel window can request the focus if necessary.
6146 * This is needed when the toplevel is a GtkPlug
6148 if (!gtk_widget_has_focus (widget))
6149 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6156 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6158 widget = widget->priv->parent;
6159 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6163 else if (toplevel != focus_widget)
6165 /* gtk_widget_grab_focus() operates on a tree without window...
6166 * actually, this is very questionable behaviour.
6169 gtk_container_foreach (GTK_CONTAINER (toplevel),
6170 reset_focus_recurse,
6174 /* now propagate the new focus up the widget tree and finally
6175 * set it on the window
6177 widget = focus_widget;
6178 while (widget->priv->parent)
6180 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6181 widget = widget->priv->parent;
6183 if (GTK_IS_WINDOW (widget))
6184 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6189 gtk_widget_real_query_tooltip (GtkWidget *widget,
6192 gboolean keyboard_tip,
6193 GtkTooltip *tooltip)
6195 gchar *tooltip_markup;
6196 gboolean has_tooltip;
6198 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6199 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6201 if (has_tooltip && tooltip_markup)
6203 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6211 gtk_widget_real_show_help (GtkWidget *widget,
6212 GtkWidgetHelpType help_type)
6214 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6216 _gtk_tooltip_toggle_keyboard_mode (widget);
6225 gtk_widget_real_focus (GtkWidget *widget,
6226 GtkDirectionType direction)
6228 if (!gtk_widget_get_can_focus (widget))
6231 if (!gtk_widget_is_focus (widget))
6233 gtk_widget_grab_focus (widget);
6241 gtk_widget_real_move_focus (GtkWidget *widget,
6242 GtkDirectionType direction)
6244 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6246 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6248 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6254 gtk_widget_real_keynav_failed (GtkWidget *widget,
6255 GtkDirectionType direction)
6257 gboolean cursor_only;
6261 case GTK_DIR_TAB_FORWARD:
6262 case GTK_DIR_TAB_BACKWARD:
6269 g_object_get (gtk_widget_get_settings (widget),
6270 "gtk-keynav-cursor-only", &cursor_only,
6277 gtk_widget_error_bell (widget);
6283 * gtk_widget_set_can_focus:
6284 * @widget: a #GtkWidget
6285 * @can_focus: whether or not @widget can own the input focus.
6287 * Specifies whether @widget can own the input focus. See
6288 * gtk_widget_grab_focus() for actually setting the input focus on a
6294 gtk_widget_set_can_focus (GtkWidget *widget,
6297 g_return_if_fail (GTK_IS_WIDGET (widget));
6299 if (widget->priv->can_focus != can_focus)
6301 widget->priv->can_focus = can_focus;
6303 gtk_widget_queue_resize (widget);
6304 g_object_notify (G_OBJECT (widget), "can-focus");
6309 * gtk_widget_get_can_focus:
6310 * @widget: a #GtkWidget
6312 * Determines whether @widget can own the input focus. See
6313 * gtk_widget_set_can_focus().
6315 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6320 gtk_widget_get_can_focus (GtkWidget *widget)
6322 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6324 return widget->priv->can_focus;
6328 * gtk_widget_has_focus:
6329 * @widget: a #GtkWidget
6331 * Determines if the widget has the global input focus. See
6332 * gtk_widget_is_focus() for the difference between having the global
6333 * input focus, and only having the focus within a toplevel.
6335 * Return value: %TRUE if the widget has the global input focus.
6340 gtk_widget_has_focus (GtkWidget *widget)
6342 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6344 return widget->priv->has_focus;
6348 * gtk_widget_is_focus:
6349 * @widget: a #GtkWidget
6351 * Determines if the widget is the focus widget within its
6352 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6353 * necessarily set; %HAS_FOCUS will only be set if the
6354 * toplevel widget additionally has the global input focus.)
6356 * Return value: %TRUE if the widget is the focus widget.
6359 gtk_widget_is_focus (GtkWidget *widget)
6361 GtkWidget *toplevel;
6363 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6365 toplevel = gtk_widget_get_toplevel (widget);
6367 if (GTK_IS_WINDOW (toplevel))
6368 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6374 * gtk_widget_set_can_default:
6375 * @widget: a #GtkWidget
6376 * @can_default: whether or not @widget can be a default widget.
6378 * Specifies whether @widget can be a default widget. See
6379 * gtk_widget_grab_default() for details about the meaning of
6385 gtk_widget_set_can_default (GtkWidget *widget,
6386 gboolean can_default)
6388 g_return_if_fail (GTK_IS_WIDGET (widget));
6390 if (widget->priv->can_default != can_default)
6392 widget->priv->can_default = can_default;
6394 gtk_widget_queue_resize (widget);
6395 g_object_notify (G_OBJECT (widget), "can-default");
6400 * gtk_widget_get_can_default:
6401 * @widget: a #GtkWidget
6403 * Determines whether @widget can be a default widget. See
6404 * gtk_widget_set_can_default().
6406 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6411 gtk_widget_get_can_default (GtkWidget *widget)
6413 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6415 return widget->priv->can_default;
6419 * gtk_widget_has_default:
6420 * @widget: a #GtkWidget
6422 * Determines whether @widget is the current default widget within its
6423 * toplevel. See gtk_widget_set_can_default().
6425 * Return value: %TRUE if @widget is the current default widget within
6426 * its toplevel, %FALSE otherwise
6431 gtk_widget_has_default (GtkWidget *widget)
6433 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6435 return widget->priv->has_default;
6439 _gtk_widget_set_has_default (GtkWidget *widget,
6440 gboolean has_default)
6442 widget->priv->has_default = has_default;
6446 * gtk_widget_grab_default:
6447 * @widget: a #GtkWidget
6449 * Causes @widget to become the default widget. @widget must have the
6450 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6451 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6452 * %TRUE)</literal>. The default widget is activated when
6453 * the user presses Enter in a window. Default widgets must be
6454 * activatable, that is, gtk_widget_activate() should affect them. Note
6455 * that #GtkEntry widgets require the "activates-default" property
6456 * set to %TRUE before they activate the default widget when Enter
6457 * is pressed and the #GtkEntry is focused.
6460 gtk_widget_grab_default (GtkWidget *widget)
6464 g_return_if_fail (GTK_IS_WIDGET (widget));
6465 g_return_if_fail (gtk_widget_get_can_default (widget));
6467 window = gtk_widget_get_toplevel (widget);
6469 if (window && gtk_widget_is_toplevel (window))
6470 gtk_window_set_default (GTK_WINDOW (window), widget);
6472 g_warning (G_STRLOC ": widget not within a GtkWindow");
6476 * gtk_widget_set_receives_default:
6477 * @widget: a #GtkWidget
6478 * @receives_default: whether or not @widget can be a default widget.
6480 * Specifies whether @widget will be treated as the default widget
6481 * within its toplevel when it has the focus, even if another widget
6484 * See gtk_widget_grab_default() for details about the meaning of
6490 gtk_widget_set_receives_default (GtkWidget *widget,
6491 gboolean receives_default)
6493 g_return_if_fail (GTK_IS_WIDGET (widget));
6495 if (widget->priv->receives_default != receives_default)
6497 widget->priv->receives_default = receives_default;
6499 g_object_notify (G_OBJECT (widget), "receives-default");
6504 * gtk_widget_get_receives_default:
6505 * @widget: a #GtkWidget
6507 * Determines whether @widget is alyways treated as default widget
6508 * withing its toplevel when it has the focus, even if another widget
6511 * See gtk_widget_set_receives_default().
6513 * Return value: %TRUE if @widget acts as default widget when focussed,
6519 gtk_widget_get_receives_default (GtkWidget *widget)
6521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6523 return widget->priv->receives_default;
6527 * gtk_widget_has_grab:
6528 * @widget: a #GtkWidget
6530 * Determines whether the widget is currently grabbing events, so it
6531 * is the only widget receiving input events (keyboard and mouse).
6533 * See also gtk_grab_add().
6535 * Return value: %TRUE if the widget is in the grab_widgets stack
6540 gtk_widget_has_grab (GtkWidget *widget)
6542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6544 return widget->priv->has_grab;
6548 _gtk_widget_set_has_grab (GtkWidget *widget,
6551 widget->priv->has_grab = has_grab;
6555 * gtk_widget_device_is_shadowed:
6556 * @widget: a #GtkWidget
6557 * @device: a #GdkDevice
6559 * Returns %TRUE if @device has been shadowed by a GTK+
6560 * device grab on another widget, so it would stop sending
6561 * events to @widget. This may be used in the
6562 * #GtkWidget::grab-notify signal to check for specific
6563 * devices. See gtk_device_grab_add().
6565 * Returns: %TRUE if there is an ongoing grab on @device
6566 * by another #GtkWidget than @widget.
6571 gtk_widget_device_is_shadowed (GtkWidget *widget,
6574 GtkWindowGroup *group;
6575 GtkWidget *grab_widget, *toplevel;
6577 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6578 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6580 if (!gtk_widget_get_realized (widget))
6583 toplevel = gtk_widget_get_toplevel (widget);
6585 if (GTK_IS_WINDOW (toplevel))
6586 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6588 group = gtk_window_get_group (NULL);
6590 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6592 /* Widget not inside the hierarchy of grab_widget */
6594 widget != grab_widget &&
6595 !gtk_widget_is_ancestor (widget, grab_widget))
6598 grab_widget = gtk_window_group_get_current_grab (group);
6599 if (grab_widget && widget != grab_widget &&
6600 !gtk_widget_is_ancestor (widget, grab_widget))
6607 * gtk_widget_set_name:
6608 * @widget: a #GtkWidget
6609 * @name: name for the widget
6611 * Widgets can be named, which allows you to refer to them from a
6612 * gtkrc file. You can apply a style to widgets with a particular name
6613 * in the gtkrc file. See the documentation for gtkrc files (on the
6614 * same page as the docs for #GtkRcStyle).
6616 * Note that widget names are separated by periods in paths (see
6617 * gtk_widget_path()), so names with embedded periods may cause confusion.
6620 gtk_widget_set_name (GtkWidget *widget,
6623 GtkWidgetPrivate *priv;
6626 g_return_if_fail (GTK_IS_WIDGET (widget));
6628 priv = widget->priv;
6630 new_name = g_strdup (name);
6631 g_free (priv->name);
6632 priv->name = new_name;
6635 gtk_widget_reset_rc_style (widget);
6637 g_object_notify (G_OBJECT (widget), "name");
6641 * gtk_widget_get_name:
6642 * @widget: a #GtkWidget
6644 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6645 * significance of widget names.
6647 * Return value: name of the widget. This string is owned by GTK+ and
6648 * should not be modified or freed
6650 G_CONST_RETURN gchar*
6651 gtk_widget_get_name (GtkWidget *widget)
6653 GtkWidgetPrivate *priv;
6655 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6657 priv = widget->priv;
6661 return G_OBJECT_TYPE_NAME (widget);
6665 * gtk_widget_set_state:
6666 * @widget: a #GtkWidget
6667 * @state: new state for @widget
6669 * This function is for use in widget implementations. Sets the state
6670 * of a widget (insensitive, prelighted, etc.) Usually you should set
6671 * the state using wrapper functions such as gtk_widget_set_sensitive().
6674 gtk_widget_set_state (GtkWidget *widget,
6677 GtkWidgetPrivate *priv;
6679 g_return_if_fail (GTK_IS_WIDGET (widget));
6681 priv = widget->priv;
6683 if (state == gtk_widget_get_state (widget))
6686 if (state == GTK_STATE_INSENSITIVE)
6687 gtk_widget_set_sensitive (widget, FALSE);
6693 data.state_restoration = FALSE;
6694 data.use_forall = FALSE;
6696 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6698 data.parent_sensitive = TRUE;
6700 gtk_widget_propagate_state (widget, &data);
6702 if (gtk_widget_is_drawable (widget))
6703 gtk_widget_queue_draw (widget);
6708 * gtk_widget_get_state:
6709 * @widget: a #GtkWidget
6711 * Returns the widget's state. See gtk_widget_set_state().
6713 * Returns: the state of @widget.
6718 gtk_widget_get_state (GtkWidget *widget)
6720 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6722 return widget->priv->state;
6726 * gtk_widget_set_visible:
6727 * @widget: a #GtkWidget
6728 * @visible: whether the widget should be shown or not
6730 * Sets the visibility state of @widget. Note that setting this to
6731 * %TRUE doesn't mean the widget is actually viewable, see
6732 * gtk_widget_get_visible().
6734 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6735 * but is nicer to use when the visibility of the widget depends on
6741 gtk_widget_set_visible (GtkWidget *widget,
6744 g_return_if_fail (GTK_IS_WIDGET (widget));
6746 if (visible != gtk_widget_get_visible (widget))
6749 gtk_widget_show (widget);
6751 gtk_widget_hide (widget);
6756 _gtk_widget_set_visible_flag (GtkWidget *widget,
6759 widget->priv->visible = visible;
6763 * gtk_widget_get_visible:
6764 * @widget: a #GtkWidget
6766 * Determines whether the widget is visible. Note that this doesn't
6767 * take into account whether the widget's parent is also visible
6768 * or the widget is obscured in any way.
6770 * See gtk_widget_set_visible().
6772 * Return value: %TRUE if the widget is visible
6777 gtk_widget_get_visible (GtkWidget *widget)
6779 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6781 return widget->priv->visible;
6785 * gtk_widget_set_has_window:
6786 * @widget: a #GtkWidget
6787 * @has_window: whether or not @widget has a window.
6789 * Specifies whether @widget has a #GdkWindow of its own. Note that
6790 * all realized widgets have a non-%NULL "window" pointer
6791 * (gtk_widget_get_window() never returns a %NULL window when a widget
6792 * is realized), but for many of them it's actually the #GdkWindow of
6793 * one of its parent widgets. Widgets that do not create a %window for
6794 * themselves in #GtkWidget::realize must announce this by
6795 * calling this function with @has_window = %FALSE.
6797 * This function should only be called by widget implementations,
6798 * and they should call it in their init() function.
6803 gtk_widget_set_has_window (GtkWidget *widget,
6804 gboolean has_window)
6806 g_return_if_fail (GTK_IS_WIDGET (widget));
6808 widget->priv->no_window = !has_window;
6812 * gtk_widget_get_has_window:
6813 * @widget: a #GtkWidget
6815 * Determines whether @widget has a #GdkWindow of its own. See
6816 * gtk_widget_set_has_window().
6818 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6823 gtk_widget_get_has_window (GtkWidget *widget)
6825 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6827 return ! widget->priv->no_window;
6831 * gtk_widget_is_toplevel:
6832 * @widget: a #GtkWidget
6834 * Determines whether @widget is a toplevel widget. Currently only
6835 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6836 * widgets have no parent widget.
6838 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6843 gtk_widget_is_toplevel (GtkWidget *widget)
6845 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6847 return widget->priv->toplevel;
6851 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6852 gboolean is_toplevel)
6854 widget->priv->toplevel = is_toplevel;
6858 * gtk_widget_is_drawable:
6859 * @widget: a #GtkWidget
6861 * Determines whether @widget can be drawn to. A widget can be drawn
6862 * to if it is mapped and visible.
6864 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6869 gtk_widget_is_drawable (GtkWidget *widget)
6871 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6873 return (gtk_widget_get_visible (widget) &&
6874 gtk_widget_get_mapped (widget));
6878 * gtk_widget_get_realized:
6879 * @widget: a #GtkWidget
6881 * Determines whether @widget is realized.
6883 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6888 gtk_widget_get_realized (GtkWidget *widget)
6890 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6892 return widget->priv->realized;
6896 * gtk_widget_set_realized:
6897 * @widget: a #GtkWidget
6898 * @realized: %TRUE to mark the widget as realized
6900 * Marks the widget as being realized.
6902 * This function should only ever be called in a derived widget's
6903 * "realize" or "unrealize" implementation.
6908 gtk_widget_set_realized (GtkWidget *widget,
6911 g_return_if_fail (GTK_IS_WIDGET (widget));
6913 widget->priv->realized = realized;
6917 * gtk_widget_get_mapped:
6918 * @widget: a #GtkWidget
6920 * Whether the widget is mapped.
6922 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6927 gtk_widget_get_mapped (GtkWidget *widget)
6929 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6931 return widget->priv->mapped;
6935 * gtk_widget_set_mapped:
6936 * @widget: a #GtkWidget
6937 * @mapped: %TRUE to mark the widget as mapped
6939 * Marks the widget as being realized.
6941 * This function should only ever be called in a derived widget's
6942 * "map" or "unmap" implementation.
6947 gtk_widget_set_mapped (GtkWidget *widget,
6950 g_return_if_fail (GTK_IS_WIDGET (widget));
6952 widget->priv->mapped = mapped;
6956 * gtk_widget_set_app_paintable:
6957 * @widget: a #GtkWidget
6958 * @app_paintable: %TRUE if the application will paint on the widget
6960 * Sets whether the application intends to draw on the widget in
6961 * an #GtkWidget::draw handler.
6963 * This is a hint to the widget and does not affect the behavior of
6964 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6965 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6966 * the effect is to suppress default themed drawing of the widget's
6967 * background. (Children of the widget will still be drawn.) The application
6968 * is then entirely responsible for drawing the widget background.
6970 * Note that the background is still drawn when the widget is mapped.
6973 gtk_widget_set_app_paintable (GtkWidget *widget,
6974 gboolean app_paintable)
6976 g_return_if_fail (GTK_IS_WIDGET (widget));
6978 app_paintable = (app_paintable != FALSE);
6980 if (widget->priv->app_paintable != app_paintable)
6982 widget->priv->app_paintable = app_paintable;
6984 if (gtk_widget_is_drawable (widget))
6985 gtk_widget_queue_draw (widget);
6987 g_object_notify (G_OBJECT (widget), "app-paintable");
6992 * gtk_widget_get_app_paintable:
6993 * @widget: a #GtkWidget
6995 * Determines whether the application intends to draw on the widget in
6996 * an #GtkWidget::draw handler.
6998 * See gtk_widget_set_app_paintable()
7000 * Return value: %TRUE if the widget is app paintable
7005 gtk_widget_get_app_paintable (GtkWidget *widget)
7007 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7009 return widget->priv->app_paintable;
7013 * gtk_widget_set_double_buffered:
7014 * @widget: a #GtkWidget
7015 * @double_buffered: %TRUE to double-buffer a widget
7017 * Widgets are double buffered by default; you can use this function
7018 * to turn off the buffering. "Double buffered" simply means that
7019 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7020 * automatically around expose events sent to the
7021 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7022 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7023 * buffer to the screen. The result is that users see the window
7024 * update in one smooth step, and don't see individual graphics
7025 * primitives being rendered.
7027 * In very simple terms, double buffered widgets don't flicker,
7028 * so you would only use this function to turn off double buffering
7029 * if you had special needs and really knew what you were doing.
7031 * Note: if you turn off double-buffering, you have to handle
7032 * expose events, since even the clearing to the background color or
7033 * pixmap will not happen automatically (as it is done in
7034 * gdk_window_begin_paint()).
7037 gtk_widget_set_double_buffered (GtkWidget *widget,
7038 gboolean double_buffered)
7040 g_return_if_fail (GTK_IS_WIDGET (widget));
7042 double_buffered = (double_buffered != FALSE);
7044 if (widget->priv->double_buffered != double_buffered)
7046 widget->priv->double_buffered = double_buffered;
7048 g_object_notify (G_OBJECT (widget), "double-buffered");
7053 * gtk_widget_get_double_buffered:
7054 * @widget: a #GtkWidget
7056 * Determines whether the widget is double buffered.
7058 * See gtk_widget_set_double_buffered()
7060 * Return value: %TRUE if the widget is double buffered
7065 gtk_widget_get_double_buffered (GtkWidget *widget)
7067 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7069 return widget->priv->double_buffered;
7073 * gtk_widget_set_redraw_on_allocate:
7074 * @widget: a #GtkWidget
7075 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7076 * when it is allocated to a new size. Otherwise, only the
7077 * new portion of the widget will be redrawn.
7079 * Sets whether the entire widget is queued for drawing when its size
7080 * allocation changes. By default, this setting is %TRUE and
7081 * the entire widget is redrawn on every size change. If your widget
7082 * leaves the upper left unchanged when made bigger, turning this
7083 * setting off will improve performance.
7085 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7086 * off all allocation on resizing: the widget will not even redraw if
7087 * its position changes; this is to allow containers that don't draw
7088 * anything to avoid excess invalidations. If you set this flag on a
7089 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7090 * you are responsible for invalidating both the old and new allocation
7091 * of the widget when the widget is moved and responsible for invalidating
7092 * regions newly when the widget increases size.
7095 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7096 gboolean redraw_on_allocate)
7098 g_return_if_fail (GTK_IS_WIDGET (widget));
7100 widget->priv->redraw_on_alloc = redraw_on_allocate;
7104 * gtk_widget_set_sensitive:
7105 * @widget: a #GtkWidget
7106 * @sensitive: %TRUE to make the widget sensitive
7108 * Sets the sensitivity of a widget. A widget is sensitive if the user
7109 * can interact with it. Insensitive widgets are "grayed out" and the
7110 * user can't interact with them. Insensitive widgets are known as
7111 * "inactive", "disabled", or "ghosted" in some other toolkits.
7114 gtk_widget_set_sensitive (GtkWidget *widget,
7117 GtkWidgetPrivate *priv;
7120 g_return_if_fail (GTK_IS_WIDGET (widget));
7122 priv = widget->priv;
7124 sensitive = (sensitive != FALSE);
7126 if (widget->priv->sensitive == sensitive)
7131 widget->priv->sensitive = TRUE;
7132 data.state = priv->saved_state;
7136 widget->priv->sensitive = FALSE;
7137 data.state = gtk_widget_get_state (widget);
7139 data.state_restoration = TRUE;
7140 data.use_forall = TRUE;
7143 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7145 data.parent_sensitive = TRUE;
7147 gtk_widget_propagate_state (widget, &data);
7148 if (gtk_widget_is_drawable (widget))
7149 gtk_widget_queue_draw (widget);
7151 g_object_notify (G_OBJECT (widget), "sensitive");
7155 * gtk_widget_get_sensitive:
7156 * @widget: a #GtkWidget
7158 * Returns the widget's sensitivity (in the sense of returning
7159 * the value that has been set using gtk_widget_set_sensitive()).
7161 * The effective sensitivity of a widget is however determined by both its
7162 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7164 * Returns: %TRUE if the widget is sensitive
7169 gtk_widget_get_sensitive (GtkWidget *widget)
7171 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7173 return widget->priv->sensitive;
7177 * gtk_widget_is_sensitive:
7178 * @widget: a #GtkWidget
7180 * Returns the widget's effective sensitivity, which means
7181 * it is sensitive itself and also its parent widget is sensntive
7183 * Returns: %TRUE if the widget is effectively sensitive
7188 gtk_widget_is_sensitive (GtkWidget *widget)
7190 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7192 return widget->priv->sensitive && widget->priv->parent_sensitive;
7196 * gtk_widget_set_parent:
7197 * @widget: a #GtkWidget
7198 * @parent: parent container
7200 * This function is useful only when implementing subclasses of
7202 * Sets the container as the parent of @widget, and takes care of
7203 * some details such as updating the state and style of the child
7204 * to reflect its new location. The opposite function is
7205 * gtk_widget_unparent().
7208 gtk_widget_set_parent (GtkWidget *widget,
7211 GtkWidgetPrivate *priv;
7213 GtkStyleContext *context;
7215 g_return_if_fail (GTK_IS_WIDGET (widget));
7216 g_return_if_fail (GTK_IS_WIDGET (parent));
7217 g_return_if_fail (widget != parent);
7219 priv = widget->priv;
7221 if (priv->parent != NULL)
7223 g_warning ("Can't set a parent on widget which has a parent\n");
7226 if (gtk_widget_is_toplevel (widget))
7228 g_warning ("Can't set a parent on a toplevel widget\n");
7232 /* keep this function in sync with gtk_menu_attach_to_widget()
7235 g_object_ref_sink (widget);
7236 priv->parent = parent;
7238 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7239 data.state = gtk_widget_get_state (parent);
7241 data.state = gtk_widget_get_state (widget);
7242 data.state_restoration = FALSE;
7243 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7244 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7246 gtk_widget_propagate_state (widget, &data);
7248 gtk_widget_reset_rc_styles (widget);
7250 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7251 if (priv->parent->priv->anchored)
7252 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7253 g_object_notify (G_OBJECT (widget), "parent");
7255 /* Enforce realized/mapped invariants
7257 if (gtk_widget_get_realized (priv->parent))
7258 gtk_widget_realize (widget);
7260 if (gtk_widget_get_visible (priv->parent) &&
7261 gtk_widget_get_visible (widget))
7263 if (gtk_widget_get_child_visible (widget) &&
7264 gtk_widget_get_mapped (priv->parent))
7265 gtk_widget_map (widget);
7267 gtk_widget_queue_resize (widget);
7270 /* child may cause parent's expand to change, if the child is
7271 * expanded. If child is not expanded, then it can't modify the
7272 * parent's expand. If the child becomes expanded later then it will
7273 * queue compute_expand then. This optimization plus defaulting
7274 * newly-constructed widgets to need_compute_expand=FALSE should
7275 * mean that initially building a widget tree doesn't have to keep
7276 * walking up setting need_compute_expand on parents over and over.
7278 * We can't change a parent to need to expand unless we're visible.
7280 if (gtk_widget_get_visible (widget) &&
7281 (priv->need_compute_expand ||
7282 priv->computed_hexpand ||
7283 priv->computed_vexpand))
7285 gtk_widget_queue_compute_expand (parent);
7288 context = g_object_get_qdata (G_OBJECT (widget),
7289 quark_style_context);
7292 GtkWidgetPath *path;
7294 path = gtk_widget_get_path (widget);
7295 gtk_style_context_set_path (context, path);
7296 gtk_widget_path_free (path);
7301 * gtk_widget_get_parent:
7302 * @widget: a #GtkWidget
7304 * Returns the parent container of @widget.
7306 * Return value: (transfer none): the parent container of @widget, or %NULL
7309 gtk_widget_get_parent (GtkWidget *widget)
7311 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7313 return widget->priv->parent;
7316 /*****************************************
7318 * see docs/styles.txt
7319 *****************************************/
7322 * gtk_widget_style_attach:
7323 * @widget: a #GtkWidget
7325 * This function attaches the widget's #GtkStyle to the widget's
7326 * #GdkWindow. It is a replacement for
7329 * widget->style = gtk_style_attach (widget->style, widget->window);
7332 * and should only ever be called in a derived widget's "realize"
7333 * implementation which does not chain up to its parent class'
7334 * "realize" implementation, because one of the parent classes
7335 * (finally #GtkWidget) would attach the style itself.
7340 gtk_widget_style_attach (GtkWidget *widget)
7342 GtkWidgetPrivate *priv;
7344 g_return_if_fail (GTK_IS_WIDGET (widget));
7345 g_return_if_fail (gtk_widget_get_realized (widget));
7347 priv = widget->priv;
7349 priv->style = gtk_style_attach (priv->style, priv->window);
7353 * gtk_widget_has_rc_style:
7354 * @widget: a #GtkWidget
7356 * Determines if the widget style has been looked up through the rc mechanism.
7358 * Returns: %TRUE if the widget has been looked up through the rc
7359 * mechanism, %FALSE otherwise.
7364 gtk_widget_has_rc_style (GtkWidget *widget)
7366 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7368 return widget->priv->rc_style;
7372 * gtk_widget_set_style:
7373 * @widget: a #GtkWidget
7374 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7375 * gtk_widget_set_style() and go back to the default style
7377 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7378 * want to use this function; it interacts badly with themes, because
7379 * themes work by replacing the #GtkStyle. Instead, use
7380 * gtk_widget_modify_style().
7383 gtk_widget_set_style (GtkWidget *widget,
7386 g_return_if_fail (GTK_IS_WIDGET (widget));
7390 gboolean initial_emission;
7392 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7394 widget->priv->rc_style = FALSE;
7395 widget->priv->user_style = TRUE;
7397 gtk_widget_set_style_internal (widget, style, initial_emission);
7401 if (widget->priv->user_style)
7402 gtk_widget_reset_rc_style (widget);
7407 * gtk_widget_ensure_style:
7408 * @widget: a #GtkWidget
7410 * Ensures that @widget has a style (@widget->style). Not a very useful
7411 * function; most of the time, if you want the style, the widget is
7412 * realized, and realized widgets are guaranteed to have a style
7416 gtk_widget_ensure_style (GtkWidget *widget)
7418 g_return_if_fail (GTK_IS_WIDGET (widget));
7420 if (!widget->priv->rc_style && !widget->priv->user_style)
7421 gtk_widget_reset_rc_style (widget);
7424 /* Look up the RC style for this widget, unsetting any user style that
7425 * may be in effect currently
7428 gtk_widget_reset_rc_style (GtkWidget *widget)
7430 GtkWidgetPrivate *priv = widget->priv;
7431 GtkStyle *new_style = NULL;
7432 gboolean initial_emission;
7434 initial_emission = !priv->rc_style && !priv->user_style;
7436 priv->user_style = FALSE;
7437 priv->rc_style = TRUE;
7439 if (gtk_widget_has_screen (widget))
7440 new_style = gtk_rc_get_style (widget);
7442 new_style = gtk_widget_get_default_style ();
7444 if (initial_emission || new_style != priv->style)
7445 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7449 * gtk_widget_get_style:
7450 * @widget: a #GtkWidget
7452 * Simply an accessor function that returns @widget->style.
7454 * Return value: (transfer none): the widget's #GtkStyle
7457 gtk_widget_get_style (GtkWidget *widget)
7459 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7461 return widget->priv->style;
7465 * gtk_widget_modify_style:
7466 * @widget: a #GtkWidget
7467 * @style: the #GtkRcStyle holding the style modifications
7469 * Modifies style values on the widget. Modifications made using this
7470 * technique take precedence over style values set via an RC file,
7471 * however, they will be overriden if a style is explicitely set on
7472 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7473 * is designed so each field can either be set or unset, so it is
7474 * possible, using this function, to modify some style values and
7475 * leave the others unchanged.
7477 * Note that modifications made with this function are not cumulative
7478 * with previous calls to gtk_widget_modify_style() or with such
7479 * functions as gtk_widget_modify_fg(). If you wish to retain
7480 * previous values, you must first call gtk_widget_get_modifier_style(),
7481 * make your modifications to the returned style, then call
7482 * gtk_widget_modify_style() with that style. On the other hand,
7483 * if you first call gtk_widget_modify_style(), subsequent calls
7484 * to such functions gtk_widget_modify_fg() will have a cumulative
7485 * effect with the initial modifications.
7488 gtk_widget_modify_style (GtkWidget *widget,
7491 g_return_if_fail (GTK_IS_WIDGET (widget));
7492 g_return_if_fail (GTK_IS_RC_STYLE (style));
7494 g_object_set_qdata_full (G_OBJECT (widget),
7496 gtk_rc_style_copy (style),
7497 (GDestroyNotify) g_object_unref);
7499 /* note that "style" may be invalid here if it was the old
7500 * modifier style and the only reference was our own.
7503 if (widget->priv->rc_style)
7504 gtk_widget_reset_rc_style (widget);
7508 * gtk_widget_get_modifier_style:
7509 * @widget: a #GtkWidget
7511 * Returns the current modifier style for the widget. (As set by
7512 * gtk_widget_modify_style().) If no style has previously set, a new
7513 * #GtkRcStyle will be created with all values unset, and set as the
7514 * modifier style for the widget. If you make changes to this rc
7515 * style, you must call gtk_widget_modify_style(), passing in the
7516 * returned rc style, to make sure that your changes take effect.
7518 * Caution: passing the style back to gtk_widget_modify_style() will
7519 * normally end up destroying it, because gtk_widget_modify_style() copies
7520 * the passed-in style and sets the copy as the new modifier style,
7521 * thus dropping any reference to the old modifier style. Add a reference
7522 * to the modifier style if you want to keep it alive.
7524 * Return value: (transfer none): the modifier style for the widget. This rc style is
7525 * owned by the widget. If you want to keep a pointer to value this
7526 * around, you must add a refcount using g_object_ref().
7529 gtk_widget_get_modifier_style (GtkWidget *widget)
7531 GtkRcStyle *rc_style;
7533 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7535 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7539 rc_style = gtk_rc_style_new ();
7540 g_object_set_qdata_full (G_OBJECT (widget),
7543 (GDestroyNotify) g_object_unref);
7550 gtk_widget_modify_color_component (GtkWidget *widget,
7551 GtkRcFlags component,
7553 const GdkColor *color)
7555 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7562 rc_style->fg[state] = *color;
7565 rc_style->bg[state] = *color;
7568 rc_style->text[state] = *color;
7571 rc_style->base[state] = *color;
7574 g_assert_not_reached();
7577 rc_style->color_flags[state] |= component;
7580 rc_style->color_flags[state] &= ~component;
7582 gtk_widget_modify_style (widget, rc_style);
7586 * gtk_widget_modify_symbolic_color:
7587 * @widget: a #GtkWidget
7588 * @name: the name of the symbolic color to modify
7589 * @color: (allow-none): the color to assign (does not need to be allocated),
7590 * or %NULL to undo the effect of previous calls to
7591 * of gtk_widget_modify_symbolic_color().
7593 * Sets a symbolic color for a widget.
7594 * All other style values are left untouched. See also
7595 * gtk_widget_modify_style().
7600 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7602 const GdkColor *color)
7604 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7606 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7608 gtk_widget_modify_style (widget, rc_style);
7612 * gtk_widget_modify_fg:
7613 * @widget: a #GtkWidget
7614 * @state: the state for which to set the foreground color
7615 * @color: (allow-none): the color to assign (does not need to be allocated),
7616 * or %NULL to undo the effect of previous calls to
7617 * of gtk_widget_modify_fg().
7619 * Sets the foreground color for a widget in a particular state.
7620 * All other style values are left untouched. See also
7621 * gtk_widget_modify_style().
7624 gtk_widget_modify_fg (GtkWidget *widget,
7626 const GdkColor *color)
7628 g_return_if_fail (GTK_IS_WIDGET (widget));
7629 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7631 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7635 * gtk_widget_modify_bg:
7636 * @widget: a #GtkWidget
7637 * @state: the state for which to set the background color
7638 * @color: (allow-none): the color to assign (does not need to be allocated),
7639 * or %NULL to undo the effect of previous calls to
7640 * of gtk_widget_modify_bg().
7642 * Sets the background color for a widget in a particular state.
7643 * All other style values are left untouched. See also
7644 * gtk_widget_modify_style().
7646 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7647 * draw on their parent container's window and thus may not draw any
7648 * background themselves. This is the case for e.g. #GtkLabel. To modify
7649 * the background of such widgets, you have to set the background color
7650 * on their parent; if you want to set the background of a rectangular
7651 * area around a label, try placing the label in a #GtkEventBox widget
7652 * and setting the background color on that.
7655 gtk_widget_modify_bg (GtkWidget *widget,
7657 const GdkColor *color)
7659 g_return_if_fail (GTK_IS_WIDGET (widget));
7660 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7662 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7666 * gtk_widget_modify_text:
7667 * @widget: a #GtkWidget
7668 * @state: the state for which to set the text color
7669 * @color: (allow-none): the color to assign (does not need to be allocated),
7670 * or %NULL to undo the effect of previous calls to
7671 * of gtk_widget_modify_text().
7673 * Sets the text color for a widget in a particular state. All other
7674 * style values are left untouched. The text color is the foreground
7675 * color used along with the base color (see gtk_widget_modify_base())
7676 * for widgets such as #GtkEntry and #GtkTextView. See also
7677 * gtk_widget_modify_style().
7680 gtk_widget_modify_text (GtkWidget *widget,
7682 const GdkColor *color)
7684 g_return_if_fail (GTK_IS_WIDGET (widget));
7685 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7687 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7691 * gtk_widget_modify_base:
7692 * @widget: a #GtkWidget
7693 * @state: the state for which to set the base color
7694 * @color: (allow-none): the color to assign (does not need to be allocated),
7695 * or %NULL to undo the effect of previous calls to
7696 * of gtk_widget_modify_base().
7698 * Sets the base color for a widget in a particular state.
7699 * All other style values are left untouched. The base color
7700 * is the background color used along with the text color
7701 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7702 * and #GtkTextView. See also gtk_widget_modify_style().
7704 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7705 * draw on their parent container's window and thus may not draw any
7706 * background themselves. This is the case for e.g. #GtkLabel. To modify
7707 * the background of such widgets, you have to set the base color on their
7708 * parent; if you want to set the background of a rectangular area around
7709 * a label, try placing the label in a #GtkEventBox widget and setting
7710 * the base color on that.
7713 gtk_widget_modify_base (GtkWidget *widget,
7715 const GdkColor *color)
7717 g_return_if_fail (GTK_IS_WIDGET (widget));
7718 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7720 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7724 modify_color_property (GtkWidget *widget,
7725 GtkRcStyle *rc_style,
7727 const GdkColor *color)
7729 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7730 GQuark property_name = g_quark_from_string (name);
7734 GtkRcProperty rc_property = {0};
7737 rc_property.type_name = type_name;
7738 rc_property.property_name = property_name;
7739 rc_property.origin = NULL;
7741 color_name = gdk_color_to_string (color);
7742 g_value_init (&rc_property.value, G_TYPE_STRING);
7743 g_value_take_string (&rc_property.value, color_name);
7745 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7747 g_value_unset (&rc_property.value);
7750 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7754 * gtk_widget_modify_cursor:
7755 * @widget: a #GtkWidget
7756 * @primary: the color to use for primary cursor (does not need to be
7757 * allocated), or %NULL to undo the effect of previous calls to
7758 * of gtk_widget_modify_cursor().
7759 * @secondary: the color to use for secondary cursor (does not need to be
7760 * allocated), or %NULL to undo the effect of previous calls to
7761 * of gtk_widget_modify_cursor().
7763 * Sets the cursor color to use in a widget, overriding the
7764 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7765 * style properties. All other style values are left untouched.
7766 * See also gtk_widget_modify_style().
7771 gtk_widget_modify_cursor (GtkWidget *widget,
7772 const GdkColor *primary,
7773 const GdkColor *secondary)
7775 GtkRcStyle *rc_style;
7777 g_return_if_fail (GTK_IS_WIDGET (widget));
7779 rc_style = gtk_widget_get_modifier_style (widget);
7781 modify_color_property (widget, rc_style, "cursor-color", primary);
7782 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7784 gtk_widget_modify_style (widget, rc_style);
7788 * gtk_widget_modify_font:
7789 * @widget: a #GtkWidget
7790 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7791 * the effect of previous calls to gtk_widget_modify_font().
7793 * Sets the font to use for a widget. All other style values are left
7794 * untouched. See also gtk_widget_modify_style().
7797 gtk_widget_modify_font (GtkWidget *widget,
7798 PangoFontDescription *font_desc)
7800 GtkRcStyle *rc_style;
7802 g_return_if_fail (GTK_IS_WIDGET (widget));
7804 rc_style = gtk_widget_get_modifier_style (widget);
7806 if (rc_style->font_desc)
7807 pango_font_description_free (rc_style->font_desc);
7810 rc_style->font_desc = pango_font_description_copy (font_desc);
7812 rc_style->font_desc = NULL;
7814 gtk_widget_modify_style (widget, rc_style);
7818 gtk_widget_real_direction_changed (GtkWidget *widget,
7819 GtkTextDirection previous_direction)
7821 gtk_widget_queue_resize (widget);
7825 gtk_widget_real_style_set (GtkWidget *widget,
7826 GtkStyle *previous_style)
7828 GtkWidgetPrivate *priv = widget->priv;
7830 if (gtk_widget_get_realized (widget) &&
7831 gtk_widget_get_has_window (widget))
7832 gtk_style_set_background (priv->style, priv->window, priv->state);
7836 gtk_widget_set_style_internal (GtkWidget *widget,
7838 gboolean initial_emission)
7840 GtkWidgetPrivate *priv = widget->priv;
7842 g_object_ref (widget);
7843 g_object_freeze_notify (G_OBJECT (widget));
7845 if (priv->style != style)
7847 GtkStyle *previous_style;
7849 if (gtk_widget_get_realized (widget))
7851 gtk_widget_reset_shapes (widget);
7852 gtk_style_detach (priv->style);
7855 previous_style = priv->style;
7856 priv->style = style;
7857 g_object_ref (priv->style);
7859 if (gtk_widget_get_realized (widget))
7860 priv->style = gtk_style_attach (priv->style, priv->window);
7862 gtk_widget_update_pango_context (widget);
7863 g_signal_emit (widget,
7864 widget_signals[STYLE_SET],
7866 initial_emission ? NULL : previous_style);
7867 g_object_unref (previous_style);
7869 if (priv->anchored && !initial_emission)
7870 gtk_widget_queue_resize (widget);
7872 else if (initial_emission)
7874 gtk_widget_update_pango_context (widget);
7875 g_signal_emit (widget,
7876 widget_signals[STYLE_SET],
7880 g_object_notify (G_OBJECT (widget), "style");
7881 g_object_thaw_notify (G_OBJECT (widget));
7882 g_object_unref (widget);
7886 GtkWidget *previous_toplevel;
7887 GdkScreen *previous_screen;
7888 GdkScreen *new_screen;
7889 } HierarchyChangedInfo;
7892 do_screen_change (GtkWidget *widget,
7893 GdkScreen *old_screen,
7894 GdkScreen *new_screen)
7896 if (old_screen != new_screen)
7900 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7902 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7905 _gtk_tooltip_hide (widget);
7906 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7911 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7912 gpointer client_data)
7914 GtkWidgetPrivate *priv = widget->priv;
7915 HierarchyChangedInfo *info = client_data;
7916 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7917 (priv->parent && priv->parent->priv->anchored);
7919 if (priv->anchored != new_anchored)
7921 g_object_ref (widget);
7923 priv->anchored = new_anchored;
7925 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7926 do_screen_change (widget, info->previous_screen, info->new_screen);
7928 if (GTK_IS_CONTAINER (widget))
7929 gtk_container_forall (GTK_CONTAINER (widget),
7930 gtk_widget_propagate_hierarchy_changed_recurse,
7933 g_object_unref (widget);
7938 * _gtk_widget_propagate_hierarchy_changed:
7939 * @widget: a #GtkWidget
7940 * @previous_toplevel: Previous toplevel
7942 * Propagates changes in the anchored state to a widget and all
7943 * children, unsetting or setting the %ANCHORED flag, and
7944 * emitting #GtkWidget::hierarchy-changed.
7947 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7948 GtkWidget *previous_toplevel)
7950 GtkWidgetPrivate *priv = widget->priv;
7951 HierarchyChangedInfo info;
7953 info.previous_toplevel = previous_toplevel;
7954 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7956 if (gtk_widget_is_toplevel (widget) ||
7957 (priv->parent && priv->parent->priv->anchored))
7958 info.new_screen = gtk_widget_get_screen (widget);
7960 info.new_screen = NULL;
7962 if (info.previous_screen)
7963 g_object_ref (info.previous_screen);
7964 if (previous_toplevel)
7965 g_object_ref (previous_toplevel);
7967 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7969 if (previous_toplevel)
7970 g_object_unref (previous_toplevel);
7971 if (info.previous_screen)
7972 g_object_unref (info.previous_screen);
7976 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7977 gpointer client_data)
7979 HierarchyChangedInfo *info = client_data;
7981 g_object_ref (widget);
7983 do_screen_change (widget, info->previous_screen, info->new_screen);
7985 if (GTK_IS_CONTAINER (widget))
7986 gtk_container_forall (GTK_CONTAINER (widget),
7987 gtk_widget_propagate_screen_changed_recurse,
7990 g_object_unref (widget);
7994 * gtk_widget_is_composited:
7995 * @widget: a #GtkWidget
7997 * Whether @widget can rely on having its alpha channel
7998 * drawn correctly. On X11 this function returns whether a
7999 * compositing manager is running for @widget's screen.
8001 * Please note that the semantics of this call will change
8002 * in the future if used on a widget that has a composited
8003 * window in its hierarchy (as set by gdk_window_set_composited()).
8005 * Return value: %TRUE if the widget can rely on its alpha
8006 * channel being drawn correctly.
8011 gtk_widget_is_composited (GtkWidget *widget)
8015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8017 screen = gtk_widget_get_screen (widget);
8019 return gdk_screen_is_composited (screen);
8023 propagate_composited_changed (GtkWidget *widget,
8026 if (GTK_IS_CONTAINER (widget))
8028 gtk_container_forall (GTK_CONTAINER (widget),
8029 propagate_composited_changed,
8033 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8037 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8039 propagate_composited_changed (widget, NULL);
8043 * _gtk_widget_propagate_screen_changed:
8044 * @widget: a #GtkWidget
8045 * @previous_screen: Previous screen
8047 * Propagates changes in the screen for a widget to all
8048 * children, emitting #GtkWidget::screen-changed.
8051 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8052 GdkScreen *previous_screen)
8054 HierarchyChangedInfo info;
8056 info.previous_screen = previous_screen;
8057 info.new_screen = gtk_widget_get_screen (widget);
8059 if (previous_screen)
8060 g_object_ref (previous_screen);
8062 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8064 if (previous_screen)
8065 g_object_unref (previous_screen);
8069 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
8071 if (widget->priv->rc_style)
8072 gtk_widget_reset_rc_style (widget);
8074 if (GTK_IS_CONTAINER (widget))
8075 gtk_container_forall (GTK_CONTAINER (widget),
8076 reset_rc_styles_recurse,
8082 * gtk_widget_reset_rc_styles:
8083 * @widget: a #GtkWidget.
8085 * Reset the styles of @widget and all descendents, so when
8086 * they are looked up again, they get the correct values
8087 * for the currently loaded RC file settings.
8089 * This function is not useful for applications.
8092 gtk_widget_reset_rc_styles (GtkWidget *widget)
8094 g_return_if_fail (GTK_IS_WIDGET (widget));
8096 reset_rc_styles_recurse (widget, NULL);
8100 * gtk_widget_get_default_style:
8102 * Returns the default style used by all widgets initially.
8104 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8105 * by GTK+ and should not be modified or freed.
8108 gtk_widget_get_default_style (void)
8110 if (!gtk_default_style)
8112 gtk_default_style = gtk_style_new ();
8113 g_object_ref (gtk_default_style);
8116 return gtk_default_style;
8119 static PangoContext *
8120 gtk_widget_peek_pango_context (GtkWidget *widget)
8122 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8126 * gtk_widget_get_pango_context:
8127 * @widget: a #GtkWidget
8129 * Gets a #PangoContext with the appropriate font map, font description,
8130 * and base direction for this widget. Unlike the context returned
8131 * by gtk_widget_create_pango_context(), this context is owned by
8132 * the widget (it can be used until the screen for the widget changes
8133 * or the widget is removed from its toplevel), and will be updated to
8134 * match any changes to the widget's attributes.
8136 * If you create and keep a #PangoLayout using this context, you must
8137 * deal with changes to the context by calling pango_layout_context_changed()
8138 * on the layout in response to the #GtkWidget::style-set and
8139 * #GtkWidget::direction-changed signals for the widget.
8141 * Return value: (transfer none): the #PangoContext for the widget.
8144 gtk_widget_get_pango_context (GtkWidget *widget)
8146 PangoContext *context;
8148 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8150 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8153 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8154 g_object_set_qdata_full (G_OBJECT (widget),
8155 quark_pango_context,
8164 update_pango_context (GtkWidget *widget,
8165 PangoContext *context)
8167 GtkWidgetPrivate *priv = widget->priv;
8169 pango_context_set_font_description (context, priv->style->font_desc);
8170 pango_context_set_base_dir (context,
8171 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8172 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8176 gtk_widget_update_pango_context (GtkWidget *widget)
8178 PangoContext *context = gtk_widget_peek_pango_context (widget);
8184 update_pango_context (widget, context);
8186 screen = gtk_widget_get_screen_unchecked (widget);
8189 pango_cairo_context_set_resolution (context,
8190 gdk_screen_get_resolution (screen));
8191 pango_cairo_context_set_font_options (context,
8192 gdk_screen_get_font_options (screen));
8198 * gtk_widget_create_pango_context:
8199 * @widget: a #GtkWidget
8201 * Creates a new #PangoContext with the appropriate font map,
8202 * font description, and base direction for drawing text for
8203 * this widget. See also gtk_widget_get_pango_context().
8205 * Return value: (transfer full): the new #PangoContext
8208 gtk_widget_create_pango_context (GtkWidget *widget)
8211 PangoContext *context;
8213 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8215 screen = gtk_widget_get_screen_unchecked (widget);
8218 GTK_NOTE (MULTIHEAD,
8219 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8221 screen = gdk_screen_get_default ();
8224 context = gdk_pango_context_get_for_screen (screen);
8226 update_pango_context (widget, context);
8227 pango_context_set_language (context, gtk_get_default_language ());
8233 * gtk_widget_create_pango_layout:
8234 * @widget: a #GtkWidget
8235 * @text: text to set on the layout (can be %NULL)
8237 * Creates a new #PangoLayout with the appropriate font map,
8238 * font description, and base direction for drawing text for
8241 * If you keep a #PangoLayout created in this way around, in order to
8242 * notify the layout of changes to the base direction or font of this
8243 * widget, you must call pango_layout_context_changed() in response to
8244 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8247 * Return value: (transfer full): the new #PangoLayout
8250 gtk_widget_create_pango_layout (GtkWidget *widget,
8253 PangoLayout *layout;
8254 PangoContext *context;
8256 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8258 context = gtk_widget_get_pango_context (widget);
8259 layout = pango_layout_new (context);
8262 pango_layout_set_text (layout, text, -1);
8268 * gtk_widget_render_icon:
8269 * @widget: a #GtkWidget
8270 * @stock_id: a stock ID
8271 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8272 * render at the size of the source and don't scale (if there are
8273 * multiple source sizes, GTK+ picks one of the available sizes).
8274 * @detail: (allow-none): render detail to pass to theme engine
8276 * A convenience function that uses the theme engine and RC file
8277 * settings for @widget to look up @stock_id and render it to
8278 * a pixbuf. @stock_id should be a stock icon ID such as
8279 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8280 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8281 * identifies the widget or code doing the rendering, so that
8282 * theme engines can special-case rendering for that widget or code.
8284 * The pixels in the returned #GdkPixbuf are shared with the rest of
8285 * the application and should not be modified. The pixbuf should be freed
8286 * after use with g_object_unref().
8288 * Return value: (transfer full): a new pixbuf, or %NULL if the
8289 * stock ID wasn't known
8292 gtk_widget_render_icon (GtkWidget *widget,
8293 const gchar *stock_id,
8295 const gchar *detail)
8297 GtkWidgetPrivate *priv;
8298 GtkIconSet *icon_set;
8301 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8302 g_return_val_if_fail (stock_id != NULL, NULL);
8303 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8305 priv = widget->priv;
8307 gtk_widget_ensure_style (widget);
8309 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8311 if (icon_set == NULL)
8314 retval = gtk_icon_set_render_icon (icon_set,
8316 gtk_widget_get_direction (widget),
8317 gtk_widget_get_state (widget),
8326 * gtk_widget_set_parent_window:
8327 * @widget: a #GtkWidget.
8328 * @parent_window: the new parent window.
8330 * Sets a non default parent window for @widget.
8333 gtk_widget_set_parent_window (GtkWidget *widget,
8334 GdkWindow *parent_window)
8336 GdkWindow *old_parent_window;
8338 g_return_if_fail (GTK_IS_WIDGET (widget));
8340 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8341 quark_parent_window);
8343 if (parent_window != old_parent_window)
8345 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8347 if (old_parent_window)
8348 g_object_unref (old_parent_window);
8350 g_object_ref (parent_window);
8355 * gtk_widget_get_parent_window:
8356 * @widget: a #GtkWidget.
8358 * Gets @widget's parent window.
8360 * Returns: (transfer none): the parent window of @widget.
8363 gtk_widget_get_parent_window (GtkWidget *widget)
8365 GtkWidgetPrivate *priv;
8366 GdkWindow *parent_window;
8368 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8370 priv = widget->priv;
8372 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8374 return (parent_window != NULL) ? parent_window :
8375 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8380 * gtk_widget_set_child_visible:
8381 * @widget: a #GtkWidget
8382 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8384 * Sets whether @widget should be mapped along with its when its parent
8385 * is mapped and @widget has been shown with gtk_widget_show().
8387 * The child visibility can be set for widget before it is added to
8388 * a container with gtk_widget_set_parent(), to avoid mapping
8389 * children unnecessary before immediately unmapping them. However
8390 * it will be reset to its default state of %TRUE when the widget
8391 * is removed from a container.
8393 * Note that changing the child visibility of a widget does not
8394 * queue a resize on the widget. Most of the time, the size of
8395 * a widget is computed from all visible children, whether or
8396 * not they are mapped. If this is not the case, the container
8397 * can queue a resize itself.
8399 * This function is only useful for container implementations and
8400 * never should be called by an application.
8403 gtk_widget_set_child_visible (GtkWidget *widget,
8404 gboolean is_visible)
8406 GtkWidgetPrivate *priv;
8408 g_return_if_fail (GTK_IS_WIDGET (widget));
8409 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8411 priv = widget->priv;
8413 g_object_ref (widget);
8416 priv->child_visible = TRUE;
8419 GtkWidget *toplevel;
8421 priv->child_visible = FALSE;
8423 toplevel = gtk_widget_get_toplevel (widget);
8424 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8425 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8428 if (priv->parent && gtk_widget_get_realized (priv->parent))
8430 if (gtk_widget_get_mapped (priv->parent) &&
8431 priv->child_visible &&
8432 gtk_widget_get_visible (widget))
8433 gtk_widget_map (widget);
8435 gtk_widget_unmap (widget);
8438 g_object_unref (widget);
8442 * gtk_widget_get_child_visible:
8443 * @widget: a #GtkWidget
8445 * Gets the value set with gtk_widget_set_child_visible().
8446 * If you feel a need to use this function, your code probably
8447 * needs reorganization.
8449 * This function is only useful for container implementations and
8450 * never should be called by an application.
8452 * Return value: %TRUE if the widget is mapped with the parent.
8455 gtk_widget_get_child_visible (GtkWidget *widget)
8457 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8459 return widget->priv->child_visible;
8463 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8465 GtkWidget *toplevel;
8467 toplevel = gtk_widget_get_toplevel (widget);
8469 if (gtk_widget_is_toplevel (toplevel))
8471 if (GTK_IS_WINDOW (toplevel))
8472 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8473 else if (GTK_IS_INVISIBLE (toplevel))
8474 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8481 * gtk_widget_get_screen:
8482 * @widget: a #GtkWidget
8484 * Get the #GdkScreen from the toplevel window associated with
8485 * this widget. This function can only be called after the widget
8486 * has been added to a widget hierarchy with a #GtkWindow
8489 * In general, you should only create screen specific
8490 * resources when a widget has been realized, and you should
8491 * free those resources when the widget is unrealized.
8493 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8498 gtk_widget_get_screen (GtkWidget *widget)
8502 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8504 screen = gtk_widget_get_screen_unchecked (widget);
8511 g_warning (G_STRLOC ": Can't get associated screen"
8512 " for a widget unless it is inside a toplevel GtkWindow\n"
8513 " widget type is %s associated top level type is %s",
8514 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8515 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8517 return gdk_screen_get_default ();
8522 * gtk_widget_has_screen:
8523 * @widget: a #GtkWidget
8525 * Checks whether there is a #GdkScreen is associated with
8526 * this widget. All toplevel widgets have an associated
8527 * screen, and all widgets added into a hierarchy with a toplevel
8528 * window at the top.
8530 * Return value: %TRUE if there is a #GdkScreen associcated
8536 gtk_widget_has_screen (GtkWidget *widget)
8538 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8540 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8544 * gtk_widget_get_display:
8545 * @widget: a #GtkWidget
8547 * Get the #GdkDisplay for the toplevel window associated with
8548 * this widget. This function can only be called after the widget
8549 * has been added to a widget hierarchy with a #GtkWindow at the top.
8551 * In general, you should only create display specific
8552 * resources when a widget has been realized, and you should
8553 * free those resources when the widget is unrealized.
8555 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8560 gtk_widget_get_display (GtkWidget *widget)
8562 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8564 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8568 * gtk_widget_get_root_window:
8569 * @widget: a #GtkWidget
8571 * Get the root window where this widget is located. This function can
8572 * only be called after the widget has been added to a widget
8573 * hierarchy with #GtkWindow at the top.
8575 * The root window is useful for such purposes as creating a popup
8576 * #GdkWindow associated with the window. In general, you should only
8577 * create display specific resources when a widget has been realized,
8578 * and you should free those resources when the widget is unrealized.
8580 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8585 gtk_widget_get_root_window (GtkWidget *widget)
8587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8589 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8593 * gtk_widget_child_focus:
8594 * @widget: a #GtkWidget
8595 * @direction: direction of focus movement
8597 * This function is used by custom widget implementations; if you're
8598 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8599 * to a particular widget, and gtk_container_set_focus_chain() to
8600 * change the focus tab order. So you may want to investigate those
8601 * functions instead.
8603 * gtk_widget_child_focus() is called by containers as the user moves
8604 * around the window using keyboard shortcuts. @direction indicates
8605 * what kind of motion is taking place (up, down, left, right, tab
8606 * forward, tab backward). gtk_widget_child_focus() emits the
8607 * #GtkWidget::focus signal; widgets override the default handler
8608 * for this signal in order to implement appropriate focus behavior.
8610 * The default ::focus handler for a widget should return %TRUE if
8611 * moving in @direction left the focus on a focusable location inside
8612 * that widget, and %FALSE if moving in @direction moved the focus
8613 * outside the widget. If returning %TRUE, widgets normally
8614 * call gtk_widget_grab_focus() to place the focus accordingly;
8615 * if returning %FALSE, they don't modify the current focus location.
8617 * Return value: %TRUE if focus ended up inside @widget
8620 gtk_widget_child_focus (GtkWidget *widget,
8621 GtkDirectionType direction)
8623 gboolean return_val;
8625 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8627 if (!gtk_widget_get_visible (widget) ||
8628 !gtk_widget_is_sensitive (widget))
8631 /* child widgets must set CAN_FOCUS, containers
8632 * don't have to though.
8634 if (!GTK_IS_CONTAINER (widget) &&
8635 !gtk_widget_get_can_focus (widget))
8638 g_signal_emit (widget,
8639 widget_signals[FOCUS],
8641 direction, &return_val);
8647 * gtk_widget_keynav_failed:
8648 * @widget: a #GtkWidget
8649 * @direction: direction of focus movement
8651 * This function should be called whenever keyboard navigation within
8652 * a single widget hits a boundary. The function emits the
8653 * #GtkWidget::keynav-failed signal on the widget and its return
8654 * value should be interpreted in a way similar to the return value of
8655 * gtk_widget_child_focus():
8657 * When %TRUE is returned, stay in the widget, the failed keyboard
8658 * navigation is Ok and/or there is nowhere we can/should move the
8661 * When %FALSE is returned, the caller should continue with keyboard
8662 * navigation outside the widget, e.g. by calling
8663 * gtk_widget_child_focus() on the widget's toplevel.
8665 * The default ::keynav-failed handler returns %TRUE for
8666 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8667 * values of #GtkDirectionType, it looks at the
8668 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8669 * if the setting is %TRUE. This way the entire user interface
8670 * becomes cursor-navigatable on input devices such as mobile phones
8671 * which only have cursor keys but no tab key.
8673 * Whenever the default handler returns %TRUE, it also calls
8674 * gtk_widget_error_bell() to notify the user of the failed keyboard
8677 * A use case for providing an own implementation of ::keynav-failed
8678 * (either by connecting to it or by overriding it) would be a row of
8679 * #GtkEntry widgets where the user should be able to navigate the
8680 * entire row with the cursor keys, as e.g. known from user interfaces
8681 * that require entering license keys.
8683 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8684 * if the emitting widget should try to handle the keyboard
8685 * navigation attempt in its parent container(s).
8690 gtk_widget_keynav_failed (GtkWidget *widget,
8691 GtkDirectionType direction)
8693 gboolean return_val;
8695 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8697 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8698 direction, &return_val);
8704 * gtk_widget_error_bell:
8705 * @widget: a #GtkWidget
8707 * Notifies the user about an input-related error on this widget.
8708 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8709 * gdk_window_beep(), otherwise it does nothing.
8711 * Note that the effect of gdk_window_beep() can be configured in many
8712 * ways, depending on the windowing backend and the desktop environment
8713 * or window manager that is used.
8718 gtk_widget_error_bell (GtkWidget *widget)
8720 GtkWidgetPrivate *priv;
8721 GtkSettings* settings;
8724 g_return_if_fail (GTK_IS_WIDGET (widget));
8726 priv = widget->priv;
8728 settings = gtk_widget_get_settings (widget);
8732 g_object_get (settings,
8733 "gtk-error-bell", &beep,
8736 if (beep && priv->window)
8737 gdk_window_beep (priv->window);
8741 gtk_widget_set_usize_internal (GtkWidget *widget,
8744 GtkQueueResizeFlags flags)
8746 GtkWidgetAuxInfo *aux_info;
8747 gboolean changed = FALSE;
8749 g_object_freeze_notify (G_OBJECT (widget));
8751 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8753 if (width > -2 && aux_info->width != width)
8755 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8756 g_object_notify (G_OBJECT (widget), "width-request");
8757 aux_info->width = width;
8760 if (height > -2 && aux_info->height != height)
8762 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8763 g_object_notify (G_OBJECT (widget), "height-request");
8764 aux_info->height = height;
8768 if (gtk_widget_get_visible (widget) && changed)
8770 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8771 gtk_widget_queue_resize (widget);
8773 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8776 g_object_thaw_notify (G_OBJECT (widget));
8780 * gtk_widget_set_size_request:
8781 * @widget: a #GtkWidget
8782 * @width: width @widget should request, or -1 to unset
8783 * @height: height @widget should request, or -1 to unset
8785 * Sets the minimum size of a widget; that is, the widget's size
8786 * request will be @width by @height. You can use this function to
8787 * force a widget to be either larger or smaller than it normally
8790 * In most cases, gtk_window_set_default_size() is a better choice for
8791 * toplevel windows than this function; setting the default size will
8792 * still allow users to shrink the window. Setting the size request
8793 * will force them to leave the window at least as large as the size
8794 * request. When dealing with window sizes,
8795 * gtk_window_set_geometry_hints() can be a useful function as well.
8797 * Note the inherent danger of setting any fixed size - themes,
8798 * translations into other languages, different fonts, and user action
8799 * can all change the appropriate size for a given widget. So, it's
8800 * basically impossible to hardcode a size that will always be
8803 * The size request of a widget is the smallest size a widget can
8804 * accept while still functioning well and drawing itself correctly.
8805 * However in some strange cases a widget may be allocated less than
8806 * its requested size, and in many cases a widget may be allocated more
8807 * space than it requested.
8809 * If the size request in a given direction is -1 (unset), then
8810 * the "natural" size request of the widget will be used instead.
8812 * Widgets can't actually be allocated a size less than 1 by 1, but
8813 * you can pass 0,0 to this function to mean "as small as possible."
8815 * The size request set here does not include any margin from the
8816 * #GtkWidget properties margin-left, margin-right, margin-top, and
8817 * margin-bottom, but it does include pretty much all other padding
8818 * or border properties set by any subclass of #GtkWidget.
8821 gtk_widget_set_size_request (GtkWidget *widget,
8825 g_return_if_fail (GTK_IS_WIDGET (widget));
8826 g_return_if_fail (width >= -1);
8827 g_return_if_fail (height >= -1);
8834 gtk_widget_set_usize_internal (widget, width, height, 0);
8839 * gtk_widget_get_size_request:
8840 * @widget: a #GtkWidget
8841 * @width: (out) (allow-none): return location for width, or %NULL
8842 * @height: (out) (allow-none): return location for height, or %NULL
8844 * Gets the size request that was explicitly set for the widget using
8845 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8846 * @height indicates that that dimension has not been set explicitly
8847 * and the natural requisition of the widget will be used intead. See
8848 * gtk_widget_set_size_request(). To get the size a widget will
8849 * actually request, call gtk_widget_get_preferred_size() instead of
8853 gtk_widget_get_size_request (GtkWidget *widget,
8857 const GtkWidgetAuxInfo *aux_info;
8859 g_return_if_fail (GTK_IS_WIDGET (widget));
8861 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8864 *width = aux_info->width;
8867 *height = aux_info->height;
8871 * _gtk_widget_override_size_request:
8872 * @widget: a #GtkWidget
8873 * @width: new forced minimum width
8874 * @height: new forced minimum height
8875 * @old_width: location to store previous forced minimum width
8876 * @old_width: location to store previous forced minumum height
8878 * Temporarily establishes a forced minimum size for a widget; this
8879 * is used by GtkWindow when calculating the size to add to the
8880 * window's geometry widget. Cached sizes for the widget and its
8881 * parents are invalidated, so that subsequent calls to the size
8882 * negotiation machinery produce the overriden result, but the
8883 * widget is not queued for relayout or redraw. The old size must
8884 * be restored with _gtk_widget_restore_size_request() or things
8888 _gtk_widget_override_size_request (GtkWidget *widget,
8894 gtk_widget_get_size_request (widget, old_width, old_height);
8895 gtk_widget_set_usize_internal (widget, width, height,
8896 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8900 * _gtk_widget_restore_size_request:
8901 * @widget: a #GtkWidget
8902 * @old_width: saved forced minimum size
8903 * @old_height: saved forced minimum size
8905 * Undoes the operation of_gtk_widget_override_size_request().
8908 _gtk_widget_restore_size_request (GtkWidget *widget,
8912 gtk_widget_set_usize_internal (widget, old_width, old_height,
8913 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8917 * gtk_widget_set_events:
8918 * @widget: a #GtkWidget
8919 * @events: event mask
8921 * Sets the event mask (see #GdkEventMask) for a widget. The event
8922 * mask determines which events a widget will receive. Keep in mind
8923 * that different widgets have different default event masks, and by
8924 * changing the event mask you may disrupt a widget's functionality,
8925 * so be careful. This function must be called while a widget is
8926 * unrealized. Consider gtk_widget_add_events() for widgets that are
8927 * already realized, or if you want to preserve the existing event
8928 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8929 * to get events on those widgets, place them inside a #GtkEventBox
8930 * and receive events on the event box.
8933 gtk_widget_set_events (GtkWidget *widget,
8936 g_return_if_fail (GTK_IS_WIDGET (widget));
8937 g_return_if_fail (!gtk_widget_get_realized (widget));
8939 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8940 GINT_TO_POINTER (events));
8941 g_object_notify (G_OBJECT (widget), "events");
8945 * gtk_widget_set_device_events:
8946 * @widget: a #GtkWidget
8947 * @device: a #GdkDevice
8948 * @events: event mask
8950 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8951 * mask determines which events a widget will receive from @device. Keep
8952 * in mind that different widgets have different default event masks, and by
8953 * changing the event mask you may disrupt a widget's functionality,
8954 * so be careful. This function must be called while a widget is
8955 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8956 * already realized, or if you want to preserve the existing event
8957 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8958 * to get events on those widgets, place them inside a #GtkEventBox
8959 * and receive events on the event box.
8964 gtk_widget_set_device_events (GtkWidget *widget,
8966 GdkEventMask events)
8968 GHashTable *device_events;
8970 g_return_if_fail (GTK_IS_WIDGET (widget));
8971 g_return_if_fail (GDK_IS_DEVICE (device));
8972 g_return_if_fail (!gtk_widget_get_realized (widget));
8974 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8976 if (G_UNLIKELY (!device_events))
8978 device_events = g_hash_table_new (NULL, NULL);
8979 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8980 (GDestroyNotify) g_hash_table_unref);
8983 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8987 gtk_widget_add_events_internal_list (GtkWidget *widget,
8994 for (l = window_list; l != NULL; l = l->next)
8996 GdkWindow *window = l->data;
8999 gdk_window_get_user_data (window, &user_data);
9000 if (user_data == widget)
9005 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9007 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9009 children = gdk_window_get_children (window);
9010 gtk_widget_add_events_internal_list (widget, device, events, children);
9011 g_list_free (children);
9017 gtk_widget_add_events_internal (GtkWidget *widget,
9021 GtkWidgetPrivate *priv = widget->priv;
9024 if (!gtk_widget_get_has_window (widget))
9025 window_list = gdk_window_get_children (priv->window);
9027 window_list = g_list_prepend (NULL, priv->window);
9029 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9031 g_list_free (window_list);
9035 * gtk_widget_add_events:
9036 * @widget: a #GtkWidget
9037 * @events: an event mask, see #GdkEventMask
9039 * Adds the events in the bitfield @events to the event mask for
9040 * @widget. See gtk_widget_set_events() for details.
9043 gtk_widget_add_events (GtkWidget *widget,
9048 g_return_if_fail (GTK_IS_WIDGET (widget));
9050 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9051 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9052 GINT_TO_POINTER (old_events | events));
9054 if (gtk_widget_get_realized (widget))
9055 gtk_widget_add_events_internal (widget, NULL, events);
9057 g_object_notify (G_OBJECT (widget), "events");
9061 * gtk_widget_add_device_events:
9062 * @widget: a #GtkWidget
9063 * @device: a #GdkDevice
9064 * @events: an event mask, see #GdkEventMask
9066 * Adds the device events in the bitfield @events to the event mask for
9067 * @widget. See gtk_widget_set_device_events() for details.
9072 gtk_widget_add_device_events (GtkWidget *widget,
9074 GdkEventMask events)
9076 GdkEventMask old_events;
9077 GHashTable *device_events;
9079 g_return_if_fail (GTK_IS_WIDGET (widget));
9080 g_return_if_fail (GDK_IS_DEVICE (device));
9082 old_events = gtk_widget_get_device_events (widget, device);
9084 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9086 if (G_UNLIKELY (!device_events))
9088 device_events = g_hash_table_new (NULL, NULL);
9089 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9090 (GDestroyNotify) g_hash_table_unref);
9093 g_hash_table_insert (device_events, device,
9094 GUINT_TO_POINTER (old_events | events));
9096 if (gtk_widget_get_realized (widget))
9097 gtk_widget_add_events_internal (widget, device, events);
9099 g_object_notify (G_OBJECT (widget), "events");
9103 * gtk_widget_set_extension_events:
9104 * @widget: a #GtkWidget
9105 * @mode: bitfield of extension events to receive
9107 * Sets the extension events mask to @mode. See #GdkExtensionMode
9108 * and gdk_input_set_extension_events().
9111 gtk_widget_set_extension_events (GtkWidget *widget,
9112 GdkExtensionMode mode)
9114 g_return_if_fail (GTK_IS_WIDGET (widget));
9116 if (gtk_widget_get_realized (widget))
9117 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9119 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9120 GINT_TO_POINTER (mode));
9121 g_object_notify (G_OBJECT (widget), "extension-events");
9125 * gtk_widget_get_toplevel:
9126 * @widget: a #GtkWidget
9128 * This function returns the topmost widget in the container hierarchy
9129 * @widget is a part of. If @widget has no parent widgets, it will be
9130 * returned as the topmost widget. No reference will be added to the
9131 * returned widget; it should not be unreferenced.
9133 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9134 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9136 * %NULL if @widget wasn't inside a toplevel window, and if the
9137 * window was inside a #GtkWindow-derived widget which was in turn
9138 * inside the toplevel #GtkWindow. While the second case may
9139 * seem unlikely, it actually happens when a #GtkPlug is embedded
9140 * inside a #GtkSocket within the same application.
9142 * To reliably find the toplevel #GtkWindow, use
9143 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9144 * is set on the result.
9146 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9147 * if (gtk_widget_is_toplevel (toplevel))
9149 * /* Perform action on toplevel. */
9153 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9154 * if there's no ancestor.
9157 gtk_widget_get_toplevel (GtkWidget *widget)
9159 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9161 while (widget->priv->parent)
9162 widget = widget->priv->parent;
9168 * gtk_widget_get_ancestor:
9169 * @widget: a #GtkWidget
9170 * @widget_type: ancestor type
9172 * Gets the first ancestor of @widget with type @widget_type. For example,
9173 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9174 * the first #GtkBox that's an ancestor of @widget. No reference will be
9175 * added to the returned widget; it should not be unreferenced. See note
9176 * about checking for a toplevel #GtkWindow in the docs for
9177 * gtk_widget_get_toplevel().
9179 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9180 * considers @widget to be an ancestor of itself.
9182 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9185 gtk_widget_get_ancestor (GtkWidget *widget,
9188 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9190 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9191 widget = widget->priv->parent;
9193 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9200 * gtk_widget_set_visual:
9201 * @widget: a #GtkWidget
9202 * @visual: visual to be used or %NULL to unset a previous one
9204 * Sets the visual that should be used for by widget and its children for
9205 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9206 * returned by gdk_widget_get_screen(), so handling the
9207 * #GtkWidget::screen-changed signal is necessary.
9209 * Setting a new @visual will not cause @widget to recreate its windows,
9210 * so you should call this function before @widget is realized.
9213 gtk_widget_set_visual (GtkWidget *widget,
9216 g_return_if_fail (GTK_IS_WIDGET (widget));
9217 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9220 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9223 g_object_set_qdata_full (G_OBJECT (widget),
9225 g_object_ref (visual),
9230 * gtk_widget_get_visual:
9231 * @widget: a #GtkWidget
9233 * Gets the visual that will be used to render @widget.
9235 * Return value: (transfer none): the visual for @widget
9238 gtk_widget_get_visual (GtkWidget *widget)
9244 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9246 if (gtk_widget_get_has_window (widget) &&
9247 widget->priv->window)
9248 return gdk_window_get_visual (widget->priv->window);
9250 screen = gtk_widget_get_screen (widget);
9252 for (w = widget; w != NULL; w = w->priv->parent)
9254 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9257 if (gdk_visual_get_screen (visual) == screen)
9260 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9261 gtk_widget_get_name (widget));
9265 return gdk_screen_get_system_visual (screen);
9269 * gtk_widget_get_settings:
9270 * @widget: a #GtkWidget
9272 * Gets the settings object holding the settings (global property
9273 * settings, RC file information, etc) used for this widget.
9275 * Note that this function can only be called when the #GtkWidget
9276 * is attached to a toplevel, since the settings object is specific
9277 * to a particular #GdkScreen.
9279 * Return value: (transfer none): the relevant #GtkSettings object
9282 gtk_widget_get_settings (GtkWidget *widget)
9284 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9286 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9290 * gtk_widget_get_events:
9291 * @widget: a #GtkWidget
9293 * Returns the event mask for the widget (a bitfield containing flags
9294 * from the #GdkEventMask enumeration). These are the events that the widget
9297 * Return value: event mask for @widget
9300 gtk_widget_get_events (GtkWidget *widget)
9302 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9304 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9308 * gtk_widget_get_device_events:
9309 * @widget: a #GtkWidget
9310 * @device: a #GdkDevice
9312 * Returns the events mask for the widget corresponding to an specific device. These
9313 * are the events that the widget will receive when @device operates on it.
9315 * Returns: device event mask for @widget
9320 gtk_widget_get_device_events (GtkWidget *widget,
9323 GHashTable *device_events;
9325 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9326 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9328 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9333 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9337 * gtk_widget_get_extension_events:
9338 * @widget: a #GtkWidget
9340 * Retrieves the extension events the widget will receive; see
9341 * gdk_input_set_extension_events().
9343 * Return value: extension events for @widget
9346 gtk_widget_get_extension_events (GtkWidget *widget)
9348 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9350 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9354 * gtk_widget_get_pointer:
9355 * @widget: a #GtkWidget
9356 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9357 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9359 * Obtains the location of the mouse pointer in widget coordinates.
9360 * Widget coordinates are a bit odd; for historical reasons, they are
9361 * defined as @widget->window coordinates for widgets that are not
9362 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9363 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9366 gtk_widget_get_pointer (GtkWidget *widget,
9370 GtkWidgetPrivate *priv;
9372 g_return_if_fail (GTK_IS_WIDGET (widget));
9374 priv = widget->priv;
9381 if (gtk_widget_get_realized (widget))
9383 gdk_window_get_pointer (priv->window, x, y, NULL);
9385 if (!gtk_widget_get_has_window (widget))
9388 *x -= priv->allocation.x;
9390 *y -= priv->allocation.y;
9396 * gtk_widget_is_ancestor:
9397 * @widget: a #GtkWidget
9398 * @ancestor: another #GtkWidget
9400 * Determines whether @widget is somewhere inside @ancestor, possibly with
9401 * intermediate containers.
9403 * Return value: %TRUE if @ancestor contains @widget as a child,
9404 * grandchild, great grandchild, etc.
9407 gtk_widget_is_ancestor (GtkWidget *widget,
9408 GtkWidget *ancestor)
9410 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9411 g_return_val_if_fail (ancestor != NULL, FALSE);
9415 if (widget->priv->parent == ancestor)
9417 widget = widget->priv->parent;
9423 static GQuark quark_composite_name = 0;
9426 * gtk_widget_set_composite_name:
9427 * @widget: a #GtkWidget.
9428 * @name: the name to set
9430 * Sets a widgets composite name. The widget must be
9431 * a composite child of its parent; see gtk_widget_push_composite_child().
9434 gtk_widget_set_composite_name (GtkWidget *widget,
9437 g_return_if_fail (GTK_IS_WIDGET (widget));
9438 g_return_if_fail (widget->priv->composite_child);
9439 g_return_if_fail (name != NULL);
9441 if (!quark_composite_name)
9442 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9444 g_object_set_qdata_full (G_OBJECT (widget),
9445 quark_composite_name,
9451 * gtk_widget_get_composite_name:
9452 * @widget: a #GtkWidget
9454 * Obtains the composite name of a widget.
9456 * Returns: the composite name of @widget, or %NULL if @widget is not
9457 * a composite child. The string should be freed when it is no
9461 gtk_widget_get_composite_name (GtkWidget *widget)
9463 GtkWidgetPrivate *priv;
9465 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9467 priv = widget->priv;
9469 if (widget->priv->composite_child && priv->parent)
9470 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9477 * gtk_widget_push_composite_child:
9479 * Makes all newly-created widgets as composite children until
9480 * the corresponding gtk_widget_pop_composite_child() call.
9482 * A composite child is a child that's an implementation detail of the
9483 * container it's inside and should not be visible to people using the
9484 * container. Composite children aren't treated differently by GTK (but
9485 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9486 * builders might want to treat them in a different way.
9488 * Here is a simple example:
9490 * gtk_widget_push_composite_child ();
9491 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9492 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9493 * gtk_widget_pop_composite_child ();
9494 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9495 * GTK_WIDGET (scrolled_window));
9496 * g_object_ref (scrolled_window->hscrollbar);
9500 gtk_widget_push_composite_child (void)
9502 composite_child_stack++;
9506 * gtk_widget_pop_composite_child:
9508 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9511 gtk_widget_pop_composite_child (void)
9513 if (composite_child_stack)
9514 composite_child_stack--;
9518 gtk_widget_emit_direction_changed (GtkWidget *widget,
9519 GtkTextDirection old_dir)
9521 gtk_widget_update_pango_context (widget);
9523 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9527 * gtk_widget_set_direction:
9528 * @widget: a #GtkWidget
9529 * @dir: the new direction
9531 * Sets the reading direction on a particular widget. This direction
9532 * controls the primary direction for widgets containing text,
9533 * and also the direction in which the children of a container are
9534 * packed. The ability to set the direction is present in order
9535 * so that correct localization into languages with right-to-left
9536 * reading directions can be done. Generally, applications will
9537 * let the default reading direction present, except for containers
9538 * where the containers are arranged in an order that is explicitely
9539 * visual rather than logical (such as buttons for text justification).
9541 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9542 * set by gtk_widget_set_default_direction() will be used.
9545 gtk_widget_set_direction (GtkWidget *widget,
9546 GtkTextDirection dir)
9548 GtkTextDirection old_dir;
9550 g_return_if_fail (GTK_IS_WIDGET (widget));
9551 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9553 old_dir = gtk_widget_get_direction (widget);
9555 widget->priv->direction = dir;
9557 if (old_dir != gtk_widget_get_direction (widget))
9558 gtk_widget_emit_direction_changed (widget, old_dir);
9562 * gtk_widget_get_direction:
9563 * @widget: a #GtkWidget
9565 * Gets the reading direction for a particular widget. See
9566 * gtk_widget_set_direction().
9568 * Return value: the reading direction for the widget.
9571 gtk_widget_get_direction (GtkWidget *widget)
9573 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9575 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9576 return gtk_default_direction;
9578 return widget->priv->direction;
9582 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9584 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9586 g_object_ref (widget);
9588 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9589 gtk_widget_emit_direction_changed (widget, old_dir);
9591 if (GTK_IS_CONTAINER (widget))
9592 gtk_container_forall (GTK_CONTAINER (widget),
9593 gtk_widget_set_default_direction_recurse,
9596 g_object_unref (widget);
9600 * gtk_widget_set_default_direction:
9601 * @dir: the new default direction. This cannot be
9602 * %GTK_TEXT_DIR_NONE.
9604 * Sets the default reading direction for widgets where the
9605 * direction has not been explicitly set by gtk_widget_set_direction().
9608 gtk_widget_set_default_direction (GtkTextDirection dir)
9610 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9612 if (dir != gtk_default_direction)
9614 GList *toplevels, *tmp_list;
9615 GtkTextDirection old_dir = gtk_default_direction;
9617 gtk_default_direction = dir;
9619 tmp_list = toplevels = gtk_window_list_toplevels ();
9620 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9624 gtk_widget_set_default_direction_recurse (tmp_list->data,
9625 GUINT_TO_POINTER (old_dir));
9626 g_object_unref (tmp_list->data);
9627 tmp_list = tmp_list->next;
9630 g_list_free (toplevels);
9635 * gtk_widget_get_default_direction:
9637 * Obtains the current default reading direction. See
9638 * gtk_widget_set_default_direction().
9640 * Return value: the current default direction.
9643 gtk_widget_get_default_direction (void)
9645 return gtk_default_direction;
9649 gtk_widget_dispose (GObject *object)
9651 GtkWidget *widget = GTK_WIDGET (object);
9652 GtkWidgetPrivate *priv = widget->priv;
9655 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9656 else if (gtk_widget_get_visible (widget))
9657 gtk_widget_hide (widget);
9659 priv->visible = FALSE;
9660 if (gtk_widget_get_realized (widget))
9661 gtk_widget_unrealize (widget);
9663 if (!priv->in_destruction)
9665 priv->in_destruction = TRUE;
9666 g_signal_emit (object, widget_signals[DESTROY], 0);
9667 priv->in_destruction = FALSE;
9670 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9674 gtk_widget_real_destroy (GtkWidget *object)
9676 /* gtk_object_destroy() will already hold a refcount on object */
9677 GtkWidget *widget = GTK_WIDGET (object);
9678 GtkWidgetPrivate *priv = widget->priv;
9680 /* wipe accelerator closures (keep order) */
9681 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9682 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9684 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9685 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9687 gtk_grab_remove (widget);
9689 g_object_unref (priv->style);
9690 priv->style = gtk_widget_get_default_style ();
9691 g_object_ref (priv->style);
9695 gtk_widget_finalize (GObject *object)
9697 GtkWidget *widget = GTK_WIDGET (object);
9698 GtkWidgetPrivate *priv = widget->priv;
9699 GtkWidgetAuxInfo *aux_info;
9700 GtkAccessible *accessible;
9702 gtk_grab_remove (widget);
9704 g_object_unref (priv->style);
9707 g_free (priv->name);
9709 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9711 gtk_widget_aux_info_destroy (aux_info);
9713 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9715 g_object_unref (accessible);
9717 if (g_object_is_floating (object))
9718 g_warning ("A floating object was finalized. This means that someone\n"
9719 "called g_object_unref() on an object that had only a floating\n"
9720 "reference; the initial floating reference is not owned by anyone\n"
9721 "and must be removed with g_object_ref_sink().");
9723 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9726 /*****************************************
9727 * gtk_widget_real_map:
9732 *****************************************/
9735 gtk_widget_real_map (GtkWidget *widget)
9737 GtkWidgetPrivate *priv = widget->priv;
9739 g_assert (gtk_widget_get_realized (widget));
9741 if (!gtk_widget_get_mapped (widget))
9743 gtk_widget_set_mapped (widget, TRUE);
9745 if (gtk_widget_get_has_window (widget))
9746 gdk_window_show (priv->window);
9750 /*****************************************
9751 * gtk_widget_real_unmap:
9756 *****************************************/
9759 gtk_widget_real_unmap (GtkWidget *widget)
9761 GtkWidgetPrivate *priv = widget->priv;
9763 if (gtk_widget_get_mapped (widget))
9765 gtk_widget_set_mapped (widget, FALSE);
9767 if (gtk_widget_get_has_window (widget))
9768 gdk_window_hide (priv->window);
9772 /*****************************************
9773 * gtk_widget_real_realize:
9778 *****************************************/
9781 gtk_widget_real_realize (GtkWidget *widget)
9783 GtkWidgetPrivate *priv = widget->priv;
9785 g_assert (!gtk_widget_get_has_window (widget));
9787 gtk_widget_set_realized (widget, TRUE);
9790 priv->window = gtk_widget_get_parent_window (widget);
9791 g_object_ref (priv->window);
9793 priv->style = gtk_style_attach (priv->style, priv->window);
9796 /*****************************************
9797 * gtk_widget_real_unrealize:
9802 *****************************************/
9805 gtk_widget_real_unrealize (GtkWidget *widget)
9807 GtkWidgetPrivate *priv = widget->priv;
9809 if (gtk_widget_get_mapped (widget))
9810 gtk_widget_real_unmap (widget);
9812 gtk_widget_set_mapped (widget, FALSE);
9814 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9817 /* We must do unrealize child widget BEFORE container widget.
9818 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9819 * So, unrealizing container widget bofore its children causes the problem
9820 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9823 if (GTK_IS_CONTAINER (widget))
9824 gtk_container_forall (GTK_CONTAINER (widget),
9825 (GtkCallback) gtk_widget_unrealize,
9828 gtk_style_detach (priv->style);
9829 if (gtk_widget_get_has_window (widget))
9831 gdk_window_set_user_data (priv->window, NULL);
9832 gdk_window_destroy (priv->window);
9833 priv->window = NULL;
9837 g_object_unref (priv->window);
9838 priv->window = NULL;
9841 gtk_selection_remove_all (widget);
9843 gtk_widget_set_realized (widget, FALSE);
9847 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9848 GtkOrientation orientation,
9852 const GtkWidgetAuxInfo *aux_info;
9854 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9856 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9857 aux_info->width > 0)
9859 *minimum_size = MAX (*minimum_size, aux_info->width);
9861 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9862 aux_info->height > 0)
9864 *minimum_size = MAX (*minimum_size, aux_info->height);
9867 /* Fix it if set_size_request made natural size smaller than min size.
9868 * This would also silently fix broken widgets, but we warn about them
9869 * in gtksizerequest.c when calling their size request vfuncs.
9871 *natural_size = MAX (*natural_size, *minimum_size);
9873 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9875 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9876 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9880 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9881 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9886 * _gtk_widget_peek_request_cache:
9888 * Returns the address of the widget's request cache (strictly for
9889 * internal use in gtksizerequest.c)
9891 * Return value: the address of @widget's size request cache.
9894 _gtk_widget_peek_request_cache (GtkWidget *widget)
9896 /* Don't bother slowing things down with the return_if_fail guards here */
9897 return &widget->priv->requests;
9901 * _gtk_widget_set_device_window:
9902 * @widget: a #GtkWidget.
9903 * @device: a #GdkDevice.
9904 * @window: the new device window.
9906 * Sets pointer window for @widget and @device. Does not ref @window.
9907 * Actually stores it on the #GdkScreen, but you don't need to know that.
9910 _gtk_widget_set_device_window (GtkWidget *widget,
9914 GtkWidgetPrivate *priv;
9916 GHashTable *device_window;
9918 g_return_if_fail (GTK_IS_WIDGET (widget));
9919 g_return_if_fail (GDK_IS_DEVICE (device));
9920 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9922 priv = widget->priv;
9924 if (!gtk_widget_get_realized (widget))
9927 screen = gdk_window_get_screen (priv->window);
9928 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9930 if (G_UNLIKELY (!device_window))
9932 device_window = g_hash_table_new (NULL, NULL);
9933 g_object_set_qdata_full (G_OBJECT (screen),
9934 quark_pointer_window,
9936 (GDestroyNotify) g_hash_table_destroy);
9940 g_hash_table_insert (device_window, device, window);
9942 g_hash_table_remove (device_window, device);
9946 * _gtk_widget_get_device_window:
9947 * @widget: a #GtkWidget.
9948 * @device: a #GdkDevice.
9950 * Return value: the device window set on the #GdkScreen @widget is attached
9954 _gtk_widget_get_device_window (GtkWidget *widget,
9957 GtkWidgetPrivate *priv;
9959 GHashTable *device_window;
9963 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9964 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9966 priv = widget->priv;
9968 if (!gtk_widget_get_realized (widget))
9971 screen = gdk_window_get_screen (priv->window);
9972 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9974 if (G_UNLIKELY (!device_window))
9977 window = g_hash_table_lookup (device_window, device);
9982 gdk_window_get_user_data (window, (gpointer *) &w);
9991 * _gtk_widget_list_devices:
9992 * @widget: a #GtkWidget.
9994 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9995 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9999 _gtk_widget_list_devices (GtkWidget *widget)
10001 GtkWidgetPrivate *priv;
10003 GHashTableIter iter;
10004 GHashTable *device_window;
10005 GList *devices = NULL;
10006 gpointer key, value;
10008 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10010 priv = widget->priv;
10012 if (!gtk_widget_get_realized (widget))
10015 screen = gdk_window_get_screen (priv->window);
10016 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10018 if (G_UNLIKELY (!device_window))
10021 g_hash_table_iter_init (&iter, device_window);
10023 while (g_hash_table_iter_next (&iter, &key, &value))
10025 GdkDevice *device = key;
10026 GdkWindow *window = value;
10031 gdk_window_get_user_data (window, (gpointer *) &w);
10034 devices = g_list_prepend (devices, device);
10042 synth_crossing (GtkWidget *widget,
10046 GdkCrossingMode mode,
10047 GdkNotifyType detail)
10051 event = gdk_event_new (type);
10053 event->crossing.window = g_object_ref (window);
10054 event->crossing.send_event = TRUE;
10055 event->crossing.subwindow = g_object_ref (window);
10056 event->crossing.time = GDK_CURRENT_TIME;
10057 event->crossing.x = event->crossing.y = 0;
10058 event->crossing.x_root = event->crossing.y_root = 0;
10059 event->crossing.mode = mode;
10060 event->crossing.detail = detail;
10061 event->crossing.focus = FALSE;
10062 event->crossing.state = 0;
10063 gdk_event_set_device (event, device);
10066 widget = gtk_get_event_widget (event);
10069 gtk_widget_event_internal (widget, event);
10071 gdk_event_free (event);
10075 * _gtk_widget_synthesize_crossing:
10076 * @from: the #GtkWidget the virtual pointer is leaving.
10077 * @to: the #GtkWidget the virtual pointer is moving to.
10078 * @mode: the #GdkCrossingMode to place on the synthesized events.
10080 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10082 * The real pointer window is the window that most recently received an enter notify
10083 * event. Windows that don't select for crossing events can't become the real
10084 * poiner window. The real pointer widget that owns the real pointer window. The
10085 * effective pointer window is the same as the real pointer window unless the real
10086 * pointer widget is either insensitive or there is a grab on a widget that is not
10087 * an ancestor of the real pointer widget (in which case the effective pointer
10088 * window should be the root window).
10090 * When the effective pointer window is the same as the real poiner window, we
10091 * receive crossing events from the windowing system. When the effective pointer
10092 * window changes to become different from the real pointer window we synthesize
10093 * crossing events, attempting to follow X protocol rules:
10095 * When the root window becomes the effective pointer window:
10096 * - leave notify on real pointer window, detail Ancestor
10097 * - leave notify on all of its ancestors, detail Virtual
10098 * - enter notify on root window, detail Inferior
10100 * When the root window ceases to be the effective pointer window:
10101 * - leave notify on root window, detail Inferior
10102 * - enter notify on all ancestors of real pointer window, detail Virtual
10103 * - enter notify on real pointer window, detail Ancestor
10106 _gtk_widget_synthesize_crossing (GtkWidget *from,
10109 GdkCrossingMode mode)
10111 GdkWindow *from_window = NULL, *to_window = NULL;
10113 g_return_if_fail (from != NULL || to != NULL);
10117 from_window = _gtk_widget_get_device_window (from, device);
10120 from_window = from->priv->window;
10125 to_window = _gtk_widget_get_device_window (to, device);
10128 to_window = to->priv->window;
10131 if (from_window == NULL && to_window == NULL)
10133 else if (from_window != NULL && to_window == NULL)
10135 GList *from_ancestors = NULL, *list;
10136 GdkWindow *from_ancestor = from_window;
10138 while (from_ancestor != NULL)
10140 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10141 if (from_ancestor == NULL)
10143 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10146 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10147 device, mode, GDK_NOTIFY_ANCESTOR);
10148 for (list = g_list_last (from_ancestors); list; list = list->prev)
10150 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10151 device, mode, GDK_NOTIFY_VIRTUAL);
10154 /* XXX: enter/inferior on root window? */
10156 g_list_free (from_ancestors);
10158 else if (from_window == NULL && to_window != NULL)
10160 GList *to_ancestors = NULL, *list;
10161 GdkWindow *to_ancestor = to_window;
10163 while (to_ancestor != NULL)
10165 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10166 if (to_ancestor == NULL)
10168 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10171 /* XXX: leave/inferior on root window? */
10173 for (list = to_ancestors; list; list = list->next)
10175 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10176 device, mode, GDK_NOTIFY_VIRTUAL);
10178 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10179 device, mode, GDK_NOTIFY_ANCESTOR);
10181 g_list_free (to_ancestors);
10183 else if (from_window == to_window)
10187 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10188 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10190 while (from_ancestor != NULL || to_ancestor != NULL)
10192 if (from_ancestor != NULL)
10194 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10195 if (from_ancestor == to_window)
10198 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10200 if (to_ancestor != NULL)
10202 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10203 if (to_ancestor == from_window)
10206 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10209 if (to_ancestor == from_window)
10211 if (mode != GDK_CROSSING_GTK_UNGRAB)
10212 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10213 device, mode, GDK_NOTIFY_INFERIOR);
10214 for (list = to_ancestors; list; list = list->next)
10215 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10216 device, mode, GDK_NOTIFY_VIRTUAL);
10217 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10218 device, mode, GDK_NOTIFY_ANCESTOR);
10220 else if (from_ancestor == to_window)
10222 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10223 device, mode, GDK_NOTIFY_ANCESTOR);
10224 for (list = g_list_last (from_ancestors); list; list = list->prev)
10226 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10227 device, mode, GDK_NOTIFY_VIRTUAL);
10229 if (mode != GDK_CROSSING_GTK_GRAB)
10230 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10231 device, mode, GDK_NOTIFY_INFERIOR);
10235 while (from_ancestors != NULL && to_ancestors != NULL
10236 && from_ancestors->data == to_ancestors->data)
10238 from_ancestors = g_list_delete_link (from_ancestors,
10240 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10243 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10244 device, mode, GDK_NOTIFY_NONLINEAR);
10246 for (list = g_list_last (from_ancestors); list; list = list->prev)
10248 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10249 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10251 for (list = to_ancestors; list; list = list->next)
10253 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10254 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10256 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10257 device, mode, GDK_NOTIFY_NONLINEAR);
10259 g_list_free (from_ancestors);
10260 g_list_free (to_ancestors);
10265 gtk_widget_propagate_state (GtkWidget *widget,
10266 GtkStateData *data)
10268 GtkWidgetPrivate *priv = widget->priv;
10269 guint8 old_state = gtk_widget_get_state (widget);
10270 guint8 old_saved_state = priv->saved_state;
10272 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10273 * parent_sensitive==TRUE on a sensitive widget
10277 priv->parent_sensitive = data->parent_sensitive;
10279 if (gtk_widget_is_sensitive (widget))
10281 if (data->state_restoration)
10282 priv->state = priv->saved_state;
10284 priv->state = data->state;
10288 if (!data->state_restoration)
10290 if (data->state != GTK_STATE_INSENSITIVE)
10291 priv->saved_state = data->state;
10293 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10294 priv->saved_state = gtk_widget_get_state (widget);
10295 priv->state = GTK_STATE_INSENSITIVE;
10298 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10302 window = gtk_widget_get_toplevel (widget);
10303 if (window && gtk_widget_is_toplevel (window))
10304 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10307 if (old_state != gtk_widget_get_state (widget) ||
10308 old_saved_state != priv->saved_state)
10310 g_object_ref (widget);
10312 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10313 gtk_grab_remove (widget);
10315 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10317 if (!priv->shadowed)
10319 GList *event_windows = NULL;
10320 GList *devices, *d;
10322 devices = _gtk_widget_list_devices (widget);
10324 for (d = devices; d; d = d->next)
10330 window = _gtk_widget_get_device_window (widget, device);
10332 /* Do not propagate more than once to the
10333 * same window if non-multidevice aware.
10335 if (!gdk_window_get_support_multidevice (window) &&
10336 g_list_find (event_windows, window))
10339 if (!gtk_widget_is_sensitive (widget))
10340 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10341 GDK_CROSSING_STATE_CHANGED);
10342 else if (old_state == GTK_STATE_INSENSITIVE)
10343 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10344 GDK_CROSSING_STATE_CHANGED);
10346 event_windows = g_list_prepend (event_windows, window);
10349 g_list_free (event_windows);
10350 g_list_free (devices);
10353 if (GTK_IS_CONTAINER (widget))
10355 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10356 if (data->use_forall)
10357 gtk_container_forall (GTK_CONTAINER (widget),
10358 (GtkCallback) gtk_widget_propagate_state,
10361 gtk_container_foreach (GTK_CONTAINER (widget),
10362 (GtkCallback) gtk_widget_propagate_state,
10365 g_object_unref (widget);
10369 static const GtkWidgetAuxInfo default_aux_info = {
10377 * _gtk_widget_get_aux_info:
10378 * @widget: a #GtkWidget
10379 * @create: if %TRUE, create the structure if it doesn't exist
10381 * Get the #GtkWidgetAuxInfo structure for the widget.
10383 * Return value: the #GtkAuxInfo structure for the widget, or
10384 * %NULL if @create is %FALSE and one doesn't already exist.
10387 _gtk_widget_get_aux_info (GtkWidget *widget,
10390 GtkWidgetAuxInfo *aux_info;
10392 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10393 if (!aux_info && create)
10395 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10397 *aux_info = default_aux_info;
10399 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10405 static const GtkWidgetAuxInfo*
10406 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10408 GtkWidgetAuxInfo *aux_info;
10410 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10411 if (aux_info == NULL)
10413 return &default_aux_info;
10421 /*****************************************
10422 * gtk_widget_aux_info_destroy:
10427 *****************************************/
10430 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10432 g_slice_free (GtkWidgetAuxInfo, aux_info);
10436 * gtk_widget_shape_combine_region:
10437 * @widget: a #GtkWidget
10438 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10440 * Sets a shape for this widget's GDK window. This allows for
10441 * transparent windows etc., see gdk_window_shape_combine_region()
10442 * for more information.
10447 gtk_widget_shape_combine_region (GtkWidget *widget,
10448 cairo_region_t *region)
10450 GtkWidgetPrivate *priv;
10452 g_return_if_fail (GTK_IS_WIDGET (widget));
10453 /* set_shape doesn't work on widgets without gdk window */
10454 g_return_if_fail (gtk_widget_get_has_window (widget));
10456 priv = widget->priv;
10458 if (region == NULL)
10460 priv->has_shape_mask = FALSE;
10463 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10465 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10469 priv->has_shape_mask = TRUE;
10471 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10472 cairo_region_copy (region),
10473 (GDestroyNotify) cairo_region_destroy);
10475 /* set shape if widget has a gdk window already.
10476 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10479 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10484 * gtk_widget_input_shape_combine_region:
10485 * @widget: a #GtkWidget
10486 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10488 * Sets an input shape for this widget's GDK window. This allows for
10489 * windows which react to mouse click in a nonrectangular region, see
10490 * gdk_window_input_shape_combine_region() for more information.
10495 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10496 cairo_region_t *region)
10498 GtkWidgetPrivate *priv;
10500 g_return_if_fail (GTK_IS_WIDGET (widget));
10501 /* set_shape doesn't work on widgets without gdk window */
10502 g_return_if_fail (gtk_widget_get_has_window (widget));
10504 priv = widget->priv;
10506 if (region == NULL)
10509 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10511 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10515 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10516 cairo_region_copy (region),
10517 (GDestroyNotify) cairo_region_destroy);
10519 /* set shape if widget has a gdk window already.
10520 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10523 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10529 gtk_reset_shapes_recurse (GtkWidget *widget,
10535 gdk_window_get_user_data (window, &data);
10536 if (data != widget)
10539 gdk_window_shape_combine_region (window, NULL, 0, 0);
10540 for (list = gdk_window_peek_children (window); list; list = list->next)
10541 gtk_reset_shapes_recurse (widget, list->data);
10545 * gtk_widget_reset_shapes:
10546 * @widget: a #GtkWidget
10548 * Recursively resets the shape on this widget and its descendants.
10551 gtk_widget_reset_shapes (GtkWidget *widget)
10553 GtkWidgetPrivate *priv;
10555 g_return_if_fail (GTK_IS_WIDGET (widget));
10556 g_return_if_fail (gtk_widget_get_realized (widget));
10558 priv = widget->priv;
10560 if (!priv->has_shape_mask)
10561 gtk_reset_shapes_recurse (widget, priv->window);
10564 /* style properties
10568 * gtk_widget_class_install_style_property_parser:
10569 * @klass: a #GtkWidgetClass
10570 * @pspec: the #GParamSpec for the style property
10571 * @parser: the parser for the style property
10573 * Installs a style property on a widget class.
10576 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10578 GtkRcPropertyParser parser)
10580 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10581 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10582 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10583 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10585 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10587 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10588 G_OBJECT_CLASS_NAME (klass),
10593 g_param_spec_ref_sink (pspec);
10594 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10595 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10599 * gtk_widget_class_install_style_property:
10600 * @klass: a #GtkWidgetClass
10601 * @pspec: the #GParamSpec for the property
10603 * Installs a style property on a widget class. The parser for the
10604 * style property is determined by the value type of @pspec.
10607 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10610 GtkRcPropertyParser parser;
10612 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10613 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10615 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10617 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10621 * gtk_widget_class_find_style_property:
10622 * @klass: a #GtkWidgetClass
10623 * @property_name: the name of the style property to find
10624 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10625 * style property with that name.
10627 * Finds a style property of a widget class by name.
10632 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10633 const gchar *property_name)
10635 g_return_val_if_fail (property_name != NULL, NULL);
10637 return g_param_spec_pool_lookup (style_property_spec_pool,
10639 G_OBJECT_CLASS_TYPE (klass),
10644 * gtk_widget_class_list_style_properties:
10645 * @klass: a #GtkWidgetClass
10646 * @n_properties: location to return the number of style properties found
10647 * @returns: an newly allocated array of #GParamSpec*. The array must
10648 * be freed with g_free().
10650 * Returns all style properties of a widget class.
10655 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10656 guint *n_properties)
10658 GParamSpec **pspecs;
10661 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10662 G_OBJECT_CLASS_TYPE (klass),
10671 * gtk_widget_style_get_property:
10672 * @widget: a #GtkWidget
10673 * @property_name: the name of a style property
10674 * @value: location to return the property value
10676 * Gets the value of a style property of @widget.
10679 gtk_widget_style_get_property (GtkWidget *widget,
10680 const gchar *property_name,
10685 g_return_if_fail (GTK_IS_WIDGET (widget));
10686 g_return_if_fail (property_name != NULL);
10687 g_return_if_fail (G_IS_VALUE (value));
10689 g_object_ref (widget);
10690 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10692 G_OBJECT_TYPE (widget),
10695 g_warning ("%s: widget class `%s' has no property named `%s'",
10697 G_OBJECT_TYPE_NAME (widget),
10701 GtkStyleContext *context;
10702 const GValue *peek_value;
10704 context = gtk_widget_get_style_context (widget);
10705 peek_value = _gtk_style_context_peek_style_property (context,
10706 G_OBJECT_TYPE (widget),
10709 /* auto-conversion of the caller's value type
10711 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10712 g_value_copy (peek_value, value);
10713 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10714 g_value_transform (peek_value, value);
10716 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10718 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10719 G_VALUE_TYPE_NAME (value));
10721 g_object_unref (widget);
10725 * gtk_widget_style_get_valist:
10726 * @widget: a #GtkWidget
10727 * @first_property_name: the name of the first property to get
10728 * @var_args: a <type>va_list</type> of pairs of property names and
10729 * locations to return the property values, starting with the location
10730 * for @first_property_name.
10732 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10736 gtk_widget_style_get_valist (GtkWidget *widget,
10737 const gchar *first_property_name,
10740 GtkStyleContext *context;
10743 g_return_if_fail (GTK_IS_WIDGET (widget));
10745 g_object_ref (widget);
10746 context = gtk_widget_get_style_context (widget);
10748 name = first_property_name;
10751 const GValue *peek_value;
10755 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10757 G_OBJECT_TYPE (widget),
10761 g_warning ("%s: widget class `%s' has no property named `%s'",
10763 G_OBJECT_TYPE_NAME (widget),
10767 /* style pspecs are always readable so we can spare that check here */
10769 peek_value = _gtk_style_context_peek_style_property (context,
10770 G_OBJECT_TYPE (widget),
10773 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10776 g_warning ("%s: %s", G_STRLOC, error);
10781 name = va_arg (var_args, gchar*);
10784 g_object_unref (widget);
10788 * gtk_widget_style_get:
10789 * @widget: a #GtkWidget
10790 * @first_property_name: the name of the first property to get
10791 * @Varargs: pairs of property names and locations to
10792 * return the property values, starting with the location for
10793 * @first_property_name, terminated by %NULL.
10795 * Gets the values of a multiple style properties of @widget.
10798 gtk_widget_style_get (GtkWidget *widget,
10799 const gchar *first_property_name,
10804 g_return_if_fail (GTK_IS_WIDGET (widget));
10806 va_start (var_args, first_property_name);
10807 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10813 * @widget: a #GtkWidget
10814 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10815 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10816 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10818 * Obtains the full path to @widget. The path is simply the name of a
10819 * widget and all its parents in the container hierarchy, separated by
10820 * periods. The name of a widget comes from
10821 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10822 * in gtkrc configuration files. Widget names are the type of the
10823 * widget by default (e.g. "GtkButton") or can be set to an
10824 * application-specific value with gtk_widget_set_name(). By setting
10825 * the name of a widget, you allow users or theme authors to apply
10826 * styles to that specific widget in their gtkrc
10827 * file. @path_reversed_p fills in the path in reverse order,
10828 * i.e. starting with @widget's name instead of starting with the name
10829 * of @widget's outermost ancestor.
10832 gtk_widget_path (GtkWidget *widget,
10833 guint *path_length,
10835 gchar **path_reversed)
10837 static gchar *rev_path = NULL;
10838 static guint tmp_path_len = 0;
10841 g_return_if_fail (GTK_IS_WIDGET (widget));
10846 const gchar *string;
10851 string = gtk_widget_get_name (widget);
10852 l = strlen (string);
10853 while (tmp_path_len <= len + l + 1)
10855 tmp_path_len += INIT_PATH_SIZE;
10856 rev_path = g_realloc (rev_path, tmp_path_len);
10858 s = string + l - 1;
10859 d = rev_path + len;
10860 while (s >= string)
10864 widget = widget->priv->parent;
10867 rev_path[len++] = '.';
10869 rev_path[len++] = 0;
10874 *path_length = len - 1;
10876 *path_reversed = g_strdup (rev_path);
10879 *path = g_strdup (rev_path);
10880 g_strreverse (*path);
10885 * gtk_widget_class_path:
10886 * @widget: a #GtkWidget
10887 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10888 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10889 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10892 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10893 * never uses a custom name set with gtk_widget_set_name().
10897 gtk_widget_class_path (GtkWidget *widget,
10898 guint *path_length,
10900 gchar **path_reversed)
10902 static gchar *rev_path = NULL;
10903 static guint tmp_path_len = 0;
10906 g_return_if_fail (GTK_IS_WIDGET (widget));
10911 const gchar *string;
10916 string = g_type_name (G_OBJECT_TYPE (widget));
10917 l = strlen (string);
10918 while (tmp_path_len <= len + l + 1)
10920 tmp_path_len += INIT_PATH_SIZE;
10921 rev_path = g_realloc (rev_path, tmp_path_len);
10923 s = string + l - 1;
10924 d = rev_path + len;
10925 while (s >= string)
10929 widget = widget->priv->parent;
10932 rev_path[len++] = '.';
10934 rev_path[len++] = 0;
10939 *path_length = len - 1;
10941 *path_reversed = g_strdup (rev_path);
10944 *path = g_strdup (rev_path);
10945 g_strreverse (*path);
10950 * gtk_requisition_new:
10952 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10954 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10955 * be freed with gtk_requisition_free().
10960 gtk_requisition_new (void)
10962 return g_slice_new0 (GtkRequisition);
10966 * gtk_requisition_copy:
10967 * @requisition: a #GtkRequisition
10969 * Copies a #GtkRequisition.
10971 * Returns: a copy of @requisition
10974 gtk_requisition_copy (const GtkRequisition *requisition)
10976 return g_slice_dup (GtkRequisition, requisition);
10980 * gtk_requisition_free:
10981 * @requisition: a #GtkRequisition
10983 * Frees a #GtkRequisition.
10986 gtk_requisition_free (GtkRequisition *requisition)
10988 g_slice_free (GtkRequisition, requisition);
10991 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10992 gtk_requisition_copy,
10993 gtk_requisition_free)
10996 * gtk_widget_get_accessible:
10997 * @widget: a #GtkWidget
10999 * Returns the accessible object that describes the widget to an
11000 * assistive technology.
11002 * If no accessibility library is loaded (i.e. no ATK implementation library is
11003 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11004 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11005 * if no class-specific #AtkObject implementation is available for the widget
11006 * instance in question, it will inherit an #AtkObject implementation from the
11007 * first ancestor class for which such an implementation is defined.
11009 * The documentation of the
11010 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11011 * library contains more information about accessible objects and their uses.
11013 * Returns: (transfer none): the #AtkObject associated with @widget
11016 gtk_widget_get_accessible (GtkWidget *widget)
11018 GtkWidgetClass *klass;
11020 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11022 klass = GTK_WIDGET_GET_CLASS (widget);
11024 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11026 return klass->get_accessible (widget);
11030 gtk_widget_real_get_accessible (GtkWidget *widget)
11032 AtkObject* accessible;
11034 accessible = g_object_get_qdata (G_OBJECT (widget),
11035 quark_accessible_object);
11038 AtkObjectFactory *factory;
11039 AtkRegistry *default_registry;
11041 default_registry = atk_get_default_registry ();
11042 factory = atk_registry_get_factory (default_registry,
11043 G_TYPE_FROM_INSTANCE (widget));
11045 atk_object_factory_create_accessible (factory,
11046 G_OBJECT (widget));
11047 g_object_set_qdata (G_OBJECT (widget),
11048 quark_accessible_object,
11055 * Initialize a AtkImplementorIface instance's virtual pointers as
11056 * appropriate to this implementor's class (GtkWidget).
11059 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11061 iface->ref_accessible = gtk_widget_ref_accessible;
11065 gtk_widget_ref_accessible (AtkImplementor *implementor)
11067 AtkObject *accessible;
11069 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11071 g_object_ref (accessible);
11076 * Expand flag management
11080 gtk_widget_update_computed_expand (GtkWidget *widget)
11082 GtkWidgetPrivate *priv;
11084 priv = widget->priv;
11086 if (priv->need_compute_expand)
11090 if (priv->hexpand_set)
11095 if (priv->vexpand_set)
11100 /* we don't need to use compute_expand if both expands are
11101 * forced by the app
11103 if (!(priv->hexpand_set && priv->vexpand_set))
11105 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11109 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11110 priv->hexpand_set ? &ignored : &h,
11111 priv->vexpand_set ? &ignored : &v);
11115 priv->need_compute_expand = FALSE;
11116 priv->computed_hexpand = h != FALSE;
11117 priv->computed_vexpand = v != FALSE;
11122 * gtk_widget_queue_compute_expand:
11123 * @widget: a #GtkWidget
11125 * Mark @widget as needing to recompute its expand flags. Call
11126 * this function when setting legacy expand child properties
11127 * on the child of a container.
11129 * See gtk_widget_compute_expand().
11132 gtk_widget_queue_compute_expand (GtkWidget *widget)
11135 gboolean changed_anything;
11137 if (widget->priv->need_compute_expand)
11140 changed_anything = FALSE;
11142 while (parent != NULL)
11144 if (!parent->priv->need_compute_expand)
11146 parent->priv->need_compute_expand = TRUE;
11147 changed_anything = TRUE;
11150 /* Note: if we had an invariant that "if a child needs to
11151 * compute expand, its parents also do" then we could stop going
11152 * up when we got to a parent that already needed to
11153 * compute. However, in general we compute expand lazily (as
11154 * soon as we see something in a subtree that is expand, we know
11155 * we're expanding) and so this invariant does not hold and we
11156 * have to always walk all the way up in case some ancestor
11157 * is not currently need_compute_expand.
11160 parent = parent->priv->parent;
11163 /* recomputing expand always requires
11164 * a relayout as well
11166 if (changed_anything)
11167 gtk_widget_queue_resize (widget);
11171 * gtk_widget_compute_expand:
11172 * @widget: the widget
11173 * @orientation: expand direction
11175 * Computes whether a container should give this widget extra space
11176 * when possible. Containers should check this, rather than
11177 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11179 * This function already checks whether the widget is visible, so
11180 * visibility does not need to be checked separately. Non-visible
11181 * widgets are not expanded.
11183 * The computed expand value uses either the expand setting explicitly
11184 * set on the widget itself, or, if none has been explicitly set,
11185 * the widget may expand if some of its children do.
11187 * Return value: whether widget tree rooted here should be expanded
11190 gtk_widget_compute_expand (GtkWidget *widget,
11191 GtkOrientation orientation)
11193 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11195 /* We never make a widget expand if not even showing. */
11196 if (!gtk_widget_get_visible (widget))
11199 gtk_widget_update_computed_expand (widget);
11201 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11203 return widget->priv->computed_hexpand;
11207 return widget->priv->computed_vexpand;
11212 gtk_widget_set_expand (GtkWidget *widget,
11213 GtkOrientation orientation,
11216 const char *expand_prop;
11217 const char *expand_set_prop;
11219 GtkWidgetPrivate *priv;
11221 g_return_if_fail (GTK_IS_WIDGET (widget));
11223 priv = widget->priv;
11225 expand = expand != FALSE;
11227 was_both = priv->hexpand && priv->vexpand;
11229 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11231 if (priv->hexpand_set &&
11232 priv->hexpand == expand)
11235 priv->hexpand_set = TRUE;
11236 priv->hexpand = expand;
11238 expand_prop = "hexpand";
11239 expand_set_prop = "hexpand-set";
11243 if (priv->vexpand_set &&
11244 priv->vexpand == expand)
11247 priv->vexpand_set = TRUE;
11248 priv->vexpand = expand;
11250 expand_prop = "vexpand";
11251 expand_set_prop = "vexpand-set";
11254 gtk_widget_queue_compute_expand (widget);
11256 g_object_freeze_notify (G_OBJECT (widget));
11257 g_object_notify (G_OBJECT (widget), expand_prop);
11258 g_object_notify (G_OBJECT (widget), expand_set_prop);
11259 if (was_both != (priv->hexpand && priv->vexpand))
11260 g_object_notify (G_OBJECT (widget), "expand");
11261 g_object_thaw_notify (G_OBJECT (widget));
11265 gtk_widget_set_expand_set (GtkWidget *widget,
11266 GtkOrientation orientation,
11269 GtkWidgetPrivate *priv;
11272 priv = widget->priv;
11274 set = set != FALSE;
11276 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11278 if (set == priv->hexpand_set)
11281 priv->hexpand_set = set;
11282 prop = "hexpand-set";
11286 if (set == priv->vexpand_set)
11289 priv->vexpand_set = set;
11290 prop = "vexpand-set";
11293 gtk_widget_queue_compute_expand (widget);
11295 g_object_notify (G_OBJECT (widget), prop);
11299 * gtk_widget_get_hexpand:
11300 * @widget: the widget
11302 * Gets whether the widget would like any available extra horizontal
11303 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11304 * generally receive the extra space. For example, a list or
11305 * scrollable area or document in your window would often be set to
11308 * Containers should use gtk_widget_compute_expand() rather than
11309 * this function, to see whether a widget, or any of its children,
11310 * has the expand flag set. If any child of a widget wants to
11311 * expand, the parent may ask to expand also.
11313 * This function only looks at the widget's own hexpand flag, rather
11314 * than computing whether the entire widget tree rooted at this widget
11317 * Return value: whether hexpand flag is set
11320 gtk_widget_get_hexpand (GtkWidget *widget)
11322 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11324 return widget->priv->hexpand;
11328 * gtk_widget_set_hexpand:
11329 * @widget: the widget
11330 * @expand: whether to expand
11332 * Sets whether the widget would like any available extra horizontal
11333 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11334 * generally receive the extra space. For example, a list or
11335 * scrollable area or document in your window would often be set to
11338 * Call this function to set the expand flag if you would like your
11339 * widget to become larger horizontally when the window has extra
11342 * By default, widgets automatically expand if any of their children
11343 * want to expand. (To see if a widget will automatically expand given
11344 * its current children and state, call gtk_widget_compute_expand(). A
11345 * container can decide how the expandability of children affects the
11346 * expansion of the container by overriding the compute_expand virtual
11347 * method on #GtkWidget.).
11349 * Setting hexpand explicitly with this function will override the
11350 * automatic expand behavior.
11352 * This function forces the widget to expand or not to expand,
11353 * regardless of children. The override occurs because
11354 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11355 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11356 * value to be used, rather than looking at children and widget state.
11359 gtk_widget_set_hexpand (GtkWidget *widget,
11362 g_return_if_fail (GTK_IS_WIDGET (widget));
11364 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11368 * gtk_widget_get_hexpand_set:
11369 * @widget: the widget
11371 * Gets whether gtk_widget_set_hexpand() has been used to
11372 * explicitly set the expand flag on this widget.
11374 * If hexpand is set, then it overrides any computed
11375 * expand value based on child widgets. If hexpand is not
11376 * set, then the expand value depends on whether any
11377 * children of the widget would like to expand.
11379 * There are few reasons to use this function, but it's here
11380 * for completeness and consistency.
11382 * Return value: whether hexpand has been explicitly set
11385 gtk_widget_get_hexpand_set (GtkWidget *widget)
11387 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11389 return widget->priv->hexpand_set;
11393 * gtk_widget_set_hexpand_set:
11394 * @widget: the widget
11395 * @set: value for hexpand-set property
11397 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11400 * The hexpand-set property will be set automatically when you call
11401 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11402 * reason to use this function would be to unset an explicit expand
11405 * If hexpand is set, then it overrides any computed
11406 * expand value based on child widgets. If hexpand is not
11407 * set, then the expand value depends on whether any
11408 * children of the widget would like to expand.
11410 * There are few reasons to use this function, but it's here
11411 * for completeness and consistency.
11413 * Return value: whether hexpand has been explicitly set
11416 gtk_widget_set_hexpand_set (GtkWidget *widget,
11419 g_return_if_fail (GTK_IS_WIDGET (widget));
11421 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11426 * gtk_widget_get_vexpand:
11427 * @widget: the widget
11429 * Gets whether the widget would like any available extra vertical
11432 * See gtk_widget_get_hexpand() for more detail.
11434 * Return value: whether vexpand flag is set
11437 gtk_widget_get_vexpand (GtkWidget *widget)
11439 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11441 return widget->priv->vexpand;
11445 * gtk_widget_set_vexpand:
11446 * @widget: the widget
11447 * @expand: whether to expand
11449 * Sets whether the widget would like any available extra vertical
11452 * See gtk_widget_set_hexpand() for more detail.
11455 gtk_widget_set_vexpand (GtkWidget *widget,
11458 g_return_if_fail (GTK_IS_WIDGET (widget));
11460 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11464 * gtk_widget_get_vexpand_set:
11465 * @widget: the widget
11467 * Gets whether gtk_widget_set_vexpand() has been used to
11468 * explicitly set the expand flag on this widget.
11470 * See gtk_widget_get_hexpand_set() for more detail.
11472 * Return value: whether vexpand has been explicitly set
11475 gtk_widget_get_vexpand_set (GtkWidget *widget)
11477 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11479 return widget->priv->vexpand_set;
11483 * gtk_widget_set_vexpand_set:
11484 * @widget: the widget
11485 * @set: value for vexpand-set property
11487 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11490 * See gtk_widget_set_hexpand_set() for more detail.
11492 * Return value: whether vexpand has been explicitly set
11495 gtk_widget_set_vexpand_set (GtkWidget *widget,
11498 g_return_if_fail (GTK_IS_WIDGET (widget));
11500 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11504 * GtkBuildable implementation
11506 static GQuark quark_builder_has_default = 0;
11507 static GQuark quark_builder_has_focus = 0;
11508 static GQuark quark_builder_atk_relations = 0;
11509 static GQuark quark_builder_set_name = 0;
11512 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11514 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11515 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11516 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11517 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11519 iface->set_name = gtk_widget_buildable_set_name;
11520 iface->get_name = gtk_widget_buildable_get_name;
11521 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11522 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11523 iface->parser_finished = gtk_widget_buildable_parser_finished;
11524 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11525 iface->custom_finished = gtk_widget_buildable_custom_finished;
11529 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11532 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11533 g_strdup (name), g_free);
11536 static const gchar *
11537 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11539 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11543 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11544 GtkBuilder *builder,
11545 const gchar *childname)
11547 if (strcmp (childname, "accessible") == 0)
11548 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11554 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11555 GtkBuilder *builder,
11557 const GValue *value)
11559 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11560 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11561 GINT_TO_POINTER (TRUE));
11562 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11563 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11564 GINT_TO_POINTER (TRUE));
11566 g_object_set_property (G_OBJECT (buildable), name, value);
11571 gchar *action_name;
11572 GString *description;
11574 gboolean translatable;
11584 free_action (AtkActionData *data, gpointer user_data)
11586 g_free (data->action_name);
11587 g_string_free (data->description, TRUE);
11588 g_free (data->context);
11589 g_slice_free (AtkActionData, data);
11593 free_relation (AtkRelationData *data, gpointer user_data)
11595 g_free (data->target);
11596 g_free (data->type);
11597 g_slice_free (AtkRelationData, data);
11601 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11602 GtkBuilder *builder)
11604 GSList *atk_relations;
11606 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11607 gtk_widget_grab_default (GTK_WIDGET (buildable));
11608 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11609 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11611 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11612 quark_builder_atk_relations);
11615 AtkObject *accessible;
11616 AtkRelationSet *relation_set;
11619 AtkRelationType relation_type;
11620 AtkObject *target_accessible;
11622 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11623 relation_set = atk_object_ref_relation_set (accessible);
11625 for (l = atk_relations; l; l = l->next)
11627 AtkRelationData *relation = (AtkRelationData*)l->data;
11629 target = gtk_builder_get_object (builder, relation->target);
11632 g_warning ("Target object %s in <relation> does not exist",
11636 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11637 g_assert (target_accessible != NULL);
11639 relation_type = atk_relation_type_for_name (relation->type);
11640 if (relation_type == ATK_RELATION_NULL)
11642 g_warning ("<relation> type %s not found",
11646 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11647 target_accessible);
11649 g_object_unref (relation_set);
11651 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11652 g_slist_free (atk_relations);
11653 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11662 } AccessibilitySubParserData;
11665 accessibility_start_element (GMarkupParseContext *context,
11666 const gchar *element_name,
11667 const gchar **names,
11668 const gchar **values,
11669 gpointer user_data,
11672 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11674 gint line_number, char_number;
11676 if (strcmp (element_name, "relation") == 0)
11678 gchar *target = NULL;
11679 gchar *type = NULL;
11680 AtkRelationData *relation;
11682 for (i = 0; names[i]; i++)
11684 if (strcmp (names[i], "target") == 0)
11685 target = g_strdup (values[i]);
11686 else if (strcmp (names[i], "type") == 0)
11687 type = g_strdup (values[i]);
11690 g_markup_parse_context_get_position (context,
11693 g_set_error (error,
11695 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11696 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11698 line_number, char_number, names[i], "relation");
11705 if (!target || !type)
11707 g_markup_parse_context_get_position (context,
11710 g_set_error (error,
11712 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11713 "%s:%d:%d <%s> requires attribute \"%s\"",
11715 line_number, char_number, "relation",
11716 type ? "target" : "type");
11722 relation = g_slice_new (AtkRelationData);
11723 relation->target = target;
11724 relation->type = type;
11726 data->relations = g_slist_prepend (data->relations, relation);
11728 else if (strcmp (element_name, "action") == 0)
11730 const gchar *action_name = NULL;
11731 const gchar *description = NULL;
11732 const gchar *msg_context = NULL;
11733 gboolean translatable = FALSE;
11734 AtkActionData *action;
11736 for (i = 0; names[i]; i++)
11738 if (strcmp (names[i], "action_name") == 0)
11739 action_name = values[i];
11740 else if (strcmp (names[i], "description") == 0)
11741 description = values[i];
11742 else if (strcmp (names[i], "translatable") == 0)
11744 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11747 else if (strcmp (names[i], "comments") == 0)
11749 /* do nothing, comments are for translators */
11751 else if (strcmp (names[i], "context") == 0)
11752 msg_context = values[i];
11755 g_markup_parse_context_get_position (context,
11758 g_set_error (error,
11760 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11761 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11763 line_number, char_number, names[i], "action");
11770 g_markup_parse_context_get_position (context,
11773 g_set_error (error,
11775 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11776 "%s:%d:%d <%s> requires attribute \"%s\"",
11778 line_number, char_number, "action",
11783 action = g_slice_new (AtkActionData);
11784 action->action_name = g_strdup (action_name);
11785 action->description = g_string_new (description);
11786 action->context = g_strdup (msg_context);
11787 action->translatable = translatable;
11789 data->actions = g_slist_prepend (data->actions, action);
11791 else if (strcmp (element_name, "accessibility") == 0)
11794 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11798 accessibility_text (GMarkupParseContext *context,
11801 gpointer user_data,
11804 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11806 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11808 AtkActionData *action = data->actions->data;
11810 g_string_append_len (action->description, text, text_len);
11814 static const GMarkupParser accessibility_parser =
11816 accessibility_start_element,
11818 accessibility_text,
11827 } AccelGroupParserData;
11830 accel_group_start_element (GMarkupParseContext *context,
11831 const gchar *element_name,
11832 const gchar **names,
11833 const gchar **values,
11834 gpointer user_data,
11839 guint modifiers = 0;
11840 gchar *signal = NULL;
11841 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11843 for (i = 0; names[i]; i++)
11845 if (strcmp (names[i], "key") == 0)
11846 key = gdk_keyval_from_name (values[i]);
11847 else if (strcmp (names[i], "modifiers") == 0)
11849 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11855 else if (strcmp (names[i], "signal") == 0)
11856 signal = g_strdup (values[i]);
11859 if (key == 0 || signal == NULL)
11861 g_warning ("<accelerator> requires key and signal attributes");
11864 parser_data->key = key;
11865 parser_data->modifiers = modifiers;
11866 parser_data->signal = signal;
11869 static const GMarkupParser accel_group_parser =
11871 accel_group_start_element,
11875 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11876 GtkBuilder *builder,
11878 const gchar *tagname,
11879 GMarkupParser *parser,
11882 g_assert (buildable);
11884 if (strcmp (tagname, "accelerator") == 0)
11886 AccelGroupParserData *parser_data;
11888 parser_data = g_slice_new0 (AccelGroupParserData);
11889 parser_data->object = g_object_ref (buildable);
11890 *parser = accel_group_parser;
11891 *data = parser_data;
11894 if (strcmp (tagname, "accessibility") == 0)
11896 AccessibilitySubParserData *parser_data;
11898 parser_data = g_slice_new0 (AccessibilitySubParserData);
11899 *parser = accessibility_parser;
11900 *data = parser_data;
11907 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11908 GtkWidget *toplevel,
11909 gpointer user_data)
11911 AccelGroupParserData *accel_data;
11912 GSList *accel_groups;
11913 GtkAccelGroup *accel_group;
11915 g_return_if_fail (GTK_IS_WIDGET (widget));
11916 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11917 g_return_if_fail (user_data != NULL);
11919 accel_data = (AccelGroupParserData*)user_data;
11920 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11921 if (g_slist_length (accel_groups) == 0)
11923 accel_group = gtk_accel_group_new ();
11924 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11928 g_assert (g_slist_length (accel_groups) == 1);
11929 accel_group = g_slist_nth_data (accel_groups, 0);
11932 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11933 accel_data->signal,
11936 accel_data->modifiers,
11937 GTK_ACCEL_VISIBLE);
11939 g_object_unref (accel_data->object);
11940 g_free (accel_data->signal);
11941 g_slice_free (AccelGroupParserData, accel_data);
11945 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11946 GtkBuilder *builder,
11948 const gchar *tagname,
11949 gpointer user_data)
11951 AccelGroupParserData *accel_data;
11952 AccessibilitySubParserData *a11y_data;
11953 GtkWidget *toplevel;
11955 if (strcmp (tagname, "accelerator") == 0)
11957 accel_data = (AccelGroupParserData*)user_data;
11958 g_assert (accel_data->object);
11960 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11962 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11964 else if (strcmp (tagname, "accessibility") == 0)
11966 a11y_data = (AccessibilitySubParserData*)user_data;
11968 if (a11y_data->actions)
11970 AtkObject *accessible;
11975 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11977 action = ATK_ACTION (accessible);
11978 n_actions = atk_action_get_n_actions (action);
11980 for (l = a11y_data->actions; l; l = l->next)
11982 AtkActionData *action_data = (AtkActionData*)l->data;
11984 for (i = 0; i < n_actions; i++)
11985 if (strcmp (atk_action_get_name (action, i),
11986 action_data->action_name) == 0)
11991 gchar *description;
11993 if (action_data->translatable && action_data->description->len)
11994 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11995 action_data->context,
11996 action_data->description->str);
11998 description = action_data->description->str;
12000 atk_action_set_description (action, i, description);
12004 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12005 g_slist_free (a11y_data->actions);
12008 if (a11y_data->relations)
12009 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12010 a11y_data->relations);
12012 g_slice_free (AccessibilitySubParserData, a11y_data);
12017 gtk_widget_real_get_width (GtkWidget *widget,
12018 gint *minimum_size,
12019 gint *natural_size)
12029 gtk_widget_real_get_height (GtkWidget *widget,
12030 gint *minimum_size,
12031 gint *natural_size)
12041 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12043 gint *minimum_height,
12044 gint *natural_height)
12046 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12050 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12052 gint *minimum_width,
12053 gint *natural_width)
12055 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12059 * gtk_widget_get_halign:
12060 * @widget: a #GtkWidget
12062 * Gets the value of the #GtkWidget:halign property.
12064 * Returns: the horizontal alignment of @widget
12067 gtk_widget_get_halign (GtkWidget *widget)
12069 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12070 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12074 * gtk_widget_set_halign:
12075 * @widget: a #GtkWidget
12076 * @align: the horizontal alignment
12078 * Sets the horizontal alignment of @widget.
12079 * See the #GtkWidget:halign property.
12082 gtk_widget_set_halign (GtkWidget *widget,
12085 GtkWidgetAuxInfo *aux_info;
12087 g_return_if_fail (GTK_IS_WIDGET (widget));
12089 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12091 if (aux_info->halign == align)
12094 aux_info->halign = align;
12095 gtk_widget_queue_resize (widget);
12096 g_object_notify (G_OBJECT (widget), "halign");
12100 * gtk_widget_get_valign:
12101 * @widget: a #GtkWidget
12103 * Gets the value of the #GtkWidget:valign property.
12105 * Returns: the vertical alignment of @widget
12108 gtk_widget_get_valign (GtkWidget *widget)
12110 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12111 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12115 * gtk_widget_set_valign:
12116 * @widget: a #GtkWidget
12117 * @align: the vertical alignment
12119 * Sets the vertical alignment of @widget.
12120 * See the #GtkWidget:valign property.
12123 gtk_widget_set_valign (GtkWidget *widget,
12126 GtkWidgetAuxInfo *aux_info;
12128 g_return_if_fail (GTK_IS_WIDGET (widget));
12130 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12132 if (aux_info->valign == align)
12135 aux_info->valign = align;
12136 gtk_widget_queue_resize (widget);
12137 g_object_notify (G_OBJECT (widget), "valign");
12141 * gtk_widget_get_margin_left:
12142 * @widget: a #GtkWidget
12144 * Gets the value of the #GtkWidget:margin-left property.
12146 * Returns: The left margin of @widget
12149 gtk_widget_get_margin_left (GtkWidget *widget)
12151 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12153 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12157 * gtk_widget_set_margin_left:
12158 * @widget: a #GtkWidget
12159 * @margin: the left margin
12161 * Sets the left margin of @widget.
12162 * See the #GtkWidget:margin-left property.
12165 gtk_widget_set_margin_left (GtkWidget *widget,
12168 GtkWidgetAuxInfo *aux_info;
12170 g_return_if_fail (GTK_IS_WIDGET (widget));
12171 g_return_if_fail (margin <= G_MAXINT16);
12173 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12175 if (aux_info->margin.left == margin)
12178 aux_info->margin.left = margin;
12179 gtk_widget_queue_resize (widget);
12180 g_object_notify (G_OBJECT (widget), "margin-left");
12184 * gtk_widget_get_margin_right:
12185 * @widget: a #GtkWidget
12187 * Gets the value of the #GtkWidget:margin-right property.
12189 * Returns: The left margin of @widget
12192 gtk_widget_get_margin_right (GtkWidget *widget)
12194 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12196 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12200 * gtk_widget_set_margin_right:
12201 * @widget: a #GtkWidget
12202 * @margin: the right margin
12204 * Sets the right margin of @widget.
12205 * See the #GtkWidget:margin-right property.
12208 gtk_widget_set_margin_right (GtkWidget *widget,
12211 GtkWidgetAuxInfo *aux_info;
12213 g_return_if_fail (GTK_IS_WIDGET (widget));
12214 g_return_if_fail (margin <= G_MAXINT16);
12216 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12218 if (aux_info->margin.right == margin)
12221 aux_info->margin.right = margin;
12222 gtk_widget_queue_resize (widget);
12223 g_object_notify (G_OBJECT (widget), "margin-right");
12227 * gtk_widget_get_margin_top:
12228 * @widget: a #GtkWidget
12230 * Gets the value of the #GtkWidget:margin-top property.
12232 * Returns: The top margin of @widget
12235 gtk_widget_get_margin_top (GtkWidget *widget)
12237 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12239 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12243 * gtk_widget_set_margin_top:
12244 * @widget: a #GtkWidget
12245 * @margin: the top margin
12247 * Sets the top margin of @widget.
12248 * See the #GtkWidget:margin-top property.
12251 gtk_widget_set_margin_top (GtkWidget *widget,
12254 GtkWidgetAuxInfo *aux_info;
12256 g_return_if_fail (GTK_IS_WIDGET (widget));
12257 g_return_if_fail (margin <= G_MAXINT16);
12259 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12261 if (aux_info->margin.top == margin)
12264 aux_info->margin.top = margin;
12265 gtk_widget_queue_resize (widget);
12266 g_object_notify (G_OBJECT (widget), "margin-top");
12270 * gtk_widget_get_margin_bottom:
12271 * @widget: a #GtkWidget
12273 * Gets the value of the #GtkWidget:margin-bottom property.
12275 * Returns: The bottom margin of @widget
12278 gtk_widget_get_margin_bottom (GtkWidget *widget)
12280 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12282 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12286 * gtk_widget_set_margin_bottom:
12287 * @widget: a #GtkWidget
12288 * @margin: the bottom margin
12290 * Sets the bottom margin of @widget.
12291 * See the #GtkWidget:margin-bottom property.
12294 gtk_widget_set_margin_bottom (GtkWidget *widget,
12297 GtkWidgetAuxInfo *aux_info;
12299 g_return_if_fail (GTK_IS_WIDGET (widget));
12300 g_return_if_fail (margin <= G_MAXINT16);
12302 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12304 if (aux_info->margin.bottom == margin)
12307 aux_info->margin.bottom = margin;
12308 gtk_widget_queue_resize (widget);
12309 g_object_notify (G_OBJECT (widget), "margin-bottom");
12313 * gtk_widget_get_clipboard:
12314 * @widget: a #GtkWidget
12315 * @selection: a #GdkAtom which identifies the clipboard
12316 * to use. %GDK_SELECTION_CLIPBOARD gives the
12317 * default clipboard. Another common value
12318 * is %GDK_SELECTION_PRIMARY, which gives
12319 * the primary X selection.
12321 * Returns the clipboard object for the given selection to
12322 * be used with @widget. @widget must have a #GdkDisplay
12323 * associated with it, so must be attached to a toplevel
12326 * Return value: (transfer none): the appropriate clipboard object. If no
12327 * clipboard already exists, a new one will
12328 * be created. Once a clipboard object has
12329 * been created, it is persistent for all time.
12334 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12336 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12337 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12339 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12344 * gtk_widget_list_mnemonic_labels:
12345 * @widget: a #GtkWidget
12347 * Returns a newly allocated list of the widgets, normally labels, for
12348 * which this widget is the target of a mnemonic (see for example,
12349 * gtk_label_set_mnemonic_widget()).
12351 * The widgets in the list are not individually referenced. If you
12352 * want to iterate through the list and perform actions involving
12353 * callbacks that might destroy the widgets, you
12354 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12355 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12356 * widgets afterwards.
12358 * Return value: (element-type GtkWidget) (transfer container): the list of
12359 * mnemonic labels; free this list
12360 * with g_list_free() when you are done with it.
12365 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12367 GList *list = NULL;
12370 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12372 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12373 list = g_list_prepend (list, l->data);
12379 * gtk_widget_add_mnemonic_label:
12380 * @widget: a #GtkWidget
12381 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12383 * Adds a widget to the list of mnemonic labels for
12384 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12385 * list of mnemonic labels for the widget is cleared when the
12386 * widget is destroyed, so the caller must make sure to update
12387 * its internal state at this point as well, by using a connection
12388 * to the #GtkWidget::destroy signal or a weak notifier.
12393 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12396 GSList *old_list, *new_list;
12398 g_return_if_fail (GTK_IS_WIDGET (widget));
12399 g_return_if_fail (GTK_IS_WIDGET (label));
12401 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12402 new_list = g_slist_prepend (old_list, label);
12404 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12405 new_list, (GDestroyNotify) g_slist_free);
12409 * gtk_widget_remove_mnemonic_label:
12410 * @widget: a #GtkWidget
12411 * @label: a #GtkWidget that was previously set as a mnemnic label for
12412 * @widget with gtk_widget_add_mnemonic_label().
12414 * Removes a widget from the list of mnemonic labels for
12415 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12416 * must have previously been added to the list with
12417 * gtk_widget_add_mnemonic_label().
12422 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12425 GSList *old_list, *new_list;
12427 g_return_if_fail (GTK_IS_WIDGET (widget));
12428 g_return_if_fail (GTK_IS_WIDGET (label));
12430 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12431 new_list = g_slist_remove (old_list, label);
12434 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12435 new_list, (GDestroyNotify) g_slist_free);
12439 * gtk_widget_get_no_show_all:
12440 * @widget: a #GtkWidget
12442 * Returns the current value of the #GtkWidget:no-show-all property,
12443 * which determines whether calls to gtk_widget_show_all()
12444 * will affect this widget.
12446 * Return value: the current value of the "no-show-all" property.
12451 gtk_widget_get_no_show_all (GtkWidget *widget)
12453 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12455 return widget->priv->no_show_all;
12459 * gtk_widget_set_no_show_all:
12460 * @widget: a #GtkWidget
12461 * @no_show_all: the new value for the "no-show-all" property
12463 * Sets the #GtkWidget:no-show-all property, which determines whether
12464 * calls to gtk_widget_show_all() will affect this widget.
12466 * This is mostly for use in constructing widget hierarchies with externally
12467 * controlled visibility, see #GtkUIManager.
12472 gtk_widget_set_no_show_all (GtkWidget *widget,
12473 gboolean no_show_all)
12475 g_return_if_fail (GTK_IS_WIDGET (widget));
12477 no_show_all = (no_show_all != FALSE);
12479 if (widget->priv->no_show_all != no_show_all)
12481 widget->priv->no_show_all = no_show_all;
12483 g_object_notify (G_OBJECT (widget), "no-show-all");
12489 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12490 gboolean has_tooltip,
12493 GtkWidgetPrivate *priv = widget->priv;
12494 gboolean priv_has_tooltip;
12496 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12497 quark_has_tooltip));
12499 if (priv_has_tooltip != has_tooltip || force)
12501 priv_has_tooltip = has_tooltip;
12503 if (priv_has_tooltip)
12505 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12506 gdk_window_set_events (priv->window,
12507 gdk_window_get_events (priv->window) |
12508 GDK_LEAVE_NOTIFY_MASK |
12509 GDK_POINTER_MOTION_MASK |
12510 GDK_POINTER_MOTION_HINT_MASK);
12512 if (gtk_widget_get_has_window (widget))
12513 gtk_widget_add_events (widget,
12514 GDK_LEAVE_NOTIFY_MASK |
12515 GDK_POINTER_MOTION_MASK |
12516 GDK_POINTER_MOTION_HINT_MASK);
12519 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12520 GUINT_TO_POINTER (priv_has_tooltip));
12525 * gtk_widget_set_tooltip_window:
12526 * @widget: a #GtkWidget
12527 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12529 * Replaces the default, usually yellow, window used for displaying
12530 * tooltips with @custom_window. GTK+ will take care of showing and
12531 * hiding @custom_window at the right moment, to behave likewise as
12532 * the default tooltip window. If @custom_window is %NULL, the default
12533 * tooltip window will be used.
12535 * If the custom window should have the default theming it needs to
12536 * have the name "gtk-tooltip", see gtk_widget_set_name().
12541 gtk_widget_set_tooltip_window (GtkWidget *widget,
12542 GtkWindow *custom_window)
12544 gboolean has_tooltip;
12545 gchar *tooltip_markup;
12547 g_return_if_fail (GTK_IS_WIDGET (widget));
12548 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12550 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12553 g_object_ref (custom_window);
12555 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12556 custom_window, g_object_unref);
12558 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12559 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12561 if (has_tooltip && gtk_widget_get_visible (widget))
12562 gtk_widget_queue_tooltip_query (widget);
12566 * gtk_widget_get_tooltip_window:
12567 * @widget: a #GtkWidget
12569 * Returns the #GtkWindow of the current tooltip. This can be the
12570 * GtkWindow created by default, or the custom tooltip window set
12571 * using gtk_widget_set_tooltip_window().
12573 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12578 gtk_widget_get_tooltip_window (GtkWidget *widget)
12580 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12582 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12586 * gtk_widget_trigger_tooltip_query:
12587 * @widget: a #GtkWidget
12589 * Triggers a tooltip query on the display where the toplevel of @widget
12590 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12596 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12598 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12601 static guint tooltip_query_id;
12602 static GSList *tooltip_query_displays;
12605 tooltip_query_idle (gpointer data)
12607 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12608 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12609 g_slist_free (tooltip_query_displays);
12611 tooltip_query_displays = NULL;
12612 tooltip_query_id = 0;
12618 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12620 GdkDisplay *display;
12622 display = gtk_widget_get_display (widget);
12624 if (!g_slist_find (tooltip_query_displays, display))
12625 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12627 if (tooltip_query_id == 0)
12628 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12632 * gtk_widget_set_tooltip_text:
12633 * @widget: a #GtkWidget
12634 * @text: the contents of the tooltip for @widget
12636 * Sets @text as the contents of the tooltip. This function will take
12637 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12638 * handler for the #GtkWidget::query-tooltip signal.
12640 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12645 gtk_widget_set_tooltip_text (GtkWidget *widget,
12648 g_return_if_fail (GTK_IS_WIDGET (widget));
12650 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12654 * gtk_widget_get_tooltip_text:
12655 * @widget: a #GtkWidget
12657 * Gets the contents of the tooltip for @widget.
12659 * Return value: the tooltip text, or %NULL. You should free the
12660 * returned string with g_free() when done.
12665 gtk_widget_get_tooltip_text (GtkWidget *widget)
12667 gchar *text = NULL;
12669 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12671 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12677 * gtk_widget_set_tooltip_markup:
12678 * @widget: a #GtkWidget
12679 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12681 * Sets @markup as the contents of the tooltip, which is marked up with
12682 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12684 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12685 * and of the default handler for the #GtkWidget::query-tooltip signal.
12687 * See also the #GtkWidget:tooltip-markup property and
12688 * gtk_tooltip_set_markup().
12693 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12694 const gchar *markup)
12696 g_return_if_fail (GTK_IS_WIDGET (widget));
12698 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12702 * gtk_widget_get_tooltip_markup:
12703 * @widget: a #GtkWidget
12705 * Gets the contents of the tooltip for @widget.
12707 * Return value: the tooltip text, or %NULL. You should free the
12708 * returned string with g_free() when done.
12713 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12715 gchar *text = NULL;
12717 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12719 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12725 * gtk_widget_set_has_tooltip:
12726 * @widget: a #GtkWidget
12727 * @has_tooltip: whether or not @widget has a tooltip.
12729 * Sets the has-tooltip property on @widget to @has_tooltip. See
12730 * #GtkWidget:has-tooltip for more information.
12735 gtk_widget_set_has_tooltip (GtkWidget *widget,
12736 gboolean has_tooltip)
12738 g_return_if_fail (GTK_IS_WIDGET (widget));
12740 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12744 * gtk_widget_get_has_tooltip:
12745 * @widget: a #GtkWidget
12747 * Returns the current value of the has-tooltip property. See
12748 * #GtkWidget:has-tooltip for more information.
12750 * Return value: current value of has-tooltip on @widget.
12755 gtk_widget_get_has_tooltip (GtkWidget *widget)
12757 gboolean has_tooltip = FALSE;
12759 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12761 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12763 return has_tooltip;
12767 * gtk_widget_get_allocation:
12768 * @widget: a #GtkWidget
12769 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12771 * Retrieves the widget's allocation.
12773 * Note, when implementing a #GtkContainer: a widget's allocation will
12774 * be its "adjusted" allocation, that is, the widget's parent
12775 * container typically calls gtk_widget_size_allocate() with an
12776 * allocation, and that allocation is then adjusted (to handle margin
12777 * and alignment for example) before assignment to the widget.
12778 * gtk_widget_get_allocation() returns the adjusted allocation that
12779 * was actually assigned to the widget. The adjusted allocation is
12780 * guaranteed to be completely contained within the
12781 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12782 * is guaranteed that its children stay inside the assigned bounds,
12783 * but not that they have exactly the bounds the container assigned.
12784 * There is no way to get the original allocation assigned by
12785 * gtk_widget_size_allocate(), since it isn't stored; if a container
12786 * implementation needs that information it will have to track it itself.
12791 gtk_widget_get_allocation (GtkWidget *widget,
12792 GtkAllocation *allocation)
12794 GtkWidgetPrivate *priv;
12796 g_return_if_fail (GTK_IS_WIDGET (widget));
12797 g_return_if_fail (allocation != NULL);
12799 priv = widget->priv;
12801 *allocation = priv->allocation;
12805 * gtk_widget_set_allocation:
12806 * @widget: a #GtkWidget
12807 * @allocation: a pointer to a #GtkAllocation to copy from
12809 * Sets the widget's allocation. This should not be used
12810 * directly, but from within a widget's size_allocate method.
12812 * The allocation set should be the "adjusted" or actual
12813 * allocation. If you're implementing a #GtkContainer, you want to use
12814 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12815 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12816 * allocation inside gtk_widget_size_allocate() to create an adjusted
12822 gtk_widget_set_allocation (GtkWidget *widget,
12823 const GtkAllocation *allocation)
12825 GtkWidgetPrivate *priv;
12827 g_return_if_fail (GTK_IS_WIDGET (widget));
12828 g_return_if_fail (allocation != NULL);
12830 priv = widget->priv;
12832 priv->allocation = *allocation;
12836 * gtk_widget_get_allocated_width:
12837 * @widget: the widget to query
12839 * Returns the width that has currently been allocated to @widget.
12840 * This function is intended to be used when implementing handlers
12841 * for the #GtkWidget::draw function.
12843 * Returns: the width of the @widget
12846 gtk_widget_get_allocated_width (GtkWidget *widget)
12848 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12850 return widget->priv->allocation.width;
12854 * gtk_widget_get_allocated_height:
12855 * @widget: the widget to query
12857 * Returns the height that has currently been allocated to @widget.
12858 * This function is intended to be used when implementing handlers
12859 * for the #GtkWidget::draw function.
12861 * Returns: the height of the @widget
12864 gtk_widget_get_allocated_height (GtkWidget *widget)
12866 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12868 return widget->priv->allocation.height;
12872 * gtk_widget_get_requisition:
12873 * @widget: a #GtkWidget
12874 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12876 * Retrieves the widget's requisition.
12878 * This function should only be used by widget implementations in
12879 * order to figure whether the widget's requisition has actually
12880 * changed after some internal state change (so that they can call
12881 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12883 * Normally, gtk_widget_size_request() should be used.
12887 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12888 * removed, If you need to cache sizes across requests and allocations,
12889 * add an explicit cache to the widget in question instead.
12892 gtk_widget_get_requisition (GtkWidget *widget,
12893 GtkRequisition *requisition)
12895 g_return_if_fail (GTK_IS_WIDGET (widget));
12896 g_return_if_fail (requisition != NULL);
12898 gtk_widget_get_preferred_size (widget, requisition, NULL);
12902 * gtk_widget_set_window:
12903 * @widget: a #GtkWidget
12904 * @window: a #GdkWindow
12906 * Sets a widget's window. This function should only be used in a
12907 * widget's #GtkWidget::realize implementation. The %window passed is
12908 * usually either new window created with gdk_window_new(), or the
12909 * window of its parent widget as returned by
12910 * gtk_widget_get_parent_window().
12912 * Widgets must indicate whether they will create their own #GdkWindow
12913 * by calling gtk_widget_set_has_window(). This is usually done in the
12914 * widget's init() function.
12916 * <note><para>This function does not add any reference to @window.</para></note>
12921 gtk_widget_set_window (GtkWidget *widget,
12924 GtkWidgetPrivate *priv;
12926 g_return_if_fail (GTK_IS_WIDGET (widget));
12927 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12929 priv = widget->priv;
12931 if (priv->window != window)
12933 priv->window = window;
12934 g_object_notify (G_OBJECT (widget), "window");
12939 * gtk_widget_get_window:
12940 * @widget: a #GtkWidget
12942 * Returns the widget's window if it is realized, %NULL otherwise
12944 * Return value: (transfer none): @widget's window.
12949 gtk_widget_get_window (GtkWidget *widget)
12951 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12953 return widget->priv->window;
12957 * gtk_widget_get_support_multidevice:
12958 * @widget: a #GtkWidget
12960 * Returns %TRUE if @widget is multiple pointer aware. See
12961 * gtk_widget_set_support_multidevice() for more information.
12963 * Returns: %TRUE is @widget is multidevice aware.
12966 gtk_widget_get_support_multidevice (GtkWidget *widget)
12968 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12970 return widget->priv->multidevice;
12974 * gtk_widget_set_support_multidevice:
12975 * @widget: a #GtkWidget
12976 * @support_multidevice: %TRUE to support input from multiple devices.
12978 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12979 * @widget will start receiving multiple, per device enter/leave events. Note
12980 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12981 * gdk_window_set_support_multidevice() will have to be called manually on them.
12986 gtk_widget_set_support_multidevice (GtkWidget *widget,
12987 gboolean support_multidevice)
12989 GtkWidgetPrivate *priv;
12991 g_return_if_fail (GTK_IS_WIDGET (widget));
12993 priv = widget->priv;
12995 if (support_multidevice)
12997 priv->multidevice = TRUE;
12998 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13002 priv->multidevice = FALSE;
13003 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13006 if (gtk_widget_get_realized (widget))
13007 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13011 _gtk_widget_set_has_focus (GtkWidget *widget,
13012 gboolean has_focus)
13014 widget->priv->has_focus = has_focus;
13018 * gtk_widget_send_focus_change:
13019 * @widget: a #GtkWidget
13020 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13022 * Sends the focus change @event to @widget
13024 * This function is not meant to be used by applications. The only time it
13025 * should be used is when it is necessary for a #GtkWidget to assign focus
13026 * to a widget that is semantically owned by the first widget even though
13027 * it's not a direct child - for instance, a search entry in a floating
13028 * window similar to the quick search in #GtkTreeView.
13030 * An example of its usage is:
13033 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13035 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13036 * fevent->focus_change.in = TRUE;
13037 * fevent->focus_change.window = gtk_widget_get_window (widget);
13038 * if (fevent->focus_change.window != NULL)
13039 * g_object_ref (fevent->focus_change.window);
13041 * gtk_widget_send_focus_change (widget, fevent);
13043 * gdk_event_free (event);
13046 * Return value: the return value from the event signal emission: %TRUE
13047 * if the event was handled, and %FALSE otherwise
13052 gtk_widget_send_focus_change (GtkWidget *widget,
13057 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13058 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13060 g_object_ref (widget);
13062 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13064 res = gtk_widget_event (widget, event);
13066 g_object_notify (G_OBJECT (widget), "has-focus");
13068 g_object_unref (widget);
13074 * gtk_widget_in_destruction:
13075 * @widget: a #GtkWidget
13077 * Returns whether the widget is currently being destroyed.
13078 * This information can sometimes be used to avoid doing
13079 * unnecessary work.
13081 * Returns: %TRUE if @widget is being destroyed
13084 gtk_widget_in_destruction (GtkWidget *widget)
13086 return widget->priv->in_destruction;
13090 _gtk_widget_get_resize_pending (GtkWidget *widget)
13092 return widget->priv->resize_pending;
13096 _gtk_widget_set_resize_pending (GtkWidget *widget,
13097 gboolean resize_pending)
13099 widget->priv->resize_pending = resize_pending;
13103 _gtk_widget_get_in_reparent (GtkWidget *widget)
13105 return widget->priv->in_reparent;
13109 _gtk_widget_set_in_reparent (GtkWidget *widget,
13110 gboolean in_reparent)
13112 widget->priv->in_reparent = in_reparent;
13116 _gtk_widget_get_anchored (GtkWidget *widget)
13118 return widget->priv->anchored;
13122 _gtk_widget_set_anchored (GtkWidget *widget,
13125 widget->priv->anchored = anchored;
13129 _gtk_widget_get_shadowed (GtkWidget *widget)
13131 return widget->priv->shadowed;
13135 _gtk_widget_set_shadowed (GtkWidget *widget,
13138 widget->priv->shadowed = shadowed;
13142 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13144 return widget->priv->alloc_needed;
13148 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13149 gboolean alloc_needed)
13151 widget->priv->alloc_needed = alloc_needed;
13155 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13157 return widget->priv->width_request_needed;
13161 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13162 gboolean width_request_needed)
13164 widget->priv->width_request_needed = width_request_needed;
13168 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13170 return widget->priv->height_request_needed;
13174 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13175 gboolean height_request_needed)
13177 widget->priv->height_request_needed = height_request_needed;
13181 gtk_widget_get_path (GtkWidget *widget)
13183 GtkStyleContext *context;
13184 GtkWidgetPath *path;
13186 GList *regions, *reg;
13188 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13189 g_return_val_if_fail ((widget->parent || gtk_widget_is_toplevel (widget)), NULL);
13191 parent = widget->priv->parent;
13193 path = gtk_widget_path_new ();
13194 gtk_widget_path_prepend_type (path, G_OBJECT_TYPE (widget));
13195 regions = reg = NULL;
13197 if (widget->priv->name)
13198 gtk_widget_path_iter_set_name (path, 0, widget->priv->name);
13200 context = g_object_get_qdata (G_OBJECT (widget),
13201 quark_style_context);
13204 regions = reg = gtk_style_context_list_child_classes (context);
13208 GtkChildClassFlags flags;
13209 const gchar *region_name;
13211 region_name = reg->data;
13214 gtk_style_context_has_child_class (context, region_name, &flags);
13215 gtk_widget_path_iter_add_region (path, 0, region_name, flags);
13218 g_list_free (regions);
13224 position = gtk_widget_path_prepend_type (path, G_OBJECT_TYPE (parent));
13226 if (parent->priv->name)
13227 gtk_widget_path_iter_set_name (path, position, parent->priv->name);
13229 parent = parent->priv->parent;
13236 gtk_widget_get_style_context (GtkWidget *widget)
13238 GtkStyleContext *context;
13240 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13242 context = g_object_get_qdata (G_OBJECT (widget),
13243 quark_style_context);
13245 if (G_UNLIKELY (!context))
13247 static GtkCssProvider *css_provider = NULL;
13249 context = g_object_new (GTK_TYPE_STYLE_CONTEXT, NULL);
13250 g_object_set_qdata_full (G_OBJECT (widget),
13251 quark_style_context, context,
13252 (GDestroyNotify) g_object_unref);
13254 /* Add provider for user file */
13255 if (G_UNLIKELY (!css_provider))
13257 GFile *home_dir, *css_file;
13260 css_provider = gtk_css_provider_new ();
13261 home_dir = g_file_new_for_path (g_get_home_dir ());
13263 filename = g_strdup_printf (".gtk-%d.0.css", GTK_MAJOR_VERSION);
13264 css_file = g_file_get_child (home_dir, filename);
13267 if (g_file_query_exists (css_file, NULL))
13268 gtk_css_provider_load_from_file (css_provider, css_file, NULL);
13270 g_object_unref (home_dir);
13271 g_object_unref (css_file);
13274 gtk_style_context_add_provider (context, css_provider,
13275 GTK_STYLE_PROVIDER_PRIORITY_USER);
13278 if (widget->parent ||
13279 gtk_widget_is_toplevel (widget))
13281 GtkWidgetPath *path;
13283 path = gtk_widget_get_path (widget);
13284 gtk_style_context_set_path (context, path);
13285 gtk_widget_path_free (path);