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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <gobject/gvaluecollector.h>
32 #include <gobject/gobjectnotifyqueue.c>
33 #include <cairo-gobject.h>
35 #include "gtkcontainer.h"
36 #include "gtkaccelmapprivate.h"
37 #include "gtkclipboard.h"
38 #include "gtkiconfactory.h"
40 #include "gtkmarshalers.h"
41 #include "gtkselectionprivate.h"
42 #include "gtksettingsprivate.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindowprivate.h"
47 #include "gtkcontainerprivate.h"
48 #include "gtkbindings.h"
49 #include "gtkprivate.h"
50 #include "gtkaccessible.h"
51 #include "gtktooltip.h"
52 #include "gtkinvisible.h"
53 #include "gtkbuildable.h"
54 #include "gtkbuilderprivate.h"
55 #include "gtksizerequest.h"
56 #include "gtkstylecontextprivate.h"
57 #include "gtksymboliccolor.h"
58 #include "gtkcssprovider.h"
59 #include "gtkanimationdescription.h"
60 #include "gtkmodifierstyle.h"
61 #include "gtkversion.h"
64 #include "gtktypebuiltins.h"
65 #include "a11y/gtkwidgetaccessible.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_widget_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>
282 * Finally, GtkWidget allows style information such as style classes to
283 * be associated with widgets, using the custom <style> element:
285 * <title>A UI definition fragment specifying an style class</title>
286 * <programlisting><![CDATA[
287 * <object class="GtkButton" id="button1">
289 * <class name="my-special-button-class"/>
290 * <class name="dark-button"/>
293 * ]]></programlisting>
299 /* Add flags here that should not be propagated to children. By default,
300 * all flags will be set on children (think prelight or active), but we
301 * might want to not do this for some.
303 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
304 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
306 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
308 #define GTK_STATE_FLAGS_BITS 7
310 struct _GtkWidgetPrivate
312 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
313 * (defined in "gtkenums.h").
315 guint state_flags : GTK_STATE_FLAGS_BITS;
319 guint in_destruction : 1;
322 guint composite_child : 1;
330 guint can_default : 1;
331 guint has_default : 1;
332 guint receives_default : 1;
335 guint style_update_pending : 1;
336 guint app_paintable : 1;
337 guint double_buffered : 1;
338 guint redraw_on_alloc : 1;
339 guint no_show_all : 1;
340 guint child_visible : 1;
341 guint multidevice : 1;
342 guint has_shape_mask : 1;
343 guint in_reparent : 1;
345 /* Queue-resize related flags */
346 guint resize_pending : 1;
347 guint alloc_needed : 1;
348 guint width_request_needed : 1;
349 guint height_request_needed : 1;
351 /* Expand-related flags */
352 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
353 guint computed_hexpand : 1; /* computed results (composite of child flags) */
354 guint computed_vexpand : 1;
355 guint hexpand : 1; /* application-forced expand */
357 guint hexpand_set : 1; /* whether to use application-forced */
358 guint vexpand_set : 1; /* instead of computing from children */
360 /* SizeGroup related flags */
361 guint sizegroup_visited : 1;
362 guint sizegroup_bumping : 1;
363 guint have_size_groups : 1;
365 /* The widget's name. If the widget does not have a name
366 * (the name is NULL), then its name (as returned by
367 * "gtk_widget_get_name") is its class's name.
368 * Among other things, the widget name is used to determine
369 * the style to use for a widget.
373 /* The list of attached windows to this widget.
374 * We keep a list in order to call reset_style to all of them,
376 GList *attached_windows;
378 /* The style for the widget. The style contains the
379 * colors the widget should be drawn in for each state
380 * along with graphics contexts used to draw with and
381 * the font to use for text.
384 GtkStyleContext *context;
386 /* Widget's path for styling */
389 /* The widget's allocated size */
390 GtkAllocation allocation;
392 /* The widget's requested sizes */
393 SizeRequestCache requests;
395 /* The widget's window or its parent window if it does
396 * not have a window. (Which will be indicated by the
397 * GTK_NO_WINDOW flag being set).
401 /* The widget's parent */
404 #ifdef G_ENABLE_DEBUG
405 /* Number of gtk_widget_push_verify_invariants () */
406 guint verifying_invariants_count;
407 #endif /* G_ENABLE_DEBUG */
410 struct _GtkWidgetClassPrivate
412 GType accessible_type;
413 AtkRole accessible_role;
442 BUTTON_RELEASE_EVENT,
456 PROPERTY_NOTIFY_EVENT,
457 SELECTION_CLEAR_EVENT,
458 SELECTION_REQUEST_EVENT,
459 SELECTION_NOTIFY_EVENT,
464 VISIBILITY_NOTIFY_EVENT,
478 ACCEL_CLOSURES_CHANGED,
503 PROP_RECEIVES_DEFAULT,
504 PROP_COMPOSITE_CHILD,
512 PROP_DOUBLE_BUFFERED,
527 typedef struct _GtkStateData GtkStateData;
530 STATE_CHANGE_REPLACE,
537 guint flags : GTK_STATE_FLAGS_BITS;
541 /* --- prototypes --- */
542 static void gtk_widget_base_class_init (gpointer g_class);
543 static void gtk_widget_class_init (GtkWidgetClass *klass);
544 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
545 static void gtk_widget_init (GtkWidget *widget);
546 static void gtk_widget_set_property (GObject *object,
550 static void gtk_widget_get_property (GObject *object,
554 static void gtk_widget_dispose (GObject *object);
555 static void gtk_widget_real_destroy (GtkWidget *object);
556 static void gtk_widget_finalize (GObject *object);
557 static void gtk_widget_real_show (GtkWidget *widget);
558 static void gtk_widget_real_hide (GtkWidget *widget);
559 static void gtk_widget_real_map (GtkWidget *widget);
560 static void gtk_widget_real_unmap (GtkWidget *widget);
561 static void gtk_widget_real_realize (GtkWidget *widget);
562 static void gtk_widget_real_unrealize (GtkWidget *widget);
563 static void gtk_widget_real_size_allocate (GtkWidget *widget,
564 GtkAllocation *allocation);
565 static void gtk_widget_real_style_set (GtkWidget *widget,
566 GtkStyle *previous_style);
567 static void gtk_widget_real_direction_changed(GtkWidget *widget,
568 GtkTextDirection previous_direction);
570 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
571 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
574 gboolean keyboard_tip,
575 GtkTooltip *tooltip);
576 static void gtk_widget_real_style_updated (GtkWidget *widget);
577 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
578 GtkWidgetHelpType help_type);
580 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
582 GParamSpec **pspecs);
583 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
585 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
587 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
588 GdkEventFocus *event);
589 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
590 GdkEventFocus *event);
591 static gboolean gtk_widget_real_focus (GtkWidget *widget,
592 GtkDirectionType direction);
593 static void gtk_widget_real_move_focus (GtkWidget *widget,
594 GtkDirectionType direction);
595 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
596 GtkDirectionType direction);
597 #ifdef G_ENABLE_DEBUG
598 static void gtk_widget_verify_invariants (GtkWidget *widget);
599 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
600 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
602 #define gtk_widget_verify_invariants(widget)
603 #define gtk_widget_push_verify_invariants(widget)
604 #define gtk_widget_pop_verify_invariants(widget)
606 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
607 static void gtk_widget_update_pango_context (GtkWidget *widget);
608 static void gtk_widget_propagate_state (GtkWidget *widget,
611 static gint gtk_widget_event_internal (GtkWidget *widget,
613 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
614 gboolean group_cycling);
615 static void gtk_widget_real_get_width (GtkWidget *widget,
618 static void gtk_widget_real_get_height (GtkWidget *widget,
621 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
623 gint *minimum_height,
624 gint *natural_height);
625 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
628 gint *natural_width);
629 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
630 GtkStateFlags old_state);
631 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
632 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
634 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
635 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
636 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
637 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
638 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
639 cairo_region_t *region);
640 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
641 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
642 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
645 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
646 gboolean has_tooltip,
648 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
649 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
651 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
652 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
654 const gchar *childname);
655 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
658 const GValue *value);
659 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
662 const gchar *tagname,
663 GMarkupParser *parser,
665 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
668 const gchar *tagname,
670 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
671 GtkBuilder *builder);
673 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
674 static void gtk_widget_real_get_width (GtkWidget *widget,
677 static void gtk_widget_real_get_height (GtkWidget *widget,
681 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
684 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
685 GtkOrientation orientation,
688 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
689 GtkOrientation orientation,
693 gint *allocated_size);
695 static void gtk_widget_set_usize_internal (GtkWidget *widget,
698 GtkQueueResizeFlags flags);
700 static void gtk_widget_add_events_internal (GtkWidget *widget,
703 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
708 /* --- variables --- */
709 static gpointer gtk_widget_parent_class = NULL;
710 static guint widget_signals[LAST_SIGNAL] = { 0 };
711 static guint composite_child_stack = 0;
712 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
713 static GParamSpecPool *style_property_spec_pool = NULL;
715 static GQuark quark_property_parser = 0;
716 static GQuark quark_aux_info = 0;
717 static GQuark quark_accel_path = 0;
718 static GQuark quark_accel_closures = 0;
719 static GQuark quark_event_mask = 0;
720 static GQuark quark_device_event_mask = 0;
721 static GQuark quark_parent_window = 0;
722 static GQuark quark_pointer_window = 0;
723 static GQuark quark_shape_info = 0;
724 static GQuark quark_input_shape_info = 0;
725 static GQuark quark_pango_context = 0;
726 static GQuark quark_accessible_object = 0;
727 static GQuark quark_mnemonic_labels = 0;
728 static GQuark quark_tooltip_markup = 0;
729 static GQuark quark_has_tooltip = 0;
730 static GQuark quark_tooltip_window = 0;
731 static GQuark quark_visual = 0;
732 static GQuark quark_modifier_style = 0;
733 static GQuark quark_enabled_devices = 0;
734 static GQuark quark_size_groups = 0;
735 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
736 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
738 /* --- functions --- */
740 gtk_widget_get_type (void)
742 static GType widget_type = 0;
744 if (G_UNLIKELY (widget_type == 0))
746 const GTypeInfo widget_info =
748 sizeof (GtkWidgetClass),
749 gtk_widget_base_class_init,
750 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
751 (GClassInitFunc) gtk_widget_class_init,
752 NULL, /* class_finalize */
753 NULL, /* class_init */
756 (GInstanceInitFunc) gtk_widget_init,
757 NULL, /* value_table */
760 const GInterfaceInfo accessibility_info =
762 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
763 (GInterfaceFinalizeFunc) NULL,
764 NULL /* interface data */
767 const GInterfaceInfo buildable_info =
769 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
770 (GInterfaceFinalizeFunc) NULL,
771 NULL /* interface data */
774 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
775 &widget_info, G_TYPE_FLAG_ABSTRACT);
777 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
779 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
780 &accessibility_info) ;
781 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
789 gtk_widget_base_class_init (gpointer g_class)
791 GtkWidgetClass *klass = g_class;
793 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
797 child_property_notify_dispatcher (GObject *object,
801 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
804 /* We guard against the draw signal callbacks modifying the state of the
805 * cairo context by surounding it with save/restore.
806 * Maybe we should also cairo_new_path() just to be sure?
809 gtk_widget_draw_marshaller (GClosure *closure,
810 GValue *return_value,
811 guint n_param_values,
812 const GValue *param_values,
813 gpointer invocation_hint,
814 gpointer marshal_data)
816 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
820 _gtk_marshal_BOOLEAN__BOXED (closure,
831 gtk_widget_class_init (GtkWidgetClass *klass)
833 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
834 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
835 GtkBindingSet *binding_set;
837 gtk_widget_parent_class = g_type_class_peek_parent (klass);
839 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
840 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
841 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
842 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
843 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
844 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
845 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
846 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
847 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
848 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
849 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
850 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
851 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
852 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
853 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
854 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
855 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
856 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
857 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
858 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
860 style_property_spec_pool = g_param_spec_pool_new (FALSE);
861 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
862 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
863 cpn_context.dispatcher = child_property_notify_dispatcher;
864 _gtk_widget_child_property_notify_context = &cpn_context;
866 gobject_class->dispose = gtk_widget_dispose;
867 gobject_class->finalize = gtk_widget_finalize;
868 gobject_class->set_property = gtk_widget_set_property;
869 gobject_class->get_property = gtk_widget_get_property;
871 klass->destroy = gtk_widget_real_destroy;
873 klass->activate_signal = 0;
874 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
875 klass->show = gtk_widget_real_show;
876 klass->show_all = gtk_widget_show;
877 klass->hide = gtk_widget_real_hide;
878 klass->map = gtk_widget_real_map;
879 klass->unmap = gtk_widget_real_unmap;
880 klass->realize = gtk_widget_real_realize;
881 klass->unrealize = gtk_widget_real_unrealize;
882 klass->size_allocate = gtk_widget_real_size_allocate;
883 klass->get_request_mode = gtk_widget_real_get_request_mode;
884 klass->get_preferred_width = gtk_widget_real_get_width;
885 klass->get_preferred_height = gtk_widget_real_get_height;
886 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
887 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
888 klass->state_changed = NULL;
889 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
890 klass->parent_set = NULL;
891 klass->hierarchy_changed = NULL;
892 klass->style_set = gtk_widget_real_style_set;
893 klass->direction_changed = gtk_widget_real_direction_changed;
894 klass->grab_notify = NULL;
895 klass->child_notify = NULL;
897 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
898 klass->grab_focus = gtk_widget_real_grab_focus;
899 klass->focus = gtk_widget_real_focus;
900 klass->move_focus = gtk_widget_real_move_focus;
901 klass->keynav_failed = gtk_widget_real_keynav_failed;
903 klass->button_press_event = NULL;
904 klass->button_release_event = NULL;
905 klass->motion_notify_event = NULL;
906 klass->delete_event = NULL;
907 klass->destroy_event = NULL;
908 klass->key_press_event = gtk_widget_real_key_press_event;
909 klass->key_release_event = gtk_widget_real_key_release_event;
910 klass->enter_notify_event = NULL;
911 klass->leave_notify_event = NULL;
912 klass->configure_event = NULL;
913 klass->focus_in_event = gtk_widget_real_focus_in_event;
914 klass->focus_out_event = gtk_widget_real_focus_out_event;
915 klass->map_event = NULL;
916 klass->unmap_event = NULL;
917 klass->window_state_event = NULL;
918 klass->property_notify_event = _gtk_selection_property_notify;
919 klass->selection_clear_event = _gtk_selection_clear;
920 klass->selection_request_event = _gtk_selection_request;
921 klass->selection_notify_event = _gtk_selection_notify;
922 klass->selection_received = NULL;
923 klass->proximity_in_event = NULL;
924 klass->proximity_out_event = NULL;
925 klass->drag_begin = NULL;
926 klass->drag_end = NULL;
927 klass->drag_data_delete = NULL;
928 klass->drag_leave = NULL;
929 klass->drag_motion = NULL;
930 klass->drag_drop = NULL;
931 klass->drag_data_received = NULL;
932 klass->screen_changed = NULL;
933 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
934 klass->grab_broken_event = NULL;
935 klass->query_tooltip = gtk_widget_real_query_tooltip;
936 klass->style_updated = gtk_widget_real_style_updated;
938 klass->show_help = gtk_widget_real_show_help;
940 /* Accessibility support */
941 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
942 klass->priv->accessible_role = ATK_ROLE_INVALID;
943 klass->get_accessible = gtk_widget_real_get_accessible;
945 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
946 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
948 g_object_class_install_property (gobject_class,
950 g_param_spec_string ("name",
952 P_("The name of the widget"),
954 GTK_PARAM_READWRITE));
955 g_object_class_install_property (gobject_class,
957 g_param_spec_object ("parent",
959 P_("The parent widget of this widget. Must be a Container widget"),
961 GTK_PARAM_READWRITE));
963 g_object_class_install_property (gobject_class,
965 g_param_spec_int ("width-request",
967 P_("Override for width request of the widget, or -1 if natural request should be used"),
971 GTK_PARAM_READWRITE));
972 g_object_class_install_property (gobject_class,
974 g_param_spec_int ("height-request",
975 P_("Height request"),
976 P_("Override for height request of the widget, or -1 if natural request should be used"),
980 GTK_PARAM_READWRITE));
981 g_object_class_install_property (gobject_class,
983 g_param_spec_boolean ("visible",
985 P_("Whether the widget is visible"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_boolean ("sensitive",
992 P_("Whether the widget responds to input"),
994 GTK_PARAM_READWRITE));
995 g_object_class_install_property (gobject_class,
997 g_param_spec_boolean ("app-paintable",
998 P_("Application paintable"),
999 P_("Whether the application will paint directly on the widget"),
1001 GTK_PARAM_READWRITE));
1002 g_object_class_install_property (gobject_class,
1004 g_param_spec_boolean ("can-focus",
1006 P_("Whether the widget can accept the input focus"),
1008 GTK_PARAM_READWRITE));
1009 g_object_class_install_property (gobject_class,
1011 g_param_spec_boolean ("has-focus",
1013 P_("Whether the widget has the input focus"),
1015 GTK_PARAM_READWRITE));
1016 g_object_class_install_property (gobject_class,
1018 g_param_spec_boolean ("is-focus",
1020 P_("Whether the widget is the focus widget within the toplevel"),
1022 GTK_PARAM_READWRITE));
1023 g_object_class_install_property (gobject_class,
1025 g_param_spec_boolean ("can-default",
1027 P_("Whether the widget can be the default widget"),
1029 GTK_PARAM_READWRITE));
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_boolean ("has-default",
1034 P_("Whether the widget is the default widget"),
1036 GTK_PARAM_READWRITE));
1037 g_object_class_install_property (gobject_class,
1038 PROP_RECEIVES_DEFAULT,
1039 g_param_spec_boolean ("receives-default",
1040 P_("Receives default"),
1041 P_("If TRUE, the widget will receive the default action when it is focused"),
1043 GTK_PARAM_READWRITE));
1044 g_object_class_install_property (gobject_class,
1045 PROP_COMPOSITE_CHILD,
1046 g_param_spec_boolean ("composite-child",
1047 P_("Composite child"),
1048 P_("Whether the widget is part of a composite widget"),
1050 GTK_PARAM_READABLE));
1051 g_object_class_install_property (gobject_class,
1053 g_param_spec_object ("style",
1055 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1057 GTK_PARAM_READWRITE));
1058 g_object_class_install_property (gobject_class,
1060 g_param_spec_flags ("events",
1062 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1063 GDK_TYPE_EVENT_MASK,
1065 GTK_PARAM_READWRITE));
1066 g_object_class_install_property (gobject_class,
1068 g_param_spec_boolean ("no-show-all",
1070 P_("Whether gtk_widget_show_all() should not affect this widget"),
1072 GTK_PARAM_READWRITE));
1075 * GtkWidget:has-tooltip:
1077 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1078 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1079 * the widget will be queried using #GtkWidget::query-tooltip to determine
1080 * whether it will provide a tooltip or not.
1082 * Note that setting this property to %TRUE for the first time will change
1083 * the event masks of the GdkWindows of this widget to include leave-notify
1084 * and motion-notify events. This cannot and will not be undone when the
1085 * property is set to %FALSE again.
1089 g_object_class_install_property (gobject_class,
1091 g_param_spec_boolean ("has-tooltip",
1093 P_("Whether this widget has a tooltip"),
1095 GTK_PARAM_READWRITE));
1097 * GtkWidget:tooltip-text:
1099 * Sets the text of tooltip to be the given string.
1101 * Also see gtk_tooltip_set_text().
1103 * This is a convenience property which will take care of getting the
1104 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1105 * will automatically be set to %TRUE and there will be taken care of
1106 * #GtkWidget::query-tooltip in the default signal handler.
1110 g_object_class_install_property (gobject_class,
1112 g_param_spec_string ("tooltip-text",
1114 P_("The contents of the tooltip for this widget"),
1116 GTK_PARAM_READWRITE));
1118 * GtkWidget:tooltip-markup:
1120 * Sets the text of tooltip to be the given string, which is marked up
1121 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1122 * Also see gtk_tooltip_set_markup().
1124 * This is a convenience property which will take care of getting the
1125 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1126 * will automatically be set to %TRUE and there will be taken care of
1127 * #GtkWidget::query-tooltip in the default signal handler.
1131 g_object_class_install_property (gobject_class,
1132 PROP_TOOLTIP_MARKUP,
1133 g_param_spec_string ("tooltip-markup",
1134 P_("Tooltip markup"),
1135 P_("The contents of the tooltip for this widget"),
1137 GTK_PARAM_READWRITE));
1142 * The widget's window if it is realized, %NULL otherwise.
1146 g_object_class_install_property (gobject_class,
1148 g_param_spec_object ("window",
1150 P_("The widget's window if it is realized"),
1152 GTK_PARAM_READABLE));
1155 * GtkWidget:double-buffered
1157 * Whether the widget is double buffered.
1161 g_object_class_install_property (gobject_class,
1162 PROP_DOUBLE_BUFFERED,
1163 g_param_spec_boolean ("double-buffered",
1164 P_("Double Buffered"),
1165 P_("Whether the widget is double buffered"),
1167 GTK_PARAM_READWRITE));
1172 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1176 g_object_class_install_property (gobject_class,
1178 g_param_spec_enum ("halign",
1179 P_("Horizontal Alignment"),
1180 P_("How to position in extra horizontal space"),
1183 GTK_PARAM_READWRITE));
1188 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1192 g_object_class_install_property (gobject_class,
1194 g_param_spec_enum ("valign",
1195 P_("Vertical Alignment"),
1196 P_("How to position in extra vertical space"),
1199 GTK_PARAM_READWRITE));
1202 * GtkWidget:margin-left
1204 * Margin on left side of widget.
1206 * This property adds margin outside of the widget's normal size
1207 * request, the margin will be added in addition to the size from
1208 * gtk_widget_set_size_request() for example.
1212 g_object_class_install_property (gobject_class,
1214 g_param_spec_int ("margin-left",
1215 P_("Margin on Left"),
1216 P_("Pixels of extra space on the left side"),
1220 GTK_PARAM_READWRITE));
1223 * GtkWidget:margin-right
1225 * Margin on right side of widget.
1227 * This property adds margin outside of the widget's normal size
1228 * request, the margin will be added in addition to the size from
1229 * gtk_widget_set_size_request() for example.
1233 g_object_class_install_property (gobject_class,
1235 g_param_spec_int ("margin-right",
1236 P_("Margin on Right"),
1237 P_("Pixels of extra space on the right side"),
1241 GTK_PARAM_READWRITE));
1244 * GtkWidget:margin-top
1246 * Margin on top side of widget.
1248 * This property adds margin outside of the widget's normal size
1249 * request, the margin will be added in addition to the size from
1250 * gtk_widget_set_size_request() for example.
1254 g_object_class_install_property (gobject_class,
1256 g_param_spec_int ("margin-top",
1257 P_("Margin on Top"),
1258 P_("Pixels of extra space on the top side"),
1262 GTK_PARAM_READWRITE));
1265 * GtkWidget:margin-bottom
1267 * Margin on bottom side of widget.
1269 * This property adds margin outside of the widget's normal size
1270 * request, the margin will be added in addition to the size from
1271 * gtk_widget_set_size_request() for example.
1275 g_object_class_install_property (gobject_class,
1277 g_param_spec_int ("margin-bottom",
1278 P_("Margin on Bottom"),
1279 P_("Pixels of extra space on the bottom side"),
1283 GTK_PARAM_READWRITE));
1288 * Sets all four sides' margin at once. If read, returns max
1289 * margin on any side.
1293 g_object_class_install_property (gobject_class,
1295 g_param_spec_int ("margin",
1297 P_("Pixels of extra space on all four sides"),
1301 GTK_PARAM_READWRITE));
1304 * GtkWidget::destroy:
1305 * @object: the object which received the signal
1307 * Signals that all holders of a reference to the widget should release
1308 * the reference that they hold. May result in finalization of the widget
1309 * if all references are released.
1311 widget_signals[DESTROY] =
1312 g_signal_new (I_("destroy"),
1313 G_TYPE_FROM_CLASS (gobject_class),
1314 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1315 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1317 _gtk_marshal_VOID__VOID,
1323 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1327 g_object_class_install_property (gobject_class,
1329 g_param_spec_boolean ("hexpand",
1330 P_("Horizontal Expand"),
1331 P_("Whether widget wants more horizontal space"),
1333 GTK_PARAM_READWRITE));
1336 * GtkWidget:hexpand-set
1338 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1342 g_object_class_install_property (gobject_class,
1344 g_param_spec_boolean ("hexpand-set",
1345 P_("Horizontal Expand Set"),
1346 P_("Whether to use the hexpand property"),
1348 GTK_PARAM_READWRITE));
1353 * Whether to expand vertically. See gtk_widget_set_vexpand().
1357 g_object_class_install_property (gobject_class,
1359 g_param_spec_boolean ("vexpand",
1360 P_("Vertical Expand"),
1361 P_("Whether widget wants more vertical space"),
1363 GTK_PARAM_READWRITE));
1366 * GtkWidget:vexpand-set
1368 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1372 g_object_class_install_property (gobject_class,
1374 g_param_spec_boolean ("vexpand-set",
1375 P_("Vertical Expand Set"),
1376 P_("Whether to use the vexpand property"),
1378 GTK_PARAM_READWRITE));
1383 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1387 g_object_class_install_property (gobject_class,
1389 g_param_spec_boolean ("expand",
1391 P_("Whether widget wants to expand in both directions"),
1393 GTK_PARAM_READWRITE));
1397 * @widget: the object which received the signal.
1399 widget_signals[SHOW] =
1400 g_signal_new (I_("show"),
1401 G_TYPE_FROM_CLASS (gobject_class),
1403 G_STRUCT_OFFSET (GtkWidgetClass, show),
1405 _gtk_marshal_VOID__VOID,
1410 * @widget: the object which received the signal.
1412 widget_signals[HIDE] =
1413 g_signal_new (I_("hide"),
1414 G_TYPE_FROM_CLASS (gobject_class),
1416 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1418 _gtk_marshal_VOID__VOID,
1423 * @widget: the object which received the signal.
1425 widget_signals[MAP] =
1426 g_signal_new (I_("map"),
1427 G_TYPE_FROM_CLASS (gobject_class),
1429 G_STRUCT_OFFSET (GtkWidgetClass, map),
1431 _gtk_marshal_VOID__VOID,
1436 * @widget: the object which received the signal.
1438 widget_signals[UNMAP] =
1439 g_signal_new (I_("unmap"),
1440 G_TYPE_FROM_CLASS (gobject_class),
1442 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1444 _gtk_marshal_VOID__VOID,
1448 * GtkWidget::realize:
1449 * @widget: the object which received the signal.
1451 widget_signals[REALIZE] =
1452 g_signal_new (I_("realize"),
1453 G_TYPE_FROM_CLASS (gobject_class),
1455 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1457 _gtk_marshal_VOID__VOID,
1461 * GtkWidget::unrealize:
1462 * @widget: the object which received the signal.
1464 widget_signals[UNREALIZE] =
1465 g_signal_new (I_("unrealize"),
1466 G_TYPE_FROM_CLASS (gobject_class),
1468 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1470 _gtk_marshal_VOID__VOID,
1474 * GtkWidget::size-allocate:
1475 * @widget: the object which received the signal.
1478 widget_signals[SIZE_ALLOCATE] =
1479 g_signal_new (I_("size-allocate"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1482 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1484 _gtk_marshal_VOID__BOXED,
1486 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1489 * GtkWidget::state-changed:
1490 * @widget: the object which received the signal.
1491 * @state: the previous state
1493 * The ::state-changed signal is emitted when the widget state changes.
1494 * See gtk_widget_get_state().
1496 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1498 widget_signals[STATE_CHANGED] =
1499 g_signal_new (I_("state-changed"),
1500 G_TYPE_FROM_CLASS (gobject_class),
1502 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1504 _gtk_marshal_VOID__ENUM,
1506 GTK_TYPE_STATE_TYPE);
1509 * GtkWidget::state-flags-changed:
1510 * @widget: the object which received the signal.
1511 * @flags: The previous state flags.
1513 * The ::state-flags-changed signal is emitted when the widget state
1514 * changes, see gtk_widget_get_state_flags().
1518 widget_signals[STATE_FLAGS_CHANGED] =
1519 g_signal_new (I_("state-flags-changed"),
1520 G_TYPE_FROM_CLASS (gobject_class),
1522 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1524 _gtk_marshal_VOID__FLAGS,
1526 GTK_TYPE_STATE_FLAGS);
1529 * GtkWidget::parent-set:
1530 * @widget: the object on which the signal is emitted
1531 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1532 * just got its initial parent.
1534 * The ::parent-set signal is emitted when a new parent
1535 * has been set on a widget.
1537 widget_signals[PARENT_SET] =
1538 g_signal_new (I_("parent-set"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1541 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1543 _gtk_marshal_VOID__OBJECT,
1548 * GtkWidget::hierarchy-changed:
1549 * @widget: the object on which the signal is emitted
1550 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1551 * if the widget was previously unanchored
1553 * The ::hierarchy-changed signal is emitted when the
1554 * anchored state of a widget changes. A widget is
1555 * <firstterm>anchored</firstterm> when its toplevel
1556 * ancestor is a #GtkWindow. This signal is emitted when
1557 * a widget changes from un-anchored to anchored or vice-versa.
1559 widget_signals[HIERARCHY_CHANGED] =
1560 g_signal_new (I_("hierarchy-changed"),
1561 G_TYPE_FROM_CLASS (gobject_class),
1563 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1565 _gtk_marshal_VOID__OBJECT,
1570 * GtkWidget::style-set:
1571 * @widget: the object on which the signal is emitted
1572 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1573 * just got its initial style
1575 * The ::style-set signal is emitted when a new style has been set
1576 * on a widget. Note that style-modifying functions like
1577 * gtk_widget_modify_base() also cause this signal to be emitted.
1579 * Note that this signal is emitted for changes to the deprecated
1580 * #GtkStyle. To track changes to the #GtkStyleContext associated
1581 * with a widget, use the #GtkWidget::style-updated signal.
1583 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1585 widget_signals[STYLE_SET] =
1586 g_signal_new (I_("style-set"),
1587 G_TYPE_FROM_CLASS (gobject_class),
1589 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1591 _gtk_marshal_VOID__OBJECT,
1596 * GtkWidget::style-updated:
1597 * @widget: the object on which the signal is emitted
1599 * The ::style-updated signal is emitted when the #GtkStyleContext
1600 * of a widget is changed. Note that style-modifying functions like
1601 * gtk_widget_override_color() also cause this signal to be emitted.
1605 widget_signals[STYLE_UPDATED] =
1606 g_signal_new (I_("style-updated"),
1607 G_TYPE_FROM_CLASS (gobject_class),
1609 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1611 g_cclosure_marshal_VOID__VOID,
1615 * GtkWidget::direction-changed:
1616 * @widget: the object on which the signal is emitted
1617 * @previous_direction: the previous text direction of @widget
1619 * The ::direction-changed signal is emitted when the text direction
1620 * of a widget changes.
1622 widget_signals[DIRECTION_CHANGED] =
1623 g_signal_new (I_("direction-changed"),
1624 G_TYPE_FROM_CLASS (gobject_class),
1626 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1628 _gtk_marshal_VOID__ENUM,
1630 GTK_TYPE_TEXT_DIRECTION);
1633 * GtkWidget::grab-notify:
1634 * @widget: the object which received the signal
1635 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1636 * if it becomes unshadowed
1638 * The ::grab-notify signal is emitted when a widget becomes
1639 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1640 * another widget, or when it becomes unshadowed due to a grab
1643 * A widget is shadowed by a gtk_grab_add() when the topmost
1644 * grab widget in the grab stack of its window group is not
1647 widget_signals[GRAB_NOTIFY] =
1648 g_signal_new (I_("grab-notify"),
1649 G_TYPE_FROM_CLASS (gobject_class),
1651 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1653 _gtk_marshal_VOID__BOOLEAN,
1658 * GtkWidget::child-notify:
1659 * @widget: the object which received the signal
1660 * @pspec: the #GParamSpec of the changed child property
1662 * The ::child-notify signal is emitted for each
1663 * <link linkend="child-properties">child property</link> that has
1664 * changed on an object. The signal's detail holds the property name.
1666 widget_signals[CHILD_NOTIFY] =
1667 g_signal_new (I_("child-notify"),
1668 G_TYPE_FROM_CLASS (gobject_class),
1669 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1670 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1672 g_cclosure_marshal_VOID__PARAM,
1678 * @widget: the object which received the signal
1679 * @cr: the cairo context to draw to
1681 * This signal is emitted when a widget is supposed to render itself.
1682 * The @widget's top left corner must be painted at the origin of
1683 * the passed in context and be sized to the values returned by
1684 * gtk_widget_get_allocated_width() and
1685 * gtk_widget_get_allocated_height().
1687 * Signal handlers connected to this signal can modify the cairo
1688 * context passed as @cr in any way they like and don't need to
1689 * restore it. The signal emission takes care of calling cairo_save()
1690 * before and cairo_restore() after invoking the handler.
1694 widget_signals[DRAW] =
1695 g_signal_new (I_("draw"),
1696 G_TYPE_FROM_CLASS (gobject_class),
1698 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1699 _gtk_boolean_handled_accumulator, NULL,
1700 gtk_widget_draw_marshaller,
1702 CAIRO_GOBJECT_TYPE_CONTEXT);
1705 * GtkWidget::mnemonic-activate:
1706 * @widget: the object which received the signal.
1709 widget_signals[MNEMONIC_ACTIVATE] =
1710 g_signal_new (I_("mnemonic-activate"),
1711 G_TYPE_FROM_CLASS (gobject_class),
1713 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1714 _gtk_boolean_handled_accumulator, NULL,
1715 _gtk_marshal_BOOLEAN__BOOLEAN,
1720 * GtkWidget::grab-focus:
1721 * @widget: the object which received the signal.
1723 widget_signals[GRAB_FOCUS] =
1724 g_signal_new (I_("grab-focus"),
1725 G_TYPE_FROM_CLASS (gobject_class),
1726 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1727 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1729 _gtk_marshal_VOID__VOID,
1734 * @widget: the object which received the signal.
1737 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1739 widget_signals[FOCUS] =
1740 g_signal_new (I_("focus"),
1741 G_TYPE_FROM_CLASS (klass),
1743 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1744 _gtk_boolean_handled_accumulator, NULL,
1745 _gtk_marshal_BOOLEAN__ENUM,
1747 GTK_TYPE_DIRECTION_TYPE);
1750 * GtkWidget::move-focus:
1751 * @widget: the object which received the signal.
1754 widget_signals[MOVE_FOCUS] =
1755 g_signal_new (I_("move-focus"),
1756 G_TYPE_FROM_CLASS (klass),
1757 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1758 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1760 _gtk_marshal_VOID__ENUM,
1763 GTK_TYPE_DIRECTION_TYPE);
1766 * GtkWidget::keynav-failed:
1767 * @widget: the object which received the signal
1768 * @direction: the direction of movement
1770 * Gets emitted if keyboard navigation fails.
1771 * See gtk_widget_keynav_failed() for details.
1773 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1774 * if the emitting widget should try to handle the keyboard
1775 * navigation attempt in its parent container(s).
1779 widget_signals[KEYNAV_FAILED] =
1780 g_signal_new (I_("keynav-failed"),
1781 G_TYPE_FROM_CLASS (klass),
1783 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1784 _gtk_boolean_handled_accumulator, NULL,
1785 _gtk_marshal_BOOLEAN__ENUM,
1787 GTK_TYPE_DIRECTION_TYPE);
1791 * @widget: the object which received the signal.
1792 * @event: the #GdkEvent which triggered this signal
1794 * The GTK+ main loop will emit three signals for each GDK event delivered
1795 * to a widget: one generic ::event signal, another, more specific,
1796 * signal that matches the type of event delivered (e.g.
1797 * #GtkWidget::key-press-event) and finally a generic
1798 * #GtkWidget::event-after signal.
1800 * Returns: %TRUE to stop other handlers from being invoked for the event
1801 * and to cancel the emission of the second specific ::event signal.
1802 * %FALSE to propagate the event further and to allow the emission of
1803 * the second signal. The ::event-after signal is emitted regardless of
1806 widget_signals[EVENT] =
1807 g_signal_new (I_("event"),
1808 G_TYPE_FROM_CLASS (klass),
1810 G_STRUCT_OFFSET (GtkWidgetClass, event),
1811 _gtk_boolean_handled_accumulator, NULL,
1812 _gtk_marshal_BOOLEAN__BOXED,
1814 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1817 * GtkWidget::event-after:
1818 * @widget: the object which received the signal.
1819 * @event: the #GdkEvent which triggered this signal
1821 * After the emission of the #GtkWidget::event signal and (optionally)
1822 * the second more specific signal, ::event-after will be emitted
1823 * regardless of the previous two signals handlers return values.
1826 widget_signals[EVENT_AFTER] =
1827 g_signal_new (I_("event-after"),
1828 G_TYPE_FROM_CLASS (klass),
1832 _gtk_marshal_VOID__BOXED,
1834 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1837 * GtkWidget::button-press-event:
1838 * @widget: the object which received the signal.
1839 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1842 * The ::button-press-event signal will be emitted when a button
1843 * (typically from a mouse) is pressed.
1845 * To receive this signal, the #GdkWindow associated to the
1846 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1848 * This signal will be sent to the grab widget if there is one.
1850 * Returns: %TRUE to stop other handlers from being invoked for the event.
1851 * %FALSE to propagate the event further.
1853 widget_signals[BUTTON_PRESS_EVENT] =
1854 g_signal_new (I_("button-press-event"),
1855 G_TYPE_FROM_CLASS (klass),
1857 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1858 _gtk_boolean_handled_accumulator, NULL,
1859 _gtk_marshal_BOOLEAN__BOXED,
1861 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1864 * GtkWidget::button-release-event:
1865 * @widget: the object which received the signal.
1866 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1869 * The ::button-release-event signal will be emitted when a button
1870 * (typically from a mouse) is released.
1872 * To receive this signal, the #GdkWindow associated to the
1873 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1875 * This signal will be sent to the grab widget if there is one.
1877 * Returns: %TRUE to stop other handlers from being invoked for the event.
1878 * %FALSE to propagate the event further.
1880 widget_signals[BUTTON_RELEASE_EVENT] =
1881 g_signal_new (I_("button-release-event"),
1882 G_TYPE_FROM_CLASS (klass),
1884 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1885 _gtk_boolean_handled_accumulator, NULL,
1886 _gtk_marshal_BOOLEAN__BOXED,
1888 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1890 widget_signals[TOUCH_EVENT] =
1891 g_signal_new (I_("touch-event"),
1892 G_TYPE_FROM_CLASS (klass),
1894 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1895 _gtk_boolean_handled_accumulator, NULL,
1896 _gtk_marshal_BOOLEAN__BOXED,
1898 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1900 * GtkWidget::scroll-event:
1901 * @widget: the object which received the signal.
1902 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1905 * The ::scroll-event signal is emitted when a button in the 4 to 7
1906 * range is pressed. Wheel mice are usually configured to generate
1907 * button press events for buttons 4 and 5 when the wheel is turned.
1909 * To receive this signal, the #GdkWindow associated to the widget needs
1910 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1912 * This signal will be sent to the grab widget if there is one.
1914 * Returns: %TRUE to stop other handlers from being invoked for the event.
1915 * %FALSE to propagate the event further.
1917 widget_signals[SCROLL_EVENT] =
1918 g_signal_new (I_("scroll-event"),
1919 G_TYPE_FROM_CLASS (klass),
1921 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1922 _gtk_boolean_handled_accumulator, NULL,
1923 _gtk_marshal_BOOLEAN__BOXED,
1925 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1928 * GtkWidget::motion-notify-event:
1929 * @widget: the object which received the signal.
1930 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1933 * The ::motion-notify-event signal is emitted when the pointer moves
1934 * over the widget's #GdkWindow.
1936 * To receive this signal, the #GdkWindow associated to the widget
1937 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1939 * This signal will be sent to the grab widget if there is one.
1941 * Returns: %TRUE to stop other handlers from being invoked for the event.
1942 * %FALSE to propagate the event further.
1944 widget_signals[MOTION_NOTIFY_EVENT] =
1945 g_signal_new (I_("motion-notify-event"),
1946 G_TYPE_FROM_CLASS (klass),
1948 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1949 _gtk_boolean_handled_accumulator, NULL,
1950 _gtk_marshal_BOOLEAN__BOXED,
1952 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1955 * GtkWidget::composited-changed:
1956 * @widget: the object on which the signal is emitted
1958 * The ::composited-changed signal is emitted when the composited
1959 * status of @widget<!-- -->s screen changes.
1960 * See gdk_screen_is_composited().
1962 widget_signals[COMPOSITED_CHANGED] =
1963 g_signal_new (I_("composited-changed"),
1964 G_TYPE_FROM_CLASS (klass),
1965 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1966 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1968 _gtk_marshal_VOID__VOID,
1972 * GtkWidget::delete-event:
1973 * @widget: the object which received the signal
1974 * @event: the event which triggered this signal
1976 * The ::delete-event signal is emitted if a user requests that
1977 * a toplevel window is closed. The default handler for this signal
1978 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1979 * this signal will cause the window to be hidden instead, so that
1980 * it can later be shown again without reconstructing it.
1982 * Returns: %TRUE to stop other handlers from being invoked for the event.
1983 * %FALSE to propagate the event further.
1985 widget_signals[DELETE_EVENT] =
1986 g_signal_new (I_("delete-event"),
1987 G_TYPE_FROM_CLASS (klass),
1989 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1990 _gtk_boolean_handled_accumulator, NULL,
1991 _gtk_marshal_BOOLEAN__BOXED,
1993 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1996 * GtkWidget::destroy-event:
1997 * @widget: the object which received the signal.
1998 * @event: the event which triggered this signal
2000 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2001 * You rarely get this signal, because most widgets disconnect themselves
2002 * from their window before they destroy it, so no widget owns the
2003 * window at destroy time.
2005 * To receive this signal, the #GdkWindow associated to the widget needs
2006 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2007 * automatically for all new windows.
2009 * Returns: %TRUE to stop other handlers from being invoked for the event.
2010 * %FALSE to propagate the event further.
2012 widget_signals[DESTROY_EVENT] =
2013 g_signal_new (I_("destroy-event"),
2014 G_TYPE_FROM_CLASS (klass),
2016 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2017 _gtk_boolean_handled_accumulator, NULL,
2018 _gtk_marshal_BOOLEAN__BOXED,
2020 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2023 * GtkWidget::key-press-event:
2024 * @widget: the object which received the signal
2025 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2027 * The ::key-press-event signal is emitted when a key is pressed. The signal
2028 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2030 * To receive this signal, the #GdkWindow associated to the widget needs
2031 * to enable the #GDK_KEY_PRESS_MASK mask.
2033 * This signal will be sent to the grab widget if there is one.
2035 * Returns: %TRUE to stop other handlers from being invoked for the event.
2036 * %FALSE to propagate the event further.
2038 widget_signals[KEY_PRESS_EVENT] =
2039 g_signal_new (I_("key-press-event"),
2040 G_TYPE_FROM_CLASS (klass),
2042 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2043 _gtk_boolean_handled_accumulator, NULL,
2044 _gtk_marshal_BOOLEAN__BOXED,
2046 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2049 * GtkWidget::key-release-event:
2050 * @widget: the object which received the signal
2051 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2053 * The ::key-release-event signal is emitted when a key is released.
2055 * To receive this signal, the #GdkWindow associated to the widget needs
2056 * to enable the #GDK_KEY_RELEASE_MASK mask.
2058 * This signal will be sent to the grab widget if there is one.
2060 * Returns: %TRUE to stop other handlers from being invoked for the event.
2061 * %FALSE to propagate the event further.
2063 widget_signals[KEY_RELEASE_EVENT] =
2064 g_signal_new (I_("key-release-event"),
2065 G_TYPE_FROM_CLASS (klass),
2067 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2068 _gtk_boolean_handled_accumulator, NULL,
2069 _gtk_marshal_BOOLEAN__BOXED,
2071 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2074 * GtkWidget::enter-notify-event:
2075 * @widget: the object which received the signal
2076 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2079 * The ::enter-notify-event will be emitted when the pointer enters
2080 * the @widget's window.
2082 * To receive this signal, the #GdkWindow associated to the widget needs
2083 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2085 * This signal will be sent to the grab widget if there is one.
2087 * Returns: %TRUE to stop other handlers from being invoked for the event.
2088 * %FALSE to propagate the event further.
2090 widget_signals[ENTER_NOTIFY_EVENT] =
2091 g_signal_new (I_("enter-notify-event"),
2092 G_TYPE_FROM_CLASS (klass),
2094 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2095 _gtk_boolean_handled_accumulator, NULL,
2096 _gtk_marshal_BOOLEAN__BOXED,
2098 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2101 * GtkWidget::leave-notify-event:
2102 * @widget: the object which received the signal
2103 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2106 * The ::leave-notify-event will be emitted when the pointer leaves
2107 * the @widget's window.
2109 * To receive this signal, the #GdkWindow associated to the widget needs
2110 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2112 * This signal will be sent to the grab widget if there is one.
2114 * Returns: %TRUE to stop other handlers from being invoked for the event.
2115 * %FALSE to propagate the event further.
2117 widget_signals[LEAVE_NOTIFY_EVENT] =
2118 g_signal_new (I_("leave-notify-event"),
2119 G_TYPE_FROM_CLASS (klass),
2121 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2122 _gtk_boolean_handled_accumulator, NULL,
2123 _gtk_marshal_BOOLEAN__BOXED,
2125 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2128 * GtkWidget::configure-event:
2129 * @widget: the object which received the signal
2130 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2133 * The ::configure-event signal will be emitted when the size, position or
2134 * stacking of the @widget's window has changed.
2136 * To receive this signal, the #GdkWindow associated to the widget needs
2137 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2138 * automatically for all new windows.
2140 * Returns: %TRUE to stop other handlers from being invoked for the event.
2141 * %FALSE to propagate the event further.
2143 widget_signals[CONFIGURE_EVENT] =
2144 g_signal_new (I_("configure-event"),
2145 G_TYPE_FROM_CLASS (klass),
2147 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2148 _gtk_boolean_handled_accumulator, NULL,
2149 _gtk_marshal_BOOLEAN__BOXED,
2151 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2154 * GtkWidget::focus-in-event:
2155 * @widget: the object which received the signal
2156 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2159 * The ::focus-in-event signal will be emitted when the keyboard focus
2160 * enters the @widget's window.
2162 * To receive this signal, the #GdkWindow associated to the widget needs
2163 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2165 * Returns: %TRUE to stop other handlers from being invoked for the event.
2166 * %FALSE to propagate the event further.
2168 widget_signals[FOCUS_IN_EVENT] =
2169 g_signal_new (I_("focus-in-event"),
2170 G_TYPE_FROM_CLASS (klass),
2172 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2173 _gtk_boolean_handled_accumulator, NULL,
2174 _gtk_marshal_BOOLEAN__BOXED,
2176 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2179 * GtkWidget::focus-out-event:
2180 * @widget: the object which received the signal
2181 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2184 * The ::focus-out-event signal will be emitted when the keyboard focus
2185 * leaves the @widget's window.
2187 * To receive this signal, the #GdkWindow associated to the widget needs
2188 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2190 * Returns: %TRUE to stop other handlers from being invoked for the event.
2191 * %FALSE to propagate the event further.
2193 widget_signals[FOCUS_OUT_EVENT] =
2194 g_signal_new (I_("focus-out-event"),
2195 G_TYPE_FROM_CLASS (klass),
2197 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2198 _gtk_boolean_handled_accumulator, NULL,
2199 _gtk_marshal_BOOLEAN__BOXED,
2201 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2204 * GtkWidget::map-event:
2205 * @widget: the object which received the signal
2206 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2208 * The ::map-event signal will be emitted when the @widget's window is
2209 * mapped. A window is mapped when it becomes visible on the screen.
2211 * To receive this signal, the #GdkWindow associated to the widget needs
2212 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2213 * automatically for all new windows.
2215 * Returns: %TRUE to stop other handlers from being invoked for the event.
2216 * %FALSE to propagate the event further.
2218 widget_signals[MAP_EVENT] =
2219 g_signal_new (I_("map-event"),
2220 G_TYPE_FROM_CLASS (klass),
2222 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2223 _gtk_boolean_handled_accumulator, NULL,
2224 _gtk_marshal_BOOLEAN__BOXED,
2226 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2229 * GtkWidget::unmap-event:
2230 * @widget: the object which received the signal
2231 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2233 * The ::unmap-event signal will be emitted when the @widget's window is
2234 * unmapped. A window is unmapped when it becomes invisible on the screen.
2236 * To receive this signal, the #GdkWindow associated to the widget needs
2237 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2238 * automatically for all new windows.
2240 * Returns: %TRUE to stop other handlers from being invoked for the event.
2241 * %FALSE to propagate the event further.
2243 widget_signals[UNMAP_EVENT] =
2244 g_signal_new (I_("unmap-event"),
2245 G_TYPE_FROM_CLASS (klass),
2247 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2248 _gtk_boolean_handled_accumulator, NULL,
2249 _gtk_marshal_BOOLEAN__BOXED,
2251 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2254 * GtkWidget::property-notify-event:
2255 * @widget: the object which received the signal
2256 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2259 * The ::property-notify-event signal will be emitted when a property on
2260 * the @widget's window has been changed or deleted.
2262 * To receive this signal, the #GdkWindow associated to the widget needs
2263 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2265 * Returns: %TRUE to stop other handlers from being invoked for the event.
2266 * %FALSE to propagate the event further.
2268 widget_signals[PROPERTY_NOTIFY_EVENT] =
2269 g_signal_new (I_("property-notify-event"),
2270 G_TYPE_FROM_CLASS (klass),
2272 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2273 _gtk_boolean_handled_accumulator, NULL,
2274 _gtk_marshal_BOOLEAN__BOXED,
2276 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2279 * GtkWidget::selection-clear-event:
2280 * @widget: the object which received the signal
2281 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2284 * The ::selection-clear-event signal will be emitted when the
2285 * the @widget's window has lost ownership of a selection.
2287 * Returns: %TRUE to stop other handlers from being invoked for the event.
2288 * %FALSE to propagate the event further.
2290 widget_signals[SELECTION_CLEAR_EVENT] =
2291 g_signal_new (I_("selection-clear-event"),
2292 G_TYPE_FROM_CLASS (klass),
2294 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2295 _gtk_boolean_handled_accumulator, NULL,
2296 _gtk_marshal_BOOLEAN__BOXED,
2298 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2301 * GtkWidget::selection-request-event:
2302 * @widget: the object which received the signal
2303 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2306 * The ::selection-request-event signal will be emitted when
2307 * another client requests ownership of the selection owned by
2308 * the @widget's window.
2310 * Returns: %TRUE to stop other handlers from being invoked for the event.
2311 * %FALSE to propagate the event further.
2313 widget_signals[SELECTION_REQUEST_EVENT] =
2314 g_signal_new (I_("selection-request-event"),
2315 G_TYPE_FROM_CLASS (klass),
2317 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2318 _gtk_boolean_handled_accumulator, NULL,
2319 _gtk_marshal_BOOLEAN__BOXED,
2321 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2324 * GtkWidget::selection-notify-event:
2325 * @widget: the object which received the signal.
2326 * @event: (type Gdk.EventSelection):
2328 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2330 widget_signals[SELECTION_NOTIFY_EVENT] =
2331 g_signal_new (I_("selection-notify-event"),
2332 G_TYPE_FROM_CLASS (klass),
2334 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2335 _gtk_boolean_handled_accumulator, NULL,
2336 _gtk_marshal_BOOLEAN__BOXED,
2338 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2341 * GtkWidget::selection-received:
2342 * @widget: the object which received the signal.
2346 widget_signals[SELECTION_RECEIVED] =
2347 g_signal_new (I_("selection-received"),
2348 G_TYPE_FROM_CLASS (klass),
2350 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2352 _gtk_marshal_VOID__BOXED_UINT,
2354 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2358 * GtkWidget::selection-get:
2359 * @widget: the object which received the signal.
2364 widget_signals[SELECTION_GET] =
2365 g_signal_new (I_("selection-get"),
2366 G_TYPE_FROM_CLASS (klass),
2368 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2370 _gtk_marshal_VOID__BOXED_UINT_UINT,
2372 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2377 * GtkWidget::proximity-in-event:
2378 * @widget: the object which received the signal
2379 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2382 * To receive this signal the #GdkWindow associated to the widget needs
2383 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2385 * This signal will be sent to the grab widget if there is one.
2387 * Returns: %TRUE to stop other handlers from being invoked for the event.
2388 * %FALSE to propagate the event further.
2390 widget_signals[PROXIMITY_IN_EVENT] =
2391 g_signal_new (I_("proximity-in-event"),
2392 G_TYPE_FROM_CLASS (klass),
2394 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2395 _gtk_boolean_handled_accumulator, NULL,
2396 _gtk_marshal_BOOLEAN__BOXED,
2398 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2401 * GtkWidget::proximity-out-event:
2402 * @widget: the object which received the signal
2403 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2406 * To receive this signal the #GdkWindow associated to the widget needs
2407 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2409 * This signal will be sent to the grab widget if there is one.
2411 * Returns: %TRUE to stop other handlers from being invoked for the event.
2412 * %FALSE to propagate the event further.
2414 widget_signals[PROXIMITY_OUT_EVENT] =
2415 g_signal_new (I_("proximity-out-event"),
2416 G_TYPE_FROM_CLASS (klass),
2418 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2419 _gtk_boolean_handled_accumulator, NULL,
2420 _gtk_marshal_BOOLEAN__BOXED,
2422 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2425 * GtkWidget::drag-leave:
2426 * @widget: the object which received the signal.
2427 * @drag_context: the drag context
2428 * @time: the timestamp of the motion event
2430 * The ::drag-leave signal is emitted on the drop site when the cursor
2431 * leaves the widget. A typical reason to connect to this signal is to
2432 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2433 * with gtk_drag_unhighlight()
2435 widget_signals[DRAG_LEAVE] =
2436 g_signal_new (I_("drag-leave"),
2437 G_TYPE_FROM_CLASS (klass),
2439 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2441 _gtk_marshal_VOID__OBJECT_UINT,
2443 GDK_TYPE_DRAG_CONTEXT,
2447 * GtkWidget::drag-begin:
2448 * @widget: the object which received the signal
2449 * @drag_context: the drag context
2451 * The ::drag-begin signal is emitted on the drag source when a drag is
2452 * started. A typical reason to connect to this signal is to set up a
2453 * custom drag icon with gtk_drag_source_set_icon().
2455 * Note that some widgets set up a drag icon in the default handler of
2456 * this signal, so you may have to use g_signal_connect_after() to
2457 * override what the default handler did.
2459 widget_signals[DRAG_BEGIN] =
2460 g_signal_new (I_("drag-begin"),
2461 G_TYPE_FROM_CLASS (klass),
2463 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2465 _gtk_marshal_VOID__OBJECT,
2467 GDK_TYPE_DRAG_CONTEXT);
2470 * GtkWidget::drag-end:
2471 * @widget: the object which received the signal
2472 * @drag_context: the drag context
2474 * The ::drag-end signal is emitted on the drag source when a drag is
2475 * finished. A typical reason to connect to this signal is to undo
2476 * things done in #GtkWidget::drag-begin.
2478 widget_signals[DRAG_END] =
2479 g_signal_new (I_("drag-end"),
2480 G_TYPE_FROM_CLASS (klass),
2482 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2484 _gtk_marshal_VOID__OBJECT,
2486 GDK_TYPE_DRAG_CONTEXT);
2489 * GtkWidget::drag-data-delete:
2490 * @widget: the object which received the signal
2491 * @drag_context: the drag context
2493 * The ::drag-data-delete signal is emitted on the drag source when a drag
2494 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2495 * handler is responsible for deleting the data that has been dropped. What
2496 * "delete" means depends on the context of the drag operation.
2498 widget_signals[DRAG_DATA_DELETE] =
2499 g_signal_new (I_("drag-data-delete"),
2500 G_TYPE_FROM_CLASS (klass),
2502 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2504 _gtk_marshal_VOID__OBJECT,
2506 GDK_TYPE_DRAG_CONTEXT);
2509 * GtkWidget::drag-failed:
2510 * @widget: the object which received the signal
2511 * @drag_context: the drag context
2512 * @result: the result of the drag operation
2514 * The ::drag-failed signal is emitted on the drag source when a drag has
2515 * failed. The signal handler may hook custom code to handle a failed DND
2516 * operation based on the type of error, it returns %TRUE is the failure has
2517 * been already handled (not showing the default "drag operation failed"
2518 * animation), otherwise it returns %FALSE.
2520 * Return value: %TRUE if the failed drag operation has been already handled.
2524 widget_signals[DRAG_FAILED] =
2525 g_signal_new (I_("drag-failed"),
2526 G_TYPE_FROM_CLASS (klass),
2528 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2529 _gtk_boolean_handled_accumulator, NULL,
2530 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2532 GDK_TYPE_DRAG_CONTEXT,
2533 GTK_TYPE_DRAG_RESULT);
2536 * GtkWidget::drag-motion:
2537 * @widget: the object which received the signal
2538 * @drag_context: the drag context
2539 * @x: the x coordinate of the current cursor position
2540 * @y: the y coordinate of the current cursor position
2541 * @time: the timestamp of the motion event
2543 * The drag-motion signal is emitted on the drop site when the user
2544 * moves the cursor over the widget during a drag. The signal handler
2545 * must determine whether the cursor position is in a drop zone or not.
2546 * If it is not in a drop zone, it returns %FALSE and no further processing
2547 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2548 * handler is responsible for providing the necessary information for
2549 * displaying feedback to the user, by calling gdk_drag_status().
2551 * If the decision whether the drop will be accepted or rejected can't be
2552 * made based solely on the cursor position and the type of the data, the
2553 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2554 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2555 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2556 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2557 * when using the drag-motion signal that way.
2559 * Also note that there is no drag-enter signal. The drag receiver has to
2560 * keep track of whether he has received any drag-motion signals since the
2561 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2562 * an "enter" signal. Upon an "enter", the handler will typically highlight
2563 * the drop site with gtk_drag_highlight().
2566 * drag_motion (GtkWidget *widget,
2567 * GdkDragContext *context,
2574 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2576 * if (!private_data->drag_highlight)
2578 * private_data->drag_highlight = 1;
2579 * gtk_drag_highlight (widget);
2582 * target = gtk_drag_dest_find_target (widget, context, NULL);
2583 * if (target == GDK_NONE)
2584 * gdk_drag_status (context, 0, time);
2587 * private_data->pending_status = context->suggested_action;
2588 * gtk_drag_get_data (widget, context, target, time);
2595 * drag_data_received (GtkWidget *widget,
2596 * GdkDragContext *context,
2599 * GtkSelectionData *selection_data,
2603 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2605 * if (private_data->suggested_action)
2607 * private_data->suggested_action = 0;
2609 * /* We are getting this data due to a request in drag_motion,
2610 * * rather than due to a request in drag_drop, so we are just
2611 * * supposed to call gdk_drag_status (), not actually paste in
2614 * str = gtk_selection_data_get_text (selection_data);
2615 * if (!data_is_acceptable (str))
2616 * gdk_drag_status (context, 0, time);
2618 * gdk_drag_status (context, private_data->suggested_action, time);
2622 * /* accept the drop */
2627 * Returns: whether the cursor position is in a drop zone
2629 widget_signals[DRAG_MOTION] =
2630 g_signal_new (I_("drag-motion"),
2631 G_TYPE_FROM_CLASS (klass),
2633 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2634 _gtk_boolean_handled_accumulator, NULL,
2635 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2637 GDK_TYPE_DRAG_CONTEXT,
2643 * GtkWidget::drag-drop:
2644 * @widget: the object which received the signal
2645 * @drag_context: the drag context
2646 * @x: the x coordinate of the current cursor position
2647 * @y: the y coordinate of the current cursor position
2648 * @time: the timestamp of the motion event
2650 * The ::drag-drop signal is emitted on the drop site when the user drops
2651 * the data onto the widget. The signal handler must determine whether
2652 * the cursor position is in a drop zone or not. If it is not in a drop
2653 * zone, it returns %FALSE and no further processing is necessary.
2654 * Otherwise, the handler returns %TRUE. In this case, the handler must
2655 * ensure that gtk_drag_finish() is called to let the source know that
2656 * the drop is done. The call to gtk_drag_finish() can be done either
2657 * directly or in a #GtkWidget::drag-data-received handler which gets
2658 * triggered by calling gtk_drag_get_data() to receive the data for one
2659 * or more of the supported targets.
2661 * Returns: whether the cursor position is in a drop zone
2663 widget_signals[DRAG_DROP] =
2664 g_signal_new (I_("drag-drop"),
2665 G_TYPE_FROM_CLASS (klass),
2667 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2668 _gtk_boolean_handled_accumulator, NULL,
2669 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2671 GDK_TYPE_DRAG_CONTEXT,
2677 * GtkWidget::drag-data-get:
2678 * @widget: the object which received the signal
2679 * @drag_context: the drag context
2680 * @data: the #GtkSelectionData to be filled with the dragged data
2681 * @info: the info that has been registered with the target in the
2683 * @time: the timestamp at which the data was requested
2685 * The ::drag-data-get signal is emitted on the drag source when the drop
2686 * site requests the data which is dragged. It is the responsibility of
2687 * the signal handler to fill @data with the data in the format which
2688 * is indicated by @info. See gtk_selection_data_set() and
2689 * gtk_selection_data_set_text().
2691 widget_signals[DRAG_DATA_GET] =
2692 g_signal_new (I_("drag-data-get"),
2693 G_TYPE_FROM_CLASS (klass),
2695 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2697 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2699 GDK_TYPE_DRAG_CONTEXT,
2700 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2705 * GtkWidget::drag-data-received:
2706 * @widget: the object which received the signal
2707 * @drag_context: the drag context
2708 * @x: where the drop happened
2709 * @y: where the drop happened
2710 * @data: the received data
2711 * @info: the info that has been registered with the target in the
2713 * @time: the timestamp at which the data was received
2715 * The ::drag-data-received signal is emitted on the drop site when the
2716 * dragged data has been received. If the data was received in order to
2717 * determine whether the drop will be accepted, the handler is expected
2718 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2719 * If the data was received in response to a #GtkWidget::drag-drop signal
2720 * (and this is the last target to be received), the handler for this
2721 * signal is expected to process the received data and then call
2722 * gtk_drag_finish(), setting the @success parameter depending on whether
2723 * the data was processed successfully.
2725 * The handler may inspect and modify @drag_context->action before calling
2726 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2727 * following example:
2730 * drag_data_received (GtkWidget *widget,
2731 * GdkDragContext *drag_context,
2734 * GtkSelectionData *data,
2738 * if ((data->length >= 0) && (data->format == 8))
2740 * if (drag_context->action == GDK_ACTION_ASK)
2742 * GtkWidget *dialog;
2745 * dialog = gtk_message_dialog_new (NULL,
2746 * GTK_DIALOG_MODAL |
2747 * GTK_DIALOG_DESTROY_WITH_PARENT,
2749 * GTK_BUTTONS_YES_NO,
2750 * "Move the data ?\n");
2751 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2752 * gtk_widget_destroy (dialog);
2754 * if (response == GTK_RESPONSE_YES)
2755 * drag_context->action = GDK_ACTION_MOVE;
2757 * drag_context->action = GDK_ACTION_COPY;
2760 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2764 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2768 widget_signals[DRAG_DATA_RECEIVED] =
2769 g_signal_new (I_("drag-data-received"),
2770 G_TYPE_FROM_CLASS (klass),
2772 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2774 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2776 GDK_TYPE_DRAG_CONTEXT,
2779 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2784 * GtkWidget::visibility-notify-event:
2785 * @widget: the object which received the signal
2786 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2787 * triggered this signal.
2789 * The ::visibility-notify-event will be emitted when the @widget's window
2790 * is obscured or unobscured.
2792 * To receive this signal the #GdkWindow associated to the widget needs
2793 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2795 * Returns: %TRUE to stop other handlers from being invoked for the event.
2796 * %FALSE to propagate the event further.
2798 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2799 g_signal_new (I_("visibility-notify-event"),
2800 G_TYPE_FROM_CLASS (klass),
2802 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2803 _gtk_boolean_handled_accumulator, NULL,
2804 _gtk_marshal_BOOLEAN__BOXED,
2806 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2809 * GtkWidget::window-state-event:
2810 * @widget: the object which received the signal
2811 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2812 * triggered this signal.
2814 * The ::window-state-event will be emitted when the state of the
2815 * toplevel window associated to the @widget changes.
2817 * To receive this signal the #GdkWindow associated to the widget
2818 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2819 * this mask automatically for all new windows.
2821 * Returns: %TRUE to stop other handlers from being invoked for the
2822 * event. %FALSE to propagate the event further.
2824 widget_signals[WINDOW_STATE_EVENT] =
2825 g_signal_new (I_("window-state-event"),
2826 G_TYPE_FROM_CLASS (klass),
2828 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2829 _gtk_boolean_handled_accumulator, NULL,
2830 _gtk_marshal_BOOLEAN__BOXED,
2832 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2835 * GtkWidget::damage-event:
2836 * @widget: the object which received the signal
2837 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2839 * Emitted when a redirected window belonging to @widget gets drawn into.
2840 * The region/area members of the event shows what area of the redirected
2841 * drawable was drawn into.
2843 * Returns: %TRUE to stop other handlers from being invoked for the event.
2844 * %FALSE to propagate the event further.
2848 widget_signals[DAMAGE_EVENT] =
2849 g_signal_new (I_("damage-event"),
2850 G_TYPE_FROM_CLASS (klass),
2852 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2853 _gtk_boolean_handled_accumulator, NULL,
2854 _gtk_marshal_BOOLEAN__BOXED,
2856 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2859 * GtkWidget::grab-broken-event:
2860 * @widget: the object which received the signal
2861 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2863 * Emitted when a pointer or keyboard grab on a window belonging
2864 * to @widget gets broken.
2866 * On X11, this happens when the grab window becomes unviewable
2867 * (i.e. it or one of its ancestors is unmapped), or if the same
2868 * application grabs the pointer or keyboard again.
2870 * Returns: %TRUE to stop other handlers from being invoked for
2871 * the event. %FALSE to propagate the event further.
2875 widget_signals[GRAB_BROKEN_EVENT] =
2876 g_signal_new (I_("grab-broken-event"),
2877 G_TYPE_FROM_CLASS (klass),
2879 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2880 _gtk_boolean_handled_accumulator, NULL,
2881 _gtk_marshal_BOOLEAN__BOXED,
2883 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2886 * GtkWidget::query-tooltip:
2887 * @widget: the object which received the signal
2888 * @x: the x coordinate of the cursor position where the request has
2889 * been emitted, relative to @widget's left side
2890 * @y: the y coordinate of the cursor position where the request has
2891 * been emitted, relative to @widget's top
2892 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2893 * @tooltip: a #GtkTooltip
2895 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2896 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2897 * focus in keyboard mode.
2899 * Using the given coordinates, the signal handler should determine
2900 * whether a tooltip should be shown for @widget. If this is the case
2901 * %TRUE should be returned, %FALSE otherwise. Note that if
2902 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2903 * should not be used.
2905 * The signal handler is free to manipulate @tooltip with the therefore
2906 * destined function calls.
2908 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2912 widget_signals[QUERY_TOOLTIP] =
2913 g_signal_new (I_("query-tooltip"),
2914 G_TYPE_FROM_CLASS (klass),
2916 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2917 _gtk_boolean_handled_accumulator, NULL,
2918 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2926 * GtkWidget::popup-menu
2927 * @widget: the object which received the signal
2929 * This signal gets emitted whenever a widget should pop up a context
2930 * menu. This usually happens through the standard key binding mechanism;
2931 * by pressing a certain key while a widget is focused, the user can cause
2932 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2933 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2934 * for an example of how to use this signal.
2936 * Returns: %TRUE if a menu was activated
2938 widget_signals[POPUP_MENU] =
2939 g_signal_new (I_("popup-menu"),
2940 G_TYPE_FROM_CLASS (klass),
2941 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2942 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2943 _gtk_boolean_handled_accumulator, NULL,
2944 _gtk_marshal_BOOLEAN__VOID,
2948 * GtkWidget::show-help:
2949 * @widget: the object which received the signal.
2952 widget_signals[SHOW_HELP] =
2953 g_signal_new (I_("show-help"),
2954 G_TYPE_FROM_CLASS (klass),
2955 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2956 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2957 _gtk_boolean_handled_accumulator, NULL,
2958 _gtk_marshal_BOOLEAN__ENUM,
2960 GTK_TYPE_WIDGET_HELP_TYPE);
2963 * GtkWidget::accel-closures-changed:
2964 * @widget: the object which received the signal.
2966 widget_signals[ACCEL_CLOSURES_CHANGED] =
2967 g_signal_new (I_("accel-closures-changed"),
2968 G_TYPE_FROM_CLASS (klass),
2972 _gtk_marshal_VOID__VOID,
2976 * GtkWidget::screen-changed:
2977 * @widget: the object on which the signal is emitted
2978 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2979 * widget was not associated with a screen before
2981 * The ::screen-changed signal gets emitted when the
2982 * screen of a widget has changed.
2984 widget_signals[SCREEN_CHANGED] =
2985 g_signal_new (I_("screen-changed"),
2986 G_TYPE_FROM_CLASS (klass),
2988 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2990 _gtk_marshal_VOID__OBJECT,
2995 * GtkWidget::can-activate-accel:
2996 * @widget: the object which received the signal
2997 * @signal_id: the ID of a signal installed on @widget
2999 * Determines whether an accelerator that activates the signal
3000 * identified by @signal_id can currently be activated.
3001 * This signal is present to allow applications and derived
3002 * widgets to override the default #GtkWidget handling
3003 * for determining whether an accelerator can be activated.
3005 * Returns: %TRUE if the signal can be activated.
3007 widget_signals[CAN_ACTIVATE_ACCEL] =
3008 g_signal_new (I_("can-activate-accel"),
3009 G_TYPE_FROM_CLASS (klass),
3011 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3012 _gtk_boolean_handled_accumulator, NULL,
3013 _gtk_marshal_BOOLEAN__UINT,
3014 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3016 binding_set = gtk_binding_set_by_class (klass);
3017 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3019 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3024 GTK_TYPE_WIDGET_HELP_TYPE,
3025 GTK_WIDGET_HELP_TOOLTIP);
3026 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3028 GTK_TYPE_WIDGET_HELP_TYPE,
3029 GTK_WIDGET_HELP_TOOLTIP);
3030 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3032 GTK_TYPE_WIDGET_HELP_TYPE,
3033 GTK_WIDGET_HELP_WHATS_THIS);
3034 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3036 GTK_TYPE_WIDGET_HELP_TYPE,
3037 GTK_WIDGET_HELP_WHATS_THIS);
3039 gtk_widget_class_install_style_property (klass,
3040 g_param_spec_boolean ("interior-focus",
3041 P_("Interior Focus"),
3042 P_("Whether to draw the focus indicator inside widgets"),
3044 GTK_PARAM_READABLE));
3046 gtk_widget_class_install_style_property (klass,
3047 g_param_spec_int ("focus-line-width",
3048 P_("Focus linewidth"),
3049 P_("Width, in pixels, of the focus indicator line"),
3051 GTK_PARAM_READABLE));
3053 gtk_widget_class_install_style_property (klass,
3054 g_param_spec_string ("focus-line-pattern",
3055 P_("Focus line dash pattern"),
3056 P_("Dash pattern used to draw the focus indicator"),
3058 GTK_PARAM_READABLE));
3059 gtk_widget_class_install_style_property (klass,
3060 g_param_spec_int ("focus-padding",
3061 P_("Focus padding"),
3062 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3064 GTK_PARAM_READABLE));
3065 gtk_widget_class_install_style_property (klass,
3066 g_param_spec_boxed ("cursor-color",
3068 P_("Color with which to draw insertion cursor"),
3070 GTK_PARAM_READABLE));
3071 gtk_widget_class_install_style_property (klass,
3072 g_param_spec_boxed ("secondary-cursor-color",
3073 P_("Secondary cursor color"),
3074 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3076 GTK_PARAM_READABLE));
3077 gtk_widget_class_install_style_property (klass,
3078 g_param_spec_float ("cursor-aspect-ratio",
3079 P_("Cursor line aspect ratio"),
3080 P_("Aspect ratio with which to draw insertion cursor"),
3082 GTK_PARAM_READABLE));
3084 gtk_widget_class_install_style_property (klass,
3085 g_param_spec_boolean ("window-dragging",
3086 P_("Window dragging"),
3087 P_("Whether windows can be dragged by clicking on empty areas"),
3089 GTK_PARAM_READABLE));
3092 * GtkWidget:link-color:
3094 * The "link-color" style property defines the color of unvisited links.
3098 gtk_widget_class_install_style_property (klass,
3099 g_param_spec_boxed ("link-color",
3100 P_("Unvisited Link Color"),
3101 P_("Color of unvisited links"),
3103 GTK_PARAM_READABLE));
3106 * GtkWidget:visited-link-color:
3108 * The "visited-link-color" style property defines the color of visited links.
3112 gtk_widget_class_install_style_property (klass,
3113 g_param_spec_boxed ("visited-link-color",
3114 P_("Visited Link Color"),
3115 P_("Color of visited links"),
3117 GTK_PARAM_READABLE));
3120 * GtkWidget:wide-separators:
3122 * The "wide-separators" style property defines whether separators have
3123 * configurable width and should be drawn using a box instead of a line.
3127 gtk_widget_class_install_style_property (klass,
3128 g_param_spec_boolean ("wide-separators",
3129 P_("Wide Separators"),
3130 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3132 GTK_PARAM_READABLE));
3135 * GtkWidget:separator-width:
3137 * The "separator-width" style property defines the width of separators.
3138 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3142 gtk_widget_class_install_style_property (klass,
3143 g_param_spec_int ("separator-width",
3144 P_("Separator Width"),
3145 P_("The width of separators if wide-separators is TRUE"),
3147 GTK_PARAM_READABLE));
3150 * GtkWidget:separator-height:
3152 * The "separator-height" style property defines the height of separators.
3153 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3157 gtk_widget_class_install_style_property (klass,
3158 g_param_spec_int ("separator-height",
3159 P_("Separator Height"),
3160 P_("The height of separators if \"wide-separators\" is TRUE"),
3162 GTK_PARAM_READABLE));
3165 * GtkWidget:scroll-arrow-hlength:
3167 * The "scroll-arrow-hlength" style property defines the length of
3168 * horizontal scroll arrows.
3172 gtk_widget_class_install_style_property (klass,
3173 g_param_spec_int ("scroll-arrow-hlength",
3174 P_("Horizontal Scroll Arrow Length"),
3175 P_("The length of horizontal scroll arrows"),
3177 GTK_PARAM_READABLE));
3180 * GtkWidget:scroll-arrow-vlength:
3182 * The "scroll-arrow-vlength" style property defines the length of
3183 * vertical scroll arrows.
3187 gtk_widget_class_install_style_property (klass,
3188 g_param_spec_int ("scroll-arrow-vlength",
3189 P_("Vertical Scroll Arrow Length"),
3190 P_("The length of vertical scroll arrows"),
3192 GTK_PARAM_READABLE));
3194 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3196 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3200 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3204 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3205 for (node = list; node; node = node->next)
3207 GParamSpec *pspec = node->data;
3209 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3210 g_param_spec_unref (pspec);
3216 gtk_widget_set_property (GObject *object,
3218 const GValue *value,
3221 GtkWidget *widget = GTK_WIDGET (object);
3226 gchar *tooltip_markup;
3227 const gchar *tooltip_text;
3228 GtkWindow *tooltip_window;
3231 gtk_widget_set_name (widget, g_value_get_string (value));
3234 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3236 case PROP_WIDTH_REQUEST:
3237 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3239 case PROP_HEIGHT_REQUEST:
3240 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3243 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3245 case PROP_SENSITIVE:
3246 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3248 case PROP_APP_PAINTABLE:
3249 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3251 case PROP_CAN_FOCUS:
3252 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3254 case PROP_HAS_FOCUS:
3255 if (g_value_get_boolean (value))
3256 gtk_widget_grab_focus (widget);
3259 if (g_value_get_boolean (value))
3260 gtk_widget_grab_focus (widget);
3262 case PROP_CAN_DEFAULT:
3263 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3265 case PROP_HAS_DEFAULT:
3266 if (g_value_get_boolean (value))
3267 gtk_widget_grab_default (widget);
3269 case PROP_RECEIVES_DEFAULT:
3270 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3273 gtk_widget_set_style (widget, g_value_get_object (value));
3276 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3277 gtk_widget_set_events (widget, g_value_get_flags (value));
3279 case PROP_NO_SHOW_ALL:
3280 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3282 case PROP_HAS_TOOLTIP:
3283 gtk_widget_real_set_has_tooltip (widget,
3284 g_value_get_boolean (value), FALSE);
3286 case PROP_TOOLTIP_MARKUP:
3287 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3288 tooltip_markup = g_value_dup_string (value);
3290 /* Treat an empty string as a NULL string,
3291 * because an empty string would be useless for a tooltip:
3293 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3295 g_free (tooltip_markup);
3296 tooltip_markup = NULL;
3299 g_object_set_qdata_full (object, quark_tooltip_markup,
3300 tooltip_markup, g_free);
3302 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3303 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3304 if (gtk_widget_get_visible (widget))
3305 gtk_widget_queue_tooltip_query (widget);
3307 case PROP_TOOLTIP_TEXT:
3308 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3310 tooltip_text = g_value_get_string (value);
3312 /* Treat an empty string as a NULL string,
3313 * because an empty string would be useless for a tooltip:
3315 if (tooltip_text && (strlen (tooltip_text) == 0))
3316 tooltip_text = NULL;
3318 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3320 g_object_set_qdata_full (object, quark_tooltip_markup,
3321 tooltip_markup, g_free);
3323 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3324 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3325 if (gtk_widget_get_visible (widget))
3326 gtk_widget_queue_tooltip_query (widget);
3328 case PROP_DOUBLE_BUFFERED:
3329 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3332 gtk_widget_set_halign (widget, g_value_get_enum (value));
3335 gtk_widget_set_valign (widget, g_value_get_enum (value));
3337 case PROP_MARGIN_LEFT:
3338 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3340 case PROP_MARGIN_RIGHT:
3341 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3343 case PROP_MARGIN_TOP:
3344 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3346 case PROP_MARGIN_BOTTOM:
3347 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3350 g_object_freeze_notify (G_OBJECT (widget));
3351 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3352 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3353 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3354 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3355 g_object_thaw_notify (G_OBJECT (widget));
3358 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3360 case PROP_HEXPAND_SET:
3361 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3364 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3366 case PROP_VEXPAND_SET:
3367 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3370 g_object_freeze_notify (G_OBJECT (widget));
3371 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3372 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3373 g_object_thaw_notify (G_OBJECT (widget));
3376 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3382 gtk_widget_get_property (GObject *object,
3387 GtkWidget *widget = GTK_WIDGET (object);
3388 GtkWidgetPrivate *priv = widget->priv;
3396 g_value_set_string (value, priv->name);
3398 g_value_set_static_string (value, "");
3401 g_value_set_object (value, priv->parent);
3403 case PROP_WIDTH_REQUEST:
3406 gtk_widget_get_size_request (widget, &w, NULL);
3407 g_value_set_int (value, w);
3410 case PROP_HEIGHT_REQUEST:
3413 gtk_widget_get_size_request (widget, NULL, &h);
3414 g_value_set_int (value, h);
3418 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3420 case PROP_SENSITIVE:
3421 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3423 case PROP_APP_PAINTABLE:
3424 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3426 case PROP_CAN_FOCUS:
3427 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3429 case PROP_HAS_FOCUS:
3430 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3433 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3435 case PROP_CAN_DEFAULT:
3436 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3438 case PROP_HAS_DEFAULT:
3439 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3441 case PROP_RECEIVES_DEFAULT:
3442 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3444 case PROP_COMPOSITE_CHILD:
3445 g_value_set_boolean (value, widget->priv->composite_child);
3448 g_value_set_object (value, gtk_widget_get_style (widget));
3451 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3452 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3454 case PROP_NO_SHOW_ALL:
3455 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3457 case PROP_HAS_TOOLTIP:
3458 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3460 case PROP_TOOLTIP_TEXT:
3462 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3465 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3466 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3468 g_value_take_string (value, text);
3471 case PROP_TOOLTIP_MARKUP:
3472 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3475 g_value_set_object (value, gtk_widget_get_window (widget));
3477 case PROP_DOUBLE_BUFFERED:
3478 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3481 g_value_set_enum (value, gtk_widget_get_halign (widget));
3484 g_value_set_enum (value, gtk_widget_get_valign (widget));
3486 case PROP_MARGIN_LEFT:
3487 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3489 case PROP_MARGIN_RIGHT:
3490 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3492 case PROP_MARGIN_TOP:
3493 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3495 case PROP_MARGIN_BOTTOM:
3496 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3500 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3501 if (aux_info == NULL)
3503 g_value_set_int (value, 0);
3507 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3508 aux_info->margin.right),
3509 MAX (aux_info->margin.top,
3510 aux_info->margin.bottom)));
3515 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3517 case PROP_HEXPAND_SET:
3518 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3521 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3523 case PROP_VEXPAND_SET:
3524 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3527 g_value_set_boolean (value,
3528 gtk_widget_get_hexpand (widget) &&
3529 gtk_widget_get_vexpand (widget));
3532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3538 gtk_widget_init (GtkWidget *widget)
3540 GtkWidgetPrivate *priv;
3542 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3545 priv = widget->priv;
3547 priv->child_visible = TRUE;
3549 priv->allocation.x = -1;
3550 priv->allocation.y = -1;
3551 priv->allocation.width = 1;
3552 priv->allocation.height = 1;
3553 priv->window = NULL;
3554 priv->parent = NULL;
3556 priv->sensitive = TRUE;
3557 priv->composite_child = composite_child_stack != 0;
3558 priv->double_buffered = TRUE;
3559 priv->redraw_on_alloc = TRUE;
3560 priv->width_request_needed = TRUE;
3561 priv->height_request_needed = TRUE;
3562 priv->alloc_needed = TRUE;
3564 /* this will be set to TRUE if the widget gets a child or if the
3565 * expand flag is set on the widget, but until one of those happen
3566 * we know the expand is already properly FALSE.
3568 * We really want to default FALSE here to avoid computing expand
3569 * all over the place while initially building a widget tree.
3571 priv->need_compute_expand = FALSE;
3573 priv->style = gtk_widget_get_default_style ();
3574 g_object_ref (priv->style);
3579 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3581 GParamSpec **pspecs)
3583 GtkWidgetPrivate *priv = widget->priv;
3584 GtkWidget *container = priv->parent;
3587 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3588 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3592 * gtk_widget_freeze_child_notify:
3593 * @widget: a #GtkWidget
3595 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3596 * signals are queued until gtk_widget_thaw_child_notify() is called
3599 * This is the analogue of g_object_freeze_notify() for child properties.
3602 gtk_widget_freeze_child_notify (GtkWidget *widget)
3604 g_return_if_fail (GTK_IS_WIDGET (widget));
3606 if (!G_OBJECT (widget)->ref_count)
3609 g_object_ref (widget);
3610 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3611 g_object_unref (widget);
3615 * gtk_widget_child_notify:
3616 * @widget: a #GtkWidget
3617 * @child_property: the name of a child property installed on the
3618 * class of @widget<!-- -->'s parent
3620 * Emits a #GtkWidget::child-notify signal for the
3621 * <link linkend="child-properties">child property</link> @child_property
3624 * This is the analogue of g_object_notify() for child properties.
3626 * Also see gtk_container_child_notify().
3629 gtk_widget_child_notify (GtkWidget *widget,
3630 const gchar *child_property)
3632 if (widget->priv->parent == NULL)
3635 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3639 * gtk_widget_thaw_child_notify:
3640 * @widget: a #GtkWidget
3642 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3643 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3647 gtk_widget_thaw_child_notify (GtkWidget *widget)
3649 GObjectNotifyQueue *nqueue;
3651 g_return_if_fail (GTK_IS_WIDGET (widget));
3653 if (!G_OBJECT (widget)->ref_count)
3656 g_object_ref (widget);
3657 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3658 if (!nqueue || !nqueue->freeze_count)
3659 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3660 G_OBJECT_TYPE_NAME (widget), widget);
3662 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3663 g_object_unref (widget);
3669 * @type: type ID of the widget to create
3670 * @first_property_name: name of first property to set
3671 * @...: value of first property, followed by more properties,
3674 * This is a convenience function for creating a widget and setting
3675 * its properties in one go. For example you might write:
3676 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3677 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3678 * g_object_new(), but returns a widget so you don't have to
3679 * cast the object yourself.
3681 * Return value: a new #GtkWidget of type @widget_type
3684 gtk_widget_new (GType type,
3685 const gchar *first_property_name,
3691 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3693 va_start (var_args, first_property_name);
3694 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3701 gtk_widget_queue_draw_child (GtkWidget *widget)
3703 GtkWidgetPrivate *priv = widget->priv;
3706 parent = priv->parent;
3707 if (parent && gtk_widget_is_drawable (parent))
3708 gtk_widget_queue_draw_area (parent,
3711 priv->allocation.width,
3712 priv->allocation.height);
3716 * gtk_widget_unparent:
3717 * @widget: a #GtkWidget
3719 * This function is only for use in widget implementations.
3720 * Should be called by implementations of the remove method
3721 * on #GtkContainer, to dissociate a child from the container.
3724 gtk_widget_unparent (GtkWidget *widget)
3726 GtkWidgetPrivate *priv;
3727 GObjectNotifyQueue *nqueue;
3728 GtkWidget *toplevel;
3729 GtkWidget *old_parent;
3731 g_return_if_fail (GTK_IS_WIDGET (widget));
3733 priv = widget->priv;
3735 if (priv->parent == NULL)
3738 /* keep this function in sync with gtk_menu_detach() */
3740 gtk_widget_push_verify_invariants (widget);
3742 g_object_freeze_notify (G_OBJECT (widget));
3743 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3745 toplevel = gtk_widget_get_toplevel (widget);
3746 if (gtk_widget_is_toplevel (toplevel))
3747 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3749 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3750 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3752 gtk_widget_queue_draw_child (widget);
3754 /* Reset the width and height here, to force reallocation if we
3755 * get added back to a new parent. This won't work if our new
3756 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3757 * (would 0x0 be OK here?)
3759 priv->allocation.width = 1;
3760 priv->allocation.height = 1;
3762 if (gtk_widget_get_realized (widget))
3764 if (priv->in_reparent)
3765 gtk_widget_unmap (widget);
3767 gtk_widget_unrealize (widget);
3770 /* If we are unanchoring the child, we save around the toplevel
3771 * to emit hierarchy changed
3773 if (priv->parent->priv->anchored)
3774 g_object_ref (toplevel);
3778 /* Removing a widget from a container restores the child visible
3779 * flag to the default state, so it doesn't affect the child
3780 * in the next parent.
3782 priv->child_visible = TRUE;
3784 old_parent = priv->parent;
3785 priv->parent = NULL;
3787 /* parent may no longer expand if the removed
3788 * child was expand=TRUE and could therefore
3791 if (gtk_widget_get_visible (widget) &&
3792 (priv->need_compute_expand ||
3793 priv->computed_hexpand ||
3794 priv->computed_vexpand))
3796 gtk_widget_queue_compute_expand (old_parent);
3799 /* Unset BACKDROP since we are no longer inside a toplevel window */
3800 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3802 gtk_style_context_set_parent (priv->context, NULL);
3804 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3807 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3808 g_object_unref (toplevel);
3811 /* Now that the parent pointer is nullified and the hierarchy-changed
3812 * already passed, go ahead and unset the parent window, if we are unparenting
3813 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3814 * will fire again for the new subhierarchy.
3816 gtk_widget_set_parent_window (widget, NULL);
3818 g_object_notify (G_OBJECT (widget), "parent");
3819 g_object_thaw_notify (G_OBJECT (widget));
3821 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3822 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3824 gtk_widget_pop_verify_invariants (widget);
3825 g_object_unref (widget);
3829 * gtk_widget_destroy:
3830 * @widget: a #GtkWidget
3832 * Destroys a widget.
3835 * destroyed, it will break any references it holds to other objects.
3836 * If the widget is inside a container, the widget will be removed
3837 * from the container. If the widget is a toplevel (derived from
3838 * #GtkWindow), it will be removed from the list of toplevels, and the
3839 * reference GTK+ holds to it will be removed. Removing a
3840 * widget from its container or the list of toplevels results in the
3841 * widget being finalized, unless you've added additional references
3842 * to the widget with g_object_ref().
3844 * In most cases, only toplevel widgets (windows) require explicit
3845 * destruction, because when you destroy a toplevel its children will
3846 * be destroyed as well.
3849 gtk_widget_destroy (GtkWidget *widget)
3851 g_return_if_fail (GTK_IS_WIDGET (widget));
3853 if (!widget->priv->in_destruction)
3854 g_object_run_dispose (G_OBJECT (widget));
3858 * gtk_widget_destroyed:
3859 * @widget: a #GtkWidget
3860 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3862 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3863 * %NULL. It's intended to be used as a callback connected to the
3864 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3865 * as a signal handler, and pass the address of your widget variable
3866 * as user data. Then when the widget is destroyed, the variable will
3867 * be set to %NULL. Useful for example to avoid multiple copies
3868 * of the same dialog.
3871 gtk_widget_destroyed (GtkWidget *widget,
3872 GtkWidget **widget_pointer)
3874 /* Don't make any assumptions about the
3876 * Even check widget_pointer.
3879 *widget_pointer = NULL;
3884 * @widget: a #GtkWidget
3886 * Flags a widget to be displayed. Any widget that isn't shown will
3887 * not appear on the screen. If you want to show all the widgets in a
3888 * container, it's easier to call gtk_widget_show_all() on the
3889 * container, instead of individually showing the widgets.
3891 * Remember that you have to show the containers containing a widget,
3892 * in addition to the widget itself, before it will appear onscreen.
3894 * When a toplevel container is shown, it is immediately realized and
3895 * mapped; other shown widgets are realized and mapped when their
3896 * toplevel container is realized and mapped.
3899 gtk_widget_show (GtkWidget *widget)
3901 g_return_if_fail (GTK_IS_WIDGET (widget));
3903 if (!gtk_widget_get_visible (widget))
3905 g_object_ref (widget);
3906 gtk_widget_push_verify_invariants (widget);
3908 if (!gtk_widget_is_toplevel (widget))
3909 gtk_widget_queue_resize (widget);
3911 /* see comment in set_parent() for why this should and can be
3914 if (widget->priv->need_compute_expand ||
3915 widget->priv->computed_hexpand ||
3916 widget->priv->computed_vexpand)
3918 if (widget->priv->parent != NULL)
3919 gtk_widget_queue_compute_expand (widget->priv->parent);
3922 g_signal_emit (widget, widget_signals[SHOW], 0);
3923 g_object_notify (G_OBJECT (widget), "visible");
3925 gtk_widget_pop_verify_invariants (widget);
3926 g_object_unref (widget);
3931 gtk_widget_real_show (GtkWidget *widget)
3933 GtkWidgetPrivate *priv = widget->priv;
3935 if (!gtk_widget_get_visible (widget))
3937 priv->visible = TRUE;
3940 gtk_widget_get_mapped (priv->parent) &&
3941 gtk_widget_get_child_visible (widget) &&
3942 !gtk_widget_get_mapped (widget))
3943 gtk_widget_map (widget);
3948 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3951 g_signal_handlers_disconnect_by_func (widget,
3952 gtk_widget_show_map_callback,
3957 * gtk_widget_show_now:
3958 * @widget: a #GtkWidget
3960 * Shows a widget. If the widget is an unmapped toplevel widget
3961 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3962 * loop and wait for the window to actually be mapped. Be careful;
3963 * because the main loop is running, anything can happen during
3967 gtk_widget_show_now (GtkWidget *widget)
3971 g_return_if_fail (GTK_IS_WIDGET (widget));
3973 /* make sure we will get event */
3974 if (!gtk_widget_get_mapped (widget) &&
3975 gtk_widget_is_toplevel (widget))
3977 gtk_widget_show (widget);
3979 g_signal_connect (widget, "map-event",
3980 G_CALLBACK (gtk_widget_show_map_callback),
3984 gtk_main_iteration ();
3987 gtk_widget_show (widget);
3992 * @widget: a #GtkWidget
3994 * Reverses the effects of gtk_widget_show(), causing the widget to be
3995 * hidden (invisible to the user).
3998 gtk_widget_hide (GtkWidget *widget)
4000 g_return_if_fail (GTK_IS_WIDGET (widget));
4002 if (gtk_widget_get_visible (widget))
4004 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4006 g_object_ref (widget);
4007 gtk_widget_push_verify_invariants (widget);
4009 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4010 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4012 /* a parent may now be expand=FALSE since we're hidden. */
4013 if (widget->priv->need_compute_expand ||
4014 widget->priv->computed_hexpand ||
4015 widget->priv->computed_vexpand)
4017 gtk_widget_queue_compute_expand (widget);
4020 g_signal_emit (widget, widget_signals[HIDE], 0);
4021 if (!gtk_widget_is_toplevel (widget))
4022 gtk_widget_queue_resize (widget);
4023 g_object_notify (G_OBJECT (widget), "visible");
4025 gtk_widget_pop_verify_invariants (widget);
4026 g_object_unref (widget);
4031 gtk_widget_real_hide (GtkWidget *widget)
4033 if (gtk_widget_get_visible (widget))
4035 widget->priv->visible = FALSE;
4037 if (gtk_widget_get_mapped (widget))
4038 gtk_widget_unmap (widget);
4043 * gtk_widget_hide_on_delete:
4044 * @widget: a #GtkWidget
4046 * Utility function; intended to be connected to the #GtkWidget::delete-event
4047 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4048 * argument, then returns %TRUE. If connected to ::delete-event, the
4049 * result is that clicking the close button for a window (on the
4050 * window frame, top right corner usually) will hide but not destroy
4051 * the window. By default, GTK+ destroys windows when ::delete-event
4054 * Return value: %TRUE
4057 gtk_widget_hide_on_delete (GtkWidget *widget)
4059 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4061 gtk_widget_hide (widget);
4067 * gtk_widget_show_all:
4068 * @widget: a #GtkWidget
4070 * Recursively shows a widget, and any child widgets (if the widget is
4074 gtk_widget_show_all (GtkWidget *widget)
4076 GtkWidgetClass *class;
4078 g_return_if_fail (GTK_IS_WIDGET (widget));
4080 if (gtk_widget_get_no_show_all (widget))
4083 class = GTK_WIDGET_GET_CLASS (widget);
4085 if (class->show_all)
4086 class->show_all (widget);
4090 _gtk_widget_notify_state_change (GtkWidget *widget,
4098 case GTK_STATE_FLAG_ACTIVE:
4099 state = GTK_STATE_ACTIVE;
4101 case GTK_STATE_FLAG_PRELIGHT:
4102 state = GTK_STATE_PRELIGHT;
4104 case GTK_STATE_FLAG_SELECTED:
4105 state = GTK_STATE_SELECTED;
4107 case GTK_STATE_FLAG_INSENSITIVE:
4108 state = GTK_STATE_INSENSITIVE;
4110 case GTK_STATE_FLAG_INCONSISTENT:
4111 state = GTK_STATE_INCONSISTENT;
4113 case GTK_STATE_FLAG_FOCUSED:
4114 state = GTK_STATE_FOCUSED;
4120 gtk_style_context_notify_state_change (widget->priv->context,
4121 gtk_widget_get_window (widget),
4122 NULL, state, target);
4125 /* Initializes state transitions for those states that
4126 * were enabled before mapping and have a looping animation.
4129 _gtk_widget_start_state_transitions (GtkWidget *widget)
4131 GtkStateFlags state, flag;
4133 if (!widget->priv->context)
4136 state = gtk_widget_get_state_flags (widget);
4137 flag = GTK_STATE_FLAG_FOCUSED;
4141 GtkAnimationDescription *animation_desc;
4143 if ((state & flag) == 0)
4149 gtk_style_context_get (widget->priv->context, state,
4150 "transition", &animation_desc,
4155 if (_gtk_animation_description_get_loop (animation_desc))
4156 _gtk_widget_notify_state_change (widget, flag, TRUE);
4158 _gtk_animation_description_unref (animation_desc);
4167 * @widget: a #GtkWidget
4169 * This function is only for use in widget implementations. Causes
4170 * a widget to be mapped if it isn't already.
4173 gtk_widget_map (GtkWidget *widget)
4175 GtkWidgetPrivate *priv;
4177 g_return_if_fail (GTK_IS_WIDGET (widget));
4178 g_return_if_fail (gtk_widget_get_visible (widget));
4179 g_return_if_fail (gtk_widget_get_child_visible (widget));
4181 priv = widget->priv;
4183 if (!gtk_widget_get_mapped (widget))
4185 gtk_widget_push_verify_invariants (widget);
4187 if (!gtk_widget_get_realized (widget))
4188 gtk_widget_realize (widget);
4190 g_signal_emit (widget, widget_signals[MAP], 0);
4192 if (!gtk_widget_get_has_window (widget))
4193 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4195 gtk_widget_pop_verify_invariants (widget);
4197 _gtk_widget_start_state_transitions (widget);
4203 * @widget: a #GtkWidget
4205 * This function is only for use in widget implementations. Causes
4206 * a widget to be unmapped if it's currently mapped.
4209 gtk_widget_unmap (GtkWidget *widget)
4211 GtkWidgetPrivate *priv;
4213 g_return_if_fail (GTK_IS_WIDGET (widget));
4215 priv = widget->priv;
4217 if (gtk_widget_get_mapped (widget))
4219 gtk_widget_push_verify_invariants (widget);
4221 if (!gtk_widget_get_has_window (widget))
4222 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4223 _gtk_tooltip_hide (widget);
4224 g_signal_emit (widget, widget_signals[UNMAP], 0);
4226 gtk_widget_pop_verify_invariants (widget);
4229 gtk_style_context_cancel_animations (priv->context, NULL);
4231 /* Unset pointer/window info */
4232 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4237 _gtk_widget_enable_device_events (GtkWidget *widget)
4239 GHashTable *device_events;
4240 GHashTableIter iter;
4241 gpointer key, value;
4243 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4248 g_hash_table_iter_init (&iter, device_events);
4250 while (g_hash_table_iter_next (&iter, &key, &value))
4253 GdkEventMask event_mask;
4256 event_mask = GPOINTER_TO_UINT (value);
4257 gtk_widget_add_events_internal (widget, device, event_mask);
4262 get_widget_windows (GtkWidget *widget)
4264 GList *window_list, *last, *l, *children, *ret;
4266 if (gtk_widget_get_has_window (widget))
4267 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4269 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4271 last = g_list_last (window_list);
4274 for (l = window_list; l; l = l->next)
4276 GtkWidget *window_widget = NULL;
4278 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4280 if (widget != window_widget)
4283 ret = g_list_prepend (ret, l->data);
4284 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4288 last = g_list_concat (last, children);
4289 last = g_list_last (last);
4293 g_list_free (window_list);
4299 device_enable_foreach (GtkWidget *widget,
4302 GdkDevice *device = user_data;
4303 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4307 device_disable_foreach (GtkWidget *widget,
4310 GdkDevice *device = user_data;
4311 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4315 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4320 GList *window_list, *l;
4322 window_list = get_widget_windows (widget);
4324 for (l = window_list; l; l = l->next)
4326 GdkEventMask events = 0;
4332 events = gdk_window_get_events (window);
4334 gdk_window_set_device_events (window, device, events);
4337 if (recurse && GTK_IS_CONTAINER (widget))
4340 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4342 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4345 g_list_free (window_list);
4349 gtk_widget_update_devices_mask (GtkWidget *widget,
4352 GList *enabled_devices, *l;
4354 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4356 for (l = enabled_devices; l; l = l->next)
4357 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4361 * gtk_widget_realize:
4362 * @widget: a #GtkWidget
4364 * Creates the GDK (windowing system) resources associated with a
4365 * widget. For example, @widget->window will be created when a widget
4366 * is realized. Normally realization happens implicitly; if you show
4367 * a widget and all its parent containers, then the widget will be
4368 * realized and mapped automatically.
4370 * Realizing a widget requires all
4371 * the widget's parent widgets to be realized; calling
4372 * gtk_widget_realize() realizes the widget's parents in addition to
4373 * @widget itself. If a widget is not yet inside a toplevel window
4374 * when you realize it, bad things will happen.
4376 * This function is primarily used in widget implementations, and
4377 * isn't very useful otherwise. Many times when you think you might
4378 * need it, a better approach is to connect to a signal that will be
4379 * called after the widget is realized automatically, such as
4380 * #GtkWidget::draw. Or simply g_signal_connect () to the
4381 * #GtkWidget::realize signal.
4384 gtk_widget_realize (GtkWidget *widget)
4386 GtkWidgetPrivate *priv;
4387 cairo_region_t *region;
4389 g_return_if_fail (GTK_IS_WIDGET (widget));
4390 g_return_if_fail (widget->priv->anchored ||
4391 GTK_IS_INVISIBLE (widget));
4393 priv = widget->priv;
4395 if (!gtk_widget_get_realized (widget))
4397 gtk_widget_push_verify_invariants (widget);
4400 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4401 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4404 if (priv->parent == NULL &&
4405 !gtk_widget_is_toplevel (widget))
4406 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4407 "inside a toplevel window is not going to work very well. "
4408 "Widgets must be inside a toplevel container before realizing them.");
4410 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4411 gtk_widget_realize (priv->parent);
4413 gtk_widget_ensure_style (widget);
4415 if (priv->style_update_pending)
4416 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4418 g_signal_emit (widget, widget_signals[REALIZE], 0);
4420 gtk_widget_real_set_has_tooltip (widget,
4421 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4424 if (priv->has_shape_mask)
4426 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4427 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4430 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4432 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4434 if (priv->multidevice)
4435 gdk_window_set_support_multidevice (priv->window, TRUE);
4437 _gtk_widget_enable_device_events (widget);
4438 gtk_widget_update_devices_mask (widget, TRUE);
4440 gtk_widget_pop_verify_invariants (widget);
4445 * gtk_widget_unrealize:
4446 * @widget: a #GtkWidget
4448 * This function is only useful in widget implementations.
4449 * Causes a widget to be unrealized (frees all GDK resources
4450 * associated with the widget, such as @widget->window).
4453 gtk_widget_unrealize (GtkWidget *widget)
4455 g_return_if_fail (GTK_IS_WIDGET (widget));
4457 gtk_widget_push_verify_invariants (widget);
4459 if (widget->priv->has_shape_mask)
4460 gtk_widget_shape_combine_region (widget, NULL);
4462 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4463 gtk_widget_input_shape_combine_region (widget, NULL);
4465 if (gtk_widget_get_realized (widget))
4467 g_object_ref (widget);
4469 if (widget->priv->mapped)
4470 gtk_widget_unmap (widget);
4472 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4473 g_assert (!widget->priv->mapped);
4474 gtk_widget_set_realized (widget, FALSE);
4476 g_object_unref (widget);
4479 gtk_widget_pop_verify_invariants (widget);
4482 /*****************************************
4484 *****************************************/
4487 * gtk_widget_queue_draw_region:
4488 * @widget: a #GtkWidget
4489 * @region: region to draw
4491 * Invalidates the rectangular area of @widget defined by @region by
4492 * calling gdk_window_invalidate_region() on the widget's window and
4493 * all its child windows. Once the main loop becomes idle (after the
4494 * current batch of events has been processed, roughly), the window
4495 * will receive expose events for the union of all regions that have
4498 * Normally you would only use this function in widget
4499 * implementations. You might also use it to schedule a redraw of a
4500 * #GtkDrawingArea or some portion thereof.
4505 gtk_widget_queue_draw_region (GtkWidget *widget,
4506 const cairo_region_t *region)
4508 GtkWidgetPrivate *priv;
4511 g_return_if_fail (GTK_IS_WIDGET (widget));
4513 priv = widget->priv;
4515 if (!gtk_widget_get_realized (widget))
4518 /* Just return if the widget or one of its ancestors isn't mapped */
4519 for (w = widget; w != NULL; w = w->priv->parent)
4520 if (!gtk_widget_get_mapped (w))
4523 gdk_window_invalidate_region (priv->window, region, TRUE);
4527 * gtk_widget_queue_draw_area:
4528 * @widget: a #GtkWidget
4529 * @x: x coordinate of upper-left corner of rectangle to redraw
4530 * @y: y coordinate of upper-left corner of rectangle to redraw
4531 * @width: width of region to draw
4532 * @height: height of region to draw
4534 * Convenience function that calls gtk_widget_queue_draw_region() on
4535 * the region created from the given coordinates.
4537 * The region here is specified in widget coordinates.
4538 * Widget coordinates are a bit odd; for historical reasons, they are
4539 * defined as @widget->window coordinates for widgets that are not
4540 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4541 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4544 gtk_widget_queue_draw_area (GtkWidget *widget,
4551 cairo_region_t *region;
4553 g_return_if_fail (GTK_IS_WIDGET (widget));
4558 rect.height = height;
4560 region = cairo_region_create_rectangle (&rect);
4561 gtk_widget_queue_draw_region (widget, region);
4562 cairo_region_destroy (region);
4566 * gtk_widget_queue_draw:
4567 * @widget: a #GtkWidget
4569 * Equivalent to calling gtk_widget_queue_draw_area() for the
4570 * entire area of a widget.
4573 gtk_widget_queue_draw (GtkWidget *widget)
4577 g_return_if_fail (GTK_IS_WIDGET (widget));
4579 gtk_widget_get_allocation (widget, &rect);
4581 if (!gtk_widget_get_has_window (widget))
4582 gtk_widget_queue_draw_area (widget,
4583 rect.x, rect.y, rect.width, rect.height);
4585 gtk_widget_queue_draw_area (widget,
4586 0, 0, rect.width, rect.height);
4590 * gtk_widget_queue_resize:
4591 * @widget: a #GtkWidget
4593 * This function is only for use in widget implementations.
4594 * Flags a widget to have its size renegotiated; should
4595 * be called when a widget for some reason has a new size request.
4596 * For example, when you change the text in a #GtkLabel, #GtkLabel
4597 * queues a resize to ensure there's enough space for the new text.
4599 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4600 * from inside its implementation of the GtkWidgetClass::size_allocate
4601 * virtual method. Calls to gtk_widget_queue_resize() from inside
4602 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4605 gtk_widget_queue_resize (GtkWidget *widget)
4607 g_return_if_fail (GTK_IS_WIDGET (widget));
4609 if (gtk_widget_get_realized (widget))
4610 gtk_widget_queue_shallow_draw (widget);
4612 _gtk_size_group_queue_resize (widget, 0);
4616 * gtk_widget_queue_resize_no_redraw:
4617 * @widget: a #GtkWidget
4619 * This function works like gtk_widget_queue_resize(),
4620 * except that the widget is not invalidated.
4625 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4627 g_return_if_fail (GTK_IS_WIDGET (widget));
4629 _gtk_size_group_queue_resize (widget, 0);
4633 * gtk_widget_size_request:
4634 * @widget: a #GtkWidget
4635 * @requisition: (out): a #GtkRequisition to be filled in
4637 * This function is typically used when implementing a #GtkContainer
4638 * subclass. Obtains the preferred size of a widget. The container
4639 * uses this information to arrange its child widgets and decide what
4640 * size allocations to give them with gtk_widget_size_allocate().
4642 * You can also call this function from an application, with some
4643 * caveats. Most notably, getting a size request requires the widget
4644 * to be associated with a screen, because font information may be
4645 * needed. Multihead-aware applications should keep this in mind.
4647 * Also remember that the size request is not necessarily the size
4648 * a widget will actually be allocated.
4650 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4653 gtk_widget_size_request (GtkWidget *widget,
4654 GtkRequisition *requisition)
4656 g_return_if_fail (GTK_IS_WIDGET (widget));
4658 gtk_widget_get_preferred_size (widget, requisition, NULL);
4662 * gtk_widget_get_child_requisition:
4663 * @widget: a #GtkWidget
4664 * @requisition: (out): a #GtkRequisition to be filled in
4666 * This function is only for use in widget implementations. Obtains
4667 * @widget->requisition, unless someone has forced a particular
4668 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4669 * in which case it returns that geometry instead of the widget's
4672 * This function differs from gtk_widget_size_request() in that
4673 * it retrieves the last size request value from @widget->requisition,
4674 * while gtk_widget_size_request() actually calls the "size_request" method
4675 * on @widget to compute the size request and fill in @widget->requisition,
4676 * and only then returns @widget->requisition.
4678 * Because this function does not call the "size_request" method, it
4679 * can only be used when you know that @widget->requisition is
4680 * up-to-date, that is, gtk_widget_size_request() has been called
4681 * since the last time a resize was queued. In general, only container
4682 * implementations have this information; applications should use
4683 * gtk_widget_size_request().
4686 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4689 gtk_widget_get_child_requisition (GtkWidget *widget,
4690 GtkRequisition *requisition)
4692 gtk_widget_get_preferred_size (widget, requisition, NULL);
4696 invalidate_predicate (GdkWindow *window,
4701 gdk_window_get_user_data (window, &user_data);
4703 return (user_data == data);
4706 /* Invalidate @region in widget->window and all children
4707 * of widget->window owned by widget. @region is in the
4708 * same coordinates as widget->allocation and will be
4709 * modified by this call.
4712 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4713 cairo_region_t *region)
4715 GtkWidgetPrivate *priv = widget->priv;
4717 if (!gtk_widget_get_realized (widget))
4720 if (gtk_widget_get_has_window (widget) && priv->parent)
4724 gdk_window_get_position (priv->window, &x, &y);
4725 cairo_region_translate (region, -x, -y);
4728 gdk_window_invalidate_maybe_recurse (priv->window, region,
4729 invalidate_predicate, widget);
4733 * gtk_widget_queue_shallow_draw:
4734 * @widget: a #GtkWidget
4736 * Like gtk_widget_queue_draw(), but only windows owned
4737 * by @widget are invalidated.
4740 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4743 cairo_region_t *region;
4745 if (!gtk_widget_get_realized (widget))
4748 gtk_widget_get_allocation (widget, &rect);
4750 region = cairo_region_create_rectangle (&rect);
4751 gtk_widget_invalidate_widget_windows (widget, region);
4752 cairo_region_destroy (region);
4756 * gtk_widget_size_allocate:
4757 * @widget: a #GtkWidget
4758 * @allocation: position and size to be allocated to @widget
4760 * This function is only used by #GtkContainer subclasses, to assign a size
4761 * and position to their child widgets.
4763 * In this function, the allocation may be adjusted. It will be forced
4764 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4765 * method on the child will be used to adjust the allocation. Standard
4766 * adjustments include removing the widget's margins, and applying the
4767 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4770 gtk_widget_size_allocate (GtkWidget *widget,
4771 GtkAllocation *allocation)
4773 GtkWidgetPrivate *priv;
4774 GdkRectangle real_allocation;
4775 GdkRectangle old_allocation;
4776 GdkRectangle adjusted_allocation;
4777 gboolean alloc_needed;
4778 gboolean size_changed;
4779 gboolean position_changed;
4780 gint natural_width, natural_height, dummy;
4781 gint min_width, min_height;
4783 priv = widget->priv;
4785 g_return_if_fail (GTK_IS_WIDGET (widget));
4787 gtk_widget_push_verify_invariants (widget);
4789 #ifdef G_ENABLE_DEBUG
4790 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4801 parent = gtk_widget_get_parent (parent);
4804 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4805 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4806 2 * depth, " ", name,
4807 allocation->width, allocation->height);
4809 #endif /* G_ENABLE_DEBUG */
4811 alloc_needed = priv->alloc_needed;
4812 if (!priv->width_request_needed && !priv->height_request_needed)
4813 /* Preserve request/allocate ordering */
4814 priv->alloc_needed = FALSE;
4816 old_allocation = priv->allocation;
4817 real_allocation = *allocation;
4819 adjusted_allocation = real_allocation;
4820 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4822 /* Go ahead and request the height for allocated width, note that the internals
4823 * of get_height_for_width will internally limit the for_size to natural size
4824 * when aligning implicitly.
4826 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4827 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4831 /* Go ahead and request the width for allocated height, note that the internals
4832 * of get_width_for_height will internally limit the for_size to natural size
4833 * when aligning implicitly.
4835 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4836 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4839 #ifdef G_ENABLE_DEBUG
4840 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4842 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4843 !GTK_IS_SCROLLABLE (widget))
4844 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4845 "Allocation is %dx%d, but minimum required size is %dx%d.",
4846 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4847 G_OBJECT_TYPE_NAME (widget), widget,
4848 real_allocation.width, real_allocation.height,
4849 min_width, min_height);
4852 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4853 * allocated sizes and possibly limit them to the natural sizes */
4854 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4855 GTK_ORIENTATION_HORIZONTAL,
4858 &adjusted_allocation.x,
4859 &adjusted_allocation.width);
4860 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4861 GTK_ORIENTATION_VERTICAL,
4864 &adjusted_allocation.y,
4865 &adjusted_allocation.height);
4867 if (adjusted_allocation.x < real_allocation.x ||
4868 adjusted_allocation.y < real_allocation.y ||
4869 (adjusted_allocation.x + adjusted_allocation.width) >
4870 (real_allocation.x + real_allocation.width) ||
4871 (adjusted_allocation.y + adjusted_allocation.height >
4872 real_allocation.y + real_allocation.height))
4874 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",
4875 G_OBJECT_TYPE_NAME (widget), widget,
4876 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4877 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4878 adjusted_allocation = real_allocation; /* veto it */
4882 real_allocation = adjusted_allocation;
4885 if (real_allocation.width < 0 || real_allocation.height < 0)
4887 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4888 real_allocation.width,
4889 real_allocation.height);
4892 real_allocation.width = MAX (real_allocation.width, 1);
4893 real_allocation.height = MAX (real_allocation.height, 1);
4895 size_changed = (old_allocation.width != real_allocation.width ||
4896 old_allocation.height != real_allocation.height);
4897 position_changed = (old_allocation.x != real_allocation.x ||
4898 old_allocation.y != real_allocation.y);
4900 if (!alloc_needed && !size_changed && !position_changed)
4903 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4905 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4906 priv->width_request_needed = FALSE;
4907 priv->height_request_needed = FALSE;
4908 priv->alloc_needed = FALSE;
4910 if (gtk_widget_get_mapped (widget))
4912 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4914 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4916 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4917 cairo_region_union_rectangle (invalidate, &old_allocation);
4919 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4920 cairo_region_destroy (invalidate);
4925 if (priv->redraw_on_alloc)
4927 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4929 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4930 cairo_region_union_rectangle (invalidate, &old_allocation);
4932 gtk_widget_invalidate_widget_windows (widget, invalidate);
4933 cairo_region_destroy (invalidate);
4937 if (size_changed || position_changed)
4939 GtkStyleContext *context;
4941 context = gtk_widget_get_style_context (widget);
4942 _gtk_style_context_invalidate_animation_areas (context);
4946 if ((size_changed || position_changed) && priv->parent &&
4947 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4949 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4950 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4951 cairo_region_destroy (invalidate);
4955 gtk_widget_pop_verify_invariants (widget);
4959 * gtk_widget_common_ancestor:
4960 * @widget_a: a #GtkWidget
4961 * @widget_b: a #GtkWidget
4963 * Find the common ancestor of @widget_a and @widget_b that
4964 * is closest to the two widgets.
4966 * Return value: the closest common ancestor of @widget_a and
4967 * @widget_b or %NULL if @widget_a and @widget_b do not
4968 * share a common ancestor.
4971 gtk_widget_common_ancestor (GtkWidget *widget_a,
4972 GtkWidget *widget_b)
4974 GtkWidget *parent_a;
4975 GtkWidget *parent_b;
4979 parent_a = widget_a;
4980 while (parent_a->priv->parent)
4982 parent_a = parent_a->priv->parent;
4986 parent_b = widget_b;
4987 while (parent_b->priv->parent)
4989 parent_b = parent_b->priv->parent;
4993 if (parent_a != parent_b)
4996 while (depth_a > depth_b)
4998 widget_a = widget_a->priv->parent;
5002 while (depth_b > depth_a)
5004 widget_b = widget_b->priv->parent;
5008 while (widget_a != widget_b)
5010 widget_a = widget_a->priv->parent;
5011 widget_b = widget_b->priv->parent;
5018 * gtk_widget_translate_coordinates:
5019 * @src_widget: a #GtkWidget
5020 * @dest_widget: a #GtkWidget
5021 * @src_x: X position relative to @src_widget
5022 * @src_y: Y position relative to @src_widget
5023 * @dest_x: (out): location to store X position relative to @dest_widget
5024 * @dest_y: (out): location to store Y position relative to @dest_widget
5026 * Translate coordinates relative to @src_widget's allocation to coordinates
5027 * relative to @dest_widget's allocations. In order to perform this
5028 * operation, both widgets must be realized, and must share a common
5031 * Return value: %FALSE if either widget was not realized, or there
5032 * was no common ancestor. In this case, nothing is stored in
5033 * *@dest_x and *@dest_y. Otherwise %TRUE.
5036 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5037 GtkWidget *dest_widget,
5043 GtkWidgetPrivate *src_priv = src_widget->priv;
5044 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5045 GtkWidget *ancestor;
5047 GList *dest_list = NULL;
5049 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5050 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5052 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5053 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5056 /* Translate from allocation relative to window relative */
5057 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5060 gdk_window_get_position (src_priv->window, &wx, &wy);
5062 src_x -= wx - src_priv->allocation.x;
5063 src_y -= wy - src_priv->allocation.y;
5067 src_x += src_priv->allocation.x;
5068 src_y += src_priv->allocation.y;
5071 /* Translate to the common ancestor */
5072 window = src_priv->window;
5073 while (window != ancestor->priv->window)
5077 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5082 window = gdk_window_get_effective_parent (window);
5084 if (!window) /* Handle GtkHandleBox */
5089 window = dest_priv->window;
5090 while (window != ancestor->priv->window)
5092 dest_list = g_list_prepend (dest_list, window);
5094 window = gdk_window_get_effective_parent (window);
5096 if (!window) /* Handle GtkHandleBox */
5098 g_list_free (dest_list);
5107 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5112 dest_list = g_list_remove (dest_list, dest_list->data);
5115 /* Translate from window relative to allocation relative */
5116 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5119 gdk_window_get_position (dest_priv->window, &wx, &wy);
5121 src_x += wx - dest_priv->allocation.x;
5122 src_y += wy - dest_priv->allocation.y;
5126 src_x -= dest_priv->allocation.x;
5127 src_y -= dest_priv->allocation.y;
5139 gtk_widget_real_size_allocate (GtkWidget *widget,
5140 GtkAllocation *allocation)
5142 GtkWidgetPrivate *priv = widget->priv;
5144 priv->allocation = *allocation;
5146 if (gtk_widget_get_realized (widget) &&
5147 gtk_widget_get_has_window (widget))
5149 gdk_window_move_resize (priv->window,
5150 allocation->x, allocation->y,
5151 allocation->width, allocation->height);
5155 /* translate initial/final into start/end */
5157 effective_align (GtkAlign align,
5158 GtkTextDirection direction)
5162 case GTK_ALIGN_START:
5163 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5165 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5172 adjust_for_align (GtkAlign align,
5174 gint *allocated_pos,
5175 gint *allocated_size)
5179 case GTK_ALIGN_FILL:
5180 /* change nothing */
5182 case GTK_ALIGN_START:
5183 /* keep *allocated_pos where it is */
5184 *allocated_size = MIN (*allocated_size, *natural_size);
5187 if (*allocated_size > *natural_size)
5189 *allocated_pos += (*allocated_size - *natural_size);
5190 *allocated_size = *natural_size;
5193 case GTK_ALIGN_CENTER:
5194 if (*allocated_size > *natural_size)
5196 *allocated_pos += (*allocated_size - *natural_size) / 2;
5197 *allocated_size = MIN (*allocated_size, *natural_size);
5204 adjust_for_margin(gint start_margin,
5208 gint *allocated_pos,
5209 gint *allocated_size)
5211 *minimum_size -= (start_margin + end_margin);
5212 *natural_size -= (start_margin + end_margin);
5213 *allocated_pos += start_margin;
5214 *allocated_size -= (start_margin + end_margin);
5218 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5219 GtkOrientation orientation,
5222 gint *allocated_pos,
5223 gint *allocated_size)
5225 const GtkWidgetAuxInfo *aux_info;
5227 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5229 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5231 adjust_for_margin (aux_info->margin.left,
5232 aux_info->margin.right,
5233 minimum_size, natural_size,
5234 allocated_pos, allocated_size);
5235 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5236 natural_size, allocated_pos, allocated_size);
5240 adjust_for_margin (aux_info->margin.top,
5241 aux_info->margin.bottom,
5242 minimum_size, natural_size,
5243 allocated_pos, allocated_size);
5244 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5245 natural_size, allocated_pos, allocated_size);
5250 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5253 GtkWidgetPrivate *priv = widget->priv;
5255 /* widgets must be onscreen for accels to take effect */
5256 return gtk_widget_is_sensitive (widget) &&
5257 gtk_widget_is_drawable (widget) &&
5258 gdk_window_is_viewable (priv->window);
5262 * gtk_widget_can_activate_accel:
5263 * @widget: a #GtkWidget
5264 * @signal_id: the ID of a signal installed on @widget
5266 * Determines whether an accelerator that activates the signal
5267 * identified by @signal_id can currently be activated.
5268 * This is done by emitting the #GtkWidget::can-activate-accel
5269 * signal on @widget; if the signal isn't overridden by a
5270 * handler or in a derived widget, then the default check is
5271 * that the widget must be sensitive, and the widget and all
5272 * its ancestors mapped.
5274 * Return value: %TRUE if the accelerator can be activated.
5279 gtk_widget_can_activate_accel (GtkWidget *widget,
5282 gboolean can_activate = FALSE;
5283 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5284 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5285 return can_activate;
5294 closure_accel_activate (GClosure *closure,
5295 GValue *return_value,
5296 guint n_param_values,
5297 const GValue *param_values,
5298 gpointer invocation_hint,
5299 gpointer marshal_data)
5301 AccelClosure *aclosure = (AccelClosure*) closure;
5302 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5305 g_signal_emit (closure->data, aclosure->signal_id, 0);
5307 /* whether accelerator was handled */
5308 g_value_set_boolean (return_value, can_activate);
5312 closures_destroy (gpointer data)
5314 GSList *slist, *closures = data;
5316 for (slist = closures; slist; slist = slist->next)
5318 g_closure_invalidate (slist->data);
5319 g_closure_unref (slist->data);
5321 g_slist_free (closures);
5325 widget_new_accel_closure (GtkWidget *widget,
5328 AccelClosure *aclosure;
5329 GClosure *closure = NULL;
5330 GSList *slist, *closures;
5332 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5333 for (slist = closures; slist; slist = slist->next)
5334 if (!gtk_accel_group_from_accel_closure (slist->data))
5336 /* reuse this closure */
5337 closure = slist->data;
5342 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5343 closures = g_slist_prepend (closures, g_closure_ref (closure));
5344 g_closure_sink (closure);
5345 g_closure_set_marshal (closure, closure_accel_activate);
5347 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5349 aclosure = (AccelClosure*) closure;
5350 g_assert (closure->data == widget);
5351 g_assert (closure->marshal == closure_accel_activate);
5352 aclosure->signal_id = signal_id;
5358 * gtk_widget_add_accelerator
5359 * @widget: widget to install an accelerator on
5360 * @accel_signal: widget signal to emit on accelerator activation
5361 * @accel_group: accel group for this widget, added to its toplevel
5362 * @accel_key: GDK keyval of the accelerator
5363 * @accel_mods: modifier key combination of the accelerator
5364 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5366 * Installs an accelerator for this @widget in @accel_group that causes
5367 * @accel_signal to be emitted if the accelerator is activated.
5368 * The @accel_group needs to be added to the widget's toplevel via
5369 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5370 * Accelerators added through this function are not user changeable during
5371 * runtime. If you want to support accelerators that can be changed by the
5372 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5373 * gtk_menu_item_set_accel_path() instead.
5376 gtk_widget_add_accelerator (GtkWidget *widget,
5377 const gchar *accel_signal,
5378 GtkAccelGroup *accel_group,
5380 GdkModifierType accel_mods,
5381 GtkAccelFlags accel_flags)
5386 g_return_if_fail (GTK_IS_WIDGET (widget));
5387 g_return_if_fail (accel_signal != NULL);
5388 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5390 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5391 if (!query.signal_id ||
5392 !(query.signal_flags & G_SIGNAL_ACTION) ||
5393 query.return_type != G_TYPE_NONE ||
5396 /* hmm, should be elaborate enough */
5397 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5398 G_OBJECT_TYPE_NAME (widget), accel_signal);
5402 closure = widget_new_accel_closure (widget, query.signal_id);
5404 g_object_ref (widget);
5406 /* install the accelerator. since we don't map this onto an accel_path,
5407 * the accelerator will automatically be locked.
5409 gtk_accel_group_connect (accel_group,
5412 accel_flags | GTK_ACCEL_LOCKED,
5415 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5417 g_object_unref (widget);
5421 * gtk_widget_remove_accelerator:
5422 * @widget: widget to install an accelerator on
5423 * @accel_group: accel group for this widget
5424 * @accel_key: GDK keyval of the accelerator
5425 * @accel_mods: modifier key combination of the accelerator
5427 * Removes an accelerator from @widget, previously installed with
5428 * gtk_widget_add_accelerator().
5430 * Returns: whether an accelerator was installed and could be removed
5433 gtk_widget_remove_accelerator (GtkWidget *widget,
5434 GtkAccelGroup *accel_group,
5436 GdkModifierType accel_mods)
5438 GtkAccelGroupEntry *ag_entry;
5439 GList *slist, *clist;
5442 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5443 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5445 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5446 clist = gtk_widget_list_accel_closures (widget);
5447 for (slist = clist; slist; slist = slist->next)
5451 for (i = 0; i < n; i++)
5452 if (slist->data == (gpointer) ag_entry[i].closure)
5454 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5456 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5458 g_list_free (clist);
5463 g_list_free (clist);
5465 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5466 accel_key, accel_mods, accel_group,
5467 G_OBJECT_TYPE_NAME (widget), widget);
5473 * gtk_widget_list_accel_closures:
5474 * @widget: widget to list accelerator closures for
5476 * Lists the closures used by @widget for accelerator group connections
5477 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5478 * The closures can be used to monitor accelerator changes on @widget,
5479 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5480 * #GtkAccelGroup of a closure which can be found out with
5481 * gtk_accel_group_from_accel_closure().
5483 * Return value: (transfer container) (element-type GClosure):
5484 * a newly allocated #GList of closures
5487 gtk_widget_list_accel_closures (GtkWidget *widget)
5490 GList *clist = NULL;
5492 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5494 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5495 if (gtk_accel_group_from_accel_closure (slist->data))
5496 clist = g_list_prepend (clist, slist->data);
5502 GtkAccelGroup *accel_group;
5507 destroy_accel_path (gpointer data)
5509 AccelPath *apath = data;
5511 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5513 /* closures_destroy takes care of unrefing the closure */
5514 g_object_unref (apath->accel_group);
5516 g_slice_free (AccelPath, apath);
5521 * gtk_widget_set_accel_path:
5522 * @widget: a #GtkWidget
5523 * @accel_path: (allow-none): path used to look up the accelerator
5524 * @accel_group: (allow-none): a #GtkAccelGroup.
5526 * Given an accelerator group, @accel_group, and an accelerator path,
5527 * @accel_path, sets up an accelerator in @accel_group so whenever the
5528 * key binding that is defined for @accel_path is pressed, @widget
5529 * will be activated. This removes any accelerators (for any
5530 * accelerator group) installed by previous calls to
5531 * gtk_widget_set_accel_path(). Associating accelerators with
5532 * paths allows them to be modified by the user and the modifications
5533 * to be saved for future use. (See gtk_accel_map_save().)
5535 * This function is a low level function that would most likely
5536 * be used by a menu creation system like #GtkUIManager. If you
5537 * use #GtkUIManager, setting up accelerator paths will be done
5540 * Even when you you aren't using #GtkUIManager, if you only want to
5541 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5542 * provides a somewhat more convenient interface.
5544 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5545 * pass a static string, you can save some memory by interning it first with
5546 * g_intern_static_string().
5549 gtk_widget_set_accel_path (GtkWidget *widget,
5550 const gchar *accel_path,
5551 GtkAccelGroup *accel_group)
5555 g_return_if_fail (GTK_IS_WIDGET (widget));
5556 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5560 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5561 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5563 gtk_accel_map_add_entry (accel_path, 0, 0);
5564 apath = g_slice_new (AccelPath);
5565 apath->accel_group = g_object_ref (accel_group);
5566 apath->path_quark = g_quark_from_string (accel_path);
5567 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5572 /* also removes possible old settings */
5573 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5576 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5578 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5582 _gtk_widget_get_accel_path (GtkWidget *widget,
5587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5589 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5591 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5592 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5596 * gtk_widget_mnemonic_activate:
5597 * @widget: a #GtkWidget
5598 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5600 * Emits the #GtkWidget::mnemonic-activate signal.
5602 * The default handler for this signal activates the @widget if
5603 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5606 * Returns: %TRUE if the signal has been handled
5609 gtk_widget_mnemonic_activate (GtkWidget *widget,
5610 gboolean group_cycling)
5614 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5616 group_cycling = group_cycling != FALSE;
5617 if (!gtk_widget_is_sensitive (widget))
5620 g_signal_emit (widget,
5621 widget_signals[MNEMONIC_ACTIVATE],
5629 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5630 gboolean group_cycling)
5632 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5633 gtk_widget_activate (widget);
5634 else if (gtk_widget_get_can_focus (widget))
5635 gtk_widget_grab_focus (widget);
5638 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5639 G_OBJECT_TYPE_NAME (widget));
5640 gtk_widget_error_bell (widget);
5645 static const cairo_user_data_key_t event_key;
5648 _gtk_cairo_get_event (cairo_t *cr)
5650 g_return_val_if_fail (cr != NULL, NULL);
5652 return cairo_get_user_data (cr, &event_key);
5656 gtk_cairo_set_event (cairo_t *cr,
5657 GdkEventExpose *event)
5659 cairo_set_user_data (cr, &event_key, event, NULL);
5663 * gtk_cairo_should_draw_window:
5664 * @cr: a cairo context
5665 * @window: the window to check. @window may not be an input-only
5668 * This function is supposed to be called in #GtkWidget::draw
5669 * implementations for widgets that support multiple windows.
5670 * @cr must be untransformed from invoking of the draw function.
5671 * This function will return %TRUE if the contents of the given
5672 * @window are supposed to be drawn and %FALSE otherwise. Note
5673 * that when the drawing was not initiated by the windowing
5674 * system this function will return %TRUE for all windows, so
5675 * you need to draw the bottommost window first. Also, do not
5676 * use "else if" statements to check which window should be drawn.
5678 * Returns: %TRUE if @window should be drawn
5683 gtk_cairo_should_draw_window (cairo_t *cr,
5686 GdkEventExpose *event;
5688 g_return_val_if_fail (cr != NULL, FALSE);
5689 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5691 event = _gtk_cairo_get_event (cr);
5693 return event == NULL ||
5694 event->window == window;
5698 gtk_widget_get_clip_draw (GtkWidget *widget)
5700 /* labels are not clipped, because clipping them would cause
5701 * mnemonics to not appear on characters that go beyond the
5703 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5705 if (GTK_IS_LABEL (widget))
5711 /* code shared by gtk_container_propagate_draw() and
5715 _gtk_widget_draw_internal (GtkWidget *widget,
5717 gboolean clip_to_size)
5719 GtkStyleContext *context;
5721 if (!gtk_widget_is_drawable (widget))
5724 clip_to_size &= gtk_widget_get_clip_draw (widget);
5728 cairo_rectangle (cr,
5730 widget->priv->allocation.width,
5731 widget->priv->allocation.height);
5735 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5739 g_signal_emit (widget, widget_signals[DRAW],
5743 if (cairo_status (cr) &&
5744 _gtk_cairo_get_event (cr))
5746 /* We check the event so we only warn about internal GTK calls.
5747 * Errors might come from PDF streams having write failures and
5748 * we don't want to spam stderr in that case.
5749 * We do want to catch errors from
5751 g_warning ("drawing failure for widget `%s': %s",
5752 G_OBJECT_TYPE_NAME (widget),
5753 cairo_status_to_string (cairo_status (cr)));
5757 context = gtk_widget_get_style_context (widget);
5758 _gtk_style_context_coalesce_animation_areas (context, widget);
5763 * @widget: the widget to draw. It must be drawable (see
5764 * gtk_widget_is_drawable()) and a size must have been allocated.
5765 * @cr: a cairo context to draw to
5767 * Draws @widget to @cr. The top left corner of the widget will be
5768 * drawn to the currently set origin point of @cr.
5770 * You should pass a cairo context as @cr argument that is in an
5771 * original state. Otherwise the resulting drawing is undefined. For
5772 * example changing the operator using cairo_set_operator() or the
5773 * line width using cairo_set_line_width() might have unwanted side
5775 * You may however change the context's transform matrix - like with
5776 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5777 * region with cairo_clip() prior to calling this function. Also, it
5778 * is fine to modify the context with cairo_save() and
5779 * cairo_push_group() prior to calling this function.
5781 * <note><para>Special purpose widgets may contain special code for
5782 * rendering to the screen and might appear differently on screen
5783 * and when rendered using gtk_widget_draw().</para></note>
5788 gtk_widget_draw (GtkWidget *widget,
5791 GdkEventExpose *tmp_event;
5793 g_return_if_fail (GTK_IS_WIDGET (widget));
5794 g_return_if_fail (!widget->priv->alloc_needed);
5795 g_return_if_fail (cr != NULL);
5798 /* We have to reset the event here so that draw functions can call
5799 * gtk_widget_draw() on random other widgets and get the desired
5800 * effect: Drawing all contents, not just the current window.
5802 tmp_event = _gtk_cairo_get_event (cr);
5803 gtk_cairo_set_event (cr, NULL);
5805 _gtk_widget_draw_internal (widget, cr, TRUE);
5807 gtk_cairo_set_event (cr, tmp_event);
5812 gtk_widget_real_key_press_event (GtkWidget *widget,
5815 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5819 gtk_widget_real_key_release_event (GtkWidget *widget,
5822 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5826 gtk_widget_real_focus_in_event (GtkWidget *widget,
5827 GdkEventFocus *event)
5829 gtk_widget_queue_shallow_draw (widget);
5835 gtk_widget_real_focus_out_event (GtkWidget *widget,
5836 GdkEventFocus *event)
5838 gtk_widget_queue_shallow_draw (widget);
5843 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5844 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5848 * @widget: a #GtkWidget
5849 * @event: a #GdkEvent
5851 * Rarely-used function. This function is used to emit
5852 * the event signals on a widget (those signals should never
5853 * be emitted without using this function to do so).
5854 * If you want to synthesize an event though, don't use this function;
5855 * instead, use gtk_main_do_event() so the event will behave as if
5856 * it were in the event queue. Don't synthesize expose events; instead,
5857 * use gdk_window_invalidate_rect() to invalidate a region of the
5860 * Return value: return from the event signal emission (%TRUE if
5861 * the event was handled)
5864 gtk_widget_event (GtkWidget *widget,
5867 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5868 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5870 if (event->type == GDK_EXPOSE)
5872 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5873 "the same effect, call gdk_window_invalidate_rect/region(), "
5874 "followed by gdk_window_process_updates().");
5878 return gtk_widget_event_internal (widget, event);
5881 /* Returns TRUE if a translation should be done */
5883 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5888 GdkWindow *w, *widget_window;
5890 if (!gtk_widget_get_has_window (widget))
5892 *x = -widget->priv->allocation.x;
5893 *y = -widget->priv->allocation.y;
5901 widget_window = gtk_widget_get_window (widget);
5903 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5906 gdk_window_get_position (w, &wx, &wy);
5923 * gtk_cairo_transform_to_window:
5924 * @cr: the cairo context to transform
5925 * @widget: the widget the context is currently centered for
5926 * @window: the window to transform the context to
5928 * Transforms the given cairo context @cr that from @widget-relative
5929 * coordinates to @window-relative coordinates.
5930 * If the @widget's window is not an ancestor of @window, no
5931 * modification will be applied.
5933 * This is the inverse to the transformation GTK applies when
5934 * preparing an expose event to be emitted with the #GtkWidget::draw
5935 * signal. It is intended to help porting multiwindow widgets from
5936 * GTK+ 2 to the rendering architecture of GTK+ 3.
5941 gtk_cairo_transform_to_window (cairo_t *cr,
5947 g_return_if_fail (cr != NULL);
5948 g_return_if_fail (GTK_IS_WIDGET (widget));
5949 g_return_if_fail (GDK_IS_WINDOW (window));
5951 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5952 cairo_translate (cr, x, y);
5956 * gtk_widget_send_expose:
5957 * @widget: a #GtkWidget
5958 * @event: a expose #GdkEvent
5960 * Very rarely-used function. This function is used to emit
5961 * an expose event on a widget. This function is not normally used
5962 * directly. The only time it is used is when propagating an expose
5963 * event to a child %NO_WINDOW widget, and that is normally done
5964 * using gtk_container_propagate_draw().
5966 * If you want to force an area of a window to be redrawn,
5967 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5968 * To cause the redraw to be done immediately, follow that call
5969 * with a call to gdk_window_process_updates().
5971 * Return value: return from the event signal emission (%TRUE if
5972 * the event was handled)
5975 gtk_widget_send_expose (GtkWidget *widget,
5978 gboolean result = FALSE;
5983 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5984 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5985 g_return_val_if_fail (event != NULL, TRUE);
5986 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5988 cr = gdk_cairo_create (event->expose.window);
5989 gtk_cairo_set_event (cr, &event->expose);
5991 gdk_cairo_region (cr, event->expose.region);
5994 do_clip = _gtk_widget_get_translation_to_window (widget,
5995 event->expose.window,
5997 cairo_translate (cr, -x, -y);
5999 _gtk_widget_draw_internal (widget, cr, do_clip);
6001 /* unset here, so if someone keeps a reference to cr we
6002 * don't leak the window. */
6003 gtk_cairo_set_event (cr, NULL);
6010 event_window_is_still_viewable (GdkEvent *event)
6012 /* Check that we think the event's window is viewable before
6013 * delivering the event, to prevent suprises. We do this here
6014 * at the last moment, since the event may have been queued
6015 * up behind other events, held over a recursive main loop, etc.
6017 switch (event->type)
6020 case GDK_MOTION_NOTIFY:
6021 case GDK_BUTTON_PRESS:
6022 case GDK_2BUTTON_PRESS:
6023 case GDK_3BUTTON_PRESS:
6025 case GDK_ENTER_NOTIFY:
6026 case GDK_PROXIMITY_IN:
6028 return event->any.window && gdk_window_is_viewable (event->any.window);
6031 /* The following events are the second half of paired events;
6032 * we always deliver them to deal with widgets that clean up
6033 * on the second half.
6035 case GDK_BUTTON_RELEASE:
6036 case GDK_KEY_RELEASE:
6037 case GDK_LEAVE_NOTIFY:
6038 case GDK_PROXIMITY_OUT:
6042 /* Remaining events would make sense on an not-viewable window,
6043 * or don't have an associated window.
6050 gtk_widget_event_internal (GtkWidget *widget,
6053 gboolean return_val = FALSE;
6055 /* We check only once for is-still-visible; if someone
6056 * hides the window in on of the signals on the widget,
6057 * they are responsible for returning TRUE to terminate
6060 if (!event_window_is_still_viewable (event))
6063 g_object_ref (widget);
6065 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6066 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6071 switch (event->type)
6077 case GDK_BUTTON_PRESS:
6078 case GDK_2BUTTON_PRESS:
6079 case GDK_3BUTTON_PRESS:
6080 signal_num = BUTTON_PRESS_EVENT;
6082 case GDK_TOUCH_BEGIN:
6083 case GDK_TOUCH_UPDATE:
6085 case GDK_TOUCH_CANCEL:
6086 signal_num = TOUCH_EVENT;
6089 signal_num = SCROLL_EVENT;
6091 case GDK_BUTTON_RELEASE:
6092 signal_num = BUTTON_RELEASE_EVENT;
6094 case GDK_MOTION_NOTIFY:
6095 signal_num = MOTION_NOTIFY_EVENT;
6098 signal_num = DELETE_EVENT;
6101 signal_num = DESTROY_EVENT;
6102 _gtk_tooltip_hide (widget);
6105 signal_num = KEY_PRESS_EVENT;
6107 case GDK_KEY_RELEASE:
6108 signal_num = KEY_RELEASE_EVENT;
6110 case GDK_ENTER_NOTIFY:
6111 signal_num = ENTER_NOTIFY_EVENT;
6113 case GDK_LEAVE_NOTIFY:
6114 signal_num = LEAVE_NOTIFY_EVENT;
6116 case GDK_FOCUS_CHANGE:
6117 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6118 if (event->focus_change.in)
6119 _gtk_tooltip_focus_in (widget);
6121 _gtk_tooltip_focus_out (widget);
6124 signal_num = CONFIGURE_EVENT;
6127 signal_num = MAP_EVENT;
6130 signal_num = UNMAP_EVENT;
6132 case GDK_WINDOW_STATE:
6133 signal_num = WINDOW_STATE_EVENT;
6135 case GDK_PROPERTY_NOTIFY:
6136 signal_num = PROPERTY_NOTIFY_EVENT;
6138 case GDK_SELECTION_CLEAR:
6139 signal_num = SELECTION_CLEAR_EVENT;
6141 case GDK_SELECTION_REQUEST:
6142 signal_num = SELECTION_REQUEST_EVENT;
6144 case GDK_SELECTION_NOTIFY:
6145 signal_num = SELECTION_NOTIFY_EVENT;
6147 case GDK_PROXIMITY_IN:
6148 signal_num = PROXIMITY_IN_EVENT;
6150 case GDK_PROXIMITY_OUT:
6151 signal_num = PROXIMITY_OUT_EVENT;
6153 case GDK_VISIBILITY_NOTIFY:
6154 signal_num = VISIBILITY_NOTIFY_EVENT;
6156 case GDK_GRAB_BROKEN:
6157 signal_num = GRAB_BROKEN_EVENT;
6160 signal_num = DAMAGE_EVENT;
6163 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6167 if (signal_num != -1)
6168 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6170 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6171 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6175 g_object_unref (widget);
6181 * gtk_widget_activate:
6182 * @widget: a #GtkWidget that's activatable
6184 * For widgets that can be "activated" (buttons, menu items, etc.)
6185 * this function activates them. Activation is what happens when you
6186 * press Enter on a widget during key navigation. If @widget isn't
6187 * activatable, the function returns %FALSE.
6189 * Return value: %TRUE if the widget was activatable
6192 gtk_widget_activate (GtkWidget *widget)
6194 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6196 if (WIDGET_CLASS (widget)->activate_signal)
6198 /* FIXME: we should eventually check the signals signature here */
6199 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6208 gtk_widget_reparent_subwindows (GtkWidget *widget,
6209 GdkWindow *new_window)
6211 GtkWidgetPrivate *priv = widget->priv;
6213 if (!gtk_widget_get_has_window (widget))
6215 GList *children = gdk_window_get_children (priv->window);
6218 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6220 GdkWindow *window = tmp_list->data;
6223 gdk_window_get_user_data (window, &child);
6224 while (child && child != widget)
6225 child = ((GtkWidget*) child)->priv->parent;
6228 gdk_window_reparent (window, new_window, 0, 0);
6231 g_list_free (children);
6236 GList *tmp_list, *children;
6238 parent = gdk_window_get_parent (priv->window);
6241 gdk_window_reparent (priv->window, new_window, 0, 0);
6244 children = gdk_window_get_children (parent);
6246 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6248 GdkWindow *window = tmp_list->data;
6251 gdk_window_get_user_data (window, &child);
6253 if (child == widget)
6254 gdk_window_reparent (window, new_window, 0, 0);
6257 g_list_free (children);
6263 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6264 gpointer client_data)
6266 GtkWidgetPrivate *priv = widget->priv;
6268 g_assert (client_data != NULL);
6270 if (!gtk_widget_get_has_window (widget))
6273 g_object_unref (priv->window);
6274 priv->window = (GdkWindow*) client_data;
6276 g_object_ref (priv->window);
6278 if (GTK_IS_CONTAINER (widget))
6279 gtk_container_forall (GTK_CONTAINER (widget),
6280 gtk_widget_reparent_fixup_child,
6286 * gtk_widget_reparent:
6287 * @widget: a #GtkWidget
6288 * @new_parent: a #GtkContainer to move the widget into
6290 * Moves a widget from one #GtkContainer to another, handling reference
6291 * count issues to avoid destroying the widget.
6294 gtk_widget_reparent (GtkWidget *widget,
6295 GtkWidget *new_parent)
6297 GtkWidgetPrivate *priv;
6299 g_return_if_fail (GTK_IS_WIDGET (widget));
6300 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6301 priv = widget->priv;
6302 g_return_if_fail (priv->parent != NULL);
6304 if (priv->parent != new_parent)
6306 /* First try to see if we can get away without unrealizing
6307 * the widget as we reparent it. if so we set a flag so
6308 * that gtk_widget_unparent doesn't unrealize widget
6310 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6311 priv->in_reparent = TRUE;
6313 g_object_ref (widget);
6314 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6315 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6316 g_object_unref (widget);
6318 if (priv->in_reparent)
6320 priv->in_reparent = FALSE;
6322 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6323 gtk_widget_reparent_fixup_child (widget,
6324 gtk_widget_get_parent_window (widget));
6327 g_object_notify (G_OBJECT (widget), "parent");
6332 * gtk_widget_intersect:
6333 * @widget: a #GtkWidget
6334 * @area: a rectangle
6335 * @intersection: rectangle to store intersection of @widget and @area
6337 * Computes the intersection of a @widget's area and @area, storing
6338 * the intersection in @intersection, and returns %TRUE if there was
6339 * an intersection. @intersection may be %NULL if you're only
6340 * interested in whether there was an intersection.
6342 * Return value: %TRUE if there was an intersection
6345 gtk_widget_intersect (GtkWidget *widget,
6346 const GdkRectangle *area,
6347 GdkRectangle *intersection)
6349 GtkWidgetPrivate *priv;
6354 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6355 g_return_val_if_fail (area != NULL, FALSE);
6357 priv = widget->priv;
6360 dest = intersection;
6364 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6366 if (return_val && intersection && gtk_widget_get_has_window (widget))
6368 intersection->x -= priv->allocation.x;
6369 intersection->y -= priv->allocation.y;
6376 * gtk_widget_region_intersect:
6377 * @widget: a #GtkWidget
6378 * @region: a #cairo_region_t, in the same coordinate system as
6379 * @widget->allocation. That is, relative to @widget->window
6380 * for %NO_WINDOW widgets; relative to the parent window
6381 * of @widget->window for widgets with their own window.
6383 * Computes the intersection of a @widget's area and @region, returning
6384 * the intersection. The result may be empty, use cairo_region_is_empty() to
6387 * Returns: A newly allocated region holding the intersection of @widget
6388 * and @region. The coordinates of the return value are relative to
6389 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6390 * window of @widget->window for widgets with their own window.
6393 gtk_widget_region_intersect (GtkWidget *widget,
6394 const cairo_region_t *region)
6397 cairo_region_t *dest;
6399 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6400 g_return_val_if_fail (region != NULL, NULL);
6402 gtk_widget_get_allocation (widget, &rect);
6404 dest = cairo_region_create_rectangle (&rect);
6406 cairo_region_intersect (dest, region);
6412 * _gtk_widget_grab_notify:
6413 * @widget: a #GtkWidget
6414 * @was_grabbed: whether a grab is now in effect
6416 * Emits the #GtkWidget::grab-notify signal on @widget.
6421 _gtk_widget_grab_notify (GtkWidget *widget,
6422 gboolean was_grabbed)
6424 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6428 * gtk_widget_grab_focus:
6429 * @widget: a #GtkWidget
6431 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6432 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6433 * something like #GtkFrame won't work.
6435 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6436 * gtk_widget_set_can_focus() to modify that flag.
6438 * The widget also needs to be realized and mapped. This is indicated by the
6439 * related signals. Grabbing the focus immediately after creating the widget
6440 * will likely fail and cause critical warnings.
6443 gtk_widget_grab_focus (GtkWidget *widget)
6445 g_return_if_fail (GTK_IS_WIDGET (widget));
6447 if (!gtk_widget_is_sensitive (widget))
6450 g_object_ref (widget);
6451 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6452 g_object_notify (G_OBJECT (widget), "has-focus");
6453 g_object_unref (widget);
6457 reset_focus_recurse (GtkWidget *widget,
6460 if (GTK_IS_CONTAINER (widget))
6462 GtkContainer *container;
6464 container = GTK_CONTAINER (widget);
6465 gtk_container_set_focus_child (container, NULL);
6467 gtk_container_foreach (container,
6468 reset_focus_recurse,
6474 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6476 if (gtk_widget_get_can_focus (focus_widget))
6478 GtkWidget *toplevel;
6481 /* clear the current focus setting, break if the current widget
6482 * is the focus widget's parent, since containers above that will
6483 * be set by the next loop.
6485 toplevel = gtk_widget_get_toplevel (focus_widget);
6486 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6488 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6490 if (widget == focus_widget)
6492 /* We call _gtk_window_internal_set_focus() here so that the
6493 * toplevel window can request the focus if necessary.
6494 * This is needed when the toplevel is a GtkPlug
6496 if (!gtk_widget_has_focus (widget))
6497 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6504 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6506 if (widget != common_ancestor)
6508 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6510 widget = widget->priv->parent;
6511 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6516 else if (toplevel != focus_widget)
6518 /* gtk_widget_grab_focus() operates on a tree without window...
6519 * actually, this is very questionable behaviour.
6522 gtk_container_foreach (GTK_CONTAINER (toplevel),
6523 reset_focus_recurse,
6527 /* now propagate the new focus up the widget tree and finally
6528 * set it on the window
6530 widget = focus_widget;
6531 while (widget->priv->parent)
6533 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6534 widget = widget->priv->parent;
6536 if (GTK_IS_WINDOW (widget))
6537 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6542 gtk_widget_real_query_tooltip (GtkWidget *widget,
6545 gboolean keyboard_tip,
6546 GtkTooltip *tooltip)
6548 gchar *tooltip_markup;
6549 gboolean has_tooltip;
6551 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6552 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6554 if (has_tooltip && tooltip_markup)
6556 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6564 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6565 GtkStateFlags old_state)
6567 gtk_widget_update_pango_context (widget);
6571 gtk_widget_real_style_updated (GtkWidget *widget)
6573 GtkWidgetPrivate *priv = widget->priv;
6575 gtk_widget_update_pango_context (widget);
6577 if (priv->style != NULL &&
6578 priv->style != gtk_widget_get_default_style ())
6580 /* Trigger ::style-set for old
6581 * widgets not listening to this
6583 g_signal_emit (widget,
6584 widget_signals[STYLE_SET],
6586 widget->priv->style);
6589 if (widget->priv->context)
6591 if (gtk_widget_get_realized (widget) &&
6592 gtk_widget_get_has_window (widget))
6593 gtk_style_context_set_background (widget->priv->context,
6594 widget->priv->window);
6597 if (widget->priv->anchored)
6598 gtk_widget_queue_resize (widget);
6602 gtk_widget_real_show_help (GtkWidget *widget,
6603 GtkWidgetHelpType help_type)
6605 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6607 _gtk_tooltip_toggle_keyboard_mode (widget);
6616 gtk_widget_real_focus (GtkWidget *widget,
6617 GtkDirectionType direction)
6619 if (!gtk_widget_get_can_focus (widget))
6622 if (!gtk_widget_is_focus (widget))
6624 gtk_widget_grab_focus (widget);
6632 gtk_widget_real_move_focus (GtkWidget *widget,
6633 GtkDirectionType direction)
6635 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6637 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6639 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6645 gtk_widget_real_keynav_failed (GtkWidget *widget,
6646 GtkDirectionType direction)
6648 gboolean cursor_only;
6652 case GTK_DIR_TAB_FORWARD:
6653 case GTK_DIR_TAB_BACKWARD:
6660 g_object_get (gtk_widget_get_settings (widget),
6661 "gtk-keynav-cursor-only", &cursor_only,
6668 gtk_widget_error_bell (widget);
6674 * gtk_widget_set_can_focus:
6675 * @widget: a #GtkWidget
6676 * @can_focus: whether or not @widget can own the input focus.
6678 * Specifies whether @widget can own the input focus. See
6679 * gtk_widget_grab_focus() for actually setting the input focus on a
6685 gtk_widget_set_can_focus (GtkWidget *widget,
6688 g_return_if_fail (GTK_IS_WIDGET (widget));
6690 if (widget->priv->can_focus != can_focus)
6692 widget->priv->can_focus = can_focus;
6694 gtk_widget_queue_resize (widget);
6695 g_object_notify (G_OBJECT (widget), "can-focus");
6700 * gtk_widget_get_can_focus:
6701 * @widget: a #GtkWidget
6703 * Determines whether @widget can own the input focus. See
6704 * gtk_widget_set_can_focus().
6706 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6711 gtk_widget_get_can_focus (GtkWidget *widget)
6713 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6715 return widget->priv->can_focus;
6719 * gtk_widget_has_focus:
6720 * @widget: a #GtkWidget
6722 * Determines if the widget has the global input focus. See
6723 * gtk_widget_is_focus() for the difference between having the global
6724 * input focus, and only having the focus within a toplevel.
6726 * Return value: %TRUE if the widget has the global input focus.
6731 gtk_widget_has_focus (GtkWidget *widget)
6733 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6735 return widget->priv->has_focus;
6739 * gtk_widget_has_visible_focus:
6740 * @widget: a #GtkWidget
6742 * Determines if the widget should show a visible indication that
6743 * it has the global input focus. This is a convenience function for
6744 * use in ::draw handlers that takes into account whether focus
6745 * indication should currently be shown in the toplevel window of
6746 * @widget. See gtk_window_get_focus_visible() for more information
6747 * about focus indication.
6749 * To find out if the widget has the global input focus, use
6750 * gtk_widget_has_focus().
6752 * Return value: %TRUE if the widget should display a 'focus rectangle'
6757 gtk_widget_has_visible_focus (GtkWidget *widget)
6759 gboolean draw_focus;
6761 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6763 if (widget->priv->has_focus)
6765 GtkWidget *toplevel;
6767 toplevel = gtk_widget_get_toplevel (widget);
6769 if (GTK_IS_WINDOW (toplevel))
6770 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6781 * gtk_widget_is_focus:
6782 * @widget: a #GtkWidget
6784 * Determines if the widget is the focus widget within its
6785 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6786 * necessarily set; %HAS_FOCUS will only be set if the
6787 * toplevel widget additionally has the global input focus.)
6789 * Return value: %TRUE if the widget is the focus widget.
6792 gtk_widget_is_focus (GtkWidget *widget)
6794 GtkWidget *toplevel;
6796 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6798 toplevel = gtk_widget_get_toplevel (widget);
6800 if (GTK_IS_WINDOW (toplevel))
6801 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6807 * gtk_widget_set_can_default:
6808 * @widget: a #GtkWidget
6809 * @can_default: whether or not @widget can be a default widget.
6811 * Specifies whether @widget can be a default widget. See
6812 * gtk_widget_grab_default() for details about the meaning of
6818 gtk_widget_set_can_default (GtkWidget *widget,
6819 gboolean can_default)
6821 g_return_if_fail (GTK_IS_WIDGET (widget));
6823 if (widget->priv->can_default != can_default)
6825 widget->priv->can_default = can_default;
6827 gtk_widget_queue_resize (widget);
6828 g_object_notify (G_OBJECT (widget), "can-default");
6833 * gtk_widget_get_can_default:
6834 * @widget: a #GtkWidget
6836 * Determines whether @widget can be a default widget. See
6837 * gtk_widget_set_can_default().
6839 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6844 gtk_widget_get_can_default (GtkWidget *widget)
6846 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6848 return widget->priv->can_default;
6852 * gtk_widget_has_default:
6853 * @widget: a #GtkWidget
6855 * Determines whether @widget is the current default widget within its
6856 * toplevel. See gtk_widget_set_can_default().
6858 * Return value: %TRUE if @widget is the current default widget within
6859 * its toplevel, %FALSE otherwise
6864 gtk_widget_has_default (GtkWidget *widget)
6866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6868 return widget->priv->has_default;
6872 _gtk_widget_set_has_default (GtkWidget *widget,
6873 gboolean has_default)
6875 widget->priv->has_default = has_default;
6879 * gtk_widget_grab_default:
6880 * @widget: a #GtkWidget
6882 * Causes @widget to become the default widget. @widget must have the
6883 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6884 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6885 * %TRUE)</literal>. The default widget is activated when
6886 * the user presses Enter in a window. Default widgets must be
6887 * activatable, that is, gtk_widget_activate() should affect them. Note
6888 * that #GtkEntry widgets require the "activates-default" property
6889 * set to %TRUE before they activate the default widget when Enter
6890 * is pressed and the #GtkEntry is focused.
6893 gtk_widget_grab_default (GtkWidget *widget)
6897 g_return_if_fail (GTK_IS_WIDGET (widget));
6898 g_return_if_fail (gtk_widget_get_can_default (widget));
6900 window = gtk_widget_get_toplevel (widget);
6902 if (window && gtk_widget_is_toplevel (window))
6903 gtk_window_set_default (GTK_WINDOW (window), widget);
6905 g_warning (G_STRLOC ": widget not within a GtkWindow");
6909 * gtk_widget_set_receives_default:
6910 * @widget: a #GtkWidget
6911 * @receives_default: whether or not @widget can be a default widget.
6913 * Specifies whether @widget will be treated as the default widget
6914 * within its toplevel when it has the focus, even if another widget
6917 * See gtk_widget_grab_default() for details about the meaning of
6923 gtk_widget_set_receives_default (GtkWidget *widget,
6924 gboolean receives_default)
6926 g_return_if_fail (GTK_IS_WIDGET (widget));
6928 if (widget->priv->receives_default != receives_default)
6930 widget->priv->receives_default = receives_default;
6932 g_object_notify (G_OBJECT (widget), "receives-default");
6937 * gtk_widget_get_receives_default:
6938 * @widget: a #GtkWidget
6940 * Determines whether @widget is alyways treated as default widget
6941 * withing its toplevel when it has the focus, even if another widget
6944 * See gtk_widget_set_receives_default().
6946 * Return value: %TRUE if @widget acts as default widget when focussed,
6952 gtk_widget_get_receives_default (GtkWidget *widget)
6954 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6956 return widget->priv->receives_default;
6960 * gtk_widget_has_grab:
6961 * @widget: a #GtkWidget
6963 * Determines whether the widget is currently grabbing events, so it
6964 * is the only widget receiving input events (keyboard and mouse).
6966 * See also gtk_grab_add().
6968 * Return value: %TRUE if the widget is in the grab_widgets stack
6973 gtk_widget_has_grab (GtkWidget *widget)
6975 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6977 return widget->priv->has_grab;
6981 _gtk_widget_set_has_grab (GtkWidget *widget,
6984 widget->priv->has_grab = has_grab;
6988 * gtk_widget_device_is_shadowed:
6989 * @widget: a #GtkWidget
6990 * @device: a #GdkDevice
6992 * Returns %TRUE if @device has been shadowed by a GTK+
6993 * device grab on another widget, so it would stop sending
6994 * events to @widget. This may be used in the
6995 * #GtkWidget::grab-notify signal to check for specific
6996 * devices. See gtk_device_grab_add().
6998 * Returns: %TRUE if there is an ongoing grab on @device
6999 * by another #GtkWidget than @widget.
7004 gtk_widget_device_is_shadowed (GtkWidget *widget,
7007 GtkWindowGroup *group;
7008 GtkWidget *grab_widget, *toplevel;
7010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7011 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7013 if (!gtk_widget_get_realized (widget))
7016 toplevel = gtk_widget_get_toplevel (widget);
7018 if (GTK_IS_WINDOW (toplevel))
7019 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7021 group = gtk_window_get_group (NULL);
7023 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7025 /* Widget not inside the hierarchy of grab_widget */
7027 widget != grab_widget &&
7028 !gtk_widget_is_ancestor (widget, grab_widget))
7031 grab_widget = gtk_window_group_get_current_grab (group);
7032 if (grab_widget && widget != grab_widget &&
7033 !gtk_widget_is_ancestor (widget, grab_widget))
7040 * gtk_widget_set_name:
7041 * @widget: a #GtkWidget
7042 * @name: name for the widget
7044 * Widgets can be named, which allows you to refer to them from a
7045 * CSS file. You can apply a style to widgets with a particular name
7046 * in the CSS file. See the documentation for the CSS syntax (on the
7047 * same page as the docs for #GtkStyleContext).
7049 * Note that the CSS syntax has certain special characters to delimit
7050 * and represent elements in a selector (period, #, >, *...),
7051 * so using these will make your widget impossible to match by name.
7052 * Any combination of alphanumeric symbols, dashes and underscores will
7056 gtk_widget_set_name (GtkWidget *widget,
7059 GtkWidgetPrivate *priv;
7062 g_return_if_fail (GTK_IS_WIDGET (widget));
7064 priv = widget->priv;
7066 new_name = g_strdup (name);
7067 g_free (priv->name);
7068 priv->name = new_name;
7070 gtk_widget_reset_style (widget);
7072 g_object_notify (G_OBJECT (widget), "name");
7076 * gtk_widget_get_name:
7077 * @widget: a #GtkWidget
7079 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7080 * significance of widget names.
7082 * Return value: name of the widget. This string is owned by GTK+ and
7083 * should not be modified or freed
7086 gtk_widget_get_name (GtkWidget *widget)
7088 GtkWidgetPrivate *priv;
7090 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7092 priv = widget->priv;
7096 return G_OBJECT_TYPE_NAME (widget);
7100 _gtk_widget_update_state_flags (GtkWidget *widget,
7101 GtkStateFlags flags,
7104 GtkWidgetPrivate *priv;
7106 priv = widget->priv;
7108 /* Handle insensitive first, since it is propagated
7109 * differently throughout the widget hierarchy.
7111 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7112 gtk_widget_set_sensitive (widget, TRUE);
7113 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7114 gtk_widget_set_sensitive (widget, FALSE);
7115 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7116 gtk_widget_set_sensitive (widget, TRUE);
7118 if (operation != STATE_CHANGE_REPLACE)
7119 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7122 operation == STATE_CHANGE_REPLACE)
7127 data.operation = operation;
7129 gtk_widget_propagate_state (widget, &data);
7131 gtk_widget_queue_resize (widget);
7136 * gtk_widget_set_state_flags:
7137 * @widget: a #GtkWidget
7138 * @flags: State flags to turn on
7139 * @clear: Whether to clear state before turning on @flags
7141 * This function is for use in widget implementations. Turns on flag
7142 * values in the current widget state (insensitive, prelighted, etc.).
7144 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7145 * will be propagated down to all non-internal children if @widget is a
7146 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7147 * down to all #GtkContainer children by different means than turning on the
7148 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7149 * gtk_widget_is_sensitive() will make use of these.
7154 gtk_widget_set_state_flags (GtkWidget *widget,
7155 GtkStateFlags flags,
7158 g_return_if_fail (GTK_IS_WIDGET (widget));
7160 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7161 (clear && widget->priv->state_flags == flags))
7165 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7167 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7171 * gtk_widget_unset_state_flags:
7172 * @widget: a #GtkWidget
7173 * @flags: State flags to turn off
7175 * This function is for use in widget implementations. Turns off flag
7176 * values for the current widget state (insensitive, prelighted, etc.).
7177 * See gtk_widget_set_state_flags().
7182 gtk_widget_unset_state_flags (GtkWidget *widget,
7183 GtkStateFlags flags)
7185 g_return_if_fail (GTK_IS_WIDGET (widget));
7187 if ((widget->priv->state_flags & flags) == 0)
7190 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7194 * gtk_widget_get_state_flags:
7195 * @widget: a #GtkWidget
7197 * Returns the widget state as a flag set. It is worth mentioning
7198 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7199 * returned, that is, also based on parent insensitivity, even if
7200 * @widget itself is sensitive.
7202 * Returns: The state flags for widget
7207 gtk_widget_get_state_flags (GtkWidget *widget)
7209 GtkStateFlags flags;
7211 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7213 flags = widget->priv->state_flags;
7215 if (gtk_widget_has_focus (widget))
7216 flags |= GTK_STATE_FLAG_FOCUSED;
7222 * gtk_widget_set_state:
7223 * @widget: a #GtkWidget
7224 * @state: new state for @widget
7226 * This function is for use in widget implementations. Sets the state
7227 * of a widget (insensitive, prelighted, etc.) Usually you should set
7228 * the state using wrapper functions such as gtk_widget_set_sensitive().
7230 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7233 gtk_widget_set_state (GtkWidget *widget,
7236 GtkStateFlags flags;
7238 if (state == gtk_widget_get_state (widget))
7243 case GTK_STATE_ACTIVE:
7244 flags = GTK_STATE_FLAG_ACTIVE;
7246 case GTK_STATE_PRELIGHT:
7247 flags = GTK_STATE_FLAG_PRELIGHT;
7249 case GTK_STATE_SELECTED:
7250 flags = GTK_STATE_FLAG_SELECTED;
7252 case GTK_STATE_INSENSITIVE:
7253 flags = GTK_STATE_FLAG_INSENSITIVE;
7255 case GTK_STATE_INCONSISTENT:
7256 flags = GTK_STATE_FLAG_INCONSISTENT;
7258 case GTK_STATE_FOCUSED:
7259 flags = GTK_STATE_FLAG_FOCUSED;
7261 case GTK_STATE_NORMAL:
7267 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7271 * gtk_widget_get_state:
7272 * @widget: a #GtkWidget
7274 * Returns the widget's state. See gtk_widget_set_state().
7276 * Returns: the state of @widget.
7280 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7283 gtk_widget_get_state (GtkWidget *widget)
7285 GtkStateFlags flags;
7287 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7289 flags = gtk_widget_get_state_flags (widget);
7291 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7292 return GTK_STATE_INSENSITIVE;
7293 else if (flags & GTK_STATE_FLAG_ACTIVE)
7294 return GTK_STATE_ACTIVE;
7295 else if (flags & GTK_STATE_FLAG_SELECTED)
7296 return GTK_STATE_SELECTED;
7297 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7298 return GTK_STATE_PRELIGHT;
7300 return GTK_STATE_NORMAL;
7304 * gtk_widget_set_visible:
7305 * @widget: a #GtkWidget
7306 * @visible: whether the widget should be shown or not
7308 * Sets the visibility state of @widget. Note that setting this to
7309 * %TRUE doesn't mean the widget is actually viewable, see
7310 * gtk_widget_get_visible().
7312 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7313 * but is nicer to use when the visibility of the widget depends on
7319 gtk_widget_set_visible (GtkWidget *widget,
7322 g_return_if_fail (GTK_IS_WIDGET (widget));
7324 if (visible != gtk_widget_get_visible (widget))
7327 gtk_widget_show (widget);
7329 gtk_widget_hide (widget);
7334 _gtk_widget_set_visible_flag (GtkWidget *widget,
7337 widget->priv->visible = visible;
7341 * gtk_widget_get_visible:
7342 * @widget: a #GtkWidget
7344 * Determines whether the widget is visible. Note that this doesn't
7345 * take into account whether the widget's parent is also visible
7346 * or the widget is obscured in any way.
7348 * See gtk_widget_set_visible().
7350 * Return value: %TRUE if the widget is visible
7355 gtk_widget_get_visible (GtkWidget *widget)
7357 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7359 return widget->priv->visible;
7363 * gtk_widget_set_has_window:
7364 * @widget: a #GtkWidget
7365 * @has_window: whether or not @widget has a window.
7367 * Specifies whether @widget has a #GdkWindow of its own. Note that
7368 * all realized widgets have a non-%NULL "window" pointer
7369 * (gtk_widget_get_window() never returns a %NULL window when a widget
7370 * is realized), but for many of them it's actually the #GdkWindow of
7371 * one of its parent widgets. Widgets that do not create a %window for
7372 * themselves in #GtkWidget::realize must announce this by
7373 * calling this function with @has_window = %FALSE.
7375 * This function should only be called by widget implementations,
7376 * and they should call it in their init() function.
7381 gtk_widget_set_has_window (GtkWidget *widget,
7382 gboolean has_window)
7384 g_return_if_fail (GTK_IS_WIDGET (widget));
7386 widget->priv->no_window = !has_window;
7390 * gtk_widget_get_has_window:
7391 * @widget: a #GtkWidget
7393 * Determines whether @widget has a #GdkWindow of its own. See
7394 * gtk_widget_set_has_window().
7396 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7401 gtk_widget_get_has_window (GtkWidget *widget)
7403 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7405 return ! widget->priv->no_window;
7409 * gtk_widget_is_toplevel:
7410 * @widget: a #GtkWidget
7412 * Determines whether @widget is a toplevel widget.
7414 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7415 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7418 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7423 gtk_widget_is_toplevel (GtkWidget *widget)
7425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7427 return widget->priv->toplevel;
7431 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7432 gboolean is_toplevel)
7434 widget->priv->toplevel = is_toplevel;
7438 * gtk_widget_is_drawable:
7439 * @widget: a #GtkWidget
7441 * Determines whether @widget can be drawn to. A widget can be drawn
7442 * to if it is mapped and visible.
7444 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7449 gtk_widget_is_drawable (GtkWidget *widget)
7451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7453 return (gtk_widget_get_visible (widget) &&
7454 gtk_widget_get_mapped (widget));
7458 * gtk_widget_get_realized:
7459 * @widget: a #GtkWidget
7461 * Determines whether @widget is realized.
7463 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7468 gtk_widget_get_realized (GtkWidget *widget)
7470 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7472 return widget->priv->realized;
7476 * gtk_widget_set_realized:
7477 * @widget: a #GtkWidget
7478 * @realized: %TRUE to mark the widget as realized
7480 * Marks the widget as being realized.
7482 * This function should only ever be called in a derived widget's
7483 * "realize" or "unrealize" implementation.
7488 gtk_widget_set_realized (GtkWidget *widget,
7491 g_return_if_fail (GTK_IS_WIDGET (widget));
7493 widget->priv->realized = realized;
7497 * gtk_widget_get_mapped:
7498 * @widget: a #GtkWidget
7500 * Whether the widget is mapped.
7502 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7507 gtk_widget_get_mapped (GtkWidget *widget)
7509 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7511 return widget->priv->mapped;
7515 * gtk_widget_set_mapped:
7516 * @widget: a #GtkWidget
7517 * @mapped: %TRUE to mark the widget as mapped
7519 * Marks the widget as being realized.
7521 * This function should only ever be called in a derived widget's
7522 * "map" or "unmap" implementation.
7527 gtk_widget_set_mapped (GtkWidget *widget,
7530 g_return_if_fail (GTK_IS_WIDGET (widget));
7532 widget->priv->mapped = mapped;
7536 * gtk_widget_set_app_paintable:
7537 * @widget: a #GtkWidget
7538 * @app_paintable: %TRUE if the application will paint on the widget
7540 * Sets whether the application intends to draw on the widget in
7541 * an #GtkWidget::draw handler.
7543 * This is a hint to the widget and does not affect the behavior of
7544 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7545 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7546 * the effect is to suppress default themed drawing of the widget's
7547 * background. (Children of the widget will still be drawn.) The application
7548 * is then entirely responsible for drawing the widget background.
7550 * Note that the background is still drawn when the widget is mapped.
7553 gtk_widget_set_app_paintable (GtkWidget *widget,
7554 gboolean app_paintable)
7556 g_return_if_fail (GTK_IS_WIDGET (widget));
7558 app_paintable = (app_paintable != FALSE);
7560 if (widget->priv->app_paintable != app_paintable)
7562 widget->priv->app_paintable = app_paintable;
7564 if (gtk_widget_is_drawable (widget))
7565 gtk_widget_queue_draw (widget);
7567 g_object_notify (G_OBJECT (widget), "app-paintable");
7572 * gtk_widget_get_app_paintable:
7573 * @widget: a #GtkWidget
7575 * Determines whether the application intends to draw on the widget in
7576 * an #GtkWidget::draw handler.
7578 * See gtk_widget_set_app_paintable()
7580 * Return value: %TRUE if the widget is app paintable
7585 gtk_widget_get_app_paintable (GtkWidget *widget)
7587 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7589 return widget->priv->app_paintable;
7593 * gtk_widget_set_double_buffered:
7594 * @widget: a #GtkWidget
7595 * @double_buffered: %TRUE to double-buffer a widget
7597 * Widgets are double buffered by default; you can use this function
7598 * to turn off the buffering. "Double buffered" simply means that
7599 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7600 * automatically around expose events sent to the
7601 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7602 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7603 * buffer to the screen. The result is that users see the window
7604 * update in one smooth step, and don't see individual graphics
7605 * primitives being rendered.
7607 * In very simple terms, double buffered widgets don't flicker,
7608 * so you would only use this function to turn off double buffering
7609 * if you had special needs and really knew what you were doing.
7611 * Note: if you turn off double-buffering, you have to handle
7612 * expose events, since even the clearing to the background color or
7613 * pixmap will not happen automatically (as it is done in
7614 * gdk_window_begin_paint()).
7617 gtk_widget_set_double_buffered (GtkWidget *widget,
7618 gboolean double_buffered)
7620 g_return_if_fail (GTK_IS_WIDGET (widget));
7622 double_buffered = (double_buffered != FALSE);
7624 if (widget->priv->double_buffered != double_buffered)
7626 widget->priv->double_buffered = double_buffered;
7628 g_object_notify (G_OBJECT (widget), "double-buffered");
7633 * gtk_widget_get_double_buffered:
7634 * @widget: a #GtkWidget
7636 * Determines whether the widget is double buffered.
7638 * See gtk_widget_set_double_buffered()
7640 * Return value: %TRUE if the widget is double buffered
7645 gtk_widget_get_double_buffered (GtkWidget *widget)
7647 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7649 return widget->priv->double_buffered;
7653 * gtk_widget_set_redraw_on_allocate:
7654 * @widget: a #GtkWidget
7655 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7656 * when it is allocated to a new size. Otherwise, only the
7657 * new portion of the widget will be redrawn.
7659 * Sets whether the entire widget is queued for drawing when its size
7660 * allocation changes. By default, this setting is %TRUE and
7661 * the entire widget is redrawn on every size change. If your widget
7662 * leaves the upper left unchanged when made bigger, turning this
7663 * setting off will improve performance.
7665 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7666 * off all allocation on resizing: the widget will not even redraw if
7667 * its position changes; this is to allow containers that don't draw
7668 * anything to avoid excess invalidations. If you set this flag on a
7669 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7670 * you are responsible for invalidating both the old and new allocation
7671 * of the widget when the widget is moved and responsible for invalidating
7672 * regions newly when the widget increases size.
7675 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7676 gboolean redraw_on_allocate)
7678 g_return_if_fail (GTK_IS_WIDGET (widget));
7680 widget->priv->redraw_on_alloc = redraw_on_allocate;
7684 * gtk_widget_set_sensitive:
7685 * @widget: a #GtkWidget
7686 * @sensitive: %TRUE to make the widget sensitive
7688 * Sets the sensitivity of a widget. A widget is sensitive if the user
7689 * can interact with it. Insensitive widgets are "grayed out" and the
7690 * user can't interact with them. Insensitive widgets are known as
7691 * "inactive", "disabled", or "ghosted" in some other toolkits.
7694 gtk_widget_set_sensitive (GtkWidget *widget,
7697 GtkWidgetPrivate *priv;
7699 g_return_if_fail (GTK_IS_WIDGET (widget));
7701 priv = widget->priv;
7703 sensitive = (sensitive != FALSE);
7705 if (priv->sensitive == sensitive)
7708 priv->sensitive = sensitive;
7710 if (priv->parent == NULL
7711 || gtk_widget_is_sensitive (priv->parent))
7715 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7718 data.operation = STATE_CHANGE_UNSET;
7720 data.operation = STATE_CHANGE_SET;
7722 gtk_widget_propagate_state (widget, &data);
7724 gtk_widget_queue_resize (widget);
7727 g_object_notify (G_OBJECT (widget), "sensitive");
7731 * gtk_widget_get_sensitive:
7732 * @widget: a #GtkWidget
7734 * Returns the widget's sensitivity (in the sense of returning
7735 * the value that has been set using gtk_widget_set_sensitive()).
7737 * The effective sensitivity of a widget is however determined by both its
7738 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7740 * Returns: %TRUE if the widget is sensitive
7745 gtk_widget_get_sensitive (GtkWidget *widget)
7747 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7749 return widget->priv->sensitive;
7753 * gtk_widget_is_sensitive:
7754 * @widget: a #GtkWidget
7756 * Returns the widget's effective sensitivity, which means
7757 * it is sensitive itself and also its parent widget is sensitive
7759 * Returns: %TRUE if the widget is effectively sensitive
7764 gtk_widget_is_sensitive (GtkWidget *widget)
7766 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7768 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7772 _gtk_widget_update_path (GtkWidget *widget)
7774 if (widget->priv->path)
7776 gtk_widget_path_free (widget->priv->path);
7777 widget->priv->path = NULL;
7780 gtk_widget_get_path (widget);
7784 * gtk_widget_set_parent:
7785 * @widget: a #GtkWidget
7786 * @parent: parent container
7788 * This function is useful only when implementing subclasses of
7790 * Sets the container as the parent of @widget, and takes care of
7791 * some details such as updating the state and style of the child
7792 * to reflect its new location. The opposite function is
7793 * gtk_widget_unparent().
7796 gtk_widget_set_parent (GtkWidget *widget,
7799 GtkStateFlags parent_flags;
7800 GtkWidgetPrivate *priv;
7803 g_return_if_fail (GTK_IS_WIDGET (widget));
7804 g_return_if_fail (GTK_IS_WIDGET (parent));
7805 g_return_if_fail (widget != parent);
7807 priv = widget->priv;
7809 if (priv->parent != NULL)
7811 g_warning ("Can't set a parent on widget which has a parent\n");
7814 if (gtk_widget_is_toplevel (widget))
7816 g_warning ("Can't set a parent on a toplevel widget\n");
7820 /* keep this function in sync with gtk_menu_attach_to_widget()
7823 g_object_ref_sink (widget);
7825 gtk_widget_push_verify_invariants (widget);
7827 priv->parent = parent;
7829 parent_flags = gtk_widget_get_state_flags (parent);
7831 /* Merge both old state and current parent state,
7832 * making sure to only propagate the right states */
7833 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7834 data.flags |= priv->state_flags;
7836 data.operation = STATE_CHANGE_REPLACE;
7837 gtk_widget_propagate_state (widget, &data);
7840 gtk_style_context_set_parent (priv->context,
7841 gtk_widget_get_style_context (parent));
7842 gtk_widget_reset_style (widget);
7844 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7845 if (priv->parent->priv->anchored)
7846 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7847 g_object_notify (G_OBJECT (widget), "parent");
7849 /* Enforce realized/mapped invariants
7851 if (gtk_widget_get_realized (priv->parent))
7852 gtk_widget_realize (widget);
7854 if (gtk_widget_get_visible (priv->parent) &&
7855 gtk_widget_get_visible (widget))
7857 if (gtk_widget_get_child_visible (widget) &&
7858 gtk_widget_get_mapped (priv->parent))
7859 gtk_widget_map (widget);
7861 gtk_widget_queue_resize (widget);
7864 /* child may cause parent's expand to change, if the child is
7865 * expanded. If child is not expanded, then it can't modify the
7866 * parent's expand. If the child becomes expanded later then it will
7867 * queue compute_expand then. This optimization plus defaulting
7868 * newly-constructed widgets to need_compute_expand=FALSE should
7869 * mean that initially building a widget tree doesn't have to keep
7870 * walking up setting need_compute_expand on parents over and over.
7872 * We can't change a parent to need to expand unless we're visible.
7874 if (gtk_widget_get_visible (widget) &&
7875 (priv->need_compute_expand ||
7876 priv->computed_hexpand ||
7877 priv->computed_vexpand))
7879 gtk_widget_queue_compute_expand (parent);
7882 gtk_widget_pop_verify_invariants (widget);
7886 * gtk_widget_get_parent:
7887 * @widget: a #GtkWidget
7889 * Returns the parent container of @widget.
7891 * Return value: (transfer none): the parent container of @widget, or %NULL
7894 gtk_widget_get_parent (GtkWidget *widget)
7896 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7898 return widget->priv->parent;
7902 modifier_style_changed (GtkModifierStyle *style,
7905 GtkStyleContext *context;
7907 context = gtk_widget_get_style_context (widget);
7908 gtk_style_context_invalidate (context);
7911 static GtkModifierStyle *
7912 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7914 GtkModifierStyle *style;
7916 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7918 if (G_UNLIKELY (!style))
7920 GtkStyleContext *context;
7922 style = _gtk_modifier_style_new ();
7923 g_object_set_qdata_full (G_OBJECT (widget),
7924 quark_modifier_style,
7926 (GDestroyNotify) g_object_unref);
7928 g_signal_connect (style, "changed",
7929 G_CALLBACK (modifier_style_changed), widget);
7931 context = gtk_widget_get_style_context (widget);
7933 gtk_style_context_add_provider (context,
7934 GTK_STYLE_PROVIDER (style),
7935 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7942 * gtk_widget_override_color:
7943 * @widget: a #GtkWidget
7944 * @state: the state for which to set the color
7945 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7946 * of previous calls to gtk_widget_override_color()
7948 * Sets the color to use for a widget.
7950 * All other style values are left untouched.
7953 * This API is mostly meant as a quick way for applications to
7954 * change a widget appearance. If you are developing a widgets
7955 * library and intend this change to be themeable, it is better
7956 * done by setting meaningful CSS classes and regions in your
7957 * widget/container implementation through gtk_style_context_add_class()
7958 * and gtk_style_context_add_region().
7960 * This way, your widget library can install a #GtkCssProvider
7961 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
7962 * to provide a default styling for those widgets that need so, and
7963 * this theming may fully overridden by the user's theme.
7966 * Note that for complex widgets this may bring in undesired
7967 * results (such as uniform background color everywhere), in
7968 * these cases it is better to fully style such widgets through a
7969 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7976 gtk_widget_override_color (GtkWidget *widget,
7977 GtkStateFlags state,
7978 const GdkRGBA *color)
7980 GtkModifierStyle *style;
7982 g_return_if_fail (GTK_IS_WIDGET (widget));
7984 style = _gtk_widget_get_modifier_properties (widget);
7985 _gtk_modifier_style_set_color (style, state, color);
7989 * gtk_widget_override_background_color:
7990 * @widget: a #GtkWidget
7991 * @state: the state for which to set the background color
7992 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7993 * of previous calls to gtk_widget_override_background_color()
7995 * Sets the background color to use for a widget.
7997 * All other style values are left untouched.
7998 * See gtk_widget_override_color().
8003 gtk_widget_override_background_color (GtkWidget *widget,
8004 GtkStateFlags state,
8005 const GdkRGBA *color)
8007 GtkModifierStyle *style;
8009 g_return_if_fail (GTK_IS_WIDGET (widget));
8011 style = _gtk_widget_get_modifier_properties (widget);
8012 _gtk_modifier_style_set_background_color (style, state, color);
8016 * gtk_widget_override_font:
8017 * @widget: a #GtkWidget
8018 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8019 * the effect of previous calls to gtk_widget_override_font()
8021 * Sets the font to use for a widget. All other style values are
8022 * left untouched. See gtk_widget_override_color().
8027 gtk_widget_override_font (GtkWidget *widget,
8028 const PangoFontDescription *font_desc)
8030 GtkModifierStyle *style;
8032 g_return_if_fail (GTK_IS_WIDGET (widget));
8034 style = _gtk_widget_get_modifier_properties (widget);
8035 _gtk_modifier_style_set_font (style, font_desc);
8039 * gtk_widget_override_symbolic_color:
8040 * @widget: a #GtkWidget
8041 * @name: the name of the symbolic color to modify
8042 * @color: (allow-none): the color to assign (does not need
8043 * to be allocated), or %NULL to undo the effect of previous
8044 * calls to gtk_widget_override_symbolic_color()
8046 * Sets a symbolic color for a widget.
8048 * All other style values are left untouched.
8049 * See gtk_widget_override_color() for overriding the foreground
8050 * or background color.
8055 gtk_widget_override_symbolic_color (GtkWidget *widget,
8057 const GdkRGBA *color)
8059 GtkModifierStyle *style;
8061 g_return_if_fail (GTK_IS_WIDGET (widget));
8063 style = _gtk_widget_get_modifier_properties (widget);
8064 _gtk_modifier_style_map_color (style, name, color);
8068 * gtk_widget_override_cursor:
8069 * @widget: a #GtkWidget
8070 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8071 * allocated), or %NULL to undo the effect of previous calls to
8072 * of gtk_widget_override_cursor().
8073 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8074 * need to be allocated), or %NULL to undo the effect of previous
8075 * calls to of gtk_widget_override_cursor().
8077 * Sets the cursor color to use in a widget, overriding the
8078 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8079 * style properties. All other style values are left untouched.
8080 * See also gtk_widget_modify_style().
8082 * Note that the underlying properties have the #GdkColor type,
8083 * so the alpha value in @primary and @secondary will be ignored.
8088 gtk_widget_override_cursor (GtkWidget *widget,
8089 const GdkRGBA *cursor,
8090 const GdkRGBA *secondary_cursor)
8092 GtkModifierStyle *style;
8094 g_return_if_fail (GTK_IS_WIDGET (widget));
8096 style = _gtk_widget_get_modifier_properties (widget);
8097 _gtk_modifier_style_set_color_property (style,
8099 "cursor-color", cursor);
8100 _gtk_modifier_style_set_color_property (style,
8102 "secondary-cursor-color",
8107 gtk_widget_real_direction_changed (GtkWidget *widget,
8108 GtkTextDirection previous_direction)
8110 gtk_widget_queue_resize (widget);
8114 gtk_widget_real_style_set (GtkWidget *widget,
8115 GtkStyle *previous_style)
8120 GtkWidget *previous_toplevel;
8121 GdkScreen *previous_screen;
8122 GdkScreen *new_screen;
8123 } HierarchyChangedInfo;
8126 do_screen_change (GtkWidget *widget,
8127 GdkScreen *old_screen,
8128 GdkScreen *new_screen)
8130 if (old_screen != new_screen)
8132 GtkWidgetPrivate *priv = widget->priv;
8136 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8138 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8141 _gtk_tooltip_hide (widget);
8143 if (new_screen && priv->context)
8144 gtk_style_context_set_screen (priv->context, new_screen);
8146 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8151 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8152 gpointer client_data)
8154 GtkWidgetPrivate *priv = widget->priv;
8155 HierarchyChangedInfo *info = client_data;
8156 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8157 (priv->parent && priv->parent->priv->anchored);
8159 if (priv->anchored != new_anchored)
8161 g_object_ref (widget);
8163 priv->anchored = new_anchored;
8165 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8166 do_screen_change (widget, info->previous_screen, info->new_screen);
8168 if (GTK_IS_CONTAINER (widget))
8169 gtk_container_forall (GTK_CONTAINER (widget),
8170 gtk_widget_propagate_hierarchy_changed_recurse,
8173 g_object_unref (widget);
8178 * _gtk_widget_propagate_hierarchy_changed:
8179 * @widget: a #GtkWidget
8180 * @previous_toplevel: Previous toplevel
8182 * Propagates changes in the anchored state to a widget and all
8183 * children, unsetting or setting the %ANCHORED flag, and
8184 * emitting #GtkWidget::hierarchy-changed.
8187 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8188 GtkWidget *previous_toplevel)
8190 GtkWidgetPrivate *priv = widget->priv;
8191 HierarchyChangedInfo info;
8193 info.previous_toplevel = previous_toplevel;
8194 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8196 if (gtk_widget_is_toplevel (widget) ||
8197 (priv->parent && priv->parent->priv->anchored))
8198 info.new_screen = gtk_widget_get_screen (widget);
8200 info.new_screen = NULL;
8202 if (info.previous_screen)
8203 g_object_ref (info.previous_screen);
8204 if (previous_toplevel)
8205 g_object_ref (previous_toplevel);
8207 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8209 if (previous_toplevel)
8210 g_object_unref (previous_toplevel);
8211 if (info.previous_screen)
8212 g_object_unref (info.previous_screen);
8216 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8217 gpointer client_data)
8219 HierarchyChangedInfo *info = client_data;
8221 g_object_ref (widget);
8223 do_screen_change (widget, info->previous_screen, info->new_screen);
8225 if (GTK_IS_CONTAINER (widget))
8226 gtk_container_forall (GTK_CONTAINER (widget),
8227 gtk_widget_propagate_screen_changed_recurse,
8230 g_object_unref (widget);
8234 * gtk_widget_is_composited:
8235 * @widget: a #GtkWidget
8237 * Whether @widget can rely on having its alpha channel
8238 * drawn correctly. On X11 this function returns whether a
8239 * compositing manager is running for @widget's screen.
8241 * Please note that the semantics of this call will change
8242 * in the future if used on a widget that has a composited
8243 * window in its hierarchy (as set by gdk_window_set_composited()).
8245 * Return value: %TRUE if the widget can rely on its alpha
8246 * channel being drawn correctly.
8251 gtk_widget_is_composited (GtkWidget *widget)
8255 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8257 screen = gtk_widget_get_screen (widget);
8259 return gdk_screen_is_composited (screen);
8263 propagate_composited_changed (GtkWidget *widget,
8266 if (GTK_IS_CONTAINER (widget))
8268 gtk_container_forall (GTK_CONTAINER (widget),
8269 propagate_composited_changed,
8273 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8277 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8279 propagate_composited_changed (widget, NULL);
8283 * _gtk_widget_propagate_screen_changed:
8284 * @widget: a #GtkWidget
8285 * @previous_screen: Previous screen
8287 * Propagates changes in the screen for a widget to all
8288 * children, emitting #GtkWidget::screen-changed.
8291 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8292 GdkScreen *previous_screen)
8294 HierarchyChangedInfo info;
8296 info.previous_screen = previous_screen;
8297 info.new_screen = gtk_widget_get_screen (widget);
8299 if (previous_screen)
8300 g_object_ref (previous_screen);
8302 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8304 if (previous_screen)
8305 g_object_unref (previous_screen);
8309 reset_style_recurse (GtkWidget *widget, gpointer data)
8311 _gtk_widget_update_path (widget);
8313 if (GTK_IS_CONTAINER (widget))
8314 gtk_container_forall (GTK_CONTAINER (widget),
8315 reset_style_recurse,
8320 * gtk_widget_reset_style:
8321 * @widget: a #GtkWidget
8323 * Updates the style context of @widget and all descendents
8324 * by updating its widget path. #GtkContainer<!-- -->s may want
8325 * to use this on a child when reordering it in a way that a different
8326 * style might apply to it. See also gtk_container_get_path_for_child().
8331 gtk_widget_reset_style (GtkWidget *widget)
8333 g_return_if_fail (GTK_IS_WIDGET (widget));
8335 reset_style_recurse (widget, NULL);
8337 g_list_foreach (widget->priv->attached_windows,
8338 (GFunc) reset_style_recurse, NULL);
8341 #ifdef G_ENABLE_DEBUG
8343 /* Verify invariants, see docs/widget_system.txt for notes on much of
8344 * this. Invariants may be temporarily broken while we're in the
8345 * process of updating state, of course, so you can only
8346 * verify_invariants() after a given operation is complete.
8347 * Use push/pop_verify_invariants to help with that.
8350 gtk_widget_verify_invariants (GtkWidget *widget)
8354 if (widget->priv->verifying_invariants_count > 0)
8357 parent = widget->priv->parent;
8359 if (widget->priv->mapped)
8361 /* Mapped implies ... */
8363 if (!widget->priv->realized)
8364 g_warning ("%s %p is mapped but not realized",
8365 G_OBJECT_TYPE_NAME (widget), widget);
8367 if (!widget->priv->visible)
8368 g_warning ("%s %p is mapped but not visible",
8369 G_OBJECT_TYPE_NAME (widget), widget);
8371 if (!widget->priv->toplevel)
8373 if (!widget->priv->child_visible)
8374 g_warning ("%s %p is mapped but not child_visible",
8375 G_OBJECT_TYPE_NAME (widget), widget);
8380 /* Not mapped implies... */
8383 /* This check makes sense for normal toplevels, but for
8384 * something like a toplevel that is embedded within a clutter
8385 * state, mapping may depend on external factors.
8387 if (widget->priv->toplevel)
8389 if (widget->priv->visible)
8390 g_warning ("%s %p toplevel is visible but not mapped",
8391 G_OBJECT_TYPE_NAME (widget), widget);
8396 /* Parent related checks aren't possible if parent has
8397 * verifying_invariants_count > 0 because parent needs to recurse
8398 * children first before the invariants will hold.
8400 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8403 parent->priv->realized)
8405 /* Parent realized implies... */
8408 /* This is in widget_system.txt but appears to fail
8409 * because there's no gtk_container_realize() that
8410 * realizes all children... instead we just lazily
8411 * wait for map to fix things up.
8413 if (!widget->priv->realized)
8414 g_warning ("%s %p is realized but child %s %p is not realized",
8415 G_OBJECT_TYPE_NAME (parent), parent,
8416 G_OBJECT_TYPE_NAME (widget), widget);
8419 else if (!widget->priv->toplevel)
8421 /* No parent or parent not realized on non-toplevel implies... */
8423 if (widget->priv->realized && !widget->priv->in_reparent)
8424 g_warning ("%s %p is not realized but child %s %p is realized",
8425 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8426 G_OBJECT_TYPE_NAME (widget), widget);
8430 parent->priv->mapped &&
8431 widget->priv->visible &&
8432 widget->priv->child_visible)
8434 /* Parent mapped and we are visible implies... */
8436 if (!widget->priv->mapped)
8437 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8438 G_OBJECT_TYPE_NAME (parent), parent,
8439 G_OBJECT_TYPE_NAME (widget), widget);
8441 else if (!widget->priv->toplevel)
8443 /* No parent or parent not mapped on non-toplevel implies... */
8445 if (widget->priv->mapped && !widget->priv->in_reparent)
8446 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8447 G_OBJECT_TYPE_NAME (widget), widget,
8448 widget->priv->visible,
8449 widget->priv->child_visible,
8450 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8451 parent ? parent->priv->mapped : FALSE);
8455 if (!widget->priv->realized)
8457 /* Not realized implies... */
8460 /* widget_system.txt says these hold, but they don't. */
8461 if (widget->priv->resize_pending)
8462 g_warning ("%s %p resize pending but not realized",
8463 G_OBJECT_TYPE_NAME (widget), widget);
8465 if (widget->priv->alloc_needed)
8466 g_warning ("%s %p alloc needed but not realized",
8467 G_OBJECT_TYPE_NAME (widget), widget);
8469 if (widget->priv->width_request_needed)
8470 g_warning ("%s %p width request needed but not realized",
8471 G_OBJECT_TYPE_NAME (widget), widget);
8473 if (widget->priv->height_request_needed)
8474 g_warning ("%s %p height request needed but not realized",
8475 G_OBJECT_TYPE_NAME (widget), widget);
8480 /* The point of this push/pop is that invariants may not hold while
8481 * we're busy making changes. So we only check at the outermost call
8482 * on the call stack, after we finish updating everything.
8485 gtk_widget_push_verify_invariants (GtkWidget *widget)
8487 widget->priv->verifying_invariants_count += 1;
8491 gtk_widget_verify_child_invariants (GtkWidget *widget,
8492 gpointer client_data)
8494 /* We don't recurse further; this is a one-level check. */
8495 gtk_widget_verify_invariants (widget);
8499 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8501 g_assert (widget->priv->verifying_invariants_count > 0);
8503 widget->priv->verifying_invariants_count -= 1;
8505 if (widget->priv->verifying_invariants_count == 0)
8507 gtk_widget_verify_invariants (widget);
8509 if (GTK_IS_CONTAINER (widget))
8511 /* Check one level of children, because our
8512 * push_verify_invariants() will have prevented some of the
8513 * checks. This does not recurse because if recursion is
8514 * needed, it will happen naturally as each child has a
8515 * push/pop on that child. For example if we're recursively
8516 * mapping children, we'll push/pop on each child as we map
8519 gtk_container_forall (GTK_CONTAINER (widget),
8520 gtk_widget_verify_child_invariants,
8525 #endif /* G_ENABLE_DEBUG */
8527 static PangoContext *
8528 gtk_widget_peek_pango_context (GtkWidget *widget)
8530 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8534 * gtk_widget_get_pango_context:
8535 * @widget: a #GtkWidget
8537 * Gets a #PangoContext with the appropriate font map, font description,
8538 * and base direction for this widget. Unlike the context returned
8539 * by gtk_widget_create_pango_context(), this context is owned by
8540 * the widget (it can be used until the screen for the widget changes
8541 * or the widget is removed from its toplevel), and will be updated to
8542 * match any changes to the widget's attributes.
8544 * If you create and keep a #PangoLayout using this context, you must
8545 * deal with changes to the context by calling pango_layout_context_changed()
8546 * on the layout in response to the #GtkWidget::style-updated and
8547 * #GtkWidget::direction-changed signals for the widget.
8549 * Return value: (transfer none): the #PangoContext for the widget.
8552 gtk_widget_get_pango_context (GtkWidget *widget)
8554 PangoContext *context;
8556 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8558 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8561 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8562 g_object_set_qdata_full (G_OBJECT (widget),
8563 quark_pango_context,
8572 update_pango_context (GtkWidget *widget,
8573 PangoContext *context)
8575 const PangoFontDescription *font_desc;
8576 GtkStyleContext *style_context;
8578 style_context = gtk_widget_get_style_context (widget);
8580 font_desc = gtk_style_context_get_font (style_context,
8581 gtk_widget_get_state_flags (widget));
8583 pango_context_set_font_description (context, font_desc);
8584 pango_context_set_base_dir (context,
8585 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8586 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8590 gtk_widget_update_pango_context (GtkWidget *widget)
8592 PangoContext *context = gtk_widget_peek_pango_context (widget);
8598 update_pango_context (widget, context);
8600 screen = gtk_widget_get_screen_unchecked (widget);
8603 pango_cairo_context_set_resolution (context,
8604 gdk_screen_get_resolution (screen));
8605 pango_cairo_context_set_font_options (context,
8606 gdk_screen_get_font_options (screen));
8612 * gtk_widget_create_pango_context:
8613 * @widget: a #GtkWidget
8615 * Creates a new #PangoContext with the appropriate font map,
8616 * font description, and base direction for drawing text for
8617 * this widget. See also gtk_widget_get_pango_context().
8619 * Return value: (transfer full): the new #PangoContext
8622 gtk_widget_create_pango_context (GtkWidget *widget)
8625 PangoContext *context;
8627 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8629 screen = gtk_widget_get_screen_unchecked (widget);
8632 GTK_NOTE (MULTIHEAD,
8633 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8635 screen = gdk_screen_get_default ();
8638 context = gdk_pango_context_get_for_screen (screen);
8640 update_pango_context (widget, context);
8641 pango_context_set_language (context, gtk_get_default_language ());
8647 * gtk_widget_create_pango_layout:
8648 * @widget: a #GtkWidget
8649 * @text: text to set on the layout (can be %NULL)
8651 * Creates a new #PangoLayout with the appropriate font map,
8652 * font description, and base direction for drawing text for
8655 * If you keep a #PangoLayout created in this way around, in order to
8656 * notify the layout of changes to the base direction or font of this
8657 * widget, you must call pango_layout_context_changed() in response to
8658 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8661 * Return value: (transfer full): the new #PangoLayout
8664 gtk_widget_create_pango_layout (GtkWidget *widget,
8667 PangoLayout *layout;
8668 PangoContext *context;
8670 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8672 context = gtk_widget_get_pango_context (widget);
8673 layout = pango_layout_new (context);
8676 pango_layout_set_text (layout, text, -1);
8682 * gtk_widget_render_icon_pixbuf:
8683 * @widget: a #GtkWidget
8684 * @stock_id: a stock ID
8685 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8686 * render at the size of the source and don't scale (if there are
8687 * multiple source sizes, GTK+ picks one of the available sizes).
8689 * A convenience function that uses the theme engine and style
8690 * settings for @widget to look up @stock_id and render it to
8691 * a pixbuf. @stock_id should be a stock icon ID such as
8692 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8693 * such as #GTK_ICON_SIZE_MENU.
8695 * The pixels in the returned #GdkPixbuf are shared with the rest of
8696 * the application and should not be modified. The pixbuf should be freed
8697 * after use with g_object_unref().
8699 * Return value: (transfer full): a new pixbuf, or %NULL if the
8700 * stock ID wasn't known
8705 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8706 const gchar *stock_id,
8709 GtkStyleContext *context;
8710 GtkIconSet *icon_set;
8712 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8713 g_return_val_if_fail (stock_id != NULL, NULL);
8714 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8716 context = gtk_widget_get_style_context (widget);
8717 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8719 if (icon_set == NULL)
8722 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8726 * gtk_widget_set_parent_window:
8727 * @widget: a #GtkWidget.
8728 * @parent_window: the new parent window.
8730 * Sets a non default parent window for @widget.
8732 * For GtkWindow classes, setting a @parent_window effects whether
8733 * the window is a toplevel window or can be embedded into other
8737 * For GtkWindow classes, this needs to be called before the
8738 * window is realized.
8743 gtk_widget_set_parent_window (GtkWidget *widget,
8744 GdkWindow *parent_window)
8746 GdkWindow *old_parent_window;
8748 g_return_if_fail (GTK_IS_WIDGET (widget));
8750 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8751 quark_parent_window);
8753 if (parent_window != old_parent_window)
8757 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8759 if (old_parent_window)
8760 g_object_unref (old_parent_window);
8762 g_object_ref (parent_window);
8764 /* Unset toplevel flag when adding a parent window to a widget,
8765 * this is the primary entry point to allow toplevels to be
8768 #ifdef GDK_WINDOWING_X11
8769 is_plug = GTK_IS_PLUG (widget);
8773 if (GTK_IS_WINDOW (widget) && !is_plug)
8774 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8779 * gtk_widget_get_parent_window:
8780 * @widget: a #GtkWidget.
8782 * Gets @widget's parent window.
8784 * Returns: (transfer none): the parent window of @widget.
8787 gtk_widget_get_parent_window (GtkWidget *widget)
8789 GtkWidgetPrivate *priv;
8790 GdkWindow *parent_window;
8792 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8794 priv = widget->priv;
8796 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8798 return (parent_window != NULL) ? parent_window :
8799 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8804 * gtk_widget_set_child_visible:
8805 * @widget: a #GtkWidget
8806 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8808 * Sets whether @widget should be mapped along with its when its parent
8809 * is mapped and @widget has been shown with gtk_widget_show().
8811 * The child visibility can be set for widget before it is added to
8812 * a container with gtk_widget_set_parent(), to avoid mapping
8813 * children unnecessary before immediately unmapping them. However
8814 * it will be reset to its default state of %TRUE when the widget
8815 * is removed from a container.
8817 * Note that changing the child visibility of a widget does not
8818 * queue a resize on the widget. Most of the time, the size of
8819 * a widget is computed from all visible children, whether or
8820 * not they are mapped. If this is not the case, the container
8821 * can queue a resize itself.
8823 * This function is only useful for container implementations and
8824 * never should be called by an application.
8827 gtk_widget_set_child_visible (GtkWidget *widget,
8828 gboolean is_visible)
8830 GtkWidgetPrivate *priv;
8832 g_return_if_fail (GTK_IS_WIDGET (widget));
8833 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8835 priv = widget->priv;
8837 g_object_ref (widget);
8838 gtk_widget_verify_invariants (widget);
8841 priv->child_visible = TRUE;
8844 GtkWidget *toplevel;
8846 priv->child_visible = FALSE;
8848 toplevel = gtk_widget_get_toplevel (widget);
8849 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8850 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8853 if (priv->parent && gtk_widget_get_realized (priv->parent))
8855 if (gtk_widget_get_mapped (priv->parent) &&
8856 priv->child_visible &&
8857 gtk_widget_get_visible (widget))
8858 gtk_widget_map (widget);
8860 gtk_widget_unmap (widget);
8863 gtk_widget_verify_invariants (widget);
8864 g_object_unref (widget);
8868 * gtk_widget_get_child_visible:
8869 * @widget: a #GtkWidget
8871 * Gets the value set with gtk_widget_set_child_visible().
8872 * If you feel a need to use this function, your code probably
8873 * needs reorganization.
8875 * This function is only useful for container implementations and
8876 * never should be called by an application.
8878 * Return value: %TRUE if the widget is mapped with the parent.
8881 gtk_widget_get_child_visible (GtkWidget *widget)
8883 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8885 return widget->priv->child_visible;
8889 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8891 GtkWidget *toplevel;
8893 toplevel = gtk_widget_get_toplevel (widget);
8895 if (gtk_widget_is_toplevel (toplevel))
8897 if (GTK_IS_WINDOW (toplevel))
8898 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8899 else if (GTK_IS_INVISIBLE (toplevel))
8900 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8907 * gtk_widget_get_screen:
8908 * @widget: a #GtkWidget
8910 * Get the #GdkScreen from the toplevel window associated with
8911 * this widget. This function can only be called after the widget
8912 * has been added to a widget hierarchy with a #GtkWindow
8915 * In general, you should only create screen specific
8916 * resources when a widget has been realized, and you should
8917 * free those resources when the widget is unrealized.
8919 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8924 gtk_widget_get_screen (GtkWidget *widget)
8928 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8930 screen = gtk_widget_get_screen_unchecked (widget);
8937 g_warning (G_STRLOC ": Can't get associated screen"
8938 " for a widget unless it is inside a toplevel GtkWindow\n"
8939 " widget type is %s associated top level type is %s",
8940 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8941 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8943 return gdk_screen_get_default ();
8948 * gtk_widget_has_screen:
8949 * @widget: a #GtkWidget
8951 * Checks whether there is a #GdkScreen is associated with
8952 * this widget. All toplevel widgets have an associated
8953 * screen, and all widgets added into a hierarchy with a toplevel
8954 * window at the top.
8956 * Return value: %TRUE if there is a #GdkScreen associcated
8962 gtk_widget_has_screen (GtkWidget *widget)
8964 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8966 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8970 * gtk_widget_get_display:
8971 * @widget: a #GtkWidget
8973 * Get the #GdkDisplay for the toplevel window associated with
8974 * this widget. This function can only be called after the widget
8975 * has been added to a widget hierarchy with a #GtkWindow at the top.
8977 * In general, you should only create display specific
8978 * resources when a widget has been realized, and you should
8979 * free those resources when the widget is unrealized.
8981 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8986 gtk_widget_get_display (GtkWidget *widget)
8988 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8990 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8994 * gtk_widget_get_root_window:
8995 * @widget: a #GtkWidget
8997 * Get the root window where this widget is located. This function can
8998 * only be called after the widget has been added to a widget
8999 * hierarchy with #GtkWindow at the top.
9001 * The root window is useful for such purposes as creating a popup
9002 * #GdkWindow associated with the window. In general, you should only
9003 * create display specific resources when a widget has been realized,
9004 * and you should free those resources when the widget is unrealized.
9006 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9011 gtk_widget_get_root_window (GtkWidget *widget)
9013 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9015 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9019 * gtk_widget_child_focus:
9020 * @widget: a #GtkWidget
9021 * @direction: direction of focus movement
9023 * This function is used by custom widget implementations; if you're
9024 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9025 * to a particular widget, and gtk_container_set_focus_chain() to
9026 * change the focus tab order. So you may want to investigate those
9027 * functions instead.
9029 * gtk_widget_child_focus() is called by containers as the user moves
9030 * around the window using keyboard shortcuts. @direction indicates
9031 * what kind of motion is taking place (up, down, left, right, tab
9032 * forward, tab backward). gtk_widget_child_focus() emits the
9033 * #GtkWidget::focus signal; widgets override the default handler
9034 * for this signal in order to implement appropriate focus behavior.
9036 * The default ::focus handler for a widget should return %TRUE if
9037 * moving in @direction left the focus on a focusable location inside
9038 * that widget, and %FALSE if moving in @direction moved the focus
9039 * outside the widget. If returning %TRUE, widgets normally
9040 * call gtk_widget_grab_focus() to place the focus accordingly;
9041 * if returning %FALSE, they don't modify the current focus location.
9043 * Return value: %TRUE if focus ended up inside @widget
9046 gtk_widget_child_focus (GtkWidget *widget,
9047 GtkDirectionType direction)
9049 gboolean return_val;
9051 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9053 if (!gtk_widget_get_visible (widget) ||
9054 !gtk_widget_is_sensitive (widget))
9057 /* child widgets must set CAN_FOCUS, containers
9058 * don't have to though.
9060 if (!GTK_IS_CONTAINER (widget) &&
9061 !gtk_widget_get_can_focus (widget))
9064 g_signal_emit (widget,
9065 widget_signals[FOCUS],
9067 direction, &return_val);
9073 * gtk_widget_keynav_failed:
9074 * @widget: a #GtkWidget
9075 * @direction: direction of focus movement
9077 * This function should be called whenever keyboard navigation within
9078 * a single widget hits a boundary. The function emits the
9079 * #GtkWidget::keynav-failed signal on the widget and its return
9080 * value should be interpreted in a way similar to the return value of
9081 * gtk_widget_child_focus():
9083 * When %TRUE is returned, stay in the widget, the failed keyboard
9084 * navigation is Ok and/or there is nowhere we can/should move the
9087 * When %FALSE is returned, the caller should continue with keyboard
9088 * navigation outside the widget, e.g. by calling
9089 * gtk_widget_child_focus() on the widget's toplevel.
9091 * The default ::keynav-failed handler returns %TRUE for
9092 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9093 * values of #GtkDirectionType, it looks at the
9094 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9095 * if the setting is %TRUE. This way the entire user interface
9096 * becomes cursor-navigatable on input devices such as mobile phones
9097 * which only have cursor keys but no tab key.
9099 * Whenever the default handler returns %TRUE, it also calls
9100 * gtk_widget_error_bell() to notify the user of the failed keyboard
9103 * A use case for providing an own implementation of ::keynav-failed
9104 * (either by connecting to it or by overriding it) would be a row of
9105 * #GtkEntry widgets where the user should be able to navigate the
9106 * entire row with the cursor keys, as e.g. known from user interfaces
9107 * that require entering license keys.
9109 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9110 * if the emitting widget should try to handle the keyboard
9111 * navigation attempt in its parent container(s).
9116 gtk_widget_keynav_failed (GtkWidget *widget,
9117 GtkDirectionType direction)
9119 gboolean return_val;
9121 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9123 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9124 direction, &return_val);
9130 * gtk_widget_error_bell:
9131 * @widget: a #GtkWidget
9133 * Notifies the user about an input-related error on this widget.
9134 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9135 * gdk_window_beep(), otherwise it does nothing.
9137 * Note that the effect of gdk_window_beep() can be configured in many
9138 * ways, depending on the windowing backend and the desktop environment
9139 * or window manager that is used.
9144 gtk_widget_error_bell (GtkWidget *widget)
9146 GtkWidgetPrivate *priv;
9147 GtkSettings* settings;
9150 g_return_if_fail (GTK_IS_WIDGET (widget));
9152 priv = widget->priv;
9154 settings = gtk_widget_get_settings (widget);
9158 g_object_get (settings,
9159 "gtk-error-bell", &beep,
9162 if (beep && priv->window)
9163 gdk_window_beep (priv->window);
9167 gtk_widget_set_usize_internal (GtkWidget *widget,
9170 GtkQueueResizeFlags flags)
9172 GtkWidgetAuxInfo *aux_info;
9173 gboolean changed = FALSE;
9175 g_object_freeze_notify (G_OBJECT (widget));
9177 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9179 if (width > -2 && aux_info->width != width)
9181 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9182 g_object_notify (G_OBJECT (widget), "width-request");
9183 aux_info->width = width;
9186 if (height > -2 && aux_info->height != height)
9188 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9189 g_object_notify (G_OBJECT (widget), "height-request");
9190 aux_info->height = height;
9194 if (gtk_widget_get_visible (widget) && changed)
9196 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9197 gtk_widget_queue_resize (widget);
9199 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9202 g_object_thaw_notify (G_OBJECT (widget));
9206 * gtk_widget_set_size_request:
9207 * @widget: a #GtkWidget
9208 * @width: width @widget should request, or -1 to unset
9209 * @height: height @widget should request, or -1 to unset
9211 * Sets the minimum size of a widget; that is, the widget's size
9212 * request will be @width by @height. You can use this function to
9213 * force a widget to be either larger or smaller than it normally
9216 * In most cases, gtk_window_set_default_size() is a better choice for
9217 * toplevel windows than this function; setting the default size will
9218 * still allow users to shrink the window. Setting the size request
9219 * will force them to leave the window at least as large as the size
9220 * request. When dealing with window sizes,
9221 * gtk_window_set_geometry_hints() can be a useful function as well.
9223 * Note the inherent danger of setting any fixed size - themes,
9224 * translations into other languages, different fonts, and user action
9225 * can all change the appropriate size for a given widget. So, it's
9226 * basically impossible to hardcode a size that will always be
9229 * The size request of a widget is the smallest size a widget can
9230 * accept while still functioning well and drawing itself correctly.
9231 * However in some strange cases a widget may be allocated less than
9232 * its requested size, and in many cases a widget may be allocated more
9233 * space than it requested.
9235 * If the size request in a given direction is -1 (unset), then
9236 * the "natural" size request of the widget will be used instead.
9238 * Widgets can't actually be allocated a size less than 1 by 1, but
9239 * you can pass 0,0 to this function to mean "as small as possible."
9241 * The size request set here does not include any margin from the
9242 * #GtkWidget properties margin-left, margin-right, margin-top, and
9243 * margin-bottom, but it does include pretty much all other padding
9244 * or border properties set by any subclass of #GtkWidget.
9247 gtk_widget_set_size_request (GtkWidget *widget,
9251 g_return_if_fail (GTK_IS_WIDGET (widget));
9252 g_return_if_fail (width >= -1);
9253 g_return_if_fail (height >= -1);
9260 gtk_widget_set_usize_internal (widget, width, height, 0);
9265 * gtk_widget_get_size_request:
9266 * @widget: a #GtkWidget
9267 * @width: (out) (allow-none): return location for width, or %NULL
9268 * @height: (out) (allow-none): return location for height, or %NULL
9270 * Gets the size request that was explicitly set for the widget using
9271 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9272 * @height indicates that that dimension has not been set explicitly
9273 * and the natural requisition of the widget will be used intead. See
9274 * gtk_widget_set_size_request(). To get the size a widget will
9275 * actually request, call gtk_widget_get_preferred_size() instead of
9279 gtk_widget_get_size_request (GtkWidget *widget,
9283 const GtkWidgetAuxInfo *aux_info;
9285 g_return_if_fail (GTK_IS_WIDGET (widget));
9287 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9290 *width = aux_info->width;
9293 *height = aux_info->height;
9297 * _gtk_widget_override_size_request:
9298 * @widget: a #GtkWidget
9299 * @width: new forced minimum width
9300 * @height: new forced minimum height
9301 * @old_width: location to store previous forced minimum width
9302 * @old_width: location to store previous forced minumum height
9304 * Temporarily establishes a forced minimum size for a widget; this
9305 * is used by GtkWindow when calculating the size to add to the
9306 * window's geometry widget. Cached sizes for the widget and its
9307 * parents are invalidated, so that subsequent calls to the size
9308 * negotiation machinery produce the overriden result, but the
9309 * widget is not queued for relayout or redraw. The old size must
9310 * be restored with _gtk_widget_restore_size_request() or things
9314 _gtk_widget_override_size_request (GtkWidget *widget,
9320 gtk_widget_get_size_request (widget, old_width, old_height);
9321 gtk_widget_set_usize_internal (widget, width, height,
9322 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9326 * _gtk_widget_restore_size_request:
9327 * @widget: a #GtkWidget
9328 * @old_width: saved forced minimum size
9329 * @old_height: saved forced minimum size
9331 * Undoes the operation of_gtk_widget_override_size_request().
9334 _gtk_widget_restore_size_request (GtkWidget *widget,
9338 gtk_widget_set_usize_internal (widget, old_width, old_height,
9339 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9343 * gtk_widget_set_events:
9344 * @widget: a #GtkWidget
9345 * @events: event mask
9347 * Sets the event mask (see #GdkEventMask) for a widget. The event
9348 * mask determines which events a widget will receive. Keep in mind
9349 * that different widgets have different default event masks, and by
9350 * changing the event mask you may disrupt a widget's functionality,
9351 * so be careful. This function must be called while a widget is
9352 * unrealized. Consider gtk_widget_add_events() for widgets that are
9353 * already realized, or if you want to preserve the existing event
9354 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9355 * to get events on those widgets, place them inside a #GtkEventBox
9356 * and receive events on the event box.
9359 gtk_widget_set_events (GtkWidget *widget,
9362 g_return_if_fail (GTK_IS_WIDGET (widget));
9363 g_return_if_fail (!gtk_widget_get_realized (widget));
9365 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9366 GINT_TO_POINTER (events));
9367 g_object_notify (G_OBJECT (widget), "events");
9371 * gtk_widget_set_device_events:
9372 * @widget: a #GtkWidget
9373 * @device: a #GdkDevice
9374 * @events: event mask
9376 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9377 * mask determines which events a widget will receive from @device. Keep
9378 * in mind that different widgets have different default event masks, and by
9379 * changing the event mask you may disrupt a widget's functionality,
9380 * so be careful. This function must be called while a widget is
9381 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9382 * already realized, or if you want to preserve the existing event
9383 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9384 * to get events on those widgets, place them inside a #GtkEventBox
9385 * and receive events on the event box.
9390 gtk_widget_set_device_events (GtkWidget *widget,
9392 GdkEventMask events)
9394 GHashTable *device_events;
9396 g_return_if_fail (GTK_IS_WIDGET (widget));
9397 g_return_if_fail (GDK_IS_DEVICE (device));
9398 g_return_if_fail (!gtk_widget_get_realized (widget));
9400 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9402 if (G_UNLIKELY (!device_events))
9404 device_events = g_hash_table_new (NULL, NULL);
9405 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9406 (GDestroyNotify) g_hash_table_unref);
9409 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9413 * gtk_widget_set_device_enabled:
9414 * @widget: a #GtkWidget
9415 * @device: a #GdkDevice
9416 * @enabled: whether to enable the device
9418 * Enables or disables a #GdkDevice to interact with @widget
9419 * and all its children.
9421 * It does so by descending through the #GdkWindow hierarchy
9422 * and enabling the same mask that is has for core events
9423 * (i.e. the one that gdk_window_get_events() returns).
9428 gtk_widget_set_device_enabled (GtkWidget *widget,
9432 GList *enabled_devices;
9434 g_return_if_fail (GTK_IS_WIDGET (widget));
9435 g_return_if_fail (GDK_IS_DEVICE (device));
9437 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9438 enabled_devices = g_list_append (enabled_devices, device);
9440 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9441 enabled_devices, (GDestroyNotify) g_list_free);;
9443 if (gtk_widget_get_realized (widget))
9444 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9448 * gtk_widget_get_device_enabled:
9449 * @widget: a #GtkWidget
9450 * @device: a #GdkDevice
9452 * Returns whether @device can interact with @widget and its
9453 * children. See gtk_widget_set_device_enabled().
9455 * Return value: %TRUE is @device is enabled for @widget
9460 gtk_widget_get_device_enabled (GtkWidget *widget,
9463 GList *enabled_devices;
9465 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9466 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9468 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9470 return g_list_find (enabled_devices, device) != NULL;
9474 gtk_widget_add_events_internal_list (GtkWidget *widget,
9481 for (l = window_list; l != NULL; l = l->next)
9483 GdkWindow *window = l->data;
9486 gdk_window_get_user_data (window, &user_data);
9487 if (user_data == widget)
9492 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9494 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9496 children = gdk_window_get_children (window);
9497 gtk_widget_add_events_internal_list (widget, device, events, children);
9498 g_list_free (children);
9504 gtk_widget_add_events_internal (GtkWidget *widget,
9508 GtkWidgetPrivate *priv = widget->priv;
9511 if (!gtk_widget_get_has_window (widget))
9512 window_list = gdk_window_get_children (priv->window);
9514 window_list = g_list_prepend (NULL, priv->window);
9516 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9518 g_list_free (window_list);
9522 * gtk_widget_add_events:
9523 * @widget: a #GtkWidget
9524 * @events: an event mask, see #GdkEventMask
9526 * Adds the events in the bitfield @events to the event mask for
9527 * @widget. See gtk_widget_set_events() for details.
9530 gtk_widget_add_events (GtkWidget *widget,
9535 g_return_if_fail (GTK_IS_WIDGET (widget));
9537 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9538 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9539 GINT_TO_POINTER (old_events | events));
9541 if (gtk_widget_get_realized (widget))
9543 gtk_widget_add_events_internal (widget, NULL, events);
9544 gtk_widget_update_devices_mask (widget, FALSE);
9547 g_object_notify (G_OBJECT (widget), "events");
9551 * gtk_widget_add_device_events:
9552 * @widget: a #GtkWidget
9553 * @device: a #GdkDevice
9554 * @events: an event mask, see #GdkEventMask
9556 * Adds the device events in the bitfield @events to the event mask for
9557 * @widget. See gtk_widget_set_device_events() for details.
9562 gtk_widget_add_device_events (GtkWidget *widget,
9564 GdkEventMask events)
9566 GdkEventMask old_events;
9567 GHashTable *device_events;
9569 g_return_if_fail (GTK_IS_WIDGET (widget));
9570 g_return_if_fail (GDK_IS_DEVICE (device));
9572 old_events = gtk_widget_get_device_events (widget, device);
9574 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9576 if (G_UNLIKELY (!device_events))
9578 device_events = g_hash_table_new (NULL, NULL);
9579 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9580 (GDestroyNotify) g_hash_table_unref);
9583 g_hash_table_insert (device_events, device,
9584 GUINT_TO_POINTER (old_events | events));
9586 if (gtk_widget_get_realized (widget))
9587 gtk_widget_add_events_internal (widget, device, events);
9589 g_object_notify (G_OBJECT (widget), "events");
9593 * gtk_widget_get_toplevel:
9594 * @widget: a #GtkWidget
9596 * This function returns the topmost widget in the container hierarchy
9597 * @widget is a part of. If @widget has no parent widgets, it will be
9598 * returned as the topmost widget. No reference will be added to the
9599 * returned widget; it should not be unreferenced.
9601 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9602 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9604 * %NULL if @widget wasn't inside a toplevel window, and if the
9605 * window was inside a #GtkWindow-derived widget which was in turn
9606 * inside the toplevel #GtkWindow. While the second case may
9607 * seem unlikely, it actually happens when a #GtkPlug is embedded
9608 * inside a #GtkSocket within the same application.
9610 * To reliably find the toplevel #GtkWindow, use
9611 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9612 * is set on the result.
9614 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9615 * if (gtk_widget_is_toplevel (toplevel))
9617 * /* Perform action on toplevel. */
9621 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9622 * if there's no ancestor.
9625 gtk_widget_get_toplevel (GtkWidget *widget)
9627 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9629 while (widget->priv->parent)
9630 widget = widget->priv->parent;
9636 * gtk_widget_get_ancestor:
9637 * @widget: a #GtkWidget
9638 * @widget_type: ancestor type
9640 * Gets the first ancestor of @widget with type @widget_type. For example,
9641 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9642 * the first #GtkBox that's an ancestor of @widget. No reference will be
9643 * added to the returned widget; it should not be unreferenced. See note
9644 * about checking for a toplevel #GtkWindow in the docs for
9645 * gtk_widget_get_toplevel().
9647 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9648 * considers @widget to be an ancestor of itself.
9650 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9653 gtk_widget_get_ancestor (GtkWidget *widget,
9656 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9658 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9659 widget = widget->priv->parent;
9661 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9668 * gtk_widget_set_visual:
9669 * @widget: a #GtkWidget
9670 * @visual: visual to be used or %NULL to unset a previous one
9672 * Sets the visual that should be used for by widget and its children for
9673 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9674 * returned by gdk_widget_get_screen(), so handling the
9675 * #GtkWidget::screen-changed signal is necessary.
9677 * Setting a new @visual will not cause @widget to recreate its windows,
9678 * so you should call this function before @widget is realized.
9681 gtk_widget_set_visual (GtkWidget *widget,
9684 g_return_if_fail (GTK_IS_WIDGET (widget));
9685 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9688 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9691 g_object_set_qdata_full (G_OBJECT (widget),
9693 g_object_ref (visual),
9698 * gtk_widget_get_visual:
9699 * @widget: a #GtkWidget
9701 * Gets the visual that will be used to render @widget.
9703 * Return value: (transfer none): the visual for @widget
9706 gtk_widget_get_visual (GtkWidget *widget)
9712 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9714 if (gtk_widget_get_has_window (widget) &&
9715 widget->priv->window)
9716 return gdk_window_get_visual (widget->priv->window);
9718 screen = gtk_widget_get_screen (widget);
9720 for (w = widget; w != NULL; w = w->priv->parent)
9722 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9725 if (gdk_visual_get_screen (visual) == screen)
9728 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9729 gtk_widget_get_name (widget));
9733 return gdk_screen_get_system_visual (screen);
9737 * gtk_widget_get_settings:
9738 * @widget: a #GtkWidget
9740 * Gets the settings object holding the settings used for this widget.
9742 * Note that this function can only be called when the #GtkWidget
9743 * is attached to a toplevel, since the settings object is specific
9744 * to a particular #GdkScreen.
9746 * Return value: (transfer none): the relevant #GtkSettings object
9749 gtk_widget_get_settings (GtkWidget *widget)
9751 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9753 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9757 * gtk_widget_get_events:
9758 * @widget: a #GtkWidget
9760 * Returns the event mask for the widget (a bitfield containing flags
9761 * from the #GdkEventMask enumeration). These are the events that the widget
9764 * Return value: event mask for @widget
9767 gtk_widget_get_events (GtkWidget *widget)
9769 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9771 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9775 * gtk_widget_get_device_events:
9776 * @widget: a #GtkWidget
9777 * @device: a #GdkDevice
9779 * Returns the events mask for the widget corresponding to an specific device. These
9780 * are the events that the widget will receive when @device operates on it.
9782 * Returns: device event mask for @widget
9787 gtk_widget_get_device_events (GtkWidget *widget,
9790 GHashTable *device_events;
9792 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9793 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9795 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9800 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9804 * gtk_widget_get_pointer:
9805 * @widget: a #GtkWidget
9806 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9807 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9809 * Obtains the location of the mouse pointer in widget coordinates.
9810 * Widget coordinates are a bit odd; for historical reasons, they are
9811 * defined as @widget->window coordinates for widgets that are not
9812 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9813 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9815 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9818 gtk_widget_get_pointer (GtkWidget *widget,
9822 GtkWidgetPrivate *priv;
9824 g_return_if_fail (GTK_IS_WIDGET (widget));
9826 priv = widget->priv;
9833 if (gtk_widget_get_realized (widget))
9835 gdk_window_get_device_position (priv->window,
9836 gdk_device_manager_get_client_pointer (
9837 gdk_display_get_device_manager (
9838 gtk_widget_get_display (widget))),
9841 if (!gtk_widget_get_has_window (widget))
9844 *x -= priv->allocation.x;
9846 *y -= priv->allocation.y;
9852 * gtk_widget_is_ancestor:
9853 * @widget: a #GtkWidget
9854 * @ancestor: another #GtkWidget
9856 * Determines whether @widget is somewhere inside @ancestor, possibly with
9857 * intermediate containers.
9859 * Return value: %TRUE if @ancestor contains @widget as a child,
9860 * grandchild, great grandchild, etc.
9863 gtk_widget_is_ancestor (GtkWidget *widget,
9864 GtkWidget *ancestor)
9866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9867 g_return_val_if_fail (ancestor != NULL, FALSE);
9871 if (widget->priv->parent == ancestor)
9873 widget = widget->priv->parent;
9879 static GQuark quark_composite_name = 0;
9882 * gtk_widget_set_composite_name:
9883 * @widget: a #GtkWidget.
9884 * @name: the name to set
9886 * Sets a widgets composite name. The widget must be
9887 * a composite child of its parent; see gtk_widget_push_composite_child().
9890 gtk_widget_set_composite_name (GtkWidget *widget,
9893 g_return_if_fail (GTK_IS_WIDGET (widget));
9894 g_return_if_fail (widget->priv->composite_child);
9895 g_return_if_fail (name != NULL);
9897 if (!quark_composite_name)
9898 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9900 g_object_set_qdata_full (G_OBJECT (widget),
9901 quark_composite_name,
9907 * gtk_widget_get_composite_name:
9908 * @widget: a #GtkWidget
9910 * Obtains the composite name of a widget.
9912 * Returns: the composite name of @widget, or %NULL if @widget is not
9913 * a composite child. The string should be freed when it is no
9917 gtk_widget_get_composite_name (GtkWidget *widget)
9919 GtkWidgetPrivate *priv;
9921 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9923 priv = widget->priv;
9925 if (widget->priv->composite_child && priv->parent)
9926 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9933 * gtk_widget_push_composite_child:
9935 * Makes all newly-created widgets as composite children until
9936 * the corresponding gtk_widget_pop_composite_child() call.
9938 * A composite child is a child that's an implementation detail of the
9939 * container it's inside and should not be visible to people using the
9940 * container. Composite children aren't treated differently by GTK (but
9941 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9942 * builders might want to treat them in a different way.
9944 * Here is a simple example:
9946 * gtk_widget_push_composite_child ();
9947 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9948 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9949 * gtk_widget_pop_composite_child ();
9950 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9951 * GTK_WIDGET (scrolled_window));
9952 * g_object_ref (scrolled_window->hscrollbar);
9956 gtk_widget_push_composite_child (void)
9958 composite_child_stack++;
9962 * gtk_widget_pop_composite_child:
9964 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9967 gtk_widget_pop_composite_child (void)
9969 if (composite_child_stack)
9970 composite_child_stack--;
9974 gtk_widget_emit_direction_changed (GtkWidget *widget,
9975 GtkTextDirection old_dir)
9977 gtk_widget_update_pango_context (widget);
9979 if (widget->priv->context)
9980 gtk_style_context_set_direction (widget->priv->context,
9981 gtk_widget_get_direction (widget));
9983 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9987 * gtk_widget_set_direction:
9988 * @widget: a #GtkWidget
9989 * @dir: the new direction
9991 * Sets the reading direction on a particular widget. This direction
9992 * controls the primary direction for widgets containing text,
9993 * and also the direction in which the children of a container are
9994 * packed. The ability to set the direction is present in order
9995 * so that correct localization into languages with right-to-left
9996 * reading directions can be done. Generally, applications will
9997 * let the default reading direction present, except for containers
9998 * where the containers are arranged in an order that is explicitely
9999 * visual rather than logical (such as buttons for text justification).
10001 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10002 * set by gtk_widget_set_default_direction() will be used.
10005 gtk_widget_set_direction (GtkWidget *widget,
10006 GtkTextDirection dir)
10008 GtkTextDirection old_dir;
10010 g_return_if_fail (GTK_IS_WIDGET (widget));
10011 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10013 old_dir = gtk_widget_get_direction (widget);
10015 widget->priv->direction = dir;
10017 if (old_dir != gtk_widget_get_direction (widget))
10018 gtk_widget_emit_direction_changed (widget, old_dir);
10022 * gtk_widget_get_direction:
10023 * @widget: a #GtkWidget
10025 * Gets the reading direction for a particular widget. See
10026 * gtk_widget_set_direction().
10028 * Return value: the reading direction for the widget.
10031 gtk_widget_get_direction (GtkWidget *widget)
10033 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10035 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10036 return gtk_default_direction;
10038 return widget->priv->direction;
10042 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10044 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10046 g_object_ref (widget);
10048 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10049 gtk_widget_emit_direction_changed (widget, old_dir);
10051 if (GTK_IS_CONTAINER (widget))
10052 gtk_container_forall (GTK_CONTAINER (widget),
10053 gtk_widget_set_default_direction_recurse,
10056 g_object_unref (widget);
10060 * gtk_widget_set_default_direction:
10061 * @dir: the new default direction. This cannot be
10062 * %GTK_TEXT_DIR_NONE.
10064 * Sets the default reading direction for widgets where the
10065 * direction has not been explicitly set by gtk_widget_set_direction().
10068 gtk_widget_set_default_direction (GtkTextDirection dir)
10070 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10072 if (dir != gtk_default_direction)
10074 GList *toplevels, *tmp_list;
10075 GtkTextDirection old_dir = gtk_default_direction;
10077 gtk_default_direction = dir;
10079 tmp_list = toplevels = gtk_window_list_toplevels ();
10080 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10084 gtk_widget_set_default_direction_recurse (tmp_list->data,
10085 GUINT_TO_POINTER (old_dir));
10086 g_object_unref (tmp_list->data);
10087 tmp_list = tmp_list->next;
10090 g_list_free (toplevels);
10095 * gtk_widget_get_default_direction:
10097 * Obtains the current default reading direction. See
10098 * gtk_widget_set_default_direction().
10100 * Return value: the current default direction.
10103 gtk_widget_get_default_direction (void)
10105 return gtk_default_direction;
10109 gtk_widget_dispose (GObject *object)
10111 GtkWidget *widget = GTK_WIDGET (object);
10112 GtkWidgetPrivate *priv = widget->priv;
10115 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10116 else if (gtk_widget_get_visible (widget))
10117 gtk_widget_hide (widget);
10119 priv->visible = FALSE;
10120 if (gtk_widget_get_realized (widget))
10121 gtk_widget_unrealize (widget);
10123 if (!priv->in_destruction)
10125 priv->in_destruction = TRUE;
10126 g_signal_emit (object, widget_signals[DESTROY], 0);
10127 priv->in_destruction = FALSE;
10130 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10134 gtk_widget_real_destroy (GtkWidget *object)
10136 /* gtk_object_destroy() will already hold a refcount on object */
10137 GtkWidget *widget = GTK_WIDGET (object);
10138 GtkWidgetPrivate *priv = widget->priv;
10140 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10142 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10146 gtk_accessible_set_widget (accessible, NULL);
10147 g_object_unref (accessible);
10151 /* wipe accelerator closures (keep order) */
10152 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10153 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10155 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10156 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10158 gtk_grab_remove (widget);
10161 g_object_unref (priv->style);
10162 priv->style = gtk_widget_get_default_style ();
10163 g_object_ref (priv->style);
10167 gtk_widget_finalize (GObject *object)
10169 GtkWidget *widget = GTK_WIDGET (object);
10170 GtkWidgetPrivate *priv = widget->priv;
10171 GtkWidgetAuxInfo *aux_info;
10172 GtkAccessible *accessible;
10174 gtk_grab_remove (widget);
10176 g_object_unref (priv->style);
10177 priv->style = NULL;
10179 g_free (priv->name);
10181 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10183 gtk_widget_aux_info_destroy (aux_info);
10185 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10187 g_object_unref (accessible);
10190 gtk_widget_path_free (priv->path);
10193 g_object_unref (priv->context);
10195 _gtk_widget_free_cached_sizes (widget);
10197 if (g_object_is_floating (object))
10198 g_warning ("A floating object was finalized. This means that someone\n"
10199 "called g_object_unref() on an object that had only a floating\n"
10200 "reference; the initial floating reference is not owned by anyone\n"
10201 "and must be removed with g_object_ref_sink().");
10203 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10206 /*****************************************
10207 * gtk_widget_real_map:
10212 *****************************************/
10215 gtk_widget_real_map (GtkWidget *widget)
10217 GtkWidgetPrivate *priv = widget->priv;
10219 g_assert (gtk_widget_get_realized (widget));
10221 if (!gtk_widget_get_mapped (widget))
10223 gtk_widget_set_mapped (widget, TRUE);
10225 if (gtk_widget_get_has_window (widget))
10226 gdk_window_show (priv->window);
10230 /*****************************************
10231 * gtk_widget_real_unmap:
10236 *****************************************/
10239 gtk_widget_real_unmap (GtkWidget *widget)
10241 GtkWidgetPrivate *priv = widget->priv;
10243 if (gtk_widget_get_mapped (widget))
10245 gtk_widget_set_mapped (widget, FALSE);
10247 if (gtk_widget_get_has_window (widget))
10248 gdk_window_hide (priv->window);
10252 /*****************************************
10253 * gtk_widget_real_realize:
10258 *****************************************/
10261 gtk_widget_real_realize (GtkWidget *widget)
10263 GtkWidgetPrivate *priv = widget->priv;
10265 g_assert (!gtk_widget_get_has_window (widget));
10267 gtk_widget_set_realized (widget, TRUE);
10270 priv->window = gtk_widget_get_parent_window (widget);
10271 g_object_ref (priv->window);
10275 /*****************************************
10276 * gtk_widget_real_unrealize:
10281 *****************************************/
10284 gtk_widget_real_unrealize (GtkWidget *widget)
10286 GtkWidgetPrivate *priv = widget->priv;
10288 g_assert (!widget->priv->mapped);
10290 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10293 /* We must do unrealize child widget BEFORE container widget.
10294 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10295 * So, unrealizing container widget bofore its children causes the problem
10296 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10299 if (GTK_IS_CONTAINER (widget))
10300 gtk_container_forall (GTK_CONTAINER (widget),
10301 (GtkCallback) gtk_widget_unrealize,
10304 if (gtk_widget_get_has_window (widget))
10306 gdk_window_set_user_data (priv->window, NULL);
10307 gdk_window_destroy (priv->window);
10308 priv->window = NULL;
10312 g_object_unref (priv->window);
10313 priv->window = NULL;
10316 gtk_selection_remove_all (widget);
10318 gtk_widget_set_realized (widget, FALSE);
10322 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10323 GtkOrientation orientation,
10324 gint *minimum_size,
10325 gint *natural_size)
10327 const GtkWidgetAuxInfo *aux_info;
10329 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10331 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10332 aux_info->width > 0)
10334 *minimum_size = MAX (*minimum_size, aux_info->width);
10336 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10337 aux_info->height > 0)
10339 *minimum_size = MAX (*minimum_size, aux_info->height);
10342 /* Fix it if set_size_request made natural size smaller than min size.
10343 * This would also silently fix broken widgets, but we warn about them
10344 * in gtksizerequest.c when calling their size request vfuncs.
10346 *natural_size = MAX (*natural_size, *minimum_size);
10348 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10350 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10351 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10355 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10356 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10361 * _gtk_widget_peek_request_cache:
10363 * Returns the address of the widget's request cache (strictly for
10364 * internal use in gtksizerequest.c)
10366 * Return value: the address of @widget's size request cache.
10369 _gtk_widget_peek_request_cache (GtkWidget *widget)
10371 /* Don't bother slowing things down with the return_if_fail guards here */
10372 return &widget->priv->requests;
10376 * _gtk_widget_set_device_window:
10377 * @widget: a #GtkWidget
10378 * @device: a #GdkDevice
10379 * @window: the new device window
10381 * Sets pointer window for @widget and @device.
10382 * Does not ref @window.
10385 _gtk_widget_set_device_window (GtkWidget *widget,
10389 GHashTable *device_window;
10391 g_return_if_fail (GTK_IS_WIDGET (widget));
10392 g_return_if_fail (GDK_IS_DEVICE (device));
10393 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10395 if (!gtk_widget_get_mapped (widget))
10398 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10400 if (!device_window && window)
10402 device_window = g_hash_table_new (NULL, NULL);
10403 g_object_set_qdata_full (G_OBJECT (widget),
10404 quark_pointer_window,
10406 (GDestroyNotify) g_hash_table_destroy);
10410 g_hash_table_insert (device_window, device, window);
10411 else if (device_window)
10413 g_hash_table_remove (device_window, device);
10415 if (g_hash_table_size (device_window) == 0)
10416 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10421 * _gtk_widget_get_device_window:
10422 * @widget: a #GtkWidget
10423 * @device: a #GdkDevice
10425 * Return value: the device window set on @widget, or %NULL
10428 _gtk_widget_get_device_window (GtkWidget *widget,
10431 GHashTable *device_window;
10433 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10434 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10436 if (!gtk_widget_get_mapped (widget))
10439 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10441 if (!device_window)
10444 return g_hash_table_lookup (device_window, device);
10448 * _gtk_widget_list_devices:
10449 * @widget: a #GtkWidget
10451 * Returns the list of #GdkDevices that is currently on top
10452 * of any window belonging to @widget.
10453 * Free the list with g_list_free(), the elements are owned
10454 * by GTK+ and must not be freed.
10457 _gtk_widget_list_devices (GtkWidget *widget)
10459 GHashTableIter iter;
10460 GHashTable *device_window;
10461 GList *devices = NULL;
10462 gpointer key, value;
10464 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10466 if (!gtk_widget_get_mapped (widget))
10469 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10471 if (G_UNLIKELY (!device_window))
10474 g_hash_table_iter_init (&iter, device_window);
10476 while (g_hash_table_iter_next (&iter, &key, &value))
10477 devices = g_list_prepend (devices, key);
10483 synth_crossing (GtkWidget *widget,
10487 GdkCrossingMode mode,
10488 GdkNotifyType detail)
10492 event = gdk_event_new (type);
10494 event->crossing.window = g_object_ref (window);
10495 event->crossing.send_event = TRUE;
10496 event->crossing.subwindow = g_object_ref (window);
10497 event->crossing.time = GDK_CURRENT_TIME;
10498 event->crossing.x = event->crossing.y = 0;
10499 event->crossing.x_root = event->crossing.y_root = 0;
10500 event->crossing.mode = mode;
10501 event->crossing.detail = detail;
10502 event->crossing.focus = FALSE;
10503 event->crossing.state = 0;
10504 gdk_event_set_device (event, device);
10507 widget = gtk_get_event_widget (event);
10510 gtk_widget_event_internal (widget, event);
10512 gdk_event_free (event);
10516 * _gtk_widget_synthesize_crossing:
10517 * @from: the #GtkWidget the virtual pointer is leaving.
10518 * @to: the #GtkWidget the virtual pointer is moving to.
10519 * @mode: the #GdkCrossingMode to place on the synthesized events.
10521 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10523 * The real pointer window is the window that most recently received an enter notify
10524 * event. Windows that don't select for crossing events can't become the real
10525 * poiner window. The real pointer widget that owns the real pointer window. The
10526 * effective pointer window is the same as the real pointer window unless the real
10527 * pointer widget is either insensitive or there is a grab on a widget that is not
10528 * an ancestor of the real pointer widget (in which case the effective pointer
10529 * window should be the root window).
10531 * When the effective pointer window is the same as the real poiner window, we
10532 * receive crossing events from the windowing system. When the effective pointer
10533 * window changes to become different from the real pointer window we synthesize
10534 * crossing events, attempting to follow X protocol rules:
10536 * When the root window becomes the effective pointer window:
10537 * - leave notify on real pointer window, detail Ancestor
10538 * - leave notify on all of its ancestors, detail Virtual
10539 * - enter notify on root window, detail Inferior
10541 * When the root window ceases to be the effective pointer window:
10542 * - leave notify on root window, detail Inferior
10543 * - enter notify on all ancestors of real pointer window, detail Virtual
10544 * - enter notify on real pointer window, detail Ancestor
10547 _gtk_widget_synthesize_crossing (GtkWidget *from,
10550 GdkCrossingMode mode)
10552 GdkWindow *from_window = NULL, *to_window = NULL;
10554 g_return_if_fail (from != NULL || to != NULL);
10558 from_window = _gtk_widget_get_device_window (from, device);
10561 from_window = from->priv->window;
10566 to_window = _gtk_widget_get_device_window (to, device);
10569 to_window = to->priv->window;
10572 if (from_window == NULL && to_window == NULL)
10574 else if (from_window != NULL && to_window == NULL)
10576 GList *from_ancestors = NULL, *list;
10577 GdkWindow *from_ancestor = from_window;
10579 while (from_ancestor != NULL)
10581 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10582 if (from_ancestor == NULL)
10584 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10587 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10588 device, mode, GDK_NOTIFY_ANCESTOR);
10589 for (list = g_list_last (from_ancestors); list; list = list->prev)
10591 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10592 device, mode, GDK_NOTIFY_VIRTUAL);
10595 /* XXX: enter/inferior on root window? */
10597 g_list_free (from_ancestors);
10599 else if (from_window == NULL && to_window != NULL)
10601 GList *to_ancestors = NULL, *list;
10602 GdkWindow *to_ancestor = to_window;
10604 while (to_ancestor != NULL)
10606 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10607 if (to_ancestor == NULL)
10609 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10612 /* XXX: leave/inferior on root window? */
10614 for (list = to_ancestors; list; list = list->next)
10616 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10617 device, mode, GDK_NOTIFY_VIRTUAL);
10619 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10620 device, mode, GDK_NOTIFY_ANCESTOR);
10622 g_list_free (to_ancestors);
10624 else if (from_window == to_window)
10628 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10629 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10631 while (from_ancestor != NULL || to_ancestor != NULL)
10633 if (from_ancestor != NULL)
10635 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10636 if (from_ancestor == to_window)
10639 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10641 if (to_ancestor != NULL)
10643 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10644 if (to_ancestor == from_window)
10647 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10650 if (to_ancestor == from_window)
10652 if (mode != GDK_CROSSING_GTK_UNGRAB)
10653 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10654 device, mode, GDK_NOTIFY_INFERIOR);
10655 for (list = to_ancestors; list; list = list->next)
10656 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10657 device, mode, GDK_NOTIFY_VIRTUAL);
10658 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10659 device, mode, GDK_NOTIFY_ANCESTOR);
10661 else if (from_ancestor == to_window)
10663 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10664 device, mode, GDK_NOTIFY_ANCESTOR);
10665 for (list = g_list_last (from_ancestors); list; list = list->prev)
10667 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10668 device, mode, GDK_NOTIFY_VIRTUAL);
10670 if (mode != GDK_CROSSING_GTK_GRAB)
10671 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10672 device, mode, GDK_NOTIFY_INFERIOR);
10676 while (from_ancestors != NULL && to_ancestors != NULL
10677 && from_ancestors->data == to_ancestors->data)
10679 from_ancestors = g_list_delete_link (from_ancestors,
10681 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10684 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10685 device, mode, GDK_NOTIFY_NONLINEAR);
10687 for (list = g_list_last (from_ancestors); list; list = list->prev)
10689 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10690 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10692 for (list = to_ancestors; list; list = list->next)
10694 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10695 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10697 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10698 device, mode, GDK_NOTIFY_NONLINEAR);
10700 g_list_free (from_ancestors);
10701 g_list_free (to_ancestors);
10706 gtk_widget_propagate_state (GtkWidget *widget,
10707 GtkStateData *data)
10709 GtkWidgetPrivate *priv = widget->priv;
10710 GtkStateFlags new_flags, old_flags = priv->state_flags;
10711 GtkStateType old_state;
10713 old_state = gtk_widget_get_state (widget);
10715 switch (data->operation)
10717 case STATE_CHANGE_REPLACE:
10718 priv->state_flags = data->flags;
10720 case STATE_CHANGE_SET:
10721 priv->state_flags |= data->flags;
10723 case STATE_CHANGE_UNSET:
10724 priv->state_flags &= ~(data->flags);
10728 /* make insensitivity unoverridable */
10729 if (!priv->sensitive)
10730 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10732 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10736 window = gtk_widget_get_toplevel (widget);
10738 if (window && gtk_widget_is_toplevel (window))
10739 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10742 new_flags = priv->state_flags;
10744 if (old_flags != new_flags)
10746 g_object_ref (widget);
10748 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10749 gtk_grab_remove (widget);
10751 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10753 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10754 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10756 if (!priv->shadowed &&
10757 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10759 GList *event_windows = NULL;
10760 GList *devices, *d;
10762 devices = _gtk_widget_list_devices (widget);
10764 for (d = devices; d; d = d->next)
10770 window = _gtk_widget_get_device_window (widget, device);
10772 /* Do not propagate more than once to the
10773 * same window if non-multidevice aware.
10775 if (!gdk_window_get_support_multidevice (window) &&
10776 g_list_find (event_windows, window))
10779 if (!gtk_widget_is_sensitive (widget))
10780 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10781 GDK_CROSSING_STATE_CHANGED);
10783 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10784 GDK_CROSSING_STATE_CHANGED);
10786 event_windows = g_list_prepend (event_windows, window);
10789 g_list_free (event_windows);
10790 g_list_free (devices);
10793 if (GTK_IS_CONTAINER (widget))
10795 GtkStateData child_data = *data;
10797 /* Make sure to only propate the right states further */
10798 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10800 gtk_container_forall (GTK_CONTAINER (widget),
10801 (GtkCallback) gtk_widget_propagate_state,
10805 /* Trigger state change transitions for the widget */
10806 if (priv->context &&
10807 gtk_widget_get_mapped (widget))
10809 gint diff, flag = 1;
10811 diff = old_flags ^ new_flags;
10815 if ((diff & flag) != 0)
10819 target = ((new_flags & flag) != 0);
10820 _gtk_widget_notify_state_change (widget, flag, target);
10829 g_object_unref (widget);
10833 static const GtkWidgetAuxInfo default_aux_info = {
10841 * gtk_widget_get_aux_info:
10842 * @widget: a #GtkWidget
10843 * @create: if %TRUE, create the structure if it doesn't exist
10845 * Get the #GtkWidgetAuxInfo structure for the widget.
10847 * Return value: the #GtkAuxInfo structure for the widget, or
10848 * %NULL if @create is %FALSE and one doesn't already exist.
10850 static GtkWidgetAuxInfo *
10851 gtk_widget_get_aux_info (GtkWidget *widget,
10854 GtkWidgetAuxInfo *aux_info;
10856 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10857 if (!aux_info && create)
10859 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10861 *aux_info = default_aux_info;
10863 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10869 static const GtkWidgetAuxInfo*
10870 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10872 GtkWidgetAuxInfo *aux_info;
10874 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10875 if (aux_info == NULL)
10877 return &default_aux_info;
10885 /*****************************************
10886 * gtk_widget_aux_info_destroy:
10891 *****************************************/
10894 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10896 g_slice_free (GtkWidgetAuxInfo, aux_info);
10900 * gtk_widget_shape_combine_region:
10901 * @widget: a #GtkWidget
10902 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10904 * Sets a shape for this widget's GDK window. This allows for
10905 * transparent windows etc., see gdk_window_shape_combine_region()
10906 * for more information.
10911 gtk_widget_shape_combine_region (GtkWidget *widget,
10912 cairo_region_t *region)
10914 GtkWidgetPrivate *priv;
10916 g_return_if_fail (GTK_IS_WIDGET (widget));
10917 /* set_shape doesn't work on widgets without gdk window */
10918 g_return_if_fail (gtk_widget_get_has_window (widget));
10920 priv = widget->priv;
10922 if (region == NULL)
10924 priv->has_shape_mask = FALSE;
10927 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10929 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10933 priv->has_shape_mask = TRUE;
10935 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10936 cairo_region_copy (region),
10937 (GDestroyNotify) cairo_region_destroy);
10939 /* set shape if widget has a gdk window already.
10940 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10943 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10948 * gtk_widget_input_shape_combine_region:
10949 * @widget: a #GtkWidget
10950 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10952 * Sets an input shape for this widget's GDK window. This allows for
10953 * windows which react to mouse click in a nonrectangular region, see
10954 * gdk_window_input_shape_combine_region() for more information.
10959 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10960 cairo_region_t *region)
10962 GtkWidgetPrivate *priv;
10964 g_return_if_fail (GTK_IS_WIDGET (widget));
10965 /* set_shape doesn't work on widgets without gdk window */
10966 g_return_if_fail (gtk_widget_get_has_window (widget));
10968 priv = widget->priv;
10970 if (region == NULL)
10973 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10975 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10979 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10980 cairo_region_copy (region),
10981 (GDestroyNotify) cairo_region_destroy);
10983 /* set shape if widget has a gdk window already.
10984 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10987 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10992 /* style properties
10996 * gtk_widget_class_install_style_property_parser: (skip)
10997 * @klass: a #GtkWidgetClass
10998 * @pspec: the #GParamSpec for the style property
10999 * @parser: the parser for the style property
11001 * Installs a style property on a widget class.
11004 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11006 GtkRcPropertyParser parser)
11008 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11009 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11010 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11011 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11013 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11015 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11016 G_OBJECT_CLASS_NAME (klass),
11021 g_param_spec_ref_sink (pspec);
11022 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11023 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11027 * gtk_widget_class_install_style_property:
11028 * @klass: a #GtkWidgetClass
11029 * @pspec: the #GParamSpec for the property
11031 * Installs a style property on a widget class. The parser for the
11032 * style property is determined by the value type of @pspec.
11035 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11038 GtkRcPropertyParser parser;
11040 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11041 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11043 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11045 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11049 * gtk_widget_class_find_style_property:
11050 * @klass: a #GtkWidgetClass
11051 * @property_name: the name of the style property to find
11053 * Finds a style property of a widget class by name.
11055 * Returns: (transfer none): the #GParamSpec of the style property or
11056 * %NULL if @class has no style property with that name.
11061 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11062 const gchar *property_name)
11064 g_return_val_if_fail (property_name != NULL, NULL);
11066 return g_param_spec_pool_lookup (style_property_spec_pool,
11068 G_OBJECT_CLASS_TYPE (klass),
11073 * gtk_widget_class_list_style_properties:
11074 * @klass: a #GtkWidgetClass
11075 * @n_properties: location to return the number of style properties found
11077 * Returns all style properties of a widget class.
11079 * Returns: (array length=n_properties) (transfer container): a
11080 * newly allocated array of #GParamSpec*. The array must be
11081 * freed with g_free().
11086 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11087 guint *n_properties)
11089 GParamSpec **pspecs;
11092 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11093 G_OBJECT_CLASS_TYPE (klass),
11102 * gtk_widget_style_get_property:
11103 * @widget: a #GtkWidget
11104 * @property_name: the name of a style property
11105 * @value: location to return the property value
11107 * Gets the value of a style property of @widget.
11110 gtk_widget_style_get_property (GtkWidget *widget,
11111 const gchar *property_name,
11116 g_return_if_fail (GTK_IS_WIDGET (widget));
11117 g_return_if_fail (property_name != NULL);
11118 g_return_if_fail (G_IS_VALUE (value));
11120 g_object_ref (widget);
11121 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11123 G_OBJECT_TYPE (widget),
11126 g_warning ("%s: widget class `%s' has no property named `%s'",
11128 G_OBJECT_TYPE_NAME (widget),
11132 GtkStyleContext *context;
11133 const GValue *peek_value;
11134 GtkStateFlags state;
11136 context = gtk_widget_get_style_context (widget);
11137 state = gtk_widget_get_state_flags (widget);
11139 peek_value = _gtk_style_context_peek_style_property (context,
11140 G_OBJECT_TYPE (widget),
11143 /* auto-conversion of the caller's value type
11145 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11146 g_value_copy (peek_value, value);
11147 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11148 g_value_transform (peek_value, value);
11150 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11152 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11153 G_VALUE_TYPE_NAME (value));
11155 g_object_unref (widget);
11159 * gtk_widget_style_get_valist:
11160 * @widget: a #GtkWidget
11161 * @first_property_name: the name of the first property to get
11162 * @var_args: a <type>va_list</type> of pairs of property names and
11163 * locations to return the property values, starting with the location
11164 * for @first_property_name.
11166 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11170 gtk_widget_style_get_valist (GtkWidget *widget,
11171 const gchar *first_property_name,
11174 GtkStyleContext *context;
11175 GtkStateFlags state;
11178 g_return_if_fail (GTK_IS_WIDGET (widget));
11180 g_object_ref (widget);
11181 context = gtk_widget_get_style_context (widget);
11182 state = gtk_widget_get_state_flags (widget);
11184 name = first_property_name;
11187 const GValue *peek_value;
11191 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11193 G_OBJECT_TYPE (widget),
11197 g_warning ("%s: widget class `%s' has no property named `%s'",
11199 G_OBJECT_TYPE_NAME (widget),
11203 /* style pspecs are always readable so we can spare that check here */
11205 peek_value = _gtk_style_context_peek_style_property (context,
11206 G_OBJECT_TYPE (widget),
11209 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11212 g_warning ("%s: %s", G_STRLOC, error);
11217 name = va_arg (var_args, gchar*);
11220 g_object_unref (widget);
11224 * gtk_widget_style_get:
11225 * @widget: a #GtkWidget
11226 * @first_property_name: the name of the first property to get
11227 * @...: pairs of property names and locations to return the
11228 * property values, starting with the location for
11229 * @first_property_name, terminated by %NULL.
11231 * Gets the values of a multiple style properties of @widget.
11234 gtk_widget_style_get (GtkWidget *widget,
11235 const gchar *first_property_name,
11240 g_return_if_fail (GTK_IS_WIDGET (widget));
11242 va_start (var_args, first_property_name);
11243 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11248 * gtk_requisition_new:
11250 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11252 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11253 * be freed with gtk_requisition_free().
11258 gtk_requisition_new (void)
11260 return g_slice_new0 (GtkRequisition);
11264 * gtk_requisition_copy:
11265 * @requisition: a #GtkRequisition
11267 * Copies a #GtkRequisition.
11269 * Returns: a copy of @requisition
11272 gtk_requisition_copy (const GtkRequisition *requisition)
11274 return g_slice_dup (GtkRequisition, requisition);
11278 * gtk_requisition_free:
11279 * @requisition: a #GtkRequisition
11281 * Frees a #GtkRequisition.
11284 gtk_requisition_free (GtkRequisition *requisition)
11286 g_slice_free (GtkRequisition, requisition);
11289 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11290 gtk_requisition_copy,
11291 gtk_requisition_free)
11294 * gtk_widget_class_set_accessible_type:
11295 * @widget_class: class to set the accessible type for
11296 * @type: The object type that implements the accessible for @widget_class
11298 * Sets the type to be used for creating accessibles for widgets of
11299 * @widget_class. The given @type must be a subtype of the type used for
11300 * accessibles of the parent class.
11302 * This function should only be called from class init functions of widgets.
11307 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11310 GtkWidgetClassPrivate *priv;
11312 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11313 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11315 priv = widget_class->priv;
11317 priv->accessible_type = type;
11318 /* reset this - honoring the type's role is better. */
11319 priv->accessible_role = ATK_ROLE_INVALID;
11323 * gtk_widget_class_set_accessible_role:
11324 * @widget_class: class to set the accessible role for
11325 * @role: The role to use for accessibles created for @widget_class
11327 * Sets the default #AtkRole to be set on accessibles created for
11328 * widgets of @widget_class. Accessibles may decide to not honor this
11329 * setting if their role reporting is more refined. Calls to
11330 * gtk_widget_class_set_accessible_type() will reset this value.
11332 * In cases where you want more fine-grained control over the role of
11333 * accessibles created for @widget_class, you should provide your own
11334 * accessible type and use gtk_widget_class_set_accessible_type()
11337 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11338 * and the accessible's default role will be used instead.
11340 * This function should only be called from class init functions of widgets.
11345 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11348 GtkWidgetClassPrivate *priv;
11350 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11352 priv = widget_class->priv;
11354 priv->accessible_role = role;
11358 * _gtk_widget_peek_accessible:
11359 * @widget: a #GtkWidget
11361 * Gets the accessible for @widget, if it has been created yet.
11362 * Otherwise, this function returns %NULL. If the @widget's implementation
11363 * does not use the default way to create accessibles, %NULL will always be
11366 * Returns: the accessible for @widget or %NULL if none has been
11370 _gtk_widget_peek_accessible (GtkWidget *widget)
11372 return g_object_get_qdata (G_OBJECT (widget),
11373 quark_accessible_object);
11377 * gtk_widget_get_accessible:
11378 * @widget: a #GtkWidget
11380 * Returns the accessible object that describes the widget to an
11381 * assistive technology.
11383 * If accessibility support is not available, this #AtkObject
11384 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11385 * implementation is available for the widget instance in question,
11386 * it will inherit an #AtkObject implementation from the first ancestor
11387 * class for which such an implementation is defined.
11389 * The documentation of the
11390 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11391 * library contains more information about accessible objects and their uses.
11393 * Returns: (transfer none): the #AtkObject associated with @widget
11396 gtk_widget_get_accessible (GtkWidget *widget)
11398 GtkWidgetClass *klass;
11400 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11402 klass = GTK_WIDGET_GET_CLASS (widget);
11404 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11406 return klass->get_accessible (widget);
11410 gtk_widget_real_get_accessible (GtkWidget *widget)
11412 AtkObject* accessible;
11414 accessible = g_object_get_qdata (G_OBJECT (widget),
11415 quark_accessible_object);
11418 GtkWidgetClass *widget_class;
11419 GtkWidgetClassPrivate *priv;
11420 AtkObjectFactory *factory;
11421 AtkRegistry *default_registry;
11423 widget_class = GTK_WIDGET_GET_CLASS (widget);
11424 priv = widget_class->priv;
11426 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11428 default_registry = atk_get_default_registry ();
11429 factory = atk_registry_get_factory (default_registry,
11430 G_TYPE_FROM_INSTANCE (widget));
11432 atk_object_factory_create_accessible (factory,
11433 G_OBJECT (widget));
11435 if (priv->accessible_role != ATK_ROLE_INVALID)
11436 atk_object_set_role (accessible, priv->accessible_role);
11438 g_object_set_qdata (G_OBJECT (widget),
11439 quark_accessible_object,
11444 accessible = g_object_new (priv->accessible_type,
11447 if (priv->accessible_role != ATK_ROLE_INVALID)
11448 atk_object_set_role (accessible, priv->accessible_role);
11450 g_object_set_qdata (G_OBJECT (widget),
11451 quark_accessible_object,
11454 atk_object_initialize (accessible, widget);
11456 /* Set the role again, since we don't want a role set
11457 * in some parent initialize() function to override
11460 if (priv->accessible_role != ATK_ROLE_INVALID)
11461 atk_object_set_role (accessible, priv->accessible_role);
11468 * Initialize a AtkImplementorIface instance's virtual pointers as
11469 * appropriate to this implementor's class (GtkWidget).
11472 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11474 iface->ref_accessible = gtk_widget_ref_accessible;
11478 gtk_widget_ref_accessible (AtkImplementor *implementor)
11480 AtkObject *accessible;
11482 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11484 g_object_ref (accessible);
11489 * Expand flag management
11493 gtk_widget_update_computed_expand (GtkWidget *widget)
11495 GtkWidgetPrivate *priv;
11497 priv = widget->priv;
11499 if (priv->need_compute_expand)
11503 if (priv->hexpand_set)
11508 if (priv->vexpand_set)
11513 /* we don't need to use compute_expand if both expands are
11514 * forced by the app
11516 if (!(priv->hexpand_set && priv->vexpand_set))
11518 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11522 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11523 priv->hexpand_set ? &ignored : &h,
11524 priv->vexpand_set ? &ignored : &v);
11528 priv->need_compute_expand = FALSE;
11529 priv->computed_hexpand = h != FALSE;
11530 priv->computed_vexpand = v != FALSE;
11535 * gtk_widget_queue_compute_expand:
11536 * @widget: a #GtkWidget
11538 * Mark @widget as needing to recompute its expand flags. Call
11539 * this function when setting legacy expand child properties
11540 * on the child of a container.
11542 * See gtk_widget_compute_expand().
11545 gtk_widget_queue_compute_expand (GtkWidget *widget)
11548 gboolean changed_anything;
11550 if (widget->priv->need_compute_expand)
11553 changed_anything = FALSE;
11555 while (parent != NULL)
11557 if (!parent->priv->need_compute_expand)
11559 parent->priv->need_compute_expand = TRUE;
11560 changed_anything = TRUE;
11563 /* Note: if we had an invariant that "if a child needs to
11564 * compute expand, its parents also do" then we could stop going
11565 * up when we got to a parent that already needed to
11566 * compute. However, in general we compute expand lazily (as
11567 * soon as we see something in a subtree that is expand, we know
11568 * we're expanding) and so this invariant does not hold and we
11569 * have to always walk all the way up in case some ancestor
11570 * is not currently need_compute_expand.
11573 parent = parent->priv->parent;
11576 /* recomputing expand always requires
11577 * a relayout as well
11579 if (changed_anything)
11580 gtk_widget_queue_resize (widget);
11584 * gtk_widget_compute_expand:
11585 * @widget: the widget
11586 * @orientation: expand direction
11588 * Computes whether a container should give this widget extra space
11589 * when possible. Containers should check this, rather than
11590 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11592 * This function already checks whether the widget is visible, so
11593 * visibility does not need to be checked separately. Non-visible
11594 * widgets are not expanded.
11596 * The computed expand value uses either the expand setting explicitly
11597 * set on the widget itself, or, if none has been explicitly set,
11598 * the widget may expand if some of its children do.
11600 * Return value: whether widget tree rooted here should be expanded
11603 gtk_widget_compute_expand (GtkWidget *widget,
11604 GtkOrientation orientation)
11606 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11608 /* We never make a widget expand if not even showing. */
11609 if (!gtk_widget_get_visible (widget))
11612 gtk_widget_update_computed_expand (widget);
11614 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11616 return widget->priv->computed_hexpand;
11620 return widget->priv->computed_vexpand;
11625 gtk_widget_set_expand (GtkWidget *widget,
11626 GtkOrientation orientation,
11629 const char *expand_prop;
11630 const char *expand_set_prop;
11632 GtkWidgetPrivate *priv;
11634 g_return_if_fail (GTK_IS_WIDGET (widget));
11636 priv = widget->priv;
11638 expand = expand != FALSE;
11640 was_both = priv->hexpand && priv->vexpand;
11642 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11644 if (priv->hexpand_set &&
11645 priv->hexpand == expand)
11648 priv->hexpand_set = TRUE;
11649 priv->hexpand = expand;
11651 expand_prop = "hexpand";
11652 expand_set_prop = "hexpand-set";
11656 if (priv->vexpand_set &&
11657 priv->vexpand == expand)
11660 priv->vexpand_set = TRUE;
11661 priv->vexpand = expand;
11663 expand_prop = "vexpand";
11664 expand_set_prop = "vexpand-set";
11667 gtk_widget_queue_compute_expand (widget);
11669 g_object_freeze_notify (G_OBJECT (widget));
11670 g_object_notify (G_OBJECT (widget), expand_prop);
11671 g_object_notify (G_OBJECT (widget), expand_set_prop);
11672 if (was_both != (priv->hexpand && priv->vexpand))
11673 g_object_notify (G_OBJECT (widget), "expand");
11674 g_object_thaw_notify (G_OBJECT (widget));
11678 gtk_widget_set_expand_set (GtkWidget *widget,
11679 GtkOrientation orientation,
11682 GtkWidgetPrivate *priv;
11685 priv = widget->priv;
11687 set = set != FALSE;
11689 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11691 if (set == priv->hexpand_set)
11694 priv->hexpand_set = set;
11695 prop = "hexpand-set";
11699 if (set == priv->vexpand_set)
11702 priv->vexpand_set = set;
11703 prop = "vexpand-set";
11706 gtk_widget_queue_compute_expand (widget);
11708 g_object_notify (G_OBJECT (widget), prop);
11712 * gtk_widget_get_hexpand:
11713 * @widget: the widget
11715 * Gets whether the widget would like any available extra horizontal
11716 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11717 * generally receive the extra space. For example, a list or
11718 * scrollable area or document in your window would often be set to
11721 * Containers should use gtk_widget_compute_expand() rather than
11722 * this function, to see whether a widget, or any of its children,
11723 * has the expand flag set. If any child of a widget wants to
11724 * expand, the parent may ask to expand also.
11726 * This function only looks at the widget's own hexpand flag, rather
11727 * than computing whether the entire widget tree rooted at this widget
11730 * Return value: whether hexpand flag is set
11733 gtk_widget_get_hexpand (GtkWidget *widget)
11735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11737 return widget->priv->hexpand;
11741 * gtk_widget_set_hexpand:
11742 * @widget: the widget
11743 * @expand: whether to expand
11745 * Sets whether the widget would like any available extra horizontal
11746 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11747 * generally receive the extra space. For example, a list or
11748 * scrollable area or document in your window would often be set to
11751 * Call this function to set the expand flag if you would like your
11752 * widget to become larger horizontally when the window has extra
11755 * By default, widgets automatically expand if any of their children
11756 * want to expand. (To see if a widget will automatically expand given
11757 * its current children and state, call gtk_widget_compute_expand(). A
11758 * container can decide how the expandability of children affects the
11759 * expansion of the container by overriding the compute_expand virtual
11760 * method on #GtkWidget.).
11762 * Setting hexpand explicitly with this function will override the
11763 * automatic expand behavior.
11765 * This function forces the widget to expand or not to expand,
11766 * regardless of children. The override occurs because
11767 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11768 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11769 * value to be used, rather than looking at children and widget state.
11772 gtk_widget_set_hexpand (GtkWidget *widget,
11775 g_return_if_fail (GTK_IS_WIDGET (widget));
11777 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11781 * gtk_widget_get_hexpand_set:
11782 * @widget: the widget
11784 * Gets whether gtk_widget_set_hexpand() has been used to
11785 * explicitly set the expand flag on this widget.
11787 * If hexpand is set, then it overrides any computed
11788 * expand value based on child widgets. If hexpand is not
11789 * set, then the expand value depends on whether any
11790 * children of the widget would like to expand.
11792 * There are few reasons to use this function, but it's here
11793 * for completeness and consistency.
11795 * Return value: whether hexpand has been explicitly set
11798 gtk_widget_get_hexpand_set (GtkWidget *widget)
11800 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11802 return widget->priv->hexpand_set;
11806 * gtk_widget_set_hexpand_set:
11807 * @widget: the widget
11808 * @set: value for hexpand-set property
11810 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11813 * The hexpand-set property will be set automatically when you call
11814 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11815 * reason to use this function would be to unset an explicit expand
11818 * If hexpand is set, then it overrides any computed
11819 * expand value based on child widgets. If hexpand is not
11820 * set, then the expand value depends on whether any
11821 * children of the widget would like to expand.
11823 * There are few reasons to use this function, but it's here
11824 * for completeness and consistency.
11827 gtk_widget_set_hexpand_set (GtkWidget *widget,
11830 g_return_if_fail (GTK_IS_WIDGET (widget));
11832 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11837 * gtk_widget_get_vexpand:
11838 * @widget: the widget
11840 * Gets whether the widget would like any available extra vertical
11843 * See gtk_widget_get_hexpand() for more detail.
11845 * Return value: whether vexpand flag is set
11848 gtk_widget_get_vexpand (GtkWidget *widget)
11850 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11852 return widget->priv->vexpand;
11856 * gtk_widget_set_vexpand:
11857 * @widget: the widget
11858 * @expand: whether to expand
11860 * Sets whether the widget would like any available extra vertical
11863 * See gtk_widget_set_hexpand() for more detail.
11866 gtk_widget_set_vexpand (GtkWidget *widget,
11869 g_return_if_fail (GTK_IS_WIDGET (widget));
11871 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11875 * gtk_widget_get_vexpand_set:
11876 * @widget: the widget
11878 * Gets whether gtk_widget_set_vexpand() has been used to
11879 * explicitly set the expand flag on this widget.
11881 * See gtk_widget_get_hexpand_set() for more detail.
11883 * Return value: whether vexpand has been explicitly set
11886 gtk_widget_get_vexpand_set (GtkWidget *widget)
11888 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11890 return widget->priv->vexpand_set;
11894 * gtk_widget_set_vexpand_set:
11895 * @widget: the widget
11896 * @set: value for vexpand-set property
11898 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11901 * See gtk_widget_set_hexpand_set() for more detail.
11904 gtk_widget_set_vexpand_set (GtkWidget *widget,
11907 g_return_if_fail (GTK_IS_WIDGET (widget));
11909 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11913 * GtkBuildable implementation
11915 static GQuark quark_builder_has_default = 0;
11916 static GQuark quark_builder_has_focus = 0;
11917 static GQuark quark_builder_atk_relations = 0;
11918 static GQuark quark_builder_set_name = 0;
11921 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11923 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11924 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11925 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11926 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11928 iface->set_name = gtk_widget_buildable_set_name;
11929 iface->get_name = gtk_widget_buildable_get_name;
11930 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11931 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11932 iface->parser_finished = gtk_widget_buildable_parser_finished;
11933 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11934 iface->custom_finished = gtk_widget_buildable_custom_finished;
11938 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11941 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11942 g_strdup (name), g_free);
11945 static const gchar *
11946 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11948 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11952 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11953 GtkBuilder *builder,
11954 const gchar *childname)
11956 if (strcmp (childname, "accessible") == 0)
11957 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11963 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11964 GtkBuilder *builder,
11966 const GValue *value)
11968 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11969 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11970 GINT_TO_POINTER (TRUE));
11971 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11972 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11973 GINT_TO_POINTER (TRUE));
11975 g_object_set_property (G_OBJECT (buildable), name, value);
11980 gchar *action_name;
11981 GString *description;
11983 gboolean translatable;
11993 free_action (AtkActionData *data, gpointer user_data)
11995 g_free (data->action_name);
11996 g_string_free (data->description, TRUE);
11997 g_free (data->context);
11998 g_slice_free (AtkActionData, data);
12002 free_relation (AtkRelationData *data, gpointer user_data)
12004 g_free (data->target);
12005 g_free (data->type);
12006 g_slice_free (AtkRelationData, data);
12010 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12011 GtkBuilder *builder)
12013 GSList *atk_relations;
12015 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12016 gtk_widget_grab_default (GTK_WIDGET (buildable));
12017 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12018 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12020 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12021 quark_builder_atk_relations);
12024 AtkObject *accessible;
12025 AtkRelationSet *relation_set;
12028 AtkRelationType relation_type;
12029 AtkObject *target_accessible;
12031 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12032 relation_set = atk_object_ref_relation_set (accessible);
12034 for (l = atk_relations; l; l = l->next)
12036 AtkRelationData *relation = (AtkRelationData*)l->data;
12038 target = gtk_builder_get_object (builder, relation->target);
12041 g_warning ("Target object %s in <relation> does not exist",
12045 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12046 g_assert (target_accessible != NULL);
12048 relation_type = atk_relation_type_for_name (relation->type);
12049 if (relation_type == ATK_RELATION_NULL)
12051 g_warning ("<relation> type %s not found",
12055 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12056 target_accessible);
12058 g_object_unref (relation_set);
12060 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12061 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12070 } AccessibilitySubParserData;
12073 accessibility_start_element (GMarkupParseContext *context,
12074 const gchar *element_name,
12075 const gchar **names,
12076 const gchar **values,
12077 gpointer user_data,
12080 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12082 gint line_number, char_number;
12084 if (strcmp (element_name, "relation") == 0)
12086 gchar *target = NULL;
12087 gchar *type = NULL;
12088 AtkRelationData *relation;
12090 for (i = 0; names[i]; i++)
12092 if (strcmp (names[i], "target") == 0)
12093 target = g_strdup (values[i]);
12094 else if (strcmp (names[i], "type") == 0)
12095 type = g_strdup (values[i]);
12098 g_markup_parse_context_get_position (context,
12101 g_set_error (error,
12103 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12104 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12106 line_number, char_number, names[i], "relation");
12113 if (!target || !type)
12115 g_markup_parse_context_get_position (context,
12118 g_set_error (error,
12120 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12121 "%s:%d:%d <%s> requires attribute \"%s\"",
12123 line_number, char_number, "relation",
12124 type ? "target" : "type");
12130 relation = g_slice_new (AtkRelationData);
12131 relation->target = target;
12132 relation->type = type;
12134 data->relations = g_slist_prepend (data->relations, relation);
12136 else if (strcmp (element_name, "action") == 0)
12138 const gchar *action_name = NULL;
12139 const gchar *description = NULL;
12140 const gchar *msg_context = NULL;
12141 gboolean translatable = FALSE;
12142 AtkActionData *action;
12144 for (i = 0; names[i]; i++)
12146 if (strcmp (names[i], "action_name") == 0)
12147 action_name = values[i];
12148 else if (strcmp (names[i], "description") == 0)
12149 description = values[i];
12150 else if (strcmp (names[i], "translatable") == 0)
12152 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12155 else if (strcmp (names[i], "comments") == 0)
12157 /* do nothing, comments are for translators */
12159 else if (strcmp (names[i], "context") == 0)
12160 msg_context = values[i];
12163 g_markup_parse_context_get_position (context,
12166 g_set_error (error,
12168 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12169 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12171 line_number, char_number, names[i], "action");
12178 g_markup_parse_context_get_position (context,
12181 g_set_error (error,
12183 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12184 "%s:%d:%d <%s> requires attribute \"%s\"",
12186 line_number, char_number, "action",
12191 action = g_slice_new (AtkActionData);
12192 action->action_name = g_strdup (action_name);
12193 action->description = g_string_new (description);
12194 action->context = g_strdup (msg_context);
12195 action->translatable = translatable;
12197 data->actions = g_slist_prepend (data->actions, action);
12199 else if (strcmp (element_name, "accessibility") == 0)
12202 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12206 accessibility_text (GMarkupParseContext *context,
12209 gpointer user_data,
12212 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12214 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12216 AtkActionData *action = data->actions->data;
12218 g_string_append_len (action->description, text, text_len);
12222 static const GMarkupParser accessibility_parser =
12224 accessibility_start_element,
12226 accessibility_text,
12235 } AccelGroupParserData;
12238 accel_group_start_element (GMarkupParseContext *context,
12239 const gchar *element_name,
12240 const gchar **names,
12241 const gchar **values,
12242 gpointer user_data,
12247 guint modifiers = 0;
12248 gchar *signal = NULL;
12249 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12251 for (i = 0; names[i]; i++)
12253 if (strcmp (names[i], "key") == 0)
12254 key = gdk_keyval_from_name (values[i]);
12255 else if (strcmp (names[i], "modifiers") == 0)
12257 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12263 else if (strcmp (names[i], "signal") == 0)
12264 signal = g_strdup (values[i]);
12267 if (key == 0 || signal == NULL)
12269 g_warning ("<accelerator> requires key and signal attributes");
12272 parser_data->key = key;
12273 parser_data->modifiers = modifiers;
12274 parser_data->signal = signal;
12277 static const GMarkupParser accel_group_parser =
12279 accel_group_start_element,
12288 style_start_element (GMarkupParseContext *context,
12289 const gchar *element_name,
12290 const gchar **names,
12291 const gchar **values,
12292 gpointer user_data,
12295 StyleParserData *style_data = (StyleParserData *)user_data;
12298 if (strcmp (element_name, "class") == 0)
12300 if (g_markup_collect_attributes (element_name,
12304 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12305 G_MARKUP_COLLECT_INVALID))
12307 style_data->classes = g_slist_append (style_data->classes, class_name);
12310 else if (strcmp (element_name, "style") == 0)
12313 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12316 static const GMarkupParser style_parser =
12318 style_start_element,
12322 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12323 GtkBuilder *builder,
12325 const gchar *tagname,
12326 GMarkupParser *parser,
12329 g_assert (buildable);
12331 if (strcmp (tagname, "accelerator") == 0)
12333 AccelGroupParserData *parser_data;
12335 parser_data = g_slice_new0 (AccelGroupParserData);
12336 parser_data->object = g_object_ref (buildable);
12337 *parser = accel_group_parser;
12338 *data = parser_data;
12341 if (strcmp (tagname, "accessibility") == 0)
12343 AccessibilitySubParserData *parser_data;
12345 parser_data = g_slice_new0 (AccessibilitySubParserData);
12346 *parser = accessibility_parser;
12347 *data = parser_data;
12350 if (strcmp (tagname, "style") == 0)
12352 StyleParserData *parser_data;
12354 parser_data = g_slice_new0 (StyleParserData);
12355 *parser = style_parser;
12356 *data = parser_data;
12364 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12365 GtkWidget *toplevel,
12366 gpointer user_data)
12368 AccelGroupParserData *accel_data;
12369 GSList *accel_groups;
12370 GtkAccelGroup *accel_group;
12372 g_return_if_fail (GTK_IS_WIDGET (widget));
12373 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12374 g_return_if_fail (user_data != NULL);
12376 accel_data = (AccelGroupParserData*)user_data;
12377 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12378 if (g_slist_length (accel_groups) == 0)
12380 accel_group = gtk_accel_group_new ();
12381 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12385 g_assert (g_slist_length (accel_groups) == 1);
12386 accel_group = g_slist_nth_data (accel_groups, 0);
12389 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12390 accel_data->signal,
12393 accel_data->modifiers,
12394 GTK_ACCEL_VISIBLE);
12396 g_object_unref (accel_data->object);
12397 g_free (accel_data->signal);
12398 g_slice_free (AccelGroupParserData, accel_data);
12402 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12403 GtkBuilder *builder,
12405 const gchar *tagname,
12406 gpointer user_data)
12408 if (strcmp (tagname, "accelerator") == 0)
12410 AccelGroupParserData *accel_data;
12411 GtkWidget *toplevel;
12413 accel_data = (AccelGroupParserData*)user_data;
12414 g_assert (accel_data->object);
12416 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12418 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12420 else if (strcmp (tagname, "accessibility") == 0)
12422 AccessibilitySubParserData *a11y_data;
12424 a11y_data = (AccessibilitySubParserData*)user_data;
12426 if (a11y_data->actions)
12428 AtkObject *accessible;
12433 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12435 if (ATK_IS_ACTION (accessible))
12437 action = ATK_ACTION (accessible);
12438 n_actions = atk_action_get_n_actions (action);
12440 for (l = a11y_data->actions; l; l = l->next)
12442 AtkActionData *action_data = (AtkActionData*)l->data;
12444 for (i = 0; i < n_actions; i++)
12445 if (strcmp (atk_action_get_name (action, i),
12446 action_data->action_name) == 0)
12451 gchar *description;
12453 if (action_data->translatable && action_data->description->len)
12454 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12455 action_data->context,
12456 action_data->description->str);
12458 description = action_data->description->str;
12460 atk_action_set_description (action, i, description);
12465 g_warning ("accessibility action on a widget that does not implement AtkAction");
12467 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12470 if (a11y_data->relations)
12471 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12472 a11y_data->relations);
12474 g_slice_free (AccessibilitySubParserData, a11y_data);
12476 else if (strcmp (tagname, "style") == 0)
12478 StyleParserData *style_data = (StyleParserData *)user_data;
12479 GtkStyleContext *context;
12482 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12484 for (l = style_data->classes; l; l = l->next)
12485 gtk_style_context_add_class (context, (const gchar *)l->data);
12487 gtk_widget_reset_style (GTK_WIDGET (buildable));
12489 g_slist_free_full (style_data->classes, g_free);
12490 g_slice_free (StyleParserData, style_data);
12494 static GtkSizeRequestMode
12495 gtk_widget_real_get_request_mode (GtkWidget *widget)
12497 /* By default widgets dont trade size at all. */
12498 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12502 gtk_widget_real_get_width (GtkWidget *widget,
12503 gint *minimum_size,
12504 gint *natural_size)
12514 gtk_widget_real_get_height (GtkWidget *widget,
12515 gint *minimum_size,
12516 gint *natural_size)
12526 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12528 gint *minimum_height,
12529 gint *natural_height)
12531 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12535 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12537 gint *minimum_width,
12538 gint *natural_width)
12540 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12544 * gtk_widget_get_halign:
12545 * @widget: a #GtkWidget
12547 * Gets the value of the #GtkWidget:halign property.
12549 * Returns: the horizontal alignment of @widget
12552 gtk_widget_get_halign (GtkWidget *widget)
12554 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12555 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12559 * gtk_widget_set_halign:
12560 * @widget: a #GtkWidget
12561 * @align: the horizontal alignment
12563 * Sets the horizontal alignment of @widget.
12564 * See the #GtkWidget:halign property.
12567 gtk_widget_set_halign (GtkWidget *widget,
12570 GtkWidgetAuxInfo *aux_info;
12572 g_return_if_fail (GTK_IS_WIDGET (widget));
12574 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12576 if (aux_info->halign == align)
12579 aux_info->halign = align;
12580 gtk_widget_queue_resize (widget);
12581 g_object_notify (G_OBJECT (widget), "halign");
12585 * gtk_widget_get_valign:
12586 * @widget: a #GtkWidget
12588 * Gets the value of the #GtkWidget:valign property.
12590 * Returns: the vertical alignment of @widget
12593 gtk_widget_get_valign (GtkWidget *widget)
12595 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12596 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12600 * gtk_widget_set_valign:
12601 * @widget: a #GtkWidget
12602 * @align: the vertical alignment
12604 * Sets the vertical alignment of @widget.
12605 * See the #GtkWidget:valign property.
12608 gtk_widget_set_valign (GtkWidget *widget,
12611 GtkWidgetAuxInfo *aux_info;
12613 g_return_if_fail (GTK_IS_WIDGET (widget));
12615 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12617 if (aux_info->valign == align)
12620 aux_info->valign = align;
12621 gtk_widget_queue_resize (widget);
12622 g_object_notify (G_OBJECT (widget), "valign");
12626 * gtk_widget_get_margin_left:
12627 * @widget: a #GtkWidget
12629 * Gets the value of the #GtkWidget:margin-left property.
12631 * Returns: The left margin of @widget
12636 gtk_widget_get_margin_left (GtkWidget *widget)
12638 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12640 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12644 * gtk_widget_set_margin_left:
12645 * @widget: a #GtkWidget
12646 * @margin: the left margin
12648 * Sets the left margin of @widget.
12649 * See the #GtkWidget:margin-left property.
12654 gtk_widget_set_margin_left (GtkWidget *widget,
12657 GtkWidgetAuxInfo *aux_info;
12659 g_return_if_fail (GTK_IS_WIDGET (widget));
12660 g_return_if_fail (margin <= G_MAXINT16);
12662 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12664 if (aux_info->margin.left == margin)
12667 aux_info->margin.left = margin;
12668 gtk_widget_queue_resize (widget);
12669 g_object_notify (G_OBJECT (widget), "margin-left");
12673 * gtk_widget_get_margin_right:
12674 * @widget: a #GtkWidget
12676 * Gets the value of the #GtkWidget:margin-right property.
12678 * Returns: The right margin of @widget
12683 gtk_widget_get_margin_right (GtkWidget *widget)
12685 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12687 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12691 * gtk_widget_set_margin_right:
12692 * @widget: a #GtkWidget
12693 * @margin: the right margin
12695 * Sets the right margin of @widget.
12696 * See the #GtkWidget:margin-right property.
12701 gtk_widget_set_margin_right (GtkWidget *widget,
12704 GtkWidgetAuxInfo *aux_info;
12706 g_return_if_fail (GTK_IS_WIDGET (widget));
12707 g_return_if_fail (margin <= G_MAXINT16);
12709 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12711 if (aux_info->margin.right == margin)
12714 aux_info->margin.right = margin;
12715 gtk_widget_queue_resize (widget);
12716 g_object_notify (G_OBJECT (widget), "margin-right");
12720 * gtk_widget_get_margin_top:
12721 * @widget: a #GtkWidget
12723 * Gets the value of the #GtkWidget:margin-top property.
12725 * Returns: The top margin of @widget
12730 gtk_widget_get_margin_top (GtkWidget *widget)
12732 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12734 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12738 * gtk_widget_set_margin_top:
12739 * @widget: a #GtkWidget
12740 * @margin: the top margin
12742 * Sets the top margin of @widget.
12743 * See the #GtkWidget:margin-top property.
12748 gtk_widget_set_margin_top (GtkWidget *widget,
12751 GtkWidgetAuxInfo *aux_info;
12753 g_return_if_fail (GTK_IS_WIDGET (widget));
12754 g_return_if_fail (margin <= G_MAXINT16);
12756 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12758 if (aux_info->margin.top == margin)
12761 aux_info->margin.top = margin;
12762 gtk_widget_queue_resize (widget);
12763 g_object_notify (G_OBJECT (widget), "margin-top");
12767 * gtk_widget_get_margin_bottom:
12768 * @widget: a #GtkWidget
12770 * Gets the value of the #GtkWidget:margin-bottom property.
12772 * Returns: The bottom margin of @widget
12777 gtk_widget_get_margin_bottom (GtkWidget *widget)
12779 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12781 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12785 * gtk_widget_set_margin_bottom:
12786 * @widget: a #GtkWidget
12787 * @margin: the bottom margin
12789 * Sets the bottom margin of @widget.
12790 * See the #GtkWidget:margin-bottom property.
12795 gtk_widget_set_margin_bottom (GtkWidget *widget,
12798 GtkWidgetAuxInfo *aux_info;
12800 g_return_if_fail (GTK_IS_WIDGET (widget));
12801 g_return_if_fail (margin <= G_MAXINT16);
12803 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12805 if (aux_info->margin.bottom == margin)
12808 aux_info->margin.bottom = margin;
12809 gtk_widget_queue_resize (widget);
12810 g_object_notify (G_OBJECT (widget), "margin-bottom");
12814 * gtk_widget_get_clipboard:
12815 * @widget: a #GtkWidget
12816 * @selection: a #GdkAtom which identifies the clipboard
12817 * to use. %GDK_SELECTION_CLIPBOARD gives the
12818 * default clipboard. Another common value
12819 * is %GDK_SELECTION_PRIMARY, which gives
12820 * the primary X selection.
12822 * Returns the clipboard object for the given selection to
12823 * be used with @widget. @widget must have a #GdkDisplay
12824 * associated with it, so must be attached to a toplevel
12827 * Return value: (transfer none): the appropriate clipboard object. If no
12828 * clipboard already exists, a new one will
12829 * be created. Once a clipboard object has
12830 * been created, it is persistent for all time.
12835 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12837 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12838 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12840 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12845 * gtk_widget_list_mnemonic_labels:
12846 * @widget: a #GtkWidget
12848 * Returns a newly allocated list of the widgets, normally labels, for
12849 * which this widget is the target of a mnemonic (see for example,
12850 * gtk_label_set_mnemonic_widget()).
12852 * The widgets in the list are not individually referenced. If you
12853 * want to iterate through the list and perform actions involving
12854 * callbacks that might destroy the widgets, you
12855 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12856 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12857 * widgets afterwards.
12859 * Return value: (element-type GtkWidget) (transfer container): the list of
12860 * mnemonic labels; free this list
12861 * with g_list_free() when you are done with it.
12866 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12868 GList *list = NULL;
12871 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12873 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12874 list = g_list_prepend (list, l->data);
12880 * gtk_widget_add_mnemonic_label:
12881 * @widget: a #GtkWidget
12882 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12884 * Adds a widget to the list of mnemonic labels for
12885 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12886 * list of mnemonic labels for the widget is cleared when the
12887 * widget is destroyed, so the caller must make sure to update
12888 * its internal state at this point as well, by using a connection
12889 * to the #GtkWidget::destroy signal or a weak notifier.
12894 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12897 GSList *old_list, *new_list;
12899 g_return_if_fail (GTK_IS_WIDGET (widget));
12900 g_return_if_fail (GTK_IS_WIDGET (label));
12902 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12903 new_list = g_slist_prepend (old_list, label);
12905 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12906 new_list, (GDestroyNotify) g_slist_free);
12910 * gtk_widget_remove_mnemonic_label:
12911 * @widget: a #GtkWidget
12912 * @label: a #GtkWidget that was previously set as a mnemnic label for
12913 * @widget with gtk_widget_add_mnemonic_label().
12915 * Removes a widget from the list of mnemonic labels for
12916 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12917 * must have previously been added to the list with
12918 * gtk_widget_add_mnemonic_label().
12923 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12926 GSList *old_list, *new_list;
12928 g_return_if_fail (GTK_IS_WIDGET (widget));
12929 g_return_if_fail (GTK_IS_WIDGET (label));
12931 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12932 new_list = g_slist_remove (old_list, label);
12935 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12936 new_list, (GDestroyNotify) g_slist_free);
12940 * gtk_widget_get_no_show_all:
12941 * @widget: a #GtkWidget
12943 * Returns the current value of the #GtkWidget:no-show-all property,
12944 * which determines whether calls to gtk_widget_show_all()
12945 * will affect this widget.
12947 * Return value: the current value of the "no-show-all" property.
12952 gtk_widget_get_no_show_all (GtkWidget *widget)
12954 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12956 return widget->priv->no_show_all;
12960 * gtk_widget_set_no_show_all:
12961 * @widget: a #GtkWidget
12962 * @no_show_all: the new value for the "no-show-all" property
12964 * Sets the #GtkWidget:no-show-all property, which determines whether
12965 * calls to gtk_widget_show_all() will affect this widget.
12967 * This is mostly for use in constructing widget hierarchies with externally
12968 * controlled visibility, see #GtkUIManager.
12973 gtk_widget_set_no_show_all (GtkWidget *widget,
12974 gboolean no_show_all)
12976 g_return_if_fail (GTK_IS_WIDGET (widget));
12978 no_show_all = (no_show_all != FALSE);
12980 if (widget->priv->no_show_all != no_show_all)
12982 widget->priv->no_show_all = no_show_all;
12984 g_object_notify (G_OBJECT (widget), "no-show-all");
12990 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12991 gboolean has_tooltip,
12994 GtkWidgetPrivate *priv = widget->priv;
12995 gboolean priv_has_tooltip;
12997 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12998 quark_has_tooltip));
13000 if (priv_has_tooltip != has_tooltip || force)
13002 priv_has_tooltip = has_tooltip;
13004 if (priv_has_tooltip)
13006 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13007 gdk_window_set_events (priv->window,
13008 gdk_window_get_events (priv->window) |
13009 GDK_LEAVE_NOTIFY_MASK |
13010 GDK_POINTER_MOTION_MASK |
13011 GDK_POINTER_MOTION_HINT_MASK);
13013 if (gtk_widget_get_has_window (widget))
13014 gtk_widget_add_events (widget,
13015 GDK_LEAVE_NOTIFY_MASK |
13016 GDK_POINTER_MOTION_MASK |
13017 GDK_POINTER_MOTION_HINT_MASK);
13020 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13021 GUINT_TO_POINTER (priv_has_tooltip));
13026 * gtk_widget_set_tooltip_window:
13027 * @widget: a #GtkWidget
13028 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13030 * Replaces the default, usually yellow, window used for displaying
13031 * tooltips with @custom_window. GTK+ will take care of showing and
13032 * hiding @custom_window at the right moment, to behave likewise as
13033 * the default tooltip window. If @custom_window is %NULL, the default
13034 * tooltip window will be used.
13036 * If the custom window should have the default theming it needs to
13037 * have the name "gtk-tooltip", see gtk_widget_set_name().
13042 gtk_widget_set_tooltip_window (GtkWidget *widget,
13043 GtkWindow *custom_window)
13045 gboolean has_tooltip;
13046 gchar *tooltip_markup;
13048 g_return_if_fail (GTK_IS_WIDGET (widget));
13049 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13051 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13054 g_object_ref (custom_window);
13056 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13057 custom_window, g_object_unref);
13059 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13060 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13062 if (has_tooltip && gtk_widget_get_visible (widget))
13063 gtk_widget_queue_tooltip_query (widget);
13067 * gtk_widget_get_tooltip_window:
13068 * @widget: a #GtkWidget
13070 * Returns the #GtkWindow of the current tooltip. This can be the
13071 * GtkWindow created by default, or the custom tooltip window set
13072 * using gtk_widget_set_tooltip_window().
13074 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13079 gtk_widget_get_tooltip_window (GtkWidget *widget)
13081 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13083 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13087 * gtk_widget_trigger_tooltip_query:
13088 * @widget: a #GtkWidget
13090 * Triggers a tooltip query on the display where the toplevel of @widget
13091 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13097 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13099 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13102 static guint tooltip_query_id;
13103 static GSList *tooltip_query_displays;
13106 tooltip_query_idle (gpointer data)
13108 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13109 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13110 g_slist_free (tooltip_query_displays);
13112 tooltip_query_displays = NULL;
13113 tooltip_query_id = 0;
13119 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13121 GdkDisplay *display;
13123 display = gtk_widget_get_display (widget);
13125 if (!g_slist_find (tooltip_query_displays, display))
13126 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13128 if (tooltip_query_id == 0)
13129 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13133 * gtk_widget_set_tooltip_text:
13134 * @widget: a #GtkWidget
13135 * @text: the contents of the tooltip for @widget
13137 * Sets @text as the contents of the tooltip. This function will take
13138 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13139 * handler for the #GtkWidget::query-tooltip signal.
13141 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13146 gtk_widget_set_tooltip_text (GtkWidget *widget,
13149 g_return_if_fail (GTK_IS_WIDGET (widget));
13151 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13155 * gtk_widget_get_tooltip_text:
13156 * @widget: a #GtkWidget
13158 * Gets the contents of the tooltip for @widget.
13160 * Return value: the tooltip text, or %NULL. You should free the
13161 * returned string with g_free() when done.
13166 gtk_widget_get_tooltip_text (GtkWidget *widget)
13168 gchar *text = NULL;
13170 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13172 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13178 * gtk_widget_set_tooltip_markup:
13179 * @widget: a #GtkWidget
13180 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13182 * Sets @markup as the contents of the tooltip, which is marked up with
13183 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13185 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13186 * and of the default handler for the #GtkWidget::query-tooltip signal.
13188 * See also the #GtkWidget:tooltip-markup property and
13189 * gtk_tooltip_set_markup().
13194 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13195 const gchar *markup)
13197 g_return_if_fail (GTK_IS_WIDGET (widget));
13199 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13203 * gtk_widget_get_tooltip_markup:
13204 * @widget: a #GtkWidget
13206 * Gets the contents of the tooltip for @widget.
13208 * Return value: the tooltip text, or %NULL. You should free the
13209 * returned string with g_free() when done.
13214 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13216 gchar *text = NULL;
13218 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13220 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13226 * gtk_widget_set_has_tooltip:
13227 * @widget: a #GtkWidget
13228 * @has_tooltip: whether or not @widget has a tooltip.
13230 * Sets the has-tooltip property on @widget to @has_tooltip. See
13231 * #GtkWidget:has-tooltip for more information.
13236 gtk_widget_set_has_tooltip (GtkWidget *widget,
13237 gboolean has_tooltip)
13239 g_return_if_fail (GTK_IS_WIDGET (widget));
13241 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13245 * gtk_widget_get_has_tooltip:
13246 * @widget: a #GtkWidget
13248 * Returns the current value of the has-tooltip property. See
13249 * #GtkWidget:has-tooltip for more information.
13251 * Return value: current value of has-tooltip on @widget.
13256 gtk_widget_get_has_tooltip (GtkWidget *widget)
13258 gboolean has_tooltip = FALSE;
13260 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13262 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13264 return has_tooltip;
13268 * gtk_widget_get_allocation:
13269 * @widget: a #GtkWidget
13270 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13272 * Retrieves the widget's allocation.
13274 * Note, when implementing a #GtkContainer: a widget's allocation will
13275 * be its "adjusted" allocation, that is, the widget's parent
13276 * container typically calls gtk_widget_size_allocate() with an
13277 * allocation, and that allocation is then adjusted (to handle margin
13278 * and alignment for example) before assignment to the widget.
13279 * gtk_widget_get_allocation() returns the adjusted allocation that
13280 * was actually assigned to the widget. The adjusted allocation is
13281 * guaranteed to be completely contained within the
13282 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13283 * is guaranteed that its children stay inside the assigned bounds,
13284 * but not that they have exactly the bounds the container assigned.
13285 * There is no way to get the original allocation assigned by
13286 * gtk_widget_size_allocate(), since it isn't stored; if a container
13287 * implementation needs that information it will have to track it itself.
13292 gtk_widget_get_allocation (GtkWidget *widget,
13293 GtkAllocation *allocation)
13295 GtkWidgetPrivate *priv;
13297 g_return_if_fail (GTK_IS_WIDGET (widget));
13298 g_return_if_fail (allocation != NULL);
13300 priv = widget->priv;
13302 *allocation = priv->allocation;
13306 * gtk_widget_set_allocation:
13307 * @widget: a #GtkWidget
13308 * @allocation: a pointer to a #GtkAllocation to copy from
13310 * Sets the widget's allocation. This should not be used
13311 * directly, but from within a widget's size_allocate method.
13313 * The allocation set should be the "adjusted" or actual
13314 * allocation. If you're implementing a #GtkContainer, you want to use
13315 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13316 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13317 * allocation inside gtk_widget_size_allocate() to create an adjusted
13323 gtk_widget_set_allocation (GtkWidget *widget,
13324 const GtkAllocation *allocation)
13326 GtkWidgetPrivate *priv;
13328 g_return_if_fail (GTK_IS_WIDGET (widget));
13329 g_return_if_fail (allocation != NULL);
13331 priv = widget->priv;
13333 priv->allocation = *allocation;
13337 * gtk_widget_get_allocated_width:
13338 * @widget: the widget to query
13340 * Returns the width that has currently been allocated to @widget.
13341 * This function is intended to be used when implementing handlers
13342 * for the #GtkWidget::draw function.
13344 * Returns: the width of the @widget
13347 gtk_widget_get_allocated_width (GtkWidget *widget)
13349 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13351 return widget->priv->allocation.width;
13355 * gtk_widget_get_allocated_height:
13356 * @widget: the widget to query
13358 * Returns the height that has currently been allocated to @widget.
13359 * This function is intended to be used when implementing handlers
13360 * for the #GtkWidget::draw function.
13362 * Returns: the height of the @widget
13365 gtk_widget_get_allocated_height (GtkWidget *widget)
13367 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13369 return widget->priv->allocation.height;
13373 * gtk_widget_get_requisition:
13374 * @widget: a #GtkWidget
13375 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13377 * Retrieves the widget's requisition.
13379 * This function should only be used by widget implementations in
13380 * order to figure whether the widget's requisition has actually
13381 * changed after some internal state change (so that they can call
13382 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13384 * Normally, gtk_widget_size_request() should be used.
13388 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13389 * removed, If you need to cache sizes across requests and allocations,
13390 * add an explicit cache to the widget in question instead.
13393 gtk_widget_get_requisition (GtkWidget *widget,
13394 GtkRequisition *requisition)
13396 g_return_if_fail (GTK_IS_WIDGET (widget));
13397 g_return_if_fail (requisition != NULL);
13399 gtk_widget_get_preferred_size (widget, requisition, NULL);
13403 * gtk_widget_set_window:
13404 * @widget: a #GtkWidget
13405 * @window: (transfer full): a #GdkWindow
13407 * Sets a widget's window. This function should only be used in a
13408 * widget's #GtkWidget::realize implementation. The %window passed is
13409 * usually either new window created with gdk_window_new(), or the
13410 * window of its parent widget as returned by
13411 * gtk_widget_get_parent_window().
13413 * Widgets must indicate whether they will create their own #GdkWindow
13414 * by calling gtk_widget_set_has_window(). This is usually done in the
13415 * widget's init() function.
13417 * <note><para>This function does not add any reference to @window.</para></note>
13422 gtk_widget_set_window (GtkWidget *widget,
13425 GtkWidgetPrivate *priv;
13427 g_return_if_fail (GTK_IS_WIDGET (widget));
13428 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13430 priv = widget->priv;
13432 if (priv->window != window)
13434 priv->window = window;
13435 g_object_notify (G_OBJECT (widget), "window");
13440 * gtk_widget_get_window:
13441 * @widget: a #GtkWidget
13443 * Returns the widget's window if it is realized, %NULL otherwise
13445 * Return value: (transfer none): @widget's window.
13450 gtk_widget_get_window (GtkWidget *widget)
13452 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13454 return widget->priv->window;
13458 * gtk_widget_get_support_multidevice:
13459 * @widget: a #GtkWidget
13461 * Returns %TRUE if @widget is multiple pointer aware. See
13462 * gtk_widget_set_support_multidevice() for more information.
13464 * Returns: %TRUE if @widget is multidevice aware.
13467 gtk_widget_get_support_multidevice (GtkWidget *widget)
13469 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13471 return widget->priv->multidevice;
13475 * gtk_widget_set_support_multidevice:
13476 * @widget: a #GtkWidget
13477 * @support_multidevice: %TRUE to support input from multiple devices.
13479 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13480 * @widget will start receiving multiple, per device enter/leave events. Note
13481 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13482 * gdk_window_set_support_multidevice() will have to be called manually on them.
13487 gtk_widget_set_support_multidevice (GtkWidget *widget,
13488 gboolean support_multidevice)
13490 GtkWidgetPrivate *priv;
13492 g_return_if_fail (GTK_IS_WIDGET (widget));
13494 priv = widget->priv;
13495 priv->multidevice = (support_multidevice == TRUE);
13497 if (gtk_widget_get_realized (widget))
13498 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13502 _gtk_widget_set_has_focus (GtkWidget *widget,
13503 gboolean has_focus)
13505 widget->priv->has_focus = has_focus;
13508 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13510 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13514 * gtk_widget_send_focus_change:
13515 * @widget: a #GtkWidget
13516 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13518 * Sends the focus change @event to @widget
13520 * This function is not meant to be used by applications. The only time it
13521 * should be used is when it is necessary for a #GtkWidget to assign focus
13522 * to a widget that is semantically owned by the first widget even though
13523 * it's not a direct child - for instance, a search entry in a floating
13524 * window similar to the quick search in #GtkTreeView.
13526 * An example of its usage is:
13529 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13531 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13532 * fevent->focus_change.in = TRUE;
13533 * fevent->focus_change.window = gtk_widget_get_window (widget);
13534 * if (fevent->focus_change.window != NULL)
13535 * g_object_ref (fevent->focus_change.window);
13537 * gtk_widget_send_focus_change (widget, fevent);
13539 * gdk_event_free (event);
13542 * Return value: the return value from the event signal emission: %TRUE
13543 * if the event was handled, and %FALSE otherwise
13548 gtk_widget_send_focus_change (GtkWidget *widget,
13553 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13554 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13556 g_object_ref (widget);
13558 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13560 res = gtk_widget_event (widget, event);
13562 g_object_notify (G_OBJECT (widget), "has-focus");
13564 g_object_unref (widget);
13570 * gtk_widget_in_destruction:
13571 * @widget: a #GtkWidget
13573 * Returns whether the widget is currently being destroyed.
13574 * This information can sometimes be used to avoid doing
13575 * unnecessary work.
13577 * Returns: %TRUE if @widget is being destroyed
13580 gtk_widget_in_destruction (GtkWidget *widget)
13582 return widget->priv->in_destruction;
13586 _gtk_widget_get_resize_pending (GtkWidget *widget)
13588 return widget->priv->resize_pending;
13592 _gtk_widget_set_resize_pending (GtkWidget *widget,
13593 gboolean resize_pending)
13595 widget->priv->resize_pending = resize_pending;
13599 _gtk_widget_get_in_reparent (GtkWidget *widget)
13601 return widget->priv->in_reparent;
13605 _gtk_widget_set_in_reparent (GtkWidget *widget,
13606 gboolean in_reparent)
13608 widget->priv->in_reparent = in_reparent;
13612 _gtk_widget_get_anchored (GtkWidget *widget)
13614 return widget->priv->anchored;
13618 _gtk_widget_set_anchored (GtkWidget *widget,
13621 widget->priv->anchored = anchored;
13625 _gtk_widget_get_shadowed (GtkWidget *widget)
13627 return widget->priv->shadowed;
13631 _gtk_widget_set_shadowed (GtkWidget *widget,
13634 widget->priv->shadowed = shadowed;
13638 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13640 return widget->priv->alloc_needed;
13644 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13645 gboolean alloc_needed)
13647 widget->priv->alloc_needed = alloc_needed;
13651 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13653 return widget->priv->width_request_needed;
13657 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13658 gboolean width_request_needed)
13660 widget->priv->width_request_needed = width_request_needed;
13664 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13666 return widget->priv->height_request_needed;
13670 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13671 gboolean height_request_needed)
13673 widget->priv->height_request_needed = height_request_needed;
13677 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13679 return widget->priv->sizegroup_visited;
13683 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13686 widget->priv->sizegroup_visited = visited;
13690 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13692 return widget->priv->sizegroup_bumping;
13696 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13699 widget->priv->sizegroup_bumping = bumping;
13703 _gtk_widget_add_sizegroup (GtkWidget *widget,
13708 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13709 groups = g_slist_prepend (groups, group);
13710 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13712 widget->priv->have_size_groups = TRUE;
13716 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13721 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13722 groups = g_slist_remove (groups, group);
13723 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13725 widget->priv->have_size_groups = groups != NULL;
13729 _gtk_widget_get_sizegroups (GtkWidget *widget)
13731 if (widget->priv->have_size_groups)
13732 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13738 _gtk_widget_add_attached_window (GtkWidget *widget,
13741 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13745 _gtk_widget_remove_attached_window (GtkWidget *widget,
13748 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13752 * gtk_widget_path_append_for_widget:
13753 * @path: a widget path
13754 * @widget: the widget to append to the widget path
13756 * Appends the data from @widget to the widget hierarchy represented
13757 * by @path. This function is a shortcut for adding information from
13758 * @widget to the given @path. This includes setting the name or
13759 * adding the style classes from @widget.
13761 * Returns: the position where the data was inserted
13766 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13771 g_return_val_if_fail (path != NULL, 0);
13772 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13774 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13776 if (widget->priv->name)
13777 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13779 if (widget->priv->context)
13781 GList *classes, *l;
13783 /* Also add any persistent classes in
13784 * the style context the widget path
13786 classes = gtk_style_context_list_classes (widget->priv->context);
13788 for (l = classes; l; l = l->next)
13789 gtk_widget_path_iter_add_class (path, pos, l->data);
13791 g_list_free (classes);
13798 * gtk_widget_get_path:
13799 * @widget: a #GtkWidget
13801 * Returns the #GtkWidgetPath representing @widget, if the widget
13802 * is not connected to a toplevel widget, a partial path will be
13805 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13808 gtk_widget_get_path (GtkWidget *widget)
13810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13812 /* As strange as it may seem, this may happen on object construction.
13813 * init() implementations of parent types may eventually call this function,
13814 * each with its corresponding GType, which could leave a child
13815 * implementation with a wrong widget type in the widget path
13817 if (widget->priv->path &&
13818 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13820 gtk_widget_path_free (widget->priv->path);
13821 widget->priv->path = NULL;
13824 if (!widget->priv->path)
13828 parent = widget->priv->parent;
13831 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13834 /* Widget is either toplevel or unparented, treat both
13835 * as toplevels style wise, since there are situations
13836 * where style properties might be retrieved on that
13839 GtkWidget *attach_widget = NULL;
13841 if (GTK_IS_WINDOW (widget))
13842 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13844 if (attach_widget != NULL)
13845 widget->priv->path = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13847 widget->priv->path = gtk_widget_path_new ();
13849 gtk_widget_path_append_for_widget (widget->priv->path, widget);
13852 if (widget->priv->context)
13853 gtk_style_context_set_path (widget->priv->context,
13854 widget->priv->path);
13857 return widget->priv->path;
13861 style_context_changed (GtkStyleContext *context,
13862 gpointer user_data)
13864 GtkWidget *widget = user_data;
13866 if (gtk_widget_get_realized (widget))
13867 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13870 /* Compress all style updates so it
13871 * is only emitted once pre-realize.
13873 widget->priv->style_update_pending = TRUE;
13876 if (widget->priv->anchored)
13877 gtk_widget_queue_resize (widget);
13881 * gtk_widget_get_style_context:
13882 * @widget: a #GtkWidget
13884 * Returns the style context associated to @widget.
13886 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13887 * must not be freed.
13890 gtk_widget_get_style_context (GtkWidget *widget)
13892 GtkWidgetPrivate *priv;
13893 GtkWidgetPath *path;
13895 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13897 priv = widget->priv;
13899 /* updates style context if it exists already */
13900 path = gtk_widget_get_path (widget);
13902 if (G_UNLIKELY (priv->context == NULL))
13906 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13907 "direction", gtk_widget_get_direction (widget),
13910 g_signal_connect (widget->priv->context, "changed",
13911 G_CALLBACK (style_context_changed), widget);
13913 screen = gtk_widget_get_screen (widget);
13916 gtk_style_context_set_screen (priv->context, screen);
13918 gtk_style_context_set_path (priv->context, path);
13920 gtk_style_context_set_parent (priv->context,
13921 gtk_widget_get_style_context (priv->parent));
13924 return widget->priv->context;
13928 * gtk_widget_get_modifier_mask:
13929 * @widget: a #GtkWidget
13930 * @intent: the use case for the modifier mask
13932 * Returns the modifier mask the @widget's windowing system backend
13933 * uses for a particular purpose.
13935 * See gdk_keymap_get_modifier_mask().
13937 * Returns: the modifier mask used for @intent.
13942 gtk_widget_get_modifier_mask (GtkWidget *widget,
13943 GdkModifierIntent intent)
13945 GdkDisplay *display;
13947 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13949 display = gtk_widget_get_display (widget);
13951 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
13956 _gtk_widget_get_style (GtkWidget *widget)
13958 return widget->priv->style;
13962 _gtk_widget_set_style (GtkWidget *widget,
13965 widget->priv->style = style;