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 "gtksizerequestcacheprivate.h"
45 #include "gtkwidget.h"
46 #include "gtkwidgetprivate.h"
47 #include "gtkwindowprivate.h"
48 #include "gtkcontainerprivate.h"
49 #include "gtkbindings.h"
50 #include "gtkprivate.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
56 #include "gtksizerequest.h"
57 #include "gtkstylecontextprivate.h"
58 #include "gtksymboliccolor.h"
59 #include "gtkcssprovider.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 alloc_needed : 1;
347 guint width_request_needed : 1;
348 guint height_request_needed : 1;
350 /* Expand-related flags */
351 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
352 guint computed_hexpand : 1; /* computed results (composite of child flags) */
353 guint computed_vexpand : 1;
354 guint hexpand : 1; /* application-forced expand */
356 guint hexpand_set : 1; /* whether to use application-forced */
357 guint vexpand_set : 1; /* instead of computing from children */
359 /* SizeGroup related flags */
360 guint have_size_groups : 1;
362 /* The widget's name. If the widget does not have a name
363 * (the name is NULL), then its name (as returned by
364 * "gtk_widget_get_name") is its class's name.
365 * Among other things, the widget name is used to determine
366 * the style to use for a widget.
370 /* The list of attached windows to this widget.
371 * We keep a list in order to call reset_style to all of them,
373 GList *attached_windows;
375 /* The style for the widget. The style contains the
376 * colors the widget should be drawn in for each state
377 * along with graphics contexts used to draw with and
378 * the font to use for text.
381 GtkStyleContext *context;
383 /* Widget's path for styling */
386 /* The widget's allocated size */
387 GtkAllocation allocation;
389 /* The widget's requested sizes */
390 SizeRequestCache requests;
392 /* actions attached to this or any parent widget */
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_constructed (GObject *object);
555 static void gtk_widget_dispose (GObject *object);
556 static void gtk_widget_real_destroy (GtkWidget *object);
557 static void gtk_widget_finalize (GObject *object);
558 static void gtk_widget_real_show (GtkWidget *widget);
559 static void gtk_widget_real_hide (GtkWidget *widget);
560 static void gtk_widget_real_map (GtkWidget *widget);
561 static void gtk_widget_real_unmap (GtkWidget *widget);
562 static void gtk_widget_real_realize (GtkWidget *widget);
563 static void gtk_widget_real_unrealize (GtkWidget *widget);
564 static void gtk_widget_real_size_allocate (GtkWidget *widget,
565 GtkAllocation *allocation);
566 static void gtk_widget_real_style_set (GtkWidget *widget,
567 GtkStyle *previous_style);
568 static void gtk_widget_real_direction_changed(GtkWidget *widget,
569 GtkTextDirection previous_direction);
571 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
572 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
575 gboolean keyboard_tip,
576 GtkTooltip *tooltip);
577 static void gtk_widget_real_style_updated (GtkWidget *widget);
578 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
579 GtkWidgetHelpType help_type);
581 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
583 GParamSpec **pspecs);
584 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
586 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
588 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
589 GdkEventFocus *event);
590 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
591 GdkEventFocus *event);
592 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
593 GdkEventTouch *event);
594 static gboolean gtk_widget_real_focus (GtkWidget *widget,
595 GtkDirectionType direction);
596 static void gtk_widget_real_move_focus (GtkWidget *widget,
597 GtkDirectionType direction);
598 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
599 GtkDirectionType direction);
600 #ifdef G_ENABLE_DEBUG
601 static void gtk_widget_verify_invariants (GtkWidget *widget);
602 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
603 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
605 #define gtk_widget_verify_invariants(widget)
606 #define gtk_widget_push_verify_invariants(widget)
607 #define gtk_widget_pop_verify_invariants(widget)
609 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
610 static void gtk_widget_update_pango_context (GtkWidget *widget);
611 static void gtk_widget_propagate_state (GtkWidget *widget,
614 static gint gtk_widget_event_internal (GtkWidget *widget,
616 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
617 gboolean group_cycling);
618 static void gtk_widget_real_get_width (GtkWidget *widget,
621 static void gtk_widget_real_get_height (GtkWidget *widget,
624 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
626 gint *minimum_height,
627 gint *natural_height);
628 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
631 gint *natural_width);
632 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
633 GtkStateFlags old_state);
634 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
635 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
637 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
638 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
639 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
640 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
641 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
642 cairo_region_t *region);
643 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
644 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
647 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
648 gboolean has_tooltip,
650 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
651 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
653 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
654 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
656 const gchar *childname);
657 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
660 const GValue *value);
661 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
664 const gchar *tagname,
665 GMarkupParser *parser,
667 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
670 const gchar *tagname,
672 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
673 GtkBuilder *builder);
675 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
676 static void gtk_widget_real_get_width (GtkWidget *widget,
679 static void gtk_widget_real_get_height (GtkWidget *widget,
683 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
686 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
687 GtkOrientation orientation,
690 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
691 GtkOrientation orientation,
695 gint *allocated_size);
697 static void gtk_widget_set_usize_internal (GtkWidget *widget,
700 GtkQueueResizeFlags flags);
702 static void gtk_widget_add_events_internal (GtkWidget *widget,
705 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
709 static gboolean event_window_is_still_viewable (GdkEvent *event);
711 /* --- variables --- */
712 static gpointer gtk_widget_parent_class = NULL;
713 static guint widget_signals[LAST_SIGNAL] = { 0 };
714 static guint composite_child_stack = 0;
715 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
716 static GParamSpecPool *style_property_spec_pool = NULL;
718 static GQuark quark_property_parser = 0;
719 static GQuark quark_aux_info = 0;
720 static GQuark quark_accel_path = 0;
721 static GQuark quark_accel_closures = 0;
722 static GQuark quark_event_mask = 0;
723 static GQuark quark_device_event_mask = 0;
724 static GQuark quark_parent_window = 0;
725 static GQuark quark_pointer_window = 0;
726 static GQuark quark_shape_info = 0;
727 static GQuark quark_input_shape_info = 0;
728 static GQuark quark_pango_context = 0;
729 static GQuark quark_accessible_object = 0;
730 static GQuark quark_mnemonic_labels = 0;
731 static GQuark quark_tooltip_markup = 0;
732 static GQuark quark_has_tooltip = 0;
733 static GQuark quark_tooltip_window = 0;
734 static GQuark quark_visual = 0;
735 static GQuark quark_modifier_style = 0;
736 static GQuark quark_enabled_devices = 0;
737 static GQuark quark_size_groups = 0;
738 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
739 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
741 /* --- functions --- */
743 gtk_widget_get_type (void)
745 static GType widget_type = 0;
747 if (G_UNLIKELY (widget_type == 0))
749 const GTypeInfo widget_info =
751 sizeof (GtkWidgetClass),
752 gtk_widget_base_class_init,
753 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
754 (GClassInitFunc) gtk_widget_class_init,
755 NULL, /* class_finalize */
756 NULL, /* class_init */
759 (GInstanceInitFunc) gtk_widget_init,
760 NULL, /* value_table */
763 const GInterfaceInfo accessibility_info =
765 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
766 (GInterfaceFinalizeFunc) NULL,
767 NULL /* interface data */
770 const GInterfaceInfo buildable_info =
772 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
773 (GInterfaceFinalizeFunc) NULL,
774 NULL /* interface data */
777 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
778 &widget_info, G_TYPE_FLAG_ABSTRACT);
780 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
782 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
783 &accessibility_info) ;
784 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
792 gtk_widget_base_class_init (gpointer g_class)
794 GtkWidgetClass *klass = g_class;
796 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
800 child_property_notify_dispatcher (GObject *object,
804 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
807 /* We guard against the draw signal callbacks modifying the state of the
808 * cairo context by surounding it with save/restore.
809 * Maybe we should also cairo_new_path() just to be sure?
812 gtk_widget_draw_marshaller (GClosure *closure,
813 GValue *return_value,
814 guint n_param_values,
815 const GValue *param_values,
816 gpointer invocation_hint,
817 gpointer marshal_data)
819 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
823 _gtk_marshal_BOOLEAN__BOXED (closure,
834 gtk_widget_draw_marshallerv (GClosure *closure,
835 GValue *return_value,
838 gpointer marshal_data,
845 G_VA_COPY (args_copy, args);
846 cr = va_arg (args_copy, gpointer);
850 _gtk_marshal_BOOLEAN__BOXEDv (closure,
862 gtk_widget_class_init (GtkWidgetClass *klass)
864 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
865 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
866 GtkBindingSet *binding_set;
868 gtk_widget_parent_class = g_type_class_peek_parent (klass);
870 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
871 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
872 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
873 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
874 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
875 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
876 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
877 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
878 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
879 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
880 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
881 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
882 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
883 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
884 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
885 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
886 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
887 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
888 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
889 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
891 style_property_spec_pool = g_param_spec_pool_new (FALSE);
892 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
893 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
894 cpn_context.dispatcher = child_property_notify_dispatcher;
895 _gtk_widget_child_property_notify_context = &cpn_context;
897 gobject_class->constructed = gtk_widget_constructed;
898 gobject_class->dispose = gtk_widget_dispose;
899 gobject_class->finalize = gtk_widget_finalize;
900 gobject_class->set_property = gtk_widget_set_property;
901 gobject_class->get_property = gtk_widget_get_property;
903 klass->destroy = gtk_widget_real_destroy;
905 klass->activate_signal = 0;
906 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
907 klass->show = gtk_widget_real_show;
908 klass->show_all = gtk_widget_show;
909 klass->hide = gtk_widget_real_hide;
910 klass->map = gtk_widget_real_map;
911 klass->unmap = gtk_widget_real_unmap;
912 klass->realize = gtk_widget_real_realize;
913 klass->unrealize = gtk_widget_real_unrealize;
914 klass->size_allocate = gtk_widget_real_size_allocate;
915 klass->get_request_mode = gtk_widget_real_get_request_mode;
916 klass->get_preferred_width = gtk_widget_real_get_width;
917 klass->get_preferred_height = gtk_widget_real_get_height;
918 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
919 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
920 klass->state_changed = NULL;
921 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
922 klass->parent_set = NULL;
923 klass->hierarchy_changed = NULL;
924 klass->style_set = gtk_widget_real_style_set;
925 klass->direction_changed = gtk_widget_real_direction_changed;
926 klass->grab_notify = NULL;
927 klass->child_notify = NULL;
929 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
930 klass->grab_focus = gtk_widget_real_grab_focus;
931 klass->focus = gtk_widget_real_focus;
932 klass->move_focus = gtk_widget_real_move_focus;
933 klass->keynav_failed = gtk_widget_real_keynav_failed;
935 klass->button_press_event = NULL;
936 klass->button_release_event = NULL;
937 klass->motion_notify_event = NULL;
938 klass->touch_event = gtk_widget_real_touch_event;
939 klass->delete_event = NULL;
940 klass->destroy_event = NULL;
941 klass->key_press_event = gtk_widget_real_key_press_event;
942 klass->key_release_event = gtk_widget_real_key_release_event;
943 klass->enter_notify_event = NULL;
944 klass->leave_notify_event = NULL;
945 klass->configure_event = NULL;
946 klass->focus_in_event = gtk_widget_real_focus_in_event;
947 klass->focus_out_event = gtk_widget_real_focus_out_event;
948 klass->map_event = NULL;
949 klass->unmap_event = NULL;
950 klass->window_state_event = NULL;
951 klass->property_notify_event = _gtk_selection_property_notify;
952 klass->selection_clear_event = _gtk_selection_clear;
953 klass->selection_request_event = _gtk_selection_request;
954 klass->selection_notify_event = _gtk_selection_notify;
955 klass->selection_received = NULL;
956 klass->proximity_in_event = NULL;
957 klass->proximity_out_event = NULL;
958 klass->drag_begin = NULL;
959 klass->drag_end = NULL;
960 klass->drag_data_delete = NULL;
961 klass->drag_leave = NULL;
962 klass->drag_motion = NULL;
963 klass->drag_drop = NULL;
964 klass->drag_data_received = NULL;
965 klass->screen_changed = NULL;
966 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
967 klass->grab_broken_event = NULL;
968 klass->query_tooltip = gtk_widget_real_query_tooltip;
969 klass->style_updated = gtk_widget_real_style_updated;
971 klass->show_help = gtk_widget_real_show_help;
973 /* Accessibility support */
974 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
975 klass->priv->accessible_role = ATK_ROLE_INVALID;
976 klass->get_accessible = gtk_widget_real_get_accessible;
978 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
979 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
981 g_object_class_install_property (gobject_class,
983 g_param_spec_string ("name",
985 P_("The name of the widget"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_object ("parent",
992 P_("The parent widget of this widget. Must be a Container widget"),
994 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_int ("width-request",
1000 P_("Override for width request of the widget, or -1 if natural request should be used"),
1004 GTK_PARAM_READWRITE));
1005 g_object_class_install_property (gobject_class,
1006 PROP_HEIGHT_REQUEST,
1007 g_param_spec_int ("height-request",
1008 P_("Height request"),
1009 P_("Override for height request of the widget, or -1 if natural request should be used"),
1013 GTK_PARAM_READWRITE));
1014 g_object_class_install_property (gobject_class,
1016 g_param_spec_boolean ("visible",
1018 P_("Whether the widget is visible"),
1020 GTK_PARAM_READWRITE));
1021 g_object_class_install_property (gobject_class,
1023 g_param_spec_boolean ("sensitive",
1025 P_("Whether the widget responds to input"),
1027 GTK_PARAM_READWRITE));
1028 g_object_class_install_property (gobject_class,
1030 g_param_spec_boolean ("app-paintable",
1031 P_("Application paintable"),
1032 P_("Whether the application will paint directly on the widget"),
1034 GTK_PARAM_READWRITE));
1035 g_object_class_install_property (gobject_class,
1037 g_param_spec_boolean ("can-focus",
1039 P_("Whether the widget can accept the input focus"),
1041 GTK_PARAM_READWRITE));
1042 g_object_class_install_property (gobject_class,
1044 g_param_spec_boolean ("has-focus",
1046 P_("Whether the widget has the input focus"),
1048 GTK_PARAM_READWRITE));
1049 g_object_class_install_property (gobject_class,
1051 g_param_spec_boolean ("is-focus",
1053 P_("Whether the widget is the focus widget within the toplevel"),
1055 GTK_PARAM_READWRITE));
1056 g_object_class_install_property (gobject_class,
1058 g_param_spec_boolean ("can-default",
1060 P_("Whether the widget can be the default widget"),
1062 GTK_PARAM_READWRITE));
1063 g_object_class_install_property (gobject_class,
1065 g_param_spec_boolean ("has-default",
1067 P_("Whether the widget is the default widget"),
1069 GTK_PARAM_READWRITE));
1070 g_object_class_install_property (gobject_class,
1071 PROP_RECEIVES_DEFAULT,
1072 g_param_spec_boolean ("receives-default",
1073 P_("Receives default"),
1074 P_("If TRUE, the widget will receive the default action when it is focused"),
1076 GTK_PARAM_READWRITE));
1077 g_object_class_install_property (gobject_class,
1078 PROP_COMPOSITE_CHILD,
1079 g_param_spec_boolean ("composite-child",
1080 P_("Composite child"),
1081 P_("Whether the widget is part of a composite widget"),
1083 GTK_PARAM_READABLE));
1084 g_object_class_install_property (gobject_class,
1086 g_param_spec_object ("style",
1088 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1090 GTK_PARAM_READWRITE));
1091 g_object_class_install_property (gobject_class,
1093 g_param_spec_flags ("events",
1095 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1096 GDK_TYPE_EVENT_MASK,
1098 GTK_PARAM_READWRITE));
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_boolean ("no-show-all",
1103 P_("Whether gtk_widget_show_all() should not affect this widget"),
1105 GTK_PARAM_READWRITE));
1108 * GtkWidget:has-tooltip:
1110 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1111 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1112 * the widget will be queried using #GtkWidget::query-tooltip to determine
1113 * whether it will provide a tooltip or not.
1115 * Note that setting this property to %TRUE for the first time will change
1116 * the event masks of the GdkWindows of this widget to include leave-notify
1117 * and motion-notify events. This cannot and will not be undone when the
1118 * property is set to %FALSE again.
1122 g_object_class_install_property (gobject_class,
1124 g_param_spec_boolean ("has-tooltip",
1126 P_("Whether this widget has a tooltip"),
1128 GTK_PARAM_READWRITE));
1130 * GtkWidget:tooltip-text:
1132 * Sets the text of tooltip to be the given string.
1134 * Also see gtk_tooltip_set_text().
1136 * This is a convenience property which will take care of getting the
1137 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1138 * will automatically be set to %TRUE and there will be taken care of
1139 * #GtkWidget::query-tooltip in the default signal handler.
1143 g_object_class_install_property (gobject_class,
1145 g_param_spec_string ("tooltip-text",
1147 P_("The contents of the tooltip for this widget"),
1149 GTK_PARAM_READWRITE));
1151 * GtkWidget:tooltip-markup:
1153 * Sets the text of tooltip to be the given string, which is marked up
1154 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1155 * Also see gtk_tooltip_set_markup().
1157 * This is a convenience property which will take care of getting the
1158 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1159 * will automatically be set to %TRUE and there will be taken care of
1160 * #GtkWidget::query-tooltip in the default signal handler.
1164 g_object_class_install_property (gobject_class,
1165 PROP_TOOLTIP_MARKUP,
1166 g_param_spec_string ("tooltip-markup",
1167 P_("Tooltip markup"),
1168 P_("The contents of the tooltip for this widget"),
1170 GTK_PARAM_READWRITE));
1175 * The widget's window if it is realized, %NULL otherwise.
1179 g_object_class_install_property (gobject_class,
1181 g_param_spec_object ("window",
1183 P_("The widget's window if it is realized"),
1185 GTK_PARAM_READABLE));
1188 * GtkWidget:double-buffered:
1190 * Whether the widget is double buffered.
1194 g_object_class_install_property (gobject_class,
1195 PROP_DOUBLE_BUFFERED,
1196 g_param_spec_boolean ("double-buffered",
1197 P_("Double Buffered"),
1198 P_("Whether the widget is double buffered"),
1200 GTK_PARAM_READWRITE));
1205 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1209 g_object_class_install_property (gobject_class,
1211 g_param_spec_enum ("halign",
1212 P_("Horizontal Alignment"),
1213 P_("How to position in extra horizontal space"),
1216 GTK_PARAM_READWRITE));
1221 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1225 g_object_class_install_property (gobject_class,
1227 g_param_spec_enum ("valign",
1228 P_("Vertical Alignment"),
1229 P_("How to position in extra vertical space"),
1232 GTK_PARAM_READWRITE));
1235 * GtkWidget:margin-left:
1237 * Margin on left side of widget.
1239 * This property adds margin outside of the widget's normal size
1240 * request, the margin will be added in addition to the size from
1241 * gtk_widget_set_size_request() for example.
1245 g_object_class_install_property (gobject_class,
1247 g_param_spec_int ("margin-left",
1248 P_("Margin on Left"),
1249 P_("Pixels of extra space on the left side"),
1253 GTK_PARAM_READWRITE));
1256 * GtkWidget:margin-right:
1258 * Margin on right side of widget.
1260 * This property adds margin outside of the widget's normal size
1261 * request, the margin will be added in addition to the size from
1262 * gtk_widget_set_size_request() for example.
1266 g_object_class_install_property (gobject_class,
1268 g_param_spec_int ("margin-right",
1269 P_("Margin on Right"),
1270 P_("Pixels of extra space on the right side"),
1274 GTK_PARAM_READWRITE));
1277 * GtkWidget:margin-top:
1279 * Margin on top side of widget.
1281 * This property adds margin outside of the widget's normal size
1282 * request, the margin will be added in addition to the size from
1283 * gtk_widget_set_size_request() for example.
1287 g_object_class_install_property (gobject_class,
1289 g_param_spec_int ("margin-top",
1290 P_("Margin on Top"),
1291 P_("Pixels of extra space on the top side"),
1295 GTK_PARAM_READWRITE));
1298 * GtkWidget:margin-bottom:
1300 * Margin on bottom side of widget.
1302 * This property adds margin outside of the widget's normal size
1303 * request, the margin will be added in addition to the size from
1304 * gtk_widget_set_size_request() for example.
1308 g_object_class_install_property (gobject_class,
1310 g_param_spec_int ("margin-bottom",
1311 P_("Margin on Bottom"),
1312 P_("Pixels of extra space on the bottom side"),
1316 GTK_PARAM_READWRITE));
1321 * Sets all four sides' margin at once. If read, returns max
1322 * margin on any side.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_int ("margin",
1330 P_("Pixels of extra space on all four sides"),
1334 GTK_PARAM_READWRITE));
1337 * GtkWidget::destroy:
1338 * @object: the object which received the signal
1340 * Signals that all holders of a reference to the widget should release
1341 * the reference that they hold. May result in finalization of the widget
1342 * if all references are released.
1344 widget_signals[DESTROY] =
1345 g_signal_new (I_("destroy"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1347 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1348 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1350 _gtk_marshal_VOID__VOID,
1354 * GtkWidget:hexpand:
1356 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1360 g_object_class_install_property (gobject_class,
1362 g_param_spec_boolean ("hexpand",
1363 P_("Horizontal Expand"),
1364 P_("Whether widget wants more horizontal space"),
1366 GTK_PARAM_READWRITE));
1369 * GtkWidget:hexpand-set:
1371 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1375 g_object_class_install_property (gobject_class,
1377 g_param_spec_boolean ("hexpand-set",
1378 P_("Horizontal Expand Set"),
1379 P_("Whether to use the hexpand property"),
1381 GTK_PARAM_READWRITE));
1384 * GtkWidget:vexpand:
1386 * Whether to expand vertically. See gtk_widget_set_vexpand().
1390 g_object_class_install_property (gobject_class,
1392 g_param_spec_boolean ("vexpand",
1393 P_("Vertical Expand"),
1394 P_("Whether widget wants more vertical space"),
1396 GTK_PARAM_READWRITE));
1399 * GtkWidget:vexpand-set:
1401 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1405 g_object_class_install_property (gobject_class,
1407 g_param_spec_boolean ("vexpand-set",
1408 P_("Vertical Expand Set"),
1409 P_("Whether to use the vexpand property"),
1411 GTK_PARAM_READWRITE));
1416 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1420 g_object_class_install_property (gobject_class,
1422 g_param_spec_boolean ("expand",
1424 P_("Whether widget wants to expand in both directions"),
1426 GTK_PARAM_READWRITE));
1430 * @widget: the object which received the signal.
1432 widget_signals[SHOW] =
1433 g_signal_new (I_("show"),
1434 G_TYPE_FROM_CLASS (gobject_class),
1436 G_STRUCT_OFFSET (GtkWidgetClass, show),
1438 _gtk_marshal_VOID__VOID,
1443 * @widget: the object which received the signal.
1445 widget_signals[HIDE] =
1446 g_signal_new (I_("hide"),
1447 G_TYPE_FROM_CLASS (gobject_class),
1449 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1451 _gtk_marshal_VOID__VOID,
1456 * @widget: the object which received the signal.
1458 widget_signals[MAP] =
1459 g_signal_new (I_("map"),
1460 G_TYPE_FROM_CLASS (gobject_class),
1462 G_STRUCT_OFFSET (GtkWidgetClass, map),
1464 _gtk_marshal_VOID__VOID,
1469 * @widget: the object which received the signal.
1471 widget_signals[UNMAP] =
1472 g_signal_new (I_("unmap"),
1473 G_TYPE_FROM_CLASS (gobject_class),
1475 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1477 _gtk_marshal_VOID__VOID,
1481 * GtkWidget::realize:
1482 * @widget: the object which received the signal.
1484 widget_signals[REALIZE] =
1485 g_signal_new (I_("realize"),
1486 G_TYPE_FROM_CLASS (gobject_class),
1488 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1490 _gtk_marshal_VOID__VOID,
1494 * GtkWidget::unrealize:
1495 * @widget: the object which received the signal.
1497 widget_signals[UNREALIZE] =
1498 g_signal_new (I_("unrealize"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1503 _gtk_marshal_VOID__VOID,
1507 * GtkWidget::size-allocate:
1508 * @widget: the object which received the signal.
1511 widget_signals[SIZE_ALLOCATE] =
1512 g_signal_new (I_("size-allocate"),
1513 G_TYPE_FROM_CLASS (gobject_class),
1515 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1517 _gtk_marshal_VOID__BOXED,
1519 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1522 * GtkWidget::state-changed:
1523 * @widget: the object which received the signal.
1524 * @state: the previous state
1526 * The ::state-changed signal is emitted when the widget state changes.
1527 * See gtk_widget_get_state().
1529 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1531 widget_signals[STATE_CHANGED] =
1532 g_signal_new (I_("state-changed"),
1533 G_TYPE_FROM_CLASS (gobject_class),
1535 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1537 _gtk_marshal_VOID__ENUM,
1539 GTK_TYPE_STATE_TYPE);
1542 * GtkWidget::state-flags-changed:
1543 * @widget: the object which received the signal.
1544 * @flags: The previous state flags.
1546 * The ::state-flags-changed signal is emitted when the widget state
1547 * changes, see gtk_widget_get_state_flags().
1551 widget_signals[STATE_FLAGS_CHANGED] =
1552 g_signal_new (I_("state-flags-changed"),
1553 G_TYPE_FROM_CLASS (gobject_class),
1555 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1557 _gtk_marshal_VOID__FLAGS,
1559 GTK_TYPE_STATE_FLAGS);
1562 * GtkWidget::parent-set:
1563 * @widget: the object on which the signal is emitted
1564 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1565 * just got its initial parent.
1567 * The ::parent-set signal is emitted when a new parent
1568 * has been set on a widget.
1570 widget_signals[PARENT_SET] =
1571 g_signal_new (I_("parent-set"),
1572 G_TYPE_FROM_CLASS (gobject_class),
1574 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1576 _gtk_marshal_VOID__OBJECT,
1581 * GtkWidget::hierarchy-changed:
1582 * @widget: the object on which the signal is emitted
1583 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1584 * if the widget was previously unanchored
1586 * The ::hierarchy-changed signal is emitted when the
1587 * anchored state of a widget changes. A widget is
1588 * <firstterm>anchored</firstterm> when its toplevel
1589 * ancestor is a #GtkWindow. This signal is emitted when
1590 * a widget changes from un-anchored to anchored or vice-versa.
1592 widget_signals[HIERARCHY_CHANGED] =
1593 g_signal_new (I_("hierarchy-changed"),
1594 G_TYPE_FROM_CLASS (gobject_class),
1596 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1598 _gtk_marshal_VOID__OBJECT,
1603 * GtkWidget::style-set:
1604 * @widget: the object on which the signal is emitted
1605 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1606 * just got its initial style
1608 * The ::style-set signal is emitted when a new style has been set
1609 * on a widget. Note that style-modifying functions like
1610 * gtk_widget_modify_base() also cause this signal to be emitted.
1612 * Note that this signal is emitted for changes to the deprecated
1613 * #GtkStyle. To track changes to the #GtkStyleContext associated
1614 * with a widget, use the #GtkWidget::style-updated signal.
1616 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1618 widget_signals[STYLE_SET] =
1619 g_signal_new (I_("style-set"),
1620 G_TYPE_FROM_CLASS (gobject_class),
1622 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1624 _gtk_marshal_VOID__OBJECT,
1629 * GtkWidget::style-updated:
1630 * @widget: the object on which the signal is emitted
1632 * The ::style-updated signal is emitted when the #GtkStyleContext
1633 * of a widget is changed. Note that style-modifying functions like
1634 * gtk_widget_override_color() also cause this signal to be emitted.
1638 widget_signals[STYLE_UPDATED] =
1639 g_signal_new (I_("style-updated"),
1640 G_TYPE_FROM_CLASS (gobject_class),
1642 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1644 g_cclosure_marshal_VOID__VOID,
1648 * GtkWidget::direction-changed:
1649 * @widget: the object on which the signal is emitted
1650 * @previous_direction: the previous text direction of @widget
1652 * The ::direction-changed signal is emitted when the text direction
1653 * of a widget changes.
1655 widget_signals[DIRECTION_CHANGED] =
1656 g_signal_new (I_("direction-changed"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1659 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1661 _gtk_marshal_VOID__ENUM,
1663 GTK_TYPE_TEXT_DIRECTION);
1666 * GtkWidget::grab-notify:
1667 * @widget: the object which received the signal
1668 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1669 * if it becomes unshadowed
1671 * The ::grab-notify signal is emitted when a widget becomes
1672 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1673 * another widget, or when it becomes unshadowed due to a grab
1676 * A widget is shadowed by a gtk_grab_add() when the topmost
1677 * grab widget in the grab stack of its window group is not
1680 widget_signals[GRAB_NOTIFY] =
1681 g_signal_new (I_("grab-notify"),
1682 G_TYPE_FROM_CLASS (gobject_class),
1684 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1686 _gtk_marshal_VOID__BOOLEAN,
1691 * GtkWidget::child-notify:
1692 * @widget: the object which received the signal
1693 * @child_property: the #GParamSpec of the changed child property
1695 * The ::child-notify signal is emitted for each
1696 * <link linkend="child-properties">child property</link> that has
1697 * changed on an object. The signal's detail holds the property name.
1699 widget_signals[CHILD_NOTIFY] =
1700 g_signal_new (I_("child-notify"),
1701 G_TYPE_FROM_CLASS (gobject_class),
1702 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1703 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1705 g_cclosure_marshal_VOID__PARAM,
1711 * @widget: the object which received the signal
1712 * @cr: the cairo context to draw to
1714 * This signal is emitted when a widget is supposed to render itself.
1715 * The @widget's top left corner must be painted at the origin of
1716 * the passed in context and be sized to the values returned by
1717 * gtk_widget_get_allocated_width() and
1718 * gtk_widget_get_allocated_height().
1720 * Signal handlers connected to this signal can modify the cairo
1721 * context passed as @cr in any way they like and don't need to
1722 * restore it. The signal emission takes care of calling cairo_save()
1723 * before and cairo_restore() after invoking the handler.
1725 * Returns: %TRUE to stop other handlers from being invoked for the event.
1726 % %FALSE to propagate the event further.
1730 widget_signals[DRAW] =
1731 g_signal_new (I_("draw"),
1732 G_TYPE_FROM_CLASS (gobject_class),
1734 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1735 _gtk_boolean_handled_accumulator, NULL,
1736 gtk_widget_draw_marshaller,
1738 CAIRO_GOBJECT_TYPE_CONTEXT);
1739 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1740 gtk_widget_draw_marshallerv);
1743 * GtkWidget::mnemonic-activate:
1744 * @widget: the object which received the signal.
1747 * Returns: %TRUE to stop other handlers from being invoked for the event.
1748 * %FALSE to propagate the event further.
1750 widget_signals[MNEMONIC_ACTIVATE] =
1751 g_signal_new (I_("mnemonic-activate"),
1752 G_TYPE_FROM_CLASS (gobject_class),
1754 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1755 _gtk_boolean_handled_accumulator, NULL,
1756 _gtk_marshal_BOOLEAN__BOOLEAN,
1761 * GtkWidget::grab-focus:
1762 * @widget: the object which received the signal.
1764 widget_signals[GRAB_FOCUS] =
1765 g_signal_new (I_("grab-focus"),
1766 G_TYPE_FROM_CLASS (gobject_class),
1767 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1768 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1770 _gtk_marshal_VOID__VOID,
1775 * @widget: the object which received the signal.
1778 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1780 widget_signals[FOCUS] =
1781 g_signal_new (I_("focus"),
1782 G_TYPE_FROM_CLASS (klass),
1784 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1785 _gtk_boolean_handled_accumulator, NULL,
1786 _gtk_marshal_BOOLEAN__ENUM,
1788 GTK_TYPE_DIRECTION_TYPE);
1791 * GtkWidget::move-focus:
1792 * @widget: the object which received the signal.
1795 widget_signals[MOVE_FOCUS] =
1796 g_signal_new (I_("move-focus"),
1797 G_TYPE_FROM_CLASS (klass),
1798 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1799 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1801 _gtk_marshal_VOID__ENUM,
1804 GTK_TYPE_DIRECTION_TYPE);
1807 * GtkWidget::keynav-failed:
1808 * @widget: the object which received the signal
1809 * @direction: the direction of movement
1811 * Gets emitted if keyboard navigation fails.
1812 * See gtk_widget_keynav_failed() for details.
1814 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1815 * if the emitting widget should try to handle the keyboard
1816 * navigation attempt in its parent container(s).
1820 widget_signals[KEYNAV_FAILED] =
1821 g_signal_new (I_("keynav-failed"),
1822 G_TYPE_FROM_CLASS (klass),
1824 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1825 _gtk_boolean_handled_accumulator, NULL,
1826 _gtk_marshal_BOOLEAN__ENUM,
1828 GTK_TYPE_DIRECTION_TYPE);
1832 * @widget: the object which received the signal.
1833 * @event: the #GdkEvent which triggered this signal
1835 * The GTK+ main loop will emit three signals for each GDK event delivered
1836 * to a widget: one generic ::event signal, another, more specific,
1837 * signal that matches the type of event delivered (e.g.
1838 * #GtkWidget::key-press-event) and finally a generic
1839 * #GtkWidget::event-after signal.
1841 * Returns: %TRUE to stop other handlers from being invoked for the event
1842 * and to cancel the emission of the second specific ::event signal.
1843 * %FALSE to propagate the event further and to allow the emission of
1844 * the second signal. The ::event-after signal is emitted regardless of
1847 widget_signals[EVENT] =
1848 g_signal_new (I_("event"),
1849 G_TYPE_FROM_CLASS (klass),
1851 G_STRUCT_OFFSET (GtkWidgetClass, event),
1852 _gtk_boolean_handled_accumulator, NULL,
1853 _gtk_marshal_BOOLEAN__BOXED,
1855 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1856 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1857 _gtk_marshal_BOOLEAN__BOXEDv);
1860 * GtkWidget::event-after:
1861 * @widget: the object which received the signal.
1862 * @event: the #GdkEvent which triggered this signal
1864 * After the emission of the #GtkWidget::event signal and (optionally)
1865 * the second more specific signal, ::event-after will be emitted
1866 * regardless of the previous two signals handlers return values.
1869 widget_signals[EVENT_AFTER] =
1870 g_signal_new (I_("event-after"),
1871 G_TYPE_FROM_CLASS (klass),
1875 _gtk_marshal_VOID__BOXED,
1877 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1878 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1879 _gtk_marshal_BOOLEAN__BOXEDv);
1882 * GtkWidget::button-press-event:
1883 * @widget: the object which received the signal.
1884 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1887 * The ::button-press-event signal will be emitted when a button
1888 * (typically from a mouse) is pressed.
1890 * To receive this signal, the #GdkWindow associated to the
1891 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1893 * This signal will be sent to the grab widget if there is one.
1895 * Returns: %TRUE to stop other handlers from being invoked for the event.
1896 * %FALSE to propagate the event further.
1898 widget_signals[BUTTON_PRESS_EVENT] =
1899 g_signal_new (I_("button-press-event"),
1900 G_TYPE_FROM_CLASS (klass),
1902 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1903 _gtk_boolean_handled_accumulator, NULL,
1904 _gtk_marshal_BOOLEAN__BOXED,
1906 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1907 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1908 _gtk_marshal_BOOLEAN__BOXEDv);
1911 * GtkWidget::button-release-event:
1912 * @widget: the object which received the signal.
1913 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1916 * The ::button-release-event signal will be emitted when a button
1917 * (typically from a mouse) is released.
1919 * To receive this signal, the #GdkWindow associated to the
1920 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1922 * This signal will be sent to the grab widget if there is one.
1924 * Returns: %TRUE to stop other handlers from being invoked for the event.
1925 * %FALSE to propagate the event further.
1927 widget_signals[BUTTON_RELEASE_EVENT] =
1928 g_signal_new (I_("button-release-event"),
1929 G_TYPE_FROM_CLASS (klass),
1931 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1932 _gtk_boolean_handled_accumulator, NULL,
1933 _gtk_marshal_BOOLEAN__BOXED,
1935 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1936 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1937 _gtk_marshal_BOOLEAN__BOXEDv);
1939 widget_signals[TOUCH_EVENT] =
1940 g_signal_new (I_("touch-event"),
1941 G_TYPE_FROM_CLASS (klass),
1943 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1944 _gtk_boolean_handled_accumulator, NULL,
1945 _gtk_marshal_BOOLEAN__BOXED,
1947 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1948 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1949 _gtk_marshal_BOOLEAN__BOXEDv);
1952 * GtkWidget::scroll-event:
1953 * @widget: the object which received the signal.
1954 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1957 * The ::scroll-event signal is emitted when a button in the 4 to 7
1958 * range is pressed. Wheel mice are usually configured to generate
1959 * button press events for buttons 4 and 5 when the wheel is turned.
1961 * To receive this signal, the #GdkWindow associated to the widget needs
1962 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1964 * This signal will be sent to the grab widget if there is one.
1966 * Returns: %TRUE to stop other handlers from being invoked for the event.
1967 * %FALSE to propagate the event further.
1969 widget_signals[SCROLL_EVENT] =
1970 g_signal_new (I_("scroll-event"),
1971 G_TYPE_FROM_CLASS (klass),
1973 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1974 _gtk_boolean_handled_accumulator, NULL,
1975 _gtk_marshal_BOOLEAN__BOXED,
1977 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1978 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1979 _gtk_marshal_BOOLEAN__BOXEDv);
1982 * GtkWidget::motion-notify-event:
1983 * @widget: the object which received the signal.
1984 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1987 * The ::motion-notify-event signal is emitted when the pointer moves
1988 * over the widget's #GdkWindow.
1990 * To receive this signal, the #GdkWindow associated to the widget
1991 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1993 * This signal will be sent to the grab widget if there is one.
1995 * Returns: %TRUE to stop other handlers from being invoked for the event.
1996 * %FALSE to propagate the event further.
1998 widget_signals[MOTION_NOTIFY_EVENT] =
1999 g_signal_new (I_("motion-notify-event"),
2000 G_TYPE_FROM_CLASS (klass),
2002 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2003 _gtk_boolean_handled_accumulator, NULL,
2004 _gtk_marshal_BOOLEAN__BOXED,
2006 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2007 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2008 _gtk_marshal_BOOLEAN__BOXEDv);
2011 * GtkWidget::composited-changed:
2012 * @widget: the object on which the signal is emitted
2014 * The ::composited-changed signal is emitted when the composited
2015 * status of @widget<!-- -->s screen changes.
2016 * See gdk_screen_is_composited().
2018 widget_signals[COMPOSITED_CHANGED] =
2019 g_signal_new (I_("composited-changed"),
2020 G_TYPE_FROM_CLASS (klass),
2021 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2022 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2024 _gtk_marshal_VOID__VOID,
2028 * GtkWidget::delete-event:
2029 * @widget: the object which received the signal
2030 * @event: the event which triggered this signal
2032 * The ::delete-event signal is emitted if a user requests that
2033 * a toplevel window is closed. The default handler for this signal
2034 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2035 * this signal will cause the window to be hidden instead, so that
2036 * it can later be shown again without reconstructing it.
2038 * Returns: %TRUE to stop other handlers from being invoked for the event.
2039 * %FALSE to propagate the event further.
2041 widget_signals[DELETE_EVENT] =
2042 g_signal_new (I_("delete-event"),
2043 G_TYPE_FROM_CLASS (klass),
2045 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2046 _gtk_boolean_handled_accumulator, NULL,
2047 _gtk_marshal_BOOLEAN__BOXED,
2049 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2050 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2051 _gtk_marshal_BOOLEAN__BOXEDv);
2054 * GtkWidget::destroy-event:
2055 * @widget: the object which received the signal.
2056 * @event: the event which triggered this signal
2058 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2059 * You rarely get this signal, because most widgets disconnect themselves
2060 * from their window before they destroy it, so no widget owns the
2061 * window at destroy time.
2063 * To receive this signal, the #GdkWindow associated to the widget needs
2064 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2065 * automatically for all new windows.
2067 * Returns: %TRUE to stop other handlers from being invoked for the event.
2068 * %FALSE to propagate the event further.
2070 widget_signals[DESTROY_EVENT] =
2071 g_signal_new (I_("destroy-event"),
2072 G_TYPE_FROM_CLASS (klass),
2074 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2075 _gtk_boolean_handled_accumulator, NULL,
2076 _gtk_marshal_BOOLEAN__BOXED,
2078 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2079 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2080 _gtk_marshal_BOOLEAN__BOXEDv);
2083 * GtkWidget::key-press-event:
2084 * @widget: the object which received the signal
2085 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2087 * The ::key-press-event signal is emitted when a key is pressed. The signal
2088 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2090 * To receive this signal, the #GdkWindow associated to the widget needs
2091 * to enable the #GDK_KEY_PRESS_MASK mask.
2093 * This signal will be sent to the grab widget if there is one.
2095 * Returns: %TRUE to stop other handlers from being invoked for the event.
2096 * %FALSE to propagate the event further.
2098 widget_signals[KEY_PRESS_EVENT] =
2099 g_signal_new (I_("key-press-event"),
2100 G_TYPE_FROM_CLASS (klass),
2102 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2103 _gtk_boolean_handled_accumulator, NULL,
2104 _gtk_marshal_BOOLEAN__BOXED,
2106 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2107 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2108 _gtk_marshal_BOOLEAN__BOXEDv);
2111 * GtkWidget::key-release-event:
2112 * @widget: the object which received the signal
2113 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2115 * The ::key-release-event signal is emitted when a key is released.
2117 * To receive this signal, the #GdkWindow associated to the widget needs
2118 * to enable the #GDK_KEY_RELEASE_MASK mask.
2120 * This signal will be sent to the grab widget if there is one.
2122 * Returns: %TRUE to stop other handlers from being invoked for the event.
2123 * %FALSE to propagate the event further.
2125 widget_signals[KEY_RELEASE_EVENT] =
2126 g_signal_new (I_("key-release-event"),
2127 G_TYPE_FROM_CLASS (klass),
2129 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2130 _gtk_boolean_handled_accumulator, NULL,
2131 _gtk_marshal_BOOLEAN__BOXED,
2133 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2134 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2135 _gtk_marshal_BOOLEAN__BOXEDv);
2138 * GtkWidget::enter-notify-event:
2139 * @widget: the object which received the signal
2140 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2143 * The ::enter-notify-event will be emitted when the pointer enters
2144 * the @widget's window.
2146 * To receive this signal, the #GdkWindow associated to the widget needs
2147 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2149 * This signal will be sent to the grab widget if there is one.
2151 * Returns: %TRUE to stop other handlers from being invoked for the event.
2152 * %FALSE to propagate the event further.
2154 widget_signals[ENTER_NOTIFY_EVENT] =
2155 g_signal_new (I_("enter-notify-event"),
2156 G_TYPE_FROM_CLASS (klass),
2158 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2159 _gtk_boolean_handled_accumulator, NULL,
2160 _gtk_marshal_BOOLEAN__BOXED,
2162 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2163 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2164 _gtk_marshal_BOOLEAN__BOXEDv);
2167 * GtkWidget::leave-notify-event:
2168 * @widget: the object which received the signal
2169 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2172 * The ::leave-notify-event will be emitted when the pointer leaves
2173 * the @widget's window.
2175 * To receive this signal, the #GdkWindow associated to the widget needs
2176 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2178 * This signal will be sent to the grab widget if there is one.
2180 * Returns: %TRUE to stop other handlers from being invoked for the event.
2181 * %FALSE to propagate the event further.
2183 widget_signals[LEAVE_NOTIFY_EVENT] =
2184 g_signal_new (I_("leave-notify-event"),
2185 G_TYPE_FROM_CLASS (klass),
2187 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2188 _gtk_boolean_handled_accumulator, NULL,
2189 _gtk_marshal_BOOLEAN__BOXED,
2191 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2192 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2193 _gtk_marshal_BOOLEAN__BOXEDv);
2196 * GtkWidget::configure-event:
2197 * @widget: the object which received the signal
2198 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2201 * The ::configure-event signal will be emitted when the size, position or
2202 * stacking of the @widget's window has changed.
2204 * To receive this signal, the #GdkWindow associated to the widget needs
2205 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2206 * automatically for all new windows.
2208 * Returns: %TRUE to stop other handlers from being invoked for the event.
2209 * %FALSE to propagate the event further.
2211 widget_signals[CONFIGURE_EVENT] =
2212 g_signal_new (I_("configure-event"),
2213 G_TYPE_FROM_CLASS (klass),
2215 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2216 _gtk_boolean_handled_accumulator, NULL,
2217 _gtk_marshal_BOOLEAN__BOXED,
2219 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2220 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2221 _gtk_marshal_BOOLEAN__BOXEDv);
2224 * GtkWidget::focus-in-event:
2225 * @widget: the object which received the signal
2226 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2229 * The ::focus-in-event signal will be emitted when the keyboard focus
2230 * enters the @widget's window.
2232 * To receive this signal, the #GdkWindow associated to the widget needs
2233 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2235 * Returns: %TRUE to stop other handlers from being invoked for the event.
2236 * %FALSE to propagate the event further.
2238 widget_signals[FOCUS_IN_EVENT] =
2239 g_signal_new (I_("focus-in-event"),
2240 G_TYPE_FROM_CLASS (klass),
2242 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2243 _gtk_boolean_handled_accumulator, NULL,
2244 _gtk_marshal_BOOLEAN__BOXED,
2246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2247 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2248 _gtk_marshal_BOOLEAN__BOXEDv);
2251 * GtkWidget::focus-out-event:
2252 * @widget: the object which received the signal
2253 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2256 * The ::focus-out-event signal will be emitted when the keyboard focus
2257 * leaves the @widget's window.
2259 * To receive this signal, the #GdkWindow associated to the widget needs
2260 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2262 * Returns: %TRUE to stop other handlers from being invoked for the event.
2263 * %FALSE to propagate the event further.
2265 widget_signals[FOCUS_OUT_EVENT] =
2266 g_signal_new (I_("focus-out-event"),
2267 G_TYPE_FROM_CLASS (klass),
2269 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2270 _gtk_boolean_handled_accumulator, NULL,
2271 _gtk_marshal_BOOLEAN__BOXED,
2273 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2274 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2275 _gtk_marshal_BOOLEAN__BOXEDv);
2278 * GtkWidget::map-event:
2279 * @widget: the object which received the signal
2280 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2282 * The ::map-event signal will be emitted when the @widget's window is
2283 * mapped. A window is mapped when it becomes visible on the screen.
2285 * To receive this signal, the #GdkWindow associated to the widget needs
2286 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2287 * automatically for all new windows.
2289 * Returns: %TRUE to stop other handlers from being invoked for the event.
2290 * %FALSE to propagate the event further.
2292 widget_signals[MAP_EVENT] =
2293 g_signal_new (I_("map-event"),
2294 G_TYPE_FROM_CLASS (klass),
2296 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2297 _gtk_boolean_handled_accumulator, NULL,
2298 _gtk_marshal_BOOLEAN__BOXED,
2300 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2301 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2302 _gtk_marshal_BOOLEAN__BOXEDv);
2305 * GtkWidget::unmap-event:
2306 * @widget: the object which received the signal
2307 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2309 * The ::unmap-event signal will be emitted when the @widget's window is
2310 * unmapped. A window is unmapped when it becomes invisible on the screen.
2312 * To receive this signal, the #GdkWindow associated to the widget needs
2313 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2314 * automatically for all new windows.
2316 * Returns: %TRUE to stop other handlers from being invoked for the event.
2317 * %FALSE to propagate the event further.
2319 widget_signals[UNMAP_EVENT] =
2320 g_signal_new (I_("unmap-event"),
2321 G_TYPE_FROM_CLASS (klass),
2323 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2324 _gtk_boolean_handled_accumulator, NULL,
2325 _gtk_marshal_BOOLEAN__BOXED,
2327 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2328 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2329 _gtk_marshal_BOOLEAN__BOXEDv);
2332 * GtkWidget::property-notify-event:
2333 * @widget: the object which received the signal
2334 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2337 * The ::property-notify-event signal will be emitted when a property on
2338 * the @widget's window has been changed or deleted.
2340 * To receive this signal, the #GdkWindow associated to the widget needs
2341 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2343 * Returns: %TRUE to stop other handlers from being invoked for the event.
2344 * %FALSE to propagate the event further.
2346 widget_signals[PROPERTY_NOTIFY_EVENT] =
2347 g_signal_new (I_("property-notify-event"),
2348 G_TYPE_FROM_CLASS (klass),
2350 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2351 _gtk_boolean_handled_accumulator, NULL,
2352 _gtk_marshal_BOOLEAN__BOXED,
2354 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2355 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2356 _gtk_marshal_BOOLEAN__BOXEDv);
2359 * GtkWidget::selection-clear-event:
2360 * @widget: the object which received the signal
2361 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2364 * The ::selection-clear-event signal will be emitted when the
2365 * the @widget's window has lost ownership of a selection.
2367 * Returns: %TRUE to stop other handlers from being invoked for the event.
2368 * %FALSE to propagate the event further.
2370 widget_signals[SELECTION_CLEAR_EVENT] =
2371 g_signal_new (I_("selection-clear-event"),
2372 G_TYPE_FROM_CLASS (klass),
2374 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2375 _gtk_boolean_handled_accumulator, NULL,
2376 _gtk_marshal_BOOLEAN__BOXED,
2378 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2379 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2380 _gtk_marshal_BOOLEAN__BOXEDv);
2383 * GtkWidget::selection-request-event:
2384 * @widget: the object which received the signal
2385 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2388 * The ::selection-request-event signal will be emitted when
2389 * another client requests ownership of the selection owned by
2390 * the @widget's window.
2392 * Returns: %TRUE to stop other handlers from being invoked for the event.
2393 * %FALSE to propagate the event further.
2395 widget_signals[SELECTION_REQUEST_EVENT] =
2396 g_signal_new (I_("selection-request-event"),
2397 G_TYPE_FROM_CLASS (klass),
2399 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2400 _gtk_boolean_handled_accumulator, NULL,
2401 _gtk_marshal_BOOLEAN__BOXED,
2403 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2404 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2405 _gtk_marshal_BOOLEAN__BOXEDv);
2408 * GtkWidget::selection-notify-event:
2409 * @widget: the object which received the signal.
2410 * @event: (type Gdk.EventSelection):
2412 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2414 widget_signals[SELECTION_NOTIFY_EVENT] =
2415 g_signal_new (I_("selection-notify-event"),
2416 G_TYPE_FROM_CLASS (klass),
2418 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2419 _gtk_boolean_handled_accumulator, NULL,
2420 _gtk_marshal_BOOLEAN__BOXED,
2422 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2423 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2424 _gtk_marshal_BOOLEAN__BOXEDv);
2427 * GtkWidget::selection-received:
2428 * @widget: the object which received the signal.
2432 widget_signals[SELECTION_RECEIVED] =
2433 g_signal_new (I_("selection-received"),
2434 G_TYPE_FROM_CLASS (klass),
2436 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2438 _gtk_marshal_VOID__BOXED_UINT,
2440 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2444 * GtkWidget::selection-get:
2445 * @widget: the object which received the signal.
2450 widget_signals[SELECTION_GET] =
2451 g_signal_new (I_("selection-get"),
2452 G_TYPE_FROM_CLASS (klass),
2454 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2456 _gtk_marshal_VOID__BOXED_UINT_UINT,
2458 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2463 * GtkWidget::proximity-in-event:
2464 * @widget: the object which received the signal
2465 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2468 * To receive this signal the #GdkWindow associated to the widget needs
2469 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2471 * This signal will be sent to the grab widget if there is one.
2473 * Returns: %TRUE to stop other handlers from being invoked for the event.
2474 * %FALSE to propagate the event further.
2476 widget_signals[PROXIMITY_IN_EVENT] =
2477 g_signal_new (I_("proximity-in-event"),
2478 G_TYPE_FROM_CLASS (klass),
2480 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2481 _gtk_boolean_handled_accumulator, NULL,
2482 _gtk_marshal_BOOLEAN__BOXED,
2484 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2485 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2486 _gtk_marshal_BOOLEAN__BOXEDv);
2489 * GtkWidget::proximity-out-event:
2490 * @widget: the object which received the signal
2491 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2494 * To receive this signal the #GdkWindow associated to the widget needs
2495 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2497 * This signal will be sent to the grab widget if there is one.
2499 * Returns: %TRUE to stop other handlers from being invoked for the event.
2500 * %FALSE to propagate the event further.
2502 widget_signals[PROXIMITY_OUT_EVENT] =
2503 g_signal_new (I_("proximity-out-event"),
2504 G_TYPE_FROM_CLASS (klass),
2506 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2507 _gtk_boolean_handled_accumulator, NULL,
2508 _gtk_marshal_BOOLEAN__BOXED,
2510 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2511 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2512 _gtk_marshal_BOOLEAN__BOXEDv);
2515 * GtkWidget::drag-leave:
2516 * @widget: the object which received the signal.
2517 * @context: the drag context
2518 * @time: the timestamp of the motion event
2520 * The ::drag-leave signal is emitted on the drop site when the cursor
2521 * leaves the widget. A typical reason to connect to this signal is to
2522 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2523 * with gtk_drag_unhighlight()
2525 widget_signals[DRAG_LEAVE] =
2526 g_signal_new (I_("drag-leave"),
2527 G_TYPE_FROM_CLASS (klass),
2529 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2531 _gtk_marshal_VOID__OBJECT_UINT,
2533 GDK_TYPE_DRAG_CONTEXT,
2537 * GtkWidget::drag-begin:
2538 * @widget: the object which received the signal
2539 * @context: the drag context
2541 * The ::drag-begin signal is emitted on the drag source when a drag is
2542 * started. A typical reason to connect to this signal is to set up a
2543 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2545 * Note that some widgets set up a drag icon in the default handler of
2546 * this signal, so you may have to use g_signal_connect_after() to
2547 * override what the default handler did.
2549 widget_signals[DRAG_BEGIN] =
2550 g_signal_new (I_("drag-begin"),
2551 G_TYPE_FROM_CLASS (klass),
2553 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2555 _gtk_marshal_VOID__OBJECT,
2557 GDK_TYPE_DRAG_CONTEXT);
2560 * GtkWidget::drag-end:
2561 * @widget: the object which received the signal
2562 * @context: the drag context
2564 * The ::drag-end signal is emitted on the drag source when a drag is
2565 * finished. A typical reason to connect to this signal is to undo
2566 * things done in #GtkWidget::drag-begin.
2568 widget_signals[DRAG_END] =
2569 g_signal_new (I_("drag-end"),
2570 G_TYPE_FROM_CLASS (klass),
2572 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2574 _gtk_marshal_VOID__OBJECT,
2576 GDK_TYPE_DRAG_CONTEXT);
2579 * GtkWidget::drag-data-delete:
2580 * @widget: the object which received the signal
2581 * @context: the drag context
2583 * The ::drag-data-delete signal is emitted on the drag source when a drag
2584 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2585 * handler is responsible for deleting the data that has been dropped. What
2586 * "delete" means depends on the context of the drag operation.
2588 widget_signals[DRAG_DATA_DELETE] =
2589 g_signal_new (I_("drag-data-delete"),
2590 G_TYPE_FROM_CLASS (klass),
2592 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2594 _gtk_marshal_VOID__OBJECT,
2596 GDK_TYPE_DRAG_CONTEXT);
2599 * GtkWidget::drag-failed:
2600 * @widget: the object which received the signal
2601 * @context: the drag context
2602 * @result: the result of the drag operation
2604 * The ::drag-failed signal is emitted on the drag source when a drag has
2605 * failed. The signal handler may hook custom code to handle a failed DND
2606 * operation based on the type of error, it returns %TRUE is the failure has
2607 * been already handled (not showing the default "drag operation failed"
2608 * animation), otherwise it returns %FALSE.
2610 * Return value: %TRUE if the failed drag operation has been already handled.
2614 widget_signals[DRAG_FAILED] =
2615 g_signal_new (I_("drag-failed"),
2616 G_TYPE_FROM_CLASS (klass),
2618 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2619 _gtk_boolean_handled_accumulator, NULL,
2620 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2622 GDK_TYPE_DRAG_CONTEXT,
2623 GTK_TYPE_DRAG_RESULT);
2626 * GtkWidget::drag-motion:
2627 * @widget: the object which received the signal
2628 * @context: the drag context
2629 * @x: the x coordinate of the current cursor position
2630 * @y: the y coordinate of the current cursor position
2631 * @time: the timestamp of the motion event
2633 * The ::drag-motion signal is emitted on the drop site when the user
2634 * moves the cursor over the widget during a drag. The signal handler
2635 * must determine whether the cursor position is in a drop zone or not.
2636 * If it is not in a drop zone, it returns %FALSE and no further processing
2637 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2638 * handler is responsible for providing the necessary information for
2639 * displaying feedback to the user, by calling gdk_drag_status().
2641 * If the decision whether the drop will be accepted or rejected can't be
2642 * made based solely on the cursor position and the type of the data, the
2643 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2644 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2645 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2646 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2647 * when using the drag-motion signal that way.
2649 * Also note that there is no drag-enter signal. The drag receiver has to
2650 * keep track of whether he has received any drag-motion signals since the
2651 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2652 * an "enter" signal. Upon an "enter", the handler will typically highlight
2653 * the drop site with gtk_drag_highlight().
2656 * drag_motion (GtkWidget *widget,
2657 * GdkDragContext *context,
2664 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2666 * if (!private_data->drag_highlight)
2668 * private_data->drag_highlight = 1;
2669 * gtk_drag_highlight (widget);
2672 * target = gtk_drag_dest_find_target (widget, context, NULL);
2673 * if (target == GDK_NONE)
2674 * gdk_drag_status (context, 0, time);
2677 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2678 * gtk_drag_get_data (widget, context, target, time);
2685 * drag_data_received (GtkWidget *widget,
2686 * GdkDragContext *context,
2689 * GtkSelectionData *selection_data,
2693 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2695 * if (private_data->suggested_action)
2697 * private_data->suggested_action = 0;
2699 * /* We are getting this data due to a request in drag_motion,
2700 * * rather than due to a request in drag_drop, so we are just
2701 * * supposed to call gdk_drag_status(), not actually paste in
2704 * str = gtk_selection_data_get_text (selection_data);
2705 * if (!data_is_acceptable (str))
2706 * gdk_drag_status (context, 0, time);
2708 * gdk_drag_status (context, private_data->suggested_action, time);
2712 * /* accept the drop */
2717 * Returns: whether the cursor position is in a drop zone
2719 widget_signals[DRAG_MOTION] =
2720 g_signal_new (I_("drag-motion"),
2721 G_TYPE_FROM_CLASS (klass),
2723 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2724 _gtk_boolean_handled_accumulator, NULL,
2725 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2727 GDK_TYPE_DRAG_CONTEXT,
2733 * GtkWidget::drag-drop:
2734 * @widget: the object which received the signal
2735 * @context: the drag context
2736 * @x: the x coordinate of the current cursor position
2737 * @y: the y coordinate of the current cursor position
2738 * @time: the timestamp of the motion event
2740 * The ::drag-drop signal is emitted on the drop site when the user drops
2741 * the data onto the widget. The signal handler must determine whether
2742 * the cursor position is in a drop zone or not. If it is not in a drop
2743 * zone, it returns %FALSE and no further processing is necessary.
2744 * Otherwise, the handler returns %TRUE. In this case, the handler must
2745 * ensure that gtk_drag_finish() is called to let the source know that
2746 * the drop is done. The call to gtk_drag_finish() can be done either
2747 * directly or in a #GtkWidget::drag-data-received handler which gets
2748 * triggered by calling gtk_drag_get_data() to receive the data for one
2749 * or more of the supported targets.
2751 * Returns: whether the cursor position is in a drop zone
2753 widget_signals[DRAG_DROP] =
2754 g_signal_new (I_("drag-drop"),
2755 G_TYPE_FROM_CLASS (klass),
2757 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2758 _gtk_boolean_handled_accumulator, NULL,
2759 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2761 GDK_TYPE_DRAG_CONTEXT,
2767 * GtkWidget::drag-data-get:
2768 * @widget: the object which received the signal
2769 * @context: the drag context
2770 * @data: the #GtkSelectionData to be filled with the dragged data
2771 * @info: the info that has been registered with the target in the
2773 * @time: the timestamp at which the data was requested
2775 * The ::drag-data-get signal is emitted on the drag source when the drop
2776 * site requests the data which is dragged. It is the responsibility of
2777 * the signal handler to fill @data with the data in the format which
2778 * is indicated by @info. See gtk_selection_data_set() and
2779 * gtk_selection_data_set_text().
2781 widget_signals[DRAG_DATA_GET] =
2782 g_signal_new (I_("drag-data-get"),
2783 G_TYPE_FROM_CLASS (klass),
2785 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2787 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2789 GDK_TYPE_DRAG_CONTEXT,
2790 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2795 * GtkWidget::drag-data-received:
2796 * @widget: the object which received the signal
2797 * @context: the drag context
2798 * @x: where the drop happened
2799 * @y: where the drop happened
2800 * @data: the received data
2801 * @info: the info that has been registered with the target in the
2803 * @time: the timestamp at which the data was received
2805 * The ::drag-data-received signal is emitted on the drop site when the
2806 * dragged data has been received. If the data was received in order to
2807 * determine whether the drop will be accepted, the handler is expected
2808 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2809 * If the data was received in response to a #GtkWidget::drag-drop signal
2810 * (and this is the last target to be received), the handler for this
2811 * signal is expected to process the received data and then call
2812 * gtk_drag_finish(), setting the @success parameter depending on
2813 * whether the data was processed successfully.
2815 * The handler may inspect the selected action with
2816 * gdk_drag_context_get_selected_action() before calling
2817 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2818 * shown in the following example:
2821 * drag_data_received (GtkWidget *widget,
2822 * GdkDragContext *context,
2825 * GtkSelectionData *data,
2829 * if ((data->length >= 0) && (data->format == 8))
2831 * GdkDragAction action;
2833 * /* handle data here */
2835 * action = gdk_drag_context_get_selected_action (context);
2836 * if (action == GDK_ACTION_ASK)
2838 * GtkWidget *dialog;
2841 * dialog = gtk_message_dialog_new (NULL,
2842 * GTK_DIALOG_MODAL |
2843 * GTK_DIALOG_DESTROY_WITH_PARENT,
2845 * GTK_BUTTONS_YES_NO,
2846 * "Move the data ?\n");
2847 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2848 * gtk_widget_destroy (dialog);
2850 * if (response == GTK_RESPONSE_YES)
2851 * action = GDK_ACTION_MOVE;
2853 * action = GDK_ACTION_COPY;
2856 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2859 * gtk_drag_finish (context, FALSE, FALSE, time);
2863 widget_signals[DRAG_DATA_RECEIVED] =
2864 g_signal_new (I_("drag-data-received"),
2865 G_TYPE_FROM_CLASS (klass),
2867 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2869 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2871 GDK_TYPE_DRAG_CONTEXT,
2874 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2879 * GtkWidget::visibility-notify-event:
2880 * @widget: the object which received the signal
2881 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2882 * triggered this signal.
2884 * The ::visibility-notify-event will be emitted when the @widget's window
2885 * is obscured or unobscured.
2887 * To receive this signal the #GdkWindow associated to the widget needs
2888 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2890 * Returns: %TRUE to stop other handlers from being invoked for the event.
2891 * %FALSE to propagate the event further.
2893 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2894 g_signal_new (I_("visibility-notify-event"),
2895 G_TYPE_FROM_CLASS (klass),
2897 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2898 _gtk_boolean_handled_accumulator, NULL,
2899 _gtk_marshal_BOOLEAN__BOXED,
2901 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2904 * GtkWidget::window-state-event:
2905 * @widget: the object which received the signal
2906 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2907 * triggered this signal.
2909 * The ::window-state-event will be emitted when the state of the
2910 * toplevel window associated to the @widget changes.
2912 * To receive this signal the #GdkWindow associated to the widget
2913 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2914 * this mask automatically for all new windows.
2916 * Returns: %TRUE to stop other handlers from being invoked for the
2917 * event. %FALSE to propagate the event further.
2919 widget_signals[WINDOW_STATE_EVENT] =
2920 g_signal_new (I_("window-state-event"),
2921 G_TYPE_FROM_CLASS (klass),
2923 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2924 _gtk_boolean_handled_accumulator, NULL,
2925 _gtk_marshal_BOOLEAN__BOXED,
2927 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2928 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2929 _gtk_marshal_BOOLEAN__BOXEDv);
2932 * GtkWidget::damage-event:
2933 * @widget: the object which received the signal
2934 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2936 * Emitted when a redirected window belonging to @widget gets drawn into.
2937 * The region/area members of the event shows what area of the redirected
2938 * drawable was drawn into.
2940 * Returns: %TRUE to stop other handlers from being invoked for the event.
2941 * %FALSE to propagate the event further.
2945 widget_signals[DAMAGE_EVENT] =
2946 g_signal_new (I_("damage-event"),
2947 G_TYPE_FROM_CLASS (klass),
2949 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2950 _gtk_boolean_handled_accumulator, NULL,
2951 _gtk_marshal_BOOLEAN__BOXED,
2953 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2954 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2955 _gtk_marshal_BOOLEAN__BOXEDv);
2958 * GtkWidget::grab-broken-event:
2959 * @widget: the object which received the signal
2960 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2962 * Emitted when a pointer or keyboard grab on a window belonging
2963 * to @widget gets broken.
2965 * On X11, this happens when the grab window becomes unviewable
2966 * (i.e. it or one of its ancestors is unmapped), or if the same
2967 * application grabs the pointer or keyboard again.
2969 * Returns: %TRUE to stop other handlers from being invoked for
2970 * the event. %FALSE to propagate the event further.
2974 widget_signals[GRAB_BROKEN_EVENT] =
2975 g_signal_new (I_("grab-broken-event"),
2976 G_TYPE_FROM_CLASS (klass),
2978 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2979 _gtk_boolean_handled_accumulator, NULL,
2980 _gtk_marshal_BOOLEAN__BOXED,
2982 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2983 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2984 _gtk_marshal_BOOLEAN__BOXEDv);
2987 * GtkWidget::query-tooltip:
2988 * @widget: the object which received the signal
2989 * @x: the x coordinate of the cursor position where the request has
2990 * been emitted, relative to @widget's left side
2991 * @y: the y coordinate of the cursor position where the request has
2992 * been emitted, relative to @widget's top
2993 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2994 * @tooltip: a #GtkTooltip
2996 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2997 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2998 * focus in keyboard mode.
3000 * Using the given coordinates, the signal handler should determine
3001 * whether a tooltip should be shown for @widget. If this is the case
3002 * %TRUE should be returned, %FALSE otherwise. Note that if
3003 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3004 * should not be used.
3006 * The signal handler is free to manipulate @tooltip with the therefore
3007 * destined function calls.
3009 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3013 widget_signals[QUERY_TOOLTIP] =
3014 g_signal_new (I_("query-tooltip"),
3015 G_TYPE_FROM_CLASS (klass),
3017 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3018 _gtk_boolean_handled_accumulator, NULL,
3019 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3027 * GtkWidget::popup-menu:
3028 * @widget: the object which received the signal
3030 * This signal gets emitted whenever a widget should pop up a context
3031 * menu. This usually happens through the standard key binding mechanism;
3032 * by pressing a certain key while a widget is focused, the user can cause
3033 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3034 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3035 * for an example of how to use this signal.
3037 * Returns: %TRUE if a menu was activated
3039 widget_signals[POPUP_MENU] =
3040 g_signal_new (I_("popup-menu"),
3041 G_TYPE_FROM_CLASS (klass),
3042 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3043 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3044 _gtk_boolean_handled_accumulator, NULL,
3045 _gtk_marshal_BOOLEAN__VOID,
3049 * GtkWidget::show-help:
3050 * @widget: the object which received the signal.
3053 * Returns: %TRUE to stop other handlers from being invoked for the event.
3054 * %FALSE to propagate the event further.
3056 widget_signals[SHOW_HELP] =
3057 g_signal_new (I_("show-help"),
3058 G_TYPE_FROM_CLASS (klass),
3059 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3060 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3061 _gtk_boolean_handled_accumulator, NULL,
3062 _gtk_marshal_BOOLEAN__ENUM,
3064 GTK_TYPE_WIDGET_HELP_TYPE);
3067 * GtkWidget::accel-closures-changed:
3068 * @widget: the object which received the signal.
3070 widget_signals[ACCEL_CLOSURES_CHANGED] =
3071 g_signal_new (I_("accel-closures-changed"),
3072 G_TYPE_FROM_CLASS (klass),
3076 _gtk_marshal_VOID__VOID,
3080 * GtkWidget::screen-changed:
3081 * @widget: the object on which the signal is emitted
3082 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3083 * widget was not associated with a screen before
3085 * The ::screen-changed signal gets emitted when the
3086 * screen of a widget has changed.
3088 widget_signals[SCREEN_CHANGED] =
3089 g_signal_new (I_("screen-changed"),
3090 G_TYPE_FROM_CLASS (klass),
3092 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3094 _gtk_marshal_VOID__OBJECT,
3099 * GtkWidget::can-activate-accel:
3100 * @widget: the object which received the signal
3101 * @signal_id: the ID of a signal installed on @widget
3103 * Determines whether an accelerator that activates the signal
3104 * identified by @signal_id can currently be activated.
3105 * This signal is present to allow applications and derived
3106 * widgets to override the default #GtkWidget handling
3107 * for determining whether an accelerator can be activated.
3109 * Returns: %TRUE if the signal can be activated.
3111 widget_signals[CAN_ACTIVATE_ACCEL] =
3112 g_signal_new (I_("can-activate-accel"),
3113 G_TYPE_FROM_CLASS (klass),
3115 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3116 _gtk_boolean_handled_accumulator, NULL,
3117 _gtk_marshal_BOOLEAN__UINT,
3118 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3120 binding_set = gtk_binding_set_by_class (klass);
3121 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3123 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3126 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3128 GTK_TYPE_WIDGET_HELP_TYPE,
3129 GTK_WIDGET_HELP_TOOLTIP);
3130 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3132 GTK_TYPE_WIDGET_HELP_TYPE,
3133 GTK_WIDGET_HELP_TOOLTIP);
3134 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3136 GTK_TYPE_WIDGET_HELP_TYPE,
3137 GTK_WIDGET_HELP_WHATS_THIS);
3138 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3140 GTK_TYPE_WIDGET_HELP_TYPE,
3141 GTK_WIDGET_HELP_WHATS_THIS);
3143 gtk_widget_class_install_style_property (klass,
3144 g_param_spec_boolean ("interior-focus",
3145 P_("Interior Focus"),
3146 P_("Whether to draw the focus indicator inside widgets"),
3148 GTK_PARAM_READABLE));
3150 gtk_widget_class_install_style_property (klass,
3151 g_param_spec_int ("focus-line-width",
3152 P_("Focus linewidth"),
3153 P_("Width, in pixels, of the focus indicator line"),
3155 GTK_PARAM_READABLE));
3157 gtk_widget_class_install_style_property (klass,
3158 g_param_spec_string ("focus-line-pattern",
3159 P_("Focus line dash pattern"),
3160 P_("Dash pattern used to draw the focus indicator"),
3162 GTK_PARAM_READABLE));
3163 gtk_widget_class_install_style_property (klass,
3164 g_param_spec_int ("focus-padding",
3165 P_("Focus padding"),
3166 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3168 GTK_PARAM_READABLE));
3169 gtk_widget_class_install_style_property (klass,
3170 g_param_spec_boxed ("cursor-color",
3172 P_("Color with which to draw insertion cursor"),
3174 GTK_PARAM_READABLE));
3175 gtk_widget_class_install_style_property (klass,
3176 g_param_spec_boxed ("secondary-cursor-color",
3177 P_("Secondary cursor color"),
3178 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3180 GTK_PARAM_READABLE));
3181 gtk_widget_class_install_style_property (klass,
3182 g_param_spec_float ("cursor-aspect-ratio",
3183 P_("Cursor line aspect ratio"),
3184 P_("Aspect ratio with which to draw insertion cursor"),
3186 GTK_PARAM_READABLE));
3188 gtk_widget_class_install_style_property (klass,
3189 g_param_spec_boolean ("window-dragging",
3190 P_("Window dragging"),
3191 P_("Whether windows can be dragged by clicking on empty areas"),
3193 GTK_PARAM_READABLE));
3196 * GtkWidget:link-color:
3198 * The "link-color" style property defines the color of unvisited links.
3202 gtk_widget_class_install_style_property (klass,
3203 g_param_spec_boxed ("link-color",
3204 P_("Unvisited Link Color"),
3205 P_("Color of unvisited links"),
3207 GTK_PARAM_READABLE));
3210 * GtkWidget:visited-link-color:
3212 * The "visited-link-color" style property defines the color of visited links.
3216 gtk_widget_class_install_style_property (klass,
3217 g_param_spec_boxed ("visited-link-color",
3218 P_("Visited Link Color"),
3219 P_("Color of visited links"),
3221 GTK_PARAM_READABLE));
3224 * GtkWidget:wide-separators:
3226 * The "wide-separators" style property defines whether separators have
3227 * configurable width and should be drawn using a box instead of a line.
3231 gtk_widget_class_install_style_property (klass,
3232 g_param_spec_boolean ("wide-separators",
3233 P_("Wide Separators"),
3234 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3236 GTK_PARAM_READABLE));
3239 * GtkWidget:separator-width:
3241 * The "separator-width" style property defines the width of separators.
3242 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3246 gtk_widget_class_install_style_property (klass,
3247 g_param_spec_int ("separator-width",
3248 P_("Separator Width"),
3249 P_("The width of separators if wide-separators is TRUE"),
3251 GTK_PARAM_READABLE));
3254 * GtkWidget:separator-height:
3256 * The "separator-height" style property defines the height of separators.
3257 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3261 gtk_widget_class_install_style_property (klass,
3262 g_param_spec_int ("separator-height",
3263 P_("Separator Height"),
3264 P_("The height of separators if \"wide-separators\" is TRUE"),
3266 GTK_PARAM_READABLE));
3269 * GtkWidget:scroll-arrow-hlength:
3271 * The "scroll-arrow-hlength" style property defines the length of
3272 * horizontal scroll arrows.
3276 gtk_widget_class_install_style_property (klass,
3277 g_param_spec_int ("scroll-arrow-hlength",
3278 P_("Horizontal Scroll Arrow Length"),
3279 P_("The length of horizontal scroll arrows"),
3281 GTK_PARAM_READABLE));
3284 * GtkWidget:scroll-arrow-vlength:
3286 * The "scroll-arrow-vlength" style property defines the length of
3287 * vertical scroll arrows.
3291 gtk_widget_class_install_style_property (klass,
3292 g_param_spec_int ("scroll-arrow-vlength",
3293 P_("Vertical Scroll Arrow Length"),
3294 P_("The length of vertical scroll arrows"),
3296 GTK_PARAM_READABLE));
3298 gtk_widget_class_install_style_property (klass,
3299 g_param_spec_int ("text-handle-width",
3300 P_("Width of text selection handles"),
3301 P_("Width of text selection handles"),
3303 GTK_PARAM_READABLE));
3304 gtk_widget_class_install_style_property (klass,
3305 g_param_spec_int ("text-handle-height",
3306 P_("Height of text selection handles"),
3307 P_("Height of text selection handles"),
3309 GTK_PARAM_READABLE));
3311 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3313 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3317 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3321 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3322 for (node = list; node; node = node->next)
3324 GParamSpec *pspec = node->data;
3326 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3327 g_param_spec_unref (pspec);
3333 gtk_widget_set_property (GObject *object,
3335 const GValue *value,
3338 GtkWidget *widget = GTK_WIDGET (object);
3343 gchar *tooltip_markup;
3344 const gchar *tooltip_text;
3345 GtkWindow *tooltip_window;
3348 gtk_widget_set_name (widget, g_value_get_string (value));
3351 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3353 case PROP_WIDTH_REQUEST:
3354 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3356 case PROP_HEIGHT_REQUEST:
3357 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3360 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3362 case PROP_SENSITIVE:
3363 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3365 case PROP_APP_PAINTABLE:
3366 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3368 case PROP_CAN_FOCUS:
3369 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3371 case PROP_HAS_FOCUS:
3372 if (g_value_get_boolean (value))
3373 gtk_widget_grab_focus (widget);
3376 if (g_value_get_boolean (value))
3377 gtk_widget_grab_focus (widget);
3379 case PROP_CAN_DEFAULT:
3380 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3382 case PROP_HAS_DEFAULT:
3383 if (g_value_get_boolean (value))
3384 gtk_widget_grab_default (widget);
3386 case PROP_RECEIVES_DEFAULT:
3387 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3390 gtk_widget_set_style (widget, g_value_get_object (value));
3393 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3394 gtk_widget_set_events (widget, g_value_get_flags (value));
3396 case PROP_NO_SHOW_ALL:
3397 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3399 case PROP_HAS_TOOLTIP:
3400 gtk_widget_real_set_has_tooltip (widget,
3401 g_value_get_boolean (value), FALSE);
3403 case PROP_TOOLTIP_MARKUP:
3404 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3405 tooltip_markup = g_value_dup_string (value);
3407 /* Treat an empty string as a NULL string,
3408 * because an empty string would be useless for a tooltip:
3410 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3412 g_free (tooltip_markup);
3413 tooltip_markup = NULL;
3416 g_object_set_qdata_full (object, quark_tooltip_markup,
3417 tooltip_markup, g_free);
3419 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3420 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3421 if (gtk_widget_get_visible (widget))
3422 gtk_widget_queue_tooltip_query (widget);
3424 case PROP_TOOLTIP_TEXT:
3425 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3427 tooltip_text = g_value_get_string (value);
3429 /* Treat an empty string as a NULL string,
3430 * because an empty string would be useless for a tooltip:
3432 if (tooltip_text && (strlen (tooltip_text) == 0))
3433 tooltip_text = NULL;
3435 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3437 g_object_set_qdata_full (object, quark_tooltip_markup,
3438 tooltip_markup, g_free);
3440 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3441 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3442 if (gtk_widget_get_visible (widget))
3443 gtk_widget_queue_tooltip_query (widget);
3445 case PROP_DOUBLE_BUFFERED:
3446 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3449 gtk_widget_set_halign (widget, g_value_get_enum (value));
3452 gtk_widget_set_valign (widget, g_value_get_enum (value));
3454 case PROP_MARGIN_LEFT:
3455 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3457 case PROP_MARGIN_RIGHT:
3458 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3460 case PROP_MARGIN_TOP:
3461 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3463 case PROP_MARGIN_BOTTOM:
3464 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3467 g_object_freeze_notify (G_OBJECT (widget));
3468 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3469 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3470 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3471 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3472 g_object_thaw_notify (G_OBJECT (widget));
3475 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3477 case PROP_HEXPAND_SET:
3478 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3481 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3483 case PROP_VEXPAND_SET:
3484 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3487 g_object_freeze_notify (G_OBJECT (widget));
3488 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3489 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3490 g_object_thaw_notify (G_OBJECT (widget));
3493 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3499 gtk_widget_get_property (GObject *object,
3504 GtkWidget *widget = GTK_WIDGET (object);
3505 GtkWidgetPrivate *priv = widget->priv;
3513 g_value_set_string (value, priv->name);
3515 g_value_set_static_string (value, "");
3518 g_value_set_object (value, priv->parent);
3520 case PROP_WIDTH_REQUEST:
3523 gtk_widget_get_size_request (widget, &w, NULL);
3524 g_value_set_int (value, w);
3527 case PROP_HEIGHT_REQUEST:
3530 gtk_widget_get_size_request (widget, NULL, &h);
3531 g_value_set_int (value, h);
3535 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3537 case PROP_SENSITIVE:
3538 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3540 case PROP_APP_PAINTABLE:
3541 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3543 case PROP_CAN_FOCUS:
3544 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3546 case PROP_HAS_FOCUS:
3547 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3550 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3552 case PROP_CAN_DEFAULT:
3553 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3555 case PROP_HAS_DEFAULT:
3556 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3558 case PROP_RECEIVES_DEFAULT:
3559 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3561 case PROP_COMPOSITE_CHILD:
3562 g_value_set_boolean (value, widget->priv->composite_child);
3565 g_value_set_object (value, gtk_widget_get_style (widget));
3568 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3569 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3571 case PROP_NO_SHOW_ALL:
3572 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3574 case PROP_HAS_TOOLTIP:
3575 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3577 case PROP_TOOLTIP_TEXT:
3579 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3582 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3583 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3585 g_value_take_string (value, text);
3588 case PROP_TOOLTIP_MARKUP:
3589 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3592 g_value_set_object (value, gtk_widget_get_window (widget));
3594 case PROP_DOUBLE_BUFFERED:
3595 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3598 g_value_set_enum (value, gtk_widget_get_halign (widget));
3601 g_value_set_enum (value, gtk_widget_get_valign (widget));
3603 case PROP_MARGIN_LEFT:
3604 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3606 case PROP_MARGIN_RIGHT:
3607 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3609 case PROP_MARGIN_TOP:
3610 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3612 case PROP_MARGIN_BOTTOM:
3613 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3617 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3618 if (aux_info == NULL)
3620 g_value_set_int (value, 0);
3624 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3625 aux_info->margin.right),
3626 MAX (aux_info->margin.top,
3627 aux_info->margin.bottom)));
3632 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3634 case PROP_HEXPAND_SET:
3635 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3638 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3640 case PROP_VEXPAND_SET:
3641 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3644 g_value_set_boolean (value,
3645 gtk_widget_get_hexpand (widget) &&
3646 gtk_widget_get_vexpand (widget));
3649 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3655 gtk_widget_init (GtkWidget *widget)
3657 GtkWidgetPrivate *priv;
3659 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3662 priv = widget->priv;
3664 priv->child_visible = TRUE;
3666 priv->allocation.x = -1;
3667 priv->allocation.y = -1;
3668 priv->allocation.width = 1;
3669 priv->allocation.height = 1;
3670 priv->window = NULL;
3671 priv->parent = NULL;
3673 priv->sensitive = TRUE;
3674 priv->composite_child = composite_child_stack != 0;
3675 priv->double_buffered = TRUE;
3676 priv->redraw_on_alloc = TRUE;
3677 priv->width_request_needed = TRUE;
3678 priv->height_request_needed = TRUE;
3679 priv->alloc_needed = TRUE;
3681 /* this will be set to TRUE if the widget gets a child or if the
3682 * expand flag is set on the widget, but until one of those happen
3683 * we know the expand is already properly FALSE.
3685 * We really want to default FALSE here to avoid computing expand
3686 * all over the place while initially building a widget tree.
3688 priv->need_compute_expand = FALSE;
3690 priv->style = gtk_widget_get_default_style ();
3691 g_object_ref (priv->style);
3696 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3698 GParamSpec **pspecs)
3700 GtkWidgetPrivate *priv = widget->priv;
3701 GtkWidget *container = priv->parent;
3704 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3705 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3709 * gtk_widget_freeze_child_notify:
3710 * @widget: a #GtkWidget
3712 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3713 * signals are queued until gtk_widget_thaw_child_notify() is called
3716 * This is the analogue of g_object_freeze_notify() for child properties.
3719 gtk_widget_freeze_child_notify (GtkWidget *widget)
3721 g_return_if_fail (GTK_IS_WIDGET (widget));
3723 if (!G_OBJECT (widget)->ref_count)
3726 g_object_ref (widget);
3727 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3728 g_object_unref (widget);
3732 * gtk_widget_child_notify:
3733 * @widget: a #GtkWidget
3734 * @child_property: the name of a child property installed on the
3735 * class of @widget<!-- -->'s parent
3737 * Emits a #GtkWidget::child-notify signal for the
3738 * <link linkend="child-properties">child property</link> @child_property
3741 * This is the analogue of g_object_notify() for child properties.
3743 * Also see gtk_container_child_notify().
3746 gtk_widget_child_notify (GtkWidget *widget,
3747 const gchar *child_property)
3749 if (widget->priv->parent == NULL)
3752 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3756 * gtk_widget_thaw_child_notify:
3757 * @widget: a #GtkWidget
3759 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3760 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3764 gtk_widget_thaw_child_notify (GtkWidget *widget)
3766 GObjectNotifyQueue *nqueue;
3768 g_return_if_fail (GTK_IS_WIDGET (widget));
3770 if (!G_OBJECT (widget)->ref_count)
3773 g_object_ref (widget);
3774 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3775 if (!nqueue || !nqueue->freeze_count)
3776 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3777 G_OBJECT_TYPE_NAME (widget), widget);
3779 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3780 g_object_unref (widget);
3786 * @type: type ID of the widget to create
3787 * @first_property_name: name of first property to set
3788 * @...: value of first property, followed by more properties,
3791 * This is a convenience function for creating a widget and setting
3792 * its properties in one go. For example you might write:
3793 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3794 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3795 * g_object_new(), but returns a widget so you don't have to
3796 * cast the object yourself.
3798 * Return value: a new #GtkWidget of type @widget_type
3801 gtk_widget_new (GType type,
3802 const gchar *first_property_name,
3808 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3810 va_start (var_args, first_property_name);
3811 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3818 gtk_widget_queue_draw_child (GtkWidget *widget)
3820 GtkWidgetPrivate *priv = widget->priv;
3823 parent = priv->parent;
3824 if (parent && gtk_widget_is_drawable (parent))
3825 gtk_widget_queue_draw_area (parent,
3828 priv->allocation.width,
3829 priv->allocation.height);
3833 * gtk_widget_unparent:
3834 * @widget: a #GtkWidget
3836 * This function is only for use in widget implementations.
3837 * Should be called by implementations of the remove method
3838 * on #GtkContainer, to dissociate a child from the container.
3841 gtk_widget_unparent (GtkWidget *widget)
3843 GtkWidgetPrivate *priv;
3844 GObjectNotifyQueue *nqueue;
3845 GtkWidget *toplevel;
3846 GtkWidget *old_parent;
3848 g_return_if_fail (GTK_IS_WIDGET (widget));
3850 priv = widget->priv;
3852 if (priv->parent == NULL)
3855 /* keep this function in sync with gtk_menu_detach() */
3857 gtk_widget_push_verify_invariants (widget);
3859 g_object_freeze_notify (G_OBJECT (widget));
3860 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3862 toplevel = gtk_widget_get_toplevel (widget);
3863 if (gtk_widget_is_toplevel (toplevel))
3864 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3866 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3867 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3869 gtk_widget_queue_draw_child (widget);
3871 /* Reset the width and height here, to force reallocation if we
3872 * get added back to a new parent. This won't work if our new
3873 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3874 * (would 0x0 be OK here?)
3876 priv->allocation.width = 1;
3877 priv->allocation.height = 1;
3879 if (gtk_widget_get_realized (widget))
3881 if (priv->in_reparent)
3882 gtk_widget_unmap (widget);
3884 gtk_widget_unrealize (widget);
3887 /* If we are unanchoring the child, we save around the toplevel
3888 * to emit hierarchy changed
3890 if (priv->parent->priv->anchored)
3891 g_object_ref (toplevel);
3895 /* Removing a widget from a container restores the child visible
3896 * flag to the default state, so it doesn't affect the child
3897 * in the next parent.
3899 priv->child_visible = TRUE;
3901 old_parent = priv->parent;
3902 priv->parent = NULL;
3904 /* parent may no longer expand if the removed
3905 * child was expand=TRUE and could therefore
3908 if (gtk_widget_get_visible (widget) &&
3909 (priv->need_compute_expand ||
3910 priv->computed_hexpand ||
3911 priv->computed_vexpand))
3913 gtk_widget_queue_compute_expand (old_parent);
3916 /* Unset BACKDROP since we are no longer inside a toplevel window */
3917 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3919 gtk_style_context_set_parent (priv->context, NULL);
3921 _gtk_widget_update_parent_muxer (widget);
3923 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3926 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3927 g_object_unref (toplevel);
3930 /* Now that the parent pointer is nullified and the hierarchy-changed
3931 * already passed, go ahead and unset the parent window, if we are unparenting
3932 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3933 * will fire again for the new subhierarchy.
3935 gtk_widget_set_parent_window (widget, NULL);
3937 g_object_notify (G_OBJECT (widget), "parent");
3938 g_object_thaw_notify (G_OBJECT (widget));
3940 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3941 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3943 gtk_widget_pop_verify_invariants (widget);
3944 g_object_unref (widget);
3948 * gtk_widget_destroy:
3949 * @widget: a #GtkWidget
3951 * Destroys a widget.
3954 * destroyed, it will break any references it holds to other objects.
3955 * If the widget is inside a container, the widget will be removed
3956 * from the container. If the widget is a toplevel (derived from
3957 * #GtkWindow), it will be removed from the list of toplevels, and the
3958 * reference GTK+ holds to it will be removed. Removing a
3959 * widget from its container or the list of toplevels results in the
3960 * widget being finalized, unless you've added additional references
3961 * to the widget with g_object_ref().
3963 * In most cases, only toplevel widgets (windows) require explicit
3964 * destruction, because when you destroy a toplevel its children will
3965 * be destroyed as well.
3968 gtk_widget_destroy (GtkWidget *widget)
3970 g_return_if_fail (GTK_IS_WIDGET (widget));
3972 if (!widget->priv->in_destruction)
3973 g_object_run_dispose (G_OBJECT (widget));
3977 * gtk_widget_destroyed:
3978 * @widget: a #GtkWidget
3979 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3981 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3982 * %NULL. It's intended to be used as a callback connected to the
3983 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3984 * as a signal handler, and pass the address of your widget variable
3985 * as user data. Then when the widget is destroyed, the variable will
3986 * be set to %NULL. Useful for example to avoid multiple copies
3987 * of the same dialog.
3990 gtk_widget_destroyed (GtkWidget *widget,
3991 GtkWidget **widget_pointer)
3993 /* Don't make any assumptions about the
3995 * Even check widget_pointer.
3998 *widget_pointer = NULL;
4003 * @widget: a #GtkWidget
4005 * Flags a widget to be displayed. Any widget that isn't shown will
4006 * not appear on the screen. If you want to show all the widgets in a
4007 * container, it's easier to call gtk_widget_show_all() on the
4008 * container, instead of individually showing the widgets.
4010 * Remember that you have to show the containers containing a widget,
4011 * in addition to the widget itself, before it will appear onscreen.
4013 * When a toplevel container is shown, it is immediately realized and
4014 * mapped; other shown widgets are realized and mapped when their
4015 * toplevel container is realized and mapped.
4018 gtk_widget_show (GtkWidget *widget)
4020 g_return_if_fail (GTK_IS_WIDGET (widget));
4022 if (!gtk_widget_get_visible (widget))
4024 g_object_ref (widget);
4025 gtk_widget_push_verify_invariants (widget);
4027 if (!gtk_widget_is_toplevel (widget))
4028 gtk_widget_queue_resize (widget);
4030 /* see comment in set_parent() for why this should and can be
4033 if (widget->priv->need_compute_expand ||
4034 widget->priv->computed_hexpand ||
4035 widget->priv->computed_vexpand)
4037 if (widget->priv->parent != NULL)
4038 gtk_widget_queue_compute_expand (widget->priv->parent);
4041 g_signal_emit (widget, widget_signals[SHOW], 0);
4042 g_object_notify (G_OBJECT (widget), "visible");
4044 gtk_widget_pop_verify_invariants (widget);
4045 g_object_unref (widget);
4050 gtk_widget_real_show (GtkWidget *widget)
4052 GtkWidgetPrivate *priv = widget->priv;
4054 if (!gtk_widget_get_visible (widget))
4056 priv->visible = TRUE;
4059 gtk_widget_get_mapped (priv->parent) &&
4060 gtk_widget_get_child_visible (widget) &&
4061 !gtk_widget_get_mapped (widget))
4062 gtk_widget_map (widget);
4067 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4070 g_signal_handlers_disconnect_by_func (widget,
4071 gtk_widget_show_map_callback,
4076 * gtk_widget_show_now:
4077 * @widget: a #GtkWidget
4079 * Shows a widget. If the widget is an unmapped toplevel widget
4080 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4081 * loop and wait for the window to actually be mapped. Be careful;
4082 * because the main loop is running, anything can happen during
4086 gtk_widget_show_now (GtkWidget *widget)
4090 g_return_if_fail (GTK_IS_WIDGET (widget));
4092 /* make sure we will get event */
4093 if (!gtk_widget_get_mapped (widget) &&
4094 gtk_widget_is_toplevel (widget))
4096 gtk_widget_show (widget);
4098 g_signal_connect (widget, "map-event",
4099 G_CALLBACK (gtk_widget_show_map_callback),
4103 gtk_main_iteration ();
4106 gtk_widget_show (widget);
4111 * @widget: a #GtkWidget
4113 * Reverses the effects of gtk_widget_show(), causing the widget to be
4114 * hidden (invisible to the user).
4117 gtk_widget_hide (GtkWidget *widget)
4119 g_return_if_fail (GTK_IS_WIDGET (widget));
4121 if (gtk_widget_get_visible (widget))
4123 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4125 g_object_ref (widget);
4126 gtk_widget_push_verify_invariants (widget);
4128 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4129 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4131 /* a parent may now be expand=FALSE since we're hidden. */
4132 if (widget->priv->need_compute_expand ||
4133 widget->priv->computed_hexpand ||
4134 widget->priv->computed_vexpand)
4136 gtk_widget_queue_compute_expand (widget);
4139 g_signal_emit (widget, widget_signals[HIDE], 0);
4140 if (!gtk_widget_is_toplevel (widget))
4141 gtk_widget_queue_resize (widget);
4142 g_object_notify (G_OBJECT (widget), "visible");
4144 gtk_widget_pop_verify_invariants (widget);
4145 g_object_unref (widget);
4150 gtk_widget_real_hide (GtkWidget *widget)
4152 if (gtk_widget_get_visible (widget))
4154 widget->priv->visible = FALSE;
4156 if (gtk_widget_get_mapped (widget))
4157 gtk_widget_unmap (widget);
4162 * gtk_widget_hide_on_delete:
4163 * @widget: a #GtkWidget
4165 * Utility function; intended to be connected to the #GtkWidget::delete-event
4166 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4167 * argument, then returns %TRUE. If connected to ::delete-event, the
4168 * result is that clicking the close button for a window (on the
4169 * window frame, top right corner usually) will hide but not destroy
4170 * the window. By default, GTK+ destroys windows when ::delete-event
4173 * Return value: %TRUE
4176 gtk_widget_hide_on_delete (GtkWidget *widget)
4178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4180 gtk_widget_hide (widget);
4186 * gtk_widget_show_all:
4187 * @widget: a #GtkWidget
4189 * Recursively shows a widget, and any child widgets (if the widget is
4193 gtk_widget_show_all (GtkWidget *widget)
4195 GtkWidgetClass *class;
4197 g_return_if_fail (GTK_IS_WIDGET (widget));
4199 if (gtk_widget_get_no_show_all (widget))
4202 class = GTK_WIDGET_GET_CLASS (widget);
4204 if (class->show_all)
4205 class->show_all (widget);
4210 * @widget: a #GtkWidget
4212 * This function is only for use in widget implementations. Causes
4213 * a widget to be mapped if it isn't already.
4216 gtk_widget_map (GtkWidget *widget)
4218 GtkWidgetPrivate *priv;
4220 g_return_if_fail (GTK_IS_WIDGET (widget));
4221 g_return_if_fail (gtk_widget_get_visible (widget));
4222 g_return_if_fail (gtk_widget_get_child_visible (widget));
4224 priv = widget->priv;
4226 if (!gtk_widget_get_mapped (widget))
4228 gtk_widget_push_verify_invariants (widget);
4230 if (!gtk_widget_get_realized (widget))
4231 gtk_widget_realize (widget);
4233 g_signal_emit (widget, widget_signals[MAP], 0);
4235 if (!gtk_widget_get_has_window (widget))
4236 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4238 if (widget->priv->context)
4239 _gtk_style_context_update_animating (widget->priv->context);
4241 gtk_widget_pop_verify_invariants (widget);
4247 * @widget: a #GtkWidget
4249 * This function is only for use in widget implementations. Causes
4250 * a widget to be unmapped if it's currently mapped.
4253 gtk_widget_unmap (GtkWidget *widget)
4255 GtkWidgetPrivate *priv;
4257 g_return_if_fail (GTK_IS_WIDGET (widget));
4259 priv = widget->priv;
4261 if (gtk_widget_get_mapped (widget))
4263 gtk_widget_push_verify_invariants (widget);
4265 if (!gtk_widget_get_has_window (widget))
4266 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4267 _gtk_tooltip_hide (widget);
4269 if (widget->priv->context)
4270 _gtk_style_context_update_animating (widget->priv->context);
4272 g_signal_emit (widget, widget_signals[UNMAP], 0);
4274 gtk_widget_pop_verify_invariants (widget);
4276 /* Unset pointer/window info */
4277 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4282 _gtk_widget_enable_device_events (GtkWidget *widget)
4284 GHashTable *device_events;
4285 GHashTableIter iter;
4286 gpointer key, value;
4288 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4293 g_hash_table_iter_init (&iter, device_events);
4295 while (g_hash_table_iter_next (&iter, &key, &value))
4298 GdkEventMask event_mask;
4301 event_mask = GPOINTER_TO_UINT (value);
4302 gtk_widget_add_events_internal (widget, device, event_mask);
4307 get_widget_windows (GtkWidget *widget)
4309 GList *window_list, *last, *l, *children, *ret;
4311 if (gtk_widget_get_has_window (widget))
4312 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4314 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4316 last = g_list_last (window_list);
4319 for (l = window_list; l; l = l->next)
4321 GtkWidget *window_widget = NULL;
4323 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4325 if (widget != window_widget)
4328 ret = g_list_prepend (ret, l->data);
4329 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4333 last = g_list_concat (last, children);
4334 last = g_list_last (last);
4338 g_list_free (window_list);
4344 device_enable_foreach (GtkWidget *widget,
4347 GdkDevice *device = user_data;
4348 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4352 device_disable_foreach (GtkWidget *widget,
4355 GdkDevice *device = user_data;
4356 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4360 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4365 GList *window_list, *l;
4367 window_list = get_widget_windows (widget);
4369 for (l = window_list; l; l = l->next)
4371 GdkEventMask events = 0;
4377 events = gdk_window_get_events (window);
4379 gdk_window_set_device_events (window, device, events);
4382 if (recurse && GTK_IS_CONTAINER (widget))
4385 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4387 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4390 g_list_free (window_list);
4394 gtk_widget_update_devices_mask (GtkWidget *widget,
4397 GList *enabled_devices, *l;
4399 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4401 for (l = enabled_devices; l; l = l->next)
4402 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4406 * gtk_widget_realize:
4407 * @widget: a #GtkWidget
4409 * Creates the GDK (windowing system) resources associated with a
4410 * widget. For example, @widget->window will be created when a widget
4411 * is realized. Normally realization happens implicitly; if you show
4412 * a widget and all its parent containers, then the widget will be
4413 * realized and mapped automatically.
4415 * Realizing a widget requires all
4416 * the widget's parent widgets to be realized; calling
4417 * gtk_widget_realize() realizes the widget's parents in addition to
4418 * @widget itself. If a widget is not yet inside a toplevel window
4419 * when you realize it, bad things will happen.
4421 * This function is primarily used in widget implementations, and
4422 * isn't very useful otherwise. Many times when you think you might
4423 * need it, a better approach is to connect to a signal that will be
4424 * called after the widget is realized automatically, such as
4425 * #GtkWidget::draw. Or simply g_signal_connect () to the
4426 * #GtkWidget::realize signal.
4429 gtk_widget_realize (GtkWidget *widget)
4431 GtkWidgetPrivate *priv;
4432 cairo_region_t *region;
4434 g_return_if_fail (GTK_IS_WIDGET (widget));
4435 g_return_if_fail (widget->priv->anchored ||
4436 GTK_IS_INVISIBLE (widget));
4438 priv = widget->priv;
4440 if (!gtk_widget_get_realized (widget))
4442 gtk_widget_push_verify_invariants (widget);
4445 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4446 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4449 if (priv->parent == NULL &&
4450 !gtk_widget_is_toplevel (widget))
4451 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4452 "inside a toplevel window is not going to work very well. "
4453 "Widgets must be inside a toplevel container before realizing them.");
4455 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4456 gtk_widget_realize (priv->parent);
4458 gtk_widget_ensure_style (widget);
4460 if (priv->style_update_pending)
4461 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4463 g_signal_emit (widget, widget_signals[REALIZE], 0);
4465 gtk_widget_real_set_has_tooltip (widget,
4466 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4469 if (priv->has_shape_mask)
4471 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4472 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4475 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4477 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4479 if (priv->multidevice)
4480 gdk_window_set_support_multidevice (priv->window, TRUE);
4482 _gtk_widget_enable_device_events (widget);
4483 gtk_widget_update_devices_mask (widget, TRUE);
4485 gtk_widget_pop_verify_invariants (widget);
4490 * gtk_widget_unrealize:
4491 * @widget: a #GtkWidget
4493 * This function is only useful in widget implementations.
4494 * Causes a widget to be unrealized (frees all GDK resources
4495 * associated with the widget, such as @widget->window).
4498 gtk_widget_unrealize (GtkWidget *widget)
4500 g_return_if_fail (GTK_IS_WIDGET (widget));
4502 gtk_widget_push_verify_invariants (widget);
4504 if (widget->priv->has_shape_mask)
4505 gtk_widget_shape_combine_region (widget, NULL);
4507 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4508 gtk_widget_input_shape_combine_region (widget, NULL);
4510 if (gtk_widget_get_realized (widget))
4512 g_object_ref (widget);
4514 if (widget->priv->mapped)
4515 gtk_widget_unmap (widget);
4517 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4518 g_assert (!widget->priv->mapped);
4519 gtk_widget_set_realized (widget, FALSE);
4521 g_object_unref (widget);
4524 gtk_widget_pop_verify_invariants (widget);
4527 /*****************************************
4529 *****************************************/
4532 * gtk_widget_queue_draw_region:
4533 * @widget: a #GtkWidget
4534 * @region: region to draw
4536 * Invalidates the rectangular area of @widget defined by @region by
4537 * calling gdk_window_invalidate_region() on the widget's window and
4538 * all its child windows. Once the main loop becomes idle (after the
4539 * current batch of events has been processed, roughly), the window
4540 * will receive expose events for the union of all regions that have
4543 * Normally you would only use this function in widget
4544 * implementations. You might also use it to schedule a redraw of a
4545 * #GtkDrawingArea or some portion thereof.
4550 gtk_widget_queue_draw_region (GtkWidget *widget,
4551 const cairo_region_t *region)
4553 GtkWidgetPrivate *priv;
4556 g_return_if_fail (GTK_IS_WIDGET (widget));
4558 priv = widget->priv;
4560 if (!gtk_widget_get_realized (widget))
4563 /* Just return if the widget or one of its ancestors isn't mapped */
4564 for (w = widget; w != NULL; w = w->priv->parent)
4565 if (!gtk_widget_get_mapped (w))
4568 gdk_window_invalidate_region (priv->window, region, TRUE);
4572 * gtk_widget_queue_draw_area:
4573 * @widget: a #GtkWidget
4574 * @x: x coordinate of upper-left corner of rectangle to redraw
4575 * @y: y coordinate of upper-left corner of rectangle to redraw
4576 * @width: width of region to draw
4577 * @height: height of region to draw
4579 * Convenience function that calls gtk_widget_queue_draw_region() on
4580 * the region created from the given coordinates.
4582 * The region here is specified in widget coordinates.
4583 * Widget coordinates are a bit odd; for historical reasons, they are
4584 * defined as @widget->window coordinates for widgets that are not
4585 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4586 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4589 gtk_widget_queue_draw_area (GtkWidget *widget,
4596 cairo_region_t *region;
4598 g_return_if_fail (GTK_IS_WIDGET (widget));
4603 rect.height = height;
4605 region = cairo_region_create_rectangle (&rect);
4606 gtk_widget_queue_draw_region (widget, region);
4607 cairo_region_destroy (region);
4611 * gtk_widget_queue_draw:
4612 * @widget: a #GtkWidget
4614 * Equivalent to calling gtk_widget_queue_draw_area() for the
4615 * entire area of a widget.
4618 gtk_widget_queue_draw (GtkWidget *widget)
4622 g_return_if_fail (GTK_IS_WIDGET (widget));
4624 gtk_widget_get_allocation (widget, &rect);
4626 if (!gtk_widget_get_has_window (widget))
4627 gtk_widget_queue_draw_area (widget,
4628 rect.x, rect.y, rect.width, rect.height);
4630 gtk_widget_queue_draw_area (widget,
4631 0, 0, rect.width, rect.height);
4635 * gtk_widget_queue_resize:
4636 * @widget: a #GtkWidget
4638 * This function is only for use in widget implementations.
4639 * Flags a widget to have its size renegotiated; should
4640 * be called when a widget for some reason has a new size request.
4641 * For example, when you change the text in a #GtkLabel, #GtkLabel
4642 * queues a resize to ensure there's enough space for the new text.
4644 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4645 * from inside its implementation of the GtkWidgetClass::size_allocate
4646 * virtual method. Calls to gtk_widget_queue_resize() from inside
4647 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4650 gtk_widget_queue_resize (GtkWidget *widget)
4652 g_return_if_fail (GTK_IS_WIDGET (widget));
4654 if (gtk_widget_get_realized (widget))
4655 gtk_widget_queue_draw (widget);
4657 _gtk_size_group_queue_resize (widget, 0);
4661 * gtk_widget_queue_resize_no_redraw:
4662 * @widget: a #GtkWidget
4664 * This function works like gtk_widget_queue_resize(),
4665 * except that the widget is not invalidated.
4670 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4672 g_return_if_fail (GTK_IS_WIDGET (widget));
4674 _gtk_size_group_queue_resize (widget, 0);
4678 * gtk_widget_size_request:
4679 * @widget: a #GtkWidget
4680 * @requisition: (out): a #GtkRequisition to be filled in
4682 * This function is typically used when implementing a #GtkContainer
4683 * subclass. Obtains the preferred size of a widget. The container
4684 * uses this information to arrange its child widgets and decide what
4685 * size allocations to give them with gtk_widget_size_allocate().
4687 * You can also call this function from an application, with some
4688 * caveats. Most notably, getting a size request requires the widget
4689 * to be associated with a screen, because font information may be
4690 * needed. Multihead-aware applications should keep this in mind.
4692 * Also remember that the size request is not necessarily the size
4693 * a widget will actually be allocated.
4695 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4698 gtk_widget_size_request (GtkWidget *widget,
4699 GtkRequisition *requisition)
4701 g_return_if_fail (GTK_IS_WIDGET (widget));
4703 gtk_widget_get_preferred_size (widget, requisition, NULL);
4707 * gtk_widget_get_child_requisition:
4708 * @widget: a #GtkWidget
4709 * @requisition: (out): a #GtkRequisition to be filled in
4711 * This function is only for use in widget implementations. Obtains
4712 * @widget->requisition, unless someone has forced a particular
4713 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4714 * in which case it returns that geometry instead of the widget's
4717 * This function differs from gtk_widget_size_request() in that
4718 * it retrieves the last size request value from @widget->requisition,
4719 * while gtk_widget_size_request() actually calls the "size_request" method
4720 * on @widget to compute the size request and fill in @widget->requisition,
4721 * and only then returns @widget->requisition.
4723 * Because this function does not call the "size_request" method, it
4724 * can only be used when you know that @widget->requisition is
4725 * up-to-date, that is, gtk_widget_size_request() has been called
4726 * since the last time a resize was queued. In general, only container
4727 * implementations have this information; applications should use
4728 * gtk_widget_size_request().
4731 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4734 gtk_widget_get_child_requisition (GtkWidget *widget,
4735 GtkRequisition *requisition)
4737 gtk_widget_get_preferred_size (widget, requisition, NULL);
4741 invalidate_predicate (GdkWindow *window,
4746 gdk_window_get_user_data (window, &user_data);
4748 return (user_data == data);
4751 /* Invalidate @region in widget->window and all children
4752 * of widget->window owned by widget. @region is in the
4753 * same coordinates as widget->allocation and will be
4754 * modified by this call.
4757 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4758 cairo_region_t *region)
4760 GtkWidgetPrivate *priv = widget->priv;
4762 if (!gtk_widget_get_realized (widget))
4765 if (gtk_widget_get_has_window (widget) && priv->parent)
4769 gdk_window_get_position (priv->window, &x, &y);
4770 cairo_region_translate (region, -x, -y);
4773 gdk_window_invalidate_maybe_recurse (priv->window, region,
4774 invalidate_predicate, widget);
4778 * gtk_widget_size_allocate:
4779 * @widget: a #GtkWidget
4780 * @allocation: position and size to be allocated to @widget
4782 * This function is only used by #GtkContainer subclasses, to assign a size
4783 * and position to their child widgets.
4785 * In this function, the allocation may be adjusted. It will be forced
4786 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4787 * method on the child will be used to adjust the allocation. Standard
4788 * adjustments include removing the widget's margins, and applying the
4789 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4792 gtk_widget_size_allocate (GtkWidget *widget,
4793 GtkAllocation *allocation)
4795 GtkWidgetPrivate *priv;
4796 GdkRectangle real_allocation;
4797 GdkRectangle old_allocation;
4798 GdkRectangle adjusted_allocation;
4799 gboolean alloc_needed;
4800 gboolean size_changed;
4801 gboolean position_changed;
4802 gint natural_width, natural_height, dummy;
4803 gint min_width, min_height;
4805 priv = widget->priv;
4807 g_return_if_fail (GTK_IS_WIDGET (widget));
4809 gtk_widget_push_verify_invariants (widget);
4811 #ifdef G_ENABLE_DEBUG
4812 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4823 parent = gtk_widget_get_parent (parent);
4826 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4827 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4828 2 * depth, " ", name,
4829 allocation->width, allocation->height);
4831 #endif /* G_ENABLE_DEBUG */
4833 alloc_needed = priv->alloc_needed;
4834 if (!priv->width_request_needed && !priv->height_request_needed)
4835 /* Preserve request/allocate ordering */
4836 priv->alloc_needed = FALSE;
4838 old_allocation = priv->allocation;
4839 real_allocation = *allocation;
4841 adjusted_allocation = real_allocation;
4842 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4844 /* Go ahead and request the height for allocated width, note that the internals
4845 * of get_height_for_width will internally limit the for_size to natural size
4846 * when aligning implicitly.
4848 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4849 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4853 /* Go ahead and request the width for allocated height, note that the internals
4854 * of get_width_for_height will internally limit the for_size to natural size
4855 * when aligning implicitly.
4857 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4858 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4861 #ifdef G_ENABLE_DEBUG
4862 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4864 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4865 !GTK_IS_SCROLLABLE (widget))
4866 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4867 "Allocation is %dx%d, but minimum required size is %dx%d.",
4868 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4869 G_OBJECT_TYPE_NAME (widget), widget,
4870 real_allocation.width, real_allocation.height,
4871 min_width, min_height);
4874 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4875 * allocated sizes and possibly limit them to the natural sizes */
4876 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4877 GTK_ORIENTATION_HORIZONTAL,
4880 &adjusted_allocation.x,
4881 &adjusted_allocation.width);
4882 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4883 GTK_ORIENTATION_VERTICAL,
4886 &adjusted_allocation.y,
4887 &adjusted_allocation.height);
4889 if (adjusted_allocation.x < real_allocation.x ||
4890 adjusted_allocation.y < real_allocation.y ||
4891 (adjusted_allocation.x + adjusted_allocation.width) >
4892 (real_allocation.x + real_allocation.width) ||
4893 (adjusted_allocation.y + adjusted_allocation.height >
4894 real_allocation.y + real_allocation.height))
4896 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",
4897 G_OBJECT_TYPE_NAME (widget), widget,
4898 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4899 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4900 adjusted_allocation = real_allocation; /* veto it */
4904 real_allocation = adjusted_allocation;
4907 if (real_allocation.width < 0 || real_allocation.height < 0)
4909 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4910 real_allocation.width,
4911 real_allocation.height);
4914 real_allocation.width = MAX (real_allocation.width, 1);
4915 real_allocation.height = MAX (real_allocation.height, 1);
4917 size_changed = (old_allocation.width != real_allocation.width ||
4918 old_allocation.height != real_allocation.height);
4919 position_changed = (old_allocation.x != real_allocation.x ||
4920 old_allocation.y != real_allocation.y);
4922 if (!alloc_needed && !size_changed && !position_changed)
4925 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4927 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4928 priv->width_request_needed = FALSE;
4929 priv->height_request_needed = FALSE;
4930 priv->alloc_needed = FALSE;
4932 if (gtk_widget_get_mapped (widget))
4934 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4936 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4938 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4939 cairo_region_union_rectangle (invalidate, &old_allocation);
4941 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4942 cairo_region_destroy (invalidate);
4947 if (priv->redraw_on_alloc)
4949 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4951 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4952 cairo_region_union_rectangle (invalidate, &old_allocation);
4954 gtk_widget_invalidate_widget_windows (widget, invalidate);
4955 cairo_region_destroy (invalidate);
4960 if ((size_changed || position_changed) && priv->parent &&
4961 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4963 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4964 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4965 cairo_region_destroy (invalidate);
4969 gtk_widget_pop_verify_invariants (widget);
4973 * gtk_widget_common_ancestor:
4974 * @widget_a: a #GtkWidget
4975 * @widget_b: a #GtkWidget
4977 * Find the common ancestor of @widget_a and @widget_b that
4978 * is closest to the two widgets.
4980 * Return value: the closest common ancestor of @widget_a and
4981 * @widget_b or %NULL if @widget_a and @widget_b do not
4982 * share a common ancestor.
4985 gtk_widget_common_ancestor (GtkWidget *widget_a,
4986 GtkWidget *widget_b)
4988 GtkWidget *parent_a;
4989 GtkWidget *parent_b;
4993 parent_a = widget_a;
4994 while (parent_a->priv->parent)
4996 parent_a = parent_a->priv->parent;
5000 parent_b = widget_b;
5001 while (parent_b->priv->parent)
5003 parent_b = parent_b->priv->parent;
5007 if (parent_a != parent_b)
5010 while (depth_a > depth_b)
5012 widget_a = widget_a->priv->parent;
5016 while (depth_b > depth_a)
5018 widget_b = widget_b->priv->parent;
5022 while (widget_a != widget_b)
5024 widget_a = widget_a->priv->parent;
5025 widget_b = widget_b->priv->parent;
5032 * gtk_widget_translate_coordinates:
5033 * @src_widget: a #GtkWidget
5034 * @dest_widget: a #GtkWidget
5035 * @src_x: X position relative to @src_widget
5036 * @src_y: Y position relative to @src_widget
5037 * @dest_x: (out): location to store X position relative to @dest_widget
5038 * @dest_y: (out): location to store Y position relative to @dest_widget
5040 * Translate coordinates relative to @src_widget's allocation to coordinates
5041 * relative to @dest_widget's allocations. In order to perform this
5042 * operation, both widgets must be realized, and must share a common
5045 * Return value: %FALSE if either widget was not realized, or there
5046 * was no common ancestor. In this case, nothing is stored in
5047 * *@dest_x and *@dest_y. Otherwise %TRUE.
5050 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5051 GtkWidget *dest_widget,
5057 GtkWidgetPrivate *src_priv = src_widget->priv;
5058 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5059 GtkWidget *ancestor;
5061 GList *dest_list = NULL;
5063 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5064 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5066 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5067 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5070 /* Translate from allocation relative to window relative */
5071 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5074 gdk_window_get_position (src_priv->window, &wx, &wy);
5076 src_x -= wx - src_priv->allocation.x;
5077 src_y -= wy - src_priv->allocation.y;
5081 src_x += src_priv->allocation.x;
5082 src_y += src_priv->allocation.y;
5085 /* Translate to the common ancestor */
5086 window = src_priv->window;
5087 while (window != ancestor->priv->window)
5091 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5096 window = gdk_window_get_effective_parent (window);
5098 if (!window) /* Handle GtkHandleBox */
5103 window = dest_priv->window;
5104 while (window != ancestor->priv->window)
5106 dest_list = g_list_prepend (dest_list, window);
5108 window = gdk_window_get_effective_parent (window);
5110 if (!window) /* Handle GtkHandleBox */
5112 g_list_free (dest_list);
5121 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5126 dest_list = g_list_remove (dest_list, dest_list->data);
5129 /* Translate from window relative to allocation relative */
5130 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5133 gdk_window_get_position (dest_priv->window, &wx, &wy);
5135 src_x += wx - dest_priv->allocation.x;
5136 src_y += wy - dest_priv->allocation.y;
5140 src_x -= dest_priv->allocation.x;
5141 src_y -= dest_priv->allocation.y;
5153 gtk_widget_real_size_allocate (GtkWidget *widget,
5154 GtkAllocation *allocation)
5156 GtkWidgetPrivate *priv = widget->priv;
5158 priv->allocation = *allocation;
5160 if (gtk_widget_get_realized (widget) &&
5161 gtk_widget_get_has_window (widget))
5163 gdk_window_move_resize (priv->window,
5164 allocation->x, allocation->y,
5165 allocation->width, allocation->height);
5169 /* translate initial/final into start/end */
5171 effective_align (GtkAlign align,
5172 GtkTextDirection direction)
5176 case GTK_ALIGN_START:
5177 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5179 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5186 adjust_for_align (GtkAlign align,
5188 gint *allocated_pos,
5189 gint *allocated_size)
5193 case GTK_ALIGN_FILL:
5194 /* change nothing */
5196 case GTK_ALIGN_START:
5197 /* keep *allocated_pos where it is */
5198 *allocated_size = MIN (*allocated_size, *natural_size);
5201 if (*allocated_size > *natural_size)
5203 *allocated_pos += (*allocated_size - *natural_size);
5204 *allocated_size = *natural_size;
5207 case GTK_ALIGN_CENTER:
5208 if (*allocated_size > *natural_size)
5210 *allocated_pos += (*allocated_size - *natural_size) / 2;
5211 *allocated_size = MIN (*allocated_size, *natural_size);
5218 adjust_for_margin(gint start_margin,
5222 gint *allocated_pos,
5223 gint *allocated_size)
5225 *minimum_size -= (start_margin + end_margin);
5226 *natural_size -= (start_margin + end_margin);
5227 *allocated_pos += start_margin;
5228 *allocated_size -= (start_margin + end_margin);
5232 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5233 GtkOrientation orientation,
5236 gint *allocated_pos,
5237 gint *allocated_size)
5239 const GtkWidgetAuxInfo *aux_info;
5241 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5243 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5245 adjust_for_margin (aux_info->margin.left,
5246 aux_info->margin.right,
5247 minimum_size, natural_size,
5248 allocated_pos, allocated_size);
5249 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5250 natural_size, allocated_pos, allocated_size);
5254 adjust_for_margin (aux_info->margin.top,
5255 aux_info->margin.bottom,
5256 minimum_size, natural_size,
5257 allocated_pos, allocated_size);
5258 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5259 natural_size, allocated_pos, allocated_size);
5264 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5267 GtkWidgetPrivate *priv = widget->priv;
5269 /* widgets must be onscreen for accels to take effect */
5270 return gtk_widget_is_sensitive (widget) &&
5271 gtk_widget_is_drawable (widget) &&
5272 gdk_window_is_viewable (priv->window);
5276 * gtk_widget_can_activate_accel:
5277 * @widget: a #GtkWidget
5278 * @signal_id: the ID of a signal installed on @widget
5280 * Determines whether an accelerator that activates the signal
5281 * identified by @signal_id can currently be activated.
5282 * This is done by emitting the #GtkWidget::can-activate-accel
5283 * signal on @widget; if the signal isn't overridden by a
5284 * handler or in a derived widget, then the default check is
5285 * that the widget must be sensitive, and the widget and all
5286 * its ancestors mapped.
5288 * Return value: %TRUE if the accelerator can be activated.
5293 gtk_widget_can_activate_accel (GtkWidget *widget,
5296 gboolean can_activate = FALSE;
5297 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5298 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5299 return can_activate;
5308 closure_accel_activate (GClosure *closure,
5309 GValue *return_value,
5310 guint n_param_values,
5311 const GValue *param_values,
5312 gpointer invocation_hint,
5313 gpointer marshal_data)
5315 AccelClosure *aclosure = (AccelClosure*) closure;
5316 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5319 g_signal_emit (closure->data, aclosure->signal_id, 0);
5321 /* whether accelerator was handled */
5322 g_value_set_boolean (return_value, can_activate);
5326 closures_destroy (gpointer data)
5328 GSList *slist, *closures = data;
5330 for (slist = closures; slist; slist = slist->next)
5332 g_closure_invalidate (slist->data);
5333 g_closure_unref (slist->data);
5335 g_slist_free (closures);
5339 widget_new_accel_closure (GtkWidget *widget,
5342 AccelClosure *aclosure;
5343 GClosure *closure = NULL;
5344 GSList *slist, *closures;
5346 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5347 for (slist = closures; slist; slist = slist->next)
5348 if (!gtk_accel_group_from_accel_closure (slist->data))
5350 /* reuse this closure */
5351 closure = slist->data;
5356 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5357 closures = g_slist_prepend (closures, g_closure_ref (closure));
5358 g_closure_sink (closure);
5359 g_closure_set_marshal (closure, closure_accel_activate);
5361 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5363 aclosure = (AccelClosure*) closure;
5364 g_assert (closure->data == widget);
5365 g_assert (closure->marshal == closure_accel_activate);
5366 aclosure->signal_id = signal_id;
5372 * gtk_widget_add_accelerator:
5373 * @widget: widget to install an accelerator on
5374 * @accel_signal: widget signal to emit on accelerator activation
5375 * @accel_group: accel group for this widget, added to its toplevel
5376 * @accel_key: GDK keyval of the accelerator
5377 * @accel_mods: modifier key combination of the accelerator
5378 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5380 * Installs an accelerator for this @widget in @accel_group that causes
5381 * @accel_signal to be emitted if the accelerator is activated.
5382 * The @accel_group needs to be added to the widget's toplevel via
5383 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5384 * Accelerators added through this function are not user changeable during
5385 * runtime. If you want to support accelerators that can be changed by the
5386 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5387 * gtk_menu_item_set_accel_path() instead.
5390 gtk_widget_add_accelerator (GtkWidget *widget,
5391 const gchar *accel_signal,
5392 GtkAccelGroup *accel_group,
5394 GdkModifierType accel_mods,
5395 GtkAccelFlags accel_flags)
5400 g_return_if_fail (GTK_IS_WIDGET (widget));
5401 g_return_if_fail (accel_signal != NULL);
5402 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5404 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5405 if (!query.signal_id ||
5406 !(query.signal_flags & G_SIGNAL_ACTION) ||
5407 query.return_type != G_TYPE_NONE ||
5410 /* hmm, should be elaborate enough */
5411 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5412 G_OBJECT_TYPE_NAME (widget), accel_signal);
5416 closure = widget_new_accel_closure (widget, query.signal_id);
5418 g_object_ref (widget);
5420 /* install the accelerator. since we don't map this onto an accel_path,
5421 * the accelerator will automatically be locked.
5423 gtk_accel_group_connect (accel_group,
5426 accel_flags | GTK_ACCEL_LOCKED,
5429 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5431 g_object_unref (widget);
5435 * gtk_widget_remove_accelerator:
5436 * @widget: widget to install an accelerator on
5437 * @accel_group: accel group for this widget
5438 * @accel_key: GDK keyval of the accelerator
5439 * @accel_mods: modifier key combination of the accelerator
5441 * Removes an accelerator from @widget, previously installed with
5442 * gtk_widget_add_accelerator().
5444 * Returns: whether an accelerator was installed and could be removed
5447 gtk_widget_remove_accelerator (GtkWidget *widget,
5448 GtkAccelGroup *accel_group,
5450 GdkModifierType accel_mods)
5452 GtkAccelGroupEntry *ag_entry;
5453 GList *slist, *clist;
5456 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5457 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5459 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5460 clist = gtk_widget_list_accel_closures (widget);
5461 for (slist = clist; slist; slist = slist->next)
5465 for (i = 0; i < n; i++)
5466 if (slist->data == (gpointer) ag_entry[i].closure)
5468 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5470 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5472 g_list_free (clist);
5477 g_list_free (clist);
5479 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5480 accel_key, accel_mods, accel_group,
5481 G_OBJECT_TYPE_NAME (widget), widget);
5487 * gtk_widget_list_accel_closures:
5488 * @widget: widget to list accelerator closures for
5490 * Lists the closures used by @widget for accelerator group connections
5491 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5492 * The closures can be used to monitor accelerator changes on @widget,
5493 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5494 * #GtkAccelGroup of a closure which can be found out with
5495 * gtk_accel_group_from_accel_closure().
5497 * Return value: (transfer container) (element-type GClosure):
5498 * a newly allocated #GList of closures
5501 gtk_widget_list_accel_closures (GtkWidget *widget)
5504 GList *clist = NULL;
5506 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5508 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5509 if (gtk_accel_group_from_accel_closure (slist->data))
5510 clist = g_list_prepend (clist, slist->data);
5516 GtkAccelGroup *accel_group;
5521 destroy_accel_path (gpointer data)
5523 AccelPath *apath = data;
5525 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5527 /* closures_destroy takes care of unrefing the closure */
5528 g_object_unref (apath->accel_group);
5530 g_slice_free (AccelPath, apath);
5535 * gtk_widget_set_accel_path:
5536 * @widget: a #GtkWidget
5537 * @accel_path: (allow-none): path used to look up the accelerator
5538 * @accel_group: (allow-none): a #GtkAccelGroup.
5540 * Given an accelerator group, @accel_group, and an accelerator path,
5541 * @accel_path, sets up an accelerator in @accel_group so whenever the
5542 * key binding that is defined for @accel_path is pressed, @widget
5543 * will be activated. This removes any accelerators (for any
5544 * accelerator group) installed by previous calls to
5545 * gtk_widget_set_accel_path(). Associating accelerators with
5546 * paths allows them to be modified by the user and the modifications
5547 * to be saved for future use. (See gtk_accel_map_save().)
5549 * This function is a low level function that would most likely
5550 * be used by a menu creation system like #GtkUIManager. If you
5551 * use #GtkUIManager, setting up accelerator paths will be done
5554 * Even when you you aren't using #GtkUIManager, if you only want to
5555 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5556 * provides a somewhat more convenient interface.
5558 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5559 * pass a static string, you can save some memory by interning it first with
5560 * g_intern_static_string().
5563 gtk_widget_set_accel_path (GtkWidget *widget,
5564 const gchar *accel_path,
5565 GtkAccelGroup *accel_group)
5569 g_return_if_fail (GTK_IS_WIDGET (widget));
5570 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5574 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5575 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5577 gtk_accel_map_add_entry (accel_path, 0, 0);
5578 apath = g_slice_new (AccelPath);
5579 apath->accel_group = g_object_ref (accel_group);
5580 apath->path_quark = g_quark_from_string (accel_path);
5581 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5586 /* also removes possible old settings */
5587 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5590 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5592 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5596 _gtk_widget_get_accel_path (GtkWidget *widget,
5601 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5603 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5605 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5606 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5610 * gtk_widget_mnemonic_activate:
5611 * @widget: a #GtkWidget
5612 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5614 * Emits the #GtkWidget::mnemonic-activate signal.
5616 * The default handler for this signal activates the @widget if
5617 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5620 * Returns: %TRUE if the signal has been handled
5623 gtk_widget_mnemonic_activate (GtkWidget *widget,
5624 gboolean group_cycling)
5628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5630 group_cycling = group_cycling != FALSE;
5631 if (!gtk_widget_is_sensitive (widget))
5634 g_signal_emit (widget,
5635 widget_signals[MNEMONIC_ACTIVATE],
5643 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5644 gboolean group_cycling)
5646 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5647 gtk_widget_activate (widget);
5648 else if (gtk_widget_get_can_focus (widget))
5649 gtk_widget_grab_focus (widget);
5652 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5653 G_OBJECT_TYPE_NAME (widget));
5654 gtk_widget_error_bell (widget);
5659 static const cairo_user_data_key_t event_key;
5662 _gtk_cairo_get_event (cairo_t *cr)
5664 g_return_val_if_fail (cr != NULL, NULL);
5666 return cairo_get_user_data (cr, &event_key);
5670 gtk_cairo_set_event (cairo_t *cr,
5671 GdkEventExpose *event)
5673 cairo_set_user_data (cr, &event_key, event, NULL);
5677 * gtk_cairo_should_draw_window:
5678 * @cr: a cairo context
5679 * @window: the window to check. @window may not be an input-only
5682 * This function is supposed to be called in #GtkWidget::draw
5683 * implementations for widgets that support multiple windows.
5684 * @cr must be untransformed from invoking of the draw function.
5685 * This function will return %TRUE if the contents of the given
5686 * @window are supposed to be drawn and %FALSE otherwise. Note
5687 * that when the drawing was not initiated by the windowing
5688 * system this function will return %TRUE for all windows, so
5689 * you need to draw the bottommost window first. Also, do not
5690 * use "else if" statements to check which window should be drawn.
5692 * Returns: %TRUE if @window should be drawn
5697 gtk_cairo_should_draw_window (cairo_t *cr,
5700 GdkEventExpose *event;
5702 g_return_val_if_fail (cr != NULL, FALSE);
5703 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5705 event = _gtk_cairo_get_event (cr);
5707 return event == NULL ||
5708 event->window == window;
5712 gtk_widget_get_clip_draw (GtkWidget *widget)
5714 /* labels are not clipped, because clipping them would cause
5715 * mnemonics to not appear on characters that go beyond the
5717 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5719 if (GTK_IS_LABEL (widget))
5725 /* code shared by gtk_container_propagate_draw() and
5729 _gtk_widget_draw_internal (GtkWidget *widget,
5731 gboolean clip_to_size)
5733 if (!gtk_widget_is_drawable (widget))
5736 clip_to_size &= gtk_widget_get_clip_draw (widget);
5740 cairo_rectangle (cr,
5742 widget->priv->allocation.width,
5743 widget->priv->allocation.height);
5747 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5751 g_signal_emit (widget, widget_signals[DRAW],
5755 if (cairo_status (cr) &&
5756 _gtk_cairo_get_event (cr))
5758 /* We check the event so we only warn about internal GTK calls.
5759 * Errors might come from PDF streams having write failures and
5760 * we don't want to spam stderr in that case.
5761 * We do want to catch errors from
5763 g_warning ("drawing failure for widget `%s': %s",
5764 G_OBJECT_TYPE_NAME (widget),
5765 cairo_status_to_string (cairo_status (cr)));
5772 * @widget: the widget to draw. It must be drawable (see
5773 * gtk_widget_is_drawable()) and a size must have been allocated.
5774 * @cr: a cairo context to draw to
5776 * Draws @widget to @cr. The top left corner of the widget will be
5777 * drawn to the currently set origin point of @cr.
5779 * You should pass a cairo context as @cr argument that is in an
5780 * original state. Otherwise the resulting drawing is undefined. For
5781 * example changing the operator using cairo_set_operator() or the
5782 * line width using cairo_set_line_width() might have unwanted side
5784 * You may however change the context's transform matrix - like with
5785 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5786 * region with cairo_clip() prior to calling this function. Also, it
5787 * is fine to modify the context with cairo_save() and
5788 * cairo_push_group() prior to calling this function.
5790 * <note><para>Special purpose widgets may contain special code for
5791 * rendering to the screen and might appear differently on screen
5792 * and when rendered using gtk_widget_draw().</para></note>
5797 gtk_widget_draw (GtkWidget *widget,
5800 GdkEventExpose *tmp_event;
5802 g_return_if_fail (GTK_IS_WIDGET (widget));
5803 g_return_if_fail (!widget->priv->alloc_needed);
5804 g_return_if_fail (cr != NULL);
5807 /* We have to reset the event here so that draw functions can call
5808 * gtk_widget_draw() on random other widgets and get the desired
5809 * effect: Drawing all contents, not just the current window.
5811 tmp_event = _gtk_cairo_get_event (cr);
5812 gtk_cairo_set_event (cr, NULL);
5814 _gtk_widget_draw_internal (widget, cr, TRUE);
5816 gtk_cairo_set_event (cr, tmp_event);
5821 gtk_widget_real_key_press_event (GtkWidget *widget,
5824 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5828 gtk_widget_real_key_release_event (GtkWidget *widget,
5831 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5835 gtk_widget_real_focus_in_event (GtkWidget *widget,
5836 GdkEventFocus *event)
5838 gtk_widget_queue_draw (widget);
5844 gtk_widget_real_focus_out_event (GtkWidget *widget,
5845 GdkEventFocus *event)
5847 gtk_widget_queue_draw (widget);
5853 gtk_widget_real_touch_event (GtkWidget *widget,
5854 GdkEventTouch *event)
5857 gboolean return_val;
5860 if (!event->emulating_pointer)
5863 if (event->type == GDK_TOUCH_BEGIN ||
5864 event->type == GDK_TOUCH_END)
5868 if (event->type == GDK_TOUCH_BEGIN)
5870 type = GDK_BUTTON_PRESS;
5871 signum = BUTTON_PRESS_EVENT;
5875 type = GDK_BUTTON_RELEASE;
5876 signum = BUTTON_RELEASE_EVENT;
5878 bevent = gdk_event_new (type);
5879 bevent->any.window = g_object_ref (event->window);
5880 bevent->any.send_event = FALSE;
5881 bevent->button.time = event->time;
5882 bevent->button.state = event->state;
5883 bevent->button.button = 1;
5884 bevent->button.x_root = event->x_root;
5885 bevent->button.y_root = event->y_root;
5886 bevent->button.x = event->x;
5887 bevent->button.y = event->y;
5888 bevent->button.device = event->device;
5889 bevent->button.axes = g_memdup (event->axes,
5890 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5891 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5893 else if (event->type == GDK_TOUCH_UPDATE)
5895 signum = MOTION_NOTIFY_EVENT;
5896 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5897 bevent->any.window = g_object_ref (event->window);
5898 bevent->any.send_event = FALSE;
5899 bevent->motion.time = event->time;
5900 bevent->motion.state = event->state;
5901 bevent->motion.x_root = event->x_root;
5902 bevent->motion.y_root = event->y_root;
5903 bevent->motion.x = event->x;
5904 bevent->motion.y = event->y;
5905 bevent->motion.device = event->device;
5906 bevent->motion.is_hint = FALSE;
5907 bevent->motion.axes = g_memdup (event->axes,
5908 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5909 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5914 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5916 gdk_event_free (bevent);
5922 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5923 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5927 * @widget: a #GtkWidget
5928 * @event: a #GdkEvent
5930 * Rarely-used function. This function is used to emit
5931 * the event signals on a widget (those signals should never
5932 * be emitted without using this function to do so).
5933 * If you want to synthesize an event though, don't use this function;
5934 * instead, use gtk_main_do_event() so the event will behave as if
5935 * it were in the event queue. Don't synthesize expose events; instead,
5936 * use gdk_window_invalidate_rect() to invalidate a region of the
5939 * Return value: return from the event signal emission (%TRUE if
5940 * the event was handled)
5943 gtk_widget_event (GtkWidget *widget,
5946 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5947 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5949 if (event->type == GDK_EXPOSE)
5951 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5952 "the same effect, call gdk_window_invalidate_rect/region(), "
5953 "followed by gdk_window_process_updates().");
5957 return gtk_widget_event_internal (widget, event);
5961 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5962 GtkCapturedEventHandler callback)
5964 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5968 _gtk_widget_captured_event (GtkWidget *widget,
5971 gboolean return_val = FALSE;
5972 GtkCapturedEventHandler handler;
5974 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5975 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5977 if (event->type == GDK_EXPOSE)
5979 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5980 "the same effect, call gdk_window_invalidate_rect/region(), "
5981 "followed by gdk_window_process_updates().");
5985 if (!event_window_is_still_viewable (event))
5988 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
5992 g_object_ref (widget);
5994 return_val = handler (widget, event);
5995 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5997 /* The widget that was originally to receive the event
5998 * handles motion hints, but the capturing widget might
5999 * not, so ensure we get further motion events.
6002 event->type == GDK_MOTION_NOTIFY &&
6003 event->motion.is_hint &&
6004 (gdk_window_get_events (event->any.window) &
6005 GDK_POINTER_MOTION_HINT_MASK) != 0)
6006 gdk_event_request_motions (&event->motion);
6008 g_object_unref (widget);
6013 /* Returns TRUE if a translation should be done */
6015 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6020 GdkWindow *w, *widget_window;
6022 if (!gtk_widget_get_has_window (widget))
6024 *x = -widget->priv->allocation.x;
6025 *y = -widget->priv->allocation.y;
6033 widget_window = gtk_widget_get_window (widget);
6035 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6038 gdk_window_get_position (w, &wx, &wy);
6055 * gtk_cairo_transform_to_window:
6056 * @cr: the cairo context to transform
6057 * @widget: the widget the context is currently centered for
6058 * @window: the window to transform the context to
6060 * Transforms the given cairo context @cr that from @widget-relative
6061 * coordinates to @window-relative coordinates.
6062 * If the @widget's window is not an ancestor of @window, no
6063 * modification will be applied.
6065 * This is the inverse to the transformation GTK applies when
6066 * preparing an expose event to be emitted with the #GtkWidget::draw
6067 * signal. It is intended to help porting multiwindow widgets from
6068 * GTK+ 2 to the rendering architecture of GTK+ 3.
6073 gtk_cairo_transform_to_window (cairo_t *cr,
6079 g_return_if_fail (cr != NULL);
6080 g_return_if_fail (GTK_IS_WIDGET (widget));
6081 g_return_if_fail (GDK_IS_WINDOW (window));
6083 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6084 cairo_translate (cr, x, y);
6088 * gtk_widget_send_expose:
6089 * @widget: a #GtkWidget
6090 * @event: a expose #GdkEvent
6092 * Very rarely-used function. This function is used to emit
6093 * an expose event on a widget. This function is not normally used
6094 * directly. The only time it is used is when propagating an expose
6095 * event to a child %NO_WINDOW widget, and that is normally done
6096 * using gtk_container_propagate_draw().
6098 * If you want to force an area of a window to be redrawn,
6099 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6100 * To cause the redraw to be done immediately, follow that call
6101 * with a call to gdk_window_process_updates().
6103 * Return value: return from the event signal emission (%TRUE if
6104 * the event was handled)
6107 gtk_widget_send_expose (GtkWidget *widget,
6110 gboolean result = FALSE;
6115 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6116 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6117 g_return_val_if_fail (event != NULL, TRUE);
6118 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6120 cr = gdk_cairo_create (event->expose.window);
6121 gtk_cairo_set_event (cr, &event->expose);
6123 gdk_cairo_region (cr, event->expose.region);
6126 do_clip = _gtk_widget_get_translation_to_window (widget,
6127 event->expose.window,
6129 cairo_translate (cr, -x, -y);
6131 _gtk_widget_draw_internal (widget, cr, do_clip);
6133 /* unset here, so if someone keeps a reference to cr we
6134 * don't leak the window. */
6135 gtk_cairo_set_event (cr, NULL);
6142 event_window_is_still_viewable (GdkEvent *event)
6144 /* Check that we think the event's window is viewable before
6145 * delivering the event, to prevent suprises. We do this here
6146 * at the last moment, since the event may have been queued
6147 * up behind other events, held over a recursive main loop, etc.
6149 switch (event->type)
6152 case GDK_MOTION_NOTIFY:
6153 case GDK_BUTTON_PRESS:
6154 case GDK_2BUTTON_PRESS:
6155 case GDK_3BUTTON_PRESS:
6157 case GDK_ENTER_NOTIFY:
6158 case GDK_PROXIMITY_IN:
6160 return event->any.window && gdk_window_is_viewable (event->any.window);
6163 /* The following events are the second half of paired events;
6164 * we always deliver them to deal with widgets that clean up
6165 * on the second half.
6167 case GDK_BUTTON_RELEASE:
6168 case GDK_KEY_RELEASE:
6169 case GDK_LEAVE_NOTIFY:
6170 case GDK_PROXIMITY_OUT:
6174 /* Remaining events would make sense on an not-viewable window,
6175 * or don't have an associated window.
6182 gtk_widget_event_internal (GtkWidget *widget,
6185 gboolean return_val = FALSE;
6187 /* We check only once for is-still-visible; if someone
6188 * hides the window in on of the signals on the widget,
6189 * they are responsible for returning TRUE to terminate
6192 if (!event_window_is_still_viewable (event))
6195 g_object_ref (widget);
6197 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6198 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6203 switch (event->type)
6209 case GDK_BUTTON_PRESS:
6210 case GDK_2BUTTON_PRESS:
6211 case GDK_3BUTTON_PRESS:
6212 signal_num = BUTTON_PRESS_EVENT;
6214 case GDK_TOUCH_BEGIN:
6215 case GDK_TOUCH_UPDATE:
6217 case GDK_TOUCH_CANCEL:
6218 signal_num = TOUCH_EVENT;
6221 signal_num = SCROLL_EVENT;
6223 case GDK_BUTTON_RELEASE:
6224 signal_num = BUTTON_RELEASE_EVENT;
6226 case GDK_MOTION_NOTIFY:
6227 signal_num = MOTION_NOTIFY_EVENT;
6230 signal_num = DELETE_EVENT;
6233 signal_num = DESTROY_EVENT;
6234 _gtk_tooltip_hide (widget);
6237 signal_num = KEY_PRESS_EVENT;
6239 case GDK_KEY_RELEASE:
6240 signal_num = KEY_RELEASE_EVENT;
6242 case GDK_ENTER_NOTIFY:
6243 signal_num = ENTER_NOTIFY_EVENT;
6245 case GDK_LEAVE_NOTIFY:
6246 signal_num = LEAVE_NOTIFY_EVENT;
6248 case GDK_FOCUS_CHANGE:
6249 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6250 if (event->focus_change.in)
6251 _gtk_tooltip_focus_in (widget);
6253 _gtk_tooltip_focus_out (widget);
6256 signal_num = CONFIGURE_EVENT;
6259 signal_num = MAP_EVENT;
6262 signal_num = UNMAP_EVENT;
6264 case GDK_WINDOW_STATE:
6265 signal_num = WINDOW_STATE_EVENT;
6267 case GDK_PROPERTY_NOTIFY:
6268 signal_num = PROPERTY_NOTIFY_EVENT;
6270 case GDK_SELECTION_CLEAR:
6271 signal_num = SELECTION_CLEAR_EVENT;
6273 case GDK_SELECTION_REQUEST:
6274 signal_num = SELECTION_REQUEST_EVENT;
6276 case GDK_SELECTION_NOTIFY:
6277 signal_num = SELECTION_NOTIFY_EVENT;
6279 case GDK_PROXIMITY_IN:
6280 signal_num = PROXIMITY_IN_EVENT;
6282 case GDK_PROXIMITY_OUT:
6283 signal_num = PROXIMITY_OUT_EVENT;
6285 case GDK_VISIBILITY_NOTIFY:
6286 signal_num = VISIBILITY_NOTIFY_EVENT;
6288 case GDK_GRAB_BROKEN:
6289 signal_num = GRAB_BROKEN_EVENT;
6292 signal_num = DAMAGE_EVENT;
6295 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6299 if (signal_num != -1)
6300 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6302 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6303 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6307 g_object_unref (widget);
6313 * gtk_widget_activate:
6314 * @widget: a #GtkWidget that's activatable
6316 * For widgets that can be "activated" (buttons, menu items, etc.)
6317 * this function activates them. Activation is what happens when you
6318 * press Enter on a widget during key navigation. If @widget isn't
6319 * activatable, the function returns %FALSE.
6321 * Return value: %TRUE if the widget was activatable
6324 gtk_widget_activate (GtkWidget *widget)
6326 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6328 if (WIDGET_CLASS (widget)->activate_signal)
6330 /* FIXME: we should eventually check the signals signature here */
6331 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6340 gtk_widget_reparent_subwindows (GtkWidget *widget,
6341 GdkWindow *new_window)
6343 GtkWidgetPrivate *priv = widget->priv;
6345 if (!gtk_widget_get_has_window (widget))
6347 GList *children = gdk_window_get_children (priv->window);
6350 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6352 GdkWindow *window = tmp_list->data;
6355 gdk_window_get_user_data (window, &child);
6356 while (child && child != widget)
6357 child = ((GtkWidget*) child)->priv->parent;
6360 gdk_window_reparent (window, new_window, 0, 0);
6363 g_list_free (children);
6368 GList *tmp_list, *children;
6370 parent = gdk_window_get_parent (priv->window);
6373 gdk_window_reparent (priv->window, new_window, 0, 0);
6376 children = gdk_window_get_children (parent);
6378 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6380 GdkWindow *window = tmp_list->data;
6383 gdk_window_get_user_data (window, &child);
6385 if (child == widget)
6386 gdk_window_reparent (window, new_window, 0, 0);
6389 g_list_free (children);
6395 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6396 gpointer client_data)
6398 GtkWidgetPrivate *priv = widget->priv;
6400 g_assert (client_data != NULL);
6402 if (!gtk_widget_get_has_window (widget))
6405 g_object_unref (priv->window);
6406 priv->window = (GdkWindow*) client_data;
6408 g_object_ref (priv->window);
6410 if (GTK_IS_CONTAINER (widget))
6411 gtk_container_forall (GTK_CONTAINER (widget),
6412 gtk_widget_reparent_fixup_child,
6418 * gtk_widget_reparent:
6419 * @widget: a #GtkWidget
6420 * @new_parent: a #GtkContainer to move the widget into
6422 * Moves a widget from one #GtkContainer to another, handling reference
6423 * count issues to avoid destroying the widget.
6426 gtk_widget_reparent (GtkWidget *widget,
6427 GtkWidget *new_parent)
6429 GtkWidgetPrivate *priv;
6431 g_return_if_fail (GTK_IS_WIDGET (widget));
6432 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6433 priv = widget->priv;
6434 g_return_if_fail (priv->parent != NULL);
6436 if (priv->parent != new_parent)
6438 /* First try to see if we can get away without unrealizing
6439 * the widget as we reparent it. if so we set a flag so
6440 * that gtk_widget_unparent doesn't unrealize widget
6442 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6443 priv->in_reparent = TRUE;
6445 g_object_ref (widget);
6446 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6447 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6448 g_object_unref (widget);
6450 if (priv->in_reparent)
6452 priv->in_reparent = FALSE;
6454 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6455 gtk_widget_reparent_fixup_child (widget,
6456 gtk_widget_get_parent_window (widget));
6459 g_object_notify (G_OBJECT (widget), "parent");
6464 * gtk_widget_intersect:
6465 * @widget: a #GtkWidget
6466 * @area: a rectangle
6467 * @intersection: rectangle to store intersection of @widget and @area
6469 * Computes the intersection of a @widget's area and @area, storing
6470 * the intersection in @intersection, and returns %TRUE if there was
6471 * an intersection. @intersection may be %NULL if you're only
6472 * interested in whether there was an intersection.
6474 * Return value: %TRUE if there was an intersection
6477 gtk_widget_intersect (GtkWidget *widget,
6478 const GdkRectangle *area,
6479 GdkRectangle *intersection)
6481 GtkWidgetPrivate *priv;
6486 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6487 g_return_val_if_fail (area != NULL, FALSE);
6489 priv = widget->priv;
6492 dest = intersection;
6496 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6498 if (return_val && intersection && gtk_widget_get_has_window (widget))
6500 intersection->x -= priv->allocation.x;
6501 intersection->y -= priv->allocation.y;
6508 * gtk_widget_region_intersect:
6509 * @widget: a #GtkWidget
6510 * @region: a #cairo_region_t, in the same coordinate system as
6511 * @widget->allocation. That is, relative to @widget->window
6512 * for %NO_WINDOW widgets; relative to the parent window
6513 * of @widget->window for widgets with their own window.
6515 * Computes the intersection of a @widget's area and @region, returning
6516 * the intersection. The result may be empty, use cairo_region_is_empty() to
6519 * Returns: A newly allocated region holding the intersection of @widget
6520 * and @region. The coordinates of the return value are relative to
6521 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6522 * window of @widget->window for widgets with their own window.
6525 gtk_widget_region_intersect (GtkWidget *widget,
6526 const cairo_region_t *region)
6529 cairo_region_t *dest;
6531 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6532 g_return_val_if_fail (region != NULL, NULL);
6534 gtk_widget_get_allocation (widget, &rect);
6536 dest = cairo_region_create_rectangle (&rect);
6538 cairo_region_intersect (dest, region);
6544 * _gtk_widget_grab_notify:
6545 * @widget: a #GtkWidget
6546 * @was_grabbed: whether a grab is now in effect
6548 * Emits the #GtkWidget::grab-notify signal on @widget.
6553 _gtk_widget_grab_notify (GtkWidget *widget,
6554 gboolean was_grabbed)
6556 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6560 * gtk_widget_grab_focus:
6561 * @widget: a #GtkWidget
6563 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6564 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6565 * something like #GtkFrame won't work.
6567 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6568 * gtk_widget_set_can_focus() to modify that flag.
6570 * The widget also needs to be realized and mapped. This is indicated by the
6571 * related signals. Grabbing the focus immediately after creating the widget
6572 * will likely fail and cause critical warnings.
6575 gtk_widget_grab_focus (GtkWidget *widget)
6577 g_return_if_fail (GTK_IS_WIDGET (widget));
6579 if (!gtk_widget_is_sensitive (widget))
6582 g_object_ref (widget);
6583 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6584 g_object_notify (G_OBJECT (widget), "has-focus");
6585 g_object_unref (widget);
6589 reset_focus_recurse (GtkWidget *widget,
6592 if (GTK_IS_CONTAINER (widget))
6594 GtkContainer *container;
6596 container = GTK_CONTAINER (widget);
6597 gtk_container_set_focus_child (container, NULL);
6599 gtk_container_foreach (container,
6600 reset_focus_recurse,
6606 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6608 if (gtk_widget_get_can_focus (focus_widget))
6610 GtkWidget *toplevel;
6613 /* clear the current focus setting, break if the current widget
6614 * is the focus widget's parent, since containers above that will
6615 * be set by the next loop.
6617 toplevel = gtk_widget_get_toplevel (focus_widget);
6618 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6620 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6622 if (widget == focus_widget)
6624 /* We call _gtk_window_internal_set_focus() here so that the
6625 * toplevel window can request the focus if necessary.
6626 * This is needed when the toplevel is a GtkPlug
6628 if (!gtk_widget_has_focus (widget))
6629 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6636 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6638 if (widget != common_ancestor)
6640 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6642 widget = widget->priv->parent;
6643 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6648 else if (toplevel != focus_widget)
6650 /* gtk_widget_grab_focus() operates on a tree without window...
6651 * actually, this is very questionable behaviour.
6654 gtk_container_foreach (GTK_CONTAINER (toplevel),
6655 reset_focus_recurse,
6659 /* now propagate the new focus up the widget tree and finally
6660 * set it on the window
6662 widget = focus_widget;
6663 while (widget->priv->parent)
6665 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6666 widget = widget->priv->parent;
6668 if (GTK_IS_WINDOW (widget))
6669 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6674 gtk_widget_real_query_tooltip (GtkWidget *widget,
6677 gboolean keyboard_tip,
6678 GtkTooltip *tooltip)
6680 gchar *tooltip_markup;
6681 gboolean has_tooltip;
6683 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6684 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6686 if (has_tooltip && tooltip_markup)
6688 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6696 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6697 GtkStateFlags old_state)
6699 gtk_widget_update_pango_context (widget);
6703 gtk_widget_real_style_updated (GtkWidget *widget)
6705 GtkWidgetPrivate *priv = widget->priv;
6707 gtk_widget_update_pango_context (widget);
6709 if (priv->style != NULL &&
6710 priv->style != gtk_widget_get_default_style ())
6712 /* Trigger ::style-set for old
6713 * widgets not listening to this
6715 g_signal_emit (widget,
6716 widget_signals[STYLE_SET],
6718 widget->priv->style);
6721 if (widget->priv->context)
6723 if (gtk_widget_get_realized (widget) &&
6724 gtk_widget_get_has_window (widget) &&
6725 !gtk_widget_get_app_paintable (widget))
6726 gtk_style_context_set_background (widget->priv->context,
6727 widget->priv->window);
6730 if (widget->priv->anchored)
6731 gtk_widget_queue_resize (widget);
6735 gtk_widget_real_show_help (GtkWidget *widget,
6736 GtkWidgetHelpType help_type)
6738 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6740 _gtk_tooltip_toggle_keyboard_mode (widget);
6749 gtk_widget_real_focus (GtkWidget *widget,
6750 GtkDirectionType direction)
6752 if (!gtk_widget_get_can_focus (widget))
6755 if (!gtk_widget_is_focus (widget))
6757 gtk_widget_grab_focus (widget);
6765 gtk_widget_real_move_focus (GtkWidget *widget,
6766 GtkDirectionType direction)
6768 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6770 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6772 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6778 gtk_widget_real_keynav_failed (GtkWidget *widget,
6779 GtkDirectionType direction)
6781 gboolean cursor_only;
6785 case GTK_DIR_TAB_FORWARD:
6786 case GTK_DIR_TAB_BACKWARD:
6793 g_object_get (gtk_widget_get_settings (widget),
6794 "gtk-keynav-cursor-only", &cursor_only,
6801 gtk_widget_error_bell (widget);
6807 * gtk_widget_set_can_focus:
6808 * @widget: a #GtkWidget
6809 * @can_focus: whether or not @widget can own the input focus.
6811 * Specifies whether @widget can own the input focus. See
6812 * gtk_widget_grab_focus() for actually setting the input focus on a
6818 gtk_widget_set_can_focus (GtkWidget *widget,
6821 g_return_if_fail (GTK_IS_WIDGET (widget));
6823 if (widget->priv->can_focus != can_focus)
6825 widget->priv->can_focus = can_focus;
6827 gtk_widget_queue_resize (widget);
6828 g_object_notify (G_OBJECT (widget), "can-focus");
6833 * gtk_widget_get_can_focus:
6834 * @widget: a #GtkWidget
6836 * Determines whether @widget can own the input focus. See
6837 * gtk_widget_set_can_focus().
6839 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6844 gtk_widget_get_can_focus (GtkWidget *widget)
6846 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6848 return widget->priv->can_focus;
6852 * gtk_widget_has_focus:
6853 * @widget: a #GtkWidget
6855 * Determines if the widget has the global input focus. See
6856 * gtk_widget_is_focus() for the difference between having the global
6857 * input focus, and only having the focus within a toplevel.
6859 * Return value: %TRUE if the widget has the global input focus.
6864 gtk_widget_has_focus (GtkWidget *widget)
6866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6868 return widget->priv->has_focus;
6872 * gtk_widget_has_visible_focus:
6873 * @widget: a #GtkWidget
6875 * Determines if the widget should show a visible indication that
6876 * it has the global input focus. This is a convenience function for
6877 * use in ::draw handlers that takes into account whether focus
6878 * indication should currently be shown in the toplevel window of
6879 * @widget. See gtk_window_get_focus_visible() for more information
6880 * about focus indication.
6882 * To find out if the widget has the global input focus, use
6883 * gtk_widget_has_focus().
6885 * Return value: %TRUE if the widget should display a 'focus rectangle'
6890 gtk_widget_has_visible_focus (GtkWidget *widget)
6892 gboolean draw_focus;
6894 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6896 if (widget->priv->has_focus)
6898 GtkWidget *toplevel;
6900 toplevel = gtk_widget_get_toplevel (widget);
6902 if (GTK_IS_WINDOW (toplevel))
6903 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6914 * gtk_widget_is_focus:
6915 * @widget: a #GtkWidget
6917 * Determines if the widget is the focus widget within its
6918 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6919 * necessarily set; %HAS_FOCUS will only be set if the
6920 * toplevel widget additionally has the global input focus.)
6922 * Return value: %TRUE if the widget is the focus widget.
6925 gtk_widget_is_focus (GtkWidget *widget)
6927 GtkWidget *toplevel;
6929 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6931 toplevel = gtk_widget_get_toplevel (widget);
6933 if (GTK_IS_WINDOW (toplevel))
6934 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6940 * gtk_widget_set_can_default:
6941 * @widget: a #GtkWidget
6942 * @can_default: whether or not @widget can be a default widget.
6944 * Specifies whether @widget can be a default widget. See
6945 * gtk_widget_grab_default() for details about the meaning of
6951 gtk_widget_set_can_default (GtkWidget *widget,
6952 gboolean can_default)
6954 g_return_if_fail (GTK_IS_WIDGET (widget));
6956 if (widget->priv->can_default != can_default)
6958 widget->priv->can_default = can_default;
6960 gtk_widget_queue_resize (widget);
6961 g_object_notify (G_OBJECT (widget), "can-default");
6966 * gtk_widget_get_can_default:
6967 * @widget: a #GtkWidget
6969 * Determines whether @widget can be a default widget. See
6970 * gtk_widget_set_can_default().
6972 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6977 gtk_widget_get_can_default (GtkWidget *widget)
6979 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6981 return widget->priv->can_default;
6985 * gtk_widget_has_default:
6986 * @widget: a #GtkWidget
6988 * Determines whether @widget is the current default widget within its
6989 * toplevel. See gtk_widget_set_can_default().
6991 * Return value: %TRUE if @widget is the current default widget within
6992 * its toplevel, %FALSE otherwise
6997 gtk_widget_has_default (GtkWidget *widget)
6999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7001 return widget->priv->has_default;
7005 _gtk_widget_set_has_default (GtkWidget *widget,
7006 gboolean has_default)
7008 GtkStyleContext *context;
7010 widget->priv->has_default = has_default;
7012 context = gtk_widget_get_style_context (widget);
7015 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7017 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7021 * gtk_widget_grab_default:
7022 * @widget: a #GtkWidget
7024 * Causes @widget to become the default widget. @widget must be able to be
7025 * a default widget; typically you would ensure this yourself
7026 * by calling gtk_widget_set_can_default() with a %TRUE value.
7027 * The default widget is activated when
7028 * the user presses Enter in a window. Default widgets must be
7029 * activatable, that is, gtk_widget_activate() should affect them. Note
7030 * that #GtkEntry widgets require the "activates-default" property
7031 * set to %TRUE before they activate the default widget when Enter
7032 * is pressed and the #GtkEntry is focused.
7035 gtk_widget_grab_default (GtkWidget *widget)
7039 g_return_if_fail (GTK_IS_WIDGET (widget));
7040 g_return_if_fail (gtk_widget_get_can_default (widget));
7042 window = gtk_widget_get_toplevel (widget);
7044 if (window && gtk_widget_is_toplevel (window))
7045 gtk_window_set_default (GTK_WINDOW (window), widget);
7047 g_warning (G_STRLOC ": widget not within a GtkWindow");
7051 * gtk_widget_set_receives_default:
7052 * @widget: a #GtkWidget
7053 * @receives_default: whether or not @widget can be a default widget.
7055 * Specifies whether @widget will be treated as the default widget
7056 * within its toplevel when it has the focus, even if another widget
7059 * See gtk_widget_grab_default() for details about the meaning of
7065 gtk_widget_set_receives_default (GtkWidget *widget,
7066 gboolean receives_default)
7068 g_return_if_fail (GTK_IS_WIDGET (widget));
7070 if (widget->priv->receives_default != receives_default)
7072 widget->priv->receives_default = receives_default;
7074 g_object_notify (G_OBJECT (widget), "receives-default");
7079 * gtk_widget_get_receives_default:
7080 * @widget: a #GtkWidget
7082 * Determines whether @widget is alyways treated as default widget
7083 * withing its toplevel when it has the focus, even if another widget
7086 * See gtk_widget_set_receives_default().
7088 * Return value: %TRUE if @widget acts as default widget when focussed,
7094 gtk_widget_get_receives_default (GtkWidget *widget)
7096 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7098 return widget->priv->receives_default;
7102 * gtk_widget_has_grab:
7103 * @widget: a #GtkWidget
7105 * Determines whether the widget is currently grabbing events, so it
7106 * is the only widget receiving input events (keyboard and mouse).
7108 * See also gtk_grab_add().
7110 * Return value: %TRUE if the widget is in the grab_widgets stack
7115 gtk_widget_has_grab (GtkWidget *widget)
7117 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7119 return widget->priv->has_grab;
7123 _gtk_widget_set_has_grab (GtkWidget *widget,
7126 widget->priv->has_grab = has_grab;
7130 * gtk_widget_device_is_shadowed:
7131 * @widget: a #GtkWidget
7132 * @device: a #GdkDevice
7134 * Returns %TRUE if @device has been shadowed by a GTK+
7135 * device grab on another widget, so it would stop sending
7136 * events to @widget. This may be used in the
7137 * #GtkWidget::grab-notify signal to check for specific
7138 * devices. See gtk_device_grab_add().
7140 * Returns: %TRUE if there is an ongoing grab on @device
7141 * by another #GtkWidget than @widget.
7146 gtk_widget_device_is_shadowed (GtkWidget *widget,
7149 GtkWindowGroup *group;
7150 GtkWidget *grab_widget, *toplevel;
7152 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7153 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7155 if (!gtk_widget_get_realized (widget))
7158 toplevel = gtk_widget_get_toplevel (widget);
7160 if (GTK_IS_WINDOW (toplevel))
7161 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7163 group = gtk_window_get_group (NULL);
7165 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7167 /* Widget not inside the hierarchy of grab_widget */
7169 widget != grab_widget &&
7170 !gtk_widget_is_ancestor (widget, grab_widget))
7173 grab_widget = gtk_window_group_get_current_grab (group);
7174 if (grab_widget && widget != grab_widget &&
7175 !gtk_widget_is_ancestor (widget, grab_widget))
7182 * gtk_widget_set_name:
7183 * @widget: a #GtkWidget
7184 * @name: name for the widget
7186 * Widgets can be named, which allows you to refer to them from a
7187 * CSS file. You can apply a style to widgets with a particular name
7188 * in the CSS file. See the documentation for the CSS syntax (on the
7189 * same page as the docs for #GtkStyleContext).
7191 * Note that the CSS syntax has certain special characters to delimit
7192 * and represent elements in a selector (period, #, >, *...),
7193 * so using these will make your widget impossible to match by name.
7194 * Any combination of alphanumeric symbols, dashes and underscores will
7198 gtk_widget_set_name (GtkWidget *widget,
7201 GtkWidgetPrivate *priv;
7204 g_return_if_fail (GTK_IS_WIDGET (widget));
7206 priv = widget->priv;
7208 new_name = g_strdup (name);
7209 g_free (priv->name);
7210 priv->name = new_name;
7212 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7214 g_object_notify (G_OBJECT (widget), "name");
7218 * gtk_widget_get_name:
7219 * @widget: a #GtkWidget
7221 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7222 * significance of widget names.
7224 * Return value: name of the widget. This string is owned by GTK+ and
7225 * should not be modified or freed
7228 gtk_widget_get_name (GtkWidget *widget)
7230 GtkWidgetPrivate *priv;
7232 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7234 priv = widget->priv;
7238 return G_OBJECT_TYPE_NAME (widget);
7242 _gtk_widget_update_state_flags (GtkWidget *widget,
7243 GtkStateFlags flags,
7246 GtkWidgetPrivate *priv;
7248 priv = widget->priv;
7250 /* Handle insensitive first, since it is propagated
7251 * differently throughout the widget hierarchy.
7253 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7254 gtk_widget_set_sensitive (widget, TRUE);
7255 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7256 gtk_widget_set_sensitive (widget, FALSE);
7257 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7258 gtk_widget_set_sensitive (widget, TRUE);
7260 if (operation != STATE_CHANGE_REPLACE)
7261 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7264 operation == STATE_CHANGE_REPLACE)
7269 data.operation = operation;
7271 gtk_widget_propagate_state (widget, &data);
7273 gtk_widget_queue_resize (widget);
7278 * gtk_widget_set_state_flags:
7279 * @widget: a #GtkWidget
7280 * @flags: State flags to turn on
7281 * @clear: Whether to clear state before turning on @flags
7283 * This function is for use in widget implementations. Turns on flag
7284 * values in the current widget state (insensitive, prelighted, etc.).
7286 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7287 * will be propagated down to all non-internal children if @widget is a
7288 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7289 * down to all #GtkContainer children by different means than turning on the
7290 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7291 * gtk_widget_is_sensitive() will make use of these.
7296 gtk_widget_set_state_flags (GtkWidget *widget,
7297 GtkStateFlags flags,
7300 g_return_if_fail (GTK_IS_WIDGET (widget));
7302 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7303 (clear && widget->priv->state_flags == flags))
7307 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7309 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7313 * gtk_widget_unset_state_flags:
7314 * @widget: a #GtkWidget
7315 * @flags: State flags to turn off
7317 * This function is for use in widget implementations. Turns off flag
7318 * values for the current widget state (insensitive, prelighted, etc.).
7319 * See gtk_widget_set_state_flags().
7324 gtk_widget_unset_state_flags (GtkWidget *widget,
7325 GtkStateFlags flags)
7327 g_return_if_fail (GTK_IS_WIDGET (widget));
7329 if ((widget->priv->state_flags & flags) == 0)
7332 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7336 * gtk_widget_get_state_flags:
7337 * @widget: a #GtkWidget
7339 * Returns the widget state as a flag set. It is worth mentioning
7340 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7341 * returned, that is, also based on parent insensitivity, even if
7342 * @widget itself is sensitive.
7344 * Returns: The state flags for widget
7349 gtk_widget_get_state_flags (GtkWidget *widget)
7351 GtkStateFlags flags;
7353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7355 flags = widget->priv->state_flags;
7357 if (gtk_widget_has_focus (widget))
7358 flags |= GTK_STATE_FLAG_FOCUSED;
7364 * gtk_widget_set_state:
7365 * @widget: a #GtkWidget
7366 * @state: new state for @widget
7368 * This function is for use in widget implementations. Sets the state
7369 * of a widget (insensitive, prelighted, etc.) Usually you should set
7370 * the state using wrapper functions such as gtk_widget_set_sensitive().
7372 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7375 gtk_widget_set_state (GtkWidget *widget,
7378 GtkStateFlags flags;
7380 if (state == gtk_widget_get_state (widget))
7385 case GTK_STATE_ACTIVE:
7386 flags = GTK_STATE_FLAG_ACTIVE;
7388 case GTK_STATE_PRELIGHT:
7389 flags = GTK_STATE_FLAG_PRELIGHT;
7391 case GTK_STATE_SELECTED:
7392 flags = GTK_STATE_FLAG_SELECTED;
7394 case GTK_STATE_INSENSITIVE:
7395 flags = GTK_STATE_FLAG_INSENSITIVE;
7397 case GTK_STATE_INCONSISTENT:
7398 flags = GTK_STATE_FLAG_INCONSISTENT;
7400 case GTK_STATE_FOCUSED:
7401 flags = GTK_STATE_FLAG_FOCUSED;
7403 case GTK_STATE_NORMAL:
7409 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7413 * gtk_widget_get_state:
7414 * @widget: a #GtkWidget
7416 * Returns the widget's state. See gtk_widget_set_state().
7418 * Returns: the state of @widget.
7422 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7425 gtk_widget_get_state (GtkWidget *widget)
7427 GtkStateFlags flags;
7429 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7431 flags = gtk_widget_get_state_flags (widget);
7433 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7434 return GTK_STATE_INSENSITIVE;
7435 else if (flags & GTK_STATE_FLAG_ACTIVE)
7436 return GTK_STATE_ACTIVE;
7437 else if (flags & GTK_STATE_FLAG_SELECTED)
7438 return GTK_STATE_SELECTED;
7439 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7440 return GTK_STATE_PRELIGHT;
7442 return GTK_STATE_NORMAL;
7446 * gtk_widget_set_visible:
7447 * @widget: a #GtkWidget
7448 * @visible: whether the widget should be shown or not
7450 * Sets the visibility state of @widget. Note that setting this to
7451 * %TRUE doesn't mean the widget is actually viewable, see
7452 * gtk_widget_get_visible().
7454 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7455 * but is nicer to use when the visibility of the widget depends on
7461 gtk_widget_set_visible (GtkWidget *widget,
7464 g_return_if_fail (GTK_IS_WIDGET (widget));
7466 if (visible != gtk_widget_get_visible (widget))
7469 gtk_widget_show (widget);
7471 gtk_widget_hide (widget);
7476 _gtk_widget_set_visible_flag (GtkWidget *widget,
7479 widget->priv->visible = visible;
7483 * gtk_widget_get_visible:
7484 * @widget: a #GtkWidget
7486 * Determines whether the widget is visible. If you want to
7487 * take into account whether the widget's parent is also marked as
7488 * visible, use gtk_widget_is_visible() instead.
7490 * This function does not check if the widget is obscured in any way.
7492 * See gtk_widget_set_visible().
7494 * Return value: %TRUE if the widget is visible
7499 gtk_widget_get_visible (GtkWidget *widget)
7501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7503 return widget->priv->visible;
7507 * gtk_widget_is_visible:
7508 * @widget: a #GtkWidget
7510 * Determines whether the widget and all its parents are marked as
7513 * This function does not check if the widget is obscured in any way.
7515 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7517 * Return value: %TRUE if the widget and all its parents are visible
7522 gtk_widget_is_visible (GtkWidget *widget)
7524 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7528 GtkWidgetPrivate *priv = widget->priv;
7533 widget = priv->parent;
7540 * gtk_widget_set_has_window:
7541 * @widget: a #GtkWidget
7542 * @has_window: whether or not @widget has a window.
7544 * Specifies whether @widget has a #GdkWindow of its own. Note that
7545 * all realized widgets have a non-%NULL "window" pointer
7546 * (gtk_widget_get_window() never returns a %NULL window when a widget
7547 * is realized), but for many of them it's actually the #GdkWindow of
7548 * one of its parent widgets. Widgets that do not create a %window for
7549 * themselves in #GtkWidget::realize must announce this by
7550 * calling this function with @has_window = %FALSE.
7552 * This function should only be called by widget implementations,
7553 * and they should call it in their init() function.
7558 gtk_widget_set_has_window (GtkWidget *widget,
7559 gboolean has_window)
7561 g_return_if_fail (GTK_IS_WIDGET (widget));
7563 widget->priv->no_window = !has_window;
7567 * gtk_widget_get_has_window:
7568 * @widget: a #GtkWidget
7570 * Determines whether @widget has a #GdkWindow of its own. See
7571 * gtk_widget_set_has_window().
7573 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7578 gtk_widget_get_has_window (GtkWidget *widget)
7580 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7582 return ! widget->priv->no_window;
7586 * gtk_widget_is_toplevel:
7587 * @widget: a #GtkWidget
7589 * Determines whether @widget is a toplevel widget.
7591 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7592 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7595 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7600 gtk_widget_is_toplevel (GtkWidget *widget)
7602 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7604 return widget->priv->toplevel;
7608 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7609 gboolean is_toplevel)
7611 widget->priv->toplevel = is_toplevel;
7615 * gtk_widget_is_drawable:
7616 * @widget: a #GtkWidget
7618 * Determines whether @widget can be drawn to. A widget can be drawn
7619 * to if it is mapped and visible.
7621 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7626 gtk_widget_is_drawable (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7630 return (gtk_widget_get_visible (widget) &&
7631 gtk_widget_get_mapped (widget));
7635 * gtk_widget_get_realized:
7636 * @widget: a #GtkWidget
7638 * Determines whether @widget is realized.
7640 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7645 gtk_widget_get_realized (GtkWidget *widget)
7647 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7649 return widget->priv->realized;
7653 * gtk_widget_set_realized:
7654 * @widget: a #GtkWidget
7655 * @realized: %TRUE to mark the widget as realized
7657 * Marks the widget as being realized.
7659 * This function should only ever be called in a derived widget's
7660 * "realize" or "unrealize" implementation.
7665 gtk_widget_set_realized (GtkWidget *widget,
7668 g_return_if_fail (GTK_IS_WIDGET (widget));
7670 widget->priv->realized = realized;
7674 * gtk_widget_get_mapped:
7675 * @widget: a #GtkWidget
7677 * Whether the widget is mapped.
7679 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7684 gtk_widget_get_mapped (GtkWidget *widget)
7686 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7688 return widget->priv->mapped;
7692 * gtk_widget_set_mapped:
7693 * @widget: a #GtkWidget
7694 * @mapped: %TRUE to mark the widget as mapped
7696 * Marks the widget as being realized.
7698 * This function should only ever be called in a derived widget's
7699 * "map" or "unmap" implementation.
7704 gtk_widget_set_mapped (GtkWidget *widget,
7707 g_return_if_fail (GTK_IS_WIDGET (widget));
7709 widget->priv->mapped = mapped;
7713 * gtk_widget_set_app_paintable:
7714 * @widget: a #GtkWidget
7715 * @app_paintable: %TRUE if the application will paint on the widget
7717 * Sets whether the application intends to draw on the widget in
7718 * an #GtkWidget::draw handler.
7720 * This is a hint to the widget and does not affect the behavior of
7721 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7722 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7723 * the effect is to suppress default themed drawing of the widget's
7724 * background. (Children of the widget will still be drawn.) The application
7725 * is then entirely responsible for drawing the widget background.
7727 * Note that the background is still drawn when the widget is mapped.
7730 gtk_widget_set_app_paintable (GtkWidget *widget,
7731 gboolean app_paintable)
7733 g_return_if_fail (GTK_IS_WIDGET (widget));
7735 app_paintable = (app_paintable != FALSE);
7737 if (widget->priv->app_paintable != app_paintable)
7739 widget->priv->app_paintable = app_paintable;
7741 if (gtk_widget_is_drawable (widget))
7742 gtk_widget_queue_draw (widget);
7744 g_object_notify (G_OBJECT (widget), "app-paintable");
7749 * gtk_widget_get_app_paintable:
7750 * @widget: a #GtkWidget
7752 * Determines whether the application intends to draw on the widget in
7753 * an #GtkWidget::draw handler.
7755 * See gtk_widget_set_app_paintable()
7757 * Return value: %TRUE if the widget is app paintable
7762 gtk_widget_get_app_paintable (GtkWidget *widget)
7764 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7766 return widget->priv->app_paintable;
7770 * gtk_widget_set_double_buffered:
7771 * @widget: a #GtkWidget
7772 * @double_buffered: %TRUE to double-buffer a widget
7774 * Widgets are double buffered by default; you can use this function
7775 * to turn off the buffering. "Double buffered" simply means that
7776 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7777 * automatically around expose events sent to the
7778 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7779 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7780 * buffer to the screen. The result is that users see the window
7781 * update in one smooth step, and don't see individual graphics
7782 * primitives being rendered.
7784 * In very simple terms, double buffered widgets don't flicker,
7785 * so you would only use this function to turn off double buffering
7786 * if you had special needs and really knew what you were doing.
7788 * Note: if you turn off double-buffering, you have to handle
7789 * expose events, since even the clearing to the background color or
7790 * pixmap will not happen automatically (as it is done in
7791 * gdk_window_begin_paint_region()).
7794 gtk_widget_set_double_buffered (GtkWidget *widget,
7795 gboolean double_buffered)
7797 g_return_if_fail (GTK_IS_WIDGET (widget));
7799 double_buffered = (double_buffered != FALSE);
7801 if (widget->priv->double_buffered != double_buffered)
7803 widget->priv->double_buffered = double_buffered;
7805 g_object_notify (G_OBJECT (widget), "double-buffered");
7810 * gtk_widget_get_double_buffered:
7811 * @widget: a #GtkWidget
7813 * Determines whether the widget is double buffered.
7815 * See gtk_widget_set_double_buffered()
7817 * Return value: %TRUE if the widget is double buffered
7822 gtk_widget_get_double_buffered (GtkWidget *widget)
7824 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7826 return widget->priv->double_buffered;
7830 * gtk_widget_set_redraw_on_allocate:
7831 * @widget: a #GtkWidget
7832 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7833 * when it is allocated to a new size. Otherwise, only the
7834 * new portion of the widget will be redrawn.
7836 * Sets whether the entire widget is queued for drawing when its size
7837 * allocation changes. By default, this setting is %TRUE and
7838 * the entire widget is redrawn on every size change. If your widget
7839 * leaves the upper left unchanged when made bigger, turning this
7840 * setting off will improve performance.
7842 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7843 * off all allocation on resizing: the widget will not even redraw if
7844 * its position changes; this is to allow containers that don't draw
7845 * anything to avoid excess invalidations. If you set this flag on a
7846 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7847 * you are responsible for invalidating both the old and new allocation
7848 * of the widget when the widget is moved and responsible for invalidating
7849 * regions newly when the widget increases size.
7852 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7853 gboolean redraw_on_allocate)
7855 g_return_if_fail (GTK_IS_WIDGET (widget));
7857 widget->priv->redraw_on_alloc = redraw_on_allocate;
7861 * gtk_widget_set_sensitive:
7862 * @widget: a #GtkWidget
7863 * @sensitive: %TRUE to make the widget sensitive
7865 * Sets the sensitivity of a widget. A widget is sensitive if the user
7866 * can interact with it. Insensitive widgets are "grayed out" and the
7867 * user can't interact with them. Insensitive widgets are known as
7868 * "inactive", "disabled", or "ghosted" in some other toolkits.
7871 gtk_widget_set_sensitive (GtkWidget *widget,
7874 GtkWidgetPrivate *priv;
7876 g_return_if_fail (GTK_IS_WIDGET (widget));
7878 priv = widget->priv;
7880 sensitive = (sensitive != FALSE);
7882 if (priv->sensitive == sensitive)
7885 priv->sensitive = sensitive;
7887 if (priv->parent == NULL
7888 || gtk_widget_is_sensitive (priv->parent))
7892 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7895 data.operation = STATE_CHANGE_UNSET;
7897 data.operation = STATE_CHANGE_SET;
7899 gtk_widget_propagate_state (widget, &data);
7901 gtk_widget_queue_resize (widget);
7904 g_object_notify (G_OBJECT (widget), "sensitive");
7908 * gtk_widget_get_sensitive:
7909 * @widget: a #GtkWidget
7911 * Returns the widget's sensitivity (in the sense of returning
7912 * the value that has been set using gtk_widget_set_sensitive()).
7914 * The effective sensitivity of a widget is however determined by both its
7915 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7917 * Returns: %TRUE if the widget is sensitive
7922 gtk_widget_get_sensitive (GtkWidget *widget)
7924 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7926 return widget->priv->sensitive;
7930 * gtk_widget_is_sensitive:
7931 * @widget: a #GtkWidget
7933 * Returns the widget's effective sensitivity, which means
7934 * it is sensitive itself and also its parent widget is sensitive
7936 * Returns: %TRUE if the widget is effectively sensitive
7941 gtk_widget_is_sensitive (GtkWidget *widget)
7943 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7945 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7949 * gtk_widget_set_parent:
7950 * @widget: a #GtkWidget
7951 * @parent: parent container
7953 * This function is useful only when implementing subclasses of
7955 * Sets the container as the parent of @widget, and takes care of
7956 * some details such as updating the state and style of the child
7957 * to reflect its new location. The opposite function is
7958 * gtk_widget_unparent().
7961 gtk_widget_set_parent (GtkWidget *widget,
7964 GtkStateFlags parent_flags;
7965 GtkWidgetPrivate *priv;
7968 g_return_if_fail (GTK_IS_WIDGET (widget));
7969 g_return_if_fail (GTK_IS_WIDGET (parent));
7970 g_return_if_fail (widget != parent);
7972 priv = widget->priv;
7974 if (priv->parent != NULL)
7976 g_warning ("Can't set a parent on widget which has a parent\n");
7979 if (gtk_widget_is_toplevel (widget))
7981 g_warning ("Can't set a parent on a toplevel widget\n");
7985 /* keep this function in sync with gtk_menu_attach_to_widget()
7988 g_object_ref_sink (widget);
7990 gtk_widget_push_verify_invariants (widget);
7992 priv->parent = parent;
7994 parent_flags = gtk_widget_get_state_flags (parent);
7996 /* Merge both old state and current parent state,
7997 * making sure to only propagate the right states */
7998 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7999 data.flags |= priv->state_flags;
8001 data.operation = STATE_CHANGE_REPLACE;
8002 gtk_widget_propagate_state (widget, &data);
8005 gtk_style_context_set_parent (priv->context,
8006 gtk_widget_get_style_context (parent));
8008 _gtk_widget_update_parent_muxer (widget);
8010 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8011 if (priv->parent->priv->anchored)
8012 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8013 g_object_notify (G_OBJECT (widget), "parent");
8015 /* Enforce realized/mapped invariants
8017 if (gtk_widget_get_realized (priv->parent))
8018 gtk_widget_realize (widget);
8020 if (gtk_widget_get_visible (priv->parent) &&
8021 gtk_widget_get_visible (widget))
8023 if (gtk_widget_get_child_visible (widget) &&
8024 gtk_widget_get_mapped (priv->parent))
8025 gtk_widget_map (widget);
8027 gtk_widget_queue_resize (widget);
8030 /* child may cause parent's expand to change, if the child is
8031 * expanded. If child is not expanded, then it can't modify the
8032 * parent's expand. If the child becomes expanded later then it will
8033 * queue compute_expand then. This optimization plus defaulting
8034 * newly-constructed widgets to need_compute_expand=FALSE should
8035 * mean that initially building a widget tree doesn't have to keep
8036 * walking up setting need_compute_expand on parents over and over.
8038 * We can't change a parent to need to expand unless we're visible.
8040 if (gtk_widget_get_visible (widget) &&
8041 (priv->need_compute_expand ||
8042 priv->computed_hexpand ||
8043 priv->computed_vexpand))
8045 gtk_widget_queue_compute_expand (parent);
8048 gtk_widget_pop_verify_invariants (widget);
8052 * gtk_widget_get_parent:
8053 * @widget: a #GtkWidget
8055 * Returns the parent container of @widget.
8057 * Return value: (transfer none): the parent container of @widget, or %NULL
8060 gtk_widget_get_parent (GtkWidget *widget)
8062 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8064 return widget->priv->parent;
8068 modifier_style_changed (GtkModifierStyle *style,
8071 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8074 static GtkModifierStyle *
8075 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8077 GtkModifierStyle *style;
8079 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8081 if (G_UNLIKELY (!style))
8083 GtkStyleContext *context;
8085 style = _gtk_modifier_style_new ();
8086 g_object_set_qdata_full (G_OBJECT (widget),
8087 quark_modifier_style,
8089 (GDestroyNotify) g_object_unref);
8091 g_signal_connect (style, "changed",
8092 G_CALLBACK (modifier_style_changed), widget);
8094 context = gtk_widget_get_style_context (widget);
8096 gtk_style_context_add_provider (context,
8097 GTK_STYLE_PROVIDER (style),
8098 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8105 * gtk_widget_override_color:
8106 * @widget: a #GtkWidget
8107 * @state: the state for which to set the color
8108 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8109 * of previous calls to gtk_widget_override_color()
8111 * Sets the color to use for a widget.
8113 * All other style values are left untouched.
8116 * This API is mostly meant as a quick way for applications to
8117 * change a widget appearance. If you are developing a widgets
8118 * library and intend this change to be themeable, it is better
8119 * done by setting meaningful CSS classes and regions in your
8120 * widget/container implementation through gtk_style_context_add_class()
8121 * and gtk_style_context_add_region().
8123 * This way, your widget library can install a #GtkCssProvider
8124 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8125 * to provide a default styling for those widgets that need so, and
8126 * this theming may fully overridden by the user's theme.
8129 * Note that for complex widgets this may bring in undesired
8130 * results (such as uniform background color everywhere), in
8131 * these cases it is better to fully style such widgets through a
8132 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8139 gtk_widget_override_color (GtkWidget *widget,
8140 GtkStateFlags state,
8141 const GdkRGBA *color)
8143 GtkModifierStyle *style;
8145 g_return_if_fail (GTK_IS_WIDGET (widget));
8147 style = _gtk_widget_get_modifier_properties (widget);
8148 _gtk_modifier_style_set_color (style, state, color);
8152 * gtk_widget_override_background_color:
8153 * @widget: a #GtkWidget
8154 * @state: the state for which to set the background color
8155 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8156 * of previous calls to gtk_widget_override_background_color()
8158 * Sets the background color to use for a widget.
8160 * All other style values are left untouched.
8161 * See gtk_widget_override_color().
8166 gtk_widget_override_background_color (GtkWidget *widget,
8167 GtkStateFlags state,
8168 const GdkRGBA *color)
8170 GtkModifierStyle *style;
8172 g_return_if_fail (GTK_IS_WIDGET (widget));
8174 style = _gtk_widget_get_modifier_properties (widget);
8175 _gtk_modifier_style_set_background_color (style, state, color);
8179 * gtk_widget_override_font:
8180 * @widget: a #GtkWidget
8181 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8182 * the effect of previous calls to gtk_widget_override_font()
8184 * Sets the font to use for a widget. All other style values are
8185 * left untouched. See gtk_widget_override_color().
8190 gtk_widget_override_font (GtkWidget *widget,
8191 const PangoFontDescription *font_desc)
8193 GtkModifierStyle *style;
8195 g_return_if_fail (GTK_IS_WIDGET (widget));
8197 style = _gtk_widget_get_modifier_properties (widget);
8198 _gtk_modifier_style_set_font (style, font_desc);
8202 * gtk_widget_override_symbolic_color:
8203 * @widget: a #GtkWidget
8204 * @name: the name of the symbolic color to modify
8205 * @color: (allow-none): the color to assign (does not need
8206 * to be allocated), or %NULL to undo the effect of previous
8207 * calls to gtk_widget_override_symbolic_color()
8209 * Sets a symbolic color for a widget.
8211 * All other style values are left untouched.
8212 * See gtk_widget_override_color() for overriding the foreground
8213 * or background color.
8218 gtk_widget_override_symbolic_color (GtkWidget *widget,
8220 const GdkRGBA *color)
8222 GtkModifierStyle *style;
8224 g_return_if_fail (GTK_IS_WIDGET (widget));
8226 style = _gtk_widget_get_modifier_properties (widget);
8227 _gtk_modifier_style_map_color (style, name, color);
8231 * gtk_widget_override_cursor:
8232 * @widget: a #GtkWidget
8233 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8234 * allocated), or %NULL to undo the effect of previous calls to
8235 * of gtk_widget_override_cursor().
8236 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8237 * need to be allocated), or %NULL to undo the effect of previous
8238 * calls to of gtk_widget_override_cursor().
8240 * Sets the cursor color to use in a widget, overriding the
8241 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8242 * style properties. All other style values are left untouched.
8243 * See also gtk_widget_modify_style().
8245 * Note that the underlying properties have the #GdkColor type,
8246 * so the alpha value in @primary and @secondary will be ignored.
8251 gtk_widget_override_cursor (GtkWidget *widget,
8252 const GdkRGBA *cursor,
8253 const GdkRGBA *secondary_cursor)
8255 GtkModifierStyle *style;
8257 g_return_if_fail (GTK_IS_WIDGET (widget));
8259 style = _gtk_widget_get_modifier_properties (widget);
8260 _gtk_modifier_style_set_color_property (style,
8262 "cursor-color", cursor);
8263 _gtk_modifier_style_set_color_property (style,
8265 "secondary-cursor-color",
8270 gtk_widget_real_direction_changed (GtkWidget *widget,
8271 GtkTextDirection previous_direction)
8273 gtk_widget_queue_resize (widget);
8277 gtk_widget_real_style_set (GtkWidget *widget,
8278 GtkStyle *previous_style)
8283 GtkWidget *previous_toplevel;
8284 GdkScreen *previous_screen;
8285 GdkScreen *new_screen;
8286 } HierarchyChangedInfo;
8289 do_screen_change (GtkWidget *widget,
8290 GdkScreen *old_screen,
8291 GdkScreen *new_screen)
8293 if (old_screen != new_screen)
8295 GtkWidgetPrivate *priv = widget->priv;
8299 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8301 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8304 _gtk_tooltip_hide (widget);
8306 if (new_screen && priv->context)
8307 gtk_style_context_set_screen (priv->context, new_screen);
8309 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8314 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8315 gpointer client_data)
8317 GtkWidgetPrivate *priv = widget->priv;
8318 HierarchyChangedInfo *info = client_data;
8319 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8320 (priv->parent && priv->parent->priv->anchored);
8322 if (priv->anchored != new_anchored)
8324 g_object_ref (widget);
8326 priv->anchored = new_anchored;
8328 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8329 do_screen_change (widget, info->previous_screen, info->new_screen);
8331 if (GTK_IS_CONTAINER (widget))
8332 gtk_container_forall (GTK_CONTAINER (widget),
8333 gtk_widget_propagate_hierarchy_changed_recurse,
8336 g_object_unref (widget);
8341 * _gtk_widget_propagate_hierarchy_changed:
8342 * @widget: a #GtkWidget
8343 * @previous_toplevel: Previous toplevel
8345 * Propagates changes in the anchored state to a widget and all
8346 * children, unsetting or setting the %ANCHORED flag, and
8347 * emitting #GtkWidget::hierarchy-changed.
8350 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8351 GtkWidget *previous_toplevel)
8353 GtkWidgetPrivate *priv = widget->priv;
8354 HierarchyChangedInfo info;
8356 info.previous_toplevel = previous_toplevel;
8357 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8359 if (gtk_widget_is_toplevel (widget) ||
8360 (priv->parent && priv->parent->priv->anchored))
8361 info.new_screen = gtk_widget_get_screen (widget);
8363 info.new_screen = NULL;
8365 if (info.previous_screen)
8366 g_object_ref (info.previous_screen);
8367 if (previous_toplevel)
8368 g_object_ref (previous_toplevel);
8370 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8372 if (previous_toplevel)
8373 g_object_unref (previous_toplevel);
8374 if (info.previous_screen)
8375 g_object_unref (info.previous_screen);
8379 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8380 gpointer client_data)
8382 HierarchyChangedInfo *info = client_data;
8384 g_object_ref (widget);
8386 do_screen_change (widget, info->previous_screen, info->new_screen);
8388 if (GTK_IS_CONTAINER (widget))
8389 gtk_container_forall (GTK_CONTAINER (widget),
8390 gtk_widget_propagate_screen_changed_recurse,
8393 g_object_unref (widget);
8397 * gtk_widget_is_composited:
8398 * @widget: a #GtkWidget
8400 * Whether @widget can rely on having its alpha channel
8401 * drawn correctly. On X11 this function returns whether a
8402 * compositing manager is running for @widget's screen.
8404 * Please note that the semantics of this call will change
8405 * in the future if used on a widget that has a composited
8406 * window in its hierarchy (as set by gdk_window_set_composited()).
8408 * Return value: %TRUE if the widget can rely on its alpha
8409 * channel being drawn correctly.
8414 gtk_widget_is_composited (GtkWidget *widget)
8418 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8420 screen = gtk_widget_get_screen (widget);
8422 return gdk_screen_is_composited (screen);
8426 propagate_composited_changed (GtkWidget *widget,
8429 if (GTK_IS_CONTAINER (widget))
8431 gtk_container_forall (GTK_CONTAINER (widget),
8432 propagate_composited_changed,
8436 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8440 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8442 propagate_composited_changed (widget, NULL);
8446 * _gtk_widget_propagate_screen_changed:
8447 * @widget: a #GtkWidget
8448 * @previous_screen: Previous screen
8450 * Propagates changes in the screen for a widget to all
8451 * children, emitting #GtkWidget::screen-changed.
8454 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8455 GdkScreen *previous_screen)
8457 HierarchyChangedInfo info;
8459 info.previous_screen = previous_screen;
8460 info.new_screen = gtk_widget_get_screen (widget);
8462 if (previous_screen)
8463 g_object_ref (previous_screen);
8465 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8467 if (previous_screen)
8468 g_object_unref (previous_screen);
8472 reset_style_recurse (GtkWidget *widget, gpointer data)
8474 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8476 if (GTK_IS_CONTAINER (widget))
8477 gtk_container_forall (GTK_CONTAINER (widget),
8478 reset_style_recurse,
8483 * gtk_widget_reset_style:
8484 * @widget: a #GtkWidget
8486 * Updates the style context of @widget and all descendents
8487 * by updating its widget path. #GtkContainer<!-- -->s may want
8488 * to use this on a child when reordering it in a way that a different
8489 * style might apply to it. See also gtk_container_get_path_for_child().
8494 gtk_widget_reset_style (GtkWidget *widget)
8496 g_return_if_fail (GTK_IS_WIDGET (widget));
8498 reset_style_recurse (widget, NULL);
8500 g_list_foreach (widget->priv->attached_windows,
8501 (GFunc) reset_style_recurse, NULL);
8504 #ifdef G_ENABLE_DEBUG
8506 /* Verify invariants, see docs/widget_system.txt for notes on much of
8507 * this. Invariants may be temporarily broken while we're in the
8508 * process of updating state, of course, so you can only
8509 * verify_invariants() after a given operation is complete.
8510 * Use push/pop_verify_invariants to help with that.
8513 gtk_widget_verify_invariants (GtkWidget *widget)
8517 if (widget->priv->verifying_invariants_count > 0)
8520 parent = widget->priv->parent;
8522 if (widget->priv->mapped)
8524 /* Mapped implies ... */
8526 if (!widget->priv->realized)
8527 g_warning ("%s %p is mapped but not realized",
8528 G_OBJECT_TYPE_NAME (widget), widget);
8530 if (!widget->priv->visible)
8531 g_warning ("%s %p is mapped but not visible",
8532 G_OBJECT_TYPE_NAME (widget), widget);
8534 if (!widget->priv->toplevel)
8536 if (!widget->priv->child_visible)
8537 g_warning ("%s %p is mapped but not child_visible",
8538 G_OBJECT_TYPE_NAME (widget), widget);
8543 /* Not mapped implies... */
8546 /* This check makes sense for normal toplevels, but for
8547 * something like a toplevel that is embedded within a clutter
8548 * state, mapping may depend on external factors.
8550 if (widget->priv->toplevel)
8552 if (widget->priv->visible)
8553 g_warning ("%s %p toplevel is visible but not mapped",
8554 G_OBJECT_TYPE_NAME (widget), widget);
8559 /* Parent related checks aren't possible if parent has
8560 * verifying_invariants_count > 0 because parent needs to recurse
8561 * children first before the invariants will hold.
8563 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8566 parent->priv->realized)
8568 /* Parent realized implies... */
8571 /* This is in widget_system.txt but appears to fail
8572 * because there's no gtk_container_realize() that
8573 * realizes all children... instead we just lazily
8574 * wait for map to fix things up.
8576 if (!widget->priv->realized)
8577 g_warning ("%s %p is realized but child %s %p is not realized",
8578 G_OBJECT_TYPE_NAME (parent), parent,
8579 G_OBJECT_TYPE_NAME (widget), widget);
8582 else if (!widget->priv->toplevel)
8584 /* No parent or parent not realized on non-toplevel implies... */
8586 if (widget->priv->realized && !widget->priv->in_reparent)
8587 g_warning ("%s %p is not realized but child %s %p is realized",
8588 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8589 G_OBJECT_TYPE_NAME (widget), widget);
8593 parent->priv->mapped &&
8594 widget->priv->visible &&
8595 widget->priv->child_visible)
8597 /* Parent mapped and we are visible implies... */
8599 if (!widget->priv->mapped)
8600 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8601 G_OBJECT_TYPE_NAME (parent), parent,
8602 G_OBJECT_TYPE_NAME (widget), widget);
8604 else if (!widget->priv->toplevel)
8606 /* No parent or parent not mapped on non-toplevel implies... */
8608 if (widget->priv->mapped && !widget->priv->in_reparent)
8609 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8610 G_OBJECT_TYPE_NAME (widget), widget,
8611 widget->priv->visible,
8612 widget->priv->child_visible,
8613 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8614 parent ? parent->priv->mapped : FALSE);
8618 if (!widget->priv->realized)
8620 /* Not realized implies... */
8623 /* widget_system.txt says these hold, but they don't. */
8624 if (widget->priv->alloc_needed)
8625 g_warning ("%s %p alloc needed but not realized",
8626 G_OBJECT_TYPE_NAME (widget), widget);
8628 if (widget->priv->width_request_needed)
8629 g_warning ("%s %p width request needed but not realized",
8630 G_OBJECT_TYPE_NAME (widget), widget);
8632 if (widget->priv->height_request_needed)
8633 g_warning ("%s %p height request needed but not realized",
8634 G_OBJECT_TYPE_NAME (widget), widget);
8639 /* The point of this push/pop is that invariants may not hold while
8640 * we're busy making changes. So we only check at the outermost call
8641 * on the call stack, after we finish updating everything.
8644 gtk_widget_push_verify_invariants (GtkWidget *widget)
8646 widget->priv->verifying_invariants_count += 1;
8650 gtk_widget_verify_child_invariants (GtkWidget *widget,
8651 gpointer client_data)
8653 /* We don't recurse further; this is a one-level check. */
8654 gtk_widget_verify_invariants (widget);
8658 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8660 g_assert (widget->priv->verifying_invariants_count > 0);
8662 widget->priv->verifying_invariants_count -= 1;
8664 if (widget->priv->verifying_invariants_count == 0)
8666 gtk_widget_verify_invariants (widget);
8668 if (GTK_IS_CONTAINER (widget))
8670 /* Check one level of children, because our
8671 * push_verify_invariants() will have prevented some of the
8672 * checks. This does not recurse because if recursion is
8673 * needed, it will happen naturally as each child has a
8674 * push/pop on that child. For example if we're recursively
8675 * mapping children, we'll push/pop on each child as we map
8678 gtk_container_forall (GTK_CONTAINER (widget),
8679 gtk_widget_verify_child_invariants,
8684 #endif /* G_ENABLE_DEBUG */
8686 static PangoContext *
8687 gtk_widget_peek_pango_context (GtkWidget *widget)
8689 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8693 * gtk_widget_get_pango_context:
8694 * @widget: a #GtkWidget
8696 * Gets a #PangoContext with the appropriate font map, font description,
8697 * and base direction for this widget. Unlike the context returned
8698 * by gtk_widget_create_pango_context(), this context is owned by
8699 * the widget (it can be used until the screen for the widget changes
8700 * or the widget is removed from its toplevel), and will be updated to
8701 * match any changes to the widget's attributes.
8703 * If you create and keep a #PangoLayout using this context, you must
8704 * deal with changes to the context by calling pango_layout_context_changed()
8705 * on the layout in response to the #GtkWidget::style-updated and
8706 * #GtkWidget::direction-changed signals for the widget.
8708 * Return value: (transfer none): the #PangoContext for the widget.
8711 gtk_widget_get_pango_context (GtkWidget *widget)
8713 PangoContext *context;
8715 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8717 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8720 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8721 g_object_set_qdata_full (G_OBJECT (widget),
8722 quark_pango_context,
8731 update_pango_context (GtkWidget *widget,
8732 PangoContext *context)
8734 const PangoFontDescription *font_desc;
8735 GtkStyleContext *style_context;
8737 style_context = gtk_widget_get_style_context (widget);
8739 font_desc = gtk_style_context_get_font (style_context,
8740 gtk_widget_get_state_flags (widget));
8742 pango_context_set_font_description (context, font_desc);
8743 pango_context_set_base_dir (context,
8744 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8745 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8749 gtk_widget_update_pango_context (GtkWidget *widget)
8751 PangoContext *context = gtk_widget_peek_pango_context (widget);
8757 update_pango_context (widget, context);
8759 screen = gtk_widget_get_screen_unchecked (widget);
8762 pango_cairo_context_set_resolution (context,
8763 gdk_screen_get_resolution (screen));
8764 pango_cairo_context_set_font_options (context,
8765 gdk_screen_get_font_options (screen));
8771 * gtk_widget_create_pango_context:
8772 * @widget: a #GtkWidget
8774 * Creates a new #PangoContext with the appropriate font map,
8775 * font description, and base direction for drawing text for
8776 * this widget. See also gtk_widget_get_pango_context().
8778 * Return value: (transfer full): the new #PangoContext
8781 gtk_widget_create_pango_context (GtkWidget *widget)
8784 PangoContext *context;
8786 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8788 screen = gtk_widget_get_screen_unchecked (widget);
8791 GTK_NOTE (MULTIHEAD,
8792 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8794 screen = gdk_screen_get_default ();
8797 context = gdk_pango_context_get_for_screen (screen);
8799 update_pango_context (widget, context);
8800 pango_context_set_language (context, gtk_get_default_language ());
8806 * gtk_widget_create_pango_layout:
8807 * @widget: a #GtkWidget
8808 * @text: text to set on the layout (can be %NULL)
8810 * Creates a new #PangoLayout with the appropriate font map,
8811 * font description, and base direction for drawing text for
8814 * If you keep a #PangoLayout created in this way around, in order to
8815 * notify the layout of changes to the base direction or font of this
8816 * widget, you must call pango_layout_context_changed() in response to
8817 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8820 * Return value: (transfer full): the new #PangoLayout
8823 gtk_widget_create_pango_layout (GtkWidget *widget,
8826 PangoLayout *layout;
8827 PangoContext *context;
8829 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8831 context = gtk_widget_get_pango_context (widget);
8832 layout = pango_layout_new (context);
8835 pango_layout_set_text (layout, text, -1);
8841 * gtk_widget_render_icon_pixbuf:
8842 * @widget: a #GtkWidget
8843 * @stock_id: a stock ID
8844 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8845 * render at the size of the source and don't scale (if there are
8846 * multiple source sizes, GTK+ picks one of the available sizes).
8848 * A convenience function that uses the theme engine and style
8849 * settings for @widget to look up @stock_id and render it to
8850 * a pixbuf. @stock_id should be a stock icon ID such as
8851 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8852 * such as #GTK_ICON_SIZE_MENU.
8854 * The pixels in the returned #GdkPixbuf are shared with the rest of
8855 * the application and should not be modified. The pixbuf should be freed
8856 * after use with g_object_unref().
8858 * Return value: (transfer full): a new pixbuf, or %NULL if the
8859 * stock ID wasn't known
8864 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8865 const gchar *stock_id,
8868 GtkStyleContext *context;
8869 GtkIconSet *icon_set;
8871 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8872 g_return_val_if_fail (stock_id != NULL, NULL);
8873 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8875 context = gtk_widget_get_style_context (widget);
8876 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8878 if (icon_set == NULL)
8881 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8885 * gtk_widget_set_parent_window:
8886 * @widget: a #GtkWidget.
8887 * @parent_window: the new parent window.
8889 * Sets a non default parent window for @widget.
8891 * For GtkWindow classes, setting a @parent_window effects whether
8892 * the window is a toplevel window or can be embedded into other
8896 * For GtkWindow classes, this needs to be called before the
8897 * window is realized.
8902 gtk_widget_set_parent_window (GtkWidget *widget,
8903 GdkWindow *parent_window)
8905 GdkWindow *old_parent_window;
8907 g_return_if_fail (GTK_IS_WIDGET (widget));
8909 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8910 quark_parent_window);
8912 if (parent_window != old_parent_window)
8916 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8918 if (old_parent_window)
8919 g_object_unref (old_parent_window);
8921 g_object_ref (parent_window);
8923 /* Unset toplevel flag when adding a parent window to a widget,
8924 * this is the primary entry point to allow toplevels to be
8927 #ifdef GDK_WINDOWING_X11
8928 is_plug = GTK_IS_PLUG (widget);
8932 if (GTK_IS_WINDOW (widget) && !is_plug)
8933 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8938 * gtk_widget_get_parent_window:
8939 * @widget: a #GtkWidget.
8941 * Gets @widget's parent window.
8943 * Returns: (transfer none): the parent window of @widget.
8946 gtk_widget_get_parent_window (GtkWidget *widget)
8948 GtkWidgetPrivate *priv;
8949 GdkWindow *parent_window;
8951 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8953 priv = widget->priv;
8955 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8957 return (parent_window != NULL) ? parent_window :
8958 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8963 * gtk_widget_set_child_visible:
8964 * @widget: a #GtkWidget
8965 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8967 * Sets whether @widget should be mapped along with its when its parent
8968 * is mapped and @widget has been shown with gtk_widget_show().
8970 * The child visibility can be set for widget before it is added to
8971 * a container with gtk_widget_set_parent(), to avoid mapping
8972 * children unnecessary before immediately unmapping them. However
8973 * it will be reset to its default state of %TRUE when the widget
8974 * is removed from a container.
8976 * Note that changing the child visibility of a widget does not
8977 * queue a resize on the widget. Most of the time, the size of
8978 * a widget is computed from all visible children, whether or
8979 * not they are mapped. If this is not the case, the container
8980 * can queue a resize itself.
8982 * This function is only useful for container implementations and
8983 * never should be called by an application.
8986 gtk_widget_set_child_visible (GtkWidget *widget,
8987 gboolean is_visible)
8989 GtkWidgetPrivate *priv;
8991 g_return_if_fail (GTK_IS_WIDGET (widget));
8992 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8994 priv = widget->priv;
8996 g_object_ref (widget);
8997 gtk_widget_verify_invariants (widget);
9000 priv->child_visible = TRUE;
9003 GtkWidget *toplevel;
9005 priv->child_visible = FALSE;
9007 toplevel = gtk_widget_get_toplevel (widget);
9008 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9009 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9012 if (priv->parent && gtk_widget_get_realized (priv->parent))
9014 if (gtk_widget_get_mapped (priv->parent) &&
9015 priv->child_visible &&
9016 gtk_widget_get_visible (widget))
9017 gtk_widget_map (widget);
9019 gtk_widget_unmap (widget);
9022 gtk_widget_verify_invariants (widget);
9023 g_object_unref (widget);
9027 * gtk_widget_get_child_visible:
9028 * @widget: a #GtkWidget
9030 * Gets the value set with gtk_widget_set_child_visible().
9031 * If you feel a need to use this function, your code probably
9032 * needs reorganization.
9034 * This function is only useful for container implementations and
9035 * never should be called by an application.
9037 * Return value: %TRUE if the widget is mapped with the parent.
9040 gtk_widget_get_child_visible (GtkWidget *widget)
9042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9044 return widget->priv->child_visible;
9048 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9050 GtkWidget *toplevel;
9052 toplevel = gtk_widget_get_toplevel (widget);
9054 if (gtk_widget_is_toplevel (toplevel))
9056 if (GTK_IS_WINDOW (toplevel))
9057 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9058 else if (GTK_IS_INVISIBLE (toplevel))
9059 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9066 * gtk_widget_get_screen:
9067 * @widget: a #GtkWidget
9069 * Get the #GdkScreen from the toplevel window associated with
9070 * this widget. This function can only be called after the widget
9071 * has been added to a widget hierarchy with a #GtkWindow
9074 * In general, you should only create screen specific
9075 * resources when a widget has been realized, and you should
9076 * free those resources when the widget is unrealized.
9078 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9083 gtk_widget_get_screen (GtkWidget *widget)
9087 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9089 screen = gtk_widget_get_screen_unchecked (widget);
9096 g_warning (G_STRLOC ": Can't get associated screen"
9097 " for a widget unless it is inside a toplevel GtkWindow\n"
9098 " widget type is %s associated top level type is %s",
9099 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9100 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9102 return gdk_screen_get_default ();
9107 * gtk_widget_has_screen:
9108 * @widget: a #GtkWidget
9110 * Checks whether there is a #GdkScreen is associated with
9111 * this widget. All toplevel widgets have an associated
9112 * screen, and all widgets added into a hierarchy with a toplevel
9113 * window at the top.
9115 * Return value: %TRUE if there is a #GdkScreen associcated
9121 gtk_widget_has_screen (GtkWidget *widget)
9123 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9125 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9129 * gtk_widget_get_display:
9130 * @widget: a #GtkWidget
9132 * Get the #GdkDisplay for the toplevel window associated with
9133 * this widget. This function can only be called after the widget
9134 * has been added to a widget hierarchy with a #GtkWindow at the top.
9136 * In general, you should only create display specific
9137 * resources when a widget has been realized, and you should
9138 * free those resources when the widget is unrealized.
9140 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9145 gtk_widget_get_display (GtkWidget *widget)
9147 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9149 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9153 * gtk_widget_get_root_window:
9154 * @widget: a #GtkWidget
9156 * Get the root window where this widget is located. This function can
9157 * only be called after the widget has been added to a widget
9158 * hierarchy with #GtkWindow at the top.
9160 * The root window is useful for such purposes as creating a popup
9161 * #GdkWindow associated with the window. In general, you should only
9162 * create display specific resources when a widget has been realized,
9163 * and you should free those resources when the widget is unrealized.
9165 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9170 gtk_widget_get_root_window (GtkWidget *widget)
9172 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9174 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9178 * gtk_widget_child_focus:
9179 * @widget: a #GtkWidget
9180 * @direction: direction of focus movement
9182 * This function is used by custom widget implementations; if you're
9183 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9184 * to a particular widget, and gtk_container_set_focus_chain() to
9185 * change the focus tab order. So you may want to investigate those
9186 * functions instead.
9188 * gtk_widget_child_focus() is called by containers as the user moves
9189 * around the window using keyboard shortcuts. @direction indicates
9190 * what kind of motion is taking place (up, down, left, right, tab
9191 * forward, tab backward). gtk_widget_child_focus() emits the
9192 * #GtkWidget::focus signal; widgets override the default handler
9193 * for this signal in order to implement appropriate focus behavior.
9195 * The default ::focus handler for a widget should return %TRUE if
9196 * moving in @direction left the focus on a focusable location inside
9197 * that widget, and %FALSE if moving in @direction moved the focus
9198 * outside the widget. If returning %TRUE, widgets normally
9199 * call gtk_widget_grab_focus() to place the focus accordingly;
9200 * if returning %FALSE, they don't modify the current focus location.
9202 * Return value: %TRUE if focus ended up inside @widget
9205 gtk_widget_child_focus (GtkWidget *widget,
9206 GtkDirectionType direction)
9208 gboolean return_val;
9210 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9212 if (!gtk_widget_get_visible (widget) ||
9213 !gtk_widget_is_sensitive (widget))
9216 /* child widgets must set CAN_FOCUS, containers
9217 * don't have to though.
9219 if (!GTK_IS_CONTAINER (widget) &&
9220 !gtk_widget_get_can_focus (widget))
9223 g_signal_emit (widget,
9224 widget_signals[FOCUS],
9226 direction, &return_val);
9232 * gtk_widget_keynav_failed:
9233 * @widget: a #GtkWidget
9234 * @direction: direction of focus movement
9236 * This function should be called whenever keyboard navigation within
9237 * a single widget hits a boundary. The function emits the
9238 * #GtkWidget::keynav-failed signal on the widget and its return
9239 * value should be interpreted in a way similar to the return value of
9240 * gtk_widget_child_focus():
9242 * When %TRUE is returned, stay in the widget, the failed keyboard
9243 * navigation is Ok and/or there is nowhere we can/should move the
9246 * When %FALSE is returned, the caller should continue with keyboard
9247 * navigation outside the widget, e.g. by calling
9248 * gtk_widget_child_focus() on the widget's toplevel.
9250 * The default ::keynav-failed handler returns %TRUE for
9251 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9252 * values of #GtkDirectionType, it looks at the
9253 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9254 * if the setting is %TRUE. This way the entire user interface
9255 * becomes cursor-navigatable on input devices such as mobile phones
9256 * which only have cursor keys but no tab key.
9258 * Whenever the default handler returns %TRUE, it also calls
9259 * gtk_widget_error_bell() to notify the user of the failed keyboard
9262 * A use case for providing an own implementation of ::keynav-failed
9263 * (either by connecting to it or by overriding it) would be a row of
9264 * #GtkEntry widgets where the user should be able to navigate the
9265 * entire row with the cursor keys, as e.g. known from user interfaces
9266 * that require entering license keys.
9268 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9269 * if the emitting widget should try to handle the keyboard
9270 * navigation attempt in its parent container(s).
9275 gtk_widget_keynav_failed (GtkWidget *widget,
9276 GtkDirectionType direction)
9278 gboolean return_val;
9280 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9282 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9283 direction, &return_val);
9289 * gtk_widget_error_bell:
9290 * @widget: a #GtkWidget
9292 * Notifies the user about an input-related error on this widget.
9293 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9294 * gdk_window_beep(), otherwise it does nothing.
9296 * Note that the effect of gdk_window_beep() can be configured in many
9297 * ways, depending on the windowing backend and the desktop environment
9298 * or window manager that is used.
9303 gtk_widget_error_bell (GtkWidget *widget)
9305 GtkWidgetPrivate *priv;
9306 GtkSettings* settings;
9309 g_return_if_fail (GTK_IS_WIDGET (widget));
9311 priv = widget->priv;
9313 settings = gtk_widget_get_settings (widget);
9317 g_object_get (settings,
9318 "gtk-error-bell", &beep,
9321 if (beep && priv->window)
9322 gdk_window_beep (priv->window);
9326 gtk_widget_set_usize_internal (GtkWidget *widget,
9329 GtkQueueResizeFlags flags)
9331 GtkWidgetAuxInfo *aux_info;
9332 gboolean changed = FALSE;
9334 g_object_freeze_notify (G_OBJECT (widget));
9336 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9338 if (width > -2 && aux_info->width != width)
9340 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9341 g_object_notify (G_OBJECT (widget), "width-request");
9342 aux_info->width = width;
9345 if (height > -2 && aux_info->height != height)
9347 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9348 g_object_notify (G_OBJECT (widget), "height-request");
9349 aux_info->height = height;
9353 if (gtk_widget_get_visible (widget) && changed)
9355 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9356 gtk_widget_queue_resize (widget);
9358 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9361 g_object_thaw_notify (G_OBJECT (widget));
9365 * gtk_widget_set_size_request:
9366 * @widget: a #GtkWidget
9367 * @width: width @widget should request, or -1 to unset
9368 * @height: height @widget should request, or -1 to unset
9370 * Sets the minimum size of a widget; that is, the widget's size
9371 * request will be at least @width by @height. You can use this
9372 * function to force a widget to be larger than it normally would be.
9374 * In most cases, gtk_window_set_default_size() is a better choice for
9375 * toplevel windows than this function; setting the default size will
9376 * still allow users to shrink the window. Setting the size request
9377 * will force them to leave the window at least as large as the size
9378 * request. When dealing with window sizes,
9379 * gtk_window_set_geometry_hints() can be a useful function as well.
9381 * Note the inherent danger of setting any fixed size - themes,
9382 * translations into other languages, different fonts, and user action
9383 * can all change the appropriate size for a given widget. So, it's
9384 * basically impossible to hardcode a size that will always be
9387 * The size request of a widget is the smallest size a widget can
9388 * accept while still functioning well and drawing itself correctly.
9389 * However in some strange cases a widget may be allocated less than
9390 * its requested size, and in many cases a widget may be allocated more
9391 * space than it requested.
9393 * If the size request in a given direction is -1 (unset), then
9394 * the "natural" size request of the widget will be used instead.
9396 * The size request set here does not include any margin from the
9397 * #GtkWidget properties margin-left, margin-right, margin-top, and
9398 * margin-bottom, but it does include pretty much all other padding
9399 * or border properties set by any subclass of #GtkWidget.
9402 gtk_widget_set_size_request (GtkWidget *widget,
9406 g_return_if_fail (GTK_IS_WIDGET (widget));
9407 g_return_if_fail (width >= -1);
9408 g_return_if_fail (height >= -1);
9415 gtk_widget_set_usize_internal (widget, width, height, 0);
9420 * gtk_widget_get_size_request:
9421 * @widget: a #GtkWidget
9422 * @width: (out) (allow-none): return location for width, or %NULL
9423 * @height: (out) (allow-none): return location for height, or %NULL
9425 * Gets the size request that was explicitly set for the widget using
9426 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9427 * @height indicates that that dimension has not been set explicitly
9428 * and the natural requisition of the widget will be used intead. See
9429 * gtk_widget_set_size_request(). To get the size a widget will
9430 * actually request, call gtk_widget_get_preferred_size() instead of
9434 gtk_widget_get_size_request (GtkWidget *widget,
9438 const GtkWidgetAuxInfo *aux_info;
9440 g_return_if_fail (GTK_IS_WIDGET (widget));
9442 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9445 *width = aux_info->width;
9448 *height = aux_info->height;
9452 * _gtk_widget_override_size_request:
9453 * @widget: a #GtkWidget
9454 * @width: new forced minimum width
9455 * @height: new forced minimum height
9456 * @old_width: location to store previous forced minimum width
9457 * @old_height: location to store previous forced minumum height
9459 * Temporarily establishes a forced minimum size for a widget; this
9460 * is used by GtkWindow when calculating the size to add to the
9461 * window's geometry widget. Cached sizes for the widget and its
9462 * parents are invalidated, so that subsequent calls to the size
9463 * negotiation machinery produce the overriden result, but the
9464 * widget is not queued for relayout or redraw. The old size must
9465 * be restored with _gtk_widget_restore_size_request() or things
9469 _gtk_widget_override_size_request (GtkWidget *widget,
9475 gtk_widget_get_size_request (widget, old_width, old_height);
9476 gtk_widget_set_usize_internal (widget, width, height,
9477 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9481 * _gtk_widget_restore_size_request:
9482 * @widget: a #GtkWidget
9483 * @old_width: saved forced minimum size
9484 * @old_height: saved forced minimum size
9486 * Undoes the operation of_gtk_widget_override_size_request().
9489 _gtk_widget_restore_size_request (GtkWidget *widget,
9493 gtk_widget_set_usize_internal (widget, old_width, old_height,
9494 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9498 * gtk_widget_set_events:
9499 * @widget: a #GtkWidget
9500 * @events: event mask
9502 * Sets the event mask (see #GdkEventMask) for a widget. The event
9503 * mask determines which events a widget will receive. Keep in mind
9504 * that different widgets have different default event masks, and by
9505 * changing the event mask you may disrupt a widget's functionality,
9506 * so be careful. This function must be called while a widget is
9507 * unrealized. Consider gtk_widget_add_events() for widgets that are
9508 * already realized, or if you want to preserve the existing event
9509 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9510 * to get events on those widgets, place them inside a #GtkEventBox
9511 * and receive events on the event box.
9514 gtk_widget_set_events (GtkWidget *widget,
9517 g_return_if_fail (GTK_IS_WIDGET (widget));
9518 g_return_if_fail (!gtk_widget_get_realized (widget));
9520 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9521 GINT_TO_POINTER (events));
9522 g_object_notify (G_OBJECT (widget), "events");
9526 * gtk_widget_set_device_events:
9527 * @widget: a #GtkWidget
9528 * @device: a #GdkDevice
9529 * @events: event mask
9531 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9532 * mask determines which events a widget will receive from @device. Keep
9533 * in mind that different widgets have different default event masks, and by
9534 * changing the event mask you may disrupt a widget's functionality,
9535 * so be careful. This function must be called while a widget is
9536 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9537 * already realized, or if you want to preserve the existing event
9538 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9539 * to get events on those widgets, place them inside a #GtkEventBox
9540 * and receive events on the event box.
9545 gtk_widget_set_device_events (GtkWidget *widget,
9547 GdkEventMask events)
9549 GHashTable *device_events;
9551 g_return_if_fail (GTK_IS_WIDGET (widget));
9552 g_return_if_fail (GDK_IS_DEVICE (device));
9553 g_return_if_fail (!gtk_widget_get_realized (widget));
9555 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9557 if (G_UNLIKELY (!device_events))
9559 device_events = g_hash_table_new (NULL, NULL);
9560 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9561 (GDestroyNotify) g_hash_table_unref);
9564 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9568 * gtk_widget_set_device_enabled:
9569 * @widget: a #GtkWidget
9570 * @device: a #GdkDevice
9571 * @enabled: whether to enable the device
9573 * Enables or disables a #GdkDevice to interact with @widget
9574 * and all its children.
9576 * It does so by descending through the #GdkWindow hierarchy
9577 * and enabling the same mask that is has for core events
9578 * (i.e. the one that gdk_window_get_events() returns).
9583 gtk_widget_set_device_enabled (GtkWidget *widget,
9587 GList *enabled_devices;
9589 g_return_if_fail (GTK_IS_WIDGET (widget));
9590 g_return_if_fail (GDK_IS_DEVICE (device));
9592 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9593 enabled_devices = g_list_append (enabled_devices, device);
9595 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9596 enabled_devices, (GDestroyNotify) g_list_free);;
9598 if (gtk_widget_get_realized (widget))
9599 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9603 * gtk_widget_get_device_enabled:
9604 * @widget: a #GtkWidget
9605 * @device: a #GdkDevice
9607 * Returns whether @device can interact with @widget and its
9608 * children. See gtk_widget_set_device_enabled().
9610 * Return value: %TRUE is @device is enabled for @widget
9615 gtk_widget_get_device_enabled (GtkWidget *widget,
9618 GList *enabled_devices;
9620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9621 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9623 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9625 return g_list_find (enabled_devices, device) != NULL;
9629 gtk_widget_add_events_internal_list (GtkWidget *widget,
9636 for (l = window_list; l != NULL; l = l->next)
9638 GdkWindow *window = l->data;
9641 gdk_window_get_user_data (window, &user_data);
9642 if (user_data == widget)
9647 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9649 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9651 children = gdk_window_get_children (window);
9652 gtk_widget_add_events_internal_list (widget, device, events, children);
9653 g_list_free (children);
9659 gtk_widget_add_events_internal (GtkWidget *widget,
9663 GtkWidgetPrivate *priv = widget->priv;
9666 if (!gtk_widget_get_has_window (widget))
9667 window_list = gdk_window_get_children (priv->window);
9669 window_list = g_list_prepend (NULL, priv->window);
9671 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9673 g_list_free (window_list);
9677 * gtk_widget_add_events:
9678 * @widget: a #GtkWidget
9679 * @events: an event mask, see #GdkEventMask
9681 * Adds the events in the bitfield @events to the event mask for
9682 * @widget. See gtk_widget_set_events() for details.
9685 gtk_widget_add_events (GtkWidget *widget,
9690 g_return_if_fail (GTK_IS_WIDGET (widget));
9692 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9693 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9694 GINT_TO_POINTER (old_events | events));
9696 if (gtk_widget_get_realized (widget))
9698 gtk_widget_add_events_internal (widget, NULL, events);
9699 gtk_widget_update_devices_mask (widget, FALSE);
9702 g_object_notify (G_OBJECT (widget), "events");
9706 * gtk_widget_add_device_events:
9707 * @widget: a #GtkWidget
9708 * @device: a #GdkDevice
9709 * @events: an event mask, see #GdkEventMask
9711 * Adds the device events in the bitfield @events to the event mask for
9712 * @widget. See gtk_widget_set_device_events() for details.
9717 gtk_widget_add_device_events (GtkWidget *widget,
9719 GdkEventMask events)
9721 GdkEventMask old_events;
9722 GHashTable *device_events;
9724 g_return_if_fail (GTK_IS_WIDGET (widget));
9725 g_return_if_fail (GDK_IS_DEVICE (device));
9727 old_events = gtk_widget_get_device_events (widget, device);
9729 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9731 if (G_UNLIKELY (!device_events))
9733 device_events = g_hash_table_new (NULL, NULL);
9734 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9735 (GDestroyNotify) g_hash_table_unref);
9738 g_hash_table_insert (device_events, device,
9739 GUINT_TO_POINTER (old_events | events));
9741 if (gtk_widget_get_realized (widget))
9742 gtk_widget_add_events_internal (widget, device, events);
9744 g_object_notify (G_OBJECT (widget), "events");
9748 * gtk_widget_get_toplevel:
9749 * @widget: a #GtkWidget
9751 * This function returns the topmost widget in the container hierarchy
9752 * @widget is a part of. If @widget has no parent widgets, it will be
9753 * returned as the topmost widget. No reference will be added to the
9754 * returned widget; it should not be unreferenced.
9756 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9757 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9759 * %NULL if @widget wasn't inside a toplevel window, and if the
9760 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9761 * inside the toplevel #GtkWindow. While the second case may
9762 * seem unlikely, it actually happens when a #GtkPlug is embedded
9763 * inside a #GtkSocket within the same application.
9765 * To reliably find the toplevel #GtkWindow, use
9766 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9767 * is set on the result.
9769 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9770 * if (gtk_widget_is_toplevel (toplevel))
9772 * /* Perform action on toplevel. */
9776 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9777 * if there's no ancestor.
9780 gtk_widget_get_toplevel (GtkWidget *widget)
9782 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9784 while (widget->priv->parent)
9785 widget = widget->priv->parent;
9791 * gtk_widget_get_ancestor:
9792 * @widget: a #GtkWidget
9793 * @widget_type: ancestor type
9795 * Gets the first ancestor of @widget with type @widget_type. For example,
9796 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9797 * the first #GtkBox that's an ancestor of @widget. No reference will be
9798 * added to the returned widget; it should not be unreferenced. See note
9799 * about checking for a toplevel #GtkWindow in the docs for
9800 * gtk_widget_get_toplevel().
9802 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9803 * considers @widget to be an ancestor of itself.
9805 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9808 gtk_widget_get_ancestor (GtkWidget *widget,
9811 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9813 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9814 widget = widget->priv->parent;
9816 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9823 * gtk_widget_set_visual:
9824 * @widget: a #GtkWidget
9825 * @visual: visual to be used or %NULL to unset a previous one
9827 * Sets the visual that should be used for by widget and its children for
9828 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9829 * returned by gtk_widget_get_screen(), so handling the
9830 * #GtkWidget::screen-changed signal is necessary.
9832 * Setting a new @visual will not cause @widget to recreate its windows,
9833 * so you should call this function before @widget is realized.
9836 gtk_widget_set_visual (GtkWidget *widget,
9839 g_return_if_fail (GTK_IS_WIDGET (widget));
9840 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9843 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9846 g_object_set_qdata_full (G_OBJECT (widget),
9848 g_object_ref (visual),
9853 * gtk_widget_get_visual:
9854 * @widget: a #GtkWidget
9856 * Gets the visual that will be used to render @widget.
9858 * Return value: (transfer none): the visual for @widget
9861 gtk_widget_get_visual (GtkWidget *widget)
9867 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9869 if (gtk_widget_get_has_window (widget) &&
9870 widget->priv->window)
9871 return gdk_window_get_visual (widget->priv->window);
9873 screen = gtk_widget_get_screen (widget);
9875 for (w = widget; w != NULL; w = w->priv->parent)
9877 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9880 if (gdk_visual_get_screen (visual) == screen)
9883 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9884 gtk_widget_get_name (widget));
9888 return gdk_screen_get_system_visual (screen);
9892 * gtk_widget_get_settings:
9893 * @widget: a #GtkWidget
9895 * Gets the settings object holding the settings used for this widget.
9897 * Note that this function can only be called when the #GtkWidget
9898 * is attached to a toplevel, since the settings object is specific
9899 * to a particular #GdkScreen.
9901 * Return value: (transfer none): the relevant #GtkSettings object
9904 gtk_widget_get_settings (GtkWidget *widget)
9906 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9908 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9912 * gtk_widget_get_events:
9913 * @widget: a #GtkWidget
9915 * Returns the event mask for the widget (a bitfield containing flags
9916 * from the #GdkEventMask enumeration). These are the events that the widget
9919 * Return value: event mask for @widget
9922 gtk_widget_get_events (GtkWidget *widget)
9924 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9926 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9930 * gtk_widget_get_device_events:
9931 * @widget: a #GtkWidget
9932 * @device: a #GdkDevice
9934 * Returns the events mask for the widget corresponding to an specific device. These
9935 * are the events that the widget will receive when @device operates on it.
9937 * Returns: device event mask for @widget
9942 gtk_widget_get_device_events (GtkWidget *widget,
9945 GHashTable *device_events;
9947 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9948 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9950 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9955 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9959 * gtk_widget_get_pointer:
9960 * @widget: a #GtkWidget
9961 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9962 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9964 * Obtains the location of the mouse pointer in widget coordinates.
9965 * Widget coordinates are a bit odd; for historical reasons, they are
9966 * defined as @widget->window coordinates for widgets that are not
9967 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9968 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9970 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9973 gtk_widget_get_pointer (GtkWidget *widget,
9977 GtkWidgetPrivate *priv;
9979 g_return_if_fail (GTK_IS_WIDGET (widget));
9981 priv = widget->priv;
9988 if (gtk_widget_get_realized (widget))
9990 gdk_window_get_device_position (priv->window,
9991 gdk_device_manager_get_client_pointer (
9992 gdk_display_get_device_manager (
9993 gtk_widget_get_display (widget))),
9996 if (!gtk_widget_get_has_window (widget))
9999 *x -= priv->allocation.x;
10001 *y -= priv->allocation.y;
10007 * gtk_widget_is_ancestor:
10008 * @widget: a #GtkWidget
10009 * @ancestor: another #GtkWidget
10011 * Determines whether @widget is somewhere inside @ancestor, possibly with
10012 * intermediate containers.
10014 * Return value: %TRUE if @ancestor contains @widget as a child,
10015 * grandchild, great grandchild, etc.
10018 gtk_widget_is_ancestor (GtkWidget *widget,
10019 GtkWidget *ancestor)
10021 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10022 g_return_val_if_fail (ancestor != NULL, FALSE);
10026 if (widget->priv->parent == ancestor)
10028 widget = widget->priv->parent;
10034 static GQuark quark_composite_name = 0;
10037 * gtk_widget_set_composite_name:
10038 * @widget: a #GtkWidget.
10039 * @name: the name to set
10041 * Sets a widgets composite name. The widget must be
10042 * a composite child of its parent; see gtk_widget_push_composite_child().
10045 gtk_widget_set_composite_name (GtkWidget *widget,
10048 g_return_if_fail (GTK_IS_WIDGET (widget));
10049 g_return_if_fail (widget->priv->composite_child);
10050 g_return_if_fail (name != NULL);
10052 if (!quark_composite_name)
10053 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10055 g_object_set_qdata_full (G_OBJECT (widget),
10056 quark_composite_name,
10062 * gtk_widget_get_composite_name:
10063 * @widget: a #GtkWidget
10065 * Obtains the composite name of a widget.
10067 * Returns: the composite name of @widget, or %NULL if @widget is not
10068 * a composite child. The string should be freed when it is no
10072 gtk_widget_get_composite_name (GtkWidget *widget)
10074 GtkWidgetPrivate *priv;
10076 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10078 priv = widget->priv;
10080 if (widget->priv->composite_child && priv->parent)
10081 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10088 * gtk_widget_push_composite_child:
10090 * Makes all newly-created widgets as composite children until
10091 * the corresponding gtk_widget_pop_composite_child() call.
10093 * A composite child is a child that's an implementation detail of the
10094 * container it's inside and should not be visible to people using the
10095 * container. Composite children aren't treated differently by GTK (but
10096 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10097 * builders might want to treat them in a different way.
10099 * Here is a simple example:
10101 * gtk_widget_push_composite_child ();
10102 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10103 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10104 * gtk_widget_pop_composite_child ();
10105 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10106 * GTK_WIDGET (scrolled_window));
10107 * g_object_ref (scrolled_window->hscrollbar);
10111 gtk_widget_push_composite_child (void)
10113 composite_child_stack++;
10117 * gtk_widget_pop_composite_child:
10119 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10122 gtk_widget_pop_composite_child (void)
10124 if (composite_child_stack)
10125 composite_child_stack--;
10129 gtk_widget_emit_direction_changed (GtkWidget *widget,
10130 GtkTextDirection old_dir)
10132 gtk_widget_update_pango_context (widget);
10134 if (widget->priv->context)
10135 gtk_style_context_set_direction (widget->priv->context,
10136 gtk_widget_get_direction (widget));
10138 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10142 * gtk_widget_set_direction:
10143 * @widget: a #GtkWidget
10144 * @dir: the new direction
10146 * Sets the reading direction on a particular widget. This direction
10147 * controls the primary direction for widgets containing text,
10148 * and also the direction in which the children of a container are
10149 * packed. The ability to set the direction is present in order
10150 * so that correct localization into languages with right-to-left
10151 * reading directions can be done. Generally, applications will
10152 * let the default reading direction present, except for containers
10153 * where the containers are arranged in an order that is explicitely
10154 * visual rather than logical (such as buttons for text justification).
10156 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10157 * set by gtk_widget_set_default_direction() will be used.
10160 gtk_widget_set_direction (GtkWidget *widget,
10161 GtkTextDirection dir)
10163 GtkTextDirection old_dir;
10165 g_return_if_fail (GTK_IS_WIDGET (widget));
10166 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10168 old_dir = gtk_widget_get_direction (widget);
10170 widget->priv->direction = dir;
10172 if (old_dir != gtk_widget_get_direction (widget))
10173 gtk_widget_emit_direction_changed (widget, old_dir);
10177 * gtk_widget_get_direction:
10178 * @widget: a #GtkWidget
10180 * Gets the reading direction for a particular widget. See
10181 * gtk_widget_set_direction().
10183 * Return value: the reading direction for the widget.
10186 gtk_widget_get_direction (GtkWidget *widget)
10188 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10190 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10191 return gtk_default_direction;
10193 return widget->priv->direction;
10197 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10199 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10201 g_object_ref (widget);
10203 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10204 gtk_widget_emit_direction_changed (widget, old_dir);
10206 if (GTK_IS_CONTAINER (widget))
10207 gtk_container_forall (GTK_CONTAINER (widget),
10208 gtk_widget_set_default_direction_recurse,
10211 g_object_unref (widget);
10215 * gtk_widget_set_default_direction:
10216 * @dir: the new default direction. This cannot be
10217 * %GTK_TEXT_DIR_NONE.
10219 * Sets the default reading direction for widgets where the
10220 * direction has not been explicitly set by gtk_widget_set_direction().
10223 gtk_widget_set_default_direction (GtkTextDirection dir)
10225 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10227 if (dir != gtk_default_direction)
10229 GList *toplevels, *tmp_list;
10230 GtkTextDirection old_dir = gtk_default_direction;
10232 gtk_default_direction = dir;
10234 tmp_list = toplevels = gtk_window_list_toplevels ();
10235 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10239 gtk_widget_set_default_direction_recurse (tmp_list->data,
10240 GUINT_TO_POINTER (old_dir));
10241 g_object_unref (tmp_list->data);
10242 tmp_list = tmp_list->next;
10245 g_list_free (toplevels);
10250 * gtk_widget_get_default_direction:
10252 * Obtains the current default reading direction. See
10253 * gtk_widget_set_default_direction().
10255 * Return value: the current default direction.
10258 gtk_widget_get_default_direction (void)
10260 return gtk_default_direction;
10264 gtk_widget_constructed (GObject *object)
10266 GtkWidget *widget = GTK_WIDGET (object);
10267 GtkWidgetPrivate *priv = widget->priv;
10269 /* As strange as it may seem, this may happen on object construction.
10270 * init() implementations of parent types may eventually call this function,
10271 * each with its corresponding GType, which could leave a child
10272 * implementation with a wrong widget type in the widget path
10275 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10277 gtk_widget_path_free (priv->path);
10281 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10285 gtk_widget_dispose (GObject *object)
10287 GtkWidget *widget = GTK_WIDGET (object);
10288 GtkWidgetPrivate *priv = widget->priv;
10291 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10292 else if (gtk_widget_get_visible (widget))
10293 gtk_widget_hide (widget);
10295 priv->visible = FALSE;
10296 if (gtk_widget_get_realized (widget))
10297 gtk_widget_unrealize (widget);
10299 if (!priv->in_destruction)
10301 priv->in_destruction = TRUE;
10302 g_signal_emit (object, widget_signals[DESTROY], 0);
10303 priv->in_destruction = FALSE;
10306 g_clear_object (&priv->muxer);
10308 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10312 gtk_widget_real_destroy (GtkWidget *object)
10314 /* gtk_object_destroy() will already hold a refcount on object */
10315 GtkWidget *widget = GTK_WIDGET (object);
10316 GtkWidgetPrivate *priv = widget->priv;
10318 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10320 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10324 gtk_accessible_set_widget (accessible, NULL);
10325 g_object_unref (accessible);
10329 /* wipe accelerator closures (keep order) */
10330 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10331 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10333 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10334 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10336 gtk_grab_remove (widget);
10339 g_object_unref (priv->style);
10340 priv->style = gtk_widget_get_default_style ();
10341 g_object_ref (priv->style);
10345 gtk_widget_finalize (GObject *object)
10347 GtkWidget *widget = GTK_WIDGET (object);
10348 GtkWidgetPrivate *priv = widget->priv;
10349 GtkWidgetAuxInfo *aux_info;
10350 GtkAccessible *accessible;
10352 gtk_grab_remove (widget);
10354 g_object_unref (priv->style);
10355 priv->style = NULL;
10357 g_free (priv->name);
10359 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10361 gtk_widget_aux_info_destroy (aux_info);
10363 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10365 g_object_unref (accessible);
10368 gtk_widget_path_free (priv->path);
10372 _gtk_style_context_set_widget (priv->context, NULL);
10373 g_object_unref (priv->context);
10376 _gtk_widget_free_cached_sizes (widget);
10378 if (g_object_is_floating (object))
10379 g_warning ("A floating object was finalized. This means that someone\n"
10380 "called g_object_unref() on an object that had only a floating\n"
10381 "reference; the initial floating reference is not owned by anyone\n"
10382 "and must be removed with g_object_ref_sink().");
10384 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10387 /*****************************************
10388 * gtk_widget_real_map:
10393 *****************************************/
10396 gtk_widget_real_map (GtkWidget *widget)
10398 GtkWidgetPrivate *priv = widget->priv;
10400 g_assert (gtk_widget_get_realized (widget));
10402 if (!gtk_widget_get_mapped (widget))
10404 gtk_widget_set_mapped (widget, TRUE);
10406 if (gtk_widget_get_has_window (widget))
10407 gdk_window_show (priv->window);
10411 /*****************************************
10412 * gtk_widget_real_unmap:
10417 *****************************************/
10420 gtk_widget_real_unmap (GtkWidget *widget)
10422 GtkWidgetPrivate *priv = widget->priv;
10424 if (gtk_widget_get_mapped (widget))
10426 gtk_widget_set_mapped (widget, FALSE);
10428 if (gtk_widget_get_has_window (widget))
10429 gdk_window_hide (priv->window);
10433 /*****************************************
10434 * gtk_widget_real_realize:
10439 *****************************************/
10442 gtk_widget_real_realize (GtkWidget *widget)
10444 GtkWidgetPrivate *priv = widget->priv;
10446 g_assert (!gtk_widget_get_has_window (widget));
10448 gtk_widget_set_realized (widget, TRUE);
10451 priv->window = gtk_widget_get_parent_window (widget);
10452 g_object_ref (priv->window);
10456 /*****************************************
10457 * gtk_widget_real_unrealize:
10462 *****************************************/
10465 gtk_widget_real_unrealize (GtkWidget *widget)
10467 GtkWidgetPrivate *priv = widget->priv;
10469 g_assert (!widget->priv->mapped);
10471 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10474 /* We must do unrealize child widget BEFORE container widget.
10475 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10476 * So, unrealizing container widget bofore its children causes the problem
10477 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10480 if (GTK_IS_CONTAINER (widget))
10481 gtk_container_forall (GTK_CONTAINER (widget),
10482 (GtkCallback) gtk_widget_unrealize,
10485 if (gtk_widget_get_has_window (widget))
10487 gdk_window_set_user_data (priv->window, NULL);
10488 gdk_window_destroy (priv->window);
10489 priv->window = NULL;
10493 g_object_unref (priv->window);
10494 priv->window = NULL;
10497 gtk_selection_remove_all (widget);
10499 gtk_widget_set_realized (widget, FALSE);
10503 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10504 GtkOrientation orientation,
10505 gint *minimum_size,
10506 gint *natural_size)
10508 const GtkWidgetAuxInfo *aux_info;
10510 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10512 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10513 aux_info->width > 0)
10515 *minimum_size = MAX (*minimum_size, aux_info->width);
10517 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10518 aux_info->height > 0)
10520 *minimum_size = MAX (*minimum_size, aux_info->height);
10523 /* Fix it if set_size_request made natural size smaller than min size.
10524 * This would also silently fix broken widgets, but we warn about them
10525 * in gtksizerequest.c when calling their size request vfuncs.
10527 *natural_size = MAX (*natural_size, *minimum_size);
10529 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10531 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10532 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10536 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10537 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10542 * _gtk_widget_peek_request_cache:
10544 * Returns the address of the widget's request cache (strictly for
10545 * internal use in gtksizerequest.c)
10547 * Return value: the address of @widget's size request cache.
10550 _gtk_widget_peek_request_cache (GtkWidget *widget)
10552 /* Don't bother slowing things down with the return_if_fail guards here */
10553 return &widget->priv->requests;
10557 * _gtk_widget_set_device_window:
10558 * @widget: a #GtkWidget
10559 * @device: a #GdkDevice
10560 * @window: the new device window
10562 * Sets pointer window for @widget and @device.
10563 * Does not ref @window.
10566 _gtk_widget_set_device_window (GtkWidget *widget,
10570 GHashTable *device_window;
10572 g_return_if_fail (GTK_IS_WIDGET (widget));
10573 g_return_if_fail (GDK_IS_DEVICE (device));
10574 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10576 if (!gtk_widget_get_mapped (widget))
10579 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10581 if (!device_window && window)
10583 device_window = g_hash_table_new (NULL, NULL);
10584 g_object_set_qdata_full (G_OBJECT (widget),
10585 quark_pointer_window,
10587 (GDestroyNotify) g_hash_table_destroy);
10591 g_hash_table_insert (device_window, device, window);
10592 else if (device_window)
10594 g_hash_table_remove (device_window, device);
10596 if (g_hash_table_size (device_window) == 0)
10597 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10602 * _gtk_widget_get_device_window:
10603 * @widget: a #GtkWidget
10604 * @device: a #GdkDevice
10606 * Return value: the device window set on @widget, or %NULL
10609 _gtk_widget_get_device_window (GtkWidget *widget,
10612 GHashTable *device_window;
10614 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10615 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10617 if (!gtk_widget_get_mapped (widget))
10620 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10622 if (!device_window)
10625 return g_hash_table_lookup (device_window, device);
10629 * _gtk_widget_list_devices:
10630 * @widget: a #GtkWidget
10632 * Returns the list of #GdkDevices that is currently on top
10633 * of any window belonging to @widget.
10634 * Free the list with g_list_free(), the elements are owned
10635 * by GTK+ and must not be freed.
10638 _gtk_widget_list_devices (GtkWidget *widget)
10640 GHashTableIter iter;
10641 GHashTable *device_window;
10642 GList *devices = NULL;
10643 gpointer key, value;
10645 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10647 if (!gtk_widget_get_mapped (widget))
10650 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10652 if (G_UNLIKELY (!device_window))
10655 g_hash_table_iter_init (&iter, device_window);
10657 while (g_hash_table_iter_next (&iter, &key, &value))
10658 devices = g_list_prepend (devices, key);
10664 synth_crossing (GtkWidget *widget,
10668 GdkCrossingMode mode,
10669 GdkNotifyType detail)
10673 event = gdk_event_new (type);
10675 event->crossing.window = g_object_ref (window);
10676 event->crossing.send_event = TRUE;
10677 event->crossing.subwindow = g_object_ref (window);
10678 event->crossing.time = GDK_CURRENT_TIME;
10679 event->crossing.x = event->crossing.y = 0;
10680 event->crossing.x_root = event->crossing.y_root = 0;
10681 event->crossing.mode = mode;
10682 event->crossing.detail = detail;
10683 event->crossing.focus = FALSE;
10684 event->crossing.state = 0;
10685 gdk_event_set_device (event, device);
10688 widget = gtk_get_event_widget (event);
10691 gtk_widget_event_internal (widget, event);
10693 gdk_event_free (event);
10697 * _gtk_widget_synthesize_crossing:
10698 * @from: the #GtkWidget the virtual pointer is leaving.
10699 * @to: the #GtkWidget the virtual pointer is moving to.
10700 * @mode: the #GdkCrossingMode to place on the synthesized events.
10702 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10704 * The real pointer window is the window that most recently received an enter notify
10705 * event. Windows that don't select for crossing events can't become the real
10706 * poiner window. The real pointer widget that owns the real pointer window. The
10707 * effective pointer window is the same as the real pointer window unless the real
10708 * pointer widget is either insensitive or there is a grab on a widget that is not
10709 * an ancestor of the real pointer widget (in which case the effective pointer
10710 * window should be the root window).
10712 * When the effective pointer window is the same as the real poiner window, we
10713 * receive crossing events from the windowing system. When the effective pointer
10714 * window changes to become different from the real pointer window we synthesize
10715 * crossing events, attempting to follow X protocol rules:
10717 * When the root window becomes the effective pointer window:
10718 * - leave notify on real pointer window, detail Ancestor
10719 * - leave notify on all of its ancestors, detail Virtual
10720 * - enter notify on root window, detail Inferior
10722 * When the root window ceases to be the effective pointer window:
10723 * - leave notify on root window, detail Inferior
10724 * - enter notify on all ancestors of real pointer window, detail Virtual
10725 * - enter notify on real pointer window, detail Ancestor
10728 _gtk_widget_synthesize_crossing (GtkWidget *from,
10731 GdkCrossingMode mode)
10733 GdkWindow *from_window = NULL, *to_window = NULL;
10735 g_return_if_fail (from != NULL || to != NULL);
10739 from_window = _gtk_widget_get_device_window (from, device);
10742 from_window = from->priv->window;
10747 to_window = _gtk_widget_get_device_window (to, device);
10750 to_window = to->priv->window;
10753 if (from_window == NULL && to_window == NULL)
10755 else if (from_window != NULL && to_window == NULL)
10757 GList *from_ancestors = NULL, *list;
10758 GdkWindow *from_ancestor = from_window;
10760 while (from_ancestor != NULL)
10762 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10763 if (from_ancestor == NULL)
10765 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10768 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10769 device, mode, GDK_NOTIFY_ANCESTOR);
10770 for (list = g_list_last (from_ancestors); list; list = list->prev)
10772 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10773 device, mode, GDK_NOTIFY_VIRTUAL);
10776 /* XXX: enter/inferior on root window? */
10778 g_list_free (from_ancestors);
10780 else if (from_window == NULL && to_window != NULL)
10782 GList *to_ancestors = NULL, *list;
10783 GdkWindow *to_ancestor = to_window;
10785 while (to_ancestor != NULL)
10787 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10788 if (to_ancestor == NULL)
10790 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10793 /* XXX: leave/inferior on root window? */
10795 for (list = to_ancestors; list; list = list->next)
10797 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10798 device, mode, GDK_NOTIFY_VIRTUAL);
10800 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10801 device, mode, GDK_NOTIFY_ANCESTOR);
10803 g_list_free (to_ancestors);
10805 else if (from_window == to_window)
10809 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10810 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10812 while (from_ancestor != NULL || to_ancestor != NULL)
10814 if (from_ancestor != NULL)
10816 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10817 if (from_ancestor == to_window)
10820 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10822 if (to_ancestor != NULL)
10824 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10825 if (to_ancestor == from_window)
10828 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10831 if (to_ancestor == from_window)
10833 if (mode != GDK_CROSSING_GTK_UNGRAB)
10834 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10835 device, mode, GDK_NOTIFY_INFERIOR);
10836 for (list = to_ancestors; list; list = list->next)
10837 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10838 device, mode, GDK_NOTIFY_VIRTUAL);
10839 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10840 device, mode, GDK_NOTIFY_ANCESTOR);
10842 else if (from_ancestor == to_window)
10844 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10845 device, mode, GDK_NOTIFY_ANCESTOR);
10846 for (list = g_list_last (from_ancestors); list; list = list->prev)
10848 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10849 device, mode, GDK_NOTIFY_VIRTUAL);
10851 if (mode != GDK_CROSSING_GTK_GRAB)
10852 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10853 device, mode, GDK_NOTIFY_INFERIOR);
10857 while (from_ancestors != NULL && to_ancestors != NULL
10858 && from_ancestors->data == to_ancestors->data)
10860 from_ancestors = g_list_delete_link (from_ancestors,
10862 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10865 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10866 device, mode, GDK_NOTIFY_NONLINEAR);
10868 for (list = g_list_last (from_ancestors); list; list = list->prev)
10870 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10871 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10873 for (list = to_ancestors; list; list = list->next)
10875 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10876 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10878 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10879 device, mode, GDK_NOTIFY_NONLINEAR);
10881 g_list_free (from_ancestors);
10882 g_list_free (to_ancestors);
10887 gtk_widget_propagate_state (GtkWidget *widget,
10888 GtkStateData *data)
10890 GtkWidgetPrivate *priv = widget->priv;
10891 GtkStateFlags new_flags, old_flags = priv->state_flags;
10892 GtkStateType old_state;
10894 old_state = gtk_widget_get_state (widget);
10896 switch (data->operation)
10898 case STATE_CHANGE_REPLACE:
10899 priv->state_flags = data->flags;
10901 case STATE_CHANGE_SET:
10902 priv->state_flags |= data->flags;
10904 case STATE_CHANGE_UNSET:
10905 priv->state_flags &= ~(data->flags);
10909 /* make insensitivity unoverridable */
10910 if (!priv->sensitive)
10911 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10913 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10917 window = gtk_widget_get_toplevel (widget);
10919 if (window && gtk_widget_is_toplevel (window))
10920 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10923 new_flags = priv->state_flags;
10925 if (old_flags != new_flags)
10927 g_object_ref (widget);
10929 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10930 gtk_grab_remove (widget);
10932 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10934 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10935 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10937 if (!priv->shadowed &&
10938 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10940 GList *event_windows = NULL;
10941 GList *devices, *d;
10943 devices = _gtk_widget_list_devices (widget);
10945 for (d = devices; d; d = d->next)
10951 window = _gtk_widget_get_device_window (widget, device);
10953 /* Do not propagate more than once to the
10954 * same window if non-multidevice aware.
10956 if (!gdk_window_get_support_multidevice (window) &&
10957 g_list_find (event_windows, window))
10960 if (!gtk_widget_is_sensitive (widget))
10961 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10962 GDK_CROSSING_STATE_CHANGED);
10964 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10965 GDK_CROSSING_STATE_CHANGED);
10967 event_windows = g_list_prepend (event_windows, window);
10970 g_list_free (event_windows);
10971 g_list_free (devices);
10974 if (GTK_IS_CONTAINER (widget))
10976 GtkStateData child_data = *data;
10978 /* Make sure to only propate the right states further */
10979 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10981 gtk_container_forall (GTK_CONTAINER (widget),
10982 (GtkCallback) gtk_widget_propagate_state,
10986 g_object_unref (widget);
10990 static const GtkWidgetAuxInfo default_aux_info = {
10998 * gtk_widget_get_aux_info:
10999 * @widget: a #GtkWidget
11000 * @create: if %TRUE, create the structure if it doesn't exist
11002 * Get the #GtkWidgetAuxInfo structure for the widget.
11004 * Return value: the #GtkAuxInfo structure for the widget, or
11005 * %NULL if @create is %FALSE and one doesn't already exist.
11007 static GtkWidgetAuxInfo *
11008 gtk_widget_get_aux_info (GtkWidget *widget,
11011 GtkWidgetAuxInfo *aux_info;
11013 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11014 if (!aux_info && create)
11016 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11018 *aux_info = default_aux_info;
11020 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11026 static const GtkWidgetAuxInfo*
11027 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11029 GtkWidgetAuxInfo *aux_info;
11031 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11032 if (aux_info == NULL)
11034 return &default_aux_info;
11042 /*****************************************
11043 * gtk_widget_aux_info_destroy:
11048 *****************************************/
11051 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11053 g_slice_free (GtkWidgetAuxInfo, aux_info);
11057 * gtk_widget_shape_combine_region:
11058 * @widget: a #GtkWidget
11059 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11061 * Sets a shape for this widget's GDK window. This allows for
11062 * transparent windows etc., see gdk_window_shape_combine_region()
11063 * for more information.
11068 gtk_widget_shape_combine_region (GtkWidget *widget,
11069 cairo_region_t *region)
11071 GtkWidgetPrivate *priv;
11073 g_return_if_fail (GTK_IS_WIDGET (widget));
11074 /* set_shape doesn't work on widgets without gdk window */
11075 g_return_if_fail (gtk_widget_get_has_window (widget));
11077 priv = widget->priv;
11079 if (region == NULL)
11081 priv->has_shape_mask = FALSE;
11084 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11086 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11090 priv->has_shape_mask = TRUE;
11092 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11093 cairo_region_copy (region),
11094 (GDestroyNotify) cairo_region_destroy);
11096 /* set shape if widget has a gdk window already.
11097 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11100 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11105 * gtk_widget_input_shape_combine_region:
11106 * @widget: a #GtkWidget
11107 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11109 * Sets an input shape for this widget's GDK window. This allows for
11110 * windows which react to mouse click in a nonrectangular region, see
11111 * gdk_window_input_shape_combine_region() for more information.
11116 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11117 cairo_region_t *region)
11119 GtkWidgetPrivate *priv;
11121 g_return_if_fail (GTK_IS_WIDGET (widget));
11122 /* set_shape doesn't work on widgets without gdk window */
11123 g_return_if_fail (gtk_widget_get_has_window (widget));
11125 priv = widget->priv;
11127 if (region == NULL)
11130 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11132 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11136 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11137 cairo_region_copy (region),
11138 (GDestroyNotify) cairo_region_destroy);
11140 /* set shape if widget has a gdk window already.
11141 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11144 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11149 /* style properties
11153 * gtk_widget_class_install_style_property_parser: (skip)
11154 * @klass: a #GtkWidgetClass
11155 * @pspec: the #GParamSpec for the style property
11156 * @parser: the parser for the style property
11158 * Installs a style property on a widget class.
11161 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11163 GtkRcPropertyParser parser)
11165 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11166 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11167 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11168 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11170 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11172 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11173 G_OBJECT_CLASS_NAME (klass),
11178 g_param_spec_ref_sink (pspec);
11179 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11180 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11184 * gtk_widget_class_install_style_property:
11185 * @klass: a #GtkWidgetClass
11186 * @pspec: the #GParamSpec for the property
11188 * Installs a style property on a widget class. The parser for the
11189 * style property is determined by the value type of @pspec.
11192 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11195 GtkRcPropertyParser parser;
11197 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11198 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11200 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11202 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11206 * gtk_widget_class_find_style_property:
11207 * @klass: a #GtkWidgetClass
11208 * @property_name: the name of the style property to find
11210 * Finds a style property of a widget class by name.
11212 * Returns: (transfer none): the #GParamSpec of the style property or
11213 * %NULL if @class has no style property with that name.
11218 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11219 const gchar *property_name)
11221 g_return_val_if_fail (property_name != NULL, NULL);
11223 return g_param_spec_pool_lookup (style_property_spec_pool,
11225 G_OBJECT_CLASS_TYPE (klass),
11230 * gtk_widget_class_list_style_properties:
11231 * @klass: a #GtkWidgetClass
11232 * @n_properties: location to return the number of style properties found
11234 * Returns all style properties of a widget class.
11236 * Returns: (array length=n_properties) (transfer container): a
11237 * newly allocated array of #GParamSpec*. The array must be
11238 * freed with g_free().
11243 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11244 guint *n_properties)
11246 GParamSpec **pspecs;
11249 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11250 G_OBJECT_CLASS_TYPE (klass),
11259 * gtk_widget_style_get_property:
11260 * @widget: a #GtkWidget
11261 * @property_name: the name of a style property
11262 * @value: location to return the property value
11264 * Gets the value of a style property of @widget.
11267 gtk_widget_style_get_property (GtkWidget *widget,
11268 const gchar *property_name,
11273 g_return_if_fail (GTK_IS_WIDGET (widget));
11274 g_return_if_fail (property_name != NULL);
11275 g_return_if_fail (G_IS_VALUE (value));
11277 g_object_ref (widget);
11278 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11280 G_OBJECT_TYPE (widget),
11283 g_warning ("%s: widget class `%s' has no property named `%s'",
11285 G_OBJECT_TYPE_NAME (widget),
11289 GtkStyleContext *context;
11290 const GValue *peek_value;
11291 GtkStateFlags state;
11293 context = gtk_widget_get_style_context (widget);
11294 state = gtk_widget_get_state_flags (widget);
11296 peek_value = _gtk_style_context_peek_style_property (context,
11297 G_OBJECT_TYPE (widget),
11300 /* auto-conversion of the caller's value type
11302 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11303 g_value_copy (peek_value, value);
11304 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11305 g_value_transform (peek_value, value);
11307 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11309 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11310 G_VALUE_TYPE_NAME (value));
11312 g_object_unref (widget);
11316 * gtk_widget_style_get_valist:
11317 * @widget: a #GtkWidget
11318 * @first_property_name: the name of the first property to get
11319 * @var_args: a <type>va_list</type> of pairs of property names and
11320 * locations to return the property values, starting with the location
11321 * for @first_property_name.
11323 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11327 gtk_widget_style_get_valist (GtkWidget *widget,
11328 const gchar *first_property_name,
11331 GtkStyleContext *context;
11332 GtkStateFlags state;
11335 g_return_if_fail (GTK_IS_WIDGET (widget));
11337 g_object_ref (widget);
11338 context = gtk_widget_get_style_context (widget);
11339 state = gtk_widget_get_state_flags (widget);
11341 name = first_property_name;
11344 const GValue *peek_value;
11348 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11350 G_OBJECT_TYPE (widget),
11354 g_warning ("%s: widget class `%s' has no property named `%s'",
11356 G_OBJECT_TYPE_NAME (widget),
11360 /* style pspecs are always readable so we can spare that check here */
11362 peek_value = _gtk_style_context_peek_style_property (context,
11363 G_OBJECT_TYPE (widget),
11366 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11369 g_warning ("%s: %s", G_STRLOC, error);
11374 name = va_arg (var_args, gchar*);
11377 g_object_unref (widget);
11381 * gtk_widget_style_get:
11382 * @widget: a #GtkWidget
11383 * @first_property_name: the name of the first property to get
11384 * @...: pairs of property names and locations to return the
11385 * property values, starting with the location for
11386 * @first_property_name, terminated by %NULL.
11388 * Gets the values of a multiple style properties of @widget.
11391 gtk_widget_style_get (GtkWidget *widget,
11392 const gchar *first_property_name,
11397 g_return_if_fail (GTK_IS_WIDGET (widget));
11399 va_start (var_args, first_property_name);
11400 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11405 * gtk_requisition_new:
11407 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11409 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11410 * be freed with gtk_requisition_free().
11415 gtk_requisition_new (void)
11417 return g_slice_new0 (GtkRequisition);
11421 * gtk_requisition_copy:
11422 * @requisition: a #GtkRequisition
11424 * Copies a #GtkRequisition.
11426 * Returns: a copy of @requisition
11429 gtk_requisition_copy (const GtkRequisition *requisition)
11431 return g_slice_dup (GtkRequisition, requisition);
11435 * gtk_requisition_free:
11436 * @requisition: a #GtkRequisition
11438 * Frees a #GtkRequisition.
11441 gtk_requisition_free (GtkRequisition *requisition)
11443 g_slice_free (GtkRequisition, requisition);
11446 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11447 gtk_requisition_copy,
11448 gtk_requisition_free)
11451 * gtk_widget_class_set_accessible_type:
11452 * @widget_class: class to set the accessible type for
11453 * @type: The object type that implements the accessible for @widget_class
11455 * Sets the type to be used for creating accessibles for widgets of
11456 * @widget_class. The given @type must be a subtype of the type used for
11457 * accessibles of the parent class.
11459 * This function should only be called from class init functions of widgets.
11464 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11467 GtkWidgetClassPrivate *priv;
11469 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11470 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11472 priv = widget_class->priv;
11474 priv->accessible_type = type;
11475 /* reset this - honoring the type's role is better. */
11476 priv->accessible_role = ATK_ROLE_INVALID;
11480 * gtk_widget_class_set_accessible_role:
11481 * @widget_class: class to set the accessible role for
11482 * @role: The role to use for accessibles created for @widget_class
11484 * Sets the default #AtkRole to be set on accessibles created for
11485 * widgets of @widget_class. Accessibles may decide to not honor this
11486 * setting if their role reporting is more refined. Calls to
11487 * gtk_widget_class_set_accessible_type() will reset this value.
11489 * In cases where you want more fine-grained control over the role of
11490 * accessibles created for @widget_class, you should provide your own
11491 * accessible type and use gtk_widget_class_set_accessible_type()
11494 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11495 * and the accessible's default role will be used instead.
11497 * This function should only be called from class init functions of widgets.
11502 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11505 GtkWidgetClassPrivate *priv;
11507 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11509 priv = widget_class->priv;
11511 priv->accessible_role = role;
11515 * _gtk_widget_peek_accessible:
11516 * @widget: a #GtkWidget
11518 * Gets the accessible for @widget, if it has been created yet.
11519 * Otherwise, this function returns %NULL. If the @widget's implementation
11520 * does not use the default way to create accessibles, %NULL will always be
11523 * Returns: the accessible for @widget or %NULL if none has been
11527 _gtk_widget_peek_accessible (GtkWidget *widget)
11529 return g_object_get_qdata (G_OBJECT (widget),
11530 quark_accessible_object);
11534 * gtk_widget_get_accessible:
11535 * @widget: a #GtkWidget
11537 * Returns the accessible object that describes the widget to an
11538 * assistive technology.
11540 * If accessibility support is not available, this #AtkObject
11541 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11542 * implementation is available for the widget instance in question,
11543 * it will inherit an #AtkObject implementation from the first ancestor
11544 * class for which such an implementation is defined.
11546 * The documentation of the
11547 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11548 * library contains more information about accessible objects and their uses.
11550 * Returns: (transfer none): the #AtkObject associated with @widget
11553 gtk_widget_get_accessible (GtkWidget *widget)
11555 GtkWidgetClass *klass;
11557 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11559 klass = GTK_WIDGET_GET_CLASS (widget);
11561 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11563 return klass->get_accessible (widget);
11567 gtk_widget_real_get_accessible (GtkWidget *widget)
11569 AtkObject* accessible;
11571 accessible = g_object_get_qdata (G_OBJECT (widget),
11572 quark_accessible_object);
11575 GtkWidgetClass *widget_class;
11576 GtkWidgetClassPrivate *priv;
11577 AtkObjectFactory *factory;
11578 AtkRegistry *default_registry;
11580 widget_class = GTK_WIDGET_GET_CLASS (widget);
11581 priv = widget_class->priv;
11583 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11585 default_registry = atk_get_default_registry ();
11586 factory = atk_registry_get_factory (default_registry,
11587 G_TYPE_FROM_INSTANCE (widget));
11589 atk_object_factory_create_accessible (factory,
11590 G_OBJECT (widget));
11592 if (priv->accessible_role != ATK_ROLE_INVALID)
11593 atk_object_set_role (accessible, priv->accessible_role);
11595 g_object_set_qdata (G_OBJECT (widget),
11596 quark_accessible_object,
11601 accessible = g_object_new (priv->accessible_type,
11604 if (priv->accessible_role != ATK_ROLE_INVALID)
11605 atk_object_set_role (accessible, priv->accessible_role);
11607 g_object_set_qdata (G_OBJECT (widget),
11608 quark_accessible_object,
11611 atk_object_initialize (accessible, widget);
11613 /* Set the role again, since we don't want a role set
11614 * in some parent initialize() function to override
11617 if (priv->accessible_role != ATK_ROLE_INVALID)
11618 atk_object_set_role (accessible, priv->accessible_role);
11625 * Initialize a AtkImplementorIface instance's virtual pointers as
11626 * appropriate to this implementor's class (GtkWidget).
11629 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11631 iface->ref_accessible = gtk_widget_ref_accessible;
11635 gtk_widget_ref_accessible (AtkImplementor *implementor)
11637 AtkObject *accessible;
11639 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11641 g_object_ref (accessible);
11646 * Expand flag management
11650 gtk_widget_update_computed_expand (GtkWidget *widget)
11652 GtkWidgetPrivate *priv;
11654 priv = widget->priv;
11656 if (priv->need_compute_expand)
11660 if (priv->hexpand_set)
11665 if (priv->vexpand_set)
11670 /* we don't need to use compute_expand if both expands are
11671 * forced by the app
11673 if (!(priv->hexpand_set && priv->vexpand_set))
11675 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11679 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11680 priv->hexpand_set ? &ignored : &h,
11681 priv->vexpand_set ? &ignored : &v);
11685 priv->need_compute_expand = FALSE;
11686 priv->computed_hexpand = h != FALSE;
11687 priv->computed_vexpand = v != FALSE;
11692 * gtk_widget_queue_compute_expand:
11693 * @widget: a #GtkWidget
11695 * Mark @widget as needing to recompute its expand flags. Call
11696 * this function when setting legacy expand child properties
11697 * on the child of a container.
11699 * See gtk_widget_compute_expand().
11702 gtk_widget_queue_compute_expand (GtkWidget *widget)
11705 gboolean changed_anything;
11707 if (widget->priv->need_compute_expand)
11710 changed_anything = FALSE;
11712 while (parent != NULL)
11714 if (!parent->priv->need_compute_expand)
11716 parent->priv->need_compute_expand = TRUE;
11717 changed_anything = TRUE;
11720 /* Note: if we had an invariant that "if a child needs to
11721 * compute expand, its parents also do" then we could stop going
11722 * up when we got to a parent that already needed to
11723 * compute. However, in general we compute expand lazily (as
11724 * soon as we see something in a subtree that is expand, we know
11725 * we're expanding) and so this invariant does not hold and we
11726 * have to always walk all the way up in case some ancestor
11727 * is not currently need_compute_expand.
11730 parent = parent->priv->parent;
11733 /* recomputing expand always requires
11734 * a relayout as well
11736 if (changed_anything)
11737 gtk_widget_queue_resize (widget);
11741 * gtk_widget_compute_expand:
11742 * @widget: the widget
11743 * @orientation: expand direction
11745 * Computes whether a container should give this widget extra space
11746 * when possible. Containers should check this, rather than
11747 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11749 * This function already checks whether the widget is visible, so
11750 * visibility does not need to be checked separately. Non-visible
11751 * widgets are not expanded.
11753 * The computed expand value uses either the expand setting explicitly
11754 * set on the widget itself, or, if none has been explicitly set,
11755 * the widget may expand if some of its children do.
11757 * Return value: whether widget tree rooted here should be expanded
11760 gtk_widget_compute_expand (GtkWidget *widget,
11761 GtkOrientation orientation)
11763 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11765 /* We never make a widget expand if not even showing. */
11766 if (!gtk_widget_get_visible (widget))
11769 gtk_widget_update_computed_expand (widget);
11771 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11773 return widget->priv->computed_hexpand;
11777 return widget->priv->computed_vexpand;
11782 gtk_widget_set_expand (GtkWidget *widget,
11783 GtkOrientation orientation,
11786 const char *expand_prop;
11787 const char *expand_set_prop;
11789 GtkWidgetPrivate *priv;
11791 g_return_if_fail (GTK_IS_WIDGET (widget));
11793 priv = widget->priv;
11795 expand = expand != FALSE;
11797 was_both = priv->hexpand && priv->vexpand;
11799 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11801 if (priv->hexpand_set &&
11802 priv->hexpand == expand)
11805 priv->hexpand_set = TRUE;
11806 priv->hexpand = expand;
11808 expand_prop = "hexpand";
11809 expand_set_prop = "hexpand-set";
11813 if (priv->vexpand_set &&
11814 priv->vexpand == expand)
11817 priv->vexpand_set = TRUE;
11818 priv->vexpand = expand;
11820 expand_prop = "vexpand";
11821 expand_set_prop = "vexpand-set";
11824 gtk_widget_queue_compute_expand (widget);
11826 g_object_freeze_notify (G_OBJECT (widget));
11827 g_object_notify (G_OBJECT (widget), expand_prop);
11828 g_object_notify (G_OBJECT (widget), expand_set_prop);
11829 if (was_both != (priv->hexpand && priv->vexpand))
11830 g_object_notify (G_OBJECT (widget), "expand");
11831 g_object_thaw_notify (G_OBJECT (widget));
11835 gtk_widget_set_expand_set (GtkWidget *widget,
11836 GtkOrientation orientation,
11839 GtkWidgetPrivate *priv;
11842 priv = widget->priv;
11844 set = set != FALSE;
11846 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11848 if (set == priv->hexpand_set)
11851 priv->hexpand_set = set;
11852 prop = "hexpand-set";
11856 if (set == priv->vexpand_set)
11859 priv->vexpand_set = set;
11860 prop = "vexpand-set";
11863 gtk_widget_queue_compute_expand (widget);
11865 g_object_notify (G_OBJECT (widget), prop);
11869 * gtk_widget_get_hexpand:
11870 * @widget: the widget
11872 * Gets whether the widget would like any available extra horizontal
11873 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11874 * generally receive the extra space. For example, a list or
11875 * scrollable area or document in your window would often be set to
11878 * Containers should use gtk_widget_compute_expand() rather than
11879 * this function, to see whether a widget, or any of its children,
11880 * has the expand flag set. If any child of a widget wants to
11881 * expand, the parent may ask to expand also.
11883 * This function only looks at the widget's own hexpand flag, rather
11884 * than computing whether the entire widget tree rooted at this widget
11887 * Return value: whether hexpand flag is set
11890 gtk_widget_get_hexpand (GtkWidget *widget)
11892 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11894 return widget->priv->hexpand;
11898 * gtk_widget_set_hexpand:
11899 * @widget: the widget
11900 * @expand: whether to expand
11902 * Sets whether the widget would like any available extra horizontal
11903 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11904 * generally receive the extra space. For example, a list or
11905 * scrollable area or document in your window would often be set to
11908 * Call this function to set the expand flag if you would like your
11909 * widget to become larger horizontally when the window has extra
11912 * By default, widgets automatically expand if any of their children
11913 * want to expand. (To see if a widget will automatically expand given
11914 * its current children and state, call gtk_widget_compute_expand(). A
11915 * container can decide how the expandability of children affects the
11916 * expansion of the container by overriding the compute_expand virtual
11917 * method on #GtkWidget.).
11919 * Setting hexpand explicitly with this function will override the
11920 * automatic expand behavior.
11922 * This function forces the widget to expand or not to expand,
11923 * regardless of children. The override occurs because
11924 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11925 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11926 * value to be used, rather than looking at children and widget state.
11929 gtk_widget_set_hexpand (GtkWidget *widget,
11932 g_return_if_fail (GTK_IS_WIDGET (widget));
11934 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11938 * gtk_widget_get_hexpand_set:
11939 * @widget: the widget
11941 * Gets whether gtk_widget_set_hexpand() has been used to
11942 * explicitly set the expand flag on this widget.
11944 * If hexpand is set, then it overrides any computed
11945 * expand value based on child widgets. If hexpand is not
11946 * set, then the expand value depends on whether any
11947 * children of the widget would like to expand.
11949 * There are few reasons to use this function, but it's here
11950 * for completeness and consistency.
11952 * Return value: whether hexpand has been explicitly set
11955 gtk_widget_get_hexpand_set (GtkWidget *widget)
11957 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11959 return widget->priv->hexpand_set;
11963 * gtk_widget_set_hexpand_set:
11964 * @widget: the widget
11965 * @set: value for hexpand-set property
11967 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11970 * The hexpand-set property will be set automatically when you call
11971 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11972 * reason to use this function would be to unset an explicit expand
11975 * If hexpand is set, then it overrides any computed
11976 * expand value based on child widgets. If hexpand is not
11977 * set, then the expand value depends on whether any
11978 * children of the widget would like to expand.
11980 * There are few reasons to use this function, but it's here
11981 * for completeness and consistency.
11984 gtk_widget_set_hexpand_set (GtkWidget *widget,
11987 g_return_if_fail (GTK_IS_WIDGET (widget));
11989 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11994 * gtk_widget_get_vexpand:
11995 * @widget: the widget
11997 * Gets whether the widget would like any available extra vertical
12000 * See gtk_widget_get_hexpand() for more detail.
12002 * Return value: whether vexpand flag is set
12005 gtk_widget_get_vexpand (GtkWidget *widget)
12007 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12009 return widget->priv->vexpand;
12013 * gtk_widget_set_vexpand:
12014 * @widget: the widget
12015 * @expand: whether to expand
12017 * Sets whether the widget would like any available extra vertical
12020 * See gtk_widget_set_hexpand() for more detail.
12023 gtk_widget_set_vexpand (GtkWidget *widget,
12026 g_return_if_fail (GTK_IS_WIDGET (widget));
12028 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12032 * gtk_widget_get_vexpand_set:
12033 * @widget: the widget
12035 * Gets whether gtk_widget_set_vexpand() has been used to
12036 * explicitly set the expand flag on this widget.
12038 * See gtk_widget_get_hexpand_set() for more detail.
12040 * Return value: whether vexpand has been explicitly set
12043 gtk_widget_get_vexpand_set (GtkWidget *widget)
12045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12047 return widget->priv->vexpand_set;
12051 * gtk_widget_set_vexpand_set:
12052 * @widget: the widget
12053 * @set: value for vexpand-set property
12055 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12058 * See gtk_widget_set_hexpand_set() for more detail.
12061 gtk_widget_set_vexpand_set (GtkWidget *widget,
12064 g_return_if_fail (GTK_IS_WIDGET (widget));
12066 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12070 * GtkBuildable implementation
12072 static GQuark quark_builder_has_default = 0;
12073 static GQuark quark_builder_has_focus = 0;
12074 static GQuark quark_builder_atk_relations = 0;
12075 static GQuark quark_builder_set_name = 0;
12078 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12080 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12081 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12082 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12083 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12085 iface->set_name = gtk_widget_buildable_set_name;
12086 iface->get_name = gtk_widget_buildable_get_name;
12087 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12088 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12089 iface->parser_finished = gtk_widget_buildable_parser_finished;
12090 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12091 iface->custom_finished = gtk_widget_buildable_custom_finished;
12095 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12098 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12099 g_strdup (name), g_free);
12102 static const gchar *
12103 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12105 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12109 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12110 GtkBuilder *builder,
12111 const gchar *childname)
12113 if (strcmp (childname, "accessible") == 0)
12114 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12120 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12121 GtkBuilder *builder,
12123 const GValue *value)
12125 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12126 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12127 GINT_TO_POINTER (TRUE));
12128 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12129 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12130 GINT_TO_POINTER (TRUE));
12132 g_object_set_property (G_OBJECT (buildable), name, value);
12137 gchar *action_name;
12138 GString *description;
12140 gboolean translatable;
12150 free_action (AtkActionData *data, gpointer user_data)
12152 g_free (data->action_name);
12153 g_string_free (data->description, TRUE);
12154 g_free (data->context);
12155 g_slice_free (AtkActionData, data);
12159 free_relation (AtkRelationData *data, gpointer user_data)
12161 g_free (data->target);
12162 g_free (data->type);
12163 g_slice_free (AtkRelationData, data);
12167 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12168 GtkBuilder *builder)
12170 GSList *atk_relations;
12172 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12173 gtk_widget_grab_default (GTK_WIDGET (buildable));
12174 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12175 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12177 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12178 quark_builder_atk_relations);
12181 AtkObject *accessible;
12182 AtkRelationSet *relation_set;
12185 AtkRelationType relation_type;
12186 AtkObject *target_accessible;
12188 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12189 relation_set = atk_object_ref_relation_set (accessible);
12191 for (l = atk_relations; l; l = l->next)
12193 AtkRelationData *relation = (AtkRelationData*)l->data;
12195 target = gtk_builder_get_object (builder, relation->target);
12198 g_warning ("Target object %s in <relation> does not exist",
12202 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12203 g_assert (target_accessible != NULL);
12205 relation_type = atk_relation_type_for_name (relation->type);
12206 if (relation_type == ATK_RELATION_NULL)
12208 g_warning ("<relation> type %s not found",
12212 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12213 target_accessible);
12215 g_object_unref (relation_set);
12217 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12218 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12227 } AccessibilitySubParserData;
12230 accessibility_start_element (GMarkupParseContext *context,
12231 const gchar *element_name,
12232 const gchar **names,
12233 const gchar **values,
12234 gpointer user_data,
12237 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12239 gint line_number, char_number;
12241 if (strcmp (element_name, "relation") == 0)
12243 gchar *target = NULL;
12244 gchar *type = NULL;
12245 AtkRelationData *relation;
12247 for (i = 0; names[i]; i++)
12249 if (strcmp (names[i], "target") == 0)
12250 target = g_strdup (values[i]);
12251 else if (strcmp (names[i], "type") == 0)
12252 type = g_strdup (values[i]);
12255 g_markup_parse_context_get_position (context,
12258 g_set_error (error,
12260 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12261 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12263 line_number, char_number, names[i], "relation");
12270 if (!target || !type)
12272 g_markup_parse_context_get_position (context,
12275 g_set_error (error,
12277 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12278 "%s:%d:%d <%s> requires attribute \"%s\"",
12280 line_number, char_number, "relation",
12281 type ? "target" : "type");
12287 relation = g_slice_new (AtkRelationData);
12288 relation->target = target;
12289 relation->type = type;
12291 data->relations = g_slist_prepend (data->relations, relation);
12293 else if (strcmp (element_name, "action") == 0)
12295 const gchar *action_name = NULL;
12296 const gchar *description = NULL;
12297 const gchar *msg_context = NULL;
12298 gboolean translatable = FALSE;
12299 AtkActionData *action;
12301 for (i = 0; names[i]; i++)
12303 if (strcmp (names[i], "action_name") == 0)
12304 action_name = values[i];
12305 else if (strcmp (names[i], "description") == 0)
12306 description = values[i];
12307 else if (strcmp (names[i], "translatable") == 0)
12309 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12312 else if (strcmp (names[i], "comments") == 0)
12314 /* do nothing, comments are for translators */
12316 else if (strcmp (names[i], "context") == 0)
12317 msg_context = values[i];
12320 g_markup_parse_context_get_position (context,
12323 g_set_error (error,
12325 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12326 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12328 line_number, char_number, names[i], "action");
12335 g_markup_parse_context_get_position (context,
12338 g_set_error (error,
12340 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12341 "%s:%d:%d <%s> requires attribute \"%s\"",
12343 line_number, char_number, "action",
12348 action = g_slice_new (AtkActionData);
12349 action->action_name = g_strdup (action_name);
12350 action->description = g_string_new (description);
12351 action->context = g_strdup (msg_context);
12352 action->translatable = translatable;
12354 data->actions = g_slist_prepend (data->actions, action);
12356 else if (strcmp (element_name, "accessibility") == 0)
12359 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12363 accessibility_text (GMarkupParseContext *context,
12366 gpointer user_data,
12369 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12371 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12373 AtkActionData *action = data->actions->data;
12375 g_string_append_len (action->description, text, text_len);
12379 static const GMarkupParser accessibility_parser =
12381 accessibility_start_element,
12383 accessibility_text,
12392 } AccelGroupParserData;
12395 accel_group_start_element (GMarkupParseContext *context,
12396 const gchar *element_name,
12397 const gchar **names,
12398 const gchar **values,
12399 gpointer user_data,
12404 guint modifiers = 0;
12405 gchar *signal = NULL;
12406 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12408 for (i = 0; names[i]; i++)
12410 if (strcmp (names[i], "key") == 0)
12411 key = gdk_keyval_from_name (values[i]);
12412 else if (strcmp (names[i], "modifiers") == 0)
12414 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12420 else if (strcmp (names[i], "signal") == 0)
12421 signal = g_strdup (values[i]);
12424 if (key == 0 || signal == NULL)
12426 g_warning ("<accelerator> requires key and signal attributes");
12429 parser_data->key = key;
12430 parser_data->modifiers = modifiers;
12431 parser_data->signal = signal;
12434 static const GMarkupParser accel_group_parser =
12436 accel_group_start_element,
12445 style_start_element (GMarkupParseContext *context,
12446 const gchar *element_name,
12447 const gchar **names,
12448 const gchar **values,
12449 gpointer user_data,
12452 StyleParserData *style_data = (StyleParserData *)user_data;
12455 if (strcmp (element_name, "class") == 0)
12457 if (g_markup_collect_attributes (element_name,
12461 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12462 G_MARKUP_COLLECT_INVALID))
12464 style_data->classes = g_slist_append (style_data->classes, class_name);
12467 else if (strcmp (element_name, "style") == 0)
12470 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12473 static const GMarkupParser style_parser =
12475 style_start_element,
12479 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12480 GtkBuilder *builder,
12482 const gchar *tagname,
12483 GMarkupParser *parser,
12486 g_assert (buildable);
12488 if (strcmp (tagname, "accelerator") == 0)
12490 AccelGroupParserData *parser_data;
12492 parser_data = g_slice_new0 (AccelGroupParserData);
12493 parser_data->object = g_object_ref (buildable);
12494 *parser = accel_group_parser;
12495 *data = parser_data;
12498 if (strcmp (tagname, "accessibility") == 0)
12500 AccessibilitySubParserData *parser_data;
12502 parser_data = g_slice_new0 (AccessibilitySubParserData);
12503 *parser = accessibility_parser;
12504 *data = parser_data;
12507 if (strcmp (tagname, "style") == 0)
12509 StyleParserData *parser_data;
12511 parser_data = g_slice_new0 (StyleParserData);
12512 *parser = style_parser;
12513 *data = parser_data;
12521 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12522 GtkWidget *toplevel,
12523 gpointer user_data)
12525 AccelGroupParserData *accel_data;
12526 GSList *accel_groups;
12527 GtkAccelGroup *accel_group;
12529 g_return_if_fail (GTK_IS_WIDGET (widget));
12530 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12531 g_return_if_fail (user_data != NULL);
12533 accel_data = (AccelGroupParserData*)user_data;
12534 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12535 if (g_slist_length (accel_groups) == 0)
12537 accel_group = gtk_accel_group_new ();
12538 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12542 g_assert (g_slist_length (accel_groups) == 1);
12543 accel_group = g_slist_nth_data (accel_groups, 0);
12546 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12547 accel_data->signal,
12550 accel_data->modifiers,
12551 GTK_ACCEL_VISIBLE);
12553 g_object_unref (accel_data->object);
12554 g_free (accel_data->signal);
12555 g_slice_free (AccelGroupParserData, accel_data);
12559 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12560 GtkBuilder *builder,
12562 const gchar *tagname,
12563 gpointer user_data)
12565 if (strcmp (tagname, "accelerator") == 0)
12567 AccelGroupParserData *accel_data;
12568 GtkWidget *toplevel;
12570 accel_data = (AccelGroupParserData*)user_data;
12571 g_assert (accel_data->object);
12573 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12575 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12577 else if (strcmp (tagname, "accessibility") == 0)
12579 AccessibilitySubParserData *a11y_data;
12581 a11y_data = (AccessibilitySubParserData*)user_data;
12583 if (a11y_data->actions)
12585 AtkObject *accessible;
12590 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12592 if (ATK_IS_ACTION (accessible))
12594 action = ATK_ACTION (accessible);
12595 n_actions = atk_action_get_n_actions (action);
12597 for (l = a11y_data->actions; l; l = l->next)
12599 AtkActionData *action_data = (AtkActionData*)l->data;
12601 for (i = 0; i < n_actions; i++)
12602 if (strcmp (atk_action_get_name (action, i),
12603 action_data->action_name) == 0)
12608 gchar *description;
12610 if (action_data->translatable && action_data->description->len)
12611 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12612 action_data->context,
12613 action_data->description->str);
12615 description = action_data->description->str;
12617 atk_action_set_description (action, i, description);
12622 g_warning ("accessibility action on a widget that does not implement AtkAction");
12624 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12627 if (a11y_data->relations)
12628 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12629 a11y_data->relations);
12631 g_slice_free (AccessibilitySubParserData, a11y_data);
12633 else if (strcmp (tagname, "style") == 0)
12635 StyleParserData *style_data = (StyleParserData *)user_data;
12636 GtkStyleContext *context;
12639 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12641 for (l = style_data->classes; l; l = l->next)
12642 gtk_style_context_add_class (context, (const gchar *)l->data);
12644 gtk_widget_reset_style (GTK_WIDGET (buildable));
12646 g_slist_free_full (style_data->classes, g_free);
12647 g_slice_free (StyleParserData, style_data);
12651 static GtkSizeRequestMode
12652 gtk_widget_real_get_request_mode (GtkWidget *widget)
12654 /* By default widgets dont trade size at all. */
12655 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12659 gtk_widget_real_get_width (GtkWidget *widget,
12660 gint *minimum_size,
12661 gint *natural_size)
12671 gtk_widget_real_get_height (GtkWidget *widget,
12672 gint *minimum_size,
12673 gint *natural_size)
12683 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12685 gint *minimum_height,
12686 gint *natural_height)
12688 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12692 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12694 gint *minimum_width,
12695 gint *natural_width)
12697 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12701 * gtk_widget_get_halign:
12702 * @widget: a #GtkWidget
12704 * Gets the value of the #GtkWidget:halign property.
12706 * Returns: the horizontal alignment of @widget
12709 gtk_widget_get_halign (GtkWidget *widget)
12711 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12712 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12716 * gtk_widget_set_halign:
12717 * @widget: a #GtkWidget
12718 * @align: the horizontal alignment
12720 * Sets the horizontal alignment of @widget.
12721 * See the #GtkWidget:halign property.
12724 gtk_widget_set_halign (GtkWidget *widget,
12727 GtkWidgetAuxInfo *aux_info;
12729 g_return_if_fail (GTK_IS_WIDGET (widget));
12731 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12733 if (aux_info->halign == align)
12736 aux_info->halign = align;
12737 gtk_widget_queue_resize (widget);
12738 g_object_notify (G_OBJECT (widget), "halign");
12742 * gtk_widget_get_valign:
12743 * @widget: a #GtkWidget
12745 * Gets the value of the #GtkWidget:valign property.
12747 * Returns: the vertical alignment of @widget
12750 gtk_widget_get_valign (GtkWidget *widget)
12752 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12753 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12757 * gtk_widget_set_valign:
12758 * @widget: a #GtkWidget
12759 * @align: the vertical alignment
12761 * Sets the vertical alignment of @widget.
12762 * See the #GtkWidget:valign property.
12765 gtk_widget_set_valign (GtkWidget *widget,
12768 GtkWidgetAuxInfo *aux_info;
12770 g_return_if_fail (GTK_IS_WIDGET (widget));
12772 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12774 if (aux_info->valign == align)
12777 aux_info->valign = align;
12778 gtk_widget_queue_resize (widget);
12779 g_object_notify (G_OBJECT (widget), "valign");
12783 * gtk_widget_get_margin_left:
12784 * @widget: a #GtkWidget
12786 * Gets the value of the #GtkWidget:margin-left property.
12788 * Returns: The left margin of @widget
12793 gtk_widget_get_margin_left (GtkWidget *widget)
12795 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12797 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12801 * gtk_widget_set_margin_left:
12802 * @widget: a #GtkWidget
12803 * @margin: the left margin
12805 * Sets the left margin of @widget.
12806 * See the #GtkWidget:margin-left property.
12811 gtk_widget_set_margin_left (GtkWidget *widget,
12814 GtkWidgetAuxInfo *aux_info;
12816 g_return_if_fail (GTK_IS_WIDGET (widget));
12817 g_return_if_fail (margin <= G_MAXINT16);
12819 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12821 if (aux_info->margin.left == margin)
12824 aux_info->margin.left = margin;
12825 gtk_widget_queue_resize (widget);
12826 g_object_notify (G_OBJECT (widget), "margin-left");
12830 * gtk_widget_get_margin_right:
12831 * @widget: a #GtkWidget
12833 * Gets the value of the #GtkWidget:margin-right property.
12835 * Returns: The right margin of @widget
12840 gtk_widget_get_margin_right (GtkWidget *widget)
12842 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12844 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12848 * gtk_widget_set_margin_right:
12849 * @widget: a #GtkWidget
12850 * @margin: the right margin
12852 * Sets the right margin of @widget.
12853 * See the #GtkWidget:margin-right property.
12858 gtk_widget_set_margin_right (GtkWidget *widget,
12861 GtkWidgetAuxInfo *aux_info;
12863 g_return_if_fail (GTK_IS_WIDGET (widget));
12864 g_return_if_fail (margin <= G_MAXINT16);
12866 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12868 if (aux_info->margin.right == margin)
12871 aux_info->margin.right = margin;
12872 gtk_widget_queue_resize (widget);
12873 g_object_notify (G_OBJECT (widget), "margin-right");
12877 * gtk_widget_get_margin_top:
12878 * @widget: a #GtkWidget
12880 * Gets the value of the #GtkWidget:margin-top property.
12882 * Returns: The top margin of @widget
12887 gtk_widget_get_margin_top (GtkWidget *widget)
12889 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12891 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12895 * gtk_widget_set_margin_top:
12896 * @widget: a #GtkWidget
12897 * @margin: the top margin
12899 * Sets the top margin of @widget.
12900 * See the #GtkWidget:margin-top property.
12905 gtk_widget_set_margin_top (GtkWidget *widget,
12908 GtkWidgetAuxInfo *aux_info;
12910 g_return_if_fail (GTK_IS_WIDGET (widget));
12911 g_return_if_fail (margin <= G_MAXINT16);
12913 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12915 if (aux_info->margin.top == margin)
12918 aux_info->margin.top = margin;
12919 gtk_widget_queue_resize (widget);
12920 g_object_notify (G_OBJECT (widget), "margin-top");
12924 * gtk_widget_get_margin_bottom:
12925 * @widget: a #GtkWidget
12927 * Gets the value of the #GtkWidget:margin-bottom property.
12929 * Returns: The bottom margin of @widget
12934 gtk_widget_get_margin_bottom (GtkWidget *widget)
12936 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12938 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12942 * gtk_widget_set_margin_bottom:
12943 * @widget: a #GtkWidget
12944 * @margin: the bottom margin
12946 * Sets the bottom margin of @widget.
12947 * See the #GtkWidget:margin-bottom property.
12952 gtk_widget_set_margin_bottom (GtkWidget *widget,
12955 GtkWidgetAuxInfo *aux_info;
12957 g_return_if_fail (GTK_IS_WIDGET (widget));
12958 g_return_if_fail (margin <= G_MAXINT16);
12960 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12962 if (aux_info->margin.bottom == margin)
12965 aux_info->margin.bottom = margin;
12966 gtk_widget_queue_resize (widget);
12967 g_object_notify (G_OBJECT (widget), "margin-bottom");
12971 * gtk_widget_get_clipboard:
12972 * @widget: a #GtkWidget
12973 * @selection: a #GdkAtom which identifies the clipboard
12974 * to use. %GDK_SELECTION_CLIPBOARD gives the
12975 * default clipboard. Another common value
12976 * is %GDK_SELECTION_PRIMARY, which gives
12977 * the primary X selection.
12979 * Returns the clipboard object for the given selection to
12980 * be used with @widget. @widget must have a #GdkDisplay
12981 * associated with it, so must be attached to a toplevel
12984 * Return value: (transfer none): the appropriate clipboard object. If no
12985 * clipboard already exists, a new one will
12986 * be created. Once a clipboard object has
12987 * been created, it is persistent for all time.
12992 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12995 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12997 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13002 * gtk_widget_list_mnemonic_labels:
13003 * @widget: a #GtkWidget
13005 * Returns a newly allocated list of the widgets, normally labels, for
13006 * which this widget is the target of a mnemonic (see for example,
13007 * gtk_label_set_mnemonic_widget()).
13009 * The widgets in the list are not individually referenced. If you
13010 * want to iterate through the list and perform actions involving
13011 * callbacks that might destroy the widgets, you
13012 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13013 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13014 * widgets afterwards.
13016 * Return value: (element-type GtkWidget) (transfer container): the list of
13017 * mnemonic labels; free this list
13018 * with g_list_free() when you are done with it.
13023 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13025 GList *list = NULL;
13028 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13030 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13031 list = g_list_prepend (list, l->data);
13037 * gtk_widget_add_mnemonic_label:
13038 * @widget: a #GtkWidget
13039 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13041 * Adds a widget to the list of mnemonic labels for
13042 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13043 * list of mnemonic labels for the widget is cleared when the
13044 * widget is destroyed, so the caller must make sure to update
13045 * its internal state at this point as well, by using a connection
13046 * to the #GtkWidget::destroy signal or a weak notifier.
13051 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13054 GSList *old_list, *new_list;
13056 g_return_if_fail (GTK_IS_WIDGET (widget));
13057 g_return_if_fail (GTK_IS_WIDGET (label));
13059 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13060 new_list = g_slist_prepend (old_list, label);
13062 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13063 new_list, (GDestroyNotify) g_slist_free);
13067 * gtk_widget_remove_mnemonic_label:
13068 * @widget: a #GtkWidget
13069 * @label: a #GtkWidget that was previously set as a mnemnic label for
13070 * @widget with gtk_widget_add_mnemonic_label().
13072 * Removes a widget from the list of mnemonic labels for
13073 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13074 * must have previously been added to the list with
13075 * gtk_widget_add_mnemonic_label().
13080 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13083 GSList *old_list, *new_list;
13085 g_return_if_fail (GTK_IS_WIDGET (widget));
13086 g_return_if_fail (GTK_IS_WIDGET (label));
13088 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13089 new_list = g_slist_remove (old_list, label);
13092 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13093 new_list, (GDestroyNotify) g_slist_free);
13097 * gtk_widget_get_no_show_all:
13098 * @widget: a #GtkWidget
13100 * Returns the current value of the #GtkWidget:no-show-all property,
13101 * which determines whether calls to gtk_widget_show_all()
13102 * will affect this widget.
13104 * Return value: the current value of the "no-show-all" property.
13109 gtk_widget_get_no_show_all (GtkWidget *widget)
13111 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13113 return widget->priv->no_show_all;
13117 * gtk_widget_set_no_show_all:
13118 * @widget: a #GtkWidget
13119 * @no_show_all: the new value for the "no-show-all" property
13121 * Sets the #GtkWidget:no-show-all property, which determines whether
13122 * calls to gtk_widget_show_all() will affect this widget.
13124 * This is mostly for use in constructing widget hierarchies with externally
13125 * controlled visibility, see #GtkUIManager.
13130 gtk_widget_set_no_show_all (GtkWidget *widget,
13131 gboolean no_show_all)
13133 g_return_if_fail (GTK_IS_WIDGET (widget));
13135 no_show_all = (no_show_all != FALSE);
13137 if (widget->priv->no_show_all != no_show_all)
13139 widget->priv->no_show_all = no_show_all;
13141 g_object_notify (G_OBJECT (widget), "no-show-all");
13147 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13148 gboolean has_tooltip,
13151 GtkWidgetPrivate *priv = widget->priv;
13152 gboolean priv_has_tooltip;
13154 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13155 quark_has_tooltip));
13157 if (priv_has_tooltip != has_tooltip || force)
13159 priv_has_tooltip = has_tooltip;
13161 if (priv_has_tooltip)
13163 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13164 gdk_window_set_events (priv->window,
13165 gdk_window_get_events (priv->window) |
13166 GDK_LEAVE_NOTIFY_MASK |
13167 GDK_POINTER_MOTION_MASK |
13168 GDK_POINTER_MOTION_HINT_MASK);
13170 if (gtk_widget_get_has_window (widget))
13171 gtk_widget_add_events (widget,
13172 GDK_LEAVE_NOTIFY_MASK |
13173 GDK_POINTER_MOTION_MASK |
13174 GDK_POINTER_MOTION_HINT_MASK);
13177 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13178 GUINT_TO_POINTER (priv_has_tooltip));
13183 * gtk_widget_set_tooltip_window:
13184 * @widget: a #GtkWidget
13185 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13187 * Replaces the default, usually yellow, window used for displaying
13188 * tooltips with @custom_window. GTK+ will take care of showing and
13189 * hiding @custom_window at the right moment, to behave likewise as
13190 * the default tooltip window. If @custom_window is %NULL, the default
13191 * tooltip window will be used.
13193 * If the custom window should have the default theming it needs to
13194 * have the name "gtk-tooltip", see gtk_widget_set_name().
13199 gtk_widget_set_tooltip_window (GtkWidget *widget,
13200 GtkWindow *custom_window)
13202 gboolean has_tooltip;
13203 gchar *tooltip_markup;
13205 g_return_if_fail (GTK_IS_WIDGET (widget));
13206 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13208 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13211 g_object_ref (custom_window);
13213 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13214 custom_window, g_object_unref);
13216 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13217 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13219 if (has_tooltip && gtk_widget_get_visible (widget))
13220 gtk_widget_queue_tooltip_query (widget);
13224 * gtk_widget_get_tooltip_window:
13225 * @widget: a #GtkWidget
13227 * Returns the #GtkWindow of the current tooltip. This can be the
13228 * GtkWindow created by default, or the custom tooltip window set
13229 * using gtk_widget_set_tooltip_window().
13231 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13236 gtk_widget_get_tooltip_window (GtkWidget *widget)
13238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13240 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13244 * gtk_widget_trigger_tooltip_query:
13245 * @widget: a #GtkWidget
13247 * Triggers a tooltip query on the display where the toplevel of @widget
13248 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13254 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13256 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13259 static guint tooltip_query_id;
13260 static GSList *tooltip_query_displays;
13263 tooltip_query_idle (gpointer data)
13265 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13266 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13267 g_slist_free (tooltip_query_displays);
13269 tooltip_query_displays = NULL;
13270 tooltip_query_id = 0;
13276 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13278 GdkDisplay *display;
13280 display = gtk_widget_get_display (widget);
13282 if (!g_slist_find (tooltip_query_displays, display))
13283 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13285 if (tooltip_query_id == 0)
13286 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13290 * gtk_widget_set_tooltip_text:
13291 * @widget: a #GtkWidget
13292 * @text: the contents of the tooltip for @widget
13294 * Sets @text as the contents of the tooltip. This function will take
13295 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13296 * handler for the #GtkWidget::query-tooltip signal.
13298 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13303 gtk_widget_set_tooltip_text (GtkWidget *widget,
13306 g_return_if_fail (GTK_IS_WIDGET (widget));
13308 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13312 * gtk_widget_get_tooltip_text:
13313 * @widget: a #GtkWidget
13315 * Gets the contents of the tooltip for @widget.
13317 * Return value: the tooltip text, or %NULL. You should free the
13318 * returned string with g_free() when done.
13323 gtk_widget_get_tooltip_text (GtkWidget *widget)
13325 gchar *text = NULL;
13327 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13329 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13335 * gtk_widget_set_tooltip_markup:
13336 * @widget: a #GtkWidget
13337 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13339 * Sets @markup as the contents of the tooltip, which is marked up with
13340 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13342 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13343 * and of the default handler for the #GtkWidget::query-tooltip signal.
13345 * See also the #GtkWidget:tooltip-markup property and
13346 * gtk_tooltip_set_markup().
13351 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13352 const gchar *markup)
13354 g_return_if_fail (GTK_IS_WIDGET (widget));
13356 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13360 * gtk_widget_get_tooltip_markup:
13361 * @widget: a #GtkWidget
13363 * Gets the contents of the tooltip for @widget.
13365 * Return value: the tooltip text, or %NULL. You should free the
13366 * returned string with g_free() when done.
13371 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13373 gchar *text = NULL;
13375 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13377 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13383 * gtk_widget_set_has_tooltip:
13384 * @widget: a #GtkWidget
13385 * @has_tooltip: whether or not @widget has a tooltip.
13387 * Sets the has-tooltip property on @widget to @has_tooltip. See
13388 * #GtkWidget:has-tooltip for more information.
13393 gtk_widget_set_has_tooltip (GtkWidget *widget,
13394 gboolean has_tooltip)
13396 g_return_if_fail (GTK_IS_WIDGET (widget));
13398 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13402 * gtk_widget_get_has_tooltip:
13403 * @widget: a #GtkWidget
13405 * Returns the current value of the has-tooltip property. See
13406 * #GtkWidget:has-tooltip for more information.
13408 * Return value: current value of has-tooltip on @widget.
13413 gtk_widget_get_has_tooltip (GtkWidget *widget)
13415 gboolean has_tooltip = FALSE;
13417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13419 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13421 return has_tooltip;
13425 * gtk_widget_get_allocation:
13426 * @widget: a #GtkWidget
13427 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13429 * Retrieves the widget's allocation.
13431 * Note, when implementing a #GtkContainer: a widget's allocation will
13432 * be its "adjusted" allocation, that is, the widget's parent
13433 * container typically calls gtk_widget_size_allocate() with an
13434 * allocation, and that allocation is then adjusted (to handle margin
13435 * and alignment for example) before assignment to the widget.
13436 * gtk_widget_get_allocation() returns the adjusted allocation that
13437 * was actually assigned to the widget. The adjusted allocation is
13438 * guaranteed to be completely contained within the
13439 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13440 * is guaranteed that its children stay inside the assigned bounds,
13441 * but not that they have exactly the bounds the container assigned.
13442 * There is no way to get the original allocation assigned by
13443 * gtk_widget_size_allocate(), since it isn't stored; if a container
13444 * implementation needs that information it will have to track it itself.
13449 gtk_widget_get_allocation (GtkWidget *widget,
13450 GtkAllocation *allocation)
13452 GtkWidgetPrivate *priv;
13454 g_return_if_fail (GTK_IS_WIDGET (widget));
13455 g_return_if_fail (allocation != NULL);
13457 priv = widget->priv;
13459 *allocation = priv->allocation;
13463 * gtk_widget_set_allocation:
13464 * @widget: a #GtkWidget
13465 * @allocation: a pointer to a #GtkAllocation to copy from
13467 * Sets the widget's allocation. This should not be used
13468 * directly, but from within a widget's size_allocate method.
13470 * The allocation set should be the "adjusted" or actual
13471 * allocation. If you're implementing a #GtkContainer, you want to use
13472 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13473 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13474 * allocation inside gtk_widget_size_allocate() to create an adjusted
13480 gtk_widget_set_allocation (GtkWidget *widget,
13481 const GtkAllocation *allocation)
13483 GtkWidgetPrivate *priv;
13485 g_return_if_fail (GTK_IS_WIDGET (widget));
13486 g_return_if_fail (allocation != NULL);
13488 priv = widget->priv;
13490 priv->allocation = *allocation;
13494 * gtk_widget_get_allocated_width:
13495 * @widget: the widget to query
13497 * Returns the width that has currently been allocated to @widget.
13498 * This function is intended to be used when implementing handlers
13499 * for the #GtkWidget::draw function.
13501 * Returns: the width of the @widget
13504 gtk_widget_get_allocated_width (GtkWidget *widget)
13506 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13508 return widget->priv->allocation.width;
13512 * gtk_widget_get_allocated_height:
13513 * @widget: the widget to query
13515 * Returns the height that has currently been allocated to @widget.
13516 * This function is intended to be used when implementing handlers
13517 * for the #GtkWidget::draw function.
13519 * Returns: the height of the @widget
13522 gtk_widget_get_allocated_height (GtkWidget *widget)
13524 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13526 return widget->priv->allocation.height;
13530 * gtk_widget_get_requisition:
13531 * @widget: a #GtkWidget
13532 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13534 * Retrieves the widget's requisition.
13536 * This function should only be used by widget implementations in
13537 * order to figure whether the widget's requisition has actually
13538 * changed after some internal state change (so that they can call
13539 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13541 * Normally, gtk_widget_size_request() should be used.
13545 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13546 * removed, If you need to cache sizes across requests and allocations,
13547 * add an explicit cache to the widget in question instead.
13550 gtk_widget_get_requisition (GtkWidget *widget,
13551 GtkRequisition *requisition)
13553 g_return_if_fail (GTK_IS_WIDGET (widget));
13554 g_return_if_fail (requisition != NULL);
13556 gtk_widget_get_preferred_size (widget, requisition, NULL);
13560 * gtk_widget_set_window:
13561 * @widget: a #GtkWidget
13562 * @window: (transfer full): a #GdkWindow
13564 * Sets a widget's window. This function should only be used in a
13565 * widget's #GtkWidget::realize implementation. The %window passed is
13566 * usually either new window created with gdk_window_new(), or the
13567 * window of its parent widget as returned by
13568 * gtk_widget_get_parent_window().
13570 * Widgets must indicate whether they will create their own #GdkWindow
13571 * by calling gtk_widget_set_has_window(). This is usually done in the
13572 * widget's init() function.
13574 * <note><para>This function does not add any reference to @window.</para></note>
13579 gtk_widget_set_window (GtkWidget *widget,
13582 GtkWidgetPrivate *priv;
13584 g_return_if_fail (GTK_IS_WIDGET (widget));
13585 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13587 priv = widget->priv;
13589 if (priv->window != window)
13591 priv->window = window;
13592 g_object_notify (G_OBJECT (widget), "window");
13597 * gtk_widget_get_window:
13598 * @widget: a #GtkWidget
13600 * Returns the widget's window if it is realized, %NULL otherwise
13602 * Return value: (transfer none): @widget's window.
13607 gtk_widget_get_window (GtkWidget *widget)
13609 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13611 return widget->priv->window;
13615 * gtk_widget_get_support_multidevice:
13616 * @widget: a #GtkWidget
13618 * Returns %TRUE if @widget is multiple pointer aware. See
13619 * gtk_widget_set_support_multidevice() for more information.
13621 * Returns: %TRUE if @widget is multidevice aware.
13624 gtk_widget_get_support_multidevice (GtkWidget *widget)
13626 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13628 return widget->priv->multidevice;
13632 * gtk_widget_set_support_multidevice:
13633 * @widget: a #GtkWidget
13634 * @support_multidevice: %TRUE to support input from multiple devices.
13636 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13637 * @widget will start receiving multiple, per device enter/leave events. Note
13638 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13639 * gdk_window_set_support_multidevice() will have to be called manually on them.
13644 gtk_widget_set_support_multidevice (GtkWidget *widget,
13645 gboolean support_multidevice)
13647 GtkWidgetPrivate *priv;
13649 g_return_if_fail (GTK_IS_WIDGET (widget));
13651 priv = widget->priv;
13652 priv->multidevice = (support_multidevice == TRUE);
13654 if (gtk_widget_get_realized (widget))
13655 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13659 _gtk_widget_set_has_focus (GtkWidget *widget,
13660 gboolean has_focus)
13662 widget->priv->has_focus = has_focus;
13665 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13667 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13671 * gtk_widget_send_focus_change:
13672 * @widget: a #GtkWidget
13673 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13675 * Sends the focus change @event to @widget
13677 * This function is not meant to be used by applications. The only time it
13678 * should be used is when it is necessary for a #GtkWidget to assign focus
13679 * to a widget that is semantically owned by the first widget even though
13680 * it's not a direct child - for instance, a search entry in a floating
13681 * window similar to the quick search in #GtkTreeView.
13683 * An example of its usage is:
13686 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13688 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13689 * fevent->focus_change.in = TRUE;
13690 * fevent->focus_change.window = gtk_widget_get_window (widget);
13691 * if (fevent->focus_change.window != NULL)
13692 * g_object_ref (fevent->focus_change.window);
13694 * gtk_widget_send_focus_change (widget, fevent);
13696 * gdk_event_free (event);
13699 * Return value: the return value from the event signal emission: %TRUE
13700 * if the event was handled, and %FALSE otherwise
13705 gtk_widget_send_focus_change (GtkWidget *widget,
13710 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13711 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13713 g_object_ref (widget);
13715 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13717 res = gtk_widget_event (widget, event);
13719 g_object_notify (G_OBJECT (widget), "has-focus");
13721 g_object_unref (widget);
13727 * gtk_widget_in_destruction:
13728 * @widget: a #GtkWidget
13730 * Returns whether the widget is currently being destroyed.
13731 * This information can sometimes be used to avoid doing
13732 * unnecessary work.
13734 * Returns: %TRUE if @widget is being destroyed
13737 gtk_widget_in_destruction (GtkWidget *widget)
13739 return widget->priv->in_destruction;
13743 _gtk_widget_get_in_reparent (GtkWidget *widget)
13745 return widget->priv->in_reparent;
13749 _gtk_widget_set_in_reparent (GtkWidget *widget,
13750 gboolean in_reparent)
13752 widget->priv->in_reparent = in_reparent;
13756 _gtk_widget_get_anchored (GtkWidget *widget)
13758 return widget->priv->anchored;
13762 _gtk_widget_set_anchored (GtkWidget *widget,
13765 widget->priv->anchored = anchored;
13769 _gtk_widget_get_shadowed (GtkWidget *widget)
13771 return widget->priv->shadowed;
13775 _gtk_widget_set_shadowed (GtkWidget *widget,
13778 widget->priv->shadowed = shadowed;
13782 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13784 return widget->priv->alloc_needed;
13788 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13789 gboolean alloc_needed)
13791 widget->priv->alloc_needed = alloc_needed;
13795 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13797 return widget->priv->width_request_needed;
13801 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13802 gboolean width_request_needed)
13804 widget->priv->width_request_needed = width_request_needed;
13808 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13810 return widget->priv->height_request_needed;
13814 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13815 gboolean height_request_needed)
13817 widget->priv->height_request_needed = height_request_needed;
13821 _gtk_widget_add_sizegroup (GtkWidget *widget,
13826 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13827 groups = g_slist_prepend (groups, group);
13828 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13830 widget->priv->have_size_groups = TRUE;
13834 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13839 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13840 groups = g_slist_remove (groups, group);
13841 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13843 widget->priv->have_size_groups = groups != NULL;
13847 _gtk_widget_get_sizegroups (GtkWidget *widget)
13849 if (widget->priv->have_size_groups)
13850 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13856 _gtk_widget_add_attached_window (GtkWidget *widget,
13859 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13863 _gtk_widget_remove_attached_window (GtkWidget *widget,
13866 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13870 * gtk_widget_path_append_for_widget:
13871 * @path: a widget path
13872 * @widget: the widget to append to the widget path
13874 * Appends the data from @widget to the widget hierarchy represented
13875 * by @path. This function is a shortcut for adding information from
13876 * @widget to the given @path. This includes setting the name or
13877 * adding the style classes from @widget.
13879 * Returns: the position where the data was inserted
13884 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13889 g_return_val_if_fail (path != NULL, 0);
13890 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13892 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13894 if (widget->priv->name)
13895 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13897 if (widget->priv->context)
13899 GList *classes, *l;
13901 /* Also add any persistent classes in
13902 * the style context the widget path
13904 classes = gtk_style_context_list_classes (widget->priv->context);
13906 for (l = classes; l; l = l->next)
13907 gtk_widget_path_iter_add_class (path, pos, l->data);
13909 g_list_free (classes);
13916 _gtk_widget_create_path (GtkWidget *widget)
13920 parent = widget->priv->parent;
13923 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13926 /* Widget is either toplevel or unparented, treat both
13927 * as toplevels style wise, since there are situations
13928 * where style properties might be retrieved on that
13931 GtkWidget *attach_widget = NULL;
13932 GtkWidgetPath *result;
13934 if (GTK_IS_WINDOW (widget))
13935 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13937 if (attach_widget != NULL)
13938 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13940 result = gtk_widget_path_new ();
13942 gtk_widget_path_append_for_widget (result, widget);
13949 * gtk_widget_get_path:
13950 * @widget: a #GtkWidget
13952 * Returns the #GtkWidgetPath representing @widget, if the widget
13953 * is not connected to a toplevel widget, a partial path will be
13956 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13959 gtk_widget_get_path (GtkWidget *widget)
13961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13963 if (!widget->priv->path)
13964 widget->priv->path = _gtk_widget_create_path (widget);
13966 return widget->priv->path;
13970 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13972 if (widget->priv->path)
13974 gtk_widget_path_free (widget->priv->path);
13975 widget->priv->path = NULL;
13978 if (gtk_widget_get_realized (widget))
13979 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13982 /* Compress all style updates so it
13983 * is only emitted once pre-realize.
13985 widget->priv->style_update_pending = TRUE;
13988 if (widget->priv->anchored)
13989 gtk_widget_queue_resize (widget);
13993 * gtk_widget_get_style_context:
13994 * @widget: a #GtkWidget
13996 * Returns the style context associated to @widget.
13998 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13999 * must not be freed.
14002 gtk_widget_get_style_context (GtkWidget *widget)
14004 GtkWidgetPrivate *priv;
14006 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14008 priv = widget->priv;
14010 if (G_UNLIKELY (priv->context == NULL))
14014 priv->context = gtk_style_context_new ();
14016 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14018 screen = gtk_widget_get_screen (widget);
14020 gtk_style_context_set_screen (priv->context, screen);
14023 gtk_style_context_set_parent (priv->context,
14024 gtk_widget_get_style_context (priv->parent));
14026 _gtk_style_context_set_widget (priv->context, widget);
14029 return widget->priv->context;
14033 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14034 GtkCssChange change)
14036 GtkWidgetPrivate *priv;
14038 priv = widget->priv;
14040 if (priv->context == NULL)
14043 _gtk_style_context_queue_invalidate (priv->context, change);
14047 * gtk_widget_get_modifier_mask:
14048 * @widget: a #GtkWidget
14049 * @intent: the use case for the modifier mask
14051 * Returns the modifier mask the @widget's windowing system backend
14052 * uses for a particular purpose.
14054 * See gdk_keymap_get_modifier_mask().
14056 * Returns: the modifier mask used for @intent.
14061 gtk_widget_get_modifier_mask (GtkWidget *widget,
14062 GdkModifierIntent intent)
14064 GdkDisplay *display;
14066 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14068 display = gtk_widget_get_display (widget);
14070 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14075 _gtk_widget_get_style (GtkWidget *widget)
14077 return widget->priv->style;
14081 _gtk_widget_set_style (GtkWidget *widget,
14084 widget->priv->style = style;
14088 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14091 GActionMuxer *parent_muxer;
14093 if (widget->priv->muxer == NULL)
14096 if (GTK_IS_MENU (widget))
14097 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14099 parent = gtk_widget_get_parent (widget);
14101 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14103 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14107 _gtk_widget_get_action_muxer (GtkWidget *widget)
14109 if (widget->priv->muxer == NULL)
14111 widget->priv->muxer = g_action_muxer_new ();
14112 _gtk_widget_update_parent_muxer (widget);
14115 return widget->priv->muxer;
14119 * gtk_widget_insert_action_group:
14120 * @widget: a #GtkWidget
14121 * @name: the prefix for actions in @group
14122 * @group: a #GActionGroup
14124 * Inserts @group into @widget. Children of @widget that implement
14125 * #GtkActionable can then be associated with actions in @group by
14126 * setting their 'action-name' to
14127 * @prefix.<replaceable>action-name</replaceable>.
14132 gtk_widget_insert_action_group (GtkWidget *widget,
14134 GActionGroup *group)
14136 GActionMuxer *muxer;
14138 g_return_if_fail (GTK_IS_WIDGET (widget));
14139 g_return_if_fail (name != NULL);
14141 muxer = _gtk_widget_get_action_muxer (widget);
14144 g_action_muxer_insert (muxer, name, group);
14146 g_action_muxer_remove (muxer, name);