1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include <gobject/gvaluecollector.h>
32 #include <gobject/gobjectnotifyqueue.c>
33 #include <cairo-gobject.h>
35 #include "gtkcontainer.h"
36 #include "gtkaccelmapprivate.h"
37 #include "gtkclipboard.h"
38 #include "gtkiconfactory.h"
40 #include "gtkmarshalers.h"
41 #include "gtkselectionprivate.h"
42 #include "gtksettingsprivate.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindowprivate.h"
47 #include "gtkcontainerprivate.h"
48 #include "gtkbindings.h"
49 #include "gtkprivate.h"
50 #include "gtkaccessible.h"
51 #include "gtktooltip.h"
52 #include "gtkinvisible.h"
53 #include "gtkbuildable.h"
54 #include "gtkbuilderprivate.h"
55 #include "gtksizerequest.h"
56 #include "gtkstylecontextprivate.h"
57 #include "gtksymboliccolor.h"
58 #include "gtkcssprovider.h"
59 #include "gtkanimationdescription.h"
60 #include "gtkmodifierstyle.h"
61 #include "gtkversion.h"
64 #include "gtktypebuiltins.h"
65 #include "a11y/gtkwidgetaccessible.h"
69 * @Short_description: Base class for all widgets
72 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
73 * widget lifecycle, states and style.
75 * <refsect2 id="geometry-management">
76 * <title>Height-for-width Geometry Management</title>
78 * GTK+ uses a height-for-width (and width-for-height) geometry management
79 * system. Height-for-width means that a widget can change how much
80 * vertical space it needs, depending on the amount of horizontal space
81 * that it is given (and similar for width-for-height). The most common
82 * example is a label that reflows to fill up the available width, wraps
83 * to fewer lines, and therefore needs less height.
85 * Height-for-width geometry management is implemented in GTK+ by way
86 * of five virtual methods:
88 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
95 * There are some important things to keep in mind when implementing
96 * height-for-width and when using it in container implementations.
98 * The geometry management system will query a widget hierarchy in
99 * only one orientation at a time. When widgets are initially queried
100 * for their minimum sizes it is generally done in two initial passes
101 * in the #GtkSizeRequestMode chosen by the toplevel.
103 * For example, when queried in the normal
104 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
105 * First, the default minimum and natural width for each widget
106 * in the interface will be computed using gtk_widget_get_preferred_width().
107 * Because the preferred widths for each container depend on the preferred
108 * widths of their children, this information propagates up the hierarchy,
109 * and finally a minimum and natural width is determined for the entire
110 * toplevel. Next, the toplevel will use the minimum width to query for the
111 * minimum height contextual to that width using
112 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
113 * recursive operation. The minimum height for the minimum width is normally
114 * used to set the minimum size constraint on the toplevel
115 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
117 * After the toplevel window has initially requested its size in both
118 * dimensions it can go on to allocate itself a reasonable size (or a size
119 * previously specified with gtk_window_set_default_size()). During the
120 * recursive allocation process it's important to note that request cycles
121 * will be recursively executed while container widgets allocate their children.
122 * Each container widget, once allocated a size, will go on to first share the
123 * space in one orientation among its children and then request each child's
124 * height for its target allocated width or its width for allocated height,
125 * depending. In this way a #GtkWidget will typically be requested its size
126 * a number of times before actually being allocated a size. The size a
127 * widget is finally allocated can of course differ from the size it has
128 * requested. For this reason, #GtkWidget caches a small number of results
129 * to avoid re-querying for the same sizes in one allocation cycle.
131 * See <link linkend="container-geometry-management">GtkContainer's
132 * geometry management section</link>
133 * to learn more about how height-for-width allocations are performed
134 * by container widgets.
136 * If a widget does move content around to intelligently use up the
137 * allocated size then it must support the request in both
138 * #GtkSizeRequestModes even if the widget in question only
139 * trades sizes in a single orientation.
141 * For instance, a #GtkLabel that does height-for-width word wrapping
142 * will not expect to have #GtkWidgetClass.get_preferred_height() called
143 * because that call is specific to a width-for-height request. In this
144 * case the label must return the height required for its own minimum
145 * possible width. By following this rule any widget that handles
146 * height-for-width or width-for-height requests will always be allocated
147 * at least enough space to fit its own content.
149 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
150 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
152 * <programlisting><![CDATA[
154 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
156 * if (i_am_in_height_for_width_mode)
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
162 * min_height, nat_height);
166 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
167 * it will return the minimum and natural height for the rotated label here.
170 * ]]></programlisting>
172 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
173 * the minimum and natural width:
175 * <programlisting><![CDATA[
177 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
178 * gint *min_width, gint *nat_width)
180 * if (i_am_in_height_for_width_mode)
182 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
186 * ... again if a widget is sometimes operating in width-for-height mode
187 * (like a rotated GtkLabel) it can go ahead and do its real width for
188 * height calculation here.
191 * ]]></programlisting>
193 * Often a widget needs to get its own request during size request or
194 * allocation. For example, when computing height it may need to also
195 * compute width. Or when deciding how to use an allocation, the widget
196 * may need to know its natural size. In these cases, the widget should
197 * be careful to call its virtual methods directly, like this:
199 * <title>Widget calling its own size request method.</title>
201 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
206 * It will not work to use the wrapper functions, such as
207 * gtk_widget_get_preferred_width() inside your own size request
208 * implementation. These return a request adjusted by #GtkSizeGroup
209 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
210 * widget used the wrappers inside its virtual method implementations,
211 * then the adjustments (such as widget margins) would be applied
212 * twice. GTK+ therefore does not allow this and will warn if you try
215 * Of course if you are getting the size request for
216 * <emphasis>another</emphasis> widget, such as a child of a
217 * container, you <emphasis>must</emphasis> use the wrapper APIs.
218 * Otherwise, you would not properly consider widget margins,
219 * #GtkSizeGroup, and so forth.
222 * <refsect2 id="style-properties">
223 * <title>Style Properties</title>
225 * <structname>GtkWidget</structname> introduces <firstterm>style
226 * properties</firstterm> - these are basically object properties that are stored
227 * not on the object, but in the style object associated to the widget. Style
228 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
229 * This mechanism is used for configuring such things as the location of the
230 * scrollbar arrows through the theme, giving theme authors more control over the
231 * look of applications without the need to write a theme engine in C.
234 * Use gtk_widget_class_install_style_property() to install style properties for
235 * a widget class, gtk_widget_class_find_style_property() or
236 * gtk_widget_class_list_style_properties() to get information about existing
237 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
238 * gtk_widget_style_get_valist() to obtain the value of a style property.
241 * <refsect2 id="GtkWidget-BUILDER-UI">
242 * <title>GtkWidget as GtkBuildable</title>
244 * The GtkWidget implementation of the GtkBuildable interface supports a
245 * custom <accelerator> element, which has attributes named key,
246 * modifiers and signal and allows to specify accelerators.
249 * <title>A UI definition fragment specifying an accelerator</title>
250 * <programlisting><![CDATA[
251 * <object class="GtkButton">
252 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
254 * ]]></programlisting>
257 * In addition to accelerators, <structname>GtkWidget</structname> also support a
258 * custom <accessible> element, which supports actions and relations.
259 * Properties on the accessible implementation of an object can be set by accessing the
260 * internal child "accessible" of a <structname>GtkWidget</structname>.
263 * <title>A UI definition fragment specifying an accessible</title>
264 * <programlisting><![CDATA[
265 * <object class="GtkButton" id="label1"/>
266 * <property name="label">I am a Label for a Button</property>
268 * <object class="GtkButton" id="button1">
270 * <action action_name="click" translatable="yes">Click the button.</action>
271 * <relation target="label1" type="labelled-by"/>
273 * <child internal-child="accessible">
274 * <object class="AtkObject" id="a11y-button1">
275 * <property name="AtkObject::name">Clickable Button</property>
279 * ]]></programlisting>
282 * Finally, GtkWidget allows style information such as style classes to
283 * be associated with widgets, using the custom <style> element:
285 * <title>A UI definition fragment specifying an style class</title>
286 * <programlisting><![CDATA[
287 * <object class="GtkButton" id="button1">
289 * <class name="my-special-button-class"/>
290 * <class name="dark-button"/>
293 * ]]></programlisting>
299 /* Add flags here that should not be propagated to children. By default,
300 * all flags will be set on children (think prelight or active), but we
301 * might want to not do this for some.
303 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
304 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
306 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
308 #define GTK_STATE_FLAGS_BITS 7
310 struct _GtkWidgetPrivate
312 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
313 * (defined in "gtkenums.h").
315 guint state_flags : GTK_STATE_FLAGS_BITS;
319 guint in_destruction : 1;
322 guint composite_child : 1;
330 guint can_default : 1;
331 guint has_default : 1;
332 guint receives_default : 1;
335 guint style_update_pending : 1;
336 guint app_paintable : 1;
337 guint double_buffered : 1;
338 guint redraw_on_alloc : 1;
339 guint no_show_all : 1;
340 guint child_visible : 1;
341 guint multidevice : 1;
342 guint has_shape_mask : 1;
343 guint in_reparent : 1;
345 /* Queue-resize related flags */
346 guint resize_pending : 1;
347 guint alloc_needed : 1;
348 guint width_request_needed : 1;
349 guint height_request_needed : 1;
351 /* Expand-related flags */
352 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
353 guint computed_hexpand : 1; /* computed results (composite of child flags) */
354 guint computed_vexpand : 1;
355 guint hexpand : 1; /* application-forced expand */
357 guint hexpand_set : 1; /* whether to use application-forced */
358 guint vexpand_set : 1; /* instead of computing from children */
360 /* SizeGroup related flags */
361 guint sizegroup_visited : 1;
362 guint sizegroup_bumping : 1;
363 guint have_size_groups : 1;
365 /* The widget's name. If the widget does not have a name
366 * (the name is NULL), then its name (as returned by
367 * "gtk_widget_get_name") is its class's name.
368 * Among other things, the widget name is used to determine
369 * the style to use for a widget.
373 /* The list of attached windows to this widget.
374 * We keep a list in order to call reset_style to all of them,
376 GList *attached_windows;
378 /* The style for the widget. The style contains the
379 * colors the widget should be drawn in for each state
380 * along with graphics contexts used to draw with and
381 * the font to use for text.
384 GtkStyleContext *context;
386 /* Widget's path for styling */
389 /* The widget's allocated size */
390 GtkAllocation allocation;
392 /* The widget's requested sizes */
393 SizeRequestCache requests;
395 /* The widget's window or its parent window if it does
396 * not have a window. (Which will be indicated by the
397 * GTK_NO_WINDOW flag being set).
401 /* The widget's parent */
404 #ifdef G_ENABLE_DEBUG
405 /* Number of gtk_widget_push_verify_invariants () */
406 guint verifying_invariants_count;
407 #endif /* G_ENABLE_DEBUG */
410 struct _GtkWidgetClassPrivate
412 GType accessible_type;
413 AtkRole accessible_role;
442 BUTTON_RELEASE_EVENT,
456 PROPERTY_NOTIFY_EVENT,
457 SELECTION_CLEAR_EVENT,
458 SELECTION_REQUEST_EVENT,
459 SELECTION_NOTIFY_EVENT,
464 VISIBILITY_NOTIFY_EVENT,
478 ACCEL_CLOSURES_CHANGED,
503 PROP_RECEIVES_DEFAULT,
504 PROP_COMPOSITE_CHILD,
512 PROP_DOUBLE_BUFFERED,
527 typedef struct _GtkStateData GtkStateData;
530 STATE_CHANGE_REPLACE,
537 guint flags : GTK_STATE_FLAGS_BITS;
541 /* --- prototypes --- */
542 static void gtk_widget_base_class_init (gpointer g_class);
543 static void gtk_widget_class_init (GtkWidgetClass *klass);
544 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
545 static void gtk_widget_init (GtkWidget *widget);
546 static void gtk_widget_set_property (GObject *object,
550 static void gtk_widget_get_property (GObject *object,
554 static void gtk_widget_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 void gtk_widget_queue_shallow_draw (GtkWidget *widget);
645 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
648 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
649 gboolean has_tooltip,
651 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
652 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
654 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
655 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
657 const gchar *childname);
658 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
661 const GValue *value);
662 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
665 const gchar *tagname,
666 GMarkupParser *parser,
668 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
671 const gchar *tagname,
673 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
674 GtkBuilder *builder);
676 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
677 static void gtk_widget_real_get_width (GtkWidget *widget,
680 static void gtk_widget_real_get_height (GtkWidget *widget,
684 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
687 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
688 GtkOrientation orientation,
691 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
692 GtkOrientation orientation,
696 gint *allocated_size);
698 static void gtk_widget_set_usize_internal (GtkWidget *widget,
701 GtkQueueResizeFlags flags);
703 static void gtk_widget_add_events_internal (GtkWidget *widget,
706 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
710 static gboolean event_window_is_still_viewable (GdkEvent *event);
712 /* --- variables --- */
713 static gpointer gtk_widget_parent_class = NULL;
714 static guint widget_signals[LAST_SIGNAL] = { 0 };
715 static guint composite_child_stack = 0;
716 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
717 static GParamSpecPool *style_property_spec_pool = NULL;
719 static GQuark quark_property_parser = 0;
720 static GQuark quark_aux_info = 0;
721 static GQuark quark_accel_path = 0;
722 static GQuark quark_accel_closures = 0;
723 static GQuark quark_event_mask = 0;
724 static GQuark quark_device_event_mask = 0;
725 static GQuark quark_parent_window = 0;
726 static GQuark quark_pointer_window = 0;
727 static GQuark quark_shape_info = 0;
728 static GQuark quark_input_shape_info = 0;
729 static GQuark quark_pango_context = 0;
730 static GQuark quark_accessible_object = 0;
731 static GQuark quark_mnemonic_labels = 0;
732 static GQuark quark_tooltip_markup = 0;
733 static GQuark quark_has_tooltip = 0;
734 static GQuark quark_tooltip_window = 0;
735 static GQuark quark_visual = 0;
736 static GQuark quark_modifier_style = 0;
737 static GQuark quark_enabled_devices = 0;
738 static GQuark quark_size_groups = 0;
739 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
740 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
742 /* --- functions --- */
744 gtk_widget_get_type (void)
746 static GType widget_type = 0;
748 if (G_UNLIKELY (widget_type == 0))
750 const GTypeInfo widget_info =
752 sizeof (GtkWidgetClass),
753 gtk_widget_base_class_init,
754 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
755 (GClassInitFunc) gtk_widget_class_init,
756 NULL, /* class_finalize */
757 NULL, /* class_init */
760 (GInstanceInitFunc) gtk_widget_init,
761 NULL, /* value_table */
764 const GInterfaceInfo accessibility_info =
766 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
767 (GInterfaceFinalizeFunc) NULL,
768 NULL /* interface data */
771 const GInterfaceInfo buildable_info =
773 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
774 (GInterfaceFinalizeFunc) NULL,
775 NULL /* interface data */
778 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
779 &widget_info, G_TYPE_FLAG_ABSTRACT);
781 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
783 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
784 &accessibility_info) ;
785 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
793 gtk_widget_base_class_init (gpointer g_class)
795 GtkWidgetClass *klass = g_class;
797 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
801 child_property_notify_dispatcher (GObject *object,
805 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
808 /* We guard against the draw signal callbacks modifying the state of the
809 * cairo context by surounding it with save/restore.
810 * Maybe we should also cairo_new_path() just to be sure?
813 gtk_widget_draw_marshaller (GClosure *closure,
814 GValue *return_value,
815 guint n_param_values,
816 const GValue *param_values,
817 gpointer invocation_hint,
818 gpointer marshal_data)
820 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
824 _gtk_marshal_BOOLEAN__BOXED (closure,
835 gtk_widget_draw_marshallerv (GClosure *closure,
836 GValue *return_value,
839 gpointer marshal_data,
846 G_VA_COPY (args_copy, args);
847 cr = va_arg (args_copy, gpointer);
851 _gtk_marshal_BOOLEAN__BOXEDv (closure,
863 gtk_widget_class_init (GtkWidgetClass *klass)
865 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
866 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
867 GtkBindingSet *binding_set;
869 gtk_widget_parent_class = g_type_class_peek_parent (klass);
871 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
872 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
873 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
874 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
875 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
876 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
877 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
878 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
879 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
880 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
881 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
882 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
883 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
884 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
885 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
886 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
887 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
888 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
889 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
890 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
892 style_property_spec_pool = g_param_spec_pool_new (FALSE);
893 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
894 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
895 cpn_context.dispatcher = child_property_notify_dispatcher;
896 _gtk_widget_child_property_notify_context = &cpn_context;
898 gobject_class->constructed = gtk_widget_constructed;
899 gobject_class->dispose = gtk_widget_dispose;
900 gobject_class->finalize = gtk_widget_finalize;
901 gobject_class->set_property = gtk_widget_set_property;
902 gobject_class->get_property = gtk_widget_get_property;
904 klass->destroy = gtk_widget_real_destroy;
906 klass->activate_signal = 0;
907 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
908 klass->show = gtk_widget_real_show;
909 klass->show_all = gtk_widget_show;
910 klass->hide = gtk_widget_real_hide;
911 klass->map = gtk_widget_real_map;
912 klass->unmap = gtk_widget_real_unmap;
913 klass->realize = gtk_widget_real_realize;
914 klass->unrealize = gtk_widget_real_unrealize;
915 klass->size_allocate = gtk_widget_real_size_allocate;
916 klass->get_request_mode = gtk_widget_real_get_request_mode;
917 klass->get_preferred_width = gtk_widget_real_get_width;
918 klass->get_preferred_height = gtk_widget_real_get_height;
919 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
920 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
921 klass->state_changed = NULL;
922 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
923 klass->parent_set = NULL;
924 klass->hierarchy_changed = NULL;
925 klass->style_set = gtk_widget_real_style_set;
926 klass->direction_changed = gtk_widget_real_direction_changed;
927 klass->grab_notify = NULL;
928 klass->child_notify = NULL;
930 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
931 klass->grab_focus = gtk_widget_real_grab_focus;
932 klass->focus = gtk_widget_real_focus;
933 klass->move_focus = gtk_widget_real_move_focus;
934 klass->keynav_failed = gtk_widget_real_keynav_failed;
936 klass->button_press_event = NULL;
937 klass->button_release_event = NULL;
938 klass->motion_notify_event = NULL;
939 klass->touch_event = gtk_widget_real_touch_event;
940 klass->delete_event = NULL;
941 klass->destroy_event = NULL;
942 klass->key_press_event = gtk_widget_real_key_press_event;
943 klass->key_release_event = gtk_widget_real_key_release_event;
944 klass->enter_notify_event = NULL;
945 klass->leave_notify_event = NULL;
946 klass->configure_event = NULL;
947 klass->focus_in_event = gtk_widget_real_focus_in_event;
948 klass->focus_out_event = gtk_widget_real_focus_out_event;
949 klass->map_event = NULL;
950 klass->unmap_event = NULL;
951 klass->window_state_event = NULL;
952 klass->property_notify_event = _gtk_selection_property_notify;
953 klass->selection_clear_event = _gtk_selection_clear;
954 klass->selection_request_event = _gtk_selection_request;
955 klass->selection_notify_event = _gtk_selection_notify;
956 klass->selection_received = NULL;
957 klass->proximity_in_event = NULL;
958 klass->proximity_out_event = NULL;
959 klass->drag_begin = NULL;
960 klass->drag_end = NULL;
961 klass->drag_data_delete = NULL;
962 klass->drag_leave = NULL;
963 klass->drag_motion = NULL;
964 klass->drag_drop = NULL;
965 klass->drag_data_received = NULL;
966 klass->screen_changed = NULL;
967 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
968 klass->grab_broken_event = NULL;
969 klass->query_tooltip = gtk_widget_real_query_tooltip;
970 klass->style_updated = gtk_widget_real_style_updated;
972 klass->show_help = gtk_widget_real_show_help;
974 /* Accessibility support */
975 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
976 klass->priv->accessible_role = ATK_ROLE_INVALID;
977 klass->get_accessible = gtk_widget_real_get_accessible;
979 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
980 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
982 g_object_class_install_property (gobject_class,
984 g_param_spec_string ("name",
986 P_("The name of the widget"),
988 GTK_PARAM_READWRITE));
989 g_object_class_install_property (gobject_class,
991 g_param_spec_object ("parent",
993 P_("The parent widget of this widget. Must be a Container widget"),
995 GTK_PARAM_READWRITE));
997 g_object_class_install_property (gobject_class,
999 g_param_spec_int ("width-request",
1000 P_("Width request"),
1001 P_("Override for width request of the widget, or -1 if natural request should be used"),
1005 GTK_PARAM_READWRITE));
1006 g_object_class_install_property (gobject_class,
1007 PROP_HEIGHT_REQUEST,
1008 g_param_spec_int ("height-request",
1009 P_("Height request"),
1010 P_("Override for height request of the widget, or -1 if natural request should be used"),
1014 GTK_PARAM_READWRITE));
1015 g_object_class_install_property (gobject_class,
1017 g_param_spec_boolean ("visible",
1019 P_("Whether the widget is visible"),
1021 GTK_PARAM_READWRITE));
1022 g_object_class_install_property (gobject_class,
1024 g_param_spec_boolean ("sensitive",
1026 P_("Whether the widget responds to input"),
1028 GTK_PARAM_READWRITE));
1029 g_object_class_install_property (gobject_class,
1031 g_param_spec_boolean ("app-paintable",
1032 P_("Application paintable"),
1033 P_("Whether the application will paint directly on the widget"),
1035 GTK_PARAM_READWRITE));
1036 g_object_class_install_property (gobject_class,
1038 g_param_spec_boolean ("can-focus",
1040 P_("Whether the widget can accept the input focus"),
1042 GTK_PARAM_READWRITE));
1043 g_object_class_install_property (gobject_class,
1045 g_param_spec_boolean ("has-focus",
1047 P_("Whether the widget has the input focus"),
1049 GTK_PARAM_READWRITE));
1050 g_object_class_install_property (gobject_class,
1052 g_param_spec_boolean ("is-focus",
1054 P_("Whether the widget is the focus widget within the toplevel"),
1056 GTK_PARAM_READWRITE));
1057 g_object_class_install_property (gobject_class,
1059 g_param_spec_boolean ("can-default",
1061 P_("Whether the widget can be the default widget"),
1063 GTK_PARAM_READWRITE));
1064 g_object_class_install_property (gobject_class,
1066 g_param_spec_boolean ("has-default",
1068 P_("Whether the widget is the default widget"),
1070 GTK_PARAM_READWRITE));
1071 g_object_class_install_property (gobject_class,
1072 PROP_RECEIVES_DEFAULT,
1073 g_param_spec_boolean ("receives-default",
1074 P_("Receives default"),
1075 P_("If TRUE, the widget will receive the default action when it is focused"),
1077 GTK_PARAM_READWRITE));
1078 g_object_class_install_property (gobject_class,
1079 PROP_COMPOSITE_CHILD,
1080 g_param_spec_boolean ("composite-child",
1081 P_("Composite child"),
1082 P_("Whether the widget is part of a composite widget"),
1084 GTK_PARAM_READABLE));
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_object ("style",
1089 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1091 GTK_PARAM_READWRITE));
1092 g_object_class_install_property (gobject_class,
1094 g_param_spec_flags ("events",
1096 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1097 GDK_TYPE_EVENT_MASK,
1099 GTK_PARAM_READWRITE));
1100 g_object_class_install_property (gobject_class,
1102 g_param_spec_boolean ("no-show-all",
1104 P_("Whether gtk_widget_show_all() should not affect this widget"),
1106 GTK_PARAM_READWRITE));
1109 * GtkWidget:has-tooltip:
1111 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1112 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1113 * the widget will be queried using #GtkWidget::query-tooltip to determine
1114 * whether it will provide a tooltip or not.
1116 * Note that setting this property to %TRUE for the first time will change
1117 * the event masks of the GdkWindows of this widget to include leave-notify
1118 * and motion-notify events. This cannot and will not be undone when the
1119 * property is set to %FALSE again.
1123 g_object_class_install_property (gobject_class,
1125 g_param_spec_boolean ("has-tooltip",
1127 P_("Whether this widget has a tooltip"),
1129 GTK_PARAM_READWRITE));
1131 * GtkWidget:tooltip-text:
1133 * Sets the text of tooltip to be the given string.
1135 * Also see gtk_tooltip_set_text().
1137 * This is a convenience property which will take care of getting the
1138 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1139 * will automatically be set to %TRUE and there will be taken care of
1140 * #GtkWidget::query-tooltip in the default signal handler.
1144 g_object_class_install_property (gobject_class,
1146 g_param_spec_string ("tooltip-text",
1148 P_("The contents of the tooltip for this widget"),
1150 GTK_PARAM_READWRITE));
1152 * GtkWidget:tooltip-markup:
1154 * Sets the text of tooltip to be the given string, which is marked up
1155 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1156 * Also see gtk_tooltip_set_markup().
1158 * This is a convenience property which will take care of getting the
1159 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1160 * will automatically be set to %TRUE and there will be taken care of
1161 * #GtkWidget::query-tooltip in the default signal handler.
1165 g_object_class_install_property (gobject_class,
1166 PROP_TOOLTIP_MARKUP,
1167 g_param_spec_string ("tooltip-markup",
1168 P_("Tooltip markup"),
1169 P_("The contents of the tooltip for this widget"),
1171 GTK_PARAM_READWRITE));
1176 * The widget's window if it is realized, %NULL otherwise.
1180 g_object_class_install_property (gobject_class,
1182 g_param_spec_object ("window",
1184 P_("The widget's window if it is realized"),
1186 GTK_PARAM_READABLE));
1189 * GtkWidget:double-buffered:
1191 * Whether the widget is double buffered.
1195 g_object_class_install_property (gobject_class,
1196 PROP_DOUBLE_BUFFERED,
1197 g_param_spec_boolean ("double-buffered",
1198 P_("Double Buffered"),
1199 P_("Whether the widget is double buffered"),
1201 GTK_PARAM_READWRITE));
1206 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1210 g_object_class_install_property (gobject_class,
1212 g_param_spec_enum ("halign",
1213 P_("Horizontal Alignment"),
1214 P_("How to position in extra horizontal space"),
1217 GTK_PARAM_READWRITE));
1222 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1226 g_object_class_install_property (gobject_class,
1228 g_param_spec_enum ("valign",
1229 P_("Vertical Alignment"),
1230 P_("How to position in extra vertical space"),
1233 GTK_PARAM_READWRITE));
1236 * GtkWidget:margin-left:
1238 * Margin on left side of widget.
1240 * This property adds margin outside of the widget's normal size
1241 * request, the margin will be added in addition to the size from
1242 * gtk_widget_set_size_request() for example.
1246 g_object_class_install_property (gobject_class,
1248 g_param_spec_int ("margin-left",
1249 P_("Margin on Left"),
1250 P_("Pixels of extra space on the left side"),
1254 GTK_PARAM_READWRITE));
1257 * GtkWidget:margin-right:
1259 * Margin on right side of widget.
1261 * This property adds margin outside of the widget's normal size
1262 * request, the margin will be added in addition to the size from
1263 * gtk_widget_set_size_request() for example.
1267 g_object_class_install_property (gobject_class,
1269 g_param_spec_int ("margin-right",
1270 P_("Margin on Right"),
1271 P_("Pixels of extra space on the right side"),
1275 GTK_PARAM_READWRITE));
1278 * GtkWidget:margin-top:
1280 * Margin on top side of widget.
1282 * This property adds margin outside of the widget's normal size
1283 * request, the margin will be added in addition to the size from
1284 * gtk_widget_set_size_request() for example.
1288 g_object_class_install_property (gobject_class,
1290 g_param_spec_int ("margin-top",
1291 P_("Margin on Top"),
1292 P_("Pixels of extra space on the top side"),
1296 GTK_PARAM_READWRITE));
1299 * GtkWidget:margin-bottom:
1301 * Margin on bottom side of widget.
1303 * This property adds margin outside of the widget's normal size
1304 * request, the margin will be added in addition to the size from
1305 * gtk_widget_set_size_request() for example.
1309 g_object_class_install_property (gobject_class,
1311 g_param_spec_int ("margin-bottom",
1312 P_("Margin on Bottom"),
1313 P_("Pixels of extra space on the bottom side"),
1317 GTK_PARAM_READWRITE));
1322 * Sets all four sides' margin at once. If read, returns max
1323 * margin on any side.
1327 g_object_class_install_property (gobject_class,
1329 g_param_spec_int ("margin",
1331 P_("Pixels of extra space on all four sides"),
1335 GTK_PARAM_READWRITE));
1338 * GtkWidget::destroy:
1339 * @object: the object which received the signal
1341 * Signals that all holders of a reference to the widget should release
1342 * the reference that they hold. May result in finalization of the widget
1343 * if all references are released.
1345 widget_signals[DESTROY] =
1346 g_signal_new (I_("destroy"),
1347 G_TYPE_FROM_CLASS (gobject_class),
1348 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1349 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1351 _gtk_marshal_VOID__VOID,
1355 * GtkWidget:hexpand:
1357 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1361 g_object_class_install_property (gobject_class,
1363 g_param_spec_boolean ("hexpand",
1364 P_("Horizontal Expand"),
1365 P_("Whether widget wants more horizontal space"),
1367 GTK_PARAM_READWRITE));
1370 * GtkWidget:hexpand-set:
1372 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1376 g_object_class_install_property (gobject_class,
1378 g_param_spec_boolean ("hexpand-set",
1379 P_("Horizontal Expand Set"),
1380 P_("Whether to use the hexpand property"),
1382 GTK_PARAM_READWRITE));
1385 * GtkWidget:vexpand:
1387 * Whether to expand vertically. See gtk_widget_set_vexpand().
1391 g_object_class_install_property (gobject_class,
1393 g_param_spec_boolean ("vexpand",
1394 P_("Vertical Expand"),
1395 P_("Whether widget wants more vertical space"),
1397 GTK_PARAM_READWRITE));
1400 * GtkWidget:vexpand-set:
1402 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1406 g_object_class_install_property (gobject_class,
1408 g_param_spec_boolean ("vexpand-set",
1409 P_("Vertical Expand Set"),
1410 P_("Whether to use the vexpand property"),
1412 GTK_PARAM_READWRITE));
1417 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1421 g_object_class_install_property (gobject_class,
1423 g_param_spec_boolean ("expand",
1425 P_("Whether widget wants to expand in both directions"),
1427 GTK_PARAM_READWRITE));
1431 * @widget: the object which received the signal.
1433 widget_signals[SHOW] =
1434 g_signal_new (I_("show"),
1435 G_TYPE_FROM_CLASS (gobject_class),
1437 G_STRUCT_OFFSET (GtkWidgetClass, show),
1439 _gtk_marshal_VOID__VOID,
1444 * @widget: the object which received the signal.
1446 widget_signals[HIDE] =
1447 g_signal_new (I_("hide"),
1448 G_TYPE_FROM_CLASS (gobject_class),
1450 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1452 _gtk_marshal_VOID__VOID,
1457 * @widget: the object which received the signal.
1459 widget_signals[MAP] =
1460 g_signal_new (I_("map"),
1461 G_TYPE_FROM_CLASS (gobject_class),
1463 G_STRUCT_OFFSET (GtkWidgetClass, map),
1465 _gtk_marshal_VOID__VOID,
1470 * @widget: the object which received the signal.
1472 widget_signals[UNMAP] =
1473 g_signal_new (I_("unmap"),
1474 G_TYPE_FROM_CLASS (gobject_class),
1476 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1478 _gtk_marshal_VOID__VOID,
1482 * GtkWidget::realize:
1483 * @widget: the object which received the signal.
1485 widget_signals[REALIZE] =
1486 g_signal_new (I_("realize"),
1487 G_TYPE_FROM_CLASS (gobject_class),
1489 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1491 _gtk_marshal_VOID__VOID,
1495 * GtkWidget::unrealize:
1496 * @widget: the object which received the signal.
1498 widget_signals[UNREALIZE] =
1499 g_signal_new (I_("unrealize"),
1500 G_TYPE_FROM_CLASS (gobject_class),
1502 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1504 _gtk_marshal_VOID__VOID,
1508 * GtkWidget::size-allocate:
1509 * @widget: the object which received the signal.
1512 widget_signals[SIZE_ALLOCATE] =
1513 g_signal_new (I_("size-allocate"),
1514 G_TYPE_FROM_CLASS (gobject_class),
1516 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1518 _gtk_marshal_VOID__BOXED,
1520 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1523 * GtkWidget::state-changed:
1524 * @widget: the object which received the signal.
1525 * @state: the previous state
1527 * The ::state-changed signal is emitted when the widget state changes.
1528 * See gtk_widget_get_state().
1530 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1532 widget_signals[STATE_CHANGED] =
1533 g_signal_new (I_("state-changed"),
1534 G_TYPE_FROM_CLASS (gobject_class),
1536 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1538 _gtk_marshal_VOID__ENUM,
1540 GTK_TYPE_STATE_TYPE);
1543 * GtkWidget::state-flags-changed:
1544 * @widget: the object which received the signal.
1545 * @flags: The previous state flags.
1547 * The ::state-flags-changed signal is emitted when the widget state
1548 * changes, see gtk_widget_get_state_flags().
1552 widget_signals[STATE_FLAGS_CHANGED] =
1553 g_signal_new (I_("state-flags-changed"),
1554 G_TYPE_FROM_CLASS (gobject_class),
1556 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1558 _gtk_marshal_VOID__FLAGS,
1560 GTK_TYPE_STATE_FLAGS);
1563 * GtkWidget::parent-set:
1564 * @widget: the object on which the signal is emitted
1565 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1566 * just got its initial parent.
1568 * The ::parent-set signal is emitted when a new parent
1569 * has been set on a widget.
1571 widget_signals[PARENT_SET] =
1572 g_signal_new (I_("parent-set"),
1573 G_TYPE_FROM_CLASS (gobject_class),
1575 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1577 _gtk_marshal_VOID__OBJECT,
1582 * GtkWidget::hierarchy-changed:
1583 * @widget: the object on which the signal is emitted
1584 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1585 * if the widget was previously unanchored
1587 * The ::hierarchy-changed signal is emitted when the
1588 * anchored state of a widget changes. A widget is
1589 * <firstterm>anchored</firstterm> when its toplevel
1590 * ancestor is a #GtkWindow. This signal is emitted when
1591 * a widget changes from un-anchored to anchored or vice-versa.
1593 widget_signals[HIERARCHY_CHANGED] =
1594 g_signal_new (I_("hierarchy-changed"),
1595 G_TYPE_FROM_CLASS (gobject_class),
1597 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1599 _gtk_marshal_VOID__OBJECT,
1604 * GtkWidget::style-set:
1605 * @widget: the object on which the signal is emitted
1606 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1607 * just got its initial style
1609 * The ::style-set signal is emitted when a new style has been set
1610 * on a widget. Note that style-modifying functions like
1611 * gtk_widget_modify_base() also cause this signal to be emitted.
1613 * Note that this signal is emitted for changes to the deprecated
1614 * #GtkStyle. To track changes to the #GtkStyleContext associated
1615 * with a widget, use the #GtkWidget::style-updated signal.
1617 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1619 widget_signals[STYLE_SET] =
1620 g_signal_new (I_("style-set"),
1621 G_TYPE_FROM_CLASS (gobject_class),
1623 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1625 _gtk_marshal_VOID__OBJECT,
1630 * GtkWidget::style-updated:
1631 * @widget: the object on which the signal is emitted
1633 * The ::style-updated signal is emitted when the #GtkStyleContext
1634 * of a widget is changed. Note that style-modifying functions like
1635 * gtk_widget_override_color() also cause this signal to be emitted.
1639 widget_signals[STYLE_UPDATED] =
1640 g_signal_new (I_("style-updated"),
1641 G_TYPE_FROM_CLASS (gobject_class),
1643 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1645 g_cclosure_marshal_VOID__VOID,
1649 * GtkWidget::direction-changed:
1650 * @widget: the object on which the signal is emitted
1651 * @previous_direction: the previous text direction of @widget
1653 * The ::direction-changed signal is emitted when the text direction
1654 * of a widget changes.
1656 widget_signals[DIRECTION_CHANGED] =
1657 g_signal_new (I_("direction-changed"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1662 _gtk_marshal_VOID__ENUM,
1664 GTK_TYPE_TEXT_DIRECTION);
1667 * GtkWidget::grab-notify:
1668 * @widget: the object which received the signal
1669 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1670 * if it becomes unshadowed
1672 * The ::grab-notify signal is emitted when a widget becomes
1673 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1674 * another widget, or when it becomes unshadowed due to a grab
1677 * A widget is shadowed by a gtk_grab_add() when the topmost
1678 * grab widget in the grab stack of its window group is not
1681 widget_signals[GRAB_NOTIFY] =
1682 g_signal_new (I_("grab-notify"),
1683 G_TYPE_FROM_CLASS (gobject_class),
1685 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1687 _gtk_marshal_VOID__BOOLEAN,
1692 * GtkWidget::child-notify:
1693 * @widget: the object which received the signal
1694 * @pspec: the #GParamSpec of the changed child property
1696 * The ::child-notify signal is emitted for each
1697 * <link linkend="child-properties">child property</link> that has
1698 * changed on an object. The signal's detail holds the property name.
1700 widget_signals[CHILD_NOTIFY] =
1701 g_signal_new (I_("child-notify"),
1702 G_TYPE_FROM_CLASS (gobject_class),
1703 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1704 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1706 g_cclosure_marshal_VOID__PARAM,
1712 * @widget: the object which received the signal
1713 * @cr: the cairo context to draw to
1715 * This signal is emitted when a widget is supposed to render itself.
1716 * The @widget's top left corner must be painted at the origin of
1717 * the passed in context and be sized to the values returned by
1718 * gtk_widget_get_allocated_width() and
1719 * gtk_widget_get_allocated_height().
1721 * Signal handlers connected to this signal can modify the cairo
1722 * context passed as @cr in any way they like and don't need to
1723 * restore it. The signal emission takes care of calling cairo_save()
1724 * before and cairo_restore() after invoking the handler.
1728 widget_signals[DRAW] =
1729 g_signal_new (I_("draw"),
1730 G_TYPE_FROM_CLASS (gobject_class),
1732 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1733 _gtk_boolean_handled_accumulator, NULL,
1734 gtk_widget_draw_marshaller,
1736 CAIRO_GOBJECT_TYPE_CONTEXT);
1737 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1738 gtk_widget_draw_marshallerv);
1741 * GtkWidget::mnemonic-activate:
1742 * @widget: the object which received the signal.
1745 widget_signals[MNEMONIC_ACTIVATE] =
1746 g_signal_new (I_("mnemonic-activate"),
1747 G_TYPE_FROM_CLASS (gobject_class),
1749 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1750 _gtk_boolean_handled_accumulator, NULL,
1751 _gtk_marshal_BOOLEAN__BOOLEAN,
1756 * GtkWidget::grab-focus:
1757 * @widget: the object which received the signal.
1759 widget_signals[GRAB_FOCUS] =
1760 g_signal_new (I_("grab-focus"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1763 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1765 _gtk_marshal_VOID__VOID,
1770 * @widget: the object which received the signal.
1773 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1775 widget_signals[FOCUS] =
1776 g_signal_new (I_("focus"),
1777 G_TYPE_FROM_CLASS (klass),
1779 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1780 _gtk_boolean_handled_accumulator, NULL,
1781 _gtk_marshal_BOOLEAN__ENUM,
1783 GTK_TYPE_DIRECTION_TYPE);
1786 * GtkWidget::move-focus:
1787 * @widget: the object which received the signal.
1790 widget_signals[MOVE_FOCUS] =
1791 g_signal_new (I_("move-focus"),
1792 G_TYPE_FROM_CLASS (klass),
1793 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1794 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1796 _gtk_marshal_VOID__ENUM,
1799 GTK_TYPE_DIRECTION_TYPE);
1802 * GtkWidget::keynav-failed:
1803 * @widget: the object which received the signal
1804 * @direction: the direction of movement
1806 * Gets emitted if keyboard navigation fails.
1807 * See gtk_widget_keynav_failed() for details.
1809 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1810 * if the emitting widget should try to handle the keyboard
1811 * navigation attempt in its parent container(s).
1815 widget_signals[KEYNAV_FAILED] =
1816 g_signal_new (I_("keynav-failed"),
1817 G_TYPE_FROM_CLASS (klass),
1819 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1820 _gtk_boolean_handled_accumulator, NULL,
1821 _gtk_marshal_BOOLEAN__ENUM,
1823 GTK_TYPE_DIRECTION_TYPE);
1827 * @widget: the object which received the signal.
1828 * @event: the #GdkEvent which triggered this signal
1830 * The GTK+ main loop will emit three signals for each GDK event delivered
1831 * to a widget: one generic ::event signal, another, more specific,
1832 * signal that matches the type of event delivered (e.g.
1833 * #GtkWidget::key-press-event) and finally a generic
1834 * #GtkWidget::event-after signal.
1836 * Returns: %TRUE to stop other handlers from being invoked for the event
1837 * and to cancel the emission of the second specific ::event signal.
1838 * %FALSE to propagate the event further and to allow the emission of
1839 * the second signal. The ::event-after signal is emitted regardless of
1842 widget_signals[EVENT] =
1843 g_signal_new (I_("event"),
1844 G_TYPE_FROM_CLASS (klass),
1846 G_STRUCT_OFFSET (GtkWidgetClass, event),
1847 _gtk_boolean_handled_accumulator, NULL,
1848 _gtk_marshal_BOOLEAN__BOXED,
1850 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1851 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1852 _gtk_marshal_BOOLEAN__BOXEDv);
1855 * GtkWidget::event-after:
1856 * @widget: the object which received the signal.
1857 * @event: the #GdkEvent which triggered this signal
1859 * After the emission of the #GtkWidget::event signal and (optionally)
1860 * the second more specific signal, ::event-after will be emitted
1861 * regardless of the previous two signals handlers return values.
1864 widget_signals[EVENT_AFTER] =
1865 g_signal_new (I_("event-after"),
1866 G_TYPE_FROM_CLASS (klass),
1870 _gtk_marshal_VOID__BOXED,
1872 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1873 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1874 _gtk_marshal_BOOLEAN__BOXEDv);
1877 * GtkWidget::button-press-event:
1878 * @widget: the object which received the signal.
1879 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1882 * The ::button-press-event signal will be emitted when a button
1883 * (typically from a mouse) is pressed.
1885 * To receive this signal, the #GdkWindow associated to the
1886 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1888 * This signal will be sent to the grab widget if there is one.
1890 * Returns: %TRUE to stop other handlers from being invoked for the event.
1891 * %FALSE to propagate the event further.
1893 widget_signals[BUTTON_PRESS_EVENT] =
1894 g_signal_new (I_("button-press-event"),
1895 G_TYPE_FROM_CLASS (klass),
1897 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1898 _gtk_boolean_handled_accumulator, NULL,
1899 _gtk_marshal_BOOLEAN__BOXED,
1901 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1902 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1903 _gtk_marshal_BOOLEAN__BOXEDv);
1906 * GtkWidget::button-release-event:
1907 * @widget: the object which received the signal.
1908 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1911 * The ::button-release-event signal will be emitted when a button
1912 * (typically from a mouse) is released.
1914 * To receive this signal, the #GdkWindow associated to the
1915 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1917 * This signal will be sent to the grab widget if there is one.
1919 * Returns: %TRUE to stop other handlers from being invoked for the event.
1920 * %FALSE to propagate the event further.
1922 widget_signals[BUTTON_RELEASE_EVENT] =
1923 g_signal_new (I_("button-release-event"),
1924 G_TYPE_FROM_CLASS (klass),
1926 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1927 _gtk_boolean_handled_accumulator, NULL,
1928 _gtk_marshal_BOOLEAN__BOXED,
1930 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1931 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1932 _gtk_marshal_BOOLEAN__BOXEDv);
1934 widget_signals[TOUCH_EVENT] =
1935 g_signal_new (I_("touch-event"),
1936 G_TYPE_FROM_CLASS (klass),
1938 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1939 _gtk_boolean_handled_accumulator, NULL,
1940 _gtk_marshal_BOOLEAN__BOXED,
1942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1944 _gtk_marshal_BOOLEAN__BOXEDv);
1947 * GtkWidget::scroll-event:
1948 * @widget: the object which received the signal.
1949 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1952 * The ::scroll-event signal is emitted when a button in the 4 to 7
1953 * range is pressed. Wheel mice are usually configured to generate
1954 * button press events for buttons 4 and 5 when the wheel is turned.
1956 * To receive this signal, the #GdkWindow associated to the widget needs
1957 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1959 * This signal will be sent to the grab widget if there is one.
1961 * Returns: %TRUE to stop other handlers from being invoked for the event.
1962 * %FALSE to propagate the event further.
1964 widget_signals[SCROLL_EVENT] =
1965 g_signal_new (I_("scroll-event"),
1966 G_TYPE_FROM_CLASS (klass),
1968 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1969 _gtk_boolean_handled_accumulator, NULL,
1970 _gtk_marshal_BOOLEAN__BOXED,
1972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1973 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1974 _gtk_marshal_BOOLEAN__BOXEDv);
1977 * GtkWidget::motion-notify-event:
1978 * @widget: the object which received the signal.
1979 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1982 * The ::motion-notify-event signal is emitted when the pointer moves
1983 * over the widget's #GdkWindow.
1985 * To receive this signal, the #GdkWindow associated to the widget
1986 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1988 * This signal will be sent to the grab widget if there is one.
1990 * Returns: %TRUE to stop other handlers from being invoked for the event.
1991 * %FALSE to propagate the event further.
1993 widget_signals[MOTION_NOTIFY_EVENT] =
1994 g_signal_new (I_("motion-notify-event"),
1995 G_TYPE_FROM_CLASS (klass),
1997 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1998 _gtk_boolean_handled_accumulator, NULL,
1999 _gtk_marshal_BOOLEAN__BOXED,
2001 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2002 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2003 _gtk_marshal_BOOLEAN__BOXEDv);
2006 * GtkWidget::composited-changed:
2007 * @widget: the object on which the signal is emitted
2009 * The ::composited-changed signal is emitted when the composited
2010 * status of @widget<!-- -->s screen changes.
2011 * See gdk_screen_is_composited().
2013 widget_signals[COMPOSITED_CHANGED] =
2014 g_signal_new (I_("composited-changed"),
2015 G_TYPE_FROM_CLASS (klass),
2016 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2017 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2019 _gtk_marshal_VOID__VOID,
2023 * GtkWidget::delete-event:
2024 * @widget: the object which received the signal
2025 * @event: the event which triggered this signal
2027 * The ::delete-event signal is emitted if a user requests that
2028 * a toplevel window is closed. The default handler for this signal
2029 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2030 * this signal will cause the window to be hidden instead, so that
2031 * it can later be shown again without reconstructing it.
2033 * Returns: %TRUE to stop other handlers from being invoked for the event.
2034 * %FALSE to propagate the event further.
2036 widget_signals[DELETE_EVENT] =
2037 g_signal_new (I_("delete-event"),
2038 G_TYPE_FROM_CLASS (klass),
2040 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2041 _gtk_boolean_handled_accumulator, NULL,
2042 _gtk_marshal_BOOLEAN__BOXED,
2044 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2045 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2046 _gtk_marshal_BOOLEAN__BOXEDv);
2049 * GtkWidget::destroy-event:
2050 * @widget: the object which received the signal.
2051 * @event: the event which triggered this signal
2053 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2054 * You rarely get this signal, because most widgets disconnect themselves
2055 * from their window before they destroy it, so no widget owns the
2056 * window at destroy time.
2058 * To receive this signal, the #GdkWindow associated to the widget needs
2059 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2060 * automatically for all new windows.
2062 * Returns: %TRUE to stop other handlers from being invoked for the event.
2063 * %FALSE to propagate the event further.
2065 widget_signals[DESTROY_EVENT] =
2066 g_signal_new (I_("destroy-event"),
2067 G_TYPE_FROM_CLASS (klass),
2069 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2070 _gtk_boolean_handled_accumulator, NULL,
2071 _gtk_marshal_BOOLEAN__BOXED,
2073 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2074 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2075 _gtk_marshal_BOOLEAN__BOXEDv);
2078 * GtkWidget::key-press-event:
2079 * @widget: the object which received the signal
2080 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2082 * The ::key-press-event signal is emitted when a key is pressed. The signal
2083 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2085 * To receive this signal, the #GdkWindow associated to the widget needs
2086 * to enable the #GDK_KEY_PRESS_MASK mask.
2088 * This signal will be sent to the grab widget if there is one.
2090 * Returns: %TRUE to stop other handlers from being invoked for the event.
2091 * %FALSE to propagate the event further.
2093 widget_signals[KEY_PRESS_EVENT] =
2094 g_signal_new (I_("key-press-event"),
2095 G_TYPE_FROM_CLASS (klass),
2097 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2098 _gtk_boolean_handled_accumulator, NULL,
2099 _gtk_marshal_BOOLEAN__BOXED,
2101 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2102 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2103 _gtk_marshal_BOOLEAN__BOXEDv);
2106 * GtkWidget::key-release-event:
2107 * @widget: the object which received the signal
2108 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2110 * The ::key-release-event signal is emitted when a key is released.
2112 * To receive this signal, the #GdkWindow associated to the widget needs
2113 * to enable the #GDK_KEY_RELEASE_MASK mask.
2115 * This signal will be sent to the grab widget if there is one.
2117 * Returns: %TRUE to stop other handlers from being invoked for the event.
2118 * %FALSE to propagate the event further.
2120 widget_signals[KEY_RELEASE_EVENT] =
2121 g_signal_new (I_("key-release-event"),
2122 G_TYPE_FROM_CLASS (klass),
2124 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2125 _gtk_boolean_handled_accumulator, NULL,
2126 _gtk_marshal_BOOLEAN__BOXED,
2128 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2129 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2130 _gtk_marshal_BOOLEAN__BOXEDv);
2133 * GtkWidget::enter-notify-event:
2134 * @widget: the object which received the signal
2135 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2138 * The ::enter-notify-event will be emitted when the pointer enters
2139 * the @widget's window.
2141 * To receive this signal, the #GdkWindow associated to the widget needs
2142 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2144 * This signal will be sent to the grab widget if there is one.
2146 * Returns: %TRUE to stop other handlers from being invoked for the event.
2147 * %FALSE to propagate the event further.
2149 widget_signals[ENTER_NOTIFY_EVENT] =
2150 g_signal_new (I_("enter-notify-event"),
2151 G_TYPE_FROM_CLASS (klass),
2153 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2154 _gtk_boolean_handled_accumulator, NULL,
2155 _gtk_marshal_BOOLEAN__BOXED,
2157 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2158 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2159 _gtk_marshal_BOOLEAN__BOXEDv);
2162 * GtkWidget::leave-notify-event:
2163 * @widget: the object which received the signal
2164 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2167 * The ::leave-notify-event will be emitted when the pointer leaves
2168 * the @widget's window.
2170 * To receive this signal, the #GdkWindow associated to the widget needs
2171 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2173 * This signal will be sent to the grab widget if there is one.
2175 * Returns: %TRUE to stop other handlers from being invoked for the event.
2176 * %FALSE to propagate the event further.
2178 widget_signals[LEAVE_NOTIFY_EVENT] =
2179 g_signal_new (I_("leave-notify-event"),
2180 G_TYPE_FROM_CLASS (klass),
2182 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2183 _gtk_boolean_handled_accumulator, NULL,
2184 _gtk_marshal_BOOLEAN__BOXED,
2186 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2187 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2188 _gtk_marshal_BOOLEAN__BOXEDv);
2191 * GtkWidget::configure-event:
2192 * @widget: the object which received the signal
2193 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2196 * The ::configure-event signal will be emitted when the size, position or
2197 * stacking of the @widget's window has changed.
2199 * To receive this signal, the #GdkWindow associated to the widget needs
2200 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2201 * automatically for all new windows.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event.
2204 * %FALSE to propagate the event further.
2206 widget_signals[CONFIGURE_EVENT] =
2207 g_signal_new (I_("configure-event"),
2208 G_TYPE_FROM_CLASS (klass),
2210 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2215 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2216 _gtk_marshal_BOOLEAN__BOXEDv);
2219 * GtkWidget::focus-in-event:
2220 * @widget: the object which received the signal
2221 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2224 * The ::focus-in-event signal will be emitted when the keyboard focus
2225 * enters the @widget's window.
2227 * To receive this signal, the #GdkWindow associated to the widget needs
2228 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[FOCUS_IN_EVENT] =
2234 g_signal_new (I_("focus-in-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2243 _gtk_marshal_BOOLEAN__BOXEDv);
2246 * GtkWidget::focus-out-event:
2247 * @widget: the object which received the signal
2248 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2251 * The ::focus-out-event signal will be emitted when the keyboard focus
2252 * leaves the @widget's window.
2254 * To receive this signal, the #GdkWindow associated to the widget needs
2255 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2257 * Returns: %TRUE to stop other handlers from being invoked for the event.
2258 * %FALSE to propagate the event further.
2260 widget_signals[FOCUS_OUT_EVENT] =
2261 g_signal_new (I_("focus-out-event"),
2262 G_TYPE_FROM_CLASS (klass),
2264 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2265 _gtk_boolean_handled_accumulator, NULL,
2266 _gtk_marshal_BOOLEAN__BOXED,
2268 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2269 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2270 _gtk_marshal_BOOLEAN__BOXEDv);
2273 * GtkWidget::map-event:
2274 * @widget: the object which received the signal
2275 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2277 * The ::map-event signal will be emitted when the @widget's window is
2278 * mapped. A window is mapped when it becomes visible on the screen.
2280 * To receive this signal, the #GdkWindow associated to the widget needs
2281 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2282 * automatically for all new windows.
2284 * Returns: %TRUE to stop other handlers from being invoked for the event.
2285 * %FALSE to propagate the event further.
2287 widget_signals[MAP_EVENT] =
2288 g_signal_new (I_("map-event"),
2289 G_TYPE_FROM_CLASS (klass),
2291 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2292 _gtk_boolean_handled_accumulator, NULL,
2293 _gtk_marshal_BOOLEAN__BOXED,
2295 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2296 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2297 _gtk_marshal_BOOLEAN__BOXEDv);
2300 * GtkWidget::unmap-event:
2301 * @widget: the object which received the signal
2302 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2304 * The ::unmap-event signal will be emitted when the @widget's window is
2305 * unmapped. A window is unmapped when it becomes invisible on the screen.
2307 * To receive this signal, the #GdkWindow associated to the widget needs
2308 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2309 * automatically for all new windows.
2311 * Returns: %TRUE to stop other handlers from being invoked for the event.
2312 * %FALSE to propagate the event further.
2314 widget_signals[UNMAP_EVENT] =
2315 g_signal_new (I_("unmap-event"),
2316 G_TYPE_FROM_CLASS (klass),
2318 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__BOXED,
2322 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2323 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2324 _gtk_marshal_BOOLEAN__BOXEDv);
2327 * GtkWidget::property-notify-event:
2328 * @widget: the object which received the signal
2329 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2332 * The ::property-notify-event signal will be emitted when a property on
2333 * the @widget's window has been changed or deleted.
2335 * To receive this signal, the #GdkWindow associated to the widget needs
2336 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2338 * Returns: %TRUE to stop other handlers from being invoked for the event.
2339 * %FALSE to propagate the event further.
2341 widget_signals[PROPERTY_NOTIFY_EVENT] =
2342 g_signal_new (I_("property-notify-event"),
2343 G_TYPE_FROM_CLASS (klass),
2345 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2346 _gtk_boolean_handled_accumulator, NULL,
2347 _gtk_marshal_BOOLEAN__BOXED,
2349 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2350 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2351 _gtk_marshal_BOOLEAN__BOXEDv);
2354 * GtkWidget::selection-clear-event:
2355 * @widget: the object which received the signal
2356 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2359 * The ::selection-clear-event signal will be emitted when the
2360 * the @widget's window has lost ownership of a selection.
2362 * Returns: %TRUE to stop other handlers from being invoked for the event.
2363 * %FALSE to propagate the event further.
2365 widget_signals[SELECTION_CLEAR_EVENT] =
2366 g_signal_new (I_("selection-clear-event"),
2367 G_TYPE_FROM_CLASS (klass),
2369 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2370 _gtk_boolean_handled_accumulator, NULL,
2371 _gtk_marshal_BOOLEAN__BOXED,
2373 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2374 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2375 _gtk_marshal_BOOLEAN__BOXEDv);
2378 * GtkWidget::selection-request-event:
2379 * @widget: the object which received the signal
2380 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2383 * The ::selection-request-event signal will be emitted when
2384 * another client requests ownership of the selection owned by
2385 * the @widget's window.
2387 * Returns: %TRUE to stop other handlers from being invoked for the event.
2388 * %FALSE to propagate the event further.
2390 widget_signals[SELECTION_REQUEST_EVENT] =
2391 g_signal_new (I_("selection-request-event"),
2392 G_TYPE_FROM_CLASS (klass),
2394 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2395 _gtk_boolean_handled_accumulator, NULL,
2396 _gtk_marshal_BOOLEAN__BOXED,
2398 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2399 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2400 _gtk_marshal_BOOLEAN__BOXEDv);
2403 * GtkWidget::selection-notify-event:
2404 * @widget: the object which received the signal.
2405 * @event: (type Gdk.EventSelection):
2407 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2409 widget_signals[SELECTION_NOTIFY_EVENT] =
2410 g_signal_new (I_("selection-notify-event"),
2411 G_TYPE_FROM_CLASS (klass),
2413 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2414 _gtk_boolean_handled_accumulator, NULL,
2415 _gtk_marshal_BOOLEAN__BOXED,
2417 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2418 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2419 _gtk_marshal_BOOLEAN__BOXEDv);
2422 * GtkWidget::selection-received:
2423 * @widget: the object which received the signal.
2427 widget_signals[SELECTION_RECEIVED] =
2428 g_signal_new (I_("selection-received"),
2429 G_TYPE_FROM_CLASS (klass),
2431 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2433 _gtk_marshal_VOID__BOXED_UINT,
2435 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2439 * GtkWidget::selection-get:
2440 * @widget: the object which received the signal.
2445 widget_signals[SELECTION_GET] =
2446 g_signal_new (I_("selection-get"),
2447 G_TYPE_FROM_CLASS (klass),
2449 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2451 _gtk_marshal_VOID__BOXED_UINT_UINT,
2453 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2458 * GtkWidget::proximity-in-event:
2459 * @widget: the object which received the signal
2460 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2463 * To receive this signal the #GdkWindow associated to the widget needs
2464 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2466 * This signal will be sent to the grab widget if there is one.
2468 * Returns: %TRUE to stop other handlers from being invoked for the event.
2469 * %FALSE to propagate the event further.
2471 widget_signals[PROXIMITY_IN_EVENT] =
2472 g_signal_new (I_("proximity-in-event"),
2473 G_TYPE_FROM_CLASS (klass),
2475 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2476 _gtk_boolean_handled_accumulator, NULL,
2477 _gtk_marshal_BOOLEAN__BOXED,
2479 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2480 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2481 _gtk_marshal_BOOLEAN__BOXEDv);
2484 * GtkWidget::proximity-out-event:
2485 * @widget: the object which received the signal
2486 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2489 * To receive this signal the #GdkWindow associated to the widget needs
2490 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2492 * This signal will be sent to the grab widget if there is one.
2494 * Returns: %TRUE to stop other handlers from being invoked for the event.
2495 * %FALSE to propagate the event further.
2497 widget_signals[PROXIMITY_OUT_EVENT] =
2498 g_signal_new (I_("proximity-out-event"),
2499 G_TYPE_FROM_CLASS (klass),
2501 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2502 _gtk_boolean_handled_accumulator, NULL,
2503 _gtk_marshal_BOOLEAN__BOXED,
2505 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2506 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2507 _gtk_marshal_BOOLEAN__BOXEDv);
2510 * GtkWidget::drag-leave:
2511 * @widget: the object which received the signal.
2512 * @drag_context: the drag context
2513 * @time: the timestamp of the motion event
2515 * The ::drag-leave signal is emitted on the drop site when the cursor
2516 * leaves the widget. A typical reason to connect to this signal is to
2517 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2518 * with gtk_drag_unhighlight()
2520 widget_signals[DRAG_LEAVE] =
2521 g_signal_new (I_("drag-leave"),
2522 G_TYPE_FROM_CLASS (klass),
2524 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2526 _gtk_marshal_VOID__OBJECT_UINT,
2528 GDK_TYPE_DRAG_CONTEXT,
2532 * GtkWidget::drag-begin:
2533 * @widget: the object which received the signal
2534 * @drag_context: the drag context
2536 * The ::drag-begin signal is emitted on the drag source when a drag is
2537 * started. A typical reason to connect to this signal is to set up a
2538 * custom drag icon with gtk_drag_source_set_icon().
2540 * Note that some widgets set up a drag icon in the default handler of
2541 * this signal, so you may have to use g_signal_connect_after() to
2542 * override what the default handler did.
2544 widget_signals[DRAG_BEGIN] =
2545 g_signal_new (I_("drag-begin"),
2546 G_TYPE_FROM_CLASS (klass),
2548 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2550 _gtk_marshal_VOID__OBJECT,
2552 GDK_TYPE_DRAG_CONTEXT);
2555 * GtkWidget::drag-end:
2556 * @widget: the object which received the signal
2557 * @drag_context: the drag context
2559 * The ::drag-end signal is emitted on the drag source when a drag is
2560 * finished. A typical reason to connect to this signal is to undo
2561 * things done in #GtkWidget::drag-begin.
2563 widget_signals[DRAG_END] =
2564 g_signal_new (I_("drag-end"),
2565 G_TYPE_FROM_CLASS (klass),
2567 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2569 _gtk_marshal_VOID__OBJECT,
2571 GDK_TYPE_DRAG_CONTEXT);
2574 * GtkWidget::drag-data-delete:
2575 * @widget: the object which received the signal
2576 * @drag_context: the drag context
2578 * The ::drag-data-delete signal is emitted on the drag source when a drag
2579 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2580 * handler is responsible for deleting the data that has been dropped. What
2581 * "delete" means depends on the context of the drag operation.
2583 widget_signals[DRAG_DATA_DELETE] =
2584 g_signal_new (I_("drag-data-delete"),
2585 G_TYPE_FROM_CLASS (klass),
2587 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2589 _gtk_marshal_VOID__OBJECT,
2591 GDK_TYPE_DRAG_CONTEXT);
2594 * GtkWidget::drag-failed:
2595 * @widget: the object which received the signal
2596 * @drag_context: the drag context
2597 * @result: the result of the drag operation
2599 * The ::drag-failed signal is emitted on the drag source when a drag has
2600 * failed. The signal handler may hook custom code to handle a failed DND
2601 * operation based on the type of error, it returns %TRUE is the failure has
2602 * been already handled (not showing the default "drag operation failed"
2603 * animation), otherwise it returns %FALSE.
2605 * Return value: %TRUE if the failed drag operation has been already handled.
2609 widget_signals[DRAG_FAILED] =
2610 g_signal_new (I_("drag-failed"),
2611 G_TYPE_FROM_CLASS (klass),
2613 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2614 _gtk_boolean_handled_accumulator, NULL,
2615 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2617 GDK_TYPE_DRAG_CONTEXT,
2618 GTK_TYPE_DRAG_RESULT);
2621 * GtkWidget::drag-motion:
2622 * @widget: the object which received the signal
2623 * @drag_context: the drag context
2624 * @x: the x coordinate of the current cursor position
2625 * @y: the y coordinate of the current cursor position
2626 * @time: the timestamp of the motion event
2628 * The drag-motion signal is emitted on the drop site when the user
2629 * moves the cursor over the widget during a drag. The signal handler
2630 * must determine whether the cursor position is in a drop zone or not.
2631 * If it is not in a drop zone, it returns %FALSE and no further processing
2632 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2633 * handler is responsible for providing the necessary information for
2634 * displaying feedback to the user, by calling gdk_drag_status().
2636 * If the decision whether the drop will be accepted or rejected can't be
2637 * made based solely on the cursor position and the type of the data, the
2638 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2639 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2640 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2641 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2642 * when using the drag-motion signal that way.
2644 * Also note that there is no drag-enter signal. The drag receiver has to
2645 * keep track of whether he has received any drag-motion signals since the
2646 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2647 * an "enter" signal. Upon an "enter", the handler will typically highlight
2648 * the drop site with gtk_drag_highlight().
2651 * drag_motion (GtkWidget *widget,
2652 * GdkDragContext *context,
2659 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2661 * if (!private_data->drag_highlight)
2663 * private_data->drag_highlight = 1;
2664 * gtk_drag_highlight (widget);
2667 * target = gtk_drag_dest_find_target (widget, context, NULL);
2668 * if (target == GDK_NONE)
2669 * gdk_drag_status (context, 0, time);
2672 * private_data->pending_status = context->suggested_action;
2673 * gtk_drag_get_data (widget, context, target, time);
2680 * drag_data_received (GtkWidget *widget,
2681 * GdkDragContext *context,
2684 * GtkSelectionData *selection_data,
2688 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2690 * if (private_data->suggested_action)
2692 * private_data->suggested_action = 0;
2694 * /* We are getting this data due to a request in drag_motion,
2695 * * rather than due to a request in drag_drop, so we are just
2696 * * supposed to call gdk_drag_status (), not actually paste in
2699 * str = gtk_selection_data_get_text (selection_data);
2700 * if (!data_is_acceptable (str))
2701 * gdk_drag_status (context, 0, time);
2703 * gdk_drag_status (context, private_data->suggested_action, time);
2707 * /* accept the drop */
2712 * Returns: whether the cursor position is in a drop zone
2714 widget_signals[DRAG_MOTION] =
2715 g_signal_new (I_("drag-motion"),
2716 G_TYPE_FROM_CLASS (klass),
2718 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2719 _gtk_boolean_handled_accumulator, NULL,
2720 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2722 GDK_TYPE_DRAG_CONTEXT,
2728 * GtkWidget::drag-drop:
2729 * @widget: the object which received the signal
2730 * @drag_context: the drag context
2731 * @x: the x coordinate of the current cursor position
2732 * @y: the y coordinate of the current cursor position
2733 * @time: the timestamp of the motion event
2735 * The ::drag-drop signal is emitted on the drop site when the user drops
2736 * the data onto the widget. The signal handler must determine whether
2737 * the cursor position is in a drop zone or not. If it is not in a drop
2738 * zone, it returns %FALSE and no further processing is necessary.
2739 * Otherwise, the handler returns %TRUE. In this case, the handler must
2740 * ensure that gtk_drag_finish() is called to let the source know that
2741 * the drop is done. The call to gtk_drag_finish() can be done either
2742 * directly or in a #GtkWidget::drag-data-received handler which gets
2743 * triggered by calling gtk_drag_get_data() to receive the data for one
2744 * or more of the supported targets.
2746 * Returns: whether the cursor position is in a drop zone
2748 widget_signals[DRAG_DROP] =
2749 g_signal_new (I_("drag-drop"),
2750 G_TYPE_FROM_CLASS (klass),
2752 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2753 _gtk_boolean_handled_accumulator, NULL,
2754 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2756 GDK_TYPE_DRAG_CONTEXT,
2762 * GtkWidget::drag-data-get:
2763 * @widget: the object which received the signal
2764 * @drag_context: the drag context
2765 * @data: the #GtkSelectionData to be filled with the dragged data
2766 * @info: the info that has been registered with the target in the
2768 * @time: the timestamp at which the data was requested
2770 * The ::drag-data-get signal is emitted on the drag source when the drop
2771 * site requests the data which is dragged. It is the responsibility of
2772 * the signal handler to fill @data with the data in the format which
2773 * is indicated by @info. See gtk_selection_data_set() and
2774 * gtk_selection_data_set_text().
2776 widget_signals[DRAG_DATA_GET] =
2777 g_signal_new (I_("drag-data-get"),
2778 G_TYPE_FROM_CLASS (klass),
2780 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2782 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2784 GDK_TYPE_DRAG_CONTEXT,
2785 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2790 * GtkWidget::drag-data-received:
2791 * @widget: the object which received the signal
2792 * @drag_context: the drag context
2793 * @x: where the drop happened
2794 * @y: where the drop happened
2795 * @data: the received data
2796 * @info: the info that has been registered with the target in the
2798 * @time: the timestamp at which the data was received
2800 * The ::drag-data-received signal is emitted on the drop site when the
2801 * dragged data has been received. If the data was received in order to
2802 * determine whether the drop will be accepted, the handler is expected
2803 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2804 * If the data was received in response to a #GtkWidget::drag-drop signal
2805 * (and this is the last target to be received), the handler for this
2806 * signal is expected to process the received data and then call
2807 * gtk_drag_finish(), setting the @success parameter depending on whether
2808 * the data was processed successfully.
2810 * The handler may inspect and modify @drag_context->action before calling
2811 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2812 * following example:
2815 * drag_data_received (GtkWidget *widget,
2816 * GdkDragContext *drag_context,
2819 * GtkSelectionData *data,
2823 * if ((data->length >= 0) && (data->format == 8))
2825 * if (drag_context->action == GDK_ACTION_ASK)
2827 * GtkWidget *dialog;
2830 * dialog = gtk_message_dialog_new (NULL,
2831 * GTK_DIALOG_MODAL |
2832 * GTK_DIALOG_DESTROY_WITH_PARENT,
2834 * GTK_BUTTONS_YES_NO,
2835 * "Move the data ?\n");
2836 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2837 * gtk_widget_destroy (dialog);
2839 * if (response == GTK_RESPONSE_YES)
2840 * drag_context->action = GDK_ACTION_MOVE;
2842 * drag_context->action = GDK_ACTION_COPY;
2845 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2849 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2853 widget_signals[DRAG_DATA_RECEIVED] =
2854 g_signal_new (I_("drag-data-received"),
2855 G_TYPE_FROM_CLASS (klass),
2857 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2859 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2861 GDK_TYPE_DRAG_CONTEXT,
2864 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2869 * GtkWidget::visibility-notify-event:
2870 * @widget: the object which received the signal
2871 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2872 * triggered this signal.
2874 * The ::visibility-notify-event will be emitted when the @widget's window
2875 * is obscured or unobscured.
2877 * To receive this signal the #GdkWindow associated to the widget needs
2878 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2880 * Returns: %TRUE to stop other handlers from being invoked for the event.
2881 * %FALSE to propagate the event further.
2883 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2884 g_signal_new (I_("visibility-notify-event"),
2885 G_TYPE_FROM_CLASS (klass),
2887 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2888 _gtk_boolean_handled_accumulator, NULL,
2889 _gtk_marshal_BOOLEAN__BOXED,
2891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2894 * GtkWidget::window-state-event:
2895 * @widget: the object which received the signal
2896 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2897 * triggered this signal.
2899 * The ::window-state-event will be emitted when the state of the
2900 * toplevel window associated to the @widget changes.
2902 * To receive this signal the #GdkWindow associated to the widget
2903 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2904 * this mask automatically for all new windows.
2906 * Returns: %TRUE to stop other handlers from being invoked for the
2907 * event. %FALSE to propagate the event further.
2909 widget_signals[WINDOW_STATE_EVENT] =
2910 g_signal_new (I_("window-state-event"),
2911 G_TYPE_FROM_CLASS (klass),
2913 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2914 _gtk_boolean_handled_accumulator, NULL,
2915 _gtk_marshal_BOOLEAN__BOXED,
2917 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2918 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2919 _gtk_marshal_BOOLEAN__BOXEDv);
2922 * GtkWidget::damage-event:
2923 * @widget: the object which received the signal
2924 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2926 * Emitted when a redirected window belonging to @widget gets drawn into.
2927 * The region/area members of the event shows what area of the redirected
2928 * drawable was drawn into.
2930 * Returns: %TRUE to stop other handlers from being invoked for the event.
2931 * %FALSE to propagate the event further.
2935 widget_signals[DAMAGE_EVENT] =
2936 g_signal_new (I_("damage-event"),
2937 G_TYPE_FROM_CLASS (klass),
2939 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2940 _gtk_boolean_handled_accumulator, NULL,
2941 _gtk_marshal_BOOLEAN__BOXED,
2943 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2944 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2945 _gtk_marshal_BOOLEAN__BOXEDv);
2948 * GtkWidget::grab-broken-event:
2949 * @widget: the object which received the signal
2950 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2952 * Emitted when a pointer or keyboard grab on a window belonging
2953 * to @widget gets broken.
2955 * On X11, this happens when the grab window becomes unviewable
2956 * (i.e. it or one of its ancestors is unmapped), or if the same
2957 * application grabs the pointer or keyboard again.
2959 * Returns: %TRUE to stop other handlers from being invoked for
2960 * the event. %FALSE to propagate the event further.
2964 widget_signals[GRAB_BROKEN_EVENT] =
2965 g_signal_new (I_("grab-broken-event"),
2966 G_TYPE_FROM_CLASS (klass),
2968 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2969 _gtk_boolean_handled_accumulator, NULL,
2970 _gtk_marshal_BOOLEAN__BOXED,
2972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2973 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2974 _gtk_marshal_BOOLEAN__BOXEDv);
2977 * GtkWidget::query-tooltip:
2978 * @widget: the object which received the signal
2979 * @x: the x coordinate of the cursor position where the request has
2980 * been emitted, relative to @widget's left side
2981 * @y: the y coordinate of the cursor position where the request has
2982 * been emitted, relative to @widget's top
2983 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2984 * @tooltip: a #GtkTooltip
2986 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2987 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2988 * focus in keyboard mode.
2990 * Using the given coordinates, the signal handler should determine
2991 * whether a tooltip should be shown for @widget. If this is the case
2992 * %TRUE should be returned, %FALSE otherwise. Note that if
2993 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2994 * should not be used.
2996 * The signal handler is free to manipulate @tooltip with the therefore
2997 * destined function calls.
2999 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3003 widget_signals[QUERY_TOOLTIP] =
3004 g_signal_new (I_("query-tooltip"),
3005 G_TYPE_FROM_CLASS (klass),
3007 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3008 _gtk_boolean_handled_accumulator, NULL,
3009 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3017 * GtkWidget::popup-menu:
3018 * @widget: the object which received the signal
3020 * This signal gets emitted whenever a widget should pop up a context
3021 * menu. This usually happens through the standard key binding mechanism;
3022 * by pressing a certain key while a widget is focused, the user can cause
3023 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3024 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3025 * for an example of how to use this signal.
3027 * Returns: %TRUE if a menu was activated
3029 widget_signals[POPUP_MENU] =
3030 g_signal_new (I_("popup-menu"),
3031 G_TYPE_FROM_CLASS (klass),
3032 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3033 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3034 _gtk_boolean_handled_accumulator, NULL,
3035 _gtk_marshal_BOOLEAN__VOID,
3039 * GtkWidget::show-help:
3040 * @widget: the object which received the signal.
3043 widget_signals[SHOW_HELP] =
3044 g_signal_new (I_("show-help"),
3045 G_TYPE_FROM_CLASS (klass),
3046 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3047 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3048 _gtk_boolean_handled_accumulator, NULL,
3049 _gtk_marshal_BOOLEAN__ENUM,
3051 GTK_TYPE_WIDGET_HELP_TYPE);
3054 * GtkWidget::accel-closures-changed:
3055 * @widget: the object which received the signal.
3057 widget_signals[ACCEL_CLOSURES_CHANGED] =
3058 g_signal_new (I_("accel-closures-changed"),
3059 G_TYPE_FROM_CLASS (klass),
3063 _gtk_marshal_VOID__VOID,
3067 * GtkWidget::screen-changed:
3068 * @widget: the object on which the signal is emitted
3069 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3070 * widget was not associated with a screen before
3072 * The ::screen-changed signal gets emitted when the
3073 * screen of a widget has changed.
3075 widget_signals[SCREEN_CHANGED] =
3076 g_signal_new (I_("screen-changed"),
3077 G_TYPE_FROM_CLASS (klass),
3079 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3081 _gtk_marshal_VOID__OBJECT,
3086 * GtkWidget::can-activate-accel:
3087 * @widget: the object which received the signal
3088 * @signal_id: the ID of a signal installed on @widget
3090 * Determines whether an accelerator that activates the signal
3091 * identified by @signal_id can currently be activated.
3092 * This signal is present to allow applications and derived
3093 * widgets to override the default #GtkWidget handling
3094 * for determining whether an accelerator can be activated.
3096 * Returns: %TRUE if the signal can be activated.
3098 widget_signals[CAN_ACTIVATE_ACCEL] =
3099 g_signal_new (I_("can-activate-accel"),
3100 G_TYPE_FROM_CLASS (klass),
3102 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3103 _gtk_boolean_handled_accumulator, NULL,
3104 _gtk_marshal_BOOLEAN__UINT,
3105 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3107 binding_set = gtk_binding_set_by_class (klass);
3108 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3110 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3113 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3115 GTK_TYPE_WIDGET_HELP_TYPE,
3116 GTK_WIDGET_HELP_TOOLTIP);
3117 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3119 GTK_TYPE_WIDGET_HELP_TYPE,
3120 GTK_WIDGET_HELP_TOOLTIP);
3121 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3123 GTK_TYPE_WIDGET_HELP_TYPE,
3124 GTK_WIDGET_HELP_WHATS_THIS);
3125 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3127 GTK_TYPE_WIDGET_HELP_TYPE,
3128 GTK_WIDGET_HELP_WHATS_THIS);
3130 gtk_widget_class_install_style_property (klass,
3131 g_param_spec_boolean ("interior-focus",
3132 P_("Interior Focus"),
3133 P_("Whether to draw the focus indicator inside widgets"),
3135 GTK_PARAM_READABLE));
3137 gtk_widget_class_install_style_property (klass,
3138 g_param_spec_int ("focus-line-width",
3139 P_("Focus linewidth"),
3140 P_("Width, in pixels, of the focus indicator line"),
3142 GTK_PARAM_READABLE));
3144 gtk_widget_class_install_style_property (klass,
3145 g_param_spec_string ("focus-line-pattern",
3146 P_("Focus line dash pattern"),
3147 P_("Dash pattern used to draw the focus indicator"),
3149 GTK_PARAM_READABLE));
3150 gtk_widget_class_install_style_property (klass,
3151 g_param_spec_int ("focus-padding",
3152 P_("Focus padding"),
3153 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3155 GTK_PARAM_READABLE));
3156 gtk_widget_class_install_style_property (klass,
3157 g_param_spec_boxed ("cursor-color",
3159 P_("Color with which to draw insertion cursor"),
3161 GTK_PARAM_READABLE));
3162 gtk_widget_class_install_style_property (klass,
3163 g_param_spec_boxed ("secondary-cursor-color",
3164 P_("Secondary cursor color"),
3165 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3167 GTK_PARAM_READABLE));
3168 gtk_widget_class_install_style_property (klass,
3169 g_param_spec_float ("cursor-aspect-ratio",
3170 P_("Cursor line aspect ratio"),
3171 P_("Aspect ratio with which to draw insertion cursor"),
3173 GTK_PARAM_READABLE));
3175 gtk_widget_class_install_style_property (klass,
3176 g_param_spec_boolean ("window-dragging",
3177 P_("Window dragging"),
3178 P_("Whether windows can be dragged by clicking on empty areas"),
3180 GTK_PARAM_READABLE));
3183 * GtkWidget:link-color:
3185 * The "link-color" style property defines the color of unvisited links.
3189 gtk_widget_class_install_style_property (klass,
3190 g_param_spec_boxed ("link-color",
3191 P_("Unvisited Link Color"),
3192 P_("Color of unvisited links"),
3194 GTK_PARAM_READABLE));
3197 * GtkWidget:visited-link-color:
3199 * The "visited-link-color" style property defines the color of visited links.
3203 gtk_widget_class_install_style_property (klass,
3204 g_param_spec_boxed ("visited-link-color",
3205 P_("Visited Link Color"),
3206 P_("Color of visited links"),
3208 GTK_PARAM_READABLE));
3211 * GtkWidget:wide-separators:
3213 * The "wide-separators" style property defines whether separators have
3214 * configurable width and should be drawn using a box instead of a line.
3218 gtk_widget_class_install_style_property (klass,
3219 g_param_spec_boolean ("wide-separators",
3220 P_("Wide Separators"),
3221 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3223 GTK_PARAM_READABLE));
3226 * GtkWidget:separator-width:
3228 * The "separator-width" style property defines the width of separators.
3229 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3233 gtk_widget_class_install_style_property (klass,
3234 g_param_spec_int ("separator-width",
3235 P_("Separator Width"),
3236 P_("The width of separators if wide-separators is TRUE"),
3238 GTK_PARAM_READABLE));
3241 * GtkWidget:separator-height:
3243 * The "separator-height" style property defines the height of separators.
3244 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3248 gtk_widget_class_install_style_property (klass,
3249 g_param_spec_int ("separator-height",
3250 P_("Separator Height"),
3251 P_("The height of separators if \"wide-separators\" is TRUE"),
3253 GTK_PARAM_READABLE));
3256 * GtkWidget:scroll-arrow-hlength:
3258 * The "scroll-arrow-hlength" style property defines the length of
3259 * horizontal scroll arrows.
3263 gtk_widget_class_install_style_property (klass,
3264 g_param_spec_int ("scroll-arrow-hlength",
3265 P_("Horizontal Scroll Arrow Length"),
3266 P_("The length of horizontal scroll arrows"),
3268 GTK_PARAM_READABLE));
3271 * GtkWidget:scroll-arrow-vlength:
3273 * The "scroll-arrow-vlength" style property defines the length of
3274 * vertical scroll arrows.
3278 gtk_widget_class_install_style_property (klass,
3279 g_param_spec_int ("scroll-arrow-vlength",
3280 P_("Vertical Scroll Arrow Length"),
3281 P_("The length of vertical scroll arrows"),
3283 GTK_PARAM_READABLE));
3285 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3287 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3291 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3295 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3296 for (node = list; node; node = node->next)
3298 GParamSpec *pspec = node->data;
3300 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3301 g_param_spec_unref (pspec);
3307 gtk_widget_set_property (GObject *object,
3309 const GValue *value,
3312 GtkWidget *widget = GTK_WIDGET (object);
3317 gchar *tooltip_markup;
3318 const gchar *tooltip_text;
3319 GtkWindow *tooltip_window;
3322 gtk_widget_set_name (widget, g_value_get_string (value));
3325 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3327 case PROP_WIDTH_REQUEST:
3328 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3330 case PROP_HEIGHT_REQUEST:
3331 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3334 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3336 case PROP_SENSITIVE:
3337 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3339 case PROP_APP_PAINTABLE:
3340 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3342 case PROP_CAN_FOCUS:
3343 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3345 case PROP_HAS_FOCUS:
3346 if (g_value_get_boolean (value))
3347 gtk_widget_grab_focus (widget);
3350 if (g_value_get_boolean (value))
3351 gtk_widget_grab_focus (widget);
3353 case PROP_CAN_DEFAULT:
3354 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3356 case PROP_HAS_DEFAULT:
3357 if (g_value_get_boolean (value))
3358 gtk_widget_grab_default (widget);
3360 case PROP_RECEIVES_DEFAULT:
3361 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3364 gtk_widget_set_style (widget, g_value_get_object (value));
3367 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3368 gtk_widget_set_events (widget, g_value_get_flags (value));
3370 case PROP_NO_SHOW_ALL:
3371 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3373 case PROP_HAS_TOOLTIP:
3374 gtk_widget_real_set_has_tooltip (widget,
3375 g_value_get_boolean (value), FALSE);
3377 case PROP_TOOLTIP_MARKUP:
3378 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3379 tooltip_markup = g_value_dup_string (value);
3381 /* Treat an empty string as a NULL string,
3382 * because an empty string would be useless for a tooltip:
3384 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3386 g_free (tooltip_markup);
3387 tooltip_markup = NULL;
3390 g_object_set_qdata_full (object, quark_tooltip_markup,
3391 tooltip_markup, g_free);
3393 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3394 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3395 if (gtk_widget_get_visible (widget))
3396 gtk_widget_queue_tooltip_query (widget);
3398 case PROP_TOOLTIP_TEXT:
3399 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3401 tooltip_text = g_value_get_string (value);
3403 /* Treat an empty string as a NULL string,
3404 * because an empty string would be useless for a tooltip:
3406 if (tooltip_text && (strlen (tooltip_text) == 0))
3407 tooltip_text = NULL;
3409 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3411 g_object_set_qdata_full (object, quark_tooltip_markup,
3412 tooltip_markup, g_free);
3414 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3415 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3416 if (gtk_widget_get_visible (widget))
3417 gtk_widget_queue_tooltip_query (widget);
3419 case PROP_DOUBLE_BUFFERED:
3420 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3423 gtk_widget_set_halign (widget, g_value_get_enum (value));
3426 gtk_widget_set_valign (widget, g_value_get_enum (value));
3428 case PROP_MARGIN_LEFT:
3429 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3431 case PROP_MARGIN_RIGHT:
3432 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3434 case PROP_MARGIN_TOP:
3435 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3437 case PROP_MARGIN_BOTTOM:
3438 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3441 g_object_freeze_notify (G_OBJECT (widget));
3442 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3443 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3444 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3445 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3446 g_object_thaw_notify (G_OBJECT (widget));
3449 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3451 case PROP_HEXPAND_SET:
3452 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3455 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3457 case PROP_VEXPAND_SET:
3458 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3461 g_object_freeze_notify (G_OBJECT (widget));
3462 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3463 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3464 g_object_thaw_notify (G_OBJECT (widget));
3467 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3473 gtk_widget_get_property (GObject *object,
3478 GtkWidget *widget = GTK_WIDGET (object);
3479 GtkWidgetPrivate *priv = widget->priv;
3487 g_value_set_string (value, priv->name);
3489 g_value_set_static_string (value, "");
3492 g_value_set_object (value, priv->parent);
3494 case PROP_WIDTH_REQUEST:
3497 gtk_widget_get_size_request (widget, &w, NULL);
3498 g_value_set_int (value, w);
3501 case PROP_HEIGHT_REQUEST:
3504 gtk_widget_get_size_request (widget, NULL, &h);
3505 g_value_set_int (value, h);
3509 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3511 case PROP_SENSITIVE:
3512 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3514 case PROP_APP_PAINTABLE:
3515 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3517 case PROP_CAN_FOCUS:
3518 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3520 case PROP_HAS_FOCUS:
3521 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3524 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3526 case PROP_CAN_DEFAULT:
3527 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3529 case PROP_HAS_DEFAULT:
3530 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3532 case PROP_RECEIVES_DEFAULT:
3533 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3535 case PROP_COMPOSITE_CHILD:
3536 g_value_set_boolean (value, widget->priv->composite_child);
3539 g_value_set_object (value, gtk_widget_get_style (widget));
3542 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3543 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3545 case PROP_NO_SHOW_ALL:
3546 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3548 case PROP_HAS_TOOLTIP:
3549 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3551 case PROP_TOOLTIP_TEXT:
3553 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3556 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3557 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3559 g_value_take_string (value, text);
3562 case PROP_TOOLTIP_MARKUP:
3563 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3566 g_value_set_object (value, gtk_widget_get_window (widget));
3568 case PROP_DOUBLE_BUFFERED:
3569 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3572 g_value_set_enum (value, gtk_widget_get_halign (widget));
3575 g_value_set_enum (value, gtk_widget_get_valign (widget));
3577 case PROP_MARGIN_LEFT:
3578 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3580 case PROP_MARGIN_RIGHT:
3581 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3583 case PROP_MARGIN_TOP:
3584 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3586 case PROP_MARGIN_BOTTOM:
3587 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3591 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3592 if (aux_info == NULL)
3594 g_value_set_int (value, 0);
3598 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3599 aux_info->margin.right),
3600 MAX (aux_info->margin.top,
3601 aux_info->margin.bottom)));
3606 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3608 case PROP_HEXPAND_SET:
3609 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3612 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3614 case PROP_VEXPAND_SET:
3615 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3618 g_value_set_boolean (value,
3619 gtk_widget_get_hexpand (widget) &&
3620 gtk_widget_get_vexpand (widget));
3623 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3629 gtk_widget_init (GtkWidget *widget)
3631 GtkWidgetPrivate *priv;
3633 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3636 priv = widget->priv;
3638 priv->child_visible = TRUE;
3640 priv->allocation.x = -1;
3641 priv->allocation.y = -1;
3642 priv->allocation.width = 1;
3643 priv->allocation.height = 1;
3644 priv->window = NULL;
3645 priv->parent = NULL;
3647 priv->sensitive = TRUE;
3648 priv->composite_child = composite_child_stack != 0;
3649 priv->double_buffered = TRUE;
3650 priv->redraw_on_alloc = TRUE;
3651 priv->width_request_needed = TRUE;
3652 priv->height_request_needed = TRUE;
3653 priv->alloc_needed = TRUE;
3655 /* this will be set to TRUE if the widget gets a child or if the
3656 * expand flag is set on the widget, but until one of those happen
3657 * we know the expand is already properly FALSE.
3659 * We really want to default FALSE here to avoid computing expand
3660 * all over the place while initially building a widget tree.
3662 priv->need_compute_expand = FALSE;
3664 priv->style = gtk_widget_get_default_style ();
3665 g_object_ref (priv->style);
3670 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3672 GParamSpec **pspecs)
3674 GtkWidgetPrivate *priv = widget->priv;
3675 GtkWidget *container = priv->parent;
3678 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3679 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3683 * gtk_widget_freeze_child_notify:
3684 * @widget: a #GtkWidget
3686 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3687 * signals are queued until gtk_widget_thaw_child_notify() is called
3690 * This is the analogue of g_object_freeze_notify() for child properties.
3693 gtk_widget_freeze_child_notify (GtkWidget *widget)
3695 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 if (!G_OBJECT (widget)->ref_count)
3700 g_object_ref (widget);
3701 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3702 g_object_unref (widget);
3706 * gtk_widget_child_notify:
3707 * @widget: a #GtkWidget
3708 * @child_property: the name of a child property installed on the
3709 * class of @widget<!-- -->'s parent
3711 * Emits a #GtkWidget::child-notify signal for the
3712 * <link linkend="child-properties">child property</link> @child_property
3715 * This is the analogue of g_object_notify() for child properties.
3717 * Also see gtk_container_child_notify().
3720 gtk_widget_child_notify (GtkWidget *widget,
3721 const gchar *child_property)
3723 if (widget->priv->parent == NULL)
3726 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3730 * gtk_widget_thaw_child_notify:
3731 * @widget: a #GtkWidget
3733 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3734 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3738 gtk_widget_thaw_child_notify (GtkWidget *widget)
3740 GObjectNotifyQueue *nqueue;
3742 g_return_if_fail (GTK_IS_WIDGET (widget));
3744 if (!G_OBJECT (widget)->ref_count)
3747 g_object_ref (widget);
3748 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3749 if (!nqueue || !nqueue->freeze_count)
3750 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3751 G_OBJECT_TYPE_NAME (widget), widget);
3753 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3754 g_object_unref (widget);
3760 * @type: type ID of the widget to create
3761 * @first_property_name: name of first property to set
3762 * @...: value of first property, followed by more properties,
3765 * This is a convenience function for creating a widget and setting
3766 * its properties in one go. For example you might write:
3767 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3768 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3769 * g_object_new(), but returns a widget so you don't have to
3770 * cast the object yourself.
3772 * Return value: a new #GtkWidget of type @widget_type
3775 gtk_widget_new (GType type,
3776 const gchar *first_property_name,
3782 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3784 va_start (var_args, first_property_name);
3785 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3792 gtk_widget_queue_draw_child (GtkWidget *widget)
3794 GtkWidgetPrivate *priv = widget->priv;
3797 parent = priv->parent;
3798 if (parent && gtk_widget_is_drawable (parent))
3799 gtk_widget_queue_draw_area (parent,
3802 priv->allocation.width,
3803 priv->allocation.height);
3807 * gtk_widget_unparent:
3808 * @widget: a #GtkWidget
3810 * This function is only for use in widget implementations.
3811 * Should be called by implementations of the remove method
3812 * on #GtkContainer, to dissociate a child from the container.
3815 gtk_widget_unparent (GtkWidget *widget)
3817 GtkWidgetPrivate *priv;
3818 GObjectNotifyQueue *nqueue;
3819 GtkWidget *toplevel;
3820 GtkWidget *old_parent;
3822 g_return_if_fail (GTK_IS_WIDGET (widget));
3824 priv = widget->priv;
3826 if (priv->parent == NULL)
3829 /* keep this function in sync with gtk_menu_detach() */
3831 gtk_widget_push_verify_invariants (widget);
3833 g_object_freeze_notify (G_OBJECT (widget));
3834 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3836 toplevel = gtk_widget_get_toplevel (widget);
3837 if (gtk_widget_is_toplevel (toplevel))
3838 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3840 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3841 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3843 gtk_widget_queue_draw_child (widget);
3845 /* Reset the width and height here, to force reallocation if we
3846 * get added back to a new parent. This won't work if our new
3847 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3848 * (would 0x0 be OK here?)
3850 priv->allocation.width = 1;
3851 priv->allocation.height = 1;
3853 if (gtk_widget_get_realized (widget))
3855 if (priv->in_reparent)
3856 gtk_widget_unmap (widget);
3858 gtk_widget_unrealize (widget);
3861 /* If we are unanchoring the child, we save around the toplevel
3862 * to emit hierarchy changed
3864 if (priv->parent->priv->anchored)
3865 g_object_ref (toplevel);
3869 /* Removing a widget from a container restores the child visible
3870 * flag to the default state, so it doesn't affect the child
3871 * in the next parent.
3873 priv->child_visible = TRUE;
3875 old_parent = priv->parent;
3876 priv->parent = NULL;
3878 /* parent may no longer expand if the removed
3879 * child was expand=TRUE and could therefore
3882 if (gtk_widget_get_visible (widget) &&
3883 (priv->need_compute_expand ||
3884 priv->computed_hexpand ||
3885 priv->computed_vexpand))
3887 gtk_widget_queue_compute_expand (old_parent);
3890 /* Unset BACKDROP since we are no longer inside a toplevel window */
3891 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3893 gtk_style_context_set_parent (priv->context, NULL);
3895 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3898 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3899 g_object_unref (toplevel);
3902 /* Now that the parent pointer is nullified and the hierarchy-changed
3903 * already passed, go ahead and unset the parent window, if we are unparenting
3904 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3905 * will fire again for the new subhierarchy.
3907 gtk_widget_set_parent_window (widget, NULL);
3909 g_object_notify (G_OBJECT (widget), "parent");
3910 g_object_thaw_notify (G_OBJECT (widget));
3912 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3913 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3915 gtk_widget_pop_verify_invariants (widget);
3916 g_object_unref (widget);
3920 * gtk_widget_destroy:
3921 * @widget: a #GtkWidget
3923 * Destroys a widget.
3926 * destroyed, it will break any references it holds to other objects.
3927 * If the widget is inside a container, the widget will be removed
3928 * from the container. If the widget is a toplevel (derived from
3929 * #GtkWindow), it will be removed from the list of toplevels, and the
3930 * reference GTK+ holds to it will be removed. Removing a
3931 * widget from its container or the list of toplevels results in the
3932 * widget being finalized, unless you've added additional references
3933 * to the widget with g_object_ref().
3935 * In most cases, only toplevel widgets (windows) require explicit
3936 * destruction, because when you destroy a toplevel its children will
3937 * be destroyed as well.
3940 gtk_widget_destroy (GtkWidget *widget)
3942 g_return_if_fail (GTK_IS_WIDGET (widget));
3944 if (!widget->priv->in_destruction)
3945 g_object_run_dispose (G_OBJECT (widget));
3949 * gtk_widget_destroyed:
3950 * @widget: a #GtkWidget
3951 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3953 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3954 * %NULL. It's intended to be used as a callback connected to the
3955 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3956 * as a signal handler, and pass the address of your widget variable
3957 * as user data. Then when the widget is destroyed, the variable will
3958 * be set to %NULL. Useful for example to avoid multiple copies
3959 * of the same dialog.
3962 gtk_widget_destroyed (GtkWidget *widget,
3963 GtkWidget **widget_pointer)
3965 /* Don't make any assumptions about the
3967 * Even check widget_pointer.
3970 *widget_pointer = NULL;
3975 * @widget: a #GtkWidget
3977 * Flags a widget to be displayed. Any widget that isn't shown will
3978 * not appear on the screen. If you want to show all the widgets in a
3979 * container, it's easier to call gtk_widget_show_all() on the
3980 * container, instead of individually showing the widgets.
3982 * Remember that you have to show the containers containing a widget,
3983 * in addition to the widget itself, before it will appear onscreen.
3985 * When a toplevel container is shown, it is immediately realized and
3986 * mapped; other shown widgets are realized and mapped when their
3987 * toplevel container is realized and mapped.
3990 gtk_widget_show (GtkWidget *widget)
3992 g_return_if_fail (GTK_IS_WIDGET (widget));
3994 if (!gtk_widget_get_visible (widget))
3996 g_object_ref (widget);
3997 gtk_widget_push_verify_invariants (widget);
3999 if (!gtk_widget_is_toplevel (widget))
4000 gtk_widget_queue_resize (widget);
4002 /* see comment in set_parent() for why this should and can be
4005 if (widget->priv->need_compute_expand ||
4006 widget->priv->computed_hexpand ||
4007 widget->priv->computed_vexpand)
4009 if (widget->priv->parent != NULL)
4010 gtk_widget_queue_compute_expand (widget->priv->parent);
4013 g_signal_emit (widget, widget_signals[SHOW], 0);
4014 g_object_notify (G_OBJECT (widget), "visible");
4016 gtk_widget_pop_verify_invariants (widget);
4017 g_object_unref (widget);
4022 gtk_widget_real_show (GtkWidget *widget)
4024 GtkWidgetPrivate *priv = widget->priv;
4026 if (!gtk_widget_get_visible (widget))
4028 priv->visible = TRUE;
4031 gtk_widget_get_mapped (priv->parent) &&
4032 gtk_widget_get_child_visible (widget) &&
4033 !gtk_widget_get_mapped (widget))
4034 gtk_widget_map (widget);
4039 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4042 g_signal_handlers_disconnect_by_func (widget,
4043 gtk_widget_show_map_callback,
4048 * gtk_widget_show_now:
4049 * @widget: a #GtkWidget
4051 * Shows a widget. If the widget is an unmapped toplevel widget
4052 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4053 * loop and wait for the window to actually be mapped. Be careful;
4054 * because the main loop is running, anything can happen during
4058 gtk_widget_show_now (GtkWidget *widget)
4062 g_return_if_fail (GTK_IS_WIDGET (widget));
4064 /* make sure we will get event */
4065 if (!gtk_widget_get_mapped (widget) &&
4066 gtk_widget_is_toplevel (widget))
4068 gtk_widget_show (widget);
4070 g_signal_connect (widget, "map-event",
4071 G_CALLBACK (gtk_widget_show_map_callback),
4075 gtk_main_iteration ();
4078 gtk_widget_show (widget);
4083 * @widget: a #GtkWidget
4085 * Reverses the effects of gtk_widget_show(), causing the widget to be
4086 * hidden (invisible to the user).
4089 gtk_widget_hide (GtkWidget *widget)
4091 g_return_if_fail (GTK_IS_WIDGET (widget));
4093 if (gtk_widget_get_visible (widget))
4095 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4097 g_object_ref (widget);
4098 gtk_widget_push_verify_invariants (widget);
4100 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4101 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4103 /* a parent may now be expand=FALSE since we're hidden. */
4104 if (widget->priv->need_compute_expand ||
4105 widget->priv->computed_hexpand ||
4106 widget->priv->computed_vexpand)
4108 gtk_widget_queue_compute_expand (widget);
4111 g_signal_emit (widget, widget_signals[HIDE], 0);
4112 if (!gtk_widget_is_toplevel (widget))
4113 gtk_widget_queue_resize (widget);
4114 g_object_notify (G_OBJECT (widget), "visible");
4116 gtk_widget_pop_verify_invariants (widget);
4117 g_object_unref (widget);
4122 gtk_widget_real_hide (GtkWidget *widget)
4124 if (gtk_widget_get_visible (widget))
4126 widget->priv->visible = FALSE;
4128 if (gtk_widget_get_mapped (widget))
4129 gtk_widget_unmap (widget);
4134 * gtk_widget_hide_on_delete:
4135 * @widget: a #GtkWidget
4137 * Utility function; intended to be connected to the #GtkWidget::delete-event
4138 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4139 * argument, then returns %TRUE. If connected to ::delete-event, the
4140 * result is that clicking the close button for a window (on the
4141 * window frame, top right corner usually) will hide but not destroy
4142 * the window. By default, GTK+ destroys windows when ::delete-event
4145 * Return value: %TRUE
4148 gtk_widget_hide_on_delete (GtkWidget *widget)
4150 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4152 gtk_widget_hide (widget);
4158 * gtk_widget_show_all:
4159 * @widget: a #GtkWidget
4161 * Recursively shows a widget, and any child widgets (if the widget is
4165 gtk_widget_show_all (GtkWidget *widget)
4167 GtkWidgetClass *class;
4169 g_return_if_fail (GTK_IS_WIDGET (widget));
4171 if (gtk_widget_get_no_show_all (widget))
4174 class = GTK_WIDGET_GET_CLASS (widget);
4176 if (class->show_all)
4177 class->show_all (widget);
4181 _gtk_widget_notify_state_change (GtkWidget *widget,
4189 case GTK_STATE_FLAG_ACTIVE:
4190 state = GTK_STATE_ACTIVE;
4192 case GTK_STATE_FLAG_PRELIGHT:
4193 state = GTK_STATE_PRELIGHT;
4195 case GTK_STATE_FLAG_SELECTED:
4196 state = GTK_STATE_SELECTED;
4198 case GTK_STATE_FLAG_INSENSITIVE:
4199 state = GTK_STATE_INSENSITIVE;
4201 case GTK_STATE_FLAG_INCONSISTENT:
4202 state = GTK_STATE_INCONSISTENT;
4204 case GTK_STATE_FLAG_FOCUSED:
4205 state = GTK_STATE_FOCUSED;
4211 gtk_style_context_notify_state_change (widget->priv->context,
4212 gtk_widget_get_window (widget),
4213 NULL, state, target);
4216 /* Initializes state transitions for those states that
4217 * were enabled before mapping and have a looping animation.
4220 _gtk_widget_start_state_transitions (GtkWidget *widget)
4222 GtkStateFlags state, flag;
4224 if (!widget->priv->context)
4227 state = gtk_widget_get_state_flags (widget);
4228 flag = GTK_STATE_FLAG_FOCUSED;
4232 GtkAnimationDescription *animation_desc;
4234 if ((state & flag) == 0)
4240 gtk_style_context_get (widget->priv->context, state,
4241 "transition", &animation_desc,
4246 if (_gtk_animation_description_get_loop (animation_desc))
4247 _gtk_widget_notify_state_change (widget, flag, TRUE);
4249 _gtk_animation_description_unref (animation_desc);
4258 * @widget: a #GtkWidget
4260 * This function is only for use in widget implementations. Causes
4261 * a widget to be mapped if it isn't already.
4264 gtk_widget_map (GtkWidget *widget)
4266 GtkWidgetPrivate *priv;
4268 g_return_if_fail (GTK_IS_WIDGET (widget));
4269 g_return_if_fail (gtk_widget_get_visible (widget));
4270 g_return_if_fail (gtk_widget_get_child_visible (widget));
4272 priv = widget->priv;
4274 if (!gtk_widget_get_mapped (widget))
4276 gtk_widget_push_verify_invariants (widget);
4278 if (!gtk_widget_get_realized (widget))
4279 gtk_widget_realize (widget);
4281 g_signal_emit (widget, widget_signals[MAP], 0);
4283 if (!gtk_widget_get_has_window (widget))
4284 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4286 gtk_widget_pop_verify_invariants (widget);
4288 _gtk_widget_start_state_transitions (widget);
4294 * @widget: a #GtkWidget
4296 * This function is only for use in widget implementations. Causes
4297 * a widget to be unmapped if it's currently mapped.
4300 gtk_widget_unmap (GtkWidget *widget)
4302 GtkWidgetPrivate *priv;
4304 g_return_if_fail (GTK_IS_WIDGET (widget));
4306 priv = widget->priv;
4308 if (gtk_widget_get_mapped (widget))
4310 gtk_widget_push_verify_invariants (widget);
4312 if (!gtk_widget_get_has_window (widget))
4313 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4314 _gtk_tooltip_hide (widget);
4315 g_signal_emit (widget, widget_signals[UNMAP], 0);
4317 gtk_widget_pop_verify_invariants (widget);
4320 gtk_style_context_cancel_animations (priv->context, NULL);
4322 /* Unset pointer/window info */
4323 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4328 _gtk_widget_enable_device_events (GtkWidget *widget)
4330 GHashTable *device_events;
4331 GHashTableIter iter;
4332 gpointer key, value;
4334 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4339 g_hash_table_iter_init (&iter, device_events);
4341 while (g_hash_table_iter_next (&iter, &key, &value))
4344 GdkEventMask event_mask;
4347 event_mask = GPOINTER_TO_UINT (value);
4348 gtk_widget_add_events_internal (widget, device, event_mask);
4353 get_widget_windows (GtkWidget *widget)
4355 GList *window_list, *last, *l, *children, *ret;
4357 if (gtk_widget_get_has_window (widget))
4358 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4360 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4362 last = g_list_last (window_list);
4365 for (l = window_list; l; l = l->next)
4367 GtkWidget *window_widget = NULL;
4369 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4371 if (widget != window_widget)
4374 ret = g_list_prepend (ret, l->data);
4375 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4379 last = g_list_concat (last, children);
4380 last = g_list_last (last);
4384 g_list_free (window_list);
4390 device_enable_foreach (GtkWidget *widget,
4393 GdkDevice *device = user_data;
4394 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4398 device_disable_foreach (GtkWidget *widget,
4401 GdkDevice *device = user_data;
4402 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4406 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4411 GList *window_list, *l;
4413 window_list = get_widget_windows (widget);
4415 for (l = window_list; l; l = l->next)
4417 GdkEventMask events = 0;
4423 events = gdk_window_get_events (window);
4425 gdk_window_set_device_events (window, device, events);
4428 if (recurse && GTK_IS_CONTAINER (widget))
4431 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4433 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4436 g_list_free (window_list);
4440 gtk_widget_update_devices_mask (GtkWidget *widget,
4443 GList *enabled_devices, *l;
4445 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4447 for (l = enabled_devices; l; l = l->next)
4448 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4452 * gtk_widget_realize:
4453 * @widget: a #GtkWidget
4455 * Creates the GDK (windowing system) resources associated with a
4456 * widget. For example, @widget->window will be created when a widget
4457 * is realized. Normally realization happens implicitly; if you show
4458 * a widget and all its parent containers, then the widget will be
4459 * realized and mapped automatically.
4461 * Realizing a widget requires all
4462 * the widget's parent widgets to be realized; calling
4463 * gtk_widget_realize() realizes the widget's parents in addition to
4464 * @widget itself. If a widget is not yet inside a toplevel window
4465 * when you realize it, bad things will happen.
4467 * This function is primarily used in widget implementations, and
4468 * isn't very useful otherwise. Many times when you think you might
4469 * need it, a better approach is to connect to a signal that will be
4470 * called after the widget is realized automatically, such as
4471 * #GtkWidget::draw. Or simply g_signal_connect () to the
4472 * #GtkWidget::realize signal.
4475 gtk_widget_realize (GtkWidget *widget)
4477 GtkWidgetPrivate *priv;
4478 cairo_region_t *region;
4480 g_return_if_fail (GTK_IS_WIDGET (widget));
4481 g_return_if_fail (widget->priv->anchored ||
4482 GTK_IS_INVISIBLE (widget));
4484 priv = widget->priv;
4486 if (!gtk_widget_get_realized (widget))
4488 gtk_widget_push_verify_invariants (widget);
4491 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4492 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4495 if (priv->parent == NULL &&
4496 !gtk_widget_is_toplevel (widget))
4497 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4498 "inside a toplevel window is not going to work very well. "
4499 "Widgets must be inside a toplevel container before realizing them.");
4501 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4502 gtk_widget_realize (priv->parent);
4504 gtk_widget_ensure_style (widget);
4506 if (priv->style_update_pending)
4507 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4509 g_signal_emit (widget, widget_signals[REALIZE], 0);
4511 gtk_widget_real_set_has_tooltip (widget,
4512 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4515 if (priv->has_shape_mask)
4517 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4518 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4521 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4523 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4525 if (priv->multidevice)
4526 gdk_window_set_support_multidevice (priv->window, TRUE);
4528 _gtk_widget_enable_device_events (widget);
4529 gtk_widget_update_devices_mask (widget, TRUE);
4531 gtk_widget_pop_verify_invariants (widget);
4536 * gtk_widget_unrealize:
4537 * @widget: a #GtkWidget
4539 * This function is only useful in widget implementations.
4540 * Causes a widget to be unrealized (frees all GDK resources
4541 * associated with the widget, such as @widget->window).
4544 gtk_widget_unrealize (GtkWidget *widget)
4546 g_return_if_fail (GTK_IS_WIDGET (widget));
4548 gtk_widget_push_verify_invariants (widget);
4550 if (widget->priv->has_shape_mask)
4551 gtk_widget_shape_combine_region (widget, NULL);
4553 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4554 gtk_widget_input_shape_combine_region (widget, NULL);
4556 if (gtk_widget_get_realized (widget))
4558 g_object_ref (widget);
4560 if (widget->priv->mapped)
4561 gtk_widget_unmap (widget);
4563 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4564 g_assert (!widget->priv->mapped);
4565 gtk_widget_set_realized (widget, FALSE);
4567 g_object_unref (widget);
4570 gtk_widget_pop_verify_invariants (widget);
4573 /*****************************************
4575 *****************************************/
4578 * gtk_widget_queue_draw_region:
4579 * @widget: a #GtkWidget
4580 * @region: region to draw
4582 * Invalidates the rectangular area of @widget defined by @region by
4583 * calling gdk_window_invalidate_region() on the widget's window and
4584 * all its child windows. Once the main loop becomes idle (after the
4585 * current batch of events has been processed, roughly), the window
4586 * will receive expose events for the union of all regions that have
4589 * Normally you would only use this function in widget
4590 * implementations. You might also use it to schedule a redraw of a
4591 * #GtkDrawingArea or some portion thereof.
4596 gtk_widget_queue_draw_region (GtkWidget *widget,
4597 const cairo_region_t *region)
4599 GtkWidgetPrivate *priv;
4602 g_return_if_fail (GTK_IS_WIDGET (widget));
4604 priv = widget->priv;
4606 if (!gtk_widget_get_realized (widget))
4609 /* Just return if the widget or one of its ancestors isn't mapped */
4610 for (w = widget; w != NULL; w = w->priv->parent)
4611 if (!gtk_widget_get_mapped (w))
4614 gdk_window_invalidate_region (priv->window, region, TRUE);
4618 * gtk_widget_queue_draw_area:
4619 * @widget: a #GtkWidget
4620 * @x: x coordinate of upper-left corner of rectangle to redraw
4621 * @y: y coordinate of upper-left corner of rectangle to redraw
4622 * @width: width of region to draw
4623 * @height: height of region to draw
4625 * Convenience function that calls gtk_widget_queue_draw_region() on
4626 * the region created from the given coordinates.
4628 * The region here is specified in widget coordinates.
4629 * Widget coordinates are a bit odd; for historical reasons, they are
4630 * defined as @widget->window coordinates for widgets that are not
4631 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4632 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4635 gtk_widget_queue_draw_area (GtkWidget *widget,
4642 cairo_region_t *region;
4644 g_return_if_fail (GTK_IS_WIDGET (widget));
4649 rect.height = height;
4651 region = cairo_region_create_rectangle (&rect);
4652 gtk_widget_queue_draw_region (widget, region);
4653 cairo_region_destroy (region);
4657 * gtk_widget_queue_draw:
4658 * @widget: a #GtkWidget
4660 * Equivalent to calling gtk_widget_queue_draw_area() for the
4661 * entire area of a widget.
4664 gtk_widget_queue_draw (GtkWidget *widget)
4668 g_return_if_fail (GTK_IS_WIDGET (widget));
4670 gtk_widget_get_allocation (widget, &rect);
4672 if (!gtk_widget_get_has_window (widget))
4673 gtk_widget_queue_draw_area (widget,
4674 rect.x, rect.y, rect.width, rect.height);
4676 gtk_widget_queue_draw_area (widget,
4677 0, 0, rect.width, rect.height);
4681 * gtk_widget_queue_resize:
4682 * @widget: a #GtkWidget
4684 * This function is only for use in widget implementations.
4685 * Flags a widget to have its size renegotiated; should
4686 * be called when a widget for some reason has a new size request.
4687 * For example, when you change the text in a #GtkLabel, #GtkLabel
4688 * queues a resize to ensure there's enough space for the new text.
4690 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4691 * from inside its implementation of the GtkWidgetClass::size_allocate
4692 * virtual method. Calls to gtk_widget_queue_resize() from inside
4693 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4696 gtk_widget_queue_resize (GtkWidget *widget)
4698 g_return_if_fail (GTK_IS_WIDGET (widget));
4700 if (gtk_widget_get_realized (widget))
4701 gtk_widget_queue_shallow_draw (widget);
4703 _gtk_size_group_queue_resize (widget, 0);
4707 * gtk_widget_queue_resize_no_redraw:
4708 * @widget: a #GtkWidget
4710 * This function works like gtk_widget_queue_resize(),
4711 * except that the widget is not invalidated.
4716 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4718 g_return_if_fail (GTK_IS_WIDGET (widget));
4720 _gtk_size_group_queue_resize (widget, 0);
4724 * gtk_widget_size_request:
4725 * @widget: a #GtkWidget
4726 * @requisition: (out): a #GtkRequisition to be filled in
4728 * This function is typically used when implementing a #GtkContainer
4729 * subclass. Obtains the preferred size of a widget. The container
4730 * uses this information to arrange its child widgets and decide what
4731 * size allocations to give them with gtk_widget_size_allocate().
4733 * You can also call this function from an application, with some
4734 * caveats. Most notably, getting a size request requires the widget
4735 * to be associated with a screen, because font information may be
4736 * needed. Multihead-aware applications should keep this in mind.
4738 * Also remember that the size request is not necessarily the size
4739 * a widget will actually be allocated.
4741 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4744 gtk_widget_size_request (GtkWidget *widget,
4745 GtkRequisition *requisition)
4747 g_return_if_fail (GTK_IS_WIDGET (widget));
4749 gtk_widget_get_preferred_size (widget, requisition, NULL);
4753 * gtk_widget_get_child_requisition:
4754 * @widget: a #GtkWidget
4755 * @requisition: (out): a #GtkRequisition to be filled in
4757 * This function is only for use in widget implementations. Obtains
4758 * @widget->requisition, unless someone has forced a particular
4759 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4760 * in which case it returns that geometry instead of the widget's
4763 * This function differs from gtk_widget_size_request() in that
4764 * it retrieves the last size request value from @widget->requisition,
4765 * while gtk_widget_size_request() actually calls the "size_request" method
4766 * on @widget to compute the size request and fill in @widget->requisition,
4767 * and only then returns @widget->requisition.
4769 * Because this function does not call the "size_request" method, it
4770 * can only be used when you know that @widget->requisition is
4771 * up-to-date, that is, gtk_widget_size_request() has been called
4772 * since the last time a resize was queued. In general, only container
4773 * implementations have this information; applications should use
4774 * gtk_widget_size_request().
4777 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4780 gtk_widget_get_child_requisition (GtkWidget *widget,
4781 GtkRequisition *requisition)
4783 gtk_widget_get_preferred_size (widget, requisition, NULL);
4787 invalidate_predicate (GdkWindow *window,
4792 gdk_window_get_user_data (window, &user_data);
4794 return (user_data == data);
4797 /* Invalidate @region in widget->window and all children
4798 * of widget->window owned by widget. @region is in the
4799 * same coordinates as widget->allocation and will be
4800 * modified by this call.
4803 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4804 cairo_region_t *region)
4806 GtkWidgetPrivate *priv = widget->priv;
4808 if (!gtk_widget_get_realized (widget))
4811 if (gtk_widget_get_has_window (widget) && priv->parent)
4815 gdk_window_get_position (priv->window, &x, &y);
4816 cairo_region_translate (region, -x, -y);
4819 gdk_window_invalidate_maybe_recurse (priv->window, region,
4820 invalidate_predicate, widget);
4824 * gtk_widget_queue_shallow_draw:
4825 * @widget: a #GtkWidget
4827 * Like gtk_widget_queue_draw(), but only windows owned
4828 * by @widget are invalidated.
4831 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4834 cairo_region_t *region;
4836 if (!gtk_widget_get_realized (widget))
4839 gtk_widget_get_allocation (widget, &rect);
4841 region = cairo_region_create_rectangle (&rect);
4842 gtk_widget_invalidate_widget_windows (widget, region);
4843 cairo_region_destroy (region);
4847 * gtk_widget_size_allocate:
4848 * @widget: a #GtkWidget
4849 * @allocation: position and size to be allocated to @widget
4851 * This function is only used by #GtkContainer subclasses, to assign a size
4852 * and position to their child widgets.
4854 * In this function, the allocation may be adjusted. It will be forced
4855 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4856 * method on the child will be used to adjust the allocation. Standard
4857 * adjustments include removing the widget's margins, and applying the
4858 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4861 gtk_widget_size_allocate (GtkWidget *widget,
4862 GtkAllocation *allocation)
4864 GtkWidgetPrivate *priv;
4865 GdkRectangle real_allocation;
4866 GdkRectangle old_allocation;
4867 GdkRectangle adjusted_allocation;
4868 gboolean alloc_needed;
4869 gboolean size_changed;
4870 gboolean position_changed;
4871 gint natural_width, natural_height, dummy;
4872 gint min_width, min_height;
4874 priv = widget->priv;
4876 g_return_if_fail (GTK_IS_WIDGET (widget));
4878 gtk_widget_push_verify_invariants (widget);
4880 #ifdef G_ENABLE_DEBUG
4881 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4892 parent = gtk_widget_get_parent (parent);
4895 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4896 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4897 2 * depth, " ", name,
4898 allocation->width, allocation->height);
4900 #endif /* G_ENABLE_DEBUG */
4902 alloc_needed = priv->alloc_needed;
4903 if (!priv->width_request_needed && !priv->height_request_needed)
4904 /* Preserve request/allocate ordering */
4905 priv->alloc_needed = FALSE;
4907 old_allocation = priv->allocation;
4908 real_allocation = *allocation;
4910 adjusted_allocation = real_allocation;
4911 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4913 /* Go ahead and request the height for allocated width, note that the internals
4914 * of get_height_for_width will internally limit the for_size to natural size
4915 * when aligning implicitly.
4917 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4918 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4922 /* Go ahead and request the width for allocated height, note that the internals
4923 * of get_width_for_height will internally limit the for_size to natural size
4924 * when aligning implicitly.
4926 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4927 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4930 #ifdef G_ENABLE_DEBUG
4931 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4933 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4934 !GTK_IS_SCROLLABLE (widget))
4935 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4936 "Allocation is %dx%d, but minimum required size is %dx%d.",
4937 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4938 G_OBJECT_TYPE_NAME (widget), widget,
4939 real_allocation.width, real_allocation.height,
4940 min_width, min_height);
4943 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4944 * allocated sizes and possibly limit them to the natural sizes */
4945 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4946 GTK_ORIENTATION_HORIZONTAL,
4949 &adjusted_allocation.x,
4950 &adjusted_allocation.width);
4951 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4952 GTK_ORIENTATION_VERTICAL,
4955 &adjusted_allocation.y,
4956 &adjusted_allocation.height);
4958 if (adjusted_allocation.x < real_allocation.x ||
4959 adjusted_allocation.y < real_allocation.y ||
4960 (adjusted_allocation.x + adjusted_allocation.width) >
4961 (real_allocation.x + real_allocation.width) ||
4962 (adjusted_allocation.y + adjusted_allocation.height >
4963 real_allocation.y + real_allocation.height))
4965 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",
4966 G_OBJECT_TYPE_NAME (widget), widget,
4967 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4968 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4969 adjusted_allocation = real_allocation; /* veto it */
4973 real_allocation = adjusted_allocation;
4976 if (real_allocation.width < 0 || real_allocation.height < 0)
4978 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4979 real_allocation.width,
4980 real_allocation.height);
4983 real_allocation.width = MAX (real_allocation.width, 1);
4984 real_allocation.height = MAX (real_allocation.height, 1);
4986 size_changed = (old_allocation.width != real_allocation.width ||
4987 old_allocation.height != real_allocation.height);
4988 position_changed = (old_allocation.x != real_allocation.x ||
4989 old_allocation.y != real_allocation.y);
4991 if (!alloc_needed && !size_changed && !position_changed)
4994 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4996 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4997 priv->width_request_needed = FALSE;
4998 priv->height_request_needed = FALSE;
4999 priv->alloc_needed = FALSE;
5001 if (gtk_widget_get_mapped (widget))
5003 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5005 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5007 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5008 cairo_region_union_rectangle (invalidate, &old_allocation);
5010 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5011 cairo_region_destroy (invalidate);
5016 if (priv->redraw_on_alloc)
5018 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5020 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5021 cairo_region_union_rectangle (invalidate, &old_allocation);
5023 gtk_widget_invalidate_widget_windows (widget, invalidate);
5024 cairo_region_destroy (invalidate);
5028 if (size_changed || position_changed)
5030 GtkStyleContext *context;
5032 context = gtk_widget_get_style_context (widget);
5033 _gtk_style_context_invalidate_animation_areas (context);
5037 if ((size_changed || position_changed) && priv->parent &&
5038 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5040 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5041 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5042 cairo_region_destroy (invalidate);
5046 gtk_widget_pop_verify_invariants (widget);
5050 * gtk_widget_common_ancestor:
5051 * @widget_a: a #GtkWidget
5052 * @widget_b: a #GtkWidget
5054 * Find the common ancestor of @widget_a and @widget_b that
5055 * is closest to the two widgets.
5057 * Return value: the closest common ancestor of @widget_a and
5058 * @widget_b or %NULL if @widget_a and @widget_b do not
5059 * share a common ancestor.
5062 gtk_widget_common_ancestor (GtkWidget *widget_a,
5063 GtkWidget *widget_b)
5065 GtkWidget *parent_a;
5066 GtkWidget *parent_b;
5070 parent_a = widget_a;
5071 while (parent_a->priv->parent)
5073 parent_a = parent_a->priv->parent;
5077 parent_b = widget_b;
5078 while (parent_b->priv->parent)
5080 parent_b = parent_b->priv->parent;
5084 if (parent_a != parent_b)
5087 while (depth_a > depth_b)
5089 widget_a = widget_a->priv->parent;
5093 while (depth_b > depth_a)
5095 widget_b = widget_b->priv->parent;
5099 while (widget_a != widget_b)
5101 widget_a = widget_a->priv->parent;
5102 widget_b = widget_b->priv->parent;
5109 * gtk_widget_translate_coordinates:
5110 * @src_widget: a #GtkWidget
5111 * @dest_widget: a #GtkWidget
5112 * @src_x: X position relative to @src_widget
5113 * @src_y: Y position relative to @src_widget
5114 * @dest_x: (out): location to store X position relative to @dest_widget
5115 * @dest_y: (out): location to store Y position relative to @dest_widget
5117 * Translate coordinates relative to @src_widget's allocation to coordinates
5118 * relative to @dest_widget's allocations. In order to perform this
5119 * operation, both widgets must be realized, and must share a common
5122 * Return value: %FALSE if either widget was not realized, or there
5123 * was no common ancestor. In this case, nothing is stored in
5124 * *@dest_x and *@dest_y. Otherwise %TRUE.
5127 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5128 GtkWidget *dest_widget,
5134 GtkWidgetPrivate *src_priv = src_widget->priv;
5135 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5136 GtkWidget *ancestor;
5138 GList *dest_list = NULL;
5140 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5141 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5143 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5144 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5147 /* Translate from allocation relative to window relative */
5148 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5151 gdk_window_get_position (src_priv->window, &wx, &wy);
5153 src_x -= wx - src_priv->allocation.x;
5154 src_y -= wy - src_priv->allocation.y;
5158 src_x += src_priv->allocation.x;
5159 src_y += src_priv->allocation.y;
5162 /* Translate to the common ancestor */
5163 window = src_priv->window;
5164 while (window != ancestor->priv->window)
5168 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5173 window = gdk_window_get_effective_parent (window);
5175 if (!window) /* Handle GtkHandleBox */
5180 window = dest_priv->window;
5181 while (window != ancestor->priv->window)
5183 dest_list = g_list_prepend (dest_list, window);
5185 window = gdk_window_get_effective_parent (window);
5187 if (!window) /* Handle GtkHandleBox */
5189 g_list_free (dest_list);
5198 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5203 dest_list = g_list_remove (dest_list, dest_list->data);
5206 /* Translate from window relative to allocation relative */
5207 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5210 gdk_window_get_position (dest_priv->window, &wx, &wy);
5212 src_x += wx - dest_priv->allocation.x;
5213 src_y += wy - dest_priv->allocation.y;
5217 src_x -= dest_priv->allocation.x;
5218 src_y -= dest_priv->allocation.y;
5230 gtk_widget_real_size_allocate (GtkWidget *widget,
5231 GtkAllocation *allocation)
5233 GtkWidgetPrivate *priv = widget->priv;
5235 priv->allocation = *allocation;
5237 if (gtk_widget_get_realized (widget) &&
5238 gtk_widget_get_has_window (widget))
5240 gdk_window_move_resize (priv->window,
5241 allocation->x, allocation->y,
5242 allocation->width, allocation->height);
5246 /* translate initial/final into start/end */
5248 effective_align (GtkAlign align,
5249 GtkTextDirection direction)
5253 case GTK_ALIGN_START:
5254 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5256 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5263 adjust_for_align (GtkAlign align,
5265 gint *allocated_pos,
5266 gint *allocated_size)
5270 case GTK_ALIGN_FILL:
5271 /* change nothing */
5273 case GTK_ALIGN_START:
5274 /* keep *allocated_pos where it is */
5275 *allocated_size = MIN (*allocated_size, *natural_size);
5278 if (*allocated_size > *natural_size)
5280 *allocated_pos += (*allocated_size - *natural_size);
5281 *allocated_size = *natural_size;
5284 case GTK_ALIGN_CENTER:
5285 if (*allocated_size > *natural_size)
5287 *allocated_pos += (*allocated_size - *natural_size) / 2;
5288 *allocated_size = MIN (*allocated_size, *natural_size);
5295 adjust_for_margin(gint start_margin,
5299 gint *allocated_pos,
5300 gint *allocated_size)
5302 *minimum_size -= (start_margin + end_margin);
5303 *natural_size -= (start_margin + end_margin);
5304 *allocated_pos += start_margin;
5305 *allocated_size -= (start_margin + end_margin);
5309 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5310 GtkOrientation orientation,
5313 gint *allocated_pos,
5314 gint *allocated_size)
5316 const GtkWidgetAuxInfo *aux_info;
5318 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5320 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5322 adjust_for_margin (aux_info->margin.left,
5323 aux_info->margin.right,
5324 minimum_size, natural_size,
5325 allocated_pos, allocated_size);
5326 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5327 natural_size, allocated_pos, allocated_size);
5331 adjust_for_margin (aux_info->margin.top,
5332 aux_info->margin.bottom,
5333 minimum_size, natural_size,
5334 allocated_pos, allocated_size);
5335 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5336 natural_size, allocated_pos, allocated_size);
5341 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5344 GtkWidgetPrivate *priv = widget->priv;
5346 /* widgets must be onscreen for accels to take effect */
5347 return gtk_widget_is_sensitive (widget) &&
5348 gtk_widget_is_drawable (widget) &&
5349 gdk_window_is_viewable (priv->window);
5353 * gtk_widget_can_activate_accel:
5354 * @widget: a #GtkWidget
5355 * @signal_id: the ID of a signal installed on @widget
5357 * Determines whether an accelerator that activates the signal
5358 * identified by @signal_id can currently be activated.
5359 * This is done by emitting the #GtkWidget::can-activate-accel
5360 * signal on @widget; if the signal isn't overridden by a
5361 * handler or in a derived widget, then the default check is
5362 * that the widget must be sensitive, and the widget and all
5363 * its ancestors mapped.
5365 * Return value: %TRUE if the accelerator can be activated.
5370 gtk_widget_can_activate_accel (GtkWidget *widget,
5373 gboolean can_activate = FALSE;
5374 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5375 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5376 return can_activate;
5385 closure_accel_activate (GClosure *closure,
5386 GValue *return_value,
5387 guint n_param_values,
5388 const GValue *param_values,
5389 gpointer invocation_hint,
5390 gpointer marshal_data)
5392 AccelClosure *aclosure = (AccelClosure*) closure;
5393 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5396 g_signal_emit (closure->data, aclosure->signal_id, 0);
5398 /* whether accelerator was handled */
5399 g_value_set_boolean (return_value, can_activate);
5403 closures_destroy (gpointer data)
5405 GSList *slist, *closures = data;
5407 for (slist = closures; slist; slist = slist->next)
5409 g_closure_invalidate (slist->data);
5410 g_closure_unref (slist->data);
5412 g_slist_free (closures);
5416 widget_new_accel_closure (GtkWidget *widget,
5419 AccelClosure *aclosure;
5420 GClosure *closure = NULL;
5421 GSList *slist, *closures;
5423 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5424 for (slist = closures; slist; slist = slist->next)
5425 if (!gtk_accel_group_from_accel_closure (slist->data))
5427 /* reuse this closure */
5428 closure = slist->data;
5433 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5434 closures = g_slist_prepend (closures, g_closure_ref (closure));
5435 g_closure_sink (closure);
5436 g_closure_set_marshal (closure, closure_accel_activate);
5438 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5440 aclosure = (AccelClosure*) closure;
5441 g_assert (closure->data == widget);
5442 g_assert (closure->marshal == closure_accel_activate);
5443 aclosure->signal_id = signal_id;
5449 * gtk_widget_add_accelerator:
5450 * @widget: widget to install an accelerator on
5451 * @accel_signal: widget signal to emit on accelerator activation
5452 * @accel_group: accel group for this widget, added to its toplevel
5453 * @accel_key: GDK keyval of the accelerator
5454 * @accel_mods: modifier key combination of the accelerator
5455 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5457 * Installs an accelerator for this @widget in @accel_group that causes
5458 * @accel_signal to be emitted if the accelerator is activated.
5459 * The @accel_group needs to be added to the widget's toplevel via
5460 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5461 * Accelerators added through this function are not user changeable during
5462 * runtime. If you want to support accelerators that can be changed by the
5463 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5464 * gtk_menu_item_set_accel_path() instead.
5467 gtk_widget_add_accelerator (GtkWidget *widget,
5468 const gchar *accel_signal,
5469 GtkAccelGroup *accel_group,
5471 GdkModifierType accel_mods,
5472 GtkAccelFlags accel_flags)
5477 g_return_if_fail (GTK_IS_WIDGET (widget));
5478 g_return_if_fail (accel_signal != NULL);
5479 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5481 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5482 if (!query.signal_id ||
5483 !(query.signal_flags & G_SIGNAL_ACTION) ||
5484 query.return_type != G_TYPE_NONE ||
5487 /* hmm, should be elaborate enough */
5488 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5489 G_OBJECT_TYPE_NAME (widget), accel_signal);
5493 closure = widget_new_accel_closure (widget, query.signal_id);
5495 g_object_ref (widget);
5497 /* install the accelerator. since we don't map this onto an accel_path,
5498 * the accelerator will automatically be locked.
5500 gtk_accel_group_connect (accel_group,
5503 accel_flags | GTK_ACCEL_LOCKED,
5506 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5508 g_object_unref (widget);
5512 * gtk_widget_remove_accelerator:
5513 * @widget: widget to install an accelerator on
5514 * @accel_group: accel group for this widget
5515 * @accel_key: GDK keyval of the accelerator
5516 * @accel_mods: modifier key combination of the accelerator
5518 * Removes an accelerator from @widget, previously installed with
5519 * gtk_widget_add_accelerator().
5521 * Returns: whether an accelerator was installed and could be removed
5524 gtk_widget_remove_accelerator (GtkWidget *widget,
5525 GtkAccelGroup *accel_group,
5527 GdkModifierType accel_mods)
5529 GtkAccelGroupEntry *ag_entry;
5530 GList *slist, *clist;
5533 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5534 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5536 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5537 clist = gtk_widget_list_accel_closures (widget);
5538 for (slist = clist; slist; slist = slist->next)
5542 for (i = 0; i < n; i++)
5543 if (slist->data == (gpointer) ag_entry[i].closure)
5545 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5547 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5549 g_list_free (clist);
5554 g_list_free (clist);
5556 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5557 accel_key, accel_mods, accel_group,
5558 G_OBJECT_TYPE_NAME (widget), widget);
5564 * gtk_widget_list_accel_closures:
5565 * @widget: widget to list accelerator closures for
5567 * Lists the closures used by @widget for accelerator group connections
5568 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5569 * The closures can be used to monitor accelerator changes on @widget,
5570 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5571 * #GtkAccelGroup of a closure which can be found out with
5572 * gtk_accel_group_from_accel_closure().
5574 * Return value: (transfer container) (element-type GClosure):
5575 * a newly allocated #GList of closures
5578 gtk_widget_list_accel_closures (GtkWidget *widget)
5581 GList *clist = NULL;
5583 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5585 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5586 if (gtk_accel_group_from_accel_closure (slist->data))
5587 clist = g_list_prepend (clist, slist->data);
5593 GtkAccelGroup *accel_group;
5598 destroy_accel_path (gpointer data)
5600 AccelPath *apath = data;
5602 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5604 /* closures_destroy takes care of unrefing the closure */
5605 g_object_unref (apath->accel_group);
5607 g_slice_free (AccelPath, apath);
5612 * gtk_widget_set_accel_path:
5613 * @widget: a #GtkWidget
5614 * @accel_path: (allow-none): path used to look up the accelerator
5615 * @accel_group: (allow-none): a #GtkAccelGroup.
5617 * Given an accelerator group, @accel_group, and an accelerator path,
5618 * @accel_path, sets up an accelerator in @accel_group so whenever the
5619 * key binding that is defined for @accel_path is pressed, @widget
5620 * will be activated. This removes any accelerators (for any
5621 * accelerator group) installed by previous calls to
5622 * gtk_widget_set_accel_path(). Associating accelerators with
5623 * paths allows them to be modified by the user and the modifications
5624 * to be saved for future use. (See gtk_accel_map_save().)
5626 * This function is a low level function that would most likely
5627 * be used by a menu creation system like #GtkUIManager. If you
5628 * use #GtkUIManager, setting up accelerator paths will be done
5631 * Even when you you aren't using #GtkUIManager, if you only want to
5632 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5633 * provides a somewhat more convenient interface.
5635 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5636 * pass a static string, you can save some memory by interning it first with
5637 * g_intern_static_string().
5640 gtk_widget_set_accel_path (GtkWidget *widget,
5641 const gchar *accel_path,
5642 GtkAccelGroup *accel_group)
5646 g_return_if_fail (GTK_IS_WIDGET (widget));
5647 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5651 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5652 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5654 gtk_accel_map_add_entry (accel_path, 0, 0);
5655 apath = g_slice_new (AccelPath);
5656 apath->accel_group = g_object_ref (accel_group);
5657 apath->path_quark = g_quark_from_string (accel_path);
5658 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5663 /* also removes possible old settings */
5664 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5667 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5669 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5673 _gtk_widget_get_accel_path (GtkWidget *widget,
5678 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5680 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5682 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5683 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5687 * gtk_widget_mnemonic_activate:
5688 * @widget: a #GtkWidget
5689 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5691 * Emits the #GtkWidget::mnemonic-activate signal.
5693 * The default handler for this signal activates the @widget if
5694 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5697 * Returns: %TRUE if the signal has been handled
5700 gtk_widget_mnemonic_activate (GtkWidget *widget,
5701 gboolean group_cycling)
5705 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5707 group_cycling = group_cycling != FALSE;
5708 if (!gtk_widget_is_sensitive (widget))
5711 g_signal_emit (widget,
5712 widget_signals[MNEMONIC_ACTIVATE],
5720 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5721 gboolean group_cycling)
5723 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5724 gtk_widget_activate (widget);
5725 else if (gtk_widget_get_can_focus (widget))
5726 gtk_widget_grab_focus (widget);
5729 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5730 G_OBJECT_TYPE_NAME (widget));
5731 gtk_widget_error_bell (widget);
5736 static const cairo_user_data_key_t event_key;
5739 _gtk_cairo_get_event (cairo_t *cr)
5741 g_return_val_if_fail (cr != NULL, NULL);
5743 return cairo_get_user_data (cr, &event_key);
5747 gtk_cairo_set_event (cairo_t *cr,
5748 GdkEventExpose *event)
5750 cairo_set_user_data (cr, &event_key, event, NULL);
5754 * gtk_cairo_should_draw_window:
5755 * @cr: a cairo context
5756 * @window: the window to check. @window may not be an input-only
5759 * This function is supposed to be called in #GtkWidget::draw
5760 * implementations for widgets that support multiple windows.
5761 * @cr must be untransformed from invoking of the draw function.
5762 * This function will return %TRUE if the contents of the given
5763 * @window are supposed to be drawn and %FALSE otherwise. Note
5764 * that when the drawing was not initiated by the windowing
5765 * system this function will return %TRUE for all windows, so
5766 * you need to draw the bottommost window first. Also, do not
5767 * use "else if" statements to check which window should be drawn.
5769 * Returns: %TRUE if @window should be drawn
5774 gtk_cairo_should_draw_window (cairo_t *cr,
5777 GdkEventExpose *event;
5779 g_return_val_if_fail (cr != NULL, FALSE);
5780 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5782 event = _gtk_cairo_get_event (cr);
5784 return event == NULL ||
5785 event->window == window;
5789 gtk_widget_get_clip_draw (GtkWidget *widget)
5791 /* labels are not clipped, because clipping them would cause
5792 * mnemonics to not appear on characters that go beyond the
5794 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5796 if (GTK_IS_LABEL (widget))
5802 /* code shared by gtk_container_propagate_draw() and
5806 _gtk_widget_draw_internal (GtkWidget *widget,
5808 gboolean clip_to_size)
5810 GtkStyleContext *context;
5812 if (!gtk_widget_is_drawable (widget))
5815 clip_to_size &= gtk_widget_get_clip_draw (widget);
5819 cairo_rectangle (cr,
5821 widget->priv->allocation.width,
5822 widget->priv->allocation.height);
5826 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5830 g_signal_emit (widget, widget_signals[DRAW],
5834 if (cairo_status (cr) &&
5835 _gtk_cairo_get_event (cr))
5837 /* We check the event so we only warn about internal GTK calls.
5838 * Errors might come from PDF streams having write failures and
5839 * we don't want to spam stderr in that case.
5840 * We do want to catch errors from
5842 g_warning ("drawing failure for widget `%s': %s",
5843 G_OBJECT_TYPE_NAME (widget),
5844 cairo_status_to_string (cairo_status (cr)));
5848 context = gtk_widget_get_style_context (widget);
5849 _gtk_style_context_coalesce_animation_areas (context, widget);
5854 * @widget: the widget to draw. It must be drawable (see
5855 * gtk_widget_is_drawable()) and a size must have been allocated.
5856 * @cr: a cairo context to draw to
5858 * Draws @widget to @cr. The top left corner of the widget will be
5859 * drawn to the currently set origin point of @cr.
5861 * You should pass a cairo context as @cr argument that is in an
5862 * original state. Otherwise the resulting drawing is undefined. For
5863 * example changing the operator using cairo_set_operator() or the
5864 * line width using cairo_set_line_width() might have unwanted side
5866 * You may however change the context's transform matrix - like with
5867 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5868 * region with cairo_clip() prior to calling this function. Also, it
5869 * is fine to modify the context with cairo_save() and
5870 * cairo_push_group() prior to calling this function.
5872 * <note><para>Special purpose widgets may contain special code for
5873 * rendering to the screen and might appear differently on screen
5874 * and when rendered using gtk_widget_draw().</para></note>
5879 gtk_widget_draw (GtkWidget *widget,
5882 GdkEventExpose *tmp_event;
5884 g_return_if_fail (GTK_IS_WIDGET (widget));
5885 g_return_if_fail (!widget->priv->alloc_needed);
5886 g_return_if_fail (cr != NULL);
5889 /* We have to reset the event here so that draw functions can call
5890 * gtk_widget_draw() on random other widgets and get the desired
5891 * effect: Drawing all contents, not just the current window.
5893 tmp_event = _gtk_cairo_get_event (cr);
5894 gtk_cairo_set_event (cr, NULL);
5896 _gtk_widget_draw_internal (widget, cr, TRUE);
5898 gtk_cairo_set_event (cr, tmp_event);
5903 gtk_widget_real_key_press_event (GtkWidget *widget,
5906 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5910 gtk_widget_real_key_release_event (GtkWidget *widget,
5913 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5917 gtk_widget_real_focus_in_event (GtkWidget *widget,
5918 GdkEventFocus *event)
5920 gtk_widget_queue_shallow_draw (widget);
5926 gtk_widget_real_focus_out_event (GtkWidget *widget,
5927 GdkEventFocus *event)
5929 gtk_widget_queue_shallow_draw (widget);
5935 gtk_widget_real_touch_event (GtkWidget *widget,
5936 GdkEventTouch *event)
5939 gboolean return_val;
5942 if (!event->emulating_pointer)
5945 if (event->type == GDK_TOUCH_BEGIN ||
5946 event->type == GDK_TOUCH_END)
5950 if (event->type == GDK_TOUCH_BEGIN)
5952 type = GDK_BUTTON_PRESS;
5953 signum = BUTTON_PRESS_EVENT;
5957 type = GDK_BUTTON_RELEASE;
5958 signum = BUTTON_RELEASE_EVENT;
5960 bevent = gdk_event_new (type);
5961 bevent->any.window = g_object_ref (event->window);
5962 bevent->any.send_event = FALSE;
5963 bevent->button.time = event->time;
5964 bevent->button.state = event->state;
5965 bevent->button.button = 1;
5966 bevent->button.x_root = event->x_root;
5967 bevent->button.y_root = event->y_root;
5968 bevent->button.x = event->x;
5969 bevent->button.y = event->y;
5970 bevent->button.device = event->device;
5971 bevent->button.axes = g_memdup (event->axes,
5972 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5973 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5975 else if (event->type == GDK_TOUCH_UPDATE)
5977 signum = MOTION_NOTIFY_EVENT;
5978 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5979 bevent->any.window = g_object_ref (event->window);
5980 bevent->any.send_event = FALSE;
5981 bevent->motion.time = event->time;
5982 bevent->motion.state = event->state;
5983 bevent->motion.x_root = event->x_root;
5984 bevent->motion.y_root = event->y_root;
5985 bevent->motion.x = event->x;
5986 bevent->motion.y = event->y;
5987 bevent->motion.device = event->device;
5988 bevent->motion.is_hint = FALSE;
5989 bevent->motion.axes = g_memdup (event->axes,
5990 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5991 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5996 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5998 gdk_event_free (bevent);
6004 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6005 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6009 * @widget: a #GtkWidget
6010 * @event: a #GdkEvent
6012 * Rarely-used function. This function is used to emit
6013 * the event signals on a widget (those signals should never
6014 * be emitted without using this function to do so).
6015 * If you want to synthesize an event though, don't use this function;
6016 * instead, use gtk_main_do_event() so the event will behave as if
6017 * it were in the event queue. Don't synthesize expose events; instead,
6018 * use gdk_window_invalidate_rect() to invalidate a region of the
6021 * Return value: return from the event signal emission (%TRUE if
6022 * the event was handled)
6025 gtk_widget_event (GtkWidget *widget,
6028 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6029 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6031 if (event->type == GDK_EXPOSE)
6033 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6034 "the same effect, call gdk_window_invalidate_rect/region(), "
6035 "followed by gdk_window_process_updates().");
6039 return gtk_widget_event_internal (widget, event);
6043 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6044 GtkCapturedEventHandler callback)
6046 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6050 _gtk_widget_captured_event (GtkWidget *widget,
6053 gboolean return_val = FALSE;
6054 GtkCapturedEventHandler handler;
6056 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6057 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6059 if (event->type == GDK_EXPOSE)
6061 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6062 "the same effect, call gdk_window_invalidate_rect/region(), "
6063 "followed by gdk_window_process_updates().");
6067 if (!event_window_is_still_viewable (event))
6070 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6074 g_object_ref (widget);
6076 return_val = handler (widget, event);
6077 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6079 /* The widget that was originally to receive the event
6080 * handles motion hints, but the capturing widget might
6081 * not, so ensure we get further motion events.
6084 event->type == GDK_MOTION_NOTIFY &&
6085 event->motion.is_hint &&
6086 (gdk_window_get_events (event->any.window) &
6087 GDK_POINTER_MOTION_HINT_MASK) != 0)
6088 gdk_event_request_motions (&event->motion);
6090 g_object_unref (widget);
6095 /* Returns TRUE if a translation should be done */
6097 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6102 GdkWindow *w, *widget_window;
6104 if (!gtk_widget_get_has_window (widget))
6106 *x = -widget->priv->allocation.x;
6107 *y = -widget->priv->allocation.y;
6115 widget_window = gtk_widget_get_window (widget);
6117 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6120 gdk_window_get_position (w, &wx, &wy);
6137 * gtk_cairo_transform_to_window:
6138 * @cr: the cairo context to transform
6139 * @widget: the widget the context is currently centered for
6140 * @window: the window to transform the context to
6142 * Transforms the given cairo context @cr that from @widget-relative
6143 * coordinates to @window-relative coordinates.
6144 * If the @widget's window is not an ancestor of @window, no
6145 * modification will be applied.
6147 * This is the inverse to the transformation GTK applies when
6148 * preparing an expose event to be emitted with the #GtkWidget::draw
6149 * signal. It is intended to help porting multiwindow widgets from
6150 * GTK+ 2 to the rendering architecture of GTK+ 3.
6155 gtk_cairo_transform_to_window (cairo_t *cr,
6161 g_return_if_fail (cr != NULL);
6162 g_return_if_fail (GTK_IS_WIDGET (widget));
6163 g_return_if_fail (GDK_IS_WINDOW (window));
6165 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6166 cairo_translate (cr, x, y);
6170 * gtk_widget_send_expose:
6171 * @widget: a #GtkWidget
6172 * @event: a expose #GdkEvent
6174 * Very rarely-used function. This function is used to emit
6175 * an expose event on a widget. This function is not normally used
6176 * directly. The only time it is used is when propagating an expose
6177 * event to a child %NO_WINDOW widget, and that is normally done
6178 * using gtk_container_propagate_draw().
6180 * If you want to force an area of a window to be redrawn,
6181 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6182 * To cause the redraw to be done immediately, follow that call
6183 * with a call to gdk_window_process_updates().
6185 * Return value: return from the event signal emission (%TRUE if
6186 * the event was handled)
6189 gtk_widget_send_expose (GtkWidget *widget,
6192 gboolean result = FALSE;
6197 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6198 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6199 g_return_val_if_fail (event != NULL, TRUE);
6200 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6202 cr = gdk_cairo_create (event->expose.window);
6203 gtk_cairo_set_event (cr, &event->expose);
6205 gdk_cairo_region (cr, event->expose.region);
6208 do_clip = _gtk_widget_get_translation_to_window (widget,
6209 event->expose.window,
6211 cairo_translate (cr, -x, -y);
6213 _gtk_widget_draw_internal (widget, cr, do_clip);
6215 /* unset here, so if someone keeps a reference to cr we
6216 * don't leak the window. */
6217 gtk_cairo_set_event (cr, NULL);
6224 event_window_is_still_viewable (GdkEvent *event)
6226 /* Check that we think the event's window is viewable before
6227 * delivering the event, to prevent suprises. We do this here
6228 * at the last moment, since the event may have been queued
6229 * up behind other events, held over a recursive main loop, etc.
6231 switch (event->type)
6234 case GDK_MOTION_NOTIFY:
6235 case GDK_BUTTON_PRESS:
6236 case GDK_2BUTTON_PRESS:
6237 case GDK_3BUTTON_PRESS:
6239 case GDK_ENTER_NOTIFY:
6240 case GDK_PROXIMITY_IN:
6242 return event->any.window && gdk_window_is_viewable (event->any.window);
6245 /* The following events are the second half of paired events;
6246 * we always deliver them to deal with widgets that clean up
6247 * on the second half.
6249 case GDK_BUTTON_RELEASE:
6250 case GDK_KEY_RELEASE:
6251 case GDK_LEAVE_NOTIFY:
6252 case GDK_PROXIMITY_OUT:
6256 /* Remaining events would make sense on an not-viewable window,
6257 * or don't have an associated window.
6264 gtk_widget_event_internal (GtkWidget *widget,
6267 gboolean return_val = FALSE;
6269 /* We check only once for is-still-visible; if someone
6270 * hides the window in on of the signals on the widget,
6271 * they are responsible for returning TRUE to terminate
6274 if (!event_window_is_still_viewable (event))
6277 g_object_ref (widget);
6279 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6280 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6285 switch (event->type)
6291 case GDK_BUTTON_PRESS:
6292 case GDK_2BUTTON_PRESS:
6293 case GDK_3BUTTON_PRESS:
6294 signal_num = BUTTON_PRESS_EVENT;
6296 case GDK_TOUCH_BEGIN:
6297 case GDK_TOUCH_UPDATE:
6299 case GDK_TOUCH_CANCEL:
6300 signal_num = TOUCH_EVENT;
6303 signal_num = SCROLL_EVENT;
6305 case GDK_BUTTON_RELEASE:
6306 signal_num = BUTTON_RELEASE_EVENT;
6308 case GDK_MOTION_NOTIFY:
6309 signal_num = MOTION_NOTIFY_EVENT;
6312 signal_num = DELETE_EVENT;
6315 signal_num = DESTROY_EVENT;
6316 _gtk_tooltip_hide (widget);
6319 signal_num = KEY_PRESS_EVENT;
6321 case GDK_KEY_RELEASE:
6322 signal_num = KEY_RELEASE_EVENT;
6324 case GDK_ENTER_NOTIFY:
6325 signal_num = ENTER_NOTIFY_EVENT;
6327 case GDK_LEAVE_NOTIFY:
6328 signal_num = LEAVE_NOTIFY_EVENT;
6330 case GDK_FOCUS_CHANGE:
6331 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6332 if (event->focus_change.in)
6333 _gtk_tooltip_focus_in (widget);
6335 _gtk_tooltip_focus_out (widget);
6338 signal_num = CONFIGURE_EVENT;
6341 signal_num = MAP_EVENT;
6344 signal_num = UNMAP_EVENT;
6346 case GDK_WINDOW_STATE:
6347 signal_num = WINDOW_STATE_EVENT;
6349 case GDK_PROPERTY_NOTIFY:
6350 signal_num = PROPERTY_NOTIFY_EVENT;
6352 case GDK_SELECTION_CLEAR:
6353 signal_num = SELECTION_CLEAR_EVENT;
6355 case GDK_SELECTION_REQUEST:
6356 signal_num = SELECTION_REQUEST_EVENT;
6358 case GDK_SELECTION_NOTIFY:
6359 signal_num = SELECTION_NOTIFY_EVENT;
6361 case GDK_PROXIMITY_IN:
6362 signal_num = PROXIMITY_IN_EVENT;
6364 case GDK_PROXIMITY_OUT:
6365 signal_num = PROXIMITY_OUT_EVENT;
6367 case GDK_VISIBILITY_NOTIFY:
6368 signal_num = VISIBILITY_NOTIFY_EVENT;
6370 case GDK_GRAB_BROKEN:
6371 signal_num = GRAB_BROKEN_EVENT;
6374 signal_num = DAMAGE_EVENT;
6377 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6381 if (signal_num != -1)
6382 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6384 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6385 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6389 g_object_unref (widget);
6395 * gtk_widget_activate:
6396 * @widget: a #GtkWidget that's activatable
6398 * For widgets that can be "activated" (buttons, menu items, etc.)
6399 * this function activates them. Activation is what happens when you
6400 * press Enter on a widget during key navigation. If @widget isn't
6401 * activatable, the function returns %FALSE.
6403 * Return value: %TRUE if the widget was activatable
6406 gtk_widget_activate (GtkWidget *widget)
6408 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6410 if (WIDGET_CLASS (widget)->activate_signal)
6412 /* FIXME: we should eventually check the signals signature here */
6413 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6422 gtk_widget_reparent_subwindows (GtkWidget *widget,
6423 GdkWindow *new_window)
6425 GtkWidgetPrivate *priv = widget->priv;
6427 if (!gtk_widget_get_has_window (widget))
6429 GList *children = gdk_window_get_children (priv->window);
6432 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6434 GdkWindow *window = tmp_list->data;
6437 gdk_window_get_user_data (window, &child);
6438 while (child && child != widget)
6439 child = ((GtkWidget*) child)->priv->parent;
6442 gdk_window_reparent (window, new_window, 0, 0);
6445 g_list_free (children);
6450 GList *tmp_list, *children;
6452 parent = gdk_window_get_parent (priv->window);
6455 gdk_window_reparent (priv->window, new_window, 0, 0);
6458 children = gdk_window_get_children (parent);
6460 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6462 GdkWindow *window = tmp_list->data;
6465 gdk_window_get_user_data (window, &child);
6467 if (child == widget)
6468 gdk_window_reparent (window, new_window, 0, 0);
6471 g_list_free (children);
6477 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6478 gpointer client_data)
6480 GtkWidgetPrivate *priv = widget->priv;
6482 g_assert (client_data != NULL);
6484 if (!gtk_widget_get_has_window (widget))
6487 g_object_unref (priv->window);
6488 priv->window = (GdkWindow*) client_data;
6490 g_object_ref (priv->window);
6492 if (GTK_IS_CONTAINER (widget))
6493 gtk_container_forall (GTK_CONTAINER (widget),
6494 gtk_widget_reparent_fixup_child,
6500 * gtk_widget_reparent:
6501 * @widget: a #GtkWidget
6502 * @new_parent: a #GtkContainer to move the widget into
6504 * Moves a widget from one #GtkContainer to another, handling reference
6505 * count issues to avoid destroying the widget.
6508 gtk_widget_reparent (GtkWidget *widget,
6509 GtkWidget *new_parent)
6511 GtkWidgetPrivate *priv;
6513 g_return_if_fail (GTK_IS_WIDGET (widget));
6514 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6515 priv = widget->priv;
6516 g_return_if_fail (priv->parent != NULL);
6518 if (priv->parent != new_parent)
6520 /* First try to see if we can get away without unrealizing
6521 * the widget as we reparent it. if so we set a flag so
6522 * that gtk_widget_unparent doesn't unrealize widget
6524 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6525 priv->in_reparent = TRUE;
6527 g_object_ref (widget);
6528 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6529 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6530 g_object_unref (widget);
6532 if (priv->in_reparent)
6534 priv->in_reparent = FALSE;
6536 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6537 gtk_widget_reparent_fixup_child (widget,
6538 gtk_widget_get_parent_window (widget));
6541 g_object_notify (G_OBJECT (widget), "parent");
6546 * gtk_widget_intersect:
6547 * @widget: a #GtkWidget
6548 * @area: a rectangle
6549 * @intersection: rectangle to store intersection of @widget and @area
6551 * Computes the intersection of a @widget's area and @area, storing
6552 * the intersection in @intersection, and returns %TRUE if there was
6553 * an intersection. @intersection may be %NULL if you're only
6554 * interested in whether there was an intersection.
6556 * Return value: %TRUE if there was an intersection
6559 gtk_widget_intersect (GtkWidget *widget,
6560 const GdkRectangle *area,
6561 GdkRectangle *intersection)
6563 GtkWidgetPrivate *priv;
6568 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6569 g_return_val_if_fail (area != NULL, FALSE);
6571 priv = widget->priv;
6574 dest = intersection;
6578 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6580 if (return_val && intersection && gtk_widget_get_has_window (widget))
6582 intersection->x -= priv->allocation.x;
6583 intersection->y -= priv->allocation.y;
6590 * gtk_widget_region_intersect:
6591 * @widget: a #GtkWidget
6592 * @region: a #cairo_region_t, in the same coordinate system as
6593 * @widget->allocation. That is, relative to @widget->window
6594 * for %NO_WINDOW widgets; relative to the parent window
6595 * of @widget->window for widgets with their own window.
6597 * Computes the intersection of a @widget's area and @region, returning
6598 * the intersection. The result may be empty, use cairo_region_is_empty() to
6601 * Returns: A newly allocated region holding the intersection of @widget
6602 * and @region. The coordinates of the return value are relative to
6603 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6604 * window of @widget->window for widgets with their own window.
6607 gtk_widget_region_intersect (GtkWidget *widget,
6608 const cairo_region_t *region)
6611 cairo_region_t *dest;
6613 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6614 g_return_val_if_fail (region != NULL, NULL);
6616 gtk_widget_get_allocation (widget, &rect);
6618 dest = cairo_region_create_rectangle (&rect);
6620 cairo_region_intersect (dest, region);
6626 * _gtk_widget_grab_notify:
6627 * @widget: a #GtkWidget
6628 * @was_grabbed: whether a grab is now in effect
6630 * Emits the #GtkWidget::grab-notify signal on @widget.
6635 _gtk_widget_grab_notify (GtkWidget *widget,
6636 gboolean was_grabbed)
6638 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6642 * gtk_widget_grab_focus:
6643 * @widget: a #GtkWidget
6645 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6646 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6647 * something like #GtkFrame won't work.
6649 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6650 * gtk_widget_set_can_focus() to modify that flag.
6652 * The widget also needs to be realized and mapped. This is indicated by the
6653 * related signals. Grabbing the focus immediately after creating the widget
6654 * will likely fail and cause critical warnings.
6657 gtk_widget_grab_focus (GtkWidget *widget)
6659 g_return_if_fail (GTK_IS_WIDGET (widget));
6661 if (!gtk_widget_is_sensitive (widget))
6664 g_object_ref (widget);
6665 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6666 g_object_notify (G_OBJECT (widget), "has-focus");
6667 g_object_unref (widget);
6671 reset_focus_recurse (GtkWidget *widget,
6674 if (GTK_IS_CONTAINER (widget))
6676 GtkContainer *container;
6678 container = GTK_CONTAINER (widget);
6679 gtk_container_set_focus_child (container, NULL);
6681 gtk_container_foreach (container,
6682 reset_focus_recurse,
6688 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6690 if (gtk_widget_get_can_focus (focus_widget))
6692 GtkWidget *toplevel;
6695 /* clear the current focus setting, break if the current widget
6696 * is the focus widget's parent, since containers above that will
6697 * be set by the next loop.
6699 toplevel = gtk_widget_get_toplevel (focus_widget);
6700 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6702 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6704 if (widget == focus_widget)
6706 /* We call _gtk_window_internal_set_focus() here so that the
6707 * toplevel window can request the focus if necessary.
6708 * This is needed when the toplevel is a GtkPlug
6710 if (!gtk_widget_has_focus (widget))
6711 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6718 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6720 if (widget != common_ancestor)
6722 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6724 widget = widget->priv->parent;
6725 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6730 else if (toplevel != focus_widget)
6732 /* gtk_widget_grab_focus() operates on a tree without window...
6733 * actually, this is very questionable behaviour.
6736 gtk_container_foreach (GTK_CONTAINER (toplevel),
6737 reset_focus_recurse,
6741 /* now propagate the new focus up the widget tree and finally
6742 * set it on the window
6744 widget = focus_widget;
6745 while (widget->priv->parent)
6747 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6748 widget = widget->priv->parent;
6750 if (GTK_IS_WINDOW (widget))
6751 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6756 gtk_widget_real_query_tooltip (GtkWidget *widget,
6759 gboolean keyboard_tip,
6760 GtkTooltip *tooltip)
6762 gchar *tooltip_markup;
6763 gboolean has_tooltip;
6765 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6766 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6768 if (has_tooltip && tooltip_markup)
6770 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6778 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6779 GtkStateFlags old_state)
6781 gtk_widget_update_pango_context (widget);
6785 gtk_widget_real_style_updated (GtkWidget *widget)
6787 GtkWidgetPrivate *priv = widget->priv;
6789 gtk_widget_update_pango_context (widget);
6791 if (priv->style != NULL &&
6792 priv->style != gtk_widget_get_default_style ())
6794 /* Trigger ::style-set for old
6795 * widgets not listening to this
6797 g_signal_emit (widget,
6798 widget_signals[STYLE_SET],
6800 widget->priv->style);
6803 if (widget->priv->context)
6805 if (gtk_widget_get_realized (widget) &&
6806 gtk_widget_get_has_window (widget))
6807 gtk_style_context_set_background (widget->priv->context,
6808 widget->priv->window);
6811 if (widget->priv->anchored)
6812 gtk_widget_queue_resize (widget);
6816 gtk_widget_real_show_help (GtkWidget *widget,
6817 GtkWidgetHelpType help_type)
6819 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6821 _gtk_tooltip_toggle_keyboard_mode (widget);
6830 gtk_widget_real_focus (GtkWidget *widget,
6831 GtkDirectionType direction)
6833 if (!gtk_widget_get_can_focus (widget))
6836 if (!gtk_widget_is_focus (widget))
6838 gtk_widget_grab_focus (widget);
6846 gtk_widget_real_move_focus (GtkWidget *widget,
6847 GtkDirectionType direction)
6849 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6851 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6853 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6859 gtk_widget_real_keynav_failed (GtkWidget *widget,
6860 GtkDirectionType direction)
6862 gboolean cursor_only;
6866 case GTK_DIR_TAB_FORWARD:
6867 case GTK_DIR_TAB_BACKWARD:
6874 g_object_get (gtk_widget_get_settings (widget),
6875 "gtk-keynav-cursor-only", &cursor_only,
6882 gtk_widget_error_bell (widget);
6888 * gtk_widget_set_can_focus:
6889 * @widget: a #GtkWidget
6890 * @can_focus: whether or not @widget can own the input focus.
6892 * Specifies whether @widget can own the input focus. See
6893 * gtk_widget_grab_focus() for actually setting the input focus on a
6899 gtk_widget_set_can_focus (GtkWidget *widget,
6902 g_return_if_fail (GTK_IS_WIDGET (widget));
6904 if (widget->priv->can_focus != can_focus)
6906 widget->priv->can_focus = can_focus;
6908 gtk_widget_queue_resize (widget);
6909 g_object_notify (G_OBJECT (widget), "can-focus");
6914 * gtk_widget_get_can_focus:
6915 * @widget: a #GtkWidget
6917 * Determines whether @widget can own the input focus. See
6918 * gtk_widget_set_can_focus().
6920 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6925 gtk_widget_get_can_focus (GtkWidget *widget)
6927 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6929 return widget->priv->can_focus;
6933 * gtk_widget_has_focus:
6934 * @widget: a #GtkWidget
6936 * Determines if the widget has the global input focus. See
6937 * gtk_widget_is_focus() for the difference between having the global
6938 * input focus, and only having the focus within a toplevel.
6940 * Return value: %TRUE if the widget has the global input focus.
6945 gtk_widget_has_focus (GtkWidget *widget)
6947 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6949 return widget->priv->has_focus;
6953 * gtk_widget_has_visible_focus:
6954 * @widget: a #GtkWidget
6956 * Determines if the widget should show a visible indication that
6957 * it has the global input focus. This is a convenience function for
6958 * use in ::draw handlers that takes into account whether focus
6959 * indication should currently be shown in the toplevel window of
6960 * @widget. See gtk_window_get_focus_visible() for more information
6961 * about focus indication.
6963 * To find out if the widget has the global input focus, use
6964 * gtk_widget_has_focus().
6966 * Return value: %TRUE if the widget should display a 'focus rectangle'
6971 gtk_widget_has_visible_focus (GtkWidget *widget)
6973 gboolean draw_focus;
6975 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6977 if (widget->priv->has_focus)
6979 GtkWidget *toplevel;
6981 toplevel = gtk_widget_get_toplevel (widget);
6983 if (GTK_IS_WINDOW (toplevel))
6984 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6995 * gtk_widget_is_focus:
6996 * @widget: a #GtkWidget
6998 * Determines if the widget is the focus widget within its
6999 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7000 * necessarily set; %HAS_FOCUS will only be set if the
7001 * toplevel widget additionally has the global input focus.)
7003 * Return value: %TRUE if the widget is the focus widget.
7006 gtk_widget_is_focus (GtkWidget *widget)
7008 GtkWidget *toplevel;
7010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7012 toplevel = gtk_widget_get_toplevel (widget);
7014 if (GTK_IS_WINDOW (toplevel))
7015 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7021 * gtk_widget_set_can_default:
7022 * @widget: a #GtkWidget
7023 * @can_default: whether or not @widget can be a default widget.
7025 * Specifies whether @widget can be a default widget. See
7026 * gtk_widget_grab_default() for details about the meaning of
7032 gtk_widget_set_can_default (GtkWidget *widget,
7033 gboolean can_default)
7035 g_return_if_fail (GTK_IS_WIDGET (widget));
7037 if (widget->priv->can_default != can_default)
7039 widget->priv->can_default = can_default;
7041 gtk_widget_queue_resize (widget);
7042 g_object_notify (G_OBJECT (widget), "can-default");
7047 * gtk_widget_get_can_default:
7048 * @widget: a #GtkWidget
7050 * Determines whether @widget can be a default widget. See
7051 * gtk_widget_set_can_default().
7053 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7058 gtk_widget_get_can_default (GtkWidget *widget)
7060 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7062 return widget->priv->can_default;
7066 * gtk_widget_has_default:
7067 * @widget: a #GtkWidget
7069 * Determines whether @widget is the current default widget within its
7070 * toplevel. See gtk_widget_set_can_default().
7072 * Return value: %TRUE if @widget is the current default widget within
7073 * its toplevel, %FALSE otherwise
7078 gtk_widget_has_default (GtkWidget *widget)
7080 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7082 return widget->priv->has_default;
7086 _gtk_widget_set_has_default (GtkWidget *widget,
7087 gboolean has_default)
7089 widget->priv->has_default = has_default;
7093 * gtk_widget_grab_default:
7094 * @widget: a #GtkWidget
7096 * Causes @widget to become the default widget. @widget must have the
7097 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
7098 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
7099 * %TRUE)</literal>. The default widget is activated when
7100 * the user presses Enter in a window. Default widgets must be
7101 * activatable, that is, gtk_widget_activate() should affect them. Note
7102 * that #GtkEntry widgets require the "activates-default" property
7103 * set to %TRUE before they activate the default widget when Enter
7104 * is pressed and the #GtkEntry is focused.
7107 gtk_widget_grab_default (GtkWidget *widget)
7111 g_return_if_fail (GTK_IS_WIDGET (widget));
7112 g_return_if_fail (gtk_widget_get_can_default (widget));
7114 window = gtk_widget_get_toplevel (widget);
7116 if (window && gtk_widget_is_toplevel (window))
7117 gtk_window_set_default (GTK_WINDOW (window), widget);
7119 g_warning (G_STRLOC ": widget not within a GtkWindow");
7123 * gtk_widget_set_receives_default:
7124 * @widget: a #GtkWidget
7125 * @receives_default: whether or not @widget can be a default widget.
7127 * Specifies whether @widget will be treated as the default widget
7128 * within its toplevel when it has the focus, even if another widget
7131 * See gtk_widget_grab_default() for details about the meaning of
7137 gtk_widget_set_receives_default (GtkWidget *widget,
7138 gboolean receives_default)
7140 g_return_if_fail (GTK_IS_WIDGET (widget));
7142 if (widget->priv->receives_default != receives_default)
7144 widget->priv->receives_default = receives_default;
7146 g_object_notify (G_OBJECT (widget), "receives-default");
7151 * gtk_widget_get_receives_default:
7152 * @widget: a #GtkWidget
7154 * Determines whether @widget is alyways treated as default widget
7155 * withing its toplevel when it has the focus, even if another widget
7158 * See gtk_widget_set_receives_default().
7160 * Return value: %TRUE if @widget acts as default widget when focussed,
7166 gtk_widget_get_receives_default (GtkWidget *widget)
7168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7170 return widget->priv->receives_default;
7174 * gtk_widget_has_grab:
7175 * @widget: a #GtkWidget
7177 * Determines whether the widget is currently grabbing events, so it
7178 * is the only widget receiving input events (keyboard and mouse).
7180 * See also gtk_grab_add().
7182 * Return value: %TRUE if the widget is in the grab_widgets stack
7187 gtk_widget_has_grab (GtkWidget *widget)
7189 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7191 return widget->priv->has_grab;
7195 _gtk_widget_set_has_grab (GtkWidget *widget,
7198 widget->priv->has_grab = has_grab;
7202 * gtk_widget_device_is_shadowed:
7203 * @widget: a #GtkWidget
7204 * @device: a #GdkDevice
7206 * Returns %TRUE if @device has been shadowed by a GTK+
7207 * device grab on another widget, so it would stop sending
7208 * events to @widget. This may be used in the
7209 * #GtkWidget::grab-notify signal to check for specific
7210 * devices. See gtk_device_grab_add().
7212 * Returns: %TRUE if there is an ongoing grab on @device
7213 * by another #GtkWidget than @widget.
7218 gtk_widget_device_is_shadowed (GtkWidget *widget,
7221 GtkWindowGroup *group;
7222 GtkWidget *grab_widget, *toplevel;
7224 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7225 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7227 if (!gtk_widget_get_realized (widget))
7230 toplevel = gtk_widget_get_toplevel (widget);
7232 if (GTK_IS_WINDOW (toplevel))
7233 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7235 group = gtk_window_get_group (NULL);
7237 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7239 /* Widget not inside the hierarchy of grab_widget */
7241 widget != grab_widget &&
7242 !gtk_widget_is_ancestor (widget, grab_widget))
7245 grab_widget = gtk_window_group_get_current_grab (group);
7246 if (grab_widget && widget != grab_widget &&
7247 !gtk_widget_is_ancestor (widget, grab_widget))
7254 * gtk_widget_set_name:
7255 * @widget: a #GtkWidget
7256 * @name: name for the widget
7258 * Widgets can be named, which allows you to refer to them from a
7259 * CSS file. You can apply a style to widgets with a particular name
7260 * in the CSS file. See the documentation for the CSS syntax (on the
7261 * same page as the docs for #GtkStyleContext).
7263 * Note that the CSS syntax has certain special characters to delimit
7264 * and represent elements in a selector (period, #, >, *...),
7265 * so using these will make your widget impossible to match by name.
7266 * Any combination of alphanumeric symbols, dashes and underscores will
7270 gtk_widget_set_name (GtkWidget *widget,
7273 GtkWidgetPrivate *priv;
7276 g_return_if_fail (GTK_IS_WIDGET (widget));
7278 priv = widget->priv;
7280 new_name = g_strdup (name);
7281 g_free (priv->name);
7282 priv->name = new_name;
7284 gtk_widget_reset_style (widget);
7286 g_object_notify (G_OBJECT (widget), "name");
7290 * gtk_widget_get_name:
7291 * @widget: a #GtkWidget
7293 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7294 * significance of widget names.
7296 * Return value: name of the widget. This string is owned by GTK+ and
7297 * should not be modified or freed
7300 gtk_widget_get_name (GtkWidget *widget)
7302 GtkWidgetPrivate *priv;
7304 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7306 priv = widget->priv;
7310 return G_OBJECT_TYPE_NAME (widget);
7314 _gtk_widget_update_state_flags (GtkWidget *widget,
7315 GtkStateFlags flags,
7318 GtkWidgetPrivate *priv;
7320 priv = widget->priv;
7322 /* Handle insensitive first, since it is propagated
7323 * differently throughout the widget hierarchy.
7325 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7326 gtk_widget_set_sensitive (widget, TRUE);
7327 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7328 gtk_widget_set_sensitive (widget, FALSE);
7329 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7330 gtk_widget_set_sensitive (widget, TRUE);
7332 if (operation != STATE_CHANGE_REPLACE)
7333 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7336 operation == STATE_CHANGE_REPLACE)
7341 data.operation = operation;
7343 gtk_widget_propagate_state (widget, &data);
7345 gtk_widget_queue_resize (widget);
7350 * gtk_widget_set_state_flags:
7351 * @widget: a #GtkWidget
7352 * @flags: State flags to turn on
7353 * @clear: Whether to clear state before turning on @flags
7355 * This function is for use in widget implementations. Turns on flag
7356 * values in the current widget state (insensitive, prelighted, etc.).
7358 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7359 * will be propagated down to all non-internal children if @widget is a
7360 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7361 * down to all #GtkContainer children by different means than turning on the
7362 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7363 * gtk_widget_is_sensitive() will make use of these.
7368 gtk_widget_set_state_flags (GtkWidget *widget,
7369 GtkStateFlags flags,
7372 g_return_if_fail (GTK_IS_WIDGET (widget));
7374 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7375 (clear && widget->priv->state_flags == flags))
7379 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7381 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7385 * gtk_widget_unset_state_flags:
7386 * @widget: a #GtkWidget
7387 * @flags: State flags to turn off
7389 * This function is for use in widget implementations. Turns off flag
7390 * values for the current widget state (insensitive, prelighted, etc.).
7391 * See gtk_widget_set_state_flags().
7396 gtk_widget_unset_state_flags (GtkWidget *widget,
7397 GtkStateFlags flags)
7399 g_return_if_fail (GTK_IS_WIDGET (widget));
7401 if ((widget->priv->state_flags & flags) == 0)
7404 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7408 * gtk_widget_get_state_flags:
7409 * @widget: a #GtkWidget
7411 * Returns the widget state as a flag set. It is worth mentioning
7412 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7413 * returned, that is, also based on parent insensitivity, even if
7414 * @widget itself is sensitive.
7416 * Returns: The state flags for widget
7421 gtk_widget_get_state_flags (GtkWidget *widget)
7423 GtkStateFlags flags;
7425 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7427 flags = widget->priv->state_flags;
7429 if (gtk_widget_has_focus (widget))
7430 flags |= GTK_STATE_FLAG_FOCUSED;
7436 * gtk_widget_set_state:
7437 * @widget: a #GtkWidget
7438 * @state: new state for @widget
7440 * This function is for use in widget implementations. Sets the state
7441 * of a widget (insensitive, prelighted, etc.) Usually you should set
7442 * the state using wrapper functions such as gtk_widget_set_sensitive().
7444 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7447 gtk_widget_set_state (GtkWidget *widget,
7450 GtkStateFlags flags;
7452 if (state == gtk_widget_get_state (widget))
7457 case GTK_STATE_ACTIVE:
7458 flags = GTK_STATE_FLAG_ACTIVE;
7460 case GTK_STATE_PRELIGHT:
7461 flags = GTK_STATE_FLAG_PRELIGHT;
7463 case GTK_STATE_SELECTED:
7464 flags = GTK_STATE_FLAG_SELECTED;
7466 case GTK_STATE_INSENSITIVE:
7467 flags = GTK_STATE_FLAG_INSENSITIVE;
7469 case GTK_STATE_INCONSISTENT:
7470 flags = GTK_STATE_FLAG_INCONSISTENT;
7472 case GTK_STATE_FOCUSED:
7473 flags = GTK_STATE_FLAG_FOCUSED;
7475 case GTK_STATE_NORMAL:
7481 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7485 * gtk_widget_get_state:
7486 * @widget: a #GtkWidget
7488 * Returns the widget's state. See gtk_widget_set_state().
7490 * Returns: the state of @widget.
7494 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7497 gtk_widget_get_state (GtkWidget *widget)
7499 GtkStateFlags flags;
7501 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7503 flags = gtk_widget_get_state_flags (widget);
7505 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7506 return GTK_STATE_INSENSITIVE;
7507 else if (flags & GTK_STATE_FLAG_ACTIVE)
7508 return GTK_STATE_ACTIVE;
7509 else if (flags & GTK_STATE_FLAG_SELECTED)
7510 return GTK_STATE_SELECTED;
7511 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7512 return GTK_STATE_PRELIGHT;
7514 return GTK_STATE_NORMAL;
7518 * gtk_widget_set_visible:
7519 * @widget: a #GtkWidget
7520 * @visible: whether the widget should be shown or not
7522 * Sets the visibility state of @widget. Note that setting this to
7523 * %TRUE doesn't mean the widget is actually viewable, see
7524 * gtk_widget_get_visible().
7526 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7527 * but is nicer to use when the visibility of the widget depends on
7533 gtk_widget_set_visible (GtkWidget *widget,
7536 g_return_if_fail (GTK_IS_WIDGET (widget));
7538 if (visible != gtk_widget_get_visible (widget))
7541 gtk_widget_show (widget);
7543 gtk_widget_hide (widget);
7548 _gtk_widget_set_visible_flag (GtkWidget *widget,
7551 widget->priv->visible = visible;
7555 * gtk_widget_get_visible:
7556 * @widget: a #GtkWidget
7558 * Determines whether the widget is visible. Note that this doesn't
7559 * take into account whether the widget's parent is also visible
7560 * or the widget is obscured in any way.
7562 * See gtk_widget_set_visible().
7564 * Return value: %TRUE if the widget is visible
7569 gtk_widget_get_visible (GtkWidget *widget)
7571 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7573 return widget->priv->visible;
7577 * gtk_widget_set_has_window:
7578 * @widget: a #GtkWidget
7579 * @has_window: whether or not @widget has a window.
7581 * Specifies whether @widget has a #GdkWindow of its own. Note that
7582 * all realized widgets have a non-%NULL "window" pointer
7583 * (gtk_widget_get_window() never returns a %NULL window when a widget
7584 * is realized), but for many of them it's actually the #GdkWindow of
7585 * one of its parent widgets. Widgets that do not create a %window for
7586 * themselves in #GtkWidget::realize must announce this by
7587 * calling this function with @has_window = %FALSE.
7589 * This function should only be called by widget implementations,
7590 * and they should call it in their init() function.
7595 gtk_widget_set_has_window (GtkWidget *widget,
7596 gboolean has_window)
7598 g_return_if_fail (GTK_IS_WIDGET (widget));
7600 widget->priv->no_window = !has_window;
7604 * gtk_widget_get_has_window:
7605 * @widget: a #GtkWidget
7607 * Determines whether @widget has a #GdkWindow of its own. See
7608 * gtk_widget_set_has_window().
7610 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7615 gtk_widget_get_has_window (GtkWidget *widget)
7617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7619 return ! widget->priv->no_window;
7623 * gtk_widget_is_toplevel:
7624 * @widget: a #GtkWidget
7626 * Determines whether @widget is a toplevel widget.
7628 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7629 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7632 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7637 gtk_widget_is_toplevel (GtkWidget *widget)
7639 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7641 return widget->priv->toplevel;
7645 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7646 gboolean is_toplevel)
7648 widget->priv->toplevel = is_toplevel;
7652 * gtk_widget_is_drawable:
7653 * @widget: a #GtkWidget
7655 * Determines whether @widget can be drawn to. A widget can be drawn
7656 * to if it is mapped and visible.
7658 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7663 gtk_widget_is_drawable (GtkWidget *widget)
7665 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7667 return (gtk_widget_get_visible (widget) &&
7668 gtk_widget_get_mapped (widget));
7672 * gtk_widget_get_realized:
7673 * @widget: a #GtkWidget
7675 * Determines whether @widget is realized.
7677 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7682 gtk_widget_get_realized (GtkWidget *widget)
7684 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7686 return widget->priv->realized;
7690 * gtk_widget_set_realized:
7691 * @widget: a #GtkWidget
7692 * @realized: %TRUE to mark the widget as realized
7694 * Marks the widget as being realized.
7696 * This function should only ever be called in a derived widget's
7697 * "realize" or "unrealize" implementation.
7702 gtk_widget_set_realized (GtkWidget *widget,
7705 g_return_if_fail (GTK_IS_WIDGET (widget));
7707 widget->priv->realized = realized;
7711 * gtk_widget_get_mapped:
7712 * @widget: a #GtkWidget
7714 * Whether the widget is mapped.
7716 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7721 gtk_widget_get_mapped (GtkWidget *widget)
7723 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7725 return widget->priv->mapped;
7729 * gtk_widget_set_mapped:
7730 * @widget: a #GtkWidget
7731 * @mapped: %TRUE to mark the widget as mapped
7733 * Marks the widget as being realized.
7735 * This function should only ever be called in a derived widget's
7736 * "map" or "unmap" implementation.
7741 gtk_widget_set_mapped (GtkWidget *widget,
7744 g_return_if_fail (GTK_IS_WIDGET (widget));
7746 widget->priv->mapped = mapped;
7750 * gtk_widget_set_app_paintable:
7751 * @widget: a #GtkWidget
7752 * @app_paintable: %TRUE if the application will paint on the widget
7754 * Sets whether the application intends to draw on the widget in
7755 * an #GtkWidget::draw handler.
7757 * This is a hint to the widget and does not affect the behavior of
7758 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7759 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7760 * the effect is to suppress default themed drawing of the widget's
7761 * background. (Children of the widget will still be drawn.) The application
7762 * is then entirely responsible for drawing the widget background.
7764 * Note that the background is still drawn when the widget is mapped.
7767 gtk_widget_set_app_paintable (GtkWidget *widget,
7768 gboolean app_paintable)
7770 g_return_if_fail (GTK_IS_WIDGET (widget));
7772 app_paintable = (app_paintable != FALSE);
7774 if (widget->priv->app_paintable != app_paintable)
7776 widget->priv->app_paintable = app_paintable;
7778 if (gtk_widget_is_drawable (widget))
7779 gtk_widget_queue_draw (widget);
7781 g_object_notify (G_OBJECT (widget), "app-paintable");
7786 * gtk_widget_get_app_paintable:
7787 * @widget: a #GtkWidget
7789 * Determines whether the application intends to draw on the widget in
7790 * an #GtkWidget::draw handler.
7792 * See gtk_widget_set_app_paintable()
7794 * Return value: %TRUE if the widget is app paintable
7799 gtk_widget_get_app_paintable (GtkWidget *widget)
7801 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7803 return widget->priv->app_paintable;
7807 * gtk_widget_set_double_buffered:
7808 * @widget: a #GtkWidget
7809 * @double_buffered: %TRUE to double-buffer a widget
7811 * Widgets are double buffered by default; you can use this function
7812 * to turn off the buffering. "Double buffered" simply means that
7813 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7814 * automatically around expose events sent to the
7815 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7816 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7817 * buffer to the screen. The result is that users see the window
7818 * update in one smooth step, and don't see individual graphics
7819 * primitives being rendered.
7821 * In very simple terms, double buffered widgets don't flicker,
7822 * so you would only use this function to turn off double buffering
7823 * if you had special needs and really knew what you were doing.
7825 * Note: if you turn off double-buffering, you have to handle
7826 * expose events, since even the clearing to the background color or
7827 * pixmap will not happen automatically (as it is done in
7828 * gdk_window_begin_paint()).
7831 gtk_widget_set_double_buffered (GtkWidget *widget,
7832 gboolean double_buffered)
7834 g_return_if_fail (GTK_IS_WIDGET (widget));
7836 double_buffered = (double_buffered != FALSE);
7838 if (widget->priv->double_buffered != double_buffered)
7840 widget->priv->double_buffered = double_buffered;
7842 g_object_notify (G_OBJECT (widget), "double-buffered");
7847 * gtk_widget_get_double_buffered:
7848 * @widget: a #GtkWidget
7850 * Determines whether the widget is double buffered.
7852 * See gtk_widget_set_double_buffered()
7854 * Return value: %TRUE if the widget is double buffered
7859 gtk_widget_get_double_buffered (GtkWidget *widget)
7861 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7863 return widget->priv->double_buffered;
7867 * gtk_widget_set_redraw_on_allocate:
7868 * @widget: a #GtkWidget
7869 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7870 * when it is allocated to a new size. Otherwise, only the
7871 * new portion of the widget will be redrawn.
7873 * Sets whether the entire widget is queued for drawing when its size
7874 * allocation changes. By default, this setting is %TRUE and
7875 * the entire widget is redrawn on every size change. If your widget
7876 * leaves the upper left unchanged when made bigger, turning this
7877 * setting off will improve performance.
7879 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7880 * off all allocation on resizing: the widget will not even redraw if
7881 * its position changes; this is to allow containers that don't draw
7882 * anything to avoid excess invalidations. If you set this flag on a
7883 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7884 * you are responsible for invalidating both the old and new allocation
7885 * of the widget when the widget is moved and responsible for invalidating
7886 * regions newly when the widget increases size.
7889 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7890 gboolean redraw_on_allocate)
7892 g_return_if_fail (GTK_IS_WIDGET (widget));
7894 widget->priv->redraw_on_alloc = redraw_on_allocate;
7898 * gtk_widget_set_sensitive:
7899 * @widget: a #GtkWidget
7900 * @sensitive: %TRUE to make the widget sensitive
7902 * Sets the sensitivity of a widget. A widget is sensitive if the user
7903 * can interact with it. Insensitive widgets are "grayed out" and the
7904 * user can't interact with them. Insensitive widgets are known as
7905 * "inactive", "disabled", or "ghosted" in some other toolkits.
7908 gtk_widget_set_sensitive (GtkWidget *widget,
7911 GtkWidgetPrivate *priv;
7913 g_return_if_fail (GTK_IS_WIDGET (widget));
7915 priv = widget->priv;
7917 sensitive = (sensitive != FALSE);
7919 if (priv->sensitive == sensitive)
7922 priv->sensitive = sensitive;
7924 if (priv->parent == NULL
7925 || gtk_widget_is_sensitive (priv->parent))
7929 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7932 data.operation = STATE_CHANGE_UNSET;
7934 data.operation = STATE_CHANGE_SET;
7936 gtk_widget_propagate_state (widget, &data);
7938 gtk_widget_queue_resize (widget);
7941 g_object_notify (G_OBJECT (widget), "sensitive");
7945 * gtk_widget_get_sensitive:
7946 * @widget: a #GtkWidget
7948 * Returns the widget's sensitivity (in the sense of returning
7949 * the value that has been set using gtk_widget_set_sensitive()).
7951 * The effective sensitivity of a widget is however determined by both its
7952 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7954 * Returns: %TRUE if the widget is sensitive
7959 gtk_widget_get_sensitive (GtkWidget *widget)
7961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7963 return widget->priv->sensitive;
7967 * gtk_widget_is_sensitive:
7968 * @widget: a #GtkWidget
7970 * Returns the widget's effective sensitivity, which means
7971 * it is sensitive itself and also its parent widget is sensitive
7973 * Returns: %TRUE if the widget is effectively sensitive
7978 gtk_widget_is_sensitive (GtkWidget *widget)
7980 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7982 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7986 * gtk_widget_set_parent:
7987 * @widget: a #GtkWidget
7988 * @parent: parent container
7990 * This function is useful only when implementing subclasses of
7992 * Sets the container as the parent of @widget, and takes care of
7993 * some details such as updating the state and style of the child
7994 * to reflect its new location. The opposite function is
7995 * gtk_widget_unparent().
7998 gtk_widget_set_parent (GtkWidget *widget,
8001 GtkStateFlags parent_flags;
8002 GtkWidgetPrivate *priv;
8005 g_return_if_fail (GTK_IS_WIDGET (widget));
8006 g_return_if_fail (GTK_IS_WIDGET (parent));
8007 g_return_if_fail (widget != parent);
8009 priv = widget->priv;
8011 if (priv->parent != NULL)
8013 g_warning ("Can't set a parent on widget which has a parent\n");
8016 if (gtk_widget_is_toplevel (widget))
8018 g_warning ("Can't set a parent on a toplevel widget\n");
8022 /* keep this function in sync with gtk_menu_attach_to_widget()
8025 g_object_ref_sink (widget);
8027 gtk_widget_push_verify_invariants (widget);
8029 priv->parent = parent;
8031 parent_flags = gtk_widget_get_state_flags (parent);
8033 /* Merge both old state and current parent state,
8034 * making sure to only propagate the right states */
8035 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8036 data.flags |= priv->state_flags;
8038 data.operation = STATE_CHANGE_REPLACE;
8039 gtk_widget_propagate_state (widget, &data);
8042 gtk_style_context_set_parent (priv->context,
8043 gtk_widget_get_style_context (parent));
8044 gtk_widget_reset_style (widget);
8046 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8047 if (priv->parent->priv->anchored)
8048 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8049 g_object_notify (G_OBJECT (widget), "parent");
8051 /* Enforce realized/mapped invariants
8053 if (gtk_widget_get_realized (priv->parent))
8054 gtk_widget_realize (widget);
8056 if (gtk_widget_get_visible (priv->parent) &&
8057 gtk_widget_get_visible (widget))
8059 if (gtk_widget_get_child_visible (widget) &&
8060 gtk_widget_get_mapped (priv->parent))
8061 gtk_widget_map (widget);
8063 gtk_widget_queue_resize (widget);
8066 /* child may cause parent's expand to change, if the child is
8067 * expanded. If child is not expanded, then it can't modify the
8068 * parent's expand. If the child becomes expanded later then it will
8069 * queue compute_expand then. This optimization plus defaulting
8070 * newly-constructed widgets to need_compute_expand=FALSE should
8071 * mean that initially building a widget tree doesn't have to keep
8072 * walking up setting need_compute_expand on parents over and over.
8074 * We can't change a parent to need to expand unless we're visible.
8076 if (gtk_widget_get_visible (widget) &&
8077 (priv->need_compute_expand ||
8078 priv->computed_hexpand ||
8079 priv->computed_vexpand))
8081 gtk_widget_queue_compute_expand (parent);
8084 gtk_widget_pop_verify_invariants (widget);
8088 * gtk_widget_get_parent:
8089 * @widget: a #GtkWidget
8091 * Returns the parent container of @widget.
8093 * Return value: (transfer none): the parent container of @widget, or %NULL
8096 gtk_widget_get_parent (GtkWidget *widget)
8098 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8100 return widget->priv->parent;
8104 modifier_style_changed (GtkModifierStyle *style,
8107 GtkStyleContext *context;
8109 context = gtk_widget_get_style_context (widget);
8110 gtk_style_context_invalidate (context);
8113 static GtkModifierStyle *
8114 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8116 GtkModifierStyle *style;
8118 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8120 if (G_UNLIKELY (!style))
8122 GtkStyleContext *context;
8124 style = _gtk_modifier_style_new ();
8125 g_object_set_qdata_full (G_OBJECT (widget),
8126 quark_modifier_style,
8128 (GDestroyNotify) g_object_unref);
8130 g_signal_connect (style, "changed",
8131 G_CALLBACK (modifier_style_changed), widget);
8133 context = gtk_widget_get_style_context (widget);
8135 gtk_style_context_add_provider (context,
8136 GTK_STYLE_PROVIDER (style),
8137 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8144 * gtk_widget_override_color:
8145 * @widget: a #GtkWidget
8146 * @state: the state for which to set the color
8147 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8148 * of previous calls to gtk_widget_override_color()
8150 * Sets the color to use for a widget.
8152 * All other style values are left untouched.
8155 * This API is mostly meant as a quick way for applications to
8156 * change a widget appearance. If you are developing a widgets
8157 * library and intend this change to be themeable, it is better
8158 * done by setting meaningful CSS classes and regions in your
8159 * widget/container implementation through gtk_style_context_add_class()
8160 * and gtk_style_context_add_region().
8162 * This way, your widget library can install a #GtkCssProvider
8163 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8164 * to provide a default styling for those widgets that need so, and
8165 * this theming may fully overridden by the user's theme.
8168 * Note that for complex widgets this may bring in undesired
8169 * results (such as uniform background color everywhere), in
8170 * these cases it is better to fully style such widgets through a
8171 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8178 gtk_widget_override_color (GtkWidget *widget,
8179 GtkStateFlags state,
8180 const GdkRGBA *color)
8182 GtkModifierStyle *style;
8184 g_return_if_fail (GTK_IS_WIDGET (widget));
8186 style = _gtk_widget_get_modifier_properties (widget);
8187 _gtk_modifier_style_set_color (style, state, color);
8191 * gtk_widget_override_background_color:
8192 * @widget: a #GtkWidget
8193 * @state: the state for which to set the background color
8194 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8195 * of previous calls to gtk_widget_override_background_color()
8197 * Sets the background color to use for a widget.
8199 * All other style values are left untouched.
8200 * See gtk_widget_override_color().
8205 gtk_widget_override_background_color (GtkWidget *widget,
8206 GtkStateFlags state,
8207 const GdkRGBA *color)
8209 GtkModifierStyle *style;
8211 g_return_if_fail (GTK_IS_WIDGET (widget));
8213 style = _gtk_widget_get_modifier_properties (widget);
8214 _gtk_modifier_style_set_background_color (style, state, color);
8218 * gtk_widget_override_font:
8219 * @widget: a #GtkWidget
8220 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8221 * the effect of previous calls to gtk_widget_override_font()
8223 * Sets the font to use for a widget. All other style values are
8224 * left untouched. See gtk_widget_override_color().
8229 gtk_widget_override_font (GtkWidget *widget,
8230 const PangoFontDescription *font_desc)
8232 GtkModifierStyle *style;
8234 g_return_if_fail (GTK_IS_WIDGET (widget));
8236 style = _gtk_widget_get_modifier_properties (widget);
8237 _gtk_modifier_style_set_font (style, font_desc);
8241 * gtk_widget_override_symbolic_color:
8242 * @widget: a #GtkWidget
8243 * @name: the name of the symbolic color to modify
8244 * @color: (allow-none): the color to assign (does not need
8245 * to be allocated), or %NULL to undo the effect of previous
8246 * calls to gtk_widget_override_symbolic_color()
8248 * Sets a symbolic color for a widget.
8250 * All other style values are left untouched.
8251 * See gtk_widget_override_color() for overriding the foreground
8252 * or background color.
8257 gtk_widget_override_symbolic_color (GtkWidget *widget,
8259 const GdkRGBA *color)
8261 GtkModifierStyle *style;
8263 g_return_if_fail (GTK_IS_WIDGET (widget));
8265 style = _gtk_widget_get_modifier_properties (widget);
8266 _gtk_modifier_style_map_color (style, name, color);
8270 * gtk_widget_override_cursor:
8271 * @widget: a #GtkWidget
8272 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8273 * allocated), or %NULL to undo the effect of previous calls to
8274 * of gtk_widget_override_cursor().
8275 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8276 * need to be allocated), or %NULL to undo the effect of previous
8277 * calls to of gtk_widget_override_cursor().
8279 * Sets the cursor color to use in a widget, overriding the
8280 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8281 * style properties. All other style values are left untouched.
8282 * See also gtk_widget_modify_style().
8284 * Note that the underlying properties have the #GdkColor type,
8285 * so the alpha value in @primary and @secondary will be ignored.
8290 gtk_widget_override_cursor (GtkWidget *widget,
8291 const GdkRGBA *cursor,
8292 const GdkRGBA *secondary_cursor)
8294 GtkModifierStyle *style;
8296 g_return_if_fail (GTK_IS_WIDGET (widget));
8298 style = _gtk_widget_get_modifier_properties (widget);
8299 _gtk_modifier_style_set_color_property (style,
8301 "cursor-color", cursor);
8302 _gtk_modifier_style_set_color_property (style,
8304 "secondary-cursor-color",
8309 gtk_widget_real_direction_changed (GtkWidget *widget,
8310 GtkTextDirection previous_direction)
8312 gtk_widget_queue_resize (widget);
8316 gtk_widget_real_style_set (GtkWidget *widget,
8317 GtkStyle *previous_style)
8322 GtkWidget *previous_toplevel;
8323 GdkScreen *previous_screen;
8324 GdkScreen *new_screen;
8325 } HierarchyChangedInfo;
8328 do_screen_change (GtkWidget *widget,
8329 GdkScreen *old_screen,
8330 GdkScreen *new_screen)
8332 if (old_screen != new_screen)
8334 GtkWidgetPrivate *priv = widget->priv;
8338 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8340 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8343 _gtk_tooltip_hide (widget);
8345 if (new_screen && priv->context)
8346 gtk_style_context_set_screen (priv->context, new_screen);
8348 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8353 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8354 gpointer client_data)
8356 GtkWidgetPrivate *priv = widget->priv;
8357 HierarchyChangedInfo *info = client_data;
8358 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8359 (priv->parent && priv->parent->priv->anchored);
8361 if (priv->anchored != new_anchored)
8363 g_object_ref (widget);
8365 priv->anchored = new_anchored;
8367 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8368 do_screen_change (widget, info->previous_screen, info->new_screen);
8370 if (GTK_IS_CONTAINER (widget))
8371 gtk_container_forall (GTK_CONTAINER (widget),
8372 gtk_widget_propagate_hierarchy_changed_recurse,
8375 g_object_unref (widget);
8380 * _gtk_widget_propagate_hierarchy_changed:
8381 * @widget: a #GtkWidget
8382 * @previous_toplevel: Previous toplevel
8384 * Propagates changes in the anchored state to a widget and all
8385 * children, unsetting or setting the %ANCHORED flag, and
8386 * emitting #GtkWidget::hierarchy-changed.
8389 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8390 GtkWidget *previous_toplevel)
8392 GtkWidgetPrivate *priv = widget->priv;
8393 HierarchyChangedInfo info;
8395 info.previous_toplevel = previous_toplevel;
8396 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8398 if (gtk_widget_is_toplevel (widget) ||
8399 (priv->parent && priv->parent->priv->anchored))
8400 info.new_screen = gtk_widget_get_screen (widget);
8402 info.new_screen = NULL;
8404 if (info.previous_screen)
8405 g_object_ref (info.previous_screen);
8406 if (previous_toplevel)
8407 g_object_ref (previous_toplevel);
8409 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8411 if (previous_toplevel)
8412 g_object_unref (previous_toplevel);
8413 if (info.previous_screen)
8414 g_object_unref (info.previous_screen);
8418 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8419 gpointer client_data)
8421 HierarchyChangedInfo *info = client_data;
8423 g_object_ref (widget);
8425 do_screen_change (widget, info->previous_screen, info->new_screen);
8427 if (GTK_IS_CONTAINER (widget))
8428 gtk_container_forall (GTK_CONTAINER (widget),
8429 gtk_widget_propagate_screen_changed_recurse,
8432 g_object_unref (widget);
8436 * gtk_widget_is_composited:
8437 * @widget: a #GtkWidget
8439 * Whether @widget can rely on having its alpha channel
8440 * drawn correctly. On X11 this function returns whether a
8441 * compositing manager is running for @widget's screen.
8443 * Please note that the semantics of this call will change
8444 * in the future if used on a widget that has a composited
8445 * window in its hierarchy (as set by gdk_window_set_composited()).
8447 * Return value: %TRUE if the widget can rely on its alpha
8448 * channel being drawn correctly.
8453 gtk_widget_is_composited (GtkWidget *widget)
8457 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8459 screen = gtk_widget_get_screen (widget);
8461 return gdk_screen_is_composited (screen);
8465 propagate_composited_changed (GtkWidget *widget,
8468 if (GTK_IS_CONTAINER (widget))
8470 gtk_container_forall (GTK_CONTAINER (widget),
8471 propagate_composited_changed,
8475 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8479 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8481 propagate_composited_changed (widget, NULL);
8485 * _gtk_widget_propagate_screen_changed:
8486 * @widget: a #GtkWidget
8487 * @previous_screen: Previous screen
8489 * Propagates changes in the screen for a widget to all
8490 * children, emitting #GtkWidget::screen-changed.
8493 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8494 GdkScreen *previous_screen)
8496 HierarchyChangedInfo info;
8498 info.previous_screen = previous_screen;
8499 info.new_screen = gtk_widget_get_screen (widget);
8501 if (previous_screen)
8502 g_object_ref (previous_screen);
8504 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8506 if (previous_screen)
8507 g_object_unref (previous_screen);
8511 reset_style_recurse (GtkWidget *widget, gpointer data)
8513 if (widget->priv->path)
8515 gtk_widget_path_free (widget->priv->path);
8516 widget->priv->path = NULL;
8519 gtk_widget_get_path (widget);
8521 if (GTK_IS_CONTAINER (widget))
8522 gtk_container_forall (GTK_CONTAINER (widget),
8523 reset_style_recurse,
8528 * gtk_widget_reset_style:
8529 * @widget: a #GtkWidget
8531 * Updates the style context of @widget and all descendents
8532 * by updating its widget path. #GtkContainer<!-- -->s may want
8533 * to use this on a child when reordering it in a way that a different
8534 * style might apply to it. See also gtk_container_get_path_for_child().
8539 gtk_widget_reset_style (GtkWidget *widget)
8541 g_return_if_fail (GTK_IS_WIDGET (widget));
8543 reset_style_recurse (widget, NULL);
8545 g_list_foreach (widget->priv->attached_windows,
8546 (GFunc) reset_style_recurse, NULL);
8549 #ifdef G_ENABLE_DEBUG
8551 /* Verify invariants, see docs/widget_system.txt for notes on much of
8552 * this. Invariants may be temporarily broken while we're in the
8553 * process of updating state, of course, so you can only
8554 * verify_invariants() after a given operation is complete.
8555 * Use push/pop_verify_invariants to help with that.
8558 gtk_widget_verify_invariants (GtkWidget *widget)
8562 if (widget->priv->verifying_invariants_count > 0)
8565 parent = widget->priv->parent;
8567 if (widget->priv->mapped)
8569 /* Mapped implies ... */
8571 if (!widget->priv->realized)
8572 g_warning ("%s %p is mapped but not realized",
8573 G_OBJECT_TYPE_NAME (widget), widget);
8575 if (!widget->priv->visible)
8576 g_warning ("%s %p is mapped but not visible",
8577 G_OBJECT_TYPE_NAME (widget), widget);
8579 if (!widget->priv->toplevel)
8581 if (!widget->priv->child_visible)
8582 g_warning ("%s %p is mapped but not child_visible",
8583 G_OBJECT_TYPE_NAME (widget), widget);
8588 /* Not mapped implies... */
8591 /* This check makes sense for normal toplevels, but for
8592 * something like a toplevel that is embedded within a clutter
8593 * state, mapping may depend on external factors.
8595 if (widget->priv->toplevel)
8597 if (widget->priv->visible)
8598 g_warning ("%s %p toplevel is visible but not mapped",
8599 G_OBJECT_TYPE_NAME (widget), widget);
8604 /* Parent related checks aren't possible if parent has
8605 * verifying_invariants_count > 0 because parent needs to recurse
8606 * children first before the invariants will hold.
8608 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8611 parent->priv->realized)
8613 /* Parent realized implies... */
8616 /* This is in widget_system.txt but appears to fail
8617 * because there's no gtk_container_realize() that
8618 * realizes all children... instead we just lazily
8619 * wait for map to fix things up.
8621 if (!widget->priv->realized)
8622 g_warning ("%s %p is realized but child %s %p is not realized",
8623 G_OBJECT_TYPE_NAME (parent), parent,
8624 G_OBJECT_TYPE_NAME (widget), widget);
8627 else if (!widget->priv->toplevel)
8629 /* No parent or parent not realized on non-toplevel implies... */
8631 if (widget->priv->realized && !widget->priv->in_reparent)
8632 g_warning ("%s %p is not realized but child %s %p is realized",
8633 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8634 G_OBJECT_TYPE_NAME (widget), widget);
8638 parent->priv->mapped &&
8639 widget->priv->visible &&
8640 widget->priv->child_visible)
8642 /* Parent mapped and we are visible implies... */
8644 if (!widget->priv->mapped)
8645 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8646 G_OBJECT_TYPE_NAME (parent), parent,
8647 G_OBJECT_TYPE_NAME (widget), widget);
8649 else if (!widget->priv->toplevel)
8651 /* No parent or parent not mapped on non-toplevel implies... */
8653 if (widget->priv->mapped && !widget->priv->in_reparent)
8654 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8655 G_OBJECT_TYPE_NAME (widget), widget,
8656 widget->priv->visible,
8657 widget->priv->child_visible,
8658 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8659 parent ? parent->priv->mapped : FALSE);
8663 if (!widget->priv->realized)
8665 /* Not realized implies... */
8668 /* widget_system.txt says these hold, but they don't. */
8669 if (widget->priv->resize_pending)
8670 g_warning ("%s %p resize pending but not realized",
8671 G_OBJECT_TYPE_NAME (widget), widget);
8673 if (widget->priv->alloc_needed)
8674 g_warning ("%s %p alloc needed but not realized",
8675 G_OBJECT_TYPE_NAME (widget), widget);
8677 if (widget->priv->width_request_needed)
8678 g_warning ("%s %p width request needed but not realized",
8679 G_OBJECT_TYPE_NAME (widget), widget);
8681 if (widget->priv->height_request_needed)
8682 g_warning ("%s %p height request needed but not realized",
8683 G_OBJECT_TYPE_NAME (widget), widget);
8688 /* The point of this push/pop is that invariants may not hold while
8689 * we're busy making changes. So we only check at the outermost call
8690 * on the call stack, after we finish updating everything.
8693 gtk_widget_push_verify_invariants (GtkWidget *widget)
8695 widget->priv->verifying_invariants_count += 1;
8699 gtk_widget_verify_child_invariants (GtkWidget *widget,
8700 gpointer client_data)
8702 /* We don't recurse further; this is a one-level check. */
8703 gtk_widget_verify_invariants (widget);
8707 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8709 g_assert (widget->priv->verifying_invariants_count > 0);
8711 widget->priv->verifying_invariants_count -= 1;
8713 if (widget->priv->verifying_invariants_count == 0)
8715 gtk_widget_verify_invariants (widget);
8717 if (GTK_IS_CONTAINER (widget))
8719 /* Check one level of children, because our
8720 * push_verify_invariants() will have prevented some of the
8721 * checks. This does not recurse because if recursion is
8722 * needed, it will happen naturally as each child has a
8723 * push/pop on that child. For example if we're recursively
8724 * mapping children, we'll push/pop on each child as we map
8727 gtk_container_forall (GTK_CONTAINER (widget),
8728 gtk_widget_verify_child_invariants,
8733 #endif /* G_ENABLE_DEBUG */
8735 static PangoContext *
8736 gtk_widget_peek_pango_context (GtkWidget *widget)
8738 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8742 * gtk_widget_get_pango_context:
8743 * @widget: a #GtkWidget
8745 * Gets a #PangoContext with the appropriate font map, font description,
8746 * and base direction for this widget. Unlike the context returned
8747 * by gtk_widget_create_pango_context(), this context is owned by
8748 * the widget (it can be used until the screen for the widget changes
8749 * or the widget is removed from its toplevel), and will be updated to
8750 * match any changes to the widget's attributes.
8752 * If you create and keep a #PangoLayout using this context, you must
8753 * deal with changes to the context by calling pango_layout_context_changed()
8754 * on the layout in response to the #GtkWidget::style-updated and
8755 * #GtkWidget::direction-changed signals for the widget.
8757 * Return value: (transfer none): the #PangoContext for the widget.
8760 gtk_widget_get_pango_context (GtkWidget *widget)
8762 PangoContext *context;
8764 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8766 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8769 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8770 g_object_set_qdata_full (G_OBJECT (widget),
8771 quark_pango_context,
8780 update_pango_context (GtkWidget *widget,
8781 PangoContext *context)
8783 const PangoFontDescription *font_desc;
8784 GtkStyleContext *style_context;
8786 style_context = gtk_widget_get_style_context (widget);
8788 font_desc = gtk_style_context_get_font (style_context,
8789 gtk_widget_get_state_flags (widget));
8791 pango_context_set_font_description (context, font_desc);
8792 pango_context_set_base_dir (context,
8793 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8794 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8798 gtk_widget_update_pango_context (GtkWidget *widget)
8800 PangoContext *context = gtk_widget_peek_pango_context (widget);
8806 update_pango_context (widget, context);
8808 screen = gtk_widget_get_screen_unchecked (widget);
8811 pango_cairo_context_set_resolution (context,
8812 gdk_screen_get_resolution (screen));
8813 pango_cairo_context_set_font_options (context,
8814 gdk_screen_get_font_options (screen));
8820 * gtk_widget_create_pango_context:
8821 * @widget: a #GtkWidget
8823 * Creates a new #PangoContext with the appropriate font map,
8824 * font description, and base direction for drawing text for
8825 * this widget. See also gtk_widget_get_pango_context().
8827 * Return value: (transfer full): the new #PangoContext
8830 gtk_widget_create_pango_context (GtkWidget *widget)
8833 PangoContext *context;
8835 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8837 screen = gtk_widget_get_screen_unchecked (widget);
8840 GTK_NOTE (MULTIHEAD,
8841 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8843 screen = gdk_screen_get_default ();
8846 context = gdk_pango_context_get_for_screen (screen);
8848 update_pango_context (widget, context);
8849 pango_context_set_language (context, gtk_get_default_language ());
8855 * gtk_widget_create_pango_layout:
8856 * @widget: a #GtkWidget
8857 * @text: text to set on the layout (can be %NULL)
8859 * Creates a new #PangoLayout with the appropriate font map,
8860 * font description, and base direction for drawing text for
8863 * If you keep a #PangoLayout created in this way around, in order to
8864 * notify the layout of changes to the base direction or font of this
8865 * widget, you must call pango_layout_context_changed() in response to
8866 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8869 * Return value: (transfer full): the new #PangoLayout
8872 gtk_widget_create_pango_layout (GtkWidget *widget,
8875 PangoLayout *layout;
8876 PangoContext *context;
8878 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8880 context = gtk_widget_get_pango_context (widget);
8881 layout = pango_layout_new (context);
8884 pango_layout_set_text (layout, text, -1);
8890 * gtk_widget_render_icon_pixbuf:
8891 * @widget: a #GtkWidget
8892 * @stock_id: a stock ID
8893 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8894 * render at the size of the source and don't scale (if there are
8895 * multiple source sizes, GTK+ picks one of the available sizes).
8897 * A convenience function that uses the theme engine and style
8898 * settings for @widget to look up @stock_id and render it to
8899 * a pixbuf. @stock_id should be a stock icon ID such as
8900 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8901 * such as #GTK_ICON_SIZE_MENU.
8903 * The pixels in the returned #GdkPixbuf are shared with the rest of
8904 * the application and should not be modified. The pixbuf should be freed
8905 * after use with g_object_unref().
8907 * Return value: (transfer full): a new pixbuf, or %NULL if the
8908 * stock ID wasn't known
8913 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8914 const gchar *stock_id,
8917 GtkStyleContext *context;
8918 GtkIconSet *icon_set;
8920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8921 g_return_val_if_fail (stock_id != NULL, NULL);
8922 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8924 context = gtk_widget_get_style_context (widget);
8925 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8927 if (icon_set == NULL)
8930 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8934 * gtk_widget_set_parent_window:
8935 * @widget: a #GtkWidget.
8936 * @parent_window: the new parent window.
8938 * Sets a non default parent window for @widget.
8940 * For GtkWindow classes, setting a @parent_window effects whether
8941 * the window is a toplevel window or can be embedded into other
8945 * For GtkWindow classes, this needs to be called before the
8946 * window is realized.
8951 gtk_widget_set_parent_window (GtkWidget *widget,
8952 GdkWindow *parent_window)
8954 GdkWindow *old_parent_window;
8956 g_return_if_fail (GTK_IS_WIDGET (widget));
8958 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8959 quark_parent_window);
8961 if (parent_window != old_parent_window)
8965 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8967 if (old_parent_window)
8968 g_object_unref (old_parent_window);
8970 g_object_ref (parent_window);
8972 /* Unset toplevel flag when adding a parent window to a widget,
8973 * this is the primary entry point to allow toplevels to be
8976 #ifdef GDK_WINDOWING_X11
8977 is_plug = GTK_IS_PLUG (widget);
8981 if (GTK_IS_WINDOW (widget) && !is_plug)
8982 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8987 * gtk_widget_get_parent_window:
8988 * @widget: a #GtkWidget.
8990 * Gets @widget's parent window.
8992 * Returns: (transfer none): the parent window of @widget.
8995 gtk_widget_get_parent_window (GtkWidget *widget)
8997 GtkWidgetPrivate *priv;
8998 GdkWindow *parent_window;
9000 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9002 priv = widget->priv;
9004 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9006 return (parent_window != NULL) ? parent_window :
9007 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9012 * gtk_widget_set_child_visible:
9013 * @widget: a #GtkWidget
9014 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9016 * Sets whether @widget should be mapped along with its when its parent
9017 * is mapped and @widget has been shown with gtk_widget_show().
9019 * The child visibility can be set for widget before it is added to
9020 * a container with gtk_widget_set_parent(), to avoid mapping
9021 * children unnecessary before immediately unmapping them. However
9022 * it will be reset to its default state of %TRUE when the widget
9023 * is removed from a container.
9025 * Note that changing the child visibility of a widget does not
9026 * queue a resize on the widget. Most of the time, the size of
9027 * a widget is computed from all visible children, whether or
9028 * not they are mapped. If this is not the case, the container
9029 * can queue a resize itself.
9031 * This function is only useful for container implementations and
9032 * never should be called by an application.
9035 gtk_widget_set_child_visible (GtkWidget *widget,
9036 gboolean is_visible)
9038 GtkWidgetPrivate *priv;
9040 g_return_if_fail (GTK_IS_WIDGET (widget));
9041 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9043 priv = widget->priv;
9045 g_object_ref (widget);
9046 gtk_widget_verify_invariants (widget);
9049 priv->child_visible = TRUE;
9052 GtkWidget *toplevel;
9054 priv->child_visible = FALSE;
9056 toplevel = gtk_widget_get_toplevel (widget);
9057 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9058 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9061 if (priv->parent && gtk_widget_get_realized (priv->parent))
9063 if (gtk_widget_get_mapped (priv->parent) &&
9064 priv->child_visible &&
9065 gtk_widget_get_visible (widget))
9066 gtk_widget_map (widget);
9068 gtk_widget_unmap (widget);
9071 gtk_widget_verify_invariants (widget);
9072 g_object_unref (widget);
9076 * gtk_widget_get_child_visible:
9077 * @widget: a #GtkWidget
9079 * Gets the value set with gtk_widget_set_child_visible().
9080 * If you feel a need to use this function, your code probably
9081 * needs reorganization.
9083 * This function is only useful for container implementations and
9084 * never should be called by an application.
9086 * Return value: %TRUE if the widget is mapped with the parent.
9089 gtk_widget_get_child_visible (GtkWidget *widget)
9091 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9093 return widget->priv->child_visible;
9097 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9099 GtkWidget *toplevel;
9101 toplevel = gtk_widget_get_toplevel (widget);
9103 if (gtk_widget_is_toplevel (toplevel))
9105 if (GTK_IS_WINDOW (toplevel))
9106 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9107 else if (GTK_IS_INVISIBLE (toplevel))
9108 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9115 * gtk_widget_get_screen:
9116 * @widget: a #GtkWidget
9118 * Get the #GdkScreen from the toplevel window associated with
9119 * this widget. This function can only be called after the widget
9120 * has been added to a widget hierarchy with a #GtkWindow
9123 * In general, you should only create screen specific
9124 * resources when a widget has been realized, and you should
9125 * free those resources when the widget is unrealized.
9127 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9132 gtk_widget_get_screen (GtkWidget *widget)
9136 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9138 screen = gtk_widget_get_screen_unchecked (widget);
9145 g_warning (G_STRLOC ": Can't get associated screen"
9146 " for a widget unless it is inside a toplevel GtkWindow\n"
9147 " widget type is %s associated top level type is %s",
9148 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9149 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9151 return gdk_screen_get_default ();
9156 * gtk_widget_has_screen:
9157 * @widget: a #GtkWidget
9159 * Checks whether there is a #GdkScreen is associated with
9160 * this widget. All toplevel widgets have an associated
9161 * screen, and all widgets added into a hierarchy with a toplevel
9162 * window at the top.
9164 * Return value: %TRUE if there is a #GdkScreen associcated
9170 gtk_widget_has_screen (GtkWidget *widget)
9172 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9174 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9178 * gtk_widget_get_display:
9179 * @widget: a #GtkWidget
9181 * Get the #GdkDisplay for the toplevel window associated with
9182 * this widget. This function can only be called after the widget
9183 * has been added to a widget hierarchy with a #GtkWindow at the top.
9185 * In general, you should only create display specific
9186 * resources when a widget has been realized, and you should
9187 * free those resources when the widget is unrealized.
9189 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9194 gtk_widget_get_display (GtkWidget *widget)
9196 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9198 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9202 * gtk_widget_get_root_window:
9203 * @widget: a #GtkWidget
9205 * Get the root window where this widget is located. This function can
9206 * only be called after the widget has been added to a widget
9207 * hierarchy with #GtkWindow at the top.
9209 * The root window is useful for such purposes as creating a popup
9210 * #GdkWindow associated with the window. In general, you should only
9211 * create display specific resources when a widget has been realized,
9212 * and you should free those resources when the widget is unrealized.
9214 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9219 gtk_widget_get_root_window (GtkWidget *widget)
9221 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9223 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9227 * gtk_widget_child_focus:
9228 * @widget: a #GtkWidget
9229 * @direction: direction of focus movement
9231 * This function is used by custom widget implementations; if you're
9232 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9233 * to a particular widget, and gtk_container_set_focus_chain() to
9234 * change the focus tab order. So you may want to investigate those
9235 * functions instead.
9237 * gtk_widget_child_focus() is called by containers as the user moves
9238 * around the window using keyboard shortcuts. @direction indicates
9239 * what kind of motion is taking place (up, down, left, right, tab
9240 * forward, tab backward). gtk_widget_child_focus() emits the
9241 * #GtkWidget::focus signal; widgets override the default handler
9242 * for this signal in order to implement appropriate focus behavior.
9244 * The default ::focus handler for a widget should return %TRUE if
9245 * moving in @direction left the focus on a focusable location inside
9246 * that widget, and %FALSE if moving in @direction moved the focus
9247 * outside the widget. If returning %TRUE, widgets normally
9248 * call gtk_widget_grab_focus() to place the focus accordingly;
9249 * if returning %FALSE, they don't modify the current focus location.
9251 * Return value: %TRUE if focus ended up inside @widget
9254 gtk_widget_child_focus (GtkWidget *widget,
9255 GtkDirectionType direction)
9257 gboolean return_val;
9259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9261 if (!gtk_widget_get_visible (widget) ||
9262 !gtk_widget_is_sensitive (widget))
9265 /* child widgets must set CAN_FOCUS, containers
9266 * don't have to though.
9268 if (!GTK_IS_CONTAINER (widget) &&
9269 !gtk_widget_get_can_focus (widget))
9272 g_signal_emit (widget,
9273 widget_signals[FOCUS],
9275 direction, &return_val);
9281 * gtk_widget_keynav_failed:
9282 * @widget: a #GtkWidget
9283 * @direction: direction of focus movement
9285 * This function should be called whenever keyboard navigation within
9286 * a single widget hits a boundary. The function emits the
9287 * #GtkWidget::keynav-failed signal on the widget and its return
9288 * value should be interpreted in a way similar to the return value of
9289 * gtk_widget_child_focus():
9291 * When %TRUE is returned, stay in the widget, the failed keyboard
9292 * navigation is Ok and/or there is nowhere we can/should move the
9295 * When %FALSE is returned, the caller should continue with keyboard
9296 * navigation outside the widget, e.g. by calling
9297 * gtk_widget_child_focus() on the widget's toplevel.
9299 * The default ::keynav-failed handler returns %TRUE for
9300 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9301 * values of #GtkDirectionType, it looks at the
9302 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9303 * if the setting is %TRUE. This way the entire user interface
9304 * becomes cursor-navigatable on input devices such as mobile phones
9305 * which only have cursor keys but no tab key.
9307 * Whenever the default handler returns %TRUE, it also calls
9308 * gtk_widget_error_bell() to notify the user of the failed keyboard
9311 * A use case for providing an own implementation of ::keynav-failed
9312 * (either by connecting to it or by overriding it) would be a row of
9313 * #GtkEntry widgets where the user should be able to navigate the
9314 * entire row with the cursor keys, as e.g. known from user interfaces
9315 * that require entering license keys.
9317 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9318 * if the emitting widget should try to handle the keyboard
9319 * navigation attempt in its parent container(s).
9324 gtk_widget_keynav_failed (GtkWidget *widget,
9325 GtkDirectionType direction)
9327 gboolean return_val;
9329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9331 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9332 direction, &return_val);
9338 * gtk_widget_error_bell:
9339 * @widget: a #GtkWidget
9341 * Notifies the user about an input-related error on this widget.
9342 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9343 * gdk_window_beep(), otherwise it does nothing.
9345 * Note that the effect of gdk_window_beep() can be configured in many
9346 * ways, depending on the windowing backend and the desktop environment
9347 * or window manager that is used.
9352 gtk_widget_error_bell (GtkWidget *widget)
9354 GtkWidgetPrivate *priv;
9355 GtkSettings* settings;
9358 g_return_if_fail (GTK_IS_WIDGET (widget));
9360 priv = widget->priv;
9362 settings = gtk_widget_get_settings (widget);
9366 g_object_get (settings,
9367 "gtk-error-bell", &beep,
9370 if (beep && priv->window)
9371 gdk_window_beep (priv->window);
9375 gtk_widget_set_usize_internal (GtkWidget *widget,
9378 GtkQueueResizeFlags flags)
9380 GtkWidgetAuxInfo *aux_info;
9381 gboolean changed = FALSE;
9383 g_object_freeze_notify (G_OBJECT (widget));
9385 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9387 if (width > -2 && aux_info->width != width)
9389 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9390 g_object_notify (G_OBJECT (widget), "width-request");
9391 aux_info->width = width;
9394 if (height > -2 && aux_info->height != height)
9396 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9397 g_object_notify (G_OBJECT (widget), "height-request");
9398 aux_info->height = height;
9402 if (gtk_widget_get_visible (widget) && changed)
9404 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9405 gtk_widget_queue_resize (widget);
9407 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9410 g_object_thaw_notify (G_OBJECT (widget));
9414 * gtk_widget_set_size_request:
9415 * @widget: a #GtkWidget
9416 * @width: width @widget should request, or -1 to unset
9417 * @height: height @widget should request, or -1 to unset
9419 * Sets the minimum size of a widget; that is, the widget's size
9420 * request will be @width by @height. You can use this function to
9421 * force a widget to be either larger or smaller than it normally
9424 * In most cases, gtk_window_set_default_size() is a better choice for
9425 * toplevel windows than this function; setting the default size will
9426 * still allow users to shrink the window. Setting the size request
9427 * will force them to leave the window at least as large as the size
9428 * request. When dealing with window sizes,
9429 * gtk_window_set_geometry_hints() can be a useful function as well.
9431 * Note the inherent danger of setting any fixed size - themes,
9432 * translations into other languages, different fonts, and user action
9433 * can all change the appropriate size for a given widget. So, it's
9434 * basically impossible to hardcode a size that will always be
9437 * The size request of a widget is the smallest size a widget can
9438 * accept while still functioning well and drawing itself correctly.
9439 * However in some strange cases a widget may be allocated less than
9440 * its requested size, and in many cases a widget may be allocated more
9441 * space than it requested.
9443 * If the size request in a given direction is -1 (unset), then
9444 * the "natural" size request of the widget will be used instead.
9446 * Widgets can't actually be allocated a size less than 1 by 1, but
9447 * you can pass 0,0 to this function to mean "as small as possible."
9449 * The size request set here does not include any margin from the
9450 * #GtkWidget properties margin-left, margin-right, margin-top, and
9451 * margin-bottom, but it does include pretty much all other padding
9452 * or border properties set by any subclass of #GtkWidget.
9455 gtk_widget_set_size_request (GtkWidget *widget,
9459 g_return_if_fail (GTK_IS_WIDGET (widget));
9460 g_return_if_fail (width >= -1);
9461 g_return_if_fail (height >= -1);
9468 gtk_widget_set_usize_internal (widget, width, height, 0);
9473 * gtk_widget_get_size_request:
9474 * @widget: a #GtkWidget
9475 * @width: (out) (allow-none): return location for width, or %NULL
9476 * @height: (out) (allow-none): return location for height, or %NULL
9478 * Gets the size request that was explicitly set for the widget using
9479 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9480 * @height indicates that that dimension has not been set explicitly
9481 * and the natural requisition of the widget will be used intead. See
9482 * gtk_widget_set_size_request(). To get the size a widget will
9483 * actually request, call gtk_widget_get_preferred_size() instead of
9487 gtk_widget_get_size_request (GtkWidget *widget,
9491 const GtkWidgetAuxInfo *aux_info;
9493 g_return_if_fail (GTK_IS_WIDGET (widget));
9495 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9498 *width = aux_info->width;
9501 *height = aux_info->height;
9505 * _gtk_widget_override_size_request:
9506 * @widget: a #GtkWidget
9507 * @width: new forced minimum width
9508 * @height: new forced minimum height
9509 * @old_width: location to store previous forced minimum width
9510 * @old_height: location to store previous forced minumum height
9512 * Temporarily establishes a forced minimum size for a widget; this
9513 * is used by GtkWindow when calculating the size to add to the
9514 * window's geometry widget. Cached sizes for the widget and its
9515 * parents are invalidated, so that subsequent calls to the size
9516 * negotiation machinery produce the overriden result, but the
9517 * widget is not queued for relayout or redraw. The old size must
9518 * be restored with _gtk_widget_restore_size_request() or things
9522 _gtk_widget_override_size_request (GtkWidget *widget,
9528 gtk_widget_get_size_request (widget, old_width, old_height);
9529 gtk_widget_set_usize_internal (widget, width, height,
9530 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9534 * _gtk_widget_restore_size_request:
9535 * @widget: a #GtkWidget
9536 * @old_width: saved forced minimum size
9537 * @old_height: saved forced minimum size
9539 * Undoes the operation of_gtk_widget_override_size_request().
9542 _gtk_widget_restore_size_request (GtkWidget *widget,
9546 gtk_widget_set_usize_internal (widget, old_width, old_height,
9547 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9551 * gtk_widget_set_events:
9552 * @widget: a #GtkWidget
9553 * @events: event mask
9555 * Sets the event mask (see #GdkEventMask) for a widget. The event
9556 * mask determines which events a widget will receive. Keep in mind
9557 * that different widgets have different default event masks, and by
9558 * changing the event mask you may disrupt a widget's functionality,
9559 * so be careful. This function must be called while a widget is
9560 * unrealized. Consider gtk_widget_add_events() for widgets that are
9561 * already realized, or if you want to preserve the existing event
9562 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9563 * to get events on those widgets, place them inside a #GtkEventBox
9564 * and receive events on the event box.
9567 gtk_widget_set_events (GtkWidget *widget,
9570 g_return_if_fail (GTK_IS_WIDGET (widget));
9571 g_return_if_fail (!gtk_widget_get_realized (widget));
9573 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9574 GINT_TO_POINTER (events));
9575 g_object_notify (G_OBJECT (widget), "events");
9579 * gtk_widget_set_device_events:
9580 * @widget: a #GtkWidget
9581 * @device: a #GdkDevice
9582 * @events: event mask
9584 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9585 * mask determines which events a widget will receive from @device. Keep
9586 * in mind that different widgets have different default event masks, and by
9587 * changing the event mask you may disrupt a widget's functionality,
9588 * so be careful. This function must be called while a widget is
9589 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9590 * already realized, or if you want to preserve the existing event
9591 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9592 * to get events on those widgets, place them inside a #GtkEventBox
9593 * and receive events on the event box.
9598 gtk_widget_set_device_events (GtkWidget *widget,
9600 GdkEventMask events)
9602 GHashTable *device_events;
9604 g_return_if_fail (GTK_IS_WIDGET (widget));
9605 g_return_if_fail (GDK_IS_DEVICE (device));
9606 g_return_if_fail (!gtk_widget_get_realized (widget));
9608 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9610 if (G_UNLIKELY (!device_events))
9612 device_events = g_hash_table_new (NULL, NULL);
9613 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9614 (GDestroyNotify) g_hash_table_unref);
9617 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9621 * gtk_widget_set_device_enabled:
9622 * @widget: a #GtkWidget
9623 * @device: a #GdkDevice
9624 * @enabled: whether to enable the device
9626 * Enables or disables a #GdkDevice to interact with @widget
9627 * and all its children.
9629 * It does so by descending through the #GdkWindow hierarchy
9630 * and enabling the same mask that is has for core events
9631 * (i.e. the one that gdk_window_get_events() returns).
9636 gtk_widget_set_device_enabled (GtkWidget *widget,
9640 GList *enabled_devices;
9642 g_return_if_fail (GTK_IS_WIDGET (widget));
9643 g_return_if_fail (GDK_IS_DEVICE (device));
9645 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9646 enabled_devices = g_list_append (enabled_devices, device);
9648 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9649 enabled_devices, (GDestroyNotify) g_list_free);;
9651 if (gtk_widget_get_realized (widget))
9652 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9656 * gtk_widget_get_device_enabled:
9657 * @widget: a #GtkWidget
9658 * @device: a #GdkDevice
9660 * Returns whether @device can interact with @widget and its
9661 * children. See gtk_widget_set_device_enabled().
9663 * Return value: %TRUE is @device is enabled for @widget
9668 gtk_widget_get_device_enabled (GtkWidget *widget,
9671 GList *enabled_devices;
9673 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9674 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9676 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9678 return g_list_find (enabled_devices, device) != NULL;
9682 gtk_widget_add_events_internal_list (GtkWidget *widget,
9689 for (l = window_list; l != NULL; l = l->next)
9691 GdkWindow *window = l->data;
9694 gdk_window_get_user_data (window, &user_data);
9695 if (user_data == widget)
9700 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9702 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9704 children = gdk_window_get_children (window);
9705 gtk_widget_add_events_internal_list (widget, device, events, children);
9706 g_list_free (children);
9712 gtk_widget_add_events_internal (GtkWidget *widget,
9716 GtkWidgetPrivate *priv = widget->priv;
9719 if (!gtk_widget_get_has_window (widget))
9720 window_list = gdk_window_get_children (priv->window);
9722 window_list = g_list_prepend (NULL, priv->window);
9724 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9726 g_list_free (window_list);
9730 * gtk_widget_add_events:
9731 * @widget: a #GtkWidget
9732 * @events: an event mask, see #GdkEventMask
9734 * Adds the events in the bitfield @events to the event mask for
9735 * @widget. See gtk_widget_set_events() for details.
9738 gtk_widget_add_events (GtkWidget *widget,
9743 g_return_if_fail (GTK_IS_WIDGET (widget));
9745 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9746 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9747 GINT_TO_POINTER (old_events | events));
9749 if (gtk_widget_get_realized (widget))
9751 gtk_widget_add_events_internal (widget, NULL, events);
9752 gtk_widget_update_devices_mask (widget, FALSE);
9755 g_object_notify (G_OBJECT (widget), "events");
9759 * gtk_widget_add_device_events:
9760 * @widget: a #GtkWidget
9761 * @device: a #GdkDevice
9762 * @events: an event mask, see #GdkEventMask
9764 * Adds the device events in the bitfield @events to the event mask for
9765 * @widget. See gtk_widget_set_device_events() for details.
9770 gtk_widget_add_device_events (GtkWidget *widget,
9772 GdkEventMask events)
9774 GdkEventMask old_events;
9775 GHashTable *device_events;
9777 g_return_if_fail (GTK_IS_WIDGET (widget));
9778 g_return_if_fail (GDK_IS_DEVICE (device));
9780 old_events = gtk_widget_get_device_events (widget, device);
9782 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9784 if (G_UNLIKELY (!device_events))
9786 device_events = g_hash_table_new (NULL, NULL);
9787 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9788 (GDestroyNotify) g_hash_table_unref);
9791 g_hash_table_insert (device_events, device,
9792 GUINT_TO_POINTER (old_events | events));
9794 if (gtk_widget_get_realized (widget))
9795 gtk_widget_add_events_internal (widget, device, events);
9797 g_object_notify (G_OBJECT (widget), "events");
9801 * gtk_widget_get_toplevel:
9802 * @widget: a #GtkWidget
9804 * This function returns the topmost widget in the container hierarchy
9805 * @widget is a part of. If @widget has no parent widgets, it will be
9806 * returned as the topmost widget. No reference will be added to the
9807 * returned widget; it should not be unreferenced.
9809 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9810 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9812 * %NULL if @widget wasn't inside a toplevel window, and if the
9813 * window was inside a #GtkWindow-derived widget which was in turn
9814 * inside the toplevel #GtkWindow. While the second case may
9815 * seem unlikely, it actually happens when a #GtkPlug is embedded
9816 * inside a #GtkSocket within the same application.
9818 * To reliably find the toplevel #GtkWindow, use
9819 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9820 * is set on the result.
9822 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9823 * if (gtk_widget_is_toplevel (toplevel))
9825 * /* Perform action on toplevel. */
9829 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9830 * if there's no ancestor.
9833 gtk_widget_get_toplevel (GtkWidget *widget)
9835 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9837 while (widget->priv->parent)
9838 widget = widget->priv->parent;
9844 * gtk_widget_get_ancestor:
9845 * @widget: a #GtkWidget
9846 * @widget_type: ancestor type
9848 * Gets the first ancestor of @widget with type @widget_type. For example,
9849 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9850 * the first #GtkBox that's an ancestor of @widget. No reference will be
9851 * added to the returned widget; it should not be unreferenced. See note
9852 * about checking for a toplevel #GtkWindow in the docs for
9853 * gtk_widget_get_toplevel().
9855 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9856 * considers @widget to be an ancestor of itself.
9858 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9861 gtk_widget_get_ancestor (GtkWidget *widget,
9864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9866 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9867 widget = widget->priv->parent;
9869 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9876 * gtk_widget_set_visual:
9877 * @widget: a #GtkWidget
9878 * @visual: visual to be used or %NULL to unset a previous one
9880 * Sets the visual that should be used for by widget and its children for
9881 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9882 * returned by gdk_widget_get_screen(), so handling the
9883 * #GtkWidget::screen-changed signal is necessary.
9885 * Setting a new @visual will not cause @widget to recreate its windows,
9886 * so you should call this function before @widget is realized.
9889 gtk_widget_set_visual (GtkWidget *widget,
9892 g_return_if_fail (GTK_IS_WIDGET (widget));
9893 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9896 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9899 g_object_set_qdata_full (G_OBJECT (widget),
9901 g_object_ref (visual),
9906 * gtk_widget_get_visual:
9907 * @widget: a #GtkWidget
9909 * Gets the visual that will be used to render @widget.
9911 * Return value: (transfer none): the visual for @widget
9914 gtk_widget_get_visual (GtkWidget *widget)
9920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9922 if (gtk_widget_get_has_window (widget) &&
9923 widget->priv->window)
9924 return gdk_window_get_visual (widget->priv->window);
9926 screen = gtk_widget_get_screen (widget);
9928 for (w = widget; w != NULL; w = w->priv->parent)
9930 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9933 if (gdk_visual_get_screen (visual) == screen)
9936 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9937 gtk_widget_get_name (widget));
9941 return gdk_screen_get_system_visual (screen);
9945 * gtk_widget_get_settings:
9946 * @widget: a #GtkWidget
9948 * Gets the settings object holding the settings used for this widget.
9950 * Note that this function can only be called when the #GtkWidget
9951 * is attached to a toplevel, since the settings object is specific
9952 * to a particular #GdkScreen.
9954 * Return value: (transfer none): the relevant #GtkSettings object
9957 gtk_widget_get_settings (GtkWidget *widget)
9959 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9961 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9965 * gtk_widget_get_events:
9966 * @widget: a #GtkWidget
9968 * Returns the event mask for the widget (a bitfield containing flags
9969 * from the #GdkEventMask enumeration). These are the events that the widget
9972 * Return value: event mask for @widget
9975 gtk_widget_get_events (GtkWidget *widget)
9977 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9979 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9983 * gtk_widget_get_device_events:
9984 * @widget: a #GtkWidget
9985 * @device: a #GdkDevice
9987 * Returns the events mask for the widget corresponding to an specific device. These
9988 * are the events that the widget will receive when @device operates on it.
9990 * Returns: device event mask for @widget
9995 gtk_widget_get_device_events (GtkWidget *widget,
9998 GHashTable *device_events;
10000 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10001 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10003 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10005 if (!device_events)
10008 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10012 * gtk_widget_get_pointer:
10013 * @widget: a #GtkWidget
10014 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10015 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10017 * Obtains the location of the mouse pointer in widget coordinates.
10018 * Widget coordinates are a bit odd; for historical reasons, they are
10019 * defined as @widget->window coordinates for widgets that are not
10020 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10021 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10023 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10026 gtk_widget_get_pointer (GtkWidget *widget,
10030 GtkWidgetPrivate *priv;
10032 g_return_if_fail (GTK_IS_WIDGET (widget));
10034 priv = widget->priv;
10041 if (gtk_widget_get_realized (widget))
10043 gdk_window_get_device_position (priv->window,
10044 gdk_device_manager_get_client_pointer (
10045 gdk_display_get_device_manager (
10046 gtk_widget_get_display (widget))),
10049 if (!gtk_widget_get_has_window (widget))
10052 *x -= priv->allocation.x;
10054 *y -= priv->allocation.y;
10060 * gtk_widget_is_ancestor:
10061 * @widget: a #GtkWidget
10062 * @ancestor: another #GtkWidget
10064 * Determines whether @widget is somewhere inside @ancestor, possibly with
10065 * intermediate containers.
10067 * Return value: %TRUE if @ancestor contains @widget as a child,
10068 * grandchild, great grandchild, etc.
10071 gtk_widget_is_ancestor (GtkWidget *widget,
10072 GtkWidget *ancestor)
10074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10075 g_return_val_if_fail (ancestor != NULL, FALSE);
10079 if (widget->priv->parent == ancestor)
10081 widget = widget->priv->parent;
10087 static GQuark quark_composite_name = 0;
10090 * gtk_widget_set_composite_name:
10091 * @widget: a #GtkWidget.
10092 * @name: the name to set
10094 * Sets a widgets composite name. The widget must be
10095 * a composite child of its parent; see gtk_widget_push_composite_child().
10098 gtk_widget_set_composite_name (GtkWidget *widget,
10101 g_return_if_fail (GTK_IS_WIDGET (widget));
10102 g_return_if_fail (widget->priv->composite_child);
10103 g_return_if_fail (name != NULL);
10105 if (!quark_composite_name)
10106 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10108 g_object_set_qdata_full (G_OBJECT (widget),
10109 quark_composite_name,
10115 * gtk_widget_get_composite_name:
10116 * @widget: a #GtkWidget
10118 * Obtains the composite name of a widget.
10120 * Returns: the composite name of @widget, or %NULL if @widget is not
10121 * a composite child. The string should be freed when it is no
10125 gtk_widget_get_composite_name (GtkWidget *widget)
10127 GtkWidgetPrivate *priv;
10129 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10131 priv = widget->priv;
10133 if (widget->priv->composite_child && priv->parent)
10134 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10141 * gtk_widget_push_composite_child:
10143 * Makes all newly-created widgets as composite children until
10144 * the corresponding gtk_widget_pop_composite_child() call.
10146 * A composite child is a child that's an implementation detail of the
10147 * container it's inside and should not be visible to people using the
10148 * container. Composite children aren't treated differently by GTK (but
10149 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10150 * builders might want to treat them in a different way.
10152 * Here is a simple example:
10154 * gtk_widget_push_composite_child ();
10155 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10156 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10157 * gtk_widget_pop_composite_child ();
10158 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10159 * GTK_WIDGET (scrolled_window));
10160 * g_object_ref (scrolled_window->hscrollbar);
10164 gtk_widget_push_composite_child (void)
10166 composite_child_stack++;
10170 * gtk_widget_pop_composite_child:
10172 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10175 gtk_widget_pop_composite_child (void)
10177 if (composite_child_stack)
10178 composite_child_stack--;
10182 gtk_widget_emit_direction_changed (GtkWidget *widget,
10183 GtkTextDirection old_dir)
10185 gtk_widget_update_pango_context (widget);
10187 if (widget->priv->context)
10188 gtk_style_context_set_direction (widget->priv->context,
10189 gtk_widget_get_direction (widget));
10191 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10195 * gtk_widget_set_direction:
10196 * @widget: a #GtkWidget
10197 * @dir: the new direction
10199 * Sets the reading direction on a particular widget. This direction
10200 * controls the primary direction for widgets containing text,
10201 * and also the direction in which the children of a container are
10202 * packed. The ability to set the direction is present in order
10203 * so that correct localization into languages with right-to-left
10204 * reading directions can be done. Generally, applications will
10205 * let the default reading direction present, except for containers
10206 * where the containers are arranged in an order that is explicitely
10207 * visual rather than logical (such as buttons for text justification).
10209 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10210 * set by gtk_widget_set_default_direction() will be used.
10213 gtk_widget_set_direction (GtkWidget *widget,
10214 GtkTextDirection dir)
10216 GtkTextDirection old_dir;
10218 g_return_if_fail (GTK_IS_WIDGET (widget));
10219 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10221 old_dir = gtk_widget_get_direction (widget);
10223 widget->priv->direction = dir;
10225 if (old_dir != gtk_widget_get_direction (widget))
10226 gtk_widget_emit_direction_changed (widget, old_dir);
10230 * gtk_widget_get_direction:
10231 * @widget: a #GtkWidget
10233 * Gets the reading direction for a particular widget. See
10234 * gtk_widget_set_direction().
10236 * Return value: the reading direction for the widget.
10239 gtk_widget_get_direction (GtkWidget *widget)
10241 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10243 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10244 return gtk_default_direction;
10246 return widget->priv->direction;
10250 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10252 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10254 g_object_ref (widget);
10256 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10257 gtk_widget_emit_direction_changed (widget, old_dir);
10259 if (GTK_IS_CONTAINER (widget))
10260 gtk_container_forall (GTK_CONTAINER (widget),
10261 gtk_widget_set_default_direction_recurse,
10264 g_object_unref (widget);
10268 * gtk_widget_set_default_direction:
10269 * @dir: the new default direction. This cannot be
10270 * %GTK_TEXT_DIR_NONE.
10272 * Sets the default reading direction for widgets where the
10273 * direction has not been explicitly set by gtk_widget_set_direction().
10276 gtk_widget_set_default_direction (GtkTextDirection dir)
10278 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10280 if (dir != gtk_default_direction)
10282 GList *toplevels, *tmp_list;
10283 GtkTextDirection old_dir = gtk_default_direction;
10285 gtk_default_direction = dir;
10287 tmp_list = toplevels = gtk_window_list_toplevels ();
10288 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10292 gtk_widget_set_default_direction_recurse (tmp_list->data,
10293 GUINT_TO_POINTER (old_dir));
10294 g_object_unref (tmp_list->data);
10295 tmp_list = tmp_list->next;
10298 g_list_free (toplevels);
10303 * gtk_widget_get_default_direction:
10305 * Obtains the current default reading direction. See
10306 * gtk_widget_set_default_direction().
10308 * Return value: the current default direction.
10311 gtk_widget_get_default_direction (void)
10313 return gtk_default_direction;
10317 gtk_widget_constructed (GObject *object)
10319 GtkWidget *widget = GTK_WIDGET (object);
10320 GtkWidgetPrivate *priv = widget->priv;
10322 /* As strange as it may seem, this may happen on object construction.
10323 * init() implementations of parent types may eventually call this function,
10324 * each with its corresponding GType, which could leave a child
10325 * implementation with a wrong widget type in the widget path
10328 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10330 gtk_widget_path_free (priv->path);
10334 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10338 gtk_widget_dispose (GObject *object)
10340 GtkWidget *widget = GTK_WIDGET (object);
10341 GtkWidgetPrivate *priv = widget->priv;
10344 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10345 else if (gtk_widget_get_visible (widget))
10346 gtk_widget_hide (widget);
10348 priv->visible = FALSE;
10349 if (gtk_widget_get_realized (widget))
10350 gtk_widget_unrealize (widget);
10352 if (!priv->in_destruction)
10354 priv->in_destruction = TRUE;
10355 g_signal_emit (object, widget_signals[DESTROY], 0);
10356 priv->in_destruction = FALSE;
10359 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10363 gtk_widget_real_destroy (GtkWidget *object)
10365 /* gtk_object_destroy() will already hold a refcount on object */
10366 GtkWidget *widget = GTK_WIDGET (object);
10367 GtkWidgetPrivate *priv = widget->priv;
10369 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10371 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10375 gtk_accessible_set_widget (accessible, NULL);
10376 g_object_unref (accessible);
10380 /* wipe accelerator closures (keep order) */
10381 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10382 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10384 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10385 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10387 gtk_grab_remove (widget);
10390 g_object_unref (priv->style);
10391 priv->style = gtk_widget_get_default_style ();
10392 g_object_ref (priv->style);
10396 gtk_widget_finalize (GObject *object)
10398 GtkWidget *widget = GTK_WIDGET (object);
10399 GtkWidgetPrivate *priv = widget->priv;
10400 GtkWidgetAuxInfo *aux_info;
10401 GtkAccessible *accessible;
10403 gtk_grab_remove (widget);
10405 g_object_unref (priv->style);
10406 priv->style = NULL;
10408 g_free (priv->name);
10410 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10412 gtk_widget_aux_info_destroy (aux_info);
10414 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10416 g_object_unref (accessible);
10419 gtk_widget_path_free (priv->path);
10423 _gtk_style_context_set_widget (priv->context, NULL);
10424 g_object_unref (priv->context);
10427 _gtk_widget_free_cached_sizes (widget);
10429 if (g_object_is_floating (object))
10430 g_warning ("A floating object was finalized. This means that someone\n"
10431 "called g_object_unref() on an object that had only a floating\n"
10432 "reference; the initial floating reference is not owned by anyone\n"
10433 "and must be removed with g_object_ref_sink().");
10435 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10438 /*****************************************
10439 * gtk_widget_real_map:
10444 *****************************************/
10447 gtk_widget_real_map (GtkWidget *widget)
10449 GtkWidgetPrivate *priv = widget->priv;
10451 g_assert (gtk_widget_get_realized (widget));
10453 if (!gtk_widget_get_mapped (widget))
10455 gtk_widget_set_mapped (widget, TRUE);
10457 if (gtk_widget_get_has_window (widget))
10458 gdk_window_show (priv->window);
10462 /*****************************************
10463 * gtk_widget_real_unmap:
10468 *****************************************/
10471 gtk_widget_real_unmap (GtkWidget *widget)
10473 GtkWidgetPrivate *priv = widget->priv;
10475 if (gtk_widget_get_mapped (widget))
10477 gtk_widget_set_mapped (widget, FALSE);
10479 if (gtk_widget_get_has_window (widget))
10480 gdk_window_hide (priv->window);
10484 /*****************************************
10485 * gtk_widget_real_realize:
10490 *****************************************/
10493 gtk_widget_real_realize (GtkWidget *widget)
10495 GtkWidgetPrivate *priv = widget->priv;
10497 g_assert (!gtk_widget_get_has_window (widget));
10499 gtk_widget_set_realized (widget, TRUE);
10502 priv->window = gtk_widget_get_parent_window (widget);
10503 g_object_ref (priv->window);
10507 /*****************************************
10508 * gtk_widget_real_unrealize:
10513 *****************************************/
10516 gtk_widget_real_unrealize (GtkWidget *widget)
10518 GtkWidgetPrivate *priv = widget->priv;
10520 g_assert (!widget->priv->mapped);
10522 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10525 /* We must do unrealize child widget BEFORE container widget.
10526 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10527 * So, unrealizing container widget bofore its children causes the problem
10528 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10531 if (GTK_IS_CONTAINER (widget))
10532 gtk_container_forall (GTK_CONTAINER (widget),
10533 (GtkCallback) gtk_widget_unrealize,
10536 if (gtk_widget_get_has_window (widget))
10538 gdk_window_set_user_data (priv->window, NULL);
10539 gdk_window_destroy (priv->window);
10540 priv->window = NULL;
10544 g_object_unref (priv->window);
10545 priv->window = NULL;
10548 gtk_selection_remove_all (widget);
10550 gtk_widget_set_realized (widget, FALSE);
10554 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10555 GtkOrientation orientation,
10556 gint *minimum_size,
10557 gint *natural_size)
10559 const GtkWidgetAuxInfo *aux_info;
10561 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10563 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10564 aux_info->width > 0)
10566 *minimum_size = MAX (*minimum_size, aux_info->width);
10568 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10569 aux_info->height > 0)
10571 *minimum_size = MAX (*minimum_size, aux_info->height);
10574 /* Fix it if set_size_request made natural size smaller than min size.
10575 * This would also silently fix broken widgets, but we warn about them
10576 * in gtksizerequest.c when calling their size request vfuncs.
10578 *natural_size = MAX (*natural_size, *minimum_size);
10580 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10582 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10583 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10587 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10588 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10593 * _gtk_widget_peek_request_cache:
10595 * Returns the address of the widget's request cache (strictly for
10596 * internal use in gtksizerequest.c)
10598 * Return value: the address of @widget's size request cache.
10601 _gtk_widget_peek_request_cache (GtkWidget *widget)
10603 /* Don't bother slowing things down with the return_if_fail guards here */
10604 return &widget->priv->requests;
10608 * _gtk_widget_set_device_window:
10609 * @widget: a #GtkWidget
10610 * @device: a #GdkDevice
10611 * @window: the new device window
10613 * Sets pointer window for @widget and @device.
10614 * Does not ref @window.
10617 _gtk_widget_set_device_window (GtkWidget *widget,
10621 GHashTable *device_window;
10623 g_return_if_fail (GTK_IS_WIDGET (widget));
10624 g_return_if_fail (GDK_IS_DEVICE (device));
10625 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10627 if (!gtk_widget_get_mapped (widget))
10630 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10632 if (!device_window && window)
10634 device_window = g_hash_table_new (NULL, NULL);
10635 g_object_set_qdata_full (G_OBJECT (widget),
10636 quark_pointer_window,
10638 (GDestroyNotify) g_hash_table_destroy);
10642 g_hash_table_insert (device_window, device, window);
10643 else if (device_window)
10645 g_hash_table_remove (device_window, device);
10647 if (g_hash_table_size (device_window) == 0)
10648 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10653 * _gtk_widget_get_device_window:
10654 * @widget: a #GtkWidget
10655 * @device: a #GdkDevice
10657 * Return value: the device window set on @widget, or %NULL
10660 _gtk_widget_get_device_window (GtkWidget *widget,
10663 GHashTable *device_window;
10665 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10666 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10668 if (!gtk_widget_get_mapped (widget))
10671 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10673 if (!device_window)
10676 return g_hash_table_lookup (device_window, device);
10680 * _gtk_widget_list_devices:
10681 * @widget: a #GtkWidget
10683 * Returns the list of #GdkDevices that is currently on top
10684 * of any window belonging to @widget.
10685 * Free the list with g_list_free(), the elements are owned
10686 * by GTK+ and must not be freed.
10689 _gtk_widget_list_devices (GtkWidget *widget)
10691 GHashTableIter iter;
10692 GHashTable *device_window;
10693 GList *devices = NULL;
10694 gpointer key, value;
10696 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10698 if (!gtk_widget_get_mapped (widget))
10701 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10703 if (G_UNLIKELY (!device_window))
10706 g_hash_table_iter_init (&iter, device_window);
10708 while (g_hash_table_iter_next (&iter, &key, &value))
10709 devices = g_list_prepend (devices, key);
10715 synth_crossing (GtkWidget *widget,
10719 GdkCrossingMode mode,
10720 GdkNotifyType detail)
10724 event = gdk_event_new (type);
10726 event->crossing.window = g_object_ref (window);
10727 event->crossing.send_event = TRUE;
10728 event->crossing.subwindow = g_object_ref (window);
10729 event->crossing.time = GDK_CURRENT_TIME;
10730 event->crossing.x = event->crossing.y = 0;
10731 event->crossing.x_root = event->crossing.y_root = 0;
10732 event->crossing.mode = mode;
10733 event->crossing.detail = detail;
10734 event->crossing.focus = FALSE;
10735 event->crossing.state = 0;
10736 gdk_event_set_device (event, device);
10739 widget = gtk_get_event_widget (event);
10742 gtk_widget_event_internal (widget, event);
10744 gdk_event_free (event);
10748 * _gtk_widget_synthesize_crossing:
10749 * @from: the #GtkWidget the virtual pointer is leaving.
10750 * @to: the #GtkWidget the virtual pointer is moving to.
10751 * @mode: the #GdkCrossingMode to place on the synthesized events.
10753 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10755 * The real pointer window is the window that most recently received an enter notify
10756 * event. Windows that don't select for crossing events can't become the real
10757 * poiner window. The real pointer widget that owns the real pointer window. The
10758 * effective pointer window is the same as the real pointer window unless the real
10759 * pointer widget is either insensitive or there is a grab on a widget that is not
10760 * an ancestor of the real pointer widget (in which case the effective pointer
10761 * window should be the root window).
10763 * When the effective pointer window is the same as the real poiner window, we
10764 * receive crossing events from the windowing system. When the effective pointer
10765 * window changes to become different from the real pointer window we synthesize
10766 * crossing events, attempting to follow X protocol rules:
10768 * When the root window becomes the effective pointer window:
10769 * - leave notify on real pointer window, detail Ancestor
10770 * - leave notify on all of its ancestors, detail Virtual
10771 * - enter notify on root window, detail Inferior
10773 * When the root window ceases to be the effective pointer window:
10774 * - leave notify on root window, detail Inferior
10775 * - enter notify on all ancestors of real pointer window, detail Virtual
10776 * - enter notify on real pointer window, detail Ancestor
10779 _gtk_widget_synthesize_crossing (GtkWidget *from,
10782 GdkCrossingMode mode)
10784 GdkWindow *from_window = NULL, *to_window = NULL;
10786 g_return_if_fail (from != NULL || to != NULL);
10790 from_window = _gtk_widget_get_device_window (from, device);
10793 from_window = from->priv->window;
10798 to_window = _gtk_widget_get_device_window (to, device);
10801 to_window = to->priv->window;
10804 if (from_window == NULL && to_window == NULL)
10806 else if (from_window != NULL && to_window == NULL)
10808 GList *from_ancestors = NULL, *list;
10809 GdkWindow *from_ancestor = from_window;
10811 while (from_ancestor != NULL)
10813 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10814 if (from_ancestor == NULL)
10816 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10819 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10820 device, mode, GDK_NOTIFY_ANCESTOR);
10821 for (list = g_list_last (from_ancestors); list; list = list->prev)
10823 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10824 device, mode, GDK_NOTIFY_VIRTUAL);
10827 /* XXX: enter/inferior on root window? */
10829 g_list_free (from_ancestors);
10831 else if (from_window == NULL && to_window != NULL)
10833 GList *to_ancestors = NULL, *list;
10834 GdkWindow *to_ancestor = to_window;
10836 while (to_ancestor != NULL)
10838 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10839 if (to_ancestor == NULL)
10841 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10844 /* XXX: leave/inferior on root window? */
10846 for (list = to_ancestors; list; list = list->next)
10848 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10849 device, mode, GDK_NOTIFY_VIRTUAL);
10851 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10852 device, mode, GDK_NOTIFY_ANCESTOR);
10854 g_list_free (to_ancestors);
10856 else if (from_window == to_window)
10860 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10861 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10863 while (from_ancestor != NULL || to_ancestor != NULL)
10865 if (from_ancestor != NULL)
10867 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10868 if (from_ancestor == to_window)
10871 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10873 if (to_ancestor != NULL)
10875 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10876 if (to_ancestor == from_window)
10879 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10882 if (to_ancestor == from_window)
10884 if (mode != GDK_CROSSING_GTK_UNGRAB)
10885 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10886 device, mode, GDK_NOTIFY_INFERIOR);
10887 for (list = to_ancestors; list; list = list->next)
10888 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10889 device, mode, GDK_NOTIFY_VIRTUAL);
10890 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10891 device, mode, GDK_NOTIFY_ANCESTOR);
10893 else if (from_ancestor == to_window)
10895 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10896 device, mode, GDK_NOTIFY_ANCESTOR);
10897 for (list = g_list_last (from_ancestors); list; list = list->prev)
10899 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10900 device, mode, GDK_NOTIFY_VIRTUAL);
10902 if (mode != GDK_CROSSING_GTK_GRAB)
10903 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10904 device, mode, GDK_NOTIFY_INFERIOR);
10908 while (from_ancestors != NULL && to_ancestors != NULL
10909 && from_ancestors->data == to_ancestors->data)
10911 from_ancestors = g_list_delete_link (from_ancestors,
10913 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10916 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10917 device, mode, GDK_NOTIFY_NONLINEAR);
10919 for (list = g_list_last (from_ancestors); list; list = list->prev)
10921 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10922 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10924 for (list = to_ancestors; list; list = list->next)
10926 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10927 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10929 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10930 device, mode, GDK_NOTIFY_NONLINEAR);
10932 g_list_free (from_ancestors);
10933 g_list_free (to_ancestors);
10938 gtk_widget_propagate_state (GtkWidget *widget,
10939 GtkStateData *data)
10941 GtkWidgetPrivate *priv = widget->priv;
10942 GtkStateFlags new_flags, old_flags = priv->state_flags;
10943 GtkStateType old_state;
10945 old_state = gtk_widget_get_state (widget);
10947 switch (data->operation)
10949 case STATE_CHANGE_REPLACE:
10950 priv->state_flags = data->flags;
10952 case STATE_CHANGE_SET:
10953 priv->state_flags |= data->flags;
10955 case STATE_CHANGE_UNSET:
10956 priv->state_flags &= ~(data->flags);
10960 /* make insensitivity unoverridable */
10961 if (!priv->sensitive)
10962 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10964 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10968 window = gtk_widget_get_toplevel (widget);
10970 if (window && gtk_widget_is_toplevel (window))
10971 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10974 new_flags = priv->state_flags;
10976 if (old_flags != new_flags)
10978 g_object_ref (widget);
10980 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10981 gtk_grab_remove (widget);
10983 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10985 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10986 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10988 if (!priv->shadowed &&
10989 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10991 GList *event_windows = NULL;
10992 GList *devices, *d;
10994 devices = _gtk_widget_list_devices (widget);
10996 for (d = devices; d; d = d->next)
11002 window = _gtk_widget_get_device_window (widget, device);
11004 /* Do not propagate more than once to the
11005 * same window if non-multidevice aware.
11007 if (!gdk_window_get_support_multidevice (window) &&
11008 g_list_find (event_windows, window))
11011 if (!gtk_widget_is_sensitive (widget))
11012 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11013 GDK_CROSSING_STATE_CHANGED);
11015 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11016 GDK_CROSSING_STATE_CHANGED);
11018 event_windows = g_list_prepend (event_windows, window);
11021 g_list_free (event_windows);
11022 g_list_free (devices);
11025 if (GTK_IS_CONTAINER (widget))
11027 GtkStateData child_data = *data;
11029 /* Make sure to only propate the right states further */
11030 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
11032 gtk_container_forall (GTK_CONTAINER (widget),
11033 (GtkCallback) gtk_widget_propagate_state,
11037 /* Trigger state change transitions for the widget */
11038 if (priv->context &&
11039 gtk_widget_get_mapped (widget))
11041 gint diff, flag = 1;
11043 diff = old_flags ^ new_flags;
11047 if ((diff & flag) != 0)
11051 target = ((new_flags & flag) != 0);
11052 _gtk_widget_notify_state_change (widget, flag, target);
11061 g_object_unref (widget);
11065 static const GtkWidgetAuxInfo default_aux_info = {
11073 * gtk_widget_get_aux_info:
11074 * @widget: a #GtkWidget
11075 * @create: if %TRUE, create the structure if it doesn't exist
11077 * Get the #GtkWidgetAuxInfo structure for the widget.
11079 * Return value: the #GtkAuxInfo structure for the widget, or
11080 * %NULL if @create is %FALSE and one doesn't already exist.
11082 static GtkWidgetAuxInfo *
11083 gtk_widget_get_aux_info (GtkWidget *widget,
11086 GtkWidgetAuxInfo *aux_info;
11088 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11089 if (!aux_info && create)
11091 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11093 *aux_info = default_aux_info;
11095 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11101 static const GtkWidgetAuxInfo*
11102 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11104 GtkWidgetAuxInfo *aux_info;
11106 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11107 if (aux_info == NULL)
11109 return &default_aux_info;
11117 /*****************************************
11118 * gtk_widget_aux_info_destroy:
11123 *****************************************/
11126 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11128 g_slice_free (GtkWidgetAuxInfo, aux_info);
11132 * gtk_widget_shape_combine_region:
11133 * @widget: a #GtkWidget
11134 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11136 * Sets a shape for this widget's GDK window. This allows for
11137 * transparent windows etc., see gdk_window_shape_combine_region()
11138 * for more information.
11143 gtk_widget_shape_combine_region (GtkWidget *widget,
11144 cairo_region_t *region)
11146 GtkWidgetPrivate *priv;
11148 g_return_if_fail (GTK_IS_WIDGET (widget));
11149 /* set_shape doesn't work on widgets without gdk window */
11150 g_return_if_fail (gtk_widget_get_has_window (widget));
11152 priv = widget->priv;
11154 if (region == NULL)
11156 priv->has_shape_mask = FALSE;
11159 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11161 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11165 priv->has_shape_mask = TRUE;
11167 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11168 cairo_region_copy (region),
11169 (GDestroyNotify) cairo_region_destroy);
11171 /* set shape if widget has a gdk window already.
11172 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11175 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11180 * gtk_widget_input_shape_combine_region:
11181 * @widget: a #GtkWidget
11182 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11184 * Sets an input shape for this widget's GDK window. This allows for
11185 * windows which react to mouse click in a nonrectangular region, see
11186 * gdk_window_input_shape_combine_region() for more information.
11191 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11192 cairo_region_t *region)
11194 GtkWidgetPrivate *priv;
11196 g_return_if_fail (GTK_IS_WIDGET (widget));
11197 /* set_shape doesn't work on widgets without gdk window */
11198 g_return_if_fail (gtk_widget_get_has_window (widget));
11200 priv = widget->priv;
11202 if (region == NULL)
11205 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11207 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11211 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11212 cairo_region_copy (region),
11213 (GDestroyNotify) cairo_region_destroy);
11215 /* set shape if widget has a gdk window already.
11216 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11219 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11224 /* style properties
11228 * gtk_widget_class_install_style_property_parser: (skip)
11229 * @klass: a #GtkWidgetClass
11230 * @pspec: the #GParamSpec for the style property
11231 * @parser: the parser for the style property
11233 * Installs a style property on a widget class.
11236 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11238 GtkRcPropertyParser parser)
11240 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11241 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11242 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11243 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11245 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11247 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11248 G_OBJECT_CLASS_NAME (klass),
11253 g_param_spec_ref_sink (pspec);
11254 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11255 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11259 * gtk_widget_class_install_style_property:
11260 * @klass: a #GtkWidgetClass
11261 * @pspec: the #GParamSpec for the property
11263 * Installs a style property on a widget class. The parser for the
11264 * style property is determined by the value type of @pspec.
11267 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11270 GtkRcPropertyParser parser;
11272 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11273 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11275 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11277 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11281 * gtk_widget_class_find_style_property:
11282 * @klass: a #GtkWidgetClass
11283 * @property_name: the name of the style property to find
11285 * Finds a style property of a widget class by name.
11287 * Returns: (transfer none): the #GParamSpec of the style property or
11288 * %NULL if @class has no style property with that name.
11293 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11294 const gchar *property_name)
11296 g_return_val_if_fail (property_name != NULL, NULL);
11298 return g_param_spec_pool_lookup (style_property_spec_pool,
11300 G_OBJECT_CLASS_TYPE (klass),
11305 * gtk_widget_class_list_style_properties:
11306 * @klass: a #GtkWidgetClass
11307 * @n_properties: location to return the number of style properties found
11309 * Returns all style properties of a widget class.
11311 * Returns: (array length=n_properties) (transfer container): a
11312 * newly allocated array of #GParamSpec*. The array must be
11313 * freed with g_free().
11318 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11319 guint *n_properties)
11321 GParamSpec **pspecs;
11324 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11325 G_OBJECT_CLASS_TYPE (klass),
11334 * gtk_widget_style_get_property:
11335 * @widget: a #GtkWidget
11336 * @property_name: the name of a style property
11337 * @value: location to return the property value
11339 * Gets the value of a style property of @widget.
11342 gtk_widget_style_get_property (GtkWidget *widget,
11343 const gchar *property_name,
11348 g_return_if_fail (GTK_IS_WIDGET (widget));
11349 g_return_if_fail (property_name != NULL);
11350 g_return_if_fail (G_IS_VALUE (value));
11352 g_object_ref (widget);
11353 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11355 G_OBJECT_TYPE (widget),
11358 g_warning ("%s: widget class `%s' has no property named `%s'",
11360 G_OBJECT_TYPE_NAME (widget),
11364 GtkStyleContext *context;
11365 const GValue *peek_value;
11366 GtkStateFlags state;
11368 context = gtk_widget_get_style_context (widget);
11369 state = gtk_widget_get_state_flags (widget);
11371 peek_value = _gtk_style_context_peek_style_property (context,
11372 G_OBJECT_TYPE (widget),
11375 /* auto-conversion of the caller's value type
11377 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11378 g_value_copy (peek_value, value);
11379 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11380 g_value_transform (peek_value, value);
11382 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11384 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11385 G_VALUE_TYPE_NAME (value));
11387 g_object_unref (widget);
11391 * gtk_widget_style_get_valist:
11392 * @widget: a #GtkWidget
11393 * @first_property_name: the name of the first property to get
11394 * @var_args: a <type>va_list</type> of pairs of property names and
11395 * locations to return the property values, starting with the location
11396 * for @first_property_name.
11398 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11402 gtk_widget_style_get_valist (GtkWidget *widget,
11403 const gchar *first_property_name,
11406 GtkStyleContext *context;
11407 GtkStateFlags state;
11410 g_return_if_fail (GTK_IS_WIDGET (widget));
11412 g_object_ref (widget);
11413 context = gtk_widget_get_style_context (widget);
11414 state = gtk_widget_get_state_flags (widget);
11416 name = first_property_name;
11419 const GValue *peek_value;
11423 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11425 G_OBJECT_TYPE (widget),
11429 g_warning ("%s: widget class `%s' has no property named `%s'",
11431 G_OBJECT_TYPE_NAME (widget),
11435 /* style pspecs are always readable so we can spare that check here */
11437 peek_value = _gtk_style_context_peek_style_property (context,
11438 G_OBJECT_TYPE (widget),
11441 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11444 g_warning ("%s: %s", G_STRLOC, error);
11449 name = va_arg (var_args, gchar*);
11452 g_object_unref (widget);
11456 * gtk_widget_style_get:
11457 * @widget: a #GtkWidget
11458 * @first_property_name: the name of the first property to get
11459 * @...: pairs of property names and locations to return the
11460 * property values, starting with the location for
11461 * @first_property_name, terminated by %NULL.
11463 * Gets the values of a multiple style properties of @widget.
11466 gtk_widget_style_get (GtkWidget *widget,
11467 const gchar *first_property_name,
11472 g_return_if_fail (GTK_IS_WIDGET (widget));
11474 va_start (var_args, first_property_name);
11475 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11480 * gtk_requisition_new:
11482 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11484 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11485 * be freed with gtk_requisition_free().
11490 gtk_requisition_new (void)
11492 return g_slice_new0 (GtkRequisition);
11496 * gtk_requisition_copy:
11497 * @requisition: a #GtkRequisition
11499 * Copies a #GtkRequisition.
11501 * Returns: a copy of @requisition
11504 gtk_requisition_copy (const GtkRequisition *requisition)
11506 return g_slice_dup (GtkRequisition, requisition);
11510 * gtk_requisition_free:
11511 * @requisition: a #GtkRequisition
11513 * Frees a #GtkRequisition.
11516 gtk_requisition_free (GtkRequisition *requisition)
11518 g_slice_free (GtkRequisition, requisition);
11521 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11522 gtk_requisition_copy,
11523 gtk_requisition_free)
11526 * gtk_widget_class_set_accessible_type:
11527 * @widget_class: class to set the accessible type for
11528 * @type: The object type that implements the accessible for @widget_class
11530 * Sets the type to be used for creating accessibles for widgets of
11531 * @widget_class. The given @type must be a subtype of the type used for
11532 * accessibles of the parent class.
11534 * This function should only be called from class init functions of widgets.
11539 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11542 GtkWidgetClassPrivate *priv;
11544 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11545 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11547 priv = widget_class->priv;
11549 priv->accessible_type = type;
11550 /* reset this - honoring the type's role is better. */
11551 priv->accessible_role = ATK_ROLE_INVALID;
11555 * gtk_widget_class_set_accessible_role:
11556 * @widget_class: class to set the accessible role for
11557 * @role: The role to use for accessibles created for @widget_class
11559 * Sets the default #AtkRole to be set on accessibles created for
11560 * widgets of @widget_class. Accessibles may decide to not honor this
11561 * setting if their role reporting is more refined. Calls to
11562 * gtk_widget_class_set_accessible_type() will reset this value.
11564 * In cases where you want more fine-grained control over the role of
11565 * accessibles created for @widget_class, you should provide your own
11566 * accessible type and use gtk_widget_class_set_accessible_type()
11569 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11570 * and the accessible's default role will be used instead.
11572 * This function should only be called from class init functions of widgets.
11577 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11580 GtkWidgetClassPrivate *priv;
11582 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11584 priv = widget_class->priv;
11586 priv->accessible_role = role;
11590 * _gtk_widget_peek_accessible:
11591 * @widget: a #GtkWidget
11593 * Gets the accessible for @widget, if it has been created yet.
11594 * Otherwise, this function returns %NULL. If the @widget's implementation
11595 * does not use the default way to create accessibles, %NULL will always be
11598 * Returns: the accessible for @widget or %NULL if none has been
11602 _gtk_widget_peek_accessible (GtkWidget *widget)
11604 return g_object_get_qdata (G_OBJECT (widget),
11605 quark_accessible_object);
11609 * gtk_widget_get_accessible:
11610 * @widget: a #GtkWidget
11612 * Returns the accessible object that describes the widget to an
11613 * assistive technology.
11615 * If accessibility support is not available, this #AtkObject
11616 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11617 * implementation is available for the widget instance in question,
11618 * it will inherit an #AtkObject implementation from the first ancestor
11619 * class for which such an implementation is defined.
11621 * The documentation of the
11622 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11623 * library contains more information about accessible objects and their uses.
11625 * Returns: (transfer none): the #AtkObject associated with @widget
11628 gtk_widget_get_accessible (GtkWidget *widget)
11630 GtkWidgetClass *klass;
11632 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11634 klass = GTK_WIDGET_GET_CLASS (widget);
11636 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11638 return klass->get_accessible (widget);
11642 gtk_widget_real_get_accessible (GtkWidget *widget)
11644 AtkObject* accessible;
11646 accessible = g_object_get_qdata (G_OBJECT (widget),
11647 quark_accessible_object);
11650 GtkWidgetClass *widget_class;
11651 GtkWidgetClassPrivate *priv;
11652 AtkObjectFactory *factory;
11653 AtkRegistry *default_registry;
11655 widget_class = GTK_WIDGET_GET_CLASS (widget);
11656 priv = widget_class->priv;
11658 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11660 default_registry = atk_get_default_registry ();
11661 factory = atk_registry_get_factory (default_registry,
11662 G_TYPE_FROM_INSTANCE (widget));
11664 atk_object_factory_create_accessible (factory,
11665 G_OBJECT (widget));
11667 if (priv->accessible_role != ATK_ROLE_INVALID)
11668 atk_object_set_role (accessible, priv->accessible_role);
11670 g_object_set_qdata (G_OBJECT (widget),
11671 quark_accessible_object,
11676 accessible = g_object_new (priv->accessible_type,
11679 if (priv->accessible_role != ATK_ROLE_INVALID)
11680 atk_object_set_role (accessible, priv->accessible_role);
11682 g_object_set_qdata (G_OBJECT (widget),
11683 quark_accessible_object,
11686 atk_object_initialize (accessible, widget);
11688 /* Set the role again, since we don't want a role set
11689 * in some parent initialize() function to override
11692 if (priv->accessible_role != ATK_ROLE_INVALID)
11693 atk_object_set_role (accessible, priv->accessible_role);
11700 * Initialize a AtkImplementorIface instance's virtual pointers as
11701 * appropriate to this implementor's class (GtkWidget).
11704 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11706 iface->ref_accessible = gtk_widget_ref_accessible;
11710 gtk_widget_ref_accessible (AtkImplementor *implementor)
11712 AtkObject *accessible;
11714 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11716 g_object_ref (accessible);
11721 * Expand flag management
11725 gtk_widget_update_computed_expand (GtkWidget *widget)
11727 GtkWidgetPrivate *priv;
11729 priv = widget->priv;
11731 if (priv->need_compute_expand)
11735 if (priv->hexpand_set)
11740 if (priv->vexpand_set)
11745 /* we don't need to use compute_expand if both expands are
11746 * forced by the app
11748 if (!(priv->hexpand_set && priv->vexpand_set))
11750 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11754 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11755 priv->hexpand_set ? &ignored : &h,
11756 priv->vexpand_set ? &ignored : &v);
11760 priv->need_compute_expand = FALSE;
11761 priv->computed_hexpand = h != FALSE;
11762 priv->computed_vexpand = v != FALSE;
11767 * gtk_widget_queue_compute_expand:
11768 * @widget: a #GtkWidget
11770 * Mark @widget as needing to recompute its expand flags. Call
11771 * this function when setting legacy expand child properties
11772 * on the child of a container.
11774 * See gtk_widget_compute_expand().
11777 gtk_widget_queue_compute_expand (GtkWidget *widget)
11780 gboolean changed_anything;
11782 if (widget->priv->need_compute_expand)
11785 changed_anything = FALSE;
11787 while (parent != NULL)
11789 if (!parent->priv->need_compute_expand)
11791 parent->priv->need_compute_expand = TRUE;
11792 changed_anything = TRUE;
11795 /* Note: if we had an invariant that "if a child needs to
11796 * compute expand, its parents also do" then we could stop going
11797 * up when we got to a parent that already needed to
11798 * compute. However, in general we compute expand lazily (as
11799 * soon as we see something in a subtree that is expand, we know
11800 * we're expanding) and so this invariant does not hold and we
11801 * have to always walk all the way up in case some ancestor
11802 * is not currently need_compute_expand.
11805 parent = parent->priv->parent;
11808 /* recomputing expand always requires
11809 * a relayout as well
11811 if (changed_anything)
11812 gtk_widget_queue_resize (widget);
11816 * gtk_widget_compute_expand:
11817 * @widget: the widget
11818 * @orientation: expand direction
11820 * Computes whether a container should give this widget extra space
11821 * when possible. Containers should check this, rather than
11822 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11824 * This function already checks whether the widget is visible, so
11825 * visibility does not need to be checked separately. Non-visible
11826 * widgets are not expanded.
11828 * The computed expand value uses either the expand setting explicitly
11829 * set on the widget itself, or, if none has been explicitly set,
11830 * the widget may expand if some of its children do.
11832 * Return value: whether widget tree rooted here should be expanded
11835 gtk_widget_compute_expand (GtkWidget *widget,
11836 GtkOrientation orientation)
11838 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11840 /* We never make a widget expand if not even showing. */
11841 if (!gtk_widget_get_visible (widget))
11844 gtk_widget_update_computed_expand (widget);
11846 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11848 return widget->priv->computed_hexpand;
11852 return widget->priv->computed_vexpand;
11857 gtk_widget_set_expand (GtkWidget *widget,
11858 GtkOrientation orientation,
11861 const char *expand_prop;
11862 const char *expand_set_prop;
11864 GtkWidgetPrivate *priv;
11866 g_return_if_fail (GTK_IS_WIDGET (widget));
11868 priv = widget->priv;
11870 expand = expand != FALSE;
11872 was_both = priv->hexpand && priv->vexpand;
11874 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11876 if (priv->hexpand_set &&
11877 priv->hexpand == expand)
11880 priv->hexpand_set = TRUE;
11881 priv->hexpand = expand;
11883 expand_prop = "hexpand";
11884 expand_set_prop = "hexpand-set";
11888 if (priv->vexpand_set &&
11889 priv->vexpand == expand)
11892 priv->vexpand_set = TRUE;
11893 priv->vexpand = expand;
11895 expand_prop = "vexpand";
11896 expand_set_prop = "vexpand-set";
11899 gtk_widget_queue_compute_expand (widget);
11901 g_object_freeze_notify (G_OBJECT (widget));
11902 g_object_notify (G_OBJECT (widget), expand_prop);
11903 g_object_notify (G_OBJECT (widget), expand_set_prop);
11904 if (was_both != (priv->hexpand && priv->vexpand))
11905 g_object_notify (G_OBJECT (widget), "expand");
11906 g_object_thaw_notify (G_OBJECT (widget));
11910 gtk_widget_set_expand_set (GtkWidget *widget,
11911 GtkOrientation orientation,
11914 GtkWidgetPrivate *priv;
11917 priv = widget->priv;
11919 set = set != FALSE;
11921 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11923 if (set == priv->hexpand_set)
11926 priv->hexpand_set = set;
11927 prop = "hexpand-set";
11931 if (set == priv->vexpand_set)
11934 priv->vexpand_set = set;
11935 prop = "vexpand-set";
11938 gtk_widget_queue_compute_expand (widget);
11940 g_object_notify (G_OBJECT (widget), prop);
11944 * gtk_widget_get_hexpand:
11945 * @widget: the widget
11947 * Gets whether the widget would like any available extra horizontal
11948 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11949 * generally receive the extra space. For example, a list or
11950 * scrollable area or document in your window would often be set to
11953 * Containers should use gtk_widget_compute_expand() rather than
11954 * this function, to see whether a widget, or any of its children,
11955 * has the expand flag set. If any child of a widget wants to
11956 * expand, the parent may ask to expand also.
11958 * This function only looks at the widget's own hexpand flag, rather
11959 * than computing whether the entire widget tree rooted at this widget
11962 * Return value: whether hexpand flag is set
11965 gtk_widget_get_hexpand (GtkWidget *widget)
11967 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11969 return widget->priv->hexpand;
11973 * gtk_widget_set_hexpand:
11974 * @widget: the widget
11975 * @expand: whether to expand
11977 * Sets whether the widget would like any available extra horizontal
11978 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11979 * generally receive the extra space. For example, a list or
11980 * scrollable area or document in your window would often be set to
11983 * Call this function to set the expand flag if you would like your
11984 * widget to become larger horizontally when the window has extra
11987 * By default, widgets automatically expand if any of their children
11988 * want to expand. (To see if a widget will automatically expand given
11989 * its current children and state, call gtk_widget_compute_expand(). A
11990 * container can decide how the expandability of children affects the
11991 * expansion of the container by overriding the compute_expand virtual
11992 * method on #GtkWidget.).
11994 * Setting hexpand explicitly with this function will override the
11995 * automatic expand behavior.
11997 * This function forces the widget to expand or not to expand,
11998 * regardless of children. The override occurs because
11999 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12000 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12001 * value to be used, rather than looking at children and widget state.
12004 gtk_widget_set_hexpand (GtkWidget *widget,
12007 g_return_if_fail (GTK_IS_WIDGET (widget));
12009 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12013 * gtk_widget_get_hexpand_set:
12014 * @widget: the widget
12016 * Gets whether gtk_widget_set_hexpand() has been used to
12017 * explicitly set the expand flag on this widget.
12019 * If hexpand is set, then it overrides any computed
12020 * expand value based on child widgets. If hexpand is not
12021 * set, then the expand value depends on whether any
12022 * children of the widget would like to expand.
12024 * There are few reasons to use this function, but it's here
12025 * for completeness and consistency.
12027 * Return value: whether hexpand has been explicitly set
12030 gtk_widget_get_hexpand_set (GtkWidget *widget)
12032 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12034 return widget->priv->hexpand_set;
12038 * gtk_widget_set_hexpand_set:
12039 * @widget: the widget
12040 * @set: value for hexpand-set property
12042 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12045 * The hexpand-set property will be set automatically when you call
12046 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12047 * reason to use this function would be to unset an explicit expand
12050 * If hexpand is set, then it overrides any computed
12051 * expand value based on child widgets. If hexpand is not
12052 * set, then the expand value depends on whether any
12053 * children of the widget would like to expand.
12055 * There are few reasons to use this function, but it's here
12056 * for completeness and consistency.
12059 gtk_widget_set_hexpand_set (GtkWidget *widget,
12062 g_return_if_fail (GTK_IS_WIDGET (widget));
12064 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12069 * gtk_widget_get_vexpand:
12070 * @widget: the widget
12072 * Gets whether the widget would like any available extra vertical
12075 * See gtk_widget_get_hexpand() for more detail.
12077 * Return value: whether vexpand flag is set
12080 gtk_widget_get_vexpand (GtkWidget *widget)
12082 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12084 return widget->priv->vexpand;
12088 * gtk_widget_set_vexpand:
12089 * @widget: the widget
12090 * @expand: whether to expand
12092 * Sets whether the widget would like any available extra vertical
12095 * See gtk_widget_set_hexpand() for more detail.
12098 gtk_widget_set_vexpand (GtkWidget *widget,
12101 g_return_if_fail (GTK_IS_WIDGET (widget));
12103 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12107 * gtk_widget_get_vexpand_set:
12108 * @widget: the widget
12110 * Gets whether gtk_widget_set_vexpand() has been used to
12111 * explicitly set the expand flag on this widget.
12113 * See gtk_widget_get_hexpand_set() for more detail.
12115 * Return value: whether vexpand has been explicitly set
12118 gtk_widget_get_vexpand_set (GtkWidget *widget)
12120 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12122 return widget->priv->vexpand_set;
12126 * gtk_widget_set_vexpand_set:
12127 * @widget: the widget
12128 * @set: value for vexpand-set property
12130 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12133 * See gtk_widget_set_hexpand_set() for more detail.
12136 gtk_widget_set_vexpand_set (GtkWidget *widget,
12139 g_return_if_fail (GTK_IS_WIDGET (widget));
12141 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12145 * GtkBuildable implementation
12147 static GQuark quark_builder_has_default = 0;
12148 static GQuark quark_builder_has_focus = 0;
12149 static GQuark quark_builder_atk_relations = 0;
12150 static GQuark quark_builder_set_name = 0;
12153 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12155 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12156 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12157 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12158 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12160 iface->set_name = gtk_widget_buildable_set_name;
12161 iface->get_name = gtk_widget_buildable_get_name;
12162 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12163 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12164 iface->parser_finished = gtk_widget_buildable_parser_finished;
12165 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12166 iface->custom_finished = gtk_widget_buildable_custom_finished;
12170 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12173 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12174 g_strdup (name), g_free);
12177 static const gchar *
12178 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12180 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12184 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12185 GtkBuilder *builder,
12186 const gchar *childname)
12188 if (strcmp (childname, "accessible") == 0)
12189 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12195 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12196 GtkBuilder *builder,
12198 const GValue *value)
12200 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12201 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12202 GINT_TO_POINTER (TRUE));
12203 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12204 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12205 GINT_TO_POINTER (TRUE));
12207 g_object_set_property (G_OBJECT (buildable), name, value);
12212 gchar *action_name;
12213 GString *description;
12215 gboolean translatable;
12225 free_action (AtkActionData *data, gpointer user_data)
12227 g_free (data->action_name);
12228 g_string_free (data->description, TRUE);
12229 g_free (data->context);
12230 g_slice_free (AtkActionData, data);
12234 free_relation (AtkRelationData *data, gpointer user_data)
12236 g_free (data->target);
12237 g_free (data->type);
12238 g_slice_free (AtkRelationData, data);
12242 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12243 GtkBuilder *builder)
12245 GSList *atk_relations;
12247 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12248 gtk_widget_grab_default (GTK_WIDGET (buildable));
12249 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12250 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12252 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12253 quark_builder_atk_relations);
12256 AtkObject *accessible;
12257 AtkRelationSet *relation_set;
12260 AtkRelationType relation_type;
12261 AtkObject *target_accessible;
12263 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12264 relation_set = atk_object_ref_relation_set (accessible);
12266 for (l = atk_relations; l; l = l->next)
12268 AtkRelationData *relation = (AtkRelationData*)l->data;
12270 target = gtk_builder_get_object (builder, relation->target);
12273 g_warning ("Target object %s in <relation> does not exist",
12277 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12278 g_assert (target_accessible != NULL);
12280 relation_type = atk_relation_type_for_name (relation->type);
12281 if (relation_type == ATK_RELATION_NULL)
12283 g_warning ("<relation> type %s not found",
12287 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12288 target_accessible);
12290 g_object_unref (relation_set);
12292 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12293 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12302 } AccessibilitySubParserData;
12305 accessibility_start_element (GMarkupParseContext *context,
12306 const gchar *element_name,
12307 const gchar **names,
12308 const gchar **values,
12309 gpointer user_data,
12312 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12314 gint line_number, char_number;
12316 if (strcmp (element_name, "relation") == 0)
12318 gchar *target = NULL;
12319 gchar *type = NULL;
12320 AtkRelationData *relation;
12322 for (i = 0; names[i]; i++)
12324 if (strcmp (names[i], "target") == 0)
12325 target = g_strdup (values[i]);
12326 else if (strcmp (names[i], "type") == 0)
12327 type = g_strdup (values[i]);
12330 g_markup_parse_context_get_position (context,
12333 g_set_error (error,
12335 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12336 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12338 line_number, char_number, names[i], "relation");
12345 if (!target || !type)
12347 g_markup_parse_context_get_position (context,
12350 g_set_error (error,
12352 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12353 "%s:%d:%d <%s> requires attribute \"%s\"",
12355 line_number, char_number, "relation",
12356 type ? "target" : "type");
12362 relation = g_slice_new (AtkRelationData);
12363 relation->target = target;
12364 relation->type = type;
12366 data->relations = g_slist_prepend (data->relations, relation);
12368 else if (strcmp (element_name, "action") == 0)
12370 const gchar *action_name = NULL;
12371 const gchar *description = NULL;
12372 const gchar *msg_context = NULL;
12373 gboolean translatable = FALSE;
12374 AtkActionData *action;
12376 for (i = 0; names[i]; i++)
12378 if (strcmp (names[i], "action_name") == 0)
12379 action_name = values[i];
12380 else if (strcmp (names[i], "description") == 0)
12381 description = values[i];
12382 else if (strcmp (names[i], "translatable") == 0)
12384 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12387 else if (strcmp (names[i], "comments") == 0)
12389 /* do nothing, comments are for translators */
12391 else if (strcmp (names[i], "context") == 0)
12392 msg_context = values[i];
12395 g_markup_parse_context_get_position (context,
12398 g_set_error (error,
12400 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12401 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12403 line_number, char_number, names[i], "action");
12410 g_markup_parse_context_get_position (context,
12413 g_set_error (error,
12415 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12416 "%s:%d:%d <%s> requires attribute \"%s\"",
12418 line_number, char_number, "action",
12423 action = g_slice_new (AtkActionData);
12424 action->action_name = g_strdup (action_name);
12425 action->description = g_string_new (description);
12426 action->context = g_strdup (msg_context);
12427 action->translatable = translatable;
12429 data->actions = g_slist_prepend (data->actions, action);
12431 else if (strcmp (element_name, "accessibility") == 0)
12434 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12438 accessibility_text (GMarkupParseContext *context,
12441 gpointer user_data,
12444 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12446 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12448 AtkActionData *action = data->actions->data;
12450 g_string_append_len (action->description, text, text_len);
12454 static const GMarkupParser accessibility_parser =
12456 accessibility_start_element,
12458 accessibility_text,
12467 } AccelGroupParserData;
12470 accel_group_start_element (GMarkupParseContext *context,
12471 const gchar *element_name,
12472 const gchar **names,
12473 const gchar **values,
12474 gpointer user_data,
12479 guint modifiers = 0;
12480 gchar *signal = NULL;
12481 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12483 for (i = 0; names[i]; i++)
12485 if (strcmp (names[i], "key") == 0)
12486 key = gdk_keyval_from_name (values[i]);
12487 else if (strcmp (names[i], "modifiers") == 0)
12489 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12495 else if (strcmp (names[i], "signal") == 0)
12496 signal = g_strdup (values[i]);
12499 if (key == 0 || signal == NULL)
12501 g_warning ("<accelerator> requires key and signal attributes");
12504 parser_data->key = key;
12505 parser_data->modifiers = modifiers;
12506 parser_data->signal = signal;
12509 static const GMarkupParser accel_group_parser =
12511 accel_group_start_element,
12520 style_start_element (GMarkupParseContext *context,
12521 const gchar *element_name,
12522 const gchar **names,
12523 const gchar **values,
12524 gpointer user_data,
12527 StyleParserData *style_data = (StyleParserData *)user_data;
12530 if (strcmp (element_name, "class") == 0)
12532 if (g_markup_collect_attributes (element_name,
12536 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12537 G_MARKUP_COLLECT_INVALID))
12539 style_data->classes = g_slist_append (style_data->classes, class_name);
12542 else if (strcmp (element_name, "style") == 0)
12545 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12548 static const GMarkupParser style_parser =
12550 style_start_element,
12554 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12555 GtkBuilder *builder,
12557 const gchar *tagname,
12558 GMarkupParser *parser,
12561 g_assert (buildable);
12563 if (strcmp (tagname, "accelerator") == 0)
12565 AccelGroupParserData *parser_data;
12567 parser_data = g_slice_new0 (AccelGroupParserData);
12568 parser_data->object = g_object_ref (buildable);
12569 *parser = accel_group_parser;
12570 *data = parser_data;
12573 if (strcmp (tagname, "accessibility") == 0)
12575 AccessibilitySubParserData *parser_data;
12577 parser_data = g_slice_new0 (AccessibilitySubParserData);
12578 *parser = accessibility_parser;
12579 *data = parser_data;
12582 if (strcmp (tagname, "style") == 0)
12584 StyleParserData *parser_data;
12586 parser_data = g_slice_new0 (StyleParserData);
12587 *parser = style_parser;
12588 *data = parser_data;
12596 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12597 GtkWidget *toplevel,
12598 gpointer user_data)
12600 AccelGroupParserData *accel_data;
12601 GSList *accel_groups;
12602 GtkAccelGroup *accel_group;
12604 g_return_if_fail (GTK_IS_WIDGET (widget));
12605 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12606 g_return_if_fail (user_data != NULL);
12608 accel_data = (AccelGroupParserData*)user_data;
12609 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12610 if (g_slist_length (accel_groups) == 0)
12612 accel_group = gtk_accel_group_new ();
12613 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12617 g_assert (g_slist_length (accel_groups) == 1);
12618 accel_group = g_slist_nth_data (accel_groups, 0);
12621 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12622 accel_data->signal,
12625 accel_data->modifiers,
12626 GTK_ACCEL_VISIBLE);
12628 g_object_unref (accel_data->object);
12629 g_free (accel_data->signal);
12630 g_slice_free (AccelGroupParserData, accel_data);
12634 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12635 GtkBuilder *builder,
12637 const gchar *tagname,
12638 gpointer user_data)
12640 if (strcmp (tagname, "accelerator") == 0)
12642 AccelGroupParserData *accel_data;
12643 GtkWidget *toplevel;
12645 accel_data = (AccelGroupParserData*)user_data;
12646 g_assert (accel_data->object);
12648 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12650 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12652 else if (strcmp (tagname, "accessibility") == 0)
12654 AccessibilitySubParserData *a11y_data;
12656 a11y_data = (AccessibilitySubParserData*)user_data;
12658 if (a11y_data->actions)
12660 AtkObject *accessible;
12665 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12667 if (ATK_IS_ACTION (accessible))
12669 action = ATK_ACTION (accessible);
12670 n_actions = atk_action_get_n_actions (action);
12672 for (l = a11y_data->actions; l; l = l->next)
12674 AtkActionData *action_data = (AtkActionData*)l->data;
12676 for (i = 0; i < n_actions; i++)
12677 if (strcmp (atk_action_get_name (action, i),
12678 action_data->action_name) == 0)
12683 gchar *description;
12685 if (action_data->translatable && action_data->description->len)
12686 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12687 action_data->context,
12688 action_data->description->str);
12690 description = action_data->description->str;
12692 atk_action_set_description (action, i, description);
12697 g_warning ("accessibility action on a widget that does not implement AtkAction");
12699 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12702 if (a11y_data->relations)
12703 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12704 a11y_data->relations);
12706 g_slice_free (AccessibilitySubParserData, a11y_data);
12708 else if (strcmp (tagname, "style") == 0)
12710 StyleParserData *style_data = (StyleParserData *)user_data;
12711 GtkStyleContext *context;
12714 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12716 for (l = style_data->classes; l; l = l->next)
12717 gtk_style_context_add_class (context, (const gchar *)l->data);
12719 gtk_widget_reset_style (GTK_WIDGET (buildable));
12721 g_slist_free_full (style_data->classes, g_free);
12722 g_slice_free (StyleParserData, style_data);
12726 static GtkSizeRequestMode
12727 gtk_widget_real_get_request_mode (GtkWidget *widget)
12729 /* By default widgets dont trade size at all. */
12730 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12734 gtk_widget_real_get_width (GtkWidget *widget,
12735 gint *minimum_size,
12736 gint *natural_size)
12746 gtk_widget_real_get_height (GtkWidget *widget,
12747 gint *minimum_size,
12748 gint *natural_size)
12758 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12760 gint *minimum_height,
12761 gint *natural_height)
12763 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12767 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12769 gint *minimum_width,
12770 gint *natural_width)
12772 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12776 * gtk_widget_get_halign:
12777 * @widget: a #GtkWidget
12779 * Gets the value of the #GtkWidget:halign property.
12781 * Returns: the horizontal alignment of @widget
12784 gtk_widget_get_halign (GtkWidget *widget)
12786 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12787 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12791 * gtk_widget_set_halign:
12792 * @widget: a #GtkWidget
12793 * @align: the horizontal alignment
12795 * Sets the horizontal alignment of @widget.
12796 * See the #GtkWidget:halign property.
12799 gtk_widget_set_halign (GtkWidget *widget,
12802 GtkWidgetAuxInfo *aux_info;
12804 g_return_if_fail (GTK_IS_WIDGET (widget));
12806 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12808 if (aux_info->halign == align)
12811 aux_info->halign = align;
12812 gtk_widget_queue_resize (widget);
12813 g_object_notify (G_OBJECT (widget), "halign");
12817 * gtk_widget_get_valign:
12818 * @widget: a #GtkWidget
12820 * Gets the value of the #GtkWidget:valign property.
12822 * Returns: the vertical alignment of @widget
12825 gtk_widget_get_valign (GtkWidget *widget)
12827 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12828 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12832 * gtk_widget_set_valign:
12833 * @widget: a #GtkWidget
12834 * @align: the vertical alignment
12836 * Sets the vertical alignment of @widget.
12837 * See the #GtkWidget:valign property.
12840 gtk_widget_set_valign (GtkWidget *widget,
12843 GtkWidgetAuxInfo *aux_info;
12845 g_return_if_fail (GTK_IS_WIDGET (widget));
12847 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12849 if (aux_info->valign == align)
12852 aux_info->valign = align;
12853 gtk_widget_queue_resize (widget);
12854 g_object_notify (G_OBJECT (widget), "valign");
12858 * gtk_widget_get_margin_left:
12859 * @widget: a #GtkWidget
12861 * Gets the value of the #GtkWidget:margin-left property.
12863 * Returns: The left margin of @widget
12868 gtk_widget_get_margin_left (GtkWidget *widget)
12870 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12872 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12876 * gtk_widget_set_margin_left:
12877 * @widget: a #GtkWidget
12878 * @margin: the left margin
12880 * Sets the left margin of @widget.
12881 * See the #GtkWidget:margin-left property.
12886 gtk_widget_set_margin_left (GtkWidget *widget,
12889 GtkWidgetAuxInfo *aux_info;
12891 g_return_if_fail (GTK_IS_WIDGET (widget));
12892 g_return_if_fail (margin <= G_MAXINT16);
12894 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12896 if (aux_info->margin.left == margin)
12899 aux_info->margin.left = margin;
12900 gtk_widget_queue_resize (widget);
12901 g_object_notify (G_OBJECT (widget), "margin-left");
12905 * gtk_widget_get_margin_right:
12906 * @widget: a #GtkWidget
12908 * Gets the value of the #GtkWidget:margin-right property.
12910 * Returns: The right margin of @widget
12915 gtk_widget_get_margin_right (GtkWidget *widget)
12917 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12919 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12923 * gtk_widget_set_margin_right:
12924 * @widget: a #GtkWidget
12925 * @margin: the right margin
12927 * Sets the right margin of @widget.
12928 * See the #GtkWidget:margin-right property.
12933 gtk_widget_set_margin_right (GtkWidget *widget,
12936 GtkWidgetAuxInfo *aux_info;
12938 g_return_if_fail (GTK_IS_WIDGET (widget));
12939 g_return_if_fail (margin <= G_MAXINT16);
12941 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12943 if (aux_info->margin.right == margin)
12946 aux_info->margin.right = margin;
12947 gtk_widget_queue_resize (widget);
12948 g_object_notify (G_OBJECT (widget), "margin-right");
12952 * gtk_widget_get_margin_top:
12953 * @widget: a #GtkWidget
12955 * Gets the value of the #GtkWidget:margin-top property.
12957 * Returns: The top margin of @widget
12962 gtk_widget_get_margin_top (GtkWidget *widget)
12964 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12966 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12970 * gtk_widget_set_margin_top:
12971 * @widget: a #GtkWidget
12972 * @margin: the top margin
12974 * Sets the top margin of @widget.
12975 * See the #GtkWidget:margin-top property.
12980 gtk_widget_set_margin_top (GtkWidget *widget,
12983 GtkWidgetAuxInfo *aux_info;
12985 g_return_if_fail (GTK_IS_WIDGET (widget));
12986 g_return_if_fail (margin <= G_MAXINT16);
12988 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12990 if (aux_info->margin.top == margin)
12993 aux_info->margin.top = margin;
12994 gtk_widget_queue_resize (widget);
12995 g_object_notify (G_OBJECT (widget), "margin-top");
12999 * gtk_widget_get_margin_bottom:
13000 * @widget: a #GtkWidget
13002 * Gets the value of the #GtkWidget:margin-bottom property.
13004 * Returns: The bottom margin of @widget
13009 gtk_widget_get_margin_bottom (GtkWidget *widget)
13011 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13013 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13017 * gtk_widget_set_margin_bottom:
13018 * @widget: a #GtkWidget
13019 * @margin: the bottom margin
13021 * Sets the bottom margin of @widget.
13022 * See the #GtkWidget:margin-bottom property.
13027 gtk_widget_set_margin_bottom (GtkWidget *widget,
13030 GtkWidgetAuxInfo *aux_info;
13032 g_return_if_fail (GTK_IS_WIDGET (widget));
13033 g_return_if_fail (margin <= G_MAXINT16);
13035 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13037 if (aux_info->margin.bottom == margin)
13040 aux_info->margin.bottom = margin;
13041 gtk_widget_queue_resize (widget);
13042 g_object_notify (G_OBJECT (widget), "margin-bottom");
13046 * gtk_widget_get_clipboard:
13047 * @widget: a #GtkWidget
13048 * @selection: a #GdkAtom which identifies the clipboard
13049 * to use. %GDK_SELECTION_CLIPBOARD gives the
13050 * default clipboard. Another common value
13051 * is %GDK_SELECTION_PRIMARY, which gives
13052 * the primary X selection.
13054 * Returns the clipboard object for the given selection to
13055 * be used with @widget. @widget must have a #GdkDisplay
13056 * associated with it, so must be attached to a toplevel
13059 * Return value: (transfer none): the appropriate clipboard object. If no
13060 * clipboard already exists, a new one will
13061 * be created. Once a clipboard object has
13062 * been created, it is persistent for all time.
13067 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13069 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13070 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13072 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13077 * gtk_widget_list_mnemonic_labels:
13078 * @widget: a #GtkWidget
13080 * Returns a newly allocated list of the widgets, normally labels, for
13081 * which this widget is the target of a mnemonic (see for example,
13082 * gtk_label_set_mnemonic_widget()).
13084 * The widgets in the list are not individually referenced. If you
13085 * want to iterate through the list and perform actions involving
13086 * callbacks that might destroy the widgets, you
13087 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13088 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13089 * widgets afterwards.
13091 * Return value: (element-type GtkWidget) (transfer container): the list of
13092 * mnemonic labels; free this list
13093 * with g_list_free() when you are done with it.
13098 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13100 GList *list = NULL;
13103 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13105 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13106 list = g_list_prepend (list, l->data);
13112 * gtk_widget_add_mnemonic_label:
13113 * @widget: a #GtkWidget
13114 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13116 * Adds a widget to the list of mnemonic labels for
13117 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13118 * list of mnemonic labels for the widget is cleared when the
13119 * widget is destroyed, so the caller must make sure to update
13120 * its internal state at this point as well, by using a connection
13121 * to the #GtkWidget::destroy signal or a weak notifier.
13126 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13129 GSList *old_list, *new_list;
13131 g_return_if_fail (GTK_IS_WIDGET (widget));
13132 g_return_if_fail (GTK_IS_WIDGET (label));
13134 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13135 new_list = g_slist_prepend (old_list, label);
13137 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13138 new_list, (GDestroyNotify) g_slist_free);
13142 * gtk_widget_remove_mnemonic_label:
13143 * @widget: a #GtkWidget
13144 * @label: a #GtkWidget that was previously set as a mnemnic label for
13145 * @widget with gtk_widget_add_mnemonic_label().
13147 * Removes a widget from the list of mnemonic labels for
13148 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13149 * must have previously been added to the list with
13150 * gtk_widget_add_mnemonic_label().
13155 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13158 GSList *old_list, *new_list;
13160 g_return_if_fail (GTK_IS_WIDGET (widget));
13161 g_return_if_fail (GTK_IS_WIDGET (label));
13163 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13164 new_list = g_slist_remove (old_list, label);
13167 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13168 new_list, (GDestroyNotify) g_slist_free);
13172 * gtk_widget_get_no_show_all:
13173 * @widget: a #GtkWidget
13175 * Returns the current value of the #GtkWidget:no-show-all property,
13176 * which determines whether calls to gtk_widget_show_all()
13177 * will affect this widget.
13179 * Return value: the current value of the "no-show-all" property.
13184 gtk_widget_get_no_show_all (GtkWidget *widget)
13186 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13188 return widget->priv->no_show_all;
13192 * gtk_widget_set_no_show_all:
13193 * @widget: a #GtkWidget
13194 * @no_show_all: the new value for the "no-show-all" property
13196 * Sets the #GtkWidget:no-show-all property, which determines whether
13197 * calls to gtk_widget_show_all() will affect this widget.
13199 * This is mostly for use in constructing widget hierarchies with externally
13200 * controlled visibility, see #GtkUIManager.
13205 gtk_widget_set_no_show_all (GtkWidget *widget,
13206 gboolean no_show_all)
13208 g_return_if_fail (GTK_IS_WIDGET (widget));
13210 no_show_all = (no_show_all != FALSE);
13212 if (widget->priv->no_show_all != no_show_all)
13214 widget->priv->no_show_all = no_show_all;
13216 g_object_notify (G_OBJECT (widget), "no-show-all");
13222 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13223 gboolean has_tooltip,
13226 GtkWidgetPrivate *priv = widget->priv;
13227 gboolean priv_has_tooltip;
13229 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13230 quark_has_tooltip));
13232 if (priv_has_tooltip != has_tooltip || force)
13234 priv_has_tooltip = has_tooltip;
13236 if (priv_has_tooltip)
13238 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13239 gdk_window_set_events (priv->window,
13240 gdk_window_get_events (priv->window) |
13241 GDK_LEAVE_NOTIFY_MASK |
13242 GDK_POINTER_MOTION_MASK |
13243 GDK_POINTER_MOTION_HINT_MASK);
13245 if (gtk_widget_get_has_window (widget))
13246 gtk_widget_add_events (widget,
13247 GDK_LEAVE_NOTIFY_MASK |
13248 GDK_POINTER_MOTION_MASK |
13249 GDK_POINTER_MOTION_HINT_MASK);
13252 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13253 GUINT_TO_POINTER (priv_has_tooltip));
13258 * gtk_widget_set_tooltip_window:
13259 * @widget: a #GtkWidget
13260 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13262 * Replaces the default, usually yellow, window used for displaying
13263 * tooltips with @custom_window. GTK+ will take care of showing and
13264 * hiding @custom_window at the right moment, to behave likewise as
13265 * the default tooltip window. If @custom_window is %NULL, the default
13266 * tooltip window will be used.
13268 * If the custom window should have the default theming it needs to
13269 * have the name "gtk-tooltip", see gtk_widget_set_name().
13274 gtk_widget_set_tooltip_window (GtkWidget *widget,
13275 GtkWindow *custom_window)
13277 gboolean has_tooltip;
13278 gchar *tooltip_markup;
13280 g_return_if_fail (GTK_IS_WIDGET (widget));
13281 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13283 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13286 g_object_ref (custom_window);
13288 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13289 custom_window, g_object_unref);
13291 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13292 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13294 if (has_tooltip && gtk_widget_get_visible (widget))
13295 gtk_widget_queue_tooltip_query (widget);
13299 * gtk_widget_get_tooltip_window:
13300 * @widget: a #GtkWidget
13302 * Returns the #GtkWindow of the current tooltip. This can be the
13303 * GtkWindow created by default, or the custom tooltip window set
13304 * using gtk_widget_set_tooltip_window().
13306 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13311 gtk_widget_get_tooltip_window (GtkWidget *widget)
13313 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13315 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13319 * gtk_widget_trigger_tooltip_query:
13320 * @widget: a #GtkWidget
13322 * Triggers a tooltip query on the display where the toplevel of @widget
13323 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13329 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13331 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13334 static guint tooltip_query_id;
13335 static GSList *tooltip_query_displays;
13338 tooltip_query_idle (gpointer data)
13340 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13341 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13342 g_slist_free (tooltip_query_displays);
13344 tooltip_query_displays = NULL;
13345 tooltip_query_id = 0;
13351 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13353 GdkDisplay *display;
13355 display = gtk_widget_get_display (widget);
13357 if (!g_slist_find (tooltip_query_displays, display))
13358 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13360 if (tooltip_query_id == 0)
13361 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13365 * gtk_widget_set_tooltip_text:
13366 * @widget: a #GtkWidget
13367 * @text: the contents of the tooltip for @widget
13369 * Sets @text as the contents of the tooltip. This function will take
13370 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13371 * handler for the #GtkWidget::query-tooltip signal.
13373 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13378 gtk_widget_set_tooltip_text (GtkWidget *widget,
13381 g_return_if_fail (GTK_IS_WIDGET (widget));
13383 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13387 * gtk_widget_get_tooltip_text:
13388 * @widget: a #GtkWidget
13390 * Gets the contents of the tooltip for @widget.
13392 * Return value: the tooltip text, or %NULL. You should free the
13393 * returned string with g_free() when done.
13398 gtk_widget_get_tooltip_text (GtkWidget *widget)
13400 gchar *text = NULL;
13402 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13404 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13410 * gtk_widget_set_tooltip_markup:
13411 * @widget: a #GtkWidget
13412 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13414 * Sets @markup as the contents of the tooltip, which is marked up with
13415 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13417 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13418 * and of the default handler for the #GtkWidget::query-tooltip signal.
13420 * See also the #GtkWidget:tooltip-markup property and
13421 * gtk_tooltip_set_markup().
13426 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13427 const gchar *markup)
13429 g_return_if_fail (GTK_IS_WIDGET (widget));
13431 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13435 * gtk_widget_get_tooltip_markup:
13436 * @widget: a #GtkWidget
13438 * Gets the contents of the tooltip for @widget.
13440 * Return value: the tooltip text, or %NULL. You should free the
13441 * returned string with g_free() when done.
13446 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13448 gchar *text = NULL;
13450 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13452 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13458 * gtk_widget_set_has_tooltip:
13459 * @widget: a #GtkWidget
13460 * @has_tooltip: whether or not @widget has a tooltip.
13462 * Sets the has-tooltip property on @widget to @has_tooltip. See
13463 * #GtkWidget:has-tooltip for more information.
13468 gtk_widget_set_has_tooltip (GtkWidget *widget,
13469 gboolean has_tooltip)
13471 g_return_if_fail (GTK_IS_WIDGET (widget));
13473 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13477 * gtk_widget_get_has_tooltip:
13478 * @widget: a #GtkWidget
13480 * Returns the current value of the has-tooltip property. See
13481 * #GtkWidget:has-tooltip for more information.
13483 * Return value: current value of has-tooltip on @widget.
13488 gtk_widget_get_has_tooltip (GtkWidget *widget)
13490 gboolean has_tooltip = FALSE;
13492 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13494 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13496 return has_tooltip;
13500 * gtk_widget_get_allocation:
13501 * @widget: a #GtkWidget
13502 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13504 * Retrieves the widget's allocation.
13506 * Note, when implementing a #GtkContainer: a widget's allocation will
13507 * be its "adjusted" allocation, that is, the widget's parent
13508 * container typically calls gtk_widget_size_allocate() with an
13509 * allocation, and that allocation is then adjusted (to handle margin
13510 * and alignment for example) before assignment to the widget.
13511 * gtk_widget_get_allocation() returns the adjusted allocation that
13512 * was actually assigned to the widget. The adjusted allocation is
13513 * guaranteed to be completely contained within the
13514 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13515 * is guaranteed that its children stay inside the assigned bounds,
13516 * but not that they have exactly the bounds the container assigned.
13517 * There is no way to get the original allocation assigned by
13518 * gtk_widget_size_allocate(), since it isn't stored; if a container
13519 * implementation needs that information it will have to track it itself.
13524 gtk_widget_get_allocation (GtkWidget *widget,
13525 GtkAllocation *allocation)
13527 GtkWidgetPrivate *priv;
13529 g_return_if_fail (GTK_IS_WIDGET (widget));
13530 g_return_if_fail (allocation != NULL);
13532 priv = widget->priv;
13534 *allocation = priv->allocation;
13538 * gtk_widget_set_allocation:
13539 * @widget: a #GtkWidget
13540 * @allocation: a pointer to a #GtkAllocation to copy from
13542 * Sets the widget's allocation. This should not be used
13543 * directly, but from within a widget's size_allocate method.
13545 * The allocation set should be the "adjusted" or actual
13546 * allocation. If you're implementing a #GtkContainer, you want to use
13547 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13548 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13549 * allocation inside gtk_widget_size_allocate() to create an adjusted
13555 gtk_widget_set_allocation (GtkWidget *widget,
13556 const GtkAllocation *allocation)
13558 GtkWidgetPrivate *priv;
13560 g_return_if_fail (GTK_IS_WIDGET (widget));
13561 g_return_if_fail (allocation != NULL);
13563 priv = widget->priv;
13565 priv->allocation = *allocation;
13569 * gtk_widget_get_allocated_width:
13570 * @widget: the widget to query
13572 * Returns the width that has currently been allocated to @widget.
13573 * This function is intended to be used when implementing handlers
13574 * for the #GtkWidget::draw function.
13576 * Returns: the width of the @widget
13579 gtk_widget_get_allocated_width (GtkWidget *widget)
13581 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13583 return widget->priv->allocation.width;
13587 * gtk_widget_get_allocated_height:
13588 * @widget: the widget to query
13590 * Returns the height that has currently been allocated to @widget.
13591 * This function is intended to be used when implementing handlers
13592 * for the #GtkWidget::draw function.
13594 * Returns: the height of the @widget
13597 gtk_widget_get_allocated_height (GtkWidget *widget)
13599 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13601 return widget->priv->allocation.height;
13605 * gtk_widget_get_requisition:
13606 * @widget: a #GtkWidget
13607 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13609 * Retrieves the widget's requisition.
13611 * This function should only be used by widget implementations in
13612 * order to figure whether the widget's requisition has actually
13613 * changed after some internal state change (so that they can call
13614 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13616 * Normally, gtk_widget_size_request() should be used.
13620 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13621 * removed, If you need to cache sizes across requests and allocations,
13622 * add an explicit cache to the widget in question instead.
13625 gtk_widget_get_requisition (GtkWidget *widget,
13626 GtkRequisition *requisition)
13628 g_return_if_fail (GTK_IS_WIDGET (widget));
13629 g_return_if_fail (requisition != NULL);
13631 gtk_widget_get_preferred_size (widget, requisition, NULL);
13635 * gtk_widget_set_window:
13636 * @widget: a #GtkWidget
13637 * @window: (transfer full): a #GdkWindow
13639 * Sets a widget's window. This function should only be used in a
13640 * widget's #GtkWidget::realize implementation. The %window passed is
13641 * usually either new window created with gdk_window_new(), or the
13642 * window of its parent widget as returned by
13643 * gtk_widget_get_parent_window().
13645 * Widgets must indicate whether they will create their own #GdkWindow
13646 * by calling gtk_widget_set_has_window(). This is usually done in the
13647 * widget's init() function.
13649 * <note><para>This function does not add any reference to @window.</para></note>
13654 gtk_widget_set_window (GtkWidget *widget,
13657 GtkWidgetPrivate *priv;
13659 g_return_if_fail (GTK_IS_WIDGET (widget));
13660 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13662 priv = widget->priv;
13664 if (priv->window != window)
13666 priv->window = window;
13667 g_object_notify (G_OBJECT (widget), "window");
13672 * gtk_widget_get_window:
13673 * @widget: a #GtkWidget
13675 * Returns the widget's window if it is realized, %NULL otherwise
13677 * Return value: (transfer none): @widget's window.
13682 gtk_widget_get_window (GtkWidget *widget)
13684 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13686 return widget->priv->window;
13690 * gtk_widget_get_support_multidevice:
13691 * @widget: a #GtkWidget
13693 * Returns %TRUE if @widget is multiple pointer aware. See
13694 * gtk_widget_set_support_multidevice() for more information.
13696 * Returns: %TRUE if @widget is multidevice aware.
13699 gtk_widget_get_support_multidevice (GtkWidget *widget)
13701 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13703 return widget->priv->multidevice;
13707 * gtk_widget_set_support_multidevice:
13708 * @widget: a #GtkWidget
13709 * @support_multidevice: %TRUE to support input from multiple devices.
13711 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13712 * @widget will start receiving multiple, per device enter/leave events. Note
13713 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13714 * gdk_window_set_support_multidevice() will have to be called manually on them.
13719 gtk_widget_set_support_multidevice (GtkWidget *widget,
13720 gboolean support_multidevice)
13722 GtkWidgetPrivate *priv;
13724 g_return_if_fail (GTK_IS_WIDGET (widget));
13726 priv = widget->priv;
13727 priv->multidevice = (support_multidevice == TRUE);
13729 if (gtk_widget_get_realized (widget))
13730 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13734 _gtk_widget_set_has_focus (GtkWidget *widget,
13735 gboolean has_focus)
13737 widget->priv->has_focus = has_focus;
13740 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13742 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13746 * gtk_widget_send_focus_change:
13747 * @widget: a #GtkWidget
13748 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13750 * Sends the focus change @event to @widget
13752 * This function is not meant to be used by applications. The only time it
13753 * should be used is when it is necessary for a #GtkWidget to assign focus
13754 * to a widget that is semantically owned by the first widget even though
13755 * it's not a direct child - for instance, a search entry in a floating
13756 * window similar to the quick search in #GtkTreeView.
13758 * An example of its usage is:
13761 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13763 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13764 * fevent->focus_change.in = TRUE;
13765 * fevent->focus_change.window = gtk_widget_get_window (widget);
13766 * if (fevent->focus_change.window != NULL)
13767 * g_object_ref (fevent->focus_change.window);
13769 * gtk_widget_send_focus_change (widget, fevent);
13771 * gdk_event_free (event);
13774 * Return value: the return value from the event signal emission: %TRUE
13775 * if the event was handled, and %FALSE otherwise
13780 gtk_widget_send_focus_change (GtkWidget *widget,
13785 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13786 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13788 g_object_ref (widget);
13790 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13792 res = gtk_widget_event (widget, event);
13794 g_object_notify (G_OBJECT (widget), "has-focus");
13796 g_object_unref (widget);
13802 * gtk_widget_in_destruction:
13803 * @widget: a #GtkWidget
13805 * Returns whether the widget is currently being destroyed.
13806 * This information can sometimes be used to avoid doing
13807 * unnecessary work.
13809 * Returns: %TRUE if @widget is being destroyed
13812 gtk_widget_in_destruction (GtkWidget *widget)
13814 return widget->priv->in_destruction;
13818 _gtk_widget_get_resize_pending (GtkWidget *widget)
13820 return widget->priv->resize_pending;
13824 _gtk_widget_set_resize_pending (GtkWidget *widget,
13825 gboolean resize_pending)
13827 widget->priv->resize_pending = resize_pending;
13831 _gtk_widget_get_in_reparent (GtkWidget *widget)
13833 return widget->priv->in_reparent;
13837 _gtk_widget_set_in_reparent (GtkWidget *widget,
13838 gboolean in_reparent)
13840 widget->priv->in_reparent = in_reparent;
13844 _gtk_widget_get_anchored (GtkWidget *widget)
13846 return widget->priv->anchored;
13850 _gtk_widget_set_anchored (GtkWidget *widget,
13853 widget->priv->anchored = anchored;
13857 _gtk_widget_get_shadowed (GtkWidget *widget)
13859 return widget->priv->shadowed;
13863 _gtk_widget_set_shadowed (GtkWidget *widget,
13866 widget->priv->shadowed = shadowed;
13870 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13872 return widget->priv->alloc_needed;
13876 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13877 gboolean alloc_needed)
13879 widget->priv->alloc_needed = alloc_needed;
13883 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13885 return widget->priv->width_request_needed;
13889 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13890 gboolean width_request_needed)
13892 widget->priv->width_request_needed = width_request_needed;
13896 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13898 return widget->priv->height_request_needed;
13902 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13903 gboolean height_request_needed)
13905 widget->priv->height_request_needed = height_request_needed;
13909 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13911 return widget->priv->sizegroup_visited;
13915 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13918 widget->priv->sizegroup_visited = visited;
13922 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13924 return widget->priv->sizegroup_bumping;
13928 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13931 widget->priv->sizegroup_bumping = bumping;
13935 _gtk_widget_add_sizegroup (GtkWidget *widget,
13940 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13941 groups = g_slist_prepend (groups, group);
13942 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13944 widget->priv->have_size_groups = TRUE;
13948 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13953 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13954 groups = g_slist_remove (groups, group);
13955 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13957 widget->priv->have_size_groups = groups != NULL;
13961 _gtk_widget_get_sizegroups (GtkWidget *widget)
13963 if (widget->priv->have_size_groups)
13964 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13970 _gtk_widget_add_attached_window (GtkWidget *widget,
13973 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13977 _gtk_widget_remove_attached_window (GtkWidget *widget,
13980 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13984 * gtk_widget_path_append_for_widget:
13985 * @path: a widget path
13986 * @widget: the widget to append to the widget path
13988 * Appends the data from @widget to the widget hierarchy represented
13989 * by @path. This function is a shortcut for adding information from
13990 * @widget to the given @path. This includes setting the name or
13991 * adding the style classes from @widget.
13993 * Returns: the position where the data was inserted
13998 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14003 g_return_val_if_fail (path != NULL, 0);
14004 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14006 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14008 if (widget->priv->name)
14009 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14011 if (widget->priv->context)
14013 GList *classes, *l;
14015 /* Also add any persistent classes in
14016 * the style context the widget path
14018 classes = gtk_style_context_list_classes (widget->priv->context);
14020 for (l = classes; l; l = l->next)
14021 gtk_widget_path_iter_add_class (path, pos, l->data);
14023 g_list_free (classes);
14030 * gtk_widget_get_path:
14031 * @widget: a #GtkWidget
14033 * Returns the #GtkWidgetPath representing @widget, if the widget
14034 * is not connected to a toplevel widget, a partial path will be
14037 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14040 gtk_widget_get_path (GtkWidget *widget)
14042 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14044 if (!widget->priv->path)
14048 parent = widget->priv->parent;
14051 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14054 /* Widget is either toplevel or unparented, treat both
14055 * as toplevels style wise, since there are situations
14056 * where style properties might be retrieved on that
14059 GtkWidget *attach_widget = NULL;
14061 if (GTK_IS_WINDOW (widget))
14062 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14064 if (attach_widget != NULL)
14065 widget->priv->path = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14067 widget->priv->path = gtk_widget_path_new ();
14069 gtk_widget_path_append_for_widget (widget->priv->path, widget);
14072 if (widget->priv->context)
14073 gtk_style_context_invalidate (widget->priv->context);
14076 return widget->priv->path;
14080 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14082 if (gtk_widget_get_realized (widget))
14083 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14086 /* Compress all style updates so it
14087 * is only emitted once pre-realize.
14089 widget->priv->style_update_pending = TRUE;
14092 if (widget->priv->anchored)
14093 gtk_widget_queue_resize (widget);
14097 * gtk_widget_get_style_context:
14098 * @widget: a #GtkWidget
14100 * Returns the style context associated to @widget.
14102 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14103 * must not be freed.
14106 gtk_widget_get_style_context (GtkWidget *widget)
14108 GtkWidgetPrivate *priv;
14110 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14112 priv = widget->priv;
14114 if (G_UNLIKELY (priv->context == NULL))
14118 priv->context = gtk_style_context_new ();
14120 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14122 screen = gtk_widget_get_screen (widget);
14124 gtk_style_context_set_screen (priv->context, screen);
14127 gtk_style_context_set_parent (priv->context,
14128 gtk_widget_get_style_context (priv->parent));
14130 _gtk_style_context_set_widget (priv->context, widget);
14133 return widget->priv->context;
14137 * gtk_widget_get_modifier_mask:
14138 * @widget: a #GtkWidget
14139 * @intent: the use case for the modifier mask
14141 * Returns the modifier mask the @widget's windowing system backend
14142 * uses for a particular purpose.
14144 * See gdk_keymap_get_modifier_mask().
14146 * Returns: the modifier mask used for @intent.
14151 gtk_widget_get_modifier_mask (GtkWidget *widget,
14152 GdkModifierIntent intent)
14154 GdkDisplay *display;
14156 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14158 display = gtk_widget_get_display (widget);
14160 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14165 _gtk_widget_get_style (GtkWidget *widget)
14167 return widget->priv->style;
14171 _gtk_widget_set_style (GtkWidget *widget,
14174 widget->priv->style = style;