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 "gtkmodifierstyle.h"
60 #include "gtkversion.h"
63 #include "gtktypebuiltins.h"
64 #include "a11y/gtkwidgetaccessible.h"
68 * @Short_description: Base class for all widgets
71 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
72 * widget lifecycle, states and style.
74 * <refsect2 id="geometry-management">
75 * <title>Height-for-width Geometry Management</title>
77 * GTK+ uses a height-for-width (and width-for-height) geometry management
78 * system. Height-for-width means that a widget can change how much
79 * vertical space it needs, depending on the amount of horizontal space
80 * that it is given (and similar for width-for-height). The most common
81 * example is a label that reflows to fill up the available width, wraps
82 * to fewer lines, and therefore needs less height.
84 * Height-for-width geometry management is implemented in GTK+ by way
85 * of five virtual methods:
87 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
88 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
94 * There are some important things to keep in mind when implementing
95 * height-for-width and when using it in container implementations.
97 * The geometry management system will query a widget hierarchy in
98 * only one orientation at a time. When widgets are initially queried
99 * for their minimum sizes it is generally done in two initial passes
100 * in the #GtkSizeRequestMode chosen by the toplevel.
102 * For example, when queried in the normal
103 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
104 * First, the default minimum and natural width for each widget
105 * in the interface will be computed using gtk_widget_get_preferred_width().
106 * Because the preferred widths for each container depend on the preferred
107 * widths of their children, this information propagates up the hierarchy,
108 * and finally a minimum and natural width is determined for the entire
109 * toplevel. Next, the toplevel will use the minimum width to query for the
110 * minimum height contextual to that width using
111 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
112 * recursive operation. The minimum height for the minimum width is normally
113 * used to set the minimum size constraint on the toplevel
114 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
116 * After the toplevel window has initially requested its size in both
117 * dimensions it can go on to allocate itself a reasonable size (or a size
118 * previously specified with gtk_window_set_default_size()). During the
119 * recursive allocation process it's important to note that request cycles
120 * will be recursively executed while container widgets allocate their children.
121 * Each container widget, once allocated a size, will go on to first share the
122 * space in one orientation among its children and then request each child's
123 * height for its target allocated width or its width for allocated height,
124 * depending. In this way a #GtkWidget will typically be requested its size
125 * a number of times before actually being allocated a size. The size a
126 * widget is finally allocated can of course differ from the size it has
127 * requested. For this reason, #GtkWidget caches a small number of results
128 * to avoid re-querying for the same sizes in one allocation cycle.
130 * See <link linkend="container-geometry-management">GtkContainer's
131 * geometry management section</link>
132 * to learn more about how height-for-width allocations are performed
133 * by container widgets.
135 * If a widget does move content around to intelligently use up the
136 * allocated size then it must support the request in both
137 * #GtkSizeRequestModes even if the widget in question only
138 * trades sizes in a single orientation.
140 * For instance, a #GtkLabel that does height-for-width word wrapping
141 * will not expect to have #GtkWidgetClass.get_preferred_height() called
142 * because that call is specific to a width-for-height request. In this
143 * case the label must return the height required for its own minimum
144 * possible width. By following this rule any widget that handles
145 * height-for-width or width-for-height requests will always be allocated
146 * at least enough space to fit its own content.
148 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
149 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
151 * <programlisting><![CDATA[
153 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
155 * if (i_am_in_height_for_width_mode)
159 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
161 * min_height, nat_height);
165 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
166 * it will return the minimum and natural height for the rotated label here.
169 * ]]></programlisting>
171 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
172 * the minimum and natural width:
174 * <programlisting><![CDATA[
176 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
177 * gint *min_width, gint *nat_width)
179 * if (i_am_in_height_for_width_mode)
181 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
185 * ... again if a widget is sometimes operating in width-for-height mode
186 * (like a rotated GtkLabel) it can go ahead and do its real width for
187 * height calculation here.
190 * ]]></programlisting>
192 * Often a widget needs to get its own request during size request or
193 * allocation. For example, when computing height it may need to also
194 * compute width. Or when deciding how to use an allocation, the widget
195 * may need to know its natural size. In these cases, the widget should
196 * be careful to call its virtual methods directly, like this:
198 * <title>Widget calling its own size request method.</title>
200 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
205 * It will not work to use the wrapper functions, such as
206 * gtk_widget_get_preferred_width() inside your own size request
207 * implementation. These return a request adjusted by #GtkSizeGroup
208 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
209 * widget used the wrappers inside its virtual method implementations,
210 * then the adjustments (such as widget margins) would be applied
211 * twice. GTK+ therefore does not allow this and will warn if you try
214 * Of course if you are getting the size request for
215 * <emphasis>another</emphasis> widget, such as a child of a
216 * container, you <emphasis>must</emphasis> use the wrapper APIs.
217 * Otherwise, you would not properly consider widget margins,
218 * #GtkSizeGroup, and so forth.
221 * <refsect2 id="style-properties">
222 * <title>Style Properties</title>
224 * <structname>GtkWidget</structname> introduces <firstterm>style
225 * properties</firstterm> - these are basically object properties that are stored
226 * not on the object, but in the style object associated to the widget. Style
227 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
228 * This mechanism is used for configuring such things as the location of the
229 * scrollbar arrows through the theme, giving theme authors more control over the
230 * look of applications without the need to write a theme engine in C.
233 * Use gtk_widget_class_install_style_property() to install style properties for
234 * a widget class, gtk_widget_class_find_style_property() or
235 * gtk_widget_class_list_style_properties() to get information about existing
236 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
237 * gtk_widget_style_get_valist() to obtain the value of a style property.
240 * <refsect2 id="GtkWidget-BUILDER-UI">
241 * <title>GtkWidget as GtkBuildable</title>
243 * The GtkWidget implementation of the GtkBuildable interface supports a
244 * custom <accelerator> element, which has attributes named key,
245 * modifiers and signal and allows to specify accelerators.
248 * <title>A UI definition fragment specifying an accelerator</title>
249 * <programlisting><![CDATA[
250 * <object class="GtkButton">
251 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
253 * ]]></programlisting>
256 * In addition to accelerators, <structname>GtkWidget</structname> also support a
257 * custom <accessible> element, which supports actions and relations.
258 * Properties on the accessible implementation of an object can be set by accessing the
259 * internal child "accessible" of a <structname>GtkWidget</structname>.
262 * <title>A UI definition fragment specifying an accessible</title>
263 * <programlisting><![CDATA[
264 * <object class="GtkButton" id="label1"/>
265 * <property name="label">I am a Label for a Button</property>
267 * <object class="GtkButton" id="button1">
269 * <action action_name="click" translatable="yes">Click the button.</action>
270 * <relation target="label1" type="labelled-by"/>
272 * <child internal-child="accessible">
273 * <object class="AtkObject" id="a11y-button1">
274 * <property name="AtkObject::name">Clickable Button</property>
278 * ]]></programlisting>
281 * Finally, GtkWidget allows style information such as style classes to
282 * be associated with widgets, using the custom <style> element:
284 * <title>A UI definition fragment specifying an style class</title>
285 * <programlisting><![CDATA[
286 * <object class="GtkButton" id="button1">
288 * <class name="my-special-button-class"/>
289 * <class name="dark-button"/>
292 * ]]></programlisting>
298 /* Add flags here that should not be propagated to children. By default,
299 * all flags will be set on children (think prelight or active), but we
300 * might want to not do this for some.
302 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
303 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
305 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
307 #define GTK_STATE_FLAGS_BITS 7
309 struct _GtkWidgetPrivate
311 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
312 * (defined in "gtkenums.h").
314 guint state_flags : GTK_STATE_FLAGS_BITS;
318 guint in_destruction : 1;
321 guint composite_child : 1;
329 guint can_default : 1;
330 guint has_default : 1;
331 guint receives_default : 1;
334 guint style_update_pending : 1;
335 guint app_paintable : 1;
336 guint double_buffered : 1;
337 guint redraw_on_alloc : 1;
338 guint no_show_all : 1;
339 guint child_visible : 1;
340 guint multidevice : 1;
341 guint has_shape_mask : 1;
342 guint in_reparent : 1;
344 /* Queue-resize related flags */
345 guint alloc_needed : 1;
346 guint width_request_needed : 1;
347 guint height_request_needed : 1;
349 /* Expand-related flags */
350 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
351 guint computed_hexpand : 1; /* computed results (composite of child flags) */
352 guint computed_vexpand : 1;
353 guint hexpand : 1; /* application-forced expand */
355 guint hexpand_set : 1; /* whether to use application-forced */
356 guint vexpand_set : 1; /* instead of computing from children */
358 /* SizeGroup related flags */
359 guint sizegroup_visited : 1;
360 guint sizegroup_bumping : 1;
361 guint have_size_groups : 1;
363 /* The widget's name. If the widget does not have a name
364 * (the name is NULL), then its name (as returned by
365 * "gtk_widget_get_name") is its class's name.
366 * Among other things, the widget name is used to determine
367 * the style to use for a widget.
371 /* The list of attached windows to this widget.
372 * We keep a list in order to call reset_style to all of them,
374 GList *attached_windows;
376 /* The style for the widget. The style contains the
377 * colors the widget should be drawn in for each state
378 * along with graphics contexts used to draw with and
379 * the font to use for text.
382 GtkStyleContext *context;
384 /* Widget's path for styling */
387 /* The widget's allocated size */
388 GtkAllocation allocation;
390 /* The widget's requested sizes */
391 SizeRequestCache requests;
393 /* actions attached to this or any parent widget */
396 /* The widget's window or its parent window if it does
397 * not have a window. (Which will be indicated by the
398 * GTK_NO_WINDOW flag being set).
402 /* The widget's parent */
405 #ifdef G_ENABLE_DEBUG
406 /* Number of gtk_widget_push_verify_invariants () */
407 guint verifying_invariants_count;
408 #endif /* G_ENABLE_DEBUG */
411 struct _GtkWidgetClassPrivate
413 GType accessible_type;
414 AtkRole accessible_role;
443 BUTTON_RELEASE_EVENT,
457 PROPERTY_NOTIFY_EVENT,
458 SELECTION_CLEAR_EVENT,
459 SELECTION_REQUEST_EVENT,
460 SELECTION_NOTIFY_EVENT,
465 VISIBILITY_NOTIFY_EVENT,
479 ACCEL_CLOSURES_CHANGED,
504 PROP_RECEIVES_DEFAULT,
505 PROP_COMPOSITE_CHILD,
513 PROP_DOUBLE_BUFFERED,
528 typedef struct _GtkStateData GtkStateData;
531 STATE_CHANGE_REPLACE,
538 guint flags : GTK_STATE_FLAGS_BITS;
542 /* --- prototypes --- */
543 static void gtk_widget_base_class_init (gpointer g_class);
544 static void gtk_widget_class_init (GtkWidgetClass *klass);
545 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
546 static void gtk_widget_init (GtkWidget *widget);
547 static void gtk_widget_set_property (GObject *object,
551 static void gtk_widget_get_property (GObject *object,
555 static void gtk_widget_constructed (GObject *object);
556 static void gtk_widget_dispose (GObject *object);
557 static void gtk_widget_real_destroy (GtkWidget *object);
558 static void gtk_widget_finalize (GObject *object);
559 static void gtk_widget_real_show (GtkWidget *widget);
560 static void gtk_widget_real_hide (GtkWidget *widget);
561 static void gtk_widget_real_map (GtkWidget *widget);
562 static void gtk_widget_real_unmap (GtkWidget *widget);
563 static void gtk_widget_real_realize (GtkWidget *widget);
564 static void gtk_widget_real_unrealize (GtkWidget *widget);
565 static void gtk_widget_real_size_allocate (GtkWidget *widget,
566 GtkAllocation *allocation);
567 static void gtk_widget_real_style_set (GtkWidget *widget,
568 GtkStyle *previous_style);
569 static void gtk_widget_real_direction_changed(GtkWidget *widget,
570 GtkTextDirection previous_direction);
572 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
573 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
576 gboolean keyboard_tip,
577 GtkTooltip *tooltip);
578 static void gtk_widget_real_style_updated (GtkWidget *widget);
579 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
580 GtkWidgetHelpType help_type);
582 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
584 GParamSpec **pspecs);
585 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
587 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
589 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
590 GdkEventFocus *event);
591 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
592 GdkEventFocus *event);
593 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
594 GdkEventTouch *event);
595 static gboolean gtk_widget_real_focus (GtkWidget *widget,
596 GtkDirectionType direction);
597 static void gtk_widget_real_move_focus (GtkWidget *widget,
598 GtkDirectionType direction);
599 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
600 GtkDirectionType direction);
601 #ifdef G_ENABLE_DEBUG
602 static void gtk_widget_verify_invariants (GtkWidget *widget);
603 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
604 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
606 #define gtk_widget_verify_invariants(widget)
607 #define gtk_widget_push_verify_invariants(widget)
608 #define gtk_widget_pop_verify_invariants(widget)
610 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
611 static void gtk_widget_update_pango_context (GtkWidget *widget);
612 static void gtk_widget_propagate_state (GtkWidget *widget,
615 static gint gtk_widget_event_internal (GtkWidget *widget,
617 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
618 gboolean group_cycling);
619 static void gtk_widget_real_get_width (GtkWidget *widget,
622 static void gtk_widget_real_get_height (GtkWidget *widget,
625 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
627 gint *minimum_height,
628 gint *natural_height);
629 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
632 gint *natural_width);
633 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
634 GtkStateFlags old_state);
635 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
636 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
638 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
639 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
640 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
641 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
642 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
643 cairo_region_t *region);
644 static GdkScreen * gtk_widget_get_screen_unchecked (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 * @child_property: 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.
1726 * Returns: %TRUE to stop other handlers from being invoked for the event.
1727 % %FALSE to propagate the event further.
1731 widget_signals[DRAW] =
1732 g_signal_new (I_("draw"),
1733 G_TYPE_FROM_CLASS (gobject_class),
1735 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1736 _gtk_boolean_handled_accumulator, NULL,
1737 gtk_widget_draw_marshaller,
1739 CAIRO_GOBJECT_TYPE_CONTEXT);
1740 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1741 gtk_widget_draw_marshallerv);
1744 * GtkWidget::mnemonic-activate:
1745 * @widget: the object which received the signal.
1748 * Returns: %TRUE to stop other handlers from being invoked for the event.
1749 * %FALSE to propagate the event further.
1751 widget_signals[MNEMONIC_ACTIVATE] =
1752 g_signal_new (I_("mnemonic-activate"),
1753 G_TYPE_FROM_CLASS (gobject_class),
1755 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1756 _gtk_boolean_handled_accumulator, NULL,
1757 _gtk_marshal_BOOLEAN__BOOLEAN,
1762 * GtkWidget::grab-focus:
1763 * @widget: the object which received the signal.
1765 widget_signals[GRAB_FOCUS] =
1766 g_signal_new (I_("grab-focus"),
1767 G_TYPE_FROM_CLASS (gobject_class),
1768 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1769 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1771 _gtk_marshal_VOID__VOID,
1776 * @widget: the object which received the signal.
1779 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1781 widget_signals[FOCUS] =
1782 g_signal_new (I_("focus"),
1783 G_TYPE_FROM_CLASS (klass),
1785 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1786 _gtk_boolean_handled_accumulator, NULL,
1787 _gtk_marshal_BOOLEAN__ENUM,
1789 GTK_TYPE_DIRECTION_TYPE);
1792 * GtkWidget::move-focus:
1793 * @widget: the object which received the signal.
1796 widget_signals[MOVE_FOCUS] =
1797 g_signal_new (I_("move-focus"),
1798 G_TYPE_FROM_CLASS (klass),
1799 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1800 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1802 _gtk_marshal_VOID__ENUM,
1805 GTK_TYPE_DIRECTION_TYPE);
1808 * GtkWidget::keynav-failed:
1809 * @widget: the object which received the signal
1810 * @direction: the direction of movement
1812 * Gets emitted if keyboard navigation fails.
1813 * See gtk_widget_keynav_failed() for details.
1815 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1816 * if the emitting widget should try to handle the keyboard
1817 * navigation attempt in its parent container(s).
1821 widget_signals[KEYNAV_FAILED] =
1822 g_signal_new (I_("keynav-failed"),
1823 G_TYPE_FROM_CLASS (klass),
1825 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1826 _gtk_boolean_handled_accumulator, NULL,
1827 _gtk_marshal_BOOLEAN__ENUM,
1829 GTK_TYPE_DIRECTION_TYPE);
1833 * @widget: the object which received the signal.
1834 * @event: the #GdkEvent which triggered this signal
1836 * The GTK+ main loop will emit three signals for each GDK event delivered
1837 * to a widget: one generic ::event signal, another, more specific,
1838 * signal that matches the type of event delivered (e.g.
1839 * #GtkWidget::key-press-event) and finally a generic
1840 * #GtkWidget::event-after signal.
1842 * Returns: %TRUE to stop other handlers from being invoked for the event
1843 * and to cancel the emission of the second specific ::event signal.
1844 * %FALSE to propagate the event further and to allow the emission of
1845 * the second signal. The ::event-after signal is emitted regardless of
1848 widget_signals[EVENT] =
1849 g_signal_new (I_("event"),
1850 G_TYPE_FROM_CLASS (klass),
1852 G_STRUCT_OFFSET (GtkWidgetClass, event),
1853 _gtk_boolean_handled_accumulator, NULL,
1854 _gtk_marshal_BOOLEAN__BOXED,
1856 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1857 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1858 _gtk_marshal_BOOLEAN__BOXEDv);
1861 * GtkWidget::event-after:
1862 * @widget: the object which received the signal.
1863 * @event: the #GdkEvent which triggered this signal
1865 * After the emission of the #GtkWidget::event signal and (optionally)
1866 * the second more specific signal, ::event-after will be emitted
1867 * regardless of the previous two signals handlers return values.
1870 widget_signals[EVENT_AFTER] =
1871 g_signal_new (I_("event-after"),
1872 G_TYPE_FROM_CLASS (klass),
1876 _gtk_marshal_VOID__BOXED,
1878 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1879 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1880 _gtk_marshal_BOOLEAN__BOXEDv);
1883 * GtkWidget::button-press-event:
1884 * @widget: the object which received the signal.
1885 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1888 * The ::button-press-event signal will be emitted when a button
1889 * (typically from a mouse) is pressed.
1891 * To receive this signal, the #GdkWindow associated to the
1892 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1894 * This signal will be sent to the grab widget if there is one.
1896 * Returns: %TRUE to stop other handlers from being invoked for the event.
1897 * %FALSE to propagate the event further.
1899 widget_signals[BUTTON_PRESS_EVENT] =
1900 g_signal_new (I_("button-press-event"),
1901 G_TYPE_FROM_CLASS (klass),
1903 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1904 _gtk_boolean_handled_accumulator, NULL,
1905 _gtk_marshal_BOOLEAN__BOXED,
1907 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1908 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1909 _gtk_marshal_BOOLEAN__BOXEDv);
1912 * GtkWidget::button-release-event:
1913 * @widget: the object which received the signal.
1914 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1917 * The ::button-release-event signal will be emitted when a button
1918 * (typically from a mouse) is released.
1920 * To receive this signal, the #GdkWindow associated to the
1921 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1923 * This signal will be sent to the grab widget if there is one.
1925 * Returns: %TRUE to stop other handlers from being invoked for the event.
1926 * %FALSE to propagate the event further.
1928 widget_signals[BUTTON_RELEASE_EVENT] =
1929 g_signal_new (I_("button-release-event"),
1930 G_TYPE_FROM_CLASS (klass),
1932 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1933 _gtk_boolean_handled_accumulator, NULL,
1934 _gtk_marshal_BOOLEAN__BOXED,
1936 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1937 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1938 _gtk_marshal_BOOLEAN__BOXEDv);
1940 widget_signals[TOUCH_EVENT] =
1941 g_signal_new (I_("touch-event"),
1942 G_TYPE_FROM_CLASS (klass),
1944 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1945 _gtk_boolean_handled_accumulator, NULL,
1946 _gtk_marshal_BOOLEAN__BOXED,
1948 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1949 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1950 _gtk_marshal_BOOLEAN__BOXEDv);
1953 * GtkWidget::scroll-event:
1954 * @widget: the object which received the signal.
1955 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1958 * The ::scroll-event signal is emitted when a button in the 4 to 7
1959 * range is pressed. Wheel mice are usually configured to generate
1960 * button press events for buttons 4 and 5 when the wheel is turned.
1962 * To receive this signal, the #GdkWindow associated to the widget needs
1963 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1965 * This signal will be sent to the grab widget if there is one.
1967 * Returns: %TRUE to stop other handlers from being invoked for the event.
1968 * %FALSE to propagate the event further.
1970 widget_signals[SCROLL_EVENT] =
1971 g_signal_new (I_("scroll-event"),
1972 G_TYPE_FROM_CLASS (klass),
1974 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1975 _gtk_boolean_handled_accumulator, NULL,
1976 _gtk_marshal_BOOLEAN__BOXED,
1978 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1979 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1980 _gtk_marshal_BOOLEAN__BOXEDv);
1983 * GtkWidget::motion-notify-event:
1984 * @widget: the object which received the signal.
1985 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1988 * The ::motion-notify-event signal is emitted when the pointer moves
1989 * over the widget's #GdkWindow.
1991 * To receive this signal, the #GdkWindow associated to the widget
1992 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1994 * This signal will be sent to the grab widget if there is one.
1996 * Returns: %TRUE to stop other handlers from being invoked for the event.
1997 * %FALSE to propagate the event further.
1999 widget_signals[MOTION_NOTIFY_EVENT] =
2000 g_signal_new (I_("motion-notify-event"),
2001 G_TYPE_FROM_CLASS (klass),
2003 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2004 _gtk_boolean_handled_accumulator, NULL,
2005 _gtk_marshal_BOOLEAN__BOXED,
2007 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2008 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2009 _gtk_marshal_BOOLEAN__BOXEDv);
2012 * GtkWidget::composited-changed:
2013 * @widget: the object on which the signal is emitted
2015 * The ::composited-changed signal is emitted when the composited
2016 * status of @widget<!-- -->s screen changes.
2017 * See gdk_screen_is_composited().
2019 widget_signals[COMPOSITED_CHANGED] =
2020 g_signal_new (I_("composited-changed"),
2021 G_TYPE_FROM_CLASS (klass),
2022 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2023 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2025 _gtk_marshal_VOID__VOID,
2029 * GtkWidget::delete-event:
2030 * @widget: the object which received the signal
2031 * @event: the event which triggered this signal
2033 * The ::delete-event signal is emitted if a user requests that
2034 * a toplevel window is closed. The default handler for this signal
2035 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2036 * this signal will cause the window to be hidden instead, so that
2037 * it can later be shown again without reconstructing it.
2039 * Returns: %TRUE to stop other handlers from being invoked for the event.
2040 * %FALSE to propagate the event further.
2042 widget_signals[DELETE_EVENT] =
2043 g_signal_new (I_("delete-event"),
2044 G_TYPE_FROM_CLASS (klass),
2046 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2047 _gtk_boolean_handled_accumulator, NULL,
2048 _gtk_marshal_BOOLEAN__BOXED,
2050 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2051 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2052 _gtk_marshal_BOOLEAN__BOXEDv);
2055 * GtkWidget::destroy-event:
2056 * @widget: the object which received the signal.
2057 * @event: the event which triggered this signal
2059 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2060 * You rarely get this signal, because most widgets disconnect themselves
2061 * from their window before they destroy it, so no widget owns the
2062 * window at destroy time.
2064 * To receive this signal, the #GdkWindow associated to the widget needs
2065 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2066 * automatically for all new windows.
2068 * Returns: %TRUE to stop other handlers from being invoked for the event.
2069 * %FALSE to propagate the event further.
2071 widget_signals[DESTROY_EVENT] =
2072 g_signal_new (I_("destroy-event"),
2073 G_TYPE_FROM_CLASS (klass),
2075 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2076 _gtk_boolean_handled_accumulator, NULL,
2077 _gtk_marshal_BOOLEAN__BOXED,
2079 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2080 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2081 _gtk_marshal_BOOLEAN__BOXEDv);
2084 * GtkWidget::key-press-event:
2085 * @widget: the object which received the signal
2086 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2088 * The ::key-press-event signal is emitted when a key is pressed. The signal
2089 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2091 * To receive this signal, the #GdkWindow associated to the widget needs
2092 * to enable the #GDK_KEY_PRESS_MASK mask.
2094 * This signal will be sent to the grab widget if there is one.
2096 * Returns: %TRUE to stop other handlers from being invoked for the event.
2097 * %FALSE to propagate the event further.
2099 widget_signals[KEY_PRESS_EVENT] =
2100 g_signal_new (I_("key-press-event"),
2101 G_TYPE_FROM_CLASS (klass),
2103 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2104 _gtk_boolean_handled_accumulator, NULL,
2105 _gtk_marshal_BOOLEAN__BOXED,
2107 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2108 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2109 _gtk_marshal_BOOLEAN__BOXEDv);
2112 * GtkWidget::key-release-event:
2113 * @widget: the object which received the signal
2114 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2116 * The ::key-release-event signal is emitted when a key is released.
2118 * To receive this signal, the #GdkWindow associated to the widget needs
2119 * to enable the #GDK_KEY_RELEASE_MASK mask.
2121 * This signal will be sent to the grab widget if there is one.
2123 * Returns: %TRUE to stop other handlers from being invoked for the event.
2124 * %FALSE to propagate the event further.
2126 widget_signals[KEY_RELEASE_EVENT] =
2127 g_signal_new (I_("key-release-event"),
2128 G_TYPE_FROM_CLASS (klass),
2130 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2131 _gtk_boolean_handled_accumulator, NULL,
2132 _gtk_marshal_BOOLEAN__BOXED,
2134 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2135 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2136 _gtk_marshal_BOOLEAN__BOXEDv);
2139 * GtkWidget::enter-notify-event:
2140 * @widget: the object which received the signal
2141 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2144 * The ::enter-notify-event will be emitted when the pointer enters
2145 * the @widget's window.
2147 * To receive this signal, the #GdkWindow associated to the widget needs
2148 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2150 * This signal will be sent to the grab widget if there is one.
2152 * Returns: %TRUE to stop other handlers from being invoked for the event.
2153 * %FALSE to propagate the event further.
2155 widget_signals[ENTER_NOTIFY_EVENT] =
2156 g_signal_new (I_("enter-notify-event"),
2157 G_TYPE_FROM_CLASS (klass),
2159 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2160 _gtk_boolean_handled_accumulator, NULL,
2161 _gtk_marshal_BOOLEAN__BOXED,
2163 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2164 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2165 _gtk_marshal_BOOLEAN__BOXEDv);
2168 * GtkWidget::leave-notify-event:
2169 * @widget: the object which received the signal
2170 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2173 * The ::leave-notify-event will be emitted when the pointer leaves
2174 * the @widget's window.
2176 * To receive this signal, the #GdkWindow associated to the widget needs
2177 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2179 * This signal will be sent to the grab widget if there is one.
2181 * Returns: %TRUE to stop other handlers from being invoked for the event.
2182 * %FALSE to propagate the event further.
2184 widget_signals[LEAVE_NOTIFY_EVENT] =
2185 g_signal_new (I_("leave-notify-event"),
2186 G_TYPE_FROM_CLASS (klass),
2188 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2189 _gtk_boolean_handled_accumulator, NULL,
2190 _gtk_marshal_BOOLEAN__BOXED,
2192 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2193 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2194 _gtk_marshal_BOOLEAN__BOXEDv);
2197 * GtkWidget::configure-event:
2198 * @widget: the object which received the signal
2199 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2202 * The ::configure-event signal will be emitted when the size, position or
2203 * stacking of the @widget's window has changed.
2205 * To receive this signal, the #GdkWindow associated to the widget needs
2206 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2207 * automatically for all new windows.
2209 * Returns: %TRUE to stop other handlers from being invoked for the event.
2210 * %FALSE to propagate the event further.
2212 widget_signals[CONFIGURE_EVENT] =
2213 g_signal_new (I_("configure-event"),
2214 G_TYPE_FROM_CLASS (klass),
2216 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2217 _gtk_boolean_handled_accumulator, NULL,
2218 _gtk_marshal_BOOLEAN__BOXED,
2220 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2222 _gtk_marshal_BOOLEAN__BOXEDv);
2225 * GtkWidget::focus-in-event:
2226 * @widget: the object which received the signal
2227 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2230 * The ::focus-in-event signal will be emitted when the keyboard focus
2231 * enters the @widget's window.
2233 * To receive this signal, the #GdkWindow associated to the widget needs
2234 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2236 * Returns: %TRUE to stop other handlers from being invoked for the event.
2237 * %FALSE to propagate the event further.
2239 widget_signals[FOCUS_IN_EVENT] =
2240 g_signal_new (I_("focus-in-event"),
2241 G_TYPE_FROM_CLASS (klass),
2243 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2244 _gtk_boolean_handled_accumulator, NULL,
2245 _gtk_marshal_BOOLEAN__BOXED,
2247 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2248 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2249 _gtk_marshal_BOOLEAN__BOXEDv);
2252 * GtkWidget::focus-out-event:
2253 * @widget: the object which received the signal
2254 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2257 * The ::focus-out-event signal will be emitted when the keyboard focus
2258 * leaves the @widget's window.
2260 * To receive this signal, the #GdkWindow associated to the widget needs
2261 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2263 * Returns: %TRUE to stop other handlers from being invoked for the event.
2264 * %FALSE to propagate the event further.
2266 widget_signals[FOCUS_OUT_EVENT] =
2267 g_signal_new (I_("focus-out-event"),
2268 G_TYPE_FROM_CLASS (klass),
2270 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2271 _gtk_boolean_handled_accumulator, NULL,
2272 _gtk_marshal_BOOLEAN__BOXED,
2274 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2275 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2276 _gtk_marshal_BOOLEAN__BOXEDv);
2279 * GtkWidget::map-event:
2280 * @widget: the object which received the signal
2281 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2283 * The ::map-event signal will be emitted when the @widget's window is
2284 * mapped. A window is mapped when it becomes visible on the screen.
2286 * To receive this signal, the #GdkWindow associated to the widget needs
2287 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2288 * automatically for all new windows.
2290 * Returns: %TRUE to stop other handlers from being invoked for the event.
2291 * %FALSE to propagate the event further.
2293 widget_signals[MAP_EVENT] =
2294 g_signal_new (I_("map-event"),
2295 G_TYPE_FROM_CLASS (klass),
2297 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2298 _gtk_boolean_handled_accumulator, NULL,
2299 _gtk_marshal_BOOLEAN__BOXED,
2301 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2302 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2303 _gtk_marshal_BOOLEAN__BOXEDv);
2306 * GtkWidget::unmap-event:
2307 * @widget: the object which received the signal
2308 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2310 * The ::unmap-event signal will be emitted when the @widget's window is
2311 * unmapped. A window is unmapped when it becomes invisible on the screen.
2313 * To receive this signal, the #GdkWindow associated to the widget needs
2314 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2315 * automatically for all new windows.
2317 * Returns: %TRUE to stop other handlers from being invoked for the event.
2318 * %FALSE to propagate the event further.
2320 widget_signals[UNMAP_EVENT] =
2321 g_signal_new (I_("unmap-event"),
2322 G_TYPE_FROM_CLASS (klass),
2324 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2325 _gtk_boolean_handled_accumulator, NULL,
2326 _gtk_marshal_BOOLEAN__BOXED,
2328 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2329 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2330 _gtk_marshal_BOOLEAN__BOXEDv);
2333 * GtkWidget::property-notify-event:
2334 * @widget: the object which received the signal
2335 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2338 * The ::property-notify-event signal will be emitted when a property on
2339 * the @widget's window has been changed or deleted.
2341 * To receive this signal, the #GdkWindow associated to the widget needs
2342 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2344 * Returns: %TRUE to stop other handlers from being invoked for the event.
2345 * %FALSE to propagate the event further.
2347 widget_signals[PROPERTY_NOTIFY_EVENT] =
2348 g_signal_new (I_("property-notify-event"),
2349 G_TYPE_FROM_CLASS (klass),
2351 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2352 _gtk_boolean_handled_accumulator, NULL,
2353 _gtk_marshal_BOOLEAN__BOXED,
2355 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2356 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2357 _gtk_marshal_BOOLEAN__BOXEDv);
2360 * GtkWidget::selection-clear-event:
2361 * @widget: the object which received the signal
2362 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2365 * The ::selection-clear-event signal will be emitted when the
2366 * the @widget's window has lost ownership of a selection.
2368 * Returns: %TRUE to stop other handlers from being invoked for the event.
2369 * %FALSE to propagate the event further.
2371 widget_signals[SELECTION_CLEAR_EVENT] =
2372 g_signal_new (I_("selection-clear-event"),
2373 G_TYPE_FROM_CLASS (klass),
2375 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2376 _gtk_boolean_handled_accumulator, NULL,
2377 _gtk_marshal_BOOLEAN__BOXED,
2379 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2380 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2381 _gtk_marshal_BOOLEAN__BOXEDv);
2384 * GtkWidget::selection-request-event:
2385 * @widget: the object which received the signal
2386 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2389 * The ::selection-request-event signal will be emitted when
2390 * another client requests ownership of the selection owned by
2391 * the @widget's window.
2393 * Returns: %TRUE to stop other handlers from being invoked for the event.
2394 * %FALSE to propagate the event further.
2396 widget_signals[SELECTION_REQUEST_EVENT] =
2397 g_signal_new (I_("selection-request-event"),
2398 G_TYPE_FROM_CLASS (klass),
2400 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2401 _gtk_boolean_handled_accumulator, NULL,
2402 _gtk_marshal_BOOLEAN__BOXED,
2404 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2405 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2406 _gtk_marshal_BOOLEAN__BOXEDv);
2409 * GtkWidget::selection-notify-event:
2410 * @widget: the object which received the signal.
2411 * @event: (type Gdk.EventSelection):
2413 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2415 widget_signals[SELECTION_NOTIFY_EVENT] =
2416 g_signal_new (I_("selection-notify-event"),
2417 G_TYPE_FROM_CLASS (klass),
2419 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2420 _gtk_boolean_handled_accumulator, NULL,
2421 _gtk_marshal_BOOLEAN__BOXED,
2423 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2424 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2425 _gtk_marshal_BOOLEAN__BOXEDv);
2428 * GtkWidget::selection-received:
2429 * @widget: the object which received the signal.
2433 widget_signals[SELECTION_RECEIVED] =
2434 g_signal_new (I_("selection-received"),
2435 G_TYPE_FROM_CLASS (klass),
2437 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2439 _gtk_marshal_VOID__BOXED_UINT,
2441 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2445 * GtkWidget::selection-get:
2446 * @widget: the object which received the signal.
2451 widget_signals[SELECTION_GET] =
2452 g_signal_new (I_("selection-get"),
2453 G_TYPE_FROM_CLASS (klass),
2455 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2457 _gtk_marshal_VOID__BOXED_UINT_UINT,
2459 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2464 * GtkWidget::proximity-in-event:
2465 * @widget: the object which received the signal
2466 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2469 * To receive this signal the #GdkWindow associated to the widget needs
2470 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2472 * This signal will be sent to the grab widget if there is one.
2474 * Returns: %TRUE to stop other handlers from being invoked for the event.
2475 * %FALSE to propagate the event further.
2477 widget_signals[PROXIMITY_IN_EVENT] =
2478 g_signal_new (I_("proximity-in-event"),
2479 G_TYPE_FROM_CLASS (klass),
2481 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2482 _gtk_boolean_handled_accumulator, NULL,
2483 _gtk_marshal_BOOLEAN__BOXED,
2485 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2486 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2487 _gtk_marshal_BOOLEAN__BOXEDv);
2490 * GtkWidget::proximity-out-event:
2491 * @widget: the object which received the signal
2492 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2495 * To receive this signal the #GdkWindow associated to the widget needs
2496 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2498 * This signal will be sent to the grab widget if there is one.
2500 * Returns: %TRUE to stop other handlers from being invoked for the event.
2501 * %FALSE to propagate the event further.
2503 widget_signals[PROXIMITY_OUT_EVENT] =
2504 g_signal_new (I_("proximity-out-event"),
2505 G_TYPE_FROM_CLASS (klass),
2507 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2508 _gtk_boolean_handled_accumulator, NULL,
2509 _gtk_marshal_BOOLEAN__BOXED,
2511 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2512 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2513 _gtk_marshal_BOOLEAN__BOXEDv);
2516 * GtkWidget::drag-leave:
2517 * @widget: the object which received the signal.
2518 * @context: the drag context
2519 * @time: the timestamp of the motion event
2521 * The ::drag-leave signal is emitted on the drop site when the cursor
2522 * leaves the widget. A typical reason to connect to this signal is to
2523 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2524 * with gtk_drag_unhighlight()
2526 widget_signals[DRAG_LEAVE] =
2527 g_signal_new (I_("drag-leave"),
2528 G_TYPE_FROM_CLASS (klass),
2530 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2532 _gtk_marshal_VOID__OBJECT_UINT,
2534 GDK_TYPE_DRAG_CONTEXT,
2538 * GtkWidget::drag-begin:
2539 * @widget: the object which received the signal
2540 * @context: the drag context
2542 * The ::drag-begin signal is emitted on the drag source when a drag is
2543 * started. A typical reason to connect to this signal is to set up a
2544 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2546 * Note that some widgets set up a drag icon in the default handler of
2547 * this signal, so you may have to use g_signal_connect_after() to
2548 * override what the default handler did.
2550 widget_signals[DRAG_BEGIN] =
2551 g_signal_new (I_("drag-begin"),
2552 G_TYPE_FROM_CLASS (klass),
2554 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2556 _gtk_marshal_VOID__OBJECT,
2558 GDK_TYPE_DRAG_CONTEXT);
2561 * GtkWidget::drag-end:
2562 * @widget: the object which received the signal
2563 * @context: the drag context
2565 * The ::drag-end signal is emitted on the drag source when a drag is
2566 * finished. A typical reason to connect to this signal is to undo
2567 * things done in #GtkWidget::drag-begin.
2569 widget_signals[DRAG_END] =
2570 g_signal_new (I_("drag-end"),
2571 G_TYPE_FROM_CLASS (klass),
2573 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2575 _gtk_marshal_VOID__OBJECT,
2577 GDK_TYPE_DRAG_CONTEXT);
2580 * GtkWidget::drag-data-delete:
2581 * @widget: the object which received the signal
2582 * @context: the drag context
2584 * The ::drag-data-delete signal is emitted on the drag source when a drag
2585 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2586 * handler is responsible for deleting the data that has been dropped. What
2587 * "delete" means depends on the context of the drag operation.
2589 widget_signals[DRAG_DATA_DELETE] =
2590 g_signal_new (I_("drag-data-delete"),
2591 G_TYPE_FROM_CLASS (klass),
2593 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2595 _gtk_marshal_VOID__OBJECT,
2597 GDK_TYPE_DRAG_CONTEXT);
2600 * GtkWidget::drag-failed:
2601 * @widget: the object which received the signal
2602 * @context: the drag context
2603 * @result: the result of the drag operation
2605 * The ::drag-failed signal is emitted on the drag source when a drag has
2606 * failed. The signal handler may hook custom code to handle a failed DND
2607 * operation based on the type of error, it returns %TRUE is the failure has
2608 * been already handled (not showing the default "drag operation failed"
2609 * animation), otherwise it returns %FALSE.
2611 * Return value: %TRUE if the failed drag operation has been already handled.
2615 widget_signals[DRAG_FAILED] =
2616 g_signal_new (I_("drag-failed"),
2617 G_TYPE_FROM_CLASS (klass),
2619 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2620 _gtk_boolean_handled_accumulator, NULL,
2621 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2623 GDK_TYPE_DRAG_CONTEXT,
2624 GTK_TYPE_DRAG_RESULT);
2627 * GtkWidget::drag-motion:
2628 * @widget: the object which received the signal
2629 * @context: the drag context
2630 * @x: the x coordinate of the current cursor position
2631 * @y: the y coordinate of the current cursor position
2632 * @time: the timestamp of the motion event
2634 * The ::drag-motion signal is emitted on the drop site when the user
2635 * moves the cursor over the widget during a drag. The signal handler
2636 * must determine whether the cursor position is in a drop zone or not.
2637 * If it is not in a drop zone, it returns %FALSE and no further processing
2638 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2639 * handler is responsible for providing the necessary information for
2640 * displaying feedback to the user, by calling gdk_drag_status().
2642 * If the decision whether the drop will be accepted or rejected can't be
2643 * made based solely on the cursor position and the type of the data, the
2644 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2645 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2646 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2647 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2648 * when using the drag-motion signal that way.
2650 * Also note that there is no drag-enter signal. The drag receiver has to
2651 * keep track of whether he has received any drag-motion signals since the
2652 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2653 * an "enter" signal. Upon an "enter", the handler will typically highlight
2654 * the drop site with gtk_drag_highlight().
2657 * drag_motion (GtkWidget *widget,
2658 * GdkDragContext *context,
2665 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2667 * if (!private_data->drag_highlight)
2669 * private_data->drag_highlight = 1;
2670 * gtk_drag_highlight (widget);
2673 * target = gtk_drag_dest_find_target (widget, context, NULL);
2674 * if (target == GDK_NONE)
2675 * gdk_drag_status (context, 0, time);
2678 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2679 * gtk_drag_get_data (widget, context, target, time);
2686 * drag_data_received (GtkWidget *widget,
2687 * GdkDragContext *context,
2690 * GtkSelectionData *selection_data,
2694 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2696 * if (private_data->suggested_action)
2698 * private_data->suggested_action = 0;
2700 * /* We are getting this data due to a request in drag_motion,
2701 * * rather than due to a request in drag_drop, so we are just
2702 * * supposed to call gdk_drag_status(), not actually paste in
2705 * str = gtk_selection_data_get_text (selection_data);
2706 * if (!data_is_acceptable (str))
2707 * gdk_drag_status (context, 0, time);
2709 * gdk_drag_status (context, private_data->suggested_action, time);
2713 * /* accept the drop */
2718 * Returns: whether the cursor position is in a drop zone
2720 widget_signals[DRAG_MOTION] =
2721 g_signal_new (I_("drag-motion"),
2722 G_TYPE_FROM_CLASS (klass),
2724 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2725 _gtk_boolean_handled_accumulator, NULL,
2726 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2728 GDK_TYPE_DRAG_CONTEXT,
2734 * GtkWidget::drag-drop:
2735 * @widget: the object which received the signal
2736 * @context: the drag context
2737 * @x: the x coordinate of the current cursor position
2738 * @y: the y coordinate of the current cursor position
2739 * @time: the timestamp of the motion event
2741 * The ::drag-drop signal is emitted on the drop site when the user drops
2742 * the data onto the widget. The signal handler must determine whether
2743 * the cursor position is in a drop zone or not. If it is not in a drop
2744 * zone, it returns %FALSE and no further processing is necessary.
2745 * Otherwise, the handler returns %TRUE. In this case, the handler must
2746 * ensure that gtk_drag_finish() is called to let the source know that
2747 * the drop is done. The call to gtk_drag_finish() can be done either
2748 * directly or in a #GtkWidget::drag-data-received handler which gets
2749 * triggered by calling gtk_drag_get_data() to receive the data for one
2750 * or more of the supported targets.
2752 * Returns: whether the cursor position is in a drop zone
2754 widget_signals[DRAG_DROP] =
2755 g_signal_new (I_("drag-drop"),
2756 G_TYPE_FROM_CLASS (klass),
2758 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2759 _gtk_boolean_handled_accumulator, NULL,
2760 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2762 GDK_TYPE_DRAG_CONTEXT,
2768 * GtkWidget::drag-data-get:
2769 * @widget: the object which received the signal
2770 * @context: the drag context
2771 * @data: the #GtkSelectionData to be filled with the dragged data
2772 * @info: the info that has been registered with the target in the
2774 * @time: the timestamp at which the data was requested
2776 * The ::drag-data-get signal is emitted on the drag source when the drop
2777 * site requests the data which is dragged. It is the responsibility of
2778 * the signal handler to fill @data with the data in the format which
2779 * is indicated by @info. See gtk_selection_data_set() and
2780 * gtk_selection_data_set_text().
2782 widget_signals[DRAG_DATA_GET] =
2783 g_signal_new (I_("drag-data-get"),
2784 G_TYPE_FROM_CLASS (klass),
2786 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2788 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2790 GDK_TYPE_DRAG_CONTEXT,
2791 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2796 * GtkWidget::drag-data-received:
2797 * @widget: the object which received the signal
2798 * @context: the drag context
2799 * @x: where the drop happened
2800 * @y: where the drop happened
2801 * @data: the received data
2802 * @info: the info that has been registered with the target in the
2804 * @time: the timestamp at which the data was received
2806 * The ::drag-data-received signal is emitted on the drop site when the
2807 * dragged data has been received. If the data was received in order to
2808 * determine whether the drop will be accepted, the handler is expected
2809 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2810 * If the data was received in response to a #GtkWidget::drag-drop signal
2811 * (and this is the last target to be received), the handler for this
2812 * signal is expected to process the received data and then call
2813 * gtk_drag_finish(), setting the @success parameter depending on
2814 * whether the data was processed successfully.
2816 * The handler may inspect the selected action with
2817 * gdk_drag_context_get_selected_action() before calling
2818 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2819 * shown in the following example:
2822 * drag_data_received (GtkWidget *widget,
2823 * GdkDragContext *context,
2826 * GtkSelectionData *data,
2830 * if ((data->length >= 0) && (data->format == 8))
2832 * GdkDragAction action;
2834 * /* handle data here */
2836 * action = gdk_drag_context_get_selected_action (context);
2837 * if (action == GDK_ACTION_ASK)
2839 * GtkWidget *dialog;
2842 * dialog = gtk_message_dialog_new (NULL,
2843 * GTK_DIALOG_MODAL |
2844 * GTK_DIALOG_DESTROY_WITH_PARENT,
2846 * GTK_BUTTONS_YES_NO,
2847 * "Move the data ?\n");
2848 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2849 * gtk_widget_destroy (dialog);
2851 * if (response == GTK_RESPONSE_YES)
2852 * action = GDK_ACTION_MOVE;
2854 * action = GDK_ACTION_COPY;
2857 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2860 * gtk_drag_finish (context, FALSE, FALSE, time);
2864 widget_signals[DRAG_DATA_RECEIVED] =
2865 g_signal_new (I_("drag-data-received"),
2866 G_TYPE_FROM_CLASS (klass),
2868 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2870 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2872 GDK_TYPE_DRAG_CONTEXT,
2875 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2880 * GtkWidget::visibility-notify-event:
2881 * @widget: the object which received the signal
2882 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2883 * triggered this signal.
2885 * The ::visibility-notify-event will be emitted when the @widget's window
2886 * is obscured or unobscured.
2888 * To receive this signal the #GdkWindow associated to the widget needs
2889 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2891 * Returns: %TRUE to stop other handlers from being invoked for the event.
2892 * %FALSE to propagate the event further.
2894 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2895 g_signal_new (I_("visibility-notify-event"),
2896 G_TYPE_FROM_CLASS (klass),
2898 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2899 _gtk_boolean_handled_accumulator, NULL,
2900 _gtk_marshal_BOOLEAN__BOXED,
2902 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2905 * GtkWidget::window-state-event:
2906 * @widget: the object which received the signal
2907 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2908 * triggered this signal.
2910 * The ::window-state-event will be emitted when the state of the
2911 * toplevel window associated to the @widget changes.
2913 * To receive this signal the #GdkWindow associated to the widget
2914 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2915 * this mask automatically for all new windows.
2917 * Returns: %TRUE to stop other handlers from being invoked for the
2918 * event. %FALSE to propagate the event further.
2920 widget_signals[WINDOW_STATE_EVENT] =
2921 g_signal_new (I_("window-state-event"),
2922 G_TYPE_FROM_CLASS (klass),
2924 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2925 _gtk_boolean_handled_accumulator, NULL,
2926 _gtk_marshal_BOOLEAN__BOXED,
2928 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2929 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2930 _gtk_marshal_BOOLEAN__BOXEDv);
2933 * GtkWidget::damage-event:
2934 * @widget: the object which received the signal
2935 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2937 * Emitted when a redirected window belonging to @widget gets drawn into.
2938 * The region/area members of the event shows what area of the redirected
2939 * drawable was drawn into.
2941 * Returns: %TRUE to stop other handlers from being invoked for the event.
2942 * %FALSE to propagate the event further.
2946 widget_signals[DAMAGE_EVENT] =
2947 g_signal_new (I_("damage-event"),
2948 G_TYPE_FROM_CLASS (klass),
2950 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2951 _gtk_boolean_handled_accumulator, NULL,
2952 _gtk_marshal_BOOLEAN__BOXED,
2954 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2955 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2956 _gtk_marshal_BOOLEAN__BOXEDv);
2959 * GtkWidget::grab-broken-event:
2960 * @widget: the object which received the signal
2961 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2963 * Emitted when a pointer or keyboard grab on a window belonging
2964 * to @widget gets broken.
2966 * On X11, this happens when the grab window becomes unviewable
2967 * (i.e. it or one of its ancestors is unmapped), or if the same
2968 * application grabs the pointer or keyboard again.
2970 * Returns: %TRUE to stop other handlers from being invoked for
2971 * the event. %FALSE to propagate the event further.
2975 widget_signals[GRAB_BROKEN_EVENT] =
2976 g_signal_new (I_("grab-broken-event"),
2977 G_TYPE_FROM_CLASS (klass),
2979 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2980 _gtk_boolean_handled_accumulator, NULL,
2981 _gtk_marshal_BOOLEAN__BOXED,
2983 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2984 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2985 _gtk_marshal_BOOLEAN__BOXEDv);
2988 * GtkWidget::query-tooltip:
2989 * @widget: the object which received the signal
2990 * @x: the x coordinate of the cursor position where the request has
2991 * been emitted, relative to @widget's left side
2992 * @y: the y coordinate of the cursor position where the request has
2993 * been emitted, relative to @widget's top
2994 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2995 * @tooltip: a #GtkTooltip
2997 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2998 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2999 * focus in keyboard mode.
3001 * Using the given coordinates, the signal handler should determine
3002 * whether a tooltip should be shown for @widget. If this is the case
3003 * %TRUE should be returned, %FALSE otherwise. Note that if
3004 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3005 * should not be used.
3007 * The signal handler is free to manipulate @tooltip with the therefore
3008 * destined function calls.
3010 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3014 widget_signals[QUERY_TOOLTIP] =
3015 g_signal_new (I_("query-tooltip"),
3016 G_TYPE_FROM_CLASS (klass),
3018 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3019 _gtk_boolean_handled_accumulator, NULL,
3020 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3028 * GtkWidget::popup-menu:
3029 * @widget: the object which received the signal
3031 * This signal gets emitted whenever a widget should pop up a context
3032 * menu. This usually happens through the standard key binding mechanism;
3033 * by pressing a certain key while a widget is focused, the user can cause
3034 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3035 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3036 * for an example of how to use this signal.
3038 * Returns: %TRUE if a menu was activated
3040 widget_signals[POPUP_MENU] =
3041 g_signal_new (I_("popup-menu"),
3042 G_TYPE_FROM_CLASS (klass),
3043 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3044 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3045 _gtk_boolean_handled_accumulator, NULL,
3046 _gtk_marshal_BOOLEAN__VOID,
3050 * GtkWidget::show-help:
3051 * @widget: the object which received the signal.
3054 * Returns: %TRUE to stop other handlers from being invoked for the event.
3055 * %FALSE to propagate the event further.
3057 widget_signals[SHOW_HELP] =
3058 g_signal_new (I_("show-help"),
3059 G_TYPE_FROM_CLASS (klass),
3060 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3061 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3062 _gtk_boolean_handled_accumulator, NULL,
3063 _gtk_marshal_BOOLEAN__ENUM,
3065 GTK_TYPE_WIDGET_HELP_TYPE);
3068 * GtkWidget::accel-closures-changed:
3069 * @widget: the object which received the signal.
3071 widget_signals[ACCEL_CLOSURES_CHANGED] =
3072 g_signal_new (I_("accel-closures-changed"),
3073 G_TYPE_FROM_CLASS (klass),
3077 _gtk_marshal_VOID__VOID,
3081 * GtkWidget::screen-changed:
3082 * @widget: the object on which the signal is emitted
3083 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3084 * widget was not associated with a screen before
3086 * The ::screen-changed signal gets emitted when the
3087 * screen of a widget has changed.
3089 widget_signals[SCREEN_CHANGED] =
3090 g_signal_new (I_("screen-changed"),
3091 G_TYPE_FROM_CLASS (klass),
3093 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3095 _gtk_marshal_VOID__OBJECT,
3100 * GtkWidget::can-activate-accel:
3101 * @widget: the object which received the signal
3102 * @signal_id: the ID of a signal installed on @widget
3104 * Determines whether an accelerator that activates the signal
3105 * identified by @signal_id can currently be activated.
3106 * This signal is present to allow applications and derived
3107 * widgets to override the default #GtkWidget handling
3108 * for determining whether an accelerator can be activated.
3110 * Returns: %TRUE if the signal can be activated.
3112 widget_signals[CAN_ACTIVATE_ACCEL] =
3113 g_signal_new (I_("can-activate-accel"),
3114 G_TYPE_FROM_CLASS (klass),
3116 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3117 _gtk_boolean_handled_accumulator, NULL,
3118 _gtk_marshal_BOOLEAN__UINT,
3119 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3121 binding_set = gtk_binding_set_by_class (klass);
3122 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3124 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3127 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3129 GTK_TYPE_WIDGET_HELP_TYPE,
3130 GTK_WIDGET_HELP_TOOLTIP);
3131 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3133 GTK_TYPE_WIDGET_HELP_TYPE,
3134 GTK_WIDGET_HELP_TOOLTIP);
3135 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3137 GTK_TYPE_WIDGET_HELP_TYPE,
3138 GTK_WIDGET_HELP_WHATS_THIS);
3139 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3141 GTK_TYPE_WIDGET_HELP_TYPE,
3142 GTK_WIDGET_HELP_WHATS_THIS);
3144 gtk_widget_class_install_style_property (klass,
3145 g_param_spec_boolean ("interior-focus",
3146 P_("Interior Focus"),
3147 P_("Whether to draw the focus indicator inside widgets"),
3149 GTK_PARAM_READABLE));
3151 gtk_widget_class_install_style_property (klass,
3152 g_param_spec_int ("focus-line-width",
3153 P_("Focus linewidth"),
3154 P_("Width, in pixels, of the focus indicator line"),
3156 GTK_PARAM_READABLE));
3158 gtk_widget_class_install_style_property (klass,
3159 g_param_spec_string ("focus-line-pattern",
3160 P_("Focus line dash pattern"),
3161 P_("Dash pattern used to draw the focus indicator"),
3163 GTK_PARAM_READABLE));
3164 gtk_widget_class_install_style_property (klass,
3165 g_param_spec_int ("focus-padding",
3166 P_("Focus padding"),
3167 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3169 GTK_PARAM_READABLE));
3170 gtk_widget_class_install_style_property (klass,
3171 g_param_spec_boxed ("cursor-color",
3173 P_("Color with which to draw insertion cursor"),
3175 GTK_PARAM_READABLE));
3176 gtk_widget_class_install_style_property (klass,
3177 g_param_spec_boxed ("secondary-cursor-color",
3178 P_("Secondary cursor color"),
3179 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3181 GTK_PARAM_READABLE));
3182 gtk_widget_class_install_style_property (klass,
3183 g_param_spec_float ("cursor-aspect-ratio",
3184 P_("Cursor line aspect ratio"),
3185 P_("Aspect ratio with which to draw insertion cursor"),
3187 GTK_PARAM_READABLE));
3189 gtk_widget_class_install_style_property (klass,
3190 g_param_spec_boolean ("window-dragging",
3191 P_("Window dragging"),
3192 P_("Whether windows can be dragged by clicking on empty areas"),
3194 GTK_PARAM_READABLE));
3197 * GtkWidget:link-color:
3199 * The "link-color" style property defines the color of unvisited links.
3203 gtk_widget_class_install_style_property (klass,
3204 g_param_spec_boxed ("link-color",
3205 P_("Unvisited Link Color"),
3206 P_("Color of unvisited links"),
3208 GTK_PARAM_READABLE));
3211 * GtkWidget:visited-link-color:
3213 * The "visited-link-color" style property defines the color of visited links.
3217 gtk_widget_class_install_style_property (klass,
3218 g_param_spec_boxed ("visited-link-color",
3219 P_("Visited Link Color"),
3220 P_("Color of visited links"),
3222 GTK_PARAM_READABLE));
3225 * GtkWidget:wide-separators:
3227 * The "wide-separators" style property defines whether separators have
3228 * configurable width and should be drawn using a box instead of a line.
3232 gtk_widget_class_install_style_property (klass,
3233 g_param_spec_boolean ("wide-separators",
3234 P_("Wide Separators"),
3235 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3237 GTK_PARAM_READABLE));
3240 * GtkWidget:separator-width:
3242 * The "separator-width" style property defines the width of separators.
3243 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3247 gtk_widget_class_install_style_property (klass,
3248 g_param_spec_int ("separator-width",
3249 P_("Separator Width"),
3250 P_("The width of separators if wide-separators is TRUE"),
3252 GTK_PARAM_READABLE));
3255 * GtkWidget:separator-height:
3257 * The "separator-height" style property defines the height of separators.
3258 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3262 gtk_widget_class_install_style_property (klass,
3263 g_param_spec_int ("separator-height",
3264 P_("Separator Height"),
3265 P_("The height of separators if \"wide-separators\" is TRUE"),
3267 GTK_PARAM_READABLE));
3270 * GtkWidget:scroll-arrow-hlength:
3272 * The "scroll-arrow-hlength" style property defines the length of
3273 * horizontal scroll arrows.
3277 gtk_widget_class_install_style_property (klass,
3278 g_param_spec_int ("scroll-arrow-hlength",
3279 P_("Horizontal Scroll Arrow Length"),
3280 P_("The length of horizontal scroll arrows"),
3282 GTK_PARAM_READABLE));
3285 * GtkWidget:scroll-arrow-vlength:
3287 * The "scroll-arrow-vlength" style property defines the length of
3288 * vertical scroll arrows.
3292 gtk_widget_class_install_style_property (klass,
3293 g_param_spec_int ("scroll-arrow-vlength",
3294 P_("Vertical Scroll Arrow Length"),
3295 P_("The length of vertical scroll arrows"),
3297 GTK_PARAM_READABLE));
3299 gtk_widget_class_install_style_property (klass,
3300 g_param_spec_int ("text-handle-width",
3301 P_("Width of text selection handles"),
3302 P_("Width of text selection handles"),
3304 GTK_PARAM_READABLE));
3305 gtk_widget_class_install_style_property (klass,
3306 g_param_spec_int ("text-handle-height",
3307 P_("Height of text selection handles"),
3308 P_("Height of text selection handles"),
3310 GTK_PARAM_READABLE));
3312 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3314 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3318 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3322 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3323 for (node = list; node; node = node->next)
3325 GParamSpec *pspec = node->data;
3327 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3328 g_param_spec_unref (pspec);
3334 gtk_widget_set_property (GObject *object,
3336 const GValue *value,
3339 GtkWidget *widget = GTK_WIDGET (object);
3344 gchar *tooltip_markup;
3345 const gchar *tooltip_text;
3346 GtkWindow *tooltip_window;
3349 gtk_widget_set_name (widget, g_value_get_string (value));
3352 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3354 case PROP_WIDTH_REQUEST:
3355 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3357 case PROP_HEIGHT_REQUEST:
3358 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3361 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3363 case PROP_SENSITIVE:
3364 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3366 case PROP_APP_PAINTABLE:
3367 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3369 case PROP_CAN_FOCUS:
3370 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3372 case PROP_HAS_FOCUS:
3373 if (g_value_get_boolean (value))
3374 gtk_widget_grab_focus (widget);
3377 if (g_value_get_boolean (value))
3378 gtk_widget_grab_focus (widget);
3380 case PROP_CAN_DEFAULT:
3381 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3383 case PROP_HAS_DEFAULT:
3384 if (g_value_get_boolean (value))
3385 gtk_widget_grab_default (widget);
3387 case PROP_RECEIVES_DEFAULT:
3388 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3391 gtk_widget_set_style (widget, g_value_get_object (value));
3394 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3395 gtk_widget_set_events (widget, g_value_get_flags (value));
3397 case PROP_NO_SHOW_ALL:
3398 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3400 case PROP_HAS_TOOLTIP:
3401 gtk_widget_real_set_has_tooltip (widget,
3402 g_value_get_boolean (value), FALSE);
3404 case PROP_TOOLTIP_MARKUP:
3405 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3406 tooltip_markup = g_value_dup_string (value);
3408 /* Treat an empty string as a NULL string,
3409 * because an empty string would be useless for a tooltip:
3411 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3413 g_free (tooltip_markup);
3414 tooltip_markup = NULL;
3417 g_object_set_qdata_full (object, quark_tooltip_markup,
3418 tooltip_markup, g_free);
3420 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3421 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3422 if (gtk_widget_get_visible (widget))
3423 gtk_widget_queue_tooltip_query (widget);
3425 case PROP_TOOLTIP_TEXT:
3426 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3428 tooltip_text = g_value_get_string (value);
3430 /* Treat an empty string as a NULL string,
3431 * because an empty string would be useless for a tooltip:
3433 if (tooltip_text && (strlen (tooltip_text) == 0))
3434 tooltip_text = NULL;
3436 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3438 g_object_set_qdata_full (object, quark_tooltip_markup,
3439 tooltip_markup, g_free);
3441 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3442 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3443 if (gtk_widget_get_visible (widget))
3444 gtk_widget_queue_tooltip_query (widget);
3446 case PROP_DOUBLE_BUFFERED:
3447 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3450 gtk_widget_set_halign (widget, g_value_get_enum (value));
3453 gtk_widget_set_valign (widget, g_value_get_enum (value));
3455 case PROP_MARGIN_LEFT:
3456 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3458 case PROP_MARGIN_RIGHT:
3459 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3461 case PROP_MARGIN_TOP:
3462 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3464 case PROP_MARGIN_BOTTOM:
3465 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3468 g_object_freeze_notify (G_OBJECT (widget));
3469 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3470 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3471 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3472 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3473 g_object_thaw_notify (G_OBJECT (widget));
3476 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3478 case PROP_HEXPAND_SET:
3479 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3482 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3484 case PROP_VEXPAND_SET:
3485 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3488 g_object_freeze_notify (G_OBJECT (widget));
3489 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3490 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3491 g_object_thaw_notify (G_OBJECT (widget));
3494 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3500 gtk_widget_get_property (GObject *object,
3505 GtkWidget *widget = GTK_WIDGET (object);
3506 GtkWidgetPrivate *priv = widget->priv;
3514 g_value_set_string (value, priv->name);
3516 g_value_set_static_string (value, "");
3519 g_value_set_object (value, priv->parent);
3521 case PROP_WIDTH_REQUEST:
3524 gtk_widget_get_size_request (widget, &w, NULL);
3525 g_value_set_int (value, w);
3528 case PROP_HEIGHT_REQUEST:
3531 gtk_widget_get_size_request (widget, NULL, &h);
3532 g_value_set_int (value, h);
3536 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3538 case PROP_SENSITIVE:
3539 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3541 case PROP_APP_PAINTABLE:
3542 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3544 case PROP_CAN_FOCUS:
3545 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3547 case PROP_HAS_FOCUS:
3548 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3551 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3553 case PROP_CAN_DEFAULT:
3554 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3556 case PROP_HAS_DEFAULT:
3557 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3559 case PROP_RECEIVES_DEFAULT:
3560 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3562 case PROP_COMPOSITE_CHILD:
3563 g_value_set_boolean (value, widget->priv->composite_child);
3566 g_value_set_object (value, gtk_widget_get_style (widget));
3569 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3570 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3572 case PROP_NO_SHOW_ALL:
3573 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3575 case PROP_HAS_TOOLTIP:
3576 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3578 case PROP_TOOLTIP_TEXT:
3580 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3583 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3584 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3586 g_value_take_string (value, text);
3589 case PROP_TOOLTIP_MARKUP:
3590 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3593 g_value_set_object (value, gtk_widget_get_window (widget));
3595 case PROP_DOUBLE_BUFFERED:
3596 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3599 g_value_set_enum (value, gtk_widget_get_halign (widget));
3602 g_value_set_enum (value, gtk_widget_get_valign (widget));
3604 case PROP_MARGIN_LEFT:
3605 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3607 case PROP_MARGIN_RIGHT:
3608 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3610 case PROP_MARGIN_TOP:
3611 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3613 case PROP_MARGIN_BOTTOM:
3614 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3618 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3619 if (aux_info == NULL)
3621 g_value_set_int (value, 0);
3625 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3626 aux_info->margin.right),
3627 MAX (aux_info->margin.top,
3628 aux_info->margin.bottom)));
3633 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3635 case PROP_HEXPAND_SET:
3636 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3639 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3641 case PROP_VEXPAND_SET:
3642 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3645 g_value_set_boolean (value,
3646 gtk_widget_get_hexpand (widget) &&
3647 gtk_widget_get_vexpand (widget));
3650 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3656 gtk_widget_init (GtkWidget *widget)
3658 GtkWidgetPrivate *priv;
3660 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3663 priv = widget->priv;
3665 priv->child_visible = TRUE;
3667 priv->allocation.x = -1;
3668 priv->allocation.y = -1;
3669 priv->allocation.width = 1;
3670 priv->allocation.height = 1;
3671 priv->window = NULL;
3672 priv->parent = NULL;
3674 priv->sensitive = TRUE;
3675 priv->composite_child = composite_child_stack != 0;
3676 priv->double_buffered = TRUE;
3677 priv->redraw_on_alloc = TRUE;
3678 priv->width_request_needed = TRUE;
3679 priv->height_request_needed = TRUE;
3680 priv->alloc_needed = TRUE;
3682 /* this will be set to TRUE if the widget gets a child or if the
3683 * expand flag is set on the widget, but until one of those happen
3684 * we know the expand is already properly FALSE.
3686 * We really want to default FALSE here to avoid computing expand
3687 * all over the place while initially building a widget tree.
3689 priv->need_compute_expand = FALSE;
3691 priv->style = gtk_widget_get_default_style ();
3692 g_object_ref (priv->style);
3697 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3699 GParamSpec **pspecs)
3701 GtkWidgetPrivate *priv = widget->priv;
3702 GtkWidget *container = priv->parent;
3705 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3706 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3710 * gtk_widget_freeze_child_notify:
3711 * @widget: a #GtkWidget
3713 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3714 * signals are queued until gtk_widget_thaw_child_notify() is called
3717 * This is the analogue of g_object_freeze_notify() for child properties.
3720 gtk_widget_freeze_child_notify (GtkWidget *widget)
3722 g_return_if_fail (GTK_IS_WIDGET (widget));
3724 if (!G_OBJECT (widget)->ref_count)
3727 g_object_ref (widget);
3728 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3729 g_object_unref (widget);
3733 * gtk_widget_child_notify:
3734 * @widget: a #GtkWidget
3735 * @child_property: the name of a child property installed on the
3736 * class of @widget<!-- -->'s parent
3738 * Emits a #GtkWidget::child-notify signal for the
3739 * <link linkend="child-properties">child property</link> @child_property
3742 * This is the analogue of g_object_notify() for child properties.
3744 * Also see gtk_container_child_notify().
3747 gtk_widget_child_notify (GtkWidget *widget,
3748 const gchar *child_property)
3750 if (widget->priv->parent == NULL)
3753 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3757 * gtk_widget_thaw_child_notify:
3758 * @widget: a #GtkWidget
3760 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3761 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3765 gtk_widget_thaw_child_notify (GtkWidget *widget)
3767 GObjectNotifyQueue *nqueue;
3769 g_return_if_fail (GTK_IS_WIDGET (widget));
3771 if (!G_OBJECT (widget)->ref_count)
3774 g_object_ref (widget);
3775 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3776 if (!nqueue || !nqueue->freeze_count)
3777 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3778 G_OBJECT_TYPE_NAME (widget), widget);
3780 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3781 g_object_unref (widget);
3787 * @type: type ID of the widget to create
3788 * @first_property_name: name of first property to set
3789 * @...: value of first property, followed by more properties,
3792 * This is a convenience function for creating a widget and setting
3793 * its properties in one go. For example you might write:
3794 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3795 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3796 * g_object_new(), but returns a widget so you don't have to
3797 * cast the object yourself.
3799 * Return value: a new #GtkWidget of type @widget_type
3802 gtk_widget_new (GType type,
3803 const gchar *first_property_name,
3809 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3811 va_start (var_args, first_property_name);
3812 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3819 gtk_widget_queue_draw_child (GtkWidget *widget)
3821 GtkWidgetPrivate *priv = widget->priv;
3824 parent = priv->parent;
3825 if (parent && gtk_widget_is_drawable (parent))
3826 gtk_widget_queue_draw_area (parent,
3829 priv->allocation.width,
3830 priv->allocation.height);
3834 * gtk_widget_unparent:
3835 * @widget: a #GtkWidget
3837 * This function is only for use in widget implementations.
3838 * Should be called by implementations of the remove method
3839 * on #GtkContainer, to dissociate a child from the container.
3842 gtk_widget_unparent (GtkWidget *widget)
3844 GtkWidgetPrivate *priv;
3845 GObjectNotifyQueue *nqueue;
3846 GtkWidget *toplevel;
3847 GtkWidget *old_parent;
3849 g_return_if_fail (GTK_IS_WIDGET (widget));
3851 priv = widget->priv;
3853 if (priv->parent == NULL)
3856 /* keep this function in sync with gtk_menu_detach() */
3858 gtk_widget_push_verify_invariants (widget);
3860 g_object_freeze_notify (G_OBJECT (widget));
3861 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3863 toplevel = gtk_widget_get_toplevel (widget);
3864 if (gtk_widget_is_toplevel (toplevel))
3865 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3867 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3868 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3870 gtk_widget_queue_draw_child (widget);
3872 /* Reset the width and height here, to force reallocation if we
3873 * get added back to a new parent. This won't work if our new
3874 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3875 * (would 0x0 be OK here?)
3877 priv->allocation.width = 1;
3878 priv->allocation.height = 1;
3880 if (gtk_widget_get_realized (widget))
3882 if (priv->in_reparent)
3883 gtk_widget_unmap (widget);
3885 gtk_widget_unrealize (widget);
3888 /* If we are unanchoring the child, we save around the toplevel
3889 * to emit hierarchy changed
3891 if (priv->parent->priv->anchored)
3892 g_object_ref (toplevel);
3896 /* Removing a widget from a container restores the child visible
3897 * flag to the default state, so it doesn't affect the child
3898 * in the next parent.
3900 priv->child_visible = TRUE;
3902 old_parent = priv->parent;
3903 priv->parent = NULL;
3905 /* parent may no longer expand if the removed
3906 * child was expand=TRUE and could therefore
3909 if (gtk_widget_get_visible (widget) &&
3910 (priv->need_compute_expand ||
3911 priv->computed_hexpand ||
3912 priv->computed_vexpand))
3914 gtk_widget_queue_compute_expand (old_parent);
3917 /* Unset BACKDROP since we are no longer inside a toplevel window */
3918 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3920 gtk_style_context_set_parent (priv->context, NULL);
3922 _gtk_widget_update_parent_muxer (widget);
3924 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3927 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3928 g_object_unref (toplevel);
3931 /* Now that the parent pointer is nullified and the hierarchy-changed
3932 * already passed, go ahead and unset the parent window, if we are unparenting
3933 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3934 * will fire again for the new subhierarchy.
3936 gtk_widget_set_parent_window (widget, NULL);
3938 g_object_notify (G_OBJECT (widget), "parent");
3939 g_object_thaw_notify (G_OBJECT (widget));
3941 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3942 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3944 gtk_widget_pop_verify_invariants (widget);
3945 g_object_unref (widget);
3949 * gtk_widget_destroy:
3950 * @widget: a #GtkWidget
3952 * Destroys a widget.
3955 * destroyed, it will break any references it holds to other objects.
3956 * If the widget is inside a container, the widget will be removed
3957 * from the container. If the widget is a toplevel (derived from
3958 * #GtkWindow), it will be removed from the list of toplevels, and the
3959 * reference GTK+ holds to it will be removed. Removing a
3960 * widget from its container or the list of toplevels results in the
3961 * widget being finalized, unless you've added additional references
3962 * to the widget with g_object_ref().
3964 * In most cases, only toplevel widgets (windows) require explicit
3965 * destruction, because when you destroy a toplevel its children will
3966 * be destroyed as well.
3969 gtk_widget_destroy (GtkWidget *widget)
3971 g_return_if_fail (GTK_IS_WIDGET (widget));
3973 if (!widget->priv->in_destruction)
3974 g_object_run_dispose (G_OBJECT (widget));
3978 * gtk_widget_destroyed:
3979 * @widget: a #GtkWidget
3980 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3982 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3983 * %NULL. It's intended to be used as a callback connected to the
3984 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3985 * as a signal handler, and pass the address of your widget variable
3986 * as user data. Then when the widget is destroyed, the variable will
3987 * be set to %NULL. Useful for example to avoid multiple copies
3988 * of the same dialog.
3991 gtk_widget_destroyed (GtkWidget *widget,
3992 GtkWidget **widget_pointer)
3994 /* Don't make any assumptions about the
3996 * Even check widget_pointer.
3999 *widget_pointer = NULL;
4004 * @widget: a #GtkWidget
4006 * Flags a widget to be displayed. Any widget that isn't shown will
4007 * not appear on the screen. If you want to show all the widgets in a
4008 * container, it's easier to call gtk_widget_show_all() on the
4009 * container, instead of individually showing the widgets.
4011 * Remember that you have to show the containers containing a widget,
4012 * in addition to the widget itself, before it will appear onscreen.
4014 * When a toplevel container is shown, it is immediately realized and
4015 * mapped; other shown widgets are realized and mapped when their
4016 * toplevel container is realized and mapped.
4019 gtk_widget_show (GtkWidget *widget)
4021 g_return_if_fail (GTK_IS_WIDGET (widget));
4023 if (!gtk_widget_get_visible (widget))
4025 g_object_ref (widget);
4026 gtk_widget_push_verify_invariants (widget);
4028 if (!gtk_widget_is_toplevel (widget))
4029 gtk_widget_queue_resize (widget);
4031 /* see comment in set_parent() for why this should and can be
4034 if (widget->priv->need_compute_expand ||
4035 widget->priv->computed_hexpand ||
4036 widget->priv->computed_vexpand)
4038 if (widget->priv->parent != NULL)
4039 gtk_widget_queue_compute_expand (widget->priv->parent);
4042 g_signal_emit (widget, widget_signals[SHOW], 0);
4043 g_object_notify (G_OBJECT (widget), "visible");
4045 gtk_widget_pop_verify_invariants (widget);
4046 g_object_unref (widget);
4051 gtk_widget_real_show (GtkWidget *widget)
4053 GtkWidgetPrivate *priv = widget->priv;
4055 if (!gtk_widget_get_visible (widget))
4057 priv->visible = TRUE;
4060 gtk_widget_get_mapped (priv->parent) &&
4061 gtk_widget_get_child_visible (widget) &&
4062 !gtk_widget_get_mapped (widget))
4063 gtk_widget_map (widget);
4068 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4071 g_signal_handlers_disconnect_by_func (widget,
4072 gtk_widget_show_map_callback,
4077 * gtk_widget_show_now:
4078 * @widget: a #GtkWidget
4080 * Shows a widget. If the widget is an unmapped toplevel widget
4081 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4082 * loop and wait for the window to actually be mapped. Be careful;
4083 * because the main loop is running, anything can happen during
4087 gtk_widget_show_now (GtkWidget *widget)
4091 g_return_if_fail (GTK_IS_WIDGET (widget));
4093 /* make sure we will get event */
4094 if (!gtk_widget_get_mapped (widget) &&
4095 gtk_widget_is_toplevel (widget))
4097 gtk_widget_show (widget);
4099 g_signal_connect (widget, "map-event",
4100 G_CALLBACK (gtk_widget_show_map_callback),
4104 gtk_main_iteration ();
4107 gtk_widget_show (widget);
4112 * @widget: a #GtkWidget
4114 * Reverses the effects of gtk_widget_show(), causing the widget to be
4115 * hidden (invisible to the user).
4118 gtk_widget_hide (GtkWidget *widget)
4120 g_return_if_fail (GTK_IS_WIDGET (widget));
4122 if (gtk_widget_get_visible (widget))
4124 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4126 g_object_ref (widget);
4127 gtk_widget_push_verify_invariants (widget);
4129 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4130 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4132 /* a parent may now be expand=FALSE since we're hidden. */
4133 if (widget->priv->need_compute_expand ||
4134 widget->priv->computed_hexpand ||
4135 widget->priv->computed_vexpand)
4137 gtk_widget_queue_compute_expand (widget);
4140 g_signal_emit (widget, widget_signals[HIDE], 0);
4141 if (!gtk_widget_is_toplevel (widget))
4142 gtk_widget_queue_resize (widget);
4143 g_object_notify (G_OBJECT (widget), "visible");
4145 gtk_widget_pop_verify_invariants (widget);
4146 g_object_unref (widget);
4151 gtk_widget_real_hide (GtkWidget *widget)
4153 if (gtk_widget_get_visible (widget))
4155 widget->priv->visible = FALSE;
4157 if (gtk_widget_get_mapped (widget))
4158 gtk_widget_unmap (widget);
4163 * gtk_widget_hide_on_delete:
4164 * @widget: a #GtkWidget
4166 * Utility function; intended to be connected to the #GtkWidget::delete-event
4167 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4168 * argument, then returns %TRUE. If connected to ::delete-event, the
4169 * result is that clicking the close button for a window (on the
4170 * window frame, top right corner usually) will hide but not destroy
4171 * the window. By default, GTK+ destroys windows when ::delete-event
4174 * Return value: %TRUE
4177 gtk_widget_hide_on_delete (GtkWidget *widget)
4179 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4181 gtk_widget_hide (widget);
4187 * gtk_widget_show_all:
4188 * @widget: a #GtkWidget
4190 * Recursively shows a widget, and any child widgets (if the widget is
4194 gtk_widget_show_all (GtkWidget *widget)
4196 GtkWidgetClass *class;
4198 g_return_if_fail (GTK_IS_WIDGET (widget));
4200 if (gtk_widget_get_no_show_all (widget))
4203 class = GTK_WIDGET_GET_CLASS (widget);
4205 if (class->show_all)
4206 class->show_all (widget);
4211 * @widget: a #GtkWidget
4213 * This function is only for use in widget implementations. Causes
4214 * a widget to be mapped if it isn't already.
4217 gtk_widget_map (GtkWidget *widget)
4219 GtkWidgetPrivate *priv;
4221 g_return_if_fail (GTK_IS_WIDGET (widget));
4222 g_return_if_fail (gtk_widget_get_visible (widget));
4223 g_return_if_fail (gtk_widget_get_child_visible (widget));
4225 priv = widget->priv;
4227 if (!gtk_widget_get_mapped (widget))
4229 gtk_widget_push_verify_invariants (widget);
4231 if (!gtk_widget_get_realized (widget))
4232 gtk_widget_realize (widget);
4234 g_signal_emit (widget, widget_signals[MAP], 0);
4236 if (!gtk_widget_get_has_window (widget))
4237 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4239 if (widget->priv->context)
4240 _gtk_style_context_update_animating (widget->priv->context);
4242 gtk_widget_pop_verify_invariants (widget);
4248 * @widget: a #GtkWidget
4250 * This function is only for use in widget implementations. Causes
4251 * a widget to be unmapped if it's currently mapped.
4254 gtk_widget_unmap (GtkWidget *widget)
4256 GtkWidgetPrivate *priv;
4258 g_return_if_fail (GTK_IS_WIDGET (widget));
4260 priv = widget->priv;
4262 if (gtk_widget_get_mapped (widget))
4264 gtk_widget_push_verify_invariants (widget);
4266 if (!gtk_widget_get_has_window (widget))
4267 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4268 _gtk_tooltip_hide (widget);
4270 if (widget->priv->context)
4271 _gtk_style_context_update_animating (widget->priv->context);
4273 g_signal_emit (widget, widget_signals[UNMAP], 0);
4275 gtk_widget_pop_verify_invariants (widget);
4277 /* Unset pointer/window info */
4278 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4283 _gtk_widget_enable_device_events (GtkWidget *widget)
4285 GHashTable *device_events;
4286 GHashTableIter iter;
4287 gpointer key, value;
4289 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4294 g_hash_table_iter_init (&iter, device_events);
4296 while (g_hash_table_iter_next (&iter, &key, &value))
4299 GdkEventMask event_mask;
4302 event_mask = GPOINTER_TO_UINT (value);
4303 gtk_widget_add_events_internal (widget, device, event_mask);
4308 get_widget_windows (GtkWidget *widget)
4310 GList *window_list, *last, *l, *children, *ret;
4312 if (gtk_widget_get_has_window (widget))
4313 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4315 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4317 last = g_list_last (window_list);
4320 for (l = window_list; l; l = l->next)
4322 GtkWidget *window_widget = NULL;
4324 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4326 if (widget != window_widget)
4329 ret = g_list_prepend (ret, l->data);
4330 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4334 last = g_list_concat (last, children);
4335 last = g_list_last (last);
4339 g_list_free (window_list);
4345 device_enable_foreach (GtkWidget *widget,
4348 GdkDevice *device = user_data;
4349 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4353 device_disable_foreach (GtkWidget *widget,
4356 GdkDevice *device = user_data;
4357 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4361 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4366 GList *window_list, *l;
4368 window_list = get_widget_windows (widget);
4370 for (l = window_list; l; l = l->next)
4372 GdkEventMask events = 0;
4378 events = gdk_window_get_events (window);
4380 gdk_window_set_device_events (window, device, events);
4383 if (recurse && GTK_IS_CONTAINER (widget))
4386 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4388 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4391 g_list_free (window_list);
4395 gtk_widget_update_devices_mask (GtkWidget *widget,
4398 GList *enabled_devices, *l;
4400 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4402 for (l = enabled_devices; l; l = l->next)
4403 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4407 * gtk_widget_realize:
4408 * @widget: a #GtkWidget
4410 * Creates the GDK (windowing system) resources associated with a
4411 * widget. For example, @widget->window will be created when a widget
4412 * is realized. Normally realization happens implicitly; if you show
4413 * a widget and all its parent containers, then the widget will be
4414 * realized and mapped automatically.
4416 * Realizing a widget requires all
4417 * the widget's parent widgets to be realized; calling
4418 * gtk_widget_realize() realizes the widget's parents in addition to
4419 * @widget itself. If a widget is not yet inside a toplevel window
4420 * when you realize it, bad things will happen.
4422 * This function is primarily used in widget implementations, and
4423 * isn't very useful otherwise. Many times when you think you might
4424 * need it, a better approach is to connect to a signal that will be
4425 * called after the widget is realized automatically, such as
4426 * #GtkWidget::draw. Or simply g_signal_connect () to the
4427 * #GtkWidget::realize signal.
4430 gtk_widget_realize (GtkWidget *widget)
4432 GtkWidgetPrivate *priv;
4433 cairo_region_t *region;
4435 g_return_if_fail (GTK_IS_WIDGET (widget));
4436 g_return_if_fail (widget->priv->anchored ||
4437 GTK_IS_INVISIBLE (widget));
4439 priv = widget->priv;
4441 if (!gtk_widget_get_realized (widget))
4443 gtk_widget_push_verify_invariants (widget);
4446 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4447 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4450 if (priv->parent == NULL &&
4451 !gtk_widget_is_toplevel (widget))
4452 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4453 "inside a toplevel window is not going to work very well. "
4454 "Widgets must be inside a toplevel container before realizing them.");
4456 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4457 gtk_widget_realize (priv->parent);
4459 gtk_widget_ensure_style (widget);
4461 if (priv->style_update_pending)
4462 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4464 g_signal_emit (widget, widget_signals[REALIZE], 0);
4466 gtk_widget_real_set_has_tooltip (widget,
4467 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4470 if (priv->has_shape_mask)
4472 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4473 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4476 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4478 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4480 if (priv->multidevice)
4481 gdk_window_set_support_multidevice (priv->window, TRUE);
4483 _gtk_widget_enable_device_events (widget);
4484 gtk_widget_update_devices_mask (widget, TRUE);
4486 gtk_widget_pop_verify_invariants (widget);
4491 * gtk_widget_unrealize:
4492 * @widget: a #GtkWidget
4494 * This function is only useful in widget implementations.
4495 * Causes a widget to be unrealized (frees all GDK resources
4496 * associated with the widget, such as @widget->window).
4499 gtk_widget_unrealize (GtkWidget *widget)
4501 g_return_if_fail (GTK_IS_WIDGET (widget));
4503 gtk_widget_push_verify_invariants (widget);
4505 if (widget->priv->has_shape_mask)
4506 gtk_widget_shape_combine_region (widget, NULL);
4508 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4509 gtk_widget_input_shape_combine_region (widget, NULL);
4511 if (gtk_widget_get_realized (widget))
4513 g_object_ref (widget);
4515 if (widget->priv->mapped)
4516 gtk_widget_unmap (widget);
4518 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4519 g_assert (!widget->priv->mapped);
4520 gtk_widget_set_realized (widget, FALSE);
4522 g_object_unref (widget);
4525 gtk_widget_pop_verify_invariants (widget);
4528 /*****************************************
4530 *****************************************/
4533 * gtk_widget_queue_draw_region:
4534 * @widget: a #GtkWidget
4535 * @region: region to draw
4537 * Invalidates the rectangular area of @widget defined by @region by
4538 * calling gdk_window_invalidate_region() on the widget's window and
4539 * all its child windows. Once the main loop becomes idle (after the
4540 * current batch of events has been processed, roughly), the window
4541 * will receive expose events for the union of all regions that have
4544 * Normally you would only use this function in widget
4545 * implementations. You might also use it to schedule a redraw of a
4546 * #GtkDrawingArea or some portion thereof.
4551 gtk_widget_queue_draw_region (GtkWidget *widget,
4552 const cairo_region_t *region)
4554 GtkWidgetPrivate *priv;
4557 g_return_if_fail (GTK_IS_WIDGET (widget));
4559 priv = widget->priv;
4561 if (!gtk_widget_get_realized (widget))
4564 /* Just return if the widget or one of its ancestors isn't mapped */
4565 for (w = widget; w != NULL; w = w->priv->parent)
4566 if (!gtk_widget_get_mapped (w))
4569 gdk_window_invalidate_region (priv->window, region, TRUE);
4573 * gtk_widget_queue_draw_area:
4574 * @widget: a #GtkWidget
4575 * @x: x coordinate of upper-left corner of rectangle to redraw
4576 * @y: y coordinate of upper-left corner of rectangle to redraw
4577 * @width: width of region to draw
4578 * @height: height of region to draw
4580 * Convenience function that calls gtk_widget_queue_draw_region() on
4581 * the region created from the given coordinates.
4583 * The region here is specified in widget coordinates.
4584 * Widget coordinates are a bit odd; for historical reasons, they are
4585 * defined as @widget->window coordinates for widgets that are not
4586 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4587 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4590 gtk_widget_queue_draw_area (GtkWidget *widget,
4597 cairo_region_t *region;
4599 g_return_if_fail (GTK_IS_WIDGET (widget));
4604 rect.height = height;
4606 region = cairo_region_create_rectangle (&rect);
4607 gtk_widget_queue_draw_region (widget, region);
4608 cairo_region_destroy (region);
4612 * gtk_widget_queue_draw:
4613 * @widget: a #GtkWidget
4615 * Equivalent to calling gtk_widget_queue_draw_area() for the
4616 * entire area of a widget.
4619 gtk_widget_queue_draw (GtkWidget *widget)
4623 g_return_if_fail (GTK_IS_WIDGET (widget));
4625 gtk_widget_get_allocation (widget, &rect);
4627 if (!gtk_widget_get_has_window (widget))
4628 gtk_widget_queue_draw_area (widget,
4629 rect.x, rect.y, rect.width, rect.height);
4631 gtk_widget_queue_draw_area (widget,
4632 0, 0, rect.width, rect.height);
4636 * gtk_widget_queue_resize:
4637 * @widget: a #GtkWidget
4639 * This function is only for use in widget implementations.
4640 * Flags a widget to have its size renegotiated; should
4641 * be called when a widget for some reason has a new size request.
4642 * For example, when you change the text in a #GtkLabel, #GtkLabel
4643 * queues a resize to ensure there's enough space for the new text.
4645 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4646 * from inside its implementation of the GtkWidgetClass::size_allocate
4647 * virtual method. Calls to gtk_widget_queue_resize() from inside
4648 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4651 gtk_widget_queue_resize (GtkWidget *widget)
4653 g_return_if_fail (GTK_IS_WIDGET (widget));
4655 if (gtk_widget_get_realized (widget))
4656 gtk_widget_queue_draw (widget);
4658 _gtk_size_group_queue_resize (widget, 0);
4662 * gtk_widget_queue_resize_no_redraw:
4663 * @widget: a #GtkWidget
4665 * This function works like gtk_widget_queue_resize(),
4666 * except that the widget is not invalidated.
4671 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4673 g_return_if_fail (GTK_IS_WIDGET (widget));
4675 _gtk_size_group_queue_resize (widget, 0);
4679 * gtk_widget_size_request:
4680 * @widget: a #GtkWidget
4681 * @requisition: (out): a #GtkRequisition to be filled in
4683 * This function is typically used when implementing a #GtkContainer
4684 * subclass. Obtains the preferred size of a widget. The container
4685 * uses this information to arrange its child widgets and decide what
4686 * size allocations to give them with gtk_widget_size_allocate().
4688 * You can also call this function from an application, with some
4689 * caveats. Most notably, getting a size request requires the widget
4690 * to be associated with a screen, because font information may be
4691 * needed. Multihead-aware applications should keep this in mind.
4693 * Also remember that the size request is not necessarily the size
4694 * a widget will actually be allocated.
4696 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4699 gtk_widget_size_request (GtkWidget *widget,
4700 GtkRequisition *requisition)
4702 g_return_if_fail (GTK_IS_WIDGET (widget));
4704 gtk_widget_get_preferred_size (widget, requisition, NULL);
4708 * gtk_widget_get_child_requisition:
4709 * @widget: a #GtkWidget
4710 * @requisition: (out): a #GtkRequisition to be filled in
4712 * This function is only for use in widget implementations. Obtains
4713 * @widget->requisition, unless someone has forced a particular
4714 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4715 * in which case it returns that geometry instead of the widget's
4718 * This function differs from gtk_widget_size_request() in that
4719 * it retrieves the last size request value from @widget->requisition,
4720 * while gtk_widget_size_request() actually calls the "size_request" method
4721 * on @widget to compute the size request and fill in @widget->requisition,
4722 * and only then returns @widget->requisition.
4724 * Because this function does not call the "size_request" method, it
4725 * can only be used when you know that @widget->requisition is
4726 * up-to-date, that is, gtk_widget_size_request() has been called
4727 * since the last time a resize was queued. In general, only container
4728 * implementations have this information; applications should use
4729 * gtk_widget_size_request().
4732 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4735 gtk_widget_get_child_requisition (GtkWidget *widget,
4736 GtkRequisition *requisition)
4738 gtk_widget_get_preferred_size (widget, requisition, NULL);
4742 invalidate_predicate (GdkWindow *window,
4747 gdk_window_get_user_data (window, &user_data);
4749 return (user_data == data);
4752 /* Invalidate @region in widget->window and all children
4753 * of widget->window owned by widget. @region is in the
4754 * same coordinates as widget->allocation and will be
4755 * modified by this call.
4758 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4759 cairo_region_t *region)
4761 GtkWidgetPrivate *priv = widget->priv;
4763 if (!gtk_widget_get_realized (widget))
4766 if (gtk_widget_get_has_window (widget) && priv->parent)
4770 gdk_window_get_position (priv->window, &x, &y);
4771 cairo_region_translate (region, -x, -y);
4774 gdk_window_invalidate_maybe_recurse (priv->window, region,
4775 invalidate_predicate, widget);
4779 * gtk_widget_size_allocate:
4780 * @widget: a #GtkWidget
4781 * @allocation: position and size to be allocated to @widget
4783 * This function is only used by #GtkContainer subclasses, to assign a size
4784 * and position to their child widgets.
4786 * In this function, the allocation may be adjusted. It will be forced
4787 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4788 * method on the child will be used to adjust the allocation. Standard
4789 * adjustments include removing the widget's margins, and applying the
4790 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4793 gtk_widget_size_allocate (GtkWidget *widget,
4794 GtkAllocation *allocation)
4796 GtkWidgetPrivate *priv;
4797 GdkRectangle real_allocation;
4798 GdkRectangle old_allocation;
4799 GdkRectangle adjusted_allocation;
4800 gboolean alloc_needed;
4801 gboolean size_changed;
4802 gboolean position_changed;
4803 gint natural_width, natural_height, dummy;
4804 gint min_width, min_height;
4806 priv = widget->priv;
4808 g_return_if_fail (GTK_IS_WIDGET (widget));
4810 gtk_widget_push_verify_invariants (widget);
4812 #ifdef G_ENABLE_DEBUG
4813 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4824 parent = gtk_widget_get_parent (parent);
4827 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4828 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4829 2 * depth, " ", name,
4830 allocation->width, allocation->height);
4832 #endif /* G_ENABLE_DEBUG */
4834 alloc_needed = priv->alloc_needed;
4835 if (!priv->width_request_needed && !priv->height_request_needed)
4836 /* Preserve request/allocate ordering */
4837 priv->alloc_needed = FALSE;
4839 old_allocation = priv->allocation;
4840 real_allocation = *allocation;
4842 adjusted_allocation = real_allocation;
4843 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4845 /* Go ahead and request the height for allocated width, note that the internals
4846 * of get_height_for_width will internally limit the for_size to natural size
4847 * when aligning implicitly.
4849 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4850 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4854 /* Go ahead and request the width for allocated height, note that the internals
4855 * of get_width_for_height will internally limit the for_size to natural size
4856 * when aligning implicitly.
4858 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4859 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4862 #ifdef G_ENABLE_DEBUG
4863 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4865 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4866 !GTK_IS_SCROLLABLE (widget))
4867 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4868 "Allocation is %dx%d, but minimum required size is %dx%d.",
4869 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4870 G_OBJECT_TYPE_NAME (widget), widget,
4871 real_allocation.width, real_allocation.height,
4872 min_width, min_height);
4875 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4876 * allocated sizes and possibly limit them to the natural sizes */
4877 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4878 GTK_ORIENTATION_HORIZONTAL,
4881 &adjusted_allocation.x,
4882 &adjusted_allocation.width);
4883 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4884 GTK_ORIENTATION_VERTICAL,
4887 &adjusted_allocation.y,
4888 &adjusted_allocation.height);
4890 if (adjusted_allocation.x < real_allocation.x ||
4891 adjusted_allocation.y < real_allocation.y ||
4892 (adjusted_allocation.x + adjusted_allocation.width) >
4893 (real_allocation.x + real_allocation.width) ||
4894 (adjusted_allocation.y + adjusted_allocation.height >
4895 real_allocation.y + real_allocation.height))
4897 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",
4898 G_OBJECT_TYPE_NAME (widget), widget,
4899 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4900 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4901 adjusted_allocation = real_allocation; /* veto it */
4905 real_allocation = adjusted_allocation;
4908 if (real_allocation.width < 0 || real_allocation.height < 0)
4910 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4911 real_allocation.width,
4912 real_allocation.height);
4915 real_allocation.width = MAX (real_allocation.width, 1);
4916 real_allocation.height = MAX (real_allocation.height, 1);
4918 size_changed = (old_allocation.width != real_allocation.width ||
4919 old_allocation.height != real_allocation.height);
4920 position_changed = (old_allocation.x != real_allocation.x ||
4921 old_allocation.y != real_allocation.y);
4923 if (!alloc_needed && !size_changed && !position_changed)
4926 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4928 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4929 priv->width_request_needed = FALSE;
4930 priv->height_request_needed = FALSE;
4931 priv->alloc_needed = FALSE;
4933 if (gtk_widget_get_mapped (widget))
4935 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4937 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4939 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4940 cairo_region_union_rectangle (invalidate, &old_allocation);
4942 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4943 cairo_region_destroy (invalidate);
4948 if (priv->redraw_on_alloc)
4950 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4952 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4953 cairo_region_union_rectangle (invalidate, &old_allocation);
4955 gtk_widget_invalidate_widget_windows (widget, invalidate);
4956 cairo_region_destroy (invalidate);
4961 if ((size_changed || position_changed) && priv->parent &&
4962 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4964 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4965 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4966 cairo_region_destroy (invalidate);
4970 gtk_widget_pop_verify_invariants (widget);
4974 * gtk_widget_common_ancestor:
4975 * @widget_a: a #GtkWidget
4976 * @widget_b: a #GtkWidget
4978 * Find the common ancestor of @widget_a and @widget_b that
4979 * is closest to the two widgets.
4981 * Return value: the closest common ancestor of @widget_a and
4982 * @widget_b or %NULL if @widget_a and @widget_b do not
4983 * share a common ancestor.
4986 gtk_widget_common_ancestor (GtkWidget *widget_a,
4987 GtkWidget *widget_b)
4989 GtkWidget *parent_a;
4990 GtkWidget *parent_b;
4994 parent_a = widget_a;
4995 while (parent_a->priv->parent)
4997 parent_a = parent_a->priv->parent;
5001 parent_b = widget_b;
5002 while (parent_b->priv->parent)
5004 parent_b = parent_b->priv->parent;
5008 if (parent_a != parent_b)
5011 while (depth_a > depth_b)
5013 widget_a = widget_a->priv->parent;
5017 while (depth_b > depth_a)
5019 widget_b = widget_b->priv->parent;
5023 while (widget_a != widget_b)
5025 widget_a = widget_a->priv->parent;
5026 widget_b = widget_b->priv->parent;
5033 * gtk_widget_translate_coordinates:
5034 * @src_widget: a #GtkWidget
5035 * @dest_widget: a #GtkWidget
5036 * @src_x: X position relative to @src_widget
5037 * @src_y: Y position relative to @src_widget
5038 * @dest_x: (out): location to store X position relative to @dest_widget
5039 * @dest_y: (out): location to store Y position relative to @dest_widget
5041 * Translate coordinates relative to @src_widget's allocation to coordinates
5042 * relative to @dest_widget's allocations. In order to perform this
5043 * operation, both widgets must be realized, and must share a common
5046 * Return value: %FALSE if either widget was not realized, or there
5047 * was no common ancestor. In this case, nothing is stored in
5048 * *@dest_x and *@dest_y. Otherwise %TRUE.
5051 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5052 GtkWidget *dest_widget,
5058 GtkWidgetPrivate *src_priv = src_widget->priv;
5059 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5060 GtkWidget *ancestor;
5062 GList *dest_list = NULL;
5064 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5065 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5067 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5068 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5071 /* Translate from allocation relative to window relative */
5072 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5075 gdk_window_get_position (src_priv->window, &wx, &wy);
5077 src_x -= wx - src_priv->allocation.x;
5078 src_y -= wy - src_priv->allocation.y;
5082 src_x += src_priv->allocation.x;
5083 src_y += src_priv->allocation.y;
5086 /* Translate to the common ancestor */
5087 window = src_priv->window;
5088 while (window != ancestor->priv->window)
5092 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5097 window = gdk_window_get_effective_parent (window);
5099 if (!window) /* Handle GtkHandleBox */
5104 window = dest_priv->window;
5105 while (window != ancestor->priv->window)
5107 dest_list = g_list_prepend (dest_list, window);
5109 window = gdk_window_get_effective_parent (window);
5111 if (!window) /* Handle GtkHandleBox */
5113 g_list_free (dest_list);
5122 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5127 dest_list = g_list_remove (dest_list, dest_list->data);
5130 /* Translate from window relative to allocation relative */
5131 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5134 gdk_window_get_position (dest_priv->window, &wx, &wy);
5136 src_x += wx - dest_priv->allocation.x;
5137 src_y += wy - dest_priv->allocation.y;
5141 src_x -= dest_priv->allocation.x;
5142 src_y -= dest_priv->allocation.y;
5154 gtk_widget_real_size_allocate (GtkWidget *widget,
5155 GtkAllocation *allocation)
5157 GtkWidgetPrivate *priv = widget->priv;
5159 priv->allocation = *allocation;
5161 if (gtk_widget_get_realized (widget) &&
5162 gtk_widget_get_has_window (widget))
5164 gdk_window_move_resize (priv->window,
5165 allocation->x, allocation->y,
5166 allocation->width, allocation->height);
5170 /* translate initial/final into start/end */
5172 effective_align (GtkAlign align,
5173 GtkTextDirection direction)
5177 case GTK_ALIGN_START:
5178 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5180 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5187 adjust_for_align (GtkAlign align,
5189 gint *allocated_pos,
5190 gint *allocated_size)
5194 case GTK_ALIGN_FILL:
5195 /* change nothing */
5197 case GTK_ALIGN_START:
5198 /* keep *allocated_pos where it is */
5199 *allocated_size = MIN (*allocated_size, *natural_size);
5202 if (*allocated_size > *natural_size)
5204 *allocated_pos += (*allocated_size - *natural_size);
5205 *allocated_size = *natural_size;
5208 case GTK_ALIGN_CENTER:
5209 if (*allocated_size > *natural_size)
5211 *allocated_pos += (*allocated_size - *natural_size) / 2;
5212 *allocated_size = MIN (*allocated_size, *natural_size);
5219 adjust_for_margin(gint start_margin,
5223 gint *allocated_pos,
5224 gint *allocated_size)
5226 *minimum_size -= (start_margin + end_margin);
5227 *natural_size -= (start_margin + end_margin);
5228 *allocated_pos += start_margin;
5229 *allocated_size -= (start_margin + end_margin);
5233 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5234 GtkOrientation orientation,
5237 gint *allocated_pos,
5238 gint *allocated_size)
5240 const GtkWidgetAuxInfo *aux_info;
5242 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5244 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5246 adjust_for_margin (aux_info->margin.left,
5247 aux_info->margin.right,
5248 minimum_size, natural_size,
5249 allocated_pos, allocated_size);
5250 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5251 natural_size, allocated_pos, allocated_size);
5255 adjust_for_margin (aux_info->margin.top,
5256 aux_info->margin.bottom,
5257 minimum_size, natural_size,
5258 allocated_pos, allocated_size);
5259 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5260 natural_size, allocated_pos, allocated_size);
5265 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5268 GtkWidgetPrivate *priv = widget->priv;
5270 /* widgets must be onscreen for accels to take effect */
5271 return gtk_widget_is_sensitive (widget) &&
5272 gtk_widget_is_drawable (widget) &&
5273 gdk_window_is_viewable (priv->window);
5277 * gtk_widget_can_activate_accel:
5278 * @widget: a #GtkWidget
5279 * @signal_id: the ID of a signal installed on @widget
5281 * Determines whether an accelerator that activates the signal
5282 * identified by @signal_id can currently be activated.
5283 * This is done by emitting the #GtkWidget::can-activate-accel
5284 * signal on @widget; if the signal isn't overridden by a
5285 * handler or in a derived widget, then the default check is
5286 * that the widget must be sensitive, and the widget and all
5287 * its ancestors mapped.
5289 * Return value: %TRUE if the accelerator can be activated.
5294 gtk_widget_can_activate_accel (GtkWidget *widget,
5297 gboolean can_activate = FALSE;
5298 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5299 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5300 return can_activate;
5309 closure_accel_activate (GClosure *closure,
5310 GValue *return_value,
5311 guint n_param_values,
5312 const GValue *param_values,
5313 gpointer invocation_hint,
5314 gpointer marshal_data)
5316 AccelClosure *aclosure = (AccelClosure*) closure;
5317 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5320 g_signal_emit (closure->data, aclosure->signal_id, 0);
5322 /* whether accelerator was handled */
5323 g_value_set_boolean (return_value, can_activate);
5327 closures_destroy (gpointer data)
5329 GSList *slist, *closures = data;
5331 for (slist = closures; slist; slist = slist->next)
5333 g_closure_invalidate (slist->data);
5334 g_closure_unref (slist->data);
5336 g_slist_free (closures);
5340 widget_new_accel_closure (GtkWidget *widget,
5343 AccelClosure *aclosure;
5344 GClosure *closure = NULL;
5345 GSList *slist, *closures;
5347 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5348 for (slist = closures; slist; slist = slist->next)
5349 if (!gtk_accel_group_from_accel_closure (slist->data))
5351 /* reuse this closure */
5352 closure = slist->data;
5357 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5358 closures = g_slist_prepend (closures, g_closure_ref (closure));
5359 g_closure_sink (closure);
5360 g_closure_set_marshal (closure, closure_accel_activate);
5362 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5364 aclosure = (AccelClosure*) closure;
5365 g_assert (closure->data == widget);
5366 g_assert (closure->marshal == closure_accel_activate);
5367 aclosure->signal_id = signal_id;
5373 * gtk_widget_add_accelerator:
5374 * @widget: widget to install an accelerator on
5375 * @accel_signal: widget signal to emit on accelerator activation
5376 * @accel_group: accel group for this widget, added to its toplevel
5377 * @accel_key: GDK keyval of the accelerator
5378 * @accel_mods: modifier key combination of the accelerator
5379 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5381 * Installs an accelerator for this @widget in @accel_group that causes
5382 * @accel_signal to be emitted if the accelerator is activated.
5383 * The @accel_group needs to be added to the widget's toplevel via
5384 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5385 * Accelerators added through this function are not user changeable during
5386 * runtime. If you want to support accelerators that can be changed by the
5387 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5388 * gtk_menu_item_set_accel_path() instead.
5391 gtk_widget_add_accelerator (GtkWidget *widget,
5392 const gchar *accel_signal,
5393 GtkAccelGroup *accel_group,
5395 GdkModifierType accel_mods,
5396 GtkAccelFlags accel_flags)
5401 g_return_if_fail (GTK_IS_WIDGET (widget));
5402 g_return_if_fail (accel_signal != NULL);
5403 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5405 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5406 if (!query.signal_id ||
5407 !(query.signal_flags & G_SIGNAL_ACTION) ||
5408 query.return_type != G_TYPE_NONE ||
5411 /* hmm, should be elaborate enough */
5412 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5413 G_OBJECT_TYPE_NAME (widget), accel_signal);
5417 closure = widget_new_accel_closure (widget, query.signal_id);
5419 g_object_ref (widget);
5421 /* install the accelerator. since we don't map this onto an accel_path,
5422 * the accelerator will automatically be locked.
5424 gtk_accel_group_connect (accel_group,
5427 accel_flags | GTK_ACCEL_LOCKED,
5430 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5432 g_object_unref (widget);
5436 * gtk_widget_remove_accelerator:
5437 * @widget: widget to install an accelerator on
5438 * @accel_group: accel group for this widget
5439 * @accel_key: GDK keyval of the accelerator
5440 * @accel_mods: modifier key combination of the accelerator
5442 * Removes an accelerator from @widget, previously installed with
5443 * gtk_widget_add_accelerator().
5445 * Returns: whether an accelerator was installed and could be removed
5448 gtk_widget_remove_accelerator (GtkWidget *widget,
5449 GtkAccelGroup *accel_group,
5451 GdkModifierType accel_mods)
5453 GtkAccelGroupEntry *ag_entry;
5454 GList *slist, *clist;
5457 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5458 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5460 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5461 clist = gtk_widget_list_accel_closures (widget);
5462 for (slist = clist; slist; slist = slist->next)
5466 for (i = 0; i < n; i++)
5467 if (slist->data == (gpointer) ag_entry[i].closure)
5469 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5471 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5473 g_list_free (clist);
5478 g_list_free (clist);
5480 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5481 accel_key, accel_mods, accel_group,
5482 G_OBJECT_TYPE_NAME (widget), widget);
5488 * gtk_widget_list_accel_closures:
5489 * @widget: widget to list accelerator closures for
5491 * Lists the closures used by @widget for accelerator group connections
5492 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5493 * The closures can be used to monitor accelerator changes on @widget,
5494 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5495 * #GtkAccelGroup of a closure which can be found out with
5496 * gtk_accel_group_from_accel_closure().
5498 * Return value: (transfer container) (element-type GClosure):
5499 * a newly allocated #GList of closures
5502 gtk_widget_list_accel_closures (GtkWidget *widget)
5505 GList *clist = NULL;
5507 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5509 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5510 if (gtk_accel_group_from_accel_closure (slist->data))
5511 clist = g_list_prepend (clist, slist->data);
5517 GtkAccelGroup *accel_group;
5522 destroy_accel_path (gpointer data)
5524 AccelPath *apath = data;
5526 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5528 /* closures_destroy takes care of unrefing the closure */
5529 g_object_unref (apath->accel_group);
5531 g_slice_free (AccelPath, apath);
5536 * gtk_widget_set_accel_path:
5537 * @widget: a #GtkWidget
5538 * @accel_path: (allow-none): path used to look up the accelerator
5539 * @accel_group: (allow-none): a #GtkAccelGroup.
5541 * Given an accelerator group, @accel_group, and an accelerator path,
5542 * @accel_path, sets up an accelerator in @accel_group so whenever the
5543 * key binding that is defined for @accel_path is pressed, @widget
5544 * will be activated. This removes any accelerators (for any
5545 * accelerator group) installed by previous calls to
5546 * gtk_widget_set_accel_path(). Associating accelerators with
5547 * paths allows them to be modified by the user and the modifications
5548 * to be saved for future use. (See gtk_accel_map_save().)
5550 * This function is a low level function that would most likely
5551 * be used by a menu creation system like #GtkUIManager. If you
5552 * use #GtkUIManager, setting up accelerator paths will be done
5555 * Even when you you aren't using #GtkUIManager, if you only want to
5556 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5557 * provides a somewhat more convenient interface.
5559 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5560 * pass a static string, you can save some memory by interning it first with
5561 * g_intern_static_string().
5564 gtk_widget_set_accel_path (GtkWidget *widget,
5565 const gchar *accel_path,
5566 GtkAccelGroup *accel_group)
5570 g_return_if_fail (GTK_IS_WIDGET (widget));
5571 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5575 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5576 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5578 gtk_accel_map_add_entry (accel_path, 0, 0);
5579 apath = g_slice_new (AccelPath);
5580 apath->accel_group = g_object_ref (accel_group);
5581 apath->path_quark = g_quark_from_string (accel_path);
5582 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5587 /* also removes possible old settings */
5588 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5591 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5593 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5597 _gtk_widget_get_accel_path (GtkWidget *widget,
5602 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5604 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5606 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5607 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5611 * gtk_widget_mnemonic_activate:
5612 * @widget: a #GtkWidget
5613 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5615 * Emits the #GtkWidget::mnemonic-activate signal.
5617 * The default handler for this signal activates the @widget if
5618 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5621 * Returns: %TRUE if the signal has been handled
5624 gtk_widget_mnemonic_activate (GtkWidget *widget,
5625 gboolean group_cycling)
5629 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5631 group_cycling = group_cycling != FALSE;
5632 if (!gtk_widget_is_sensitive (widget))
5635 g_signal_emit (widget,
5636 widget_signals[MNEMONIC_ACTIVATE],
5644 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5645 gboolean group_cycling)
5647 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5648 gtk_widget_activate (widget);
5649 else if (gtk_widget_get_can_focus (widget))
5650 gtk_widget_grab_focus (widget);
5653 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5654 G_OBJECT_TYPE_NAME (widget));
5655 gtk_widget_error_bell (widget);
5660 static const cairo_user_data_key_t event_key;
5663 _gtk_cairo_get_event (cairo_t *cr)
5665 g_return_val_if_fail (cr != NULL, NULL);
5667 return cairo_get_user_data (cr, &event_key);
5671 gtk_cairo_set_event (cairo_t *cr,
5672 GdkEventExpose *event)
5674 cairo_set_user_data (cr, &event_key, event, NULL);
5678 * gtk_cairo_should_draw_window:
5679 * @cr: a cairo context
5680 * @window: the window to check. @window may not be an input-only
5683 * This function is supposed to be called in #GtkWidget::draw
5684 * implementations for widgets that support multiple windows.
5685 * @cr must be untransformed from invoking of the draw function.
5686 * This function will return %TRUE if the contents of the given
5687 * @window are supposed to be drawn and %FALSE otherwise. Note
5688 * that when the drawing was not initiated by the windowing
5689 * system this function will return %TRUE for all windows, so
5690 * you need to draw the bottommost window first. Also, do not
5691 * use "else if" statements to check which window should be drawn.
5693 * Returns: %TRUE if @window should be drawn
5698 gtk_cairo_should_draw_window (cairo_t *cr,
5701 GdkEventExpose *event;
5703 g_return_val_if_fail (cr != NULL, FALSE);
5704 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5706 event = _gtk_cairo_get_event (cr);
5708 return event == NULL ||
5709 event->window == window;
5713 gtk_widget_get_clip_draw (GtkWidget *widget)
5715 /* labels are not clipped, because clipping them would cause
5716 * mnemonics to not appear on characters that go beyond the
5718 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5720 if (GTK_IS_LABEL (widget))
5726 /* code shared by gtk_container_propagate_draw() and
5730 _gtk_widget_draw_internal (GtkWidget *widget,
5732 gboolean clip_to_size)
5734 if (!gtk_widget_is_drawable (widget))
5737 clip_to_size &= gtk_widget_get_clip_draw (widget);
5741 cairo_rectangle (cr,
5743 widget->priv->allocation.width,
5744 widget->priv->allocation.height);
5748 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5752 g_signal_emit (widget, widget_signals[DRAW],
5756 if (cairo_status (cr) &&
5757 _gtk_cairo_get_event (cr))
5759 /* We check the event so we only warn about internal GTK calls.
5760 * Errors might come from PDF streams having write failures and
5761 * we don't want to spam stderr in that case.
5762 * We do want to catch errors from
5764 g_warning ("drawing failure for widget `%s': %s",
5765 G_OBJECT_TYPE_NAME (widget),
5766 cairo_status_to_string (cairo_status (cr)));
5773 * @widget: the widget to draw. It must be drawable (see
5774 * gtk_widget_is_drawable()) and a size must have been allocated.
5775 * @cr: a cairo context to draw to
5777 * Draws @widget to @cr. The top left corner of the widget will be
5778 * drawn to the currently set origin point of @cr.
5780 * You should pass a cairo context as @cr argument that is in an
5781 * original state. Otherwise the resulting drawing is undefined. For
5782 * example changing the operator using cairo_set_operator() or the
5783 * line width using cairo_set_line_width() might have unwanted side
5785 * You may however change the context's transform matrix - like with
5786 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5787 * region with cairo_clip() prior to calling this function. Also, it
5788 * is fine to modify the context with cairo_save() and
5789 * cairo_push_group() prior to calling this function.
5791 * <note><para>Special purpose widgets may contain special code for
5792 * rendering to the screen and might appear differently on screen
5793 * and when rendered using gtk_widget_draw().</para></note>
5798 gtk_widget_draw (GtkWidget *widget,
5801 GdkEventExpose *tmp_event;
5803 g_return_if_fail (GTK_IS_WIDGET (widget));
5804 g_return_if_fail (!widget->priv->alloc_needed);
5805 g_return_if_fail (cr != NULL);
5808 /* We have to reset the event here so that draw functions can call
5809 * gtk_widget_draw() on random other widgets and get the desired
5810 * effect: Drawing all contents, not just the current window.
5812 tmp_event = _gtk_cairo_get_event (cr);
5813 gtk_cairo_set_event (cr, NULL);
5815 _gtk_widget_draw_internal (widget, cr, TRUE);
5817 gtk_cairo_set_event (cr, tmp_event);
5822 gtk_widget_real_key_press_event (GtkWidget *widget,
5825 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5829 gtk_widget_real_key_release_event (GtkWidget *widget,
5832 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5836 gtk_widget_real_focus_in_event (GtkWidget *widget,
5837 GdkEventFocus *event)
5839 gtk_widget_queue_draw (widget);
5845 gtk_widget_real_focus_out_event (GtkWidget *widget,
5846 GdkEventFocus *event)
5848 gtk_widget_queue_draw (widget);
5854 gtk_widget_real_touch_event (GtkWidget *widget,
5855 GdkEventTouch *event)
5858 gboolean return_val;
5861 if (!event->emulating_pointer)
5864 if (event->type == GDK_TOUCH_BEGIN ||
5865 event->type == GDK_TOUCH_END)
5869 if (event->type == GDK_TOUCH_BEGIN)
5871 type = GDK_BUTTON_PRESS;
5872 signum = BUTTON_PRESS_EVENT;
5876 type = GDK_BUTTON_RELEASE;
5877 signum = BUTTON_RELEASE_EVENT;
5879 bevent = gdk_event_new (type);
5880 bevent->any.window = g_object_ref (event->window);
5881 bevent->any.send_event = FALSE;
5882 bevent->button.time = event->time;
5883 bevent->button.state = event->state;
5884 bevent->button.button = 1;
5885 bevent->button.x_root = event->x_root;
5886 bevent->button.y_root = event->y_root;
5887 bevent->button.x = event->x;
5888 bevent->button.y = event->y;
5889 bevent->button.device = event->device;
5890 bevent->button.axes = g_memdup (event->axes,
5891 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5892 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5894 else if (event->type == GDK_TOUCH_UPDATE)
5896 signum = MOTION_NOTIFY_EVENT;
5897 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5898 bevent->any.window = g_object_ref (event->window);
5899 bevent->any.send_event = FALSE;
5900 bevent->motion.time = event->time;
5901 bevent->motion.state = event->state;
5902 bevent->motion.x_root = event->x_root;
5903 bevent->motion.y_root = event->y_root;
5904 bevent->motion.x = event->x;
5905 bevent->motion.y = event->y;
5906 bevent->motion.device = event->device;
5907 bevent->motion.is_hint = FALSE;
5908 bevent->motion.axes = g_memdup (event->axes,
5909 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5910 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5915 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5917 gdk_event_free (bevent);
5923 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5924 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5928 * @widget: a #GtkWidget
5929 * @event: a #GdkEvent
5931 * Rarely-used function. This function is used to emit
5932 * the event signals on a widget (those signals should never
5933 * be emitted without using this function to do so).
5934 * If you want to synthesize an event though, don't use this function;
5935 * instead, use gtk_main_do_event() so the event will behave as if
5936 * it were in the event queue. Don't synthesize expose events; instead,
5937 * use gdk_window_invalidate_rect() to invalidate a region of the
5940 * Return value: return from the event signal emission (%TRUE if
5941 * the event was handled)
5944 gtk_widget_event (GtkWidget *widget,
5947 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5948 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5950 if (event->type == GDK_EXPOSE)
5952 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5953 "the same effect, call gdk_window_invalidate_rect/region(), "
5954 "followed by gdk_window_process_updates().");
5958 return gtk_widget_event_internal (widget, event);
5962 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5963 GtkCapturedEventHandler callback)
5965 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5969 _gtk_widget_captured_event (GtkWidget *widget,
5972 gboolean return_val = FALSE;
5973 GtkCapturedEventHandler handler;
5975 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5976 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5978 if (event->type == GDK_EXPOSE)
5980 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5981 "the same effect, call gdk_window_invalidate_rect/region(), "
5982 "followed by gdk_window_process_updates().");
5986 if (!event_window_is_still_viewable (event))
5989 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
5993 g_object_ref (widget);
5995 return_val = handler (widget, event);
5996 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5998 /* The widget that was originally to receive the event
5999 * handles motion hints, but the capturing widget might
6000 * not, so ensure we get further motion events.
6003 event->type == GDK_MOTION_NOTIFY &&
6004 event->motion.is_hint &&
6005 (gdk_window_get_events (event->any.window) &
6006 GDK_POINTER_MOTION_HINT_MASK) != 0)
6007 gdk_event_request_motions (&event->motion);
6009 g_object_unref (widget);
6014 /* Returns TRUE if a translation should be done */
6016 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6021 GdkWindow *w, *widget_window;
6023 if (!gtk_widget_get_has_window (widget))
6025 *x = -widget->priv->allocation.x;
6026 *y = -widget->priv->allocation.y;
6034 widget_window = gtk_widget_get_window (widget);
6036 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6039 gdk_window_get_position (w, &wx, &wy);
6056 * gtk_cairo_transform_to_window:
6057 * @cr: the cairo context to transform
6058 * @widget: the widget the context is currently centered for
6059 * @window: the window to transform the context to
6061 * Transforms the given cairo context @cr that from @widget-relative
6062 * coordinates to @window-relative coordinates.
6063 * If the @widget's window is not an ancestor of @window, no
6064 * modification will be applied.
6066 * This is the inverse to the transformation GTK applies when
6067 * preparing an expose event to be emitted with the #GtkWidget::draw
6068 * signal. It is intended to help porting multiwindow widgets from
6069 * GTK+ 2 to the rendering architecture of GTK+ 3.
6074 gtk_cairo_transform_to_window (cairo_t *cr,
6080 g_return_if_fail (cr != NULL);
6081 g_return_if_fail (GTK_IS_WIDGET (widget));
6082 g_return_if_fail (GDK_IS_WINDOW (window));
6084 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6085 cairo_translate (cr, x, y);
6089 * gtk_widget_send_expose:
6090 * @widget: a #GtkWidget
6091 * @event: a expose #GdkEvent
6093 * Very rarely-used function. This function is used to emit
6094 * an expose event on a widget. This function is not normally used
6095 * directly. The only time it is used is when propagating an expose
6096 * event to a child %NO_WINDOW widget, and that is normally done
6097 * using gtk_container_propagate_draw().
6099 * If you want to force an area of a window to be redrawn,
6100 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6101 * To cause the redraw to be done immediately, follow that call
6102 * with a call to gdk_window_process_updates().
6104 * Return value: return from the event signal emission (%TRUE if
6105 * the event was handled)
6108 gtk_widget_send_expose (GtkWidget *widget,
6111 gboolean result = FALSE;
6116 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6117 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6118 g_return_val_if_fail (event != NULL, TRUE);
6119 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6121 cr = gdk_cairo_create (event->expose.window);
6122 gtk_cairo_set_event (cr, &event->expose);
6124 gdk_cairo_region (cr, event->expose.region);
6127 do_clip = _gtk_widget_get_translation_to_window (widget,
6128 event->expose.window,
6130 cairo_translate (cr, -x, -y);
6132 _gtk_widget_draw_internal (widget, cr, do_clip);
6134 /* unset here, so if someone keeps a reference to cr we
6135 * don't leak the window. */
6136 gtk_cairo_set_event (cr, NULL);
6143 event_window_is_still_viewable (GdkEvent *event)
6145 /* Check that we think the event's window is viewable before
6146 * delivering the event, to prevent suprises. We do this here
6147 * at the last moment, since the event may have been queued
6148 * up behind other events, held over a recursive main loop, etc.
6150 switch (event->type)
6153 case GDK_MOTION_NOTIFY:
6154 case GDK_BUTTON_PRESS:
6155 case GDK_2BUTTON_PRESS:
6156 case GDK_3BUTTON_PRESS:
6158 case GDK_ENTER_NOTIFY:
6159 case GDK_PROXIMITY_IN:
6161 return event->any.window && gdk_window_is_viewable (event->any.window);
6164 /* The following events are the second half of paired events;
6165 * we always deliver them to deal with widgets that clean up
6166 * on the second half.
6168 case GDK_BUTTON_RELEASE:
6169 case GDK_KEY_RELEASE:
6170 case GDK_LEAVE_NOTIFY:
6171 case GDK_PROXIMITY_OUT:
6175 /* Remaining events would make sense on an not-viewable window,
6176 * or don't have an associated window.
6183 gtk_widget_event_internal (GtkWidget *widget,
6186 gboolean return_val = FALSE;
6188 /* We check only once for is-still-visible; if someone
6189 * hides the window in on of the signals on the widget,
6190 * they are responsible for returning TRUE to terminate
6193 if (!event_window_is_still_viewable (event))
6196 g_object_ref (widget);
6198 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6199 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6204 switch (event->type)
6210 case GDK_BUTTON_PRESS:
6211 case GDK_2BUTTON_PRESS:
6212 case GDK_3BUTTON_PRESS:
6213 signal_num = BUTTON_PRESS_EVENT;
6215 case GDK_TOUCH_BEGIN:
6216 case GDK_TOUCH_UPDATE:
6218 case GDK_TOUCH_CANCEL:
6219 signal_num = TOUCH_EVENT;
6222 signal_num = SCROLL_EVENT;
6224 case GDK_BUTTON_RELEASE:
6225 signal_num = BUTTON_RELEASE_EVENT;
6227 case GDK_MOTION_NOTIFY:
6228 signal_num = MOTION_NOTIFY_EVENT;
6231 signal_num = DELETE_EVENT;
6234 signal_num = DESTROY_EVENT;
6235 _gtk_tooltip_hide (widget);
6238 signal_num = KEY_PRESS_EVENT;
6240 case GDK_KEY_RELEASE:
6241 signal_num = KEY_RELEASE_EVENT;
6243 case GDK_ENTER_NOTIFY:
6244 signal_num = ENTER_NOTIFY_EVENT;
6246 case GDK_LEAVE_NOTIFY:
6247 signal_num = LEAVE_NOTIFY_EVENT;
6249 case GDK_FOCUS_CHANGE:
6250 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6251 if (event->focus_change.in)
6252 _gtk_tooltip_focus_in (widget);
6254 _gtk_tooltip_focus_out (widget);
6257 signal_num = CONFIGURE_EVENT;
6260 signal_num = MAP_EVENT;
6263 signal_num = UNMAP_EVENT;
6265 case GDK_WINDOW_STATE:
6266 signal_num = WINDOW_STATE_EVENT;
6268 case GDK_PROPERTY_NOTIFY:
6269 signal_num = PROPERTY_NOTIFY_EVENT;
6271 case GDK_SELECTION_CLEAR:
6272 signal_num = SELECTION_CLEAR_EVENT;
6274 case GDK_SELECTION_REQUEST:
6275 signal_num = SELECTION_REQUEST_EVENT;
6277 case GDK_SELECTION_NOTIFY:
6278 signal_num = SELECTION_NOTIFY_EVENT;
6280 case GDK_PROXIMITY_IN:
6281 signal_num = PROXIMITY_IN_EVENT;
6283 case GDK_PROXIMITY_OUT:
6284 signal_num = PROXIMITY_OUT_EVENT;
6286 case GDK_VISIBILITY_NOTIFY:
6287 signal_num = VISIBILITY_NOTIFY_EVENT;
6289 case GDK_GRAB_BROKEN:
6290 signal_num = GRAB_BROKEN_EVENT;
6293 signal_num = DAMAGE_EVENT;
6296 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6300 if (signal_num != -1)
6301 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6303 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6304 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6308 g_object_unref (widget);
6314 * gtk_widget_activate:
6315 * @widget: a #GtkWidget that's activatable
6317 * For widgets that can be "activated" (buttons, menu items, etc.)
6318 * this function activates them. Activation is what happens when you
6319 * press Enter on a widget during key navigation. If @widget isn't
6320 * activatable, the function returns %FALSE.
6322 * Return value: %TRUE if the widget was activatable
6325 gtk_widget_activate (GtkWidget *widget)
6327 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6329 if (WIDGET_CLASS (widget)->activate_signal)
6331 /* FIXME: we should eventually check the signals signature here */
6332 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6341 gtk_widget_reparent_subwindows (GtkWidget *widget,
6342 GdkWindow *new_window)
6344 GtkWidgetPrivate *priv = widget->priv;
6346 if (!gtk_widget_get_has_window (widget))
6348 GList *children = gdk_window_get_children (priv->window);
6351 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6353 GdkWindow *window = tmp_list->data;
6356 gdk_window_get_user_data (window, &child);
6357 while (child && child != widget)
6358 child = ((GtkWidget*) child)->priv->parent;
6361 gdk_window_reparent (window, new_window, 0, 0);
6364 g_list_free (children);
6369 GList *tmp_list, *children;
6371 parent = gdk_window_get_parent (priv->window);
6374 gdk_window_reparent (priv->window, new_window, 0, 0);
6377 children = gdk_window_get_children (parent);
6379 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6381 GdkWindow *window = tmp_list->data;
6384 gdk_window_get_user_data (window, &child);
6386 if (child == widget)
6387 gdk_window_reparent (window, new_window, 0, 0);
6390 g_list_free (children);
6396 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6397 gpointer client_data)
6399 GtkWidgetPrivate *priv = widget->priv;
6401 g_assert (client_data != NULL);
6403 if (!gtk_widget_get_has_window (widget))
6406 g_object_unref (priv->window);
6407 priv->window = (GdkWindow*) client_data;
6409 g_object_ref (priv->window);
6411 if (GTK_IS_CONTAINER (widget))
6412 gtk_container_forall (GTK_CONTAINER (widget),
6413 gtk_widget_reparent_fixup_child,
6419 * gtk_widget_reparent:
6420 * @widget: a #GtkWidget
6421 * @new_parent: a #GtkContainer to move the widget into
6423 * Moves a widget from one #GtkContainer to another, handling reference
6424 * count issues to avoid destroying the widget.
6427 gtk_widget_reparent (GtkWidget *widget,
6428 GtkWidget *new_parent)
6430 GtkWidgetPrivate *priv;
6432 g_return_if_fail (GTK_IS_WIDGET (widget));
6433 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6434 priv = widget->priv;
6435 g_return_if_fail (priv->parent != NULL);
6437 if (priv->parent != new_parent)
6439 /* First try to see if we can get away without unrealizing
6440 * the widget as we reparent it. if so we set a flag so
6441 * that gtk_widget_unparent doesn't unrealize widget
6443 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6444 priv->in_reparent = TRUE;
6446 g_object_ref (widget);
6447 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6448 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6449 g_object_unref (widget);
6451 if (priv->in_reparent)
6453 priv->in_reparent = FALSE;
6455 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6456 gtk_widget_reparent_fixup_child (widget,
6457 gtk_widget_get_parent_window (widget));
6460 g_object_notify (G_OBJECT (widget), "parent");
6465 * gtk_widget_intersect:
6466 * @widget: a #GtkWidget
6467 * @area: a rectangle
6468 * @intersection: rectangle to store intersection of @widget and @area
6470 * Computes the intersection of a @widget's area and @area, storing
6471 * the intersection in @intersection, and returns %TRUE if there was
6472 * an intersection. @intersection may be %NULL if you're only
6473 * interested in whether there was an intersection.
6475 * Return value: %TRUE if there was an intersection
6478 gtk_widget_intersect (GtkWidget *widget,
6479 const GdkRectangle *area,
6480 GdkRectangle *intersection)
6482 GtkWidgetPrivate *priv;
6487 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6488 g_return_val_if_fail (area != NULL, FALSE);
6490 priv = widget->priv;
6493 dest = intersection;
6497 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6499 if (return_val && intersection && gtk_widget_get_has_window (widget))
6501 intersection->x -= priv->allocation.x;
6502 intersection->y -= priv->allocation.y;
6509 * gtk_widget_region_intersect:
6510 * @widget: a #GtkWidget
6511 * @region: a #cairo_region_t, in the same coordinate system as
6512 * @widget->allocation. That is, relative to @widget->window
6513 * for %NO_WINDOW widgets; relative to the parent window
6514 * of @widget->window for widgets with their own window.
6516 * Computes the intersection of a @widget's area and @region, returning
6517 * the intersection. The result may be empty, use cairo_region_is_empty() to
6520 * Returns: A newly allocated region holding the intersection of @widget
6521 * and @region. The coordinates of the return value are relative to
6522 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6523 * window of @widget->window for widgets with their own window.
6526 gtk_widget_region_intersect (GtkWidget *widget,
6527 const cairo_region_t *region)
6530 cairo_region_t *dest;
6532 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6533 g_return_val_if_fail (region != NULL, NULL);
6535 gtk_widget_get_allocation (widget, &rect);
6537 dest = cairo_region_create_rectangle (&rect);
6539 cairo_region_intersect (dest, region);
6545 * _gtk_widget_grab_notify:
6546 * @widget: a #GtkWidget
6547 * @was_grabbed: whether a grab is now in effect
6549 * Emits the #GtkWidget::grab-notify signal on @widget.
6554 _gtk_widget_grab_notify (GtkWidget *widget,
6555 gboolean was_grabbed)
6557 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6561 * gtk_widget_grab_focus:
6562 * @widget: a #GtkWidget
6564 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6565 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6566 * something like #GtkFrame won't work.
6568 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6569 * gtk_widget_set_can_focus() to modify that flag.
6571 * The widget also needs to be realized and mapped. This is indicated by the
6572 * related signals. Grabbing the focus immediately after creating the widget
6573 * will likely fail and cause critical warnings.
6576 gtk_widget_grab_focus (GtkWidget *widget)
6578 g_return_if_fail (GTK_IS_WIDGET (widget));
6580 if (!gtk_widget_is_sensitive (widget))
6583 g_object_ref (widget);
6584 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6585 g_object_notify (G_OBJECT (widget), "has-focus");
6586 g_object_unref (widget);
6590 reset_focus_recurse (GtkWidget *widget,
6593 if (GTK_IS_CONTAINER (widget))
6595 GtkContainer *container;
6597 container = GTK_CONTAINER (widget);
6598 gtk_container_set_focus_child (container, NULL);
6600 gtk_container_foreach (container,
6601 reset_focus_recurse,
6607 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6609 if (gtk_widget_get_can_focus (focus_widget))
6611 GtkWidget *toplevel;
6614 /* clear the current focus setting, break if the current widget
6615 * is the focus widget's parent, since containers above that will
6616 * be set by the next loop.
6618 toplevel = gtk_widget_get_toplevel (focus_widget);
6619 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6621 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6623 if (widget == focus_widget)
6625 /* We call _gtk_window_internal_set_focus() here so that the
6626 * toplevel window can request the focus if necessary.
6627 * This is needed when the toplevel is a GtkPlug
6629 if (!gtk_widget_has_focus (widget))
6630 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6637 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6639 if (widget != common_ancestor)
6641 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6643 widget = widget->priv->parent;
6644 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6649 else if (toplevel != focus_widget)
6651 /* gtk_widget_grab_focus() operates on a tree without window...
6652 * actually, this is very questionable behaviour.
6655 gtk_container_foreach (GTK_CONTAINER (toplevel),
6656 reset_focus_recurse,
6660 /* now propagate the new focus up the widget tree and finally
6661 * set it on the window
6663 widget = focus_widget;
6664 while (widget->priv->parent)
6666 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6667 widget = widget->priv->parent;
6669 if (GTK_IS_WINDOW (widget))
6670 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6675 gtk_widget_real_query_tooltip (GtkWidget *widget,
6678 gboolean keyboard_tip,
6679 GtkTooltip *tooltip)
6681 gchar *tooltip_markup;
6682 gboolean has_tooltip;
6684 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6685 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6687 if (has_tooltip && tooltip_markup)
6689 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6697 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6698 GtkStateFlags old_state)
6700 gtk_widget_update_pango_context (widget);
6704 gtk_widget_real_style_updated (GtkWidget *widget)
6706 GtkWidgetPrivate *priv = widget->priv;
6708 gtk_widget_update_pango_context (widget);
6710 if (priv->style != NULL &&
6711 priv->style != gtk_widget_get_default_style ())
6713 /* Trigger ::style-set for old
6714 * widgets not listening to this
6716 g_signal_emit (widget,
6717 widget_signals[STYLE_SET],
6719 widget->priv->style);
6722 if (widget->priv->context)
6724 if (gtk_widget_get_realized (widget) &&
6725 gtk_widget_get_has_window (widget) &&
6726 !gtk_widget_get_app_paintable (widget))
6727 gtk_style_context_set_background (widget->priv->context,
6728 widget->priv->window);
6731 if (widget->priv->anchored)
6732 gtk_widget_queue_resize (widget);
6736 gtk_widget_real_show_help (GtkWidget *widget,
6737 GtkWidgetHelpType help_type)
6739 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6741 _gtk_tooltip_toggle_keyboard_mode (widget);
6750 gtk_widget_real_focus (GtkWidget *widget,
6751 GtkDirectionType direction)
6753 if (!gtk_widget_get_can_focus (widget))
6756 if (!gtk_widget_is_focus (widget))
6758 gtk_widget_grab_focus (widget);
6766 gtk_widget_real_move_focus (GtkWidget *widget,
6767 GtkDirectionType direction)
6769 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6771 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6773 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6779 gtk_widget_real_keynav_failed (GtkWidget *widget,
6780 GtkDirectionType direction)
6782 gboolean cursor_only;
6786 case GTK_DIR_TAB_FORWARD:
6787 case GTK_DIR_TAB_BACKWARD:
6794 g_object_get (gtk_widget_get_settings (widget),
6795 "gtk-keynav-cursor-only", &cursor_only,
6802 gtk_widget_error_bell (widget);
6808 * gtk_widget_set_can_focus:
6809 * @widget: a #GtkWidget
6810 * @can_focus: whether or not @widget can own the input focus.
6812 * Specifies whether @widget can own the input focus. See
6813 * gtk_widget_grab_focus() for actually setting the input focus on a
6819 gtk_widget_set_can_focus (GtkWidget *widget,
6822 g_return_if_fail (GTK_IS_WIDGET (widget));
6824 if (widget->priv->can_focus != can_focus)
6826 widget->priv->can_focus = can_focus;
6828 gtk_widget_queue_resize (widget);
6829 g_object_notify (G_OBJECT (widget), "can-focus");
6834 * gtk_widget_get_can_focus:
6835 * @widget: a #GtkWidget
6837 * Determines whether @widget can own the input focus. See
6838 * gtk_widget_set_can_focus().
6840 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6845 gtk_widget_get_can_focus (GtkWidget *widget)
6847 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6849 return widget->priv->can_focus;
6853 * gtk_widget_has_focus:
6854 * @widget: a #GtkWidget
6856 * Determines if the widget has the global input focus. See
6857 * gtk_widget_is_focus() for the difference between having the global
6858 * input focus, and only having the focus within a toplevel.
6860 * Return value: %TRUE if the widget has the global input focus.
6865 gtk_widget_has_focus (GtkWidget *widget)
6867 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6869 return widget->priv->has_focus;
6873 * gtk_widget_has_visible_focus:
6874 * @widget: a #GtkWidget
6876 * Determines if the widget should show a visible indication that
6877 * it has the global input focus. This is a convenience function for
6878 * use in ::draw handlers that takes into account whether focus
6879 * indication should currently be shown in the toplevel window of
6880 * @widget. See gtk_window_get_focus_visible() for more information
6881 * about focus indication.
6883 * To find out if the widget has the global input focus, use
6884 * gtk_widget_has_focus().
6886 * Return value: %TRUE if the widget should display a 'focus rectangle'
6891 gtk_widget_has_visible_focus (GtkWidget *widget)
6893 gboolean draw_focus;
6895 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6897 if (widget->priv->has_focus)
6899 GtkWidget *toplevel;
6901 toplevel = gtk_widget_get_toplevel (widget);
6903 if (GTK_IS_WINDOW (toplevel))
6904 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6915 * gtk_widget_is_focus:
6916 * @widget: a #GtkWidget
6918 * Determines if the widget is the focus widget within its
6919 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6920 * necessarily set; %HAS_FOCUS will only be set if the
6921 * toplevel widget additionally has the global input focus.)
6923 * Return value: %TRUE if the widget is the focus widget.
6926 gtk_widget_is_focus (GtkWidget *widget)
6928 GtkWidget *toplevel;
6930 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6932 toplevel = gtk_widget_get_toplevel (widget);
6934 if (GTK_IS_WINDOW (toplevel))
6935 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6941 * gtk_widget_set_can_default:
6942 * @widget: a #GtkWidget
6943 * @can_default: whether or not @widget can be a default widget.
6945 * Specifies whether @widget can be a default widget. See
6946 * gtk_widget_grab_default() for details about the meaning of
6952 gtk_widget_set_can_default (GtkWidget *widget,
6953 gboolean can_default)
6955 g_return_if_fail (GTK_IS_WIDGET (widget));
6957 if (widget->priv->can_default != can_default)
6959 widget->priv->can_default = can_default;
6961 gtk_widget_queue_resize (widget);
6962 g_object_notify (G_OBJECT (widget), "can-default");
6967 * gtk_widget_get_can_default:
6968 * @widget: a #GtkWidget
6970 * Determines whether @widget can be a default widget. See
6971 * gtk_widget_set_can_default().
6973 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6978 gtk_widget_get_can_default (GtkWidget *widget)
6980 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6982 return widget->priv->can_default;
6986 * gtk_widget_has_default:
6987 * @widget: a #GtkWidget
6989 * Determines whether @widget is the current default widget within its
6990 * toplevel. See gtk_widget_set_can_default().
6992 * Return value: %TRUE if @widget is the current default widget within
6993 * its toplevel, %FALSE otherwise
6998 gtk_widget_has_default (GtkWidget *widget)
7000 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7002 return widget->priv->has_default;
7006 _gtk_widget_set_has_default (GtkWidget *widget,
7007 gboolean has_default)
7009 GtkStyleContext *context;
7011 widget->priv->has_default = has_default;
7013 context = gtk_widget_get_style_context (widget);
7016 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7018 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7022 * gtk_widget_grab_default:
7023 * @widget: a #GtkWidget
7025 * Causes @widget to become the default widget. @widget must be able to be
7026 * a default widget; typically you would ensure this yourself
7027 * by calling gtk_widget_set_can_default() with a %TRUE value.
7028 * The default widget is activated when
7029 * the user presses Enter in a window. Default widgets must be
7030 * activatable, that is, gtk_widget_activate() should affect them. Note
7031 * that #GtkEntry widgets require the "activates-default" property
7032 * set to %TRUE before they activate the default widget when Enter
7033 * is pressed and the #GtkEntry is focused.
7036 gtk_widget_grab_default (GtkWidget *widget)
7040 g_return_if_fail (GTK_IS_WIDGET (widget));
7041 g_return_if_fail (gtk_widget_get_can_default (widget));
7043 window = gtk_widget_get_toplevel (widget);
7045 if (window && gtk_widget_is_toplevel (window))
7046 gtk_window_set_default (GTK_WINDOW (window), widget);
7048 g_warning (G_STRLOC ": widget not within a GtkWindow");
7052 * gtk_widget_set_receives_default:
7053 * @widget: a #GtkWidget
7054 * @receives_default: whether or not @widget can be a default widget.
7056 * Specifies whether @widget will be treated as the default widget
7057 * within its toplevel when it has the focus, even if another widget
7060 * See gtk_widget_grab_default() for details about the meaning of
7066 gtk_widget_set_receives_default (GtkWidget *widget,
7067 gboolean receives_default)
7069 g_return_if_fail (GTK_IS_WIDGET (widget));
7071 if (widget->priv->receives_default != receives_default)
7073 widget->priv->receives_default = receives_default;
7075 g_object_notify (G_OBJECT (widget), "receives-default");
7080 * gtk_widget_get_receives_default:
7081 * @widget: a #GtkWidget
7083 * Determines whether @widget is alyways treated as default widget
7084 * withing its toplevel when it has the focus, even if another widget
7087 * See gtk_widget_set_receives_default().
7089 * Return value: %TRUE if @widget acts as default widget when focussed,
7095 gtk_widget_get_receives_default (GtkWidget *widget)
7097 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7099 return widget->priv->receives_default;
7103 * gtk_widget_has_grab:
7104 * @widget: a #GtkWidget
7106 * Determines whether the widget is currently grabbing events, so it
7107 * is the only widget receiving input events (keyboard and mouse).
7109 * See also gtk_grab_add().
7111 * Return value: %TRUE if the widget is in the grab_widgets stack
7116 gtk_widget_has_grab (GtkWidget *widget)
7118 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7120 return widget->priv->has_grab;
7124 _gtk_widget_set_has_grab (GtkWidget *widget,
7127 widget->priv->has_grab = has_grab;
7131 * gtk_widget_device_is_shadowed:
7132 * @widget: a #GtkWidget
7133 * @device: a #GdkDevice
7135 * Returns %TRUE if @device has been shadowed by a GTK+
7136 * device grab on another widget, so it would stop sending
7137 * events to @widget. This may be used in the
7138 * #GtkWidget::grab-notify signal to check for specific
7139 * devices. See gtk_device_grab_add().
7141 * Returns: %TRUE if there is an ongoing grab on @device
7142 * by another #GtkWidget than @widget.
7147 gtk_widget_device_is_shadowed (GtkWidget *widget,
7150 GtkWindowGroup *group;
7151 GtkWidget *grab_widget, *toplevel;
7153 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7154 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7156 if (!gtk_widget_get_realized (widget))
7159 toplevel = gtk_widget_get_toplevel (widget);
7161 if (GTK_IS_WINDOW (toplevel))
7162 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7164 group = gtk_window_get_group (NULL);
7166 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7168 /* Widget not inside the hierarchy of grab_widget */
7170 widget != grab_widget &&
7171 !gtk_widget_is_ancestor (widget, grab_widget))
7174 grab_widget = gtk_window_group_get_current_grab (group);
7175 if (grab_widget && widget != grab_widget &&
7176 !gtk_widget_is_ancestor (widget, grab_widget))
7183 * gtk_widget_set_name:
7184 * @widget: a #GtkWidget
7185 * @name: name for the widget
7187 * Widgets can be named, which allows you to refer to them from a
7188 * CSS file. You can apply a style to widgets with a particular name
7189 * in the CSS file. See the documentation for the CSS syntax (on the
7190 * same page as the docs for #GtkStyleContext).
7192 * Note that the CSS syntax has certain special characters to delimit
7193 * and represent elements in a selector (period, #, >, *...),
7194 * so using these will make your widget impossible to match by name.
7195 * Any combination of alphanumeric symbols, dashes and underscores will
7199 gtk_widget_set_name (GtkWidget *widget,
7202 GtkWidgetPrivate *priv;
7205 g_return_if_fail (GTK_IS_WIDGET (widget));
7207 priv = widget->priv;
7209 new_name = g_strdup (name);
7210 g_free (priv->name);
7211 priv->name = new_name;
7213 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7215 g_object_notify (G_OBJECT (widget), "name");
7219 * gtk_widget_get_name:
7220 * @widget: a #GtkWidget
7222 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7223 * significance of widget names.
7225 * Return value: name of the widget. This string is owned by GTK+ and
7226 * should not be modified or freed
7229 gtk_widget_get_name (GtkWidget *widget)
7231 GtkWidgetPrivate *priv;
7233 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7235 priv = widget->priv;
7239 return G_OBJECT_TYPE_NAME (widget);
7243 _gtk_widget_update_state_flags (GtkWidget *widget,
7244 GtkStateFlags flags,
7247 GtkWidgetPrivate *priv;
7249 priv = widget->priv;
7251 /* Handle insensitive first, since it is propagated
7252 * differently throughout the widget hierarchy.
7254 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7255 gtk_widget_set_sensitive (widget, TRUE);
7256 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7257 gtk_widget_set_sensitive (widget, FALSE);
7258 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7259 gtk_widget_set_sensitive (widget, TRUE);
7261 if (operation != STATE_CHANGE_REPLACE)
7262 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7265 operation == STATE_CHANGE_REPLACE)
7270 data.operation = operation;
7272 gtk_widget_propagate_state (widget, &data);
7274 gtk_widget_queue_resize (widget);
7279 * gtk_widget_set_state_flags:
7280 * @widget: a #GtkWidget
7281 * @flags: State flags to turn on
7282 * @clear: Whether to clear state before turning on @flags
7284 * This function is for use in widget implementations. Turns on flag
7285 * values in the current widget state (insensitive, prelighted, etc.).
7287 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7288 * will be propagated down to all non-internal children if @widget is a
7289 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7290 * down to all #GtkContainer children by different means than turning on the
7291 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7292 * gtk_widget_is_sensitive() will make use of these.
7297 gtk_widget_set_state_flags (GtkWidget *widget,
7298 GtkStateFlags flags,
7301 g_return_if_fail (GTK_IS_WIDGET (widget));
7303 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7304 (clear && widget->priv->state_flags == flags))
7308 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7310 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7314 * gtk_widget_unset_state_flags:
7315 * @widget: a #GtkWidget
7316 * @flags: State flags to turn off
7318 * This function is for use in widget implementations. Turns off flag
7319 * values for the current widget state (insensitive, prelighted, etc.).
7320 * See gtk_widget_set_state_flags().
7325 gtk_widget_unset_state_flags (GtkWidget *widget,
7326 GtkStateFlags flags)
7328 g_return_if_fail (GTK_IS_WIDGET (widget));
7330 if ((widget->priv->state_flags & flags) == 0)
7333 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7337 * gtk_widget_get_state_flags:
7338 * @widget: a #GtkWidget
7340 * Returns the widget state as a flag set. It is worth mentioning
7341 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7342 * returned, that is, also based on parent insensitivity, even if
7343 * @widget itself is sensitive.
7345 * Returns: The state flags for widget
7350 gtk_widget_get_state_flags (GtkWidget *widget)
7352 GtkStateFlags flags;
7354 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7356 flags = widget->priv->state_flags;
7358 if (gtk_widget_has_focus (widget))
7359 flags |= GTK_STATE_FLAG_FOCUSED;
7365 * gtk_widget_set_state:
7366 * @widget: a #GtkWidget
7367 * @state: new state for @widget
7369 * This function is for use in widget implementations. Sets the state
7370 * of a widget (insensitive, prelighted, etc.) Usually you should set
7371 * the state using wrapper functions such as gtk_widget_set_sensitive().
7373 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7376 gtk_widget_set_state (GtkWidget *widget,
7379 GtkStateFlags flags;
7381 if (state == gtk_widget_get_state (widget))
7386 case GTK_STATE_ACTIVE:
7387 flags = GTK_STATE_FLAG_ACTIVE;
7389 case GTK_STATE_PRELIGHT:
7390 flags = GTK_STATE_FLAG_PRELIGHT;
7392 case GTK_STATE_SELECTED:
7393 flags = GTK_STATE_FLAG_SELECTED;
7395 case GTK_STATE_INSENSITIVE:
7396 flags = GTK_STATE_FLAG_INSENSITIVE;
7398 case GTK_STATE_INCONSISTENT:
7399 flags = GTK_STATE_FLAG_INCONSISTENT;
7401 case GTK_STATE_FOCUSED:
7402 flags = GTK_STATE_FLAG_FOCUSED;
7404 case GTK_STATE_NORMAL:
7410 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7414 * gtk_widget_get_state:
7415 * @widget: a #GtkWidget
7417 * Returns the widget's state. See gtk_widget_set_state().
7419 * Returns: the state of @widget.
7423 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7426 gtk_widget_get_state (GtkWidget *widget)
7428 GtkStateFlags flags;
7430 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7432 flags = gtk_widget_get_state_flags (widget);
7434 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7435 return GTK_STATE_INSENSITIVE;
7436 else if (flags & GTK_STATE_FLAG_ACTIVE)
7437 return GTK_STATE_ACTIVE;
7438 else if (flags & GTK_STATE_FLAG_SELECTED)
7439 return GTK_STATE_SELECTED;
7440 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7441 return GTK_STATE_PRELIGHT;
7443 return GTK_STATE_NORMAL;
7447 * gtk_widget_set_visible:
7448 * @widget: a #GtkWidget
7449 * @visible: whether the widget should be shown or not
7451 * Sets the visibility state of @widget. Note that setting this to
7452 * %TRUE doesn't mean the widget is actually viewable, see
7453 * gtk_widget_get_visible().
7455 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7456 * but is nicer to use when the visibility of the widget depends on
7462 gtk_widget_set_visible (GtkWidget *widget,
7465 g_return_if_fail (GTK_IS_WIDGET (widget));
7467 if (visible != gtk_widget_get_visible (widget))
7470 gtk_widget_show (widget);
7472 gtk_widget_hide (widget);
7477 _gtk_widget_set_visible_flag (GtkWidget *widget,
7480 widget->priv->visible = visible;
7484 * gtk_widget_get_visible:
7485 * @widget: a #GtkWidget
7487 * Determines whether the widget is visible. Note that this doesn't
7488 * take into account whether the widget's parent is also visible
7489 * or the widget is obscured in any way.
7491 * See gtk_widget_set_visible().
7493 * Return value: %TRUE if the widget is visible
7498 gtk_widget_get_visible (GtkWidget *widget)
7500 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7502 return widget->priv->visible;
7506 * gtk_widget_set_has_window:
7507 * @widget: a #GtkWidget
7508 * @has_window: whether or not @widget has a window.
7510 * Specifies whether @widget has a #GdkWindow of its own. Note that
7511 * all realized widgets have a non-%NULL "window" pointer
7512 * (gtk_widget_get_window() never returns a %NULL window when a widget
7513 * is realized), but for many of them it's actually the #GdkWindow of
7514 * one of its parent widgets. Widgets that do not create a %window for
7515 * themselves in #GtkWidget::realize must announce this by
7516 * calling this function with @has_window = %FALSE.
7518 * This function should only be called by widget implementations,
7519 * and they should call it in their init() function.
7524 gtk_widget_set_has_window (GtkWidget *widget,
7525 gboolean has_window)
7527 g_return_if_fail (GTK_IS_WIDGET (widget));
7529 widget->priv->no_window = !has_window;
7533 * gtk_widget_get_has_window:
7534 * @widget: a #GtkWidget
7536 * Determines whether @widget has a #GdkWindow of its own. See
7537 * gtk_widget_set_has_window().
7539 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7544 gtk_widget_get_has_window (GtkWidget *widget)
7546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7548 return ! widget->priv->no_window;
7552 * gtk_widget_is_toplevel:
7553 * @widget: a #GtkWidget
7555 * Determines whether @widget is a toplevel widget.
7557 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7558 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7561 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7566 gtk_widget_is_toplevel (GtkWidget *widget)
7568 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7570 return widget->priv->toplevel;
7574 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7575 gboolean is_toplevel)
7577 widget->priv->toplevel = is_toplevel;
7581 * gtk_widget_is_drawable:
7582 * @widget: a #GtkWidget
7584 * Determines whether @widget can be drawn to. A widget can be drawn
7585 * to if it is mapped and visible.
7587 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7592 gtk_widget_is_drawable (GtkWidget *widget)
7594 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7596 return (gtk_widget_get_visible (widget) &&
7597 gtk_widget_get_mapped (widget));
7601 * gtk_widget_get_realized:
7602 * @widget: a #GtkWidget
7604 * Determines whether @widget is realized.
7606 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7611 gtk_widget_get_realized (GtkWidget *widget)
7613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7615 return widget->priv->realized;
7619 * gtk_widget_set_realized:
7620 * @widget: a #GtkWidget
7621 * @realized: %TRUE to mark the widget as realized
7623 * Marks the widget as being realized.
7625 * This function should only ever be called in a derived widget's
7626 * "realize" or "unrealize" implementation.
7631 gtk_widget_set_realized (GtkWidget *widget,
7634 g_return_if_fail (GTK_IS_WIDGET (widget));
7636 widget->priv->realized = realized;
7640 * gtk_widget_get_mapped:
7641 * @widget: a #GtkWidget
7643 * Whether the widget is mapped.
7645 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7650 gtk_widget_get_mapped (GtkWidget *widget)
7652 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7654 return widget->priv->mapped;
7658 * gtk_widget_set_mapped:
7659 * @widget: a #GtkWidget
7660 * @mapped: %TRUE to mark the widget as mapped
7662 * Marks the widget as being realized.
7664 * This function should only ever be called in a derived widget's
7665 * "map" or "unmap" implementation.
7670 gtk_widget_set_mapped (GtkWidget *widget,
7673 g_return_if_fail (GTK_IS_WIDGET (widget));
7675 widget->priv->mapped = mapped;
7679 * gtk_widget_set_app_paintable:
7680 * @widget: a #GtkWidget
7681 * @app_paintable: %TRUE if the application will paint on the widget
7683 * Sets whether the application intends to draw on the widget in
7684 * an #GtkWidget::draw handler.
7686 * This is a hint to the widget and does not affect the behavior of
7687 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7688 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7689 * the effect is to suppress default themed drawing of the widget's
7690 * background. (Children of the widget will still be drawn.) The application
7691 * is then entirely responsible for drawing the widget background.
7693 * Note that the background is still drawn when the widget is mapped.
7696 gtk_widget_set_app_paintable (GtkWidget *widget,
7697 gboolean app_paintable)
7699 g_return_if_fail (GTK_IS_WIDGET (widget));
7701 app_paintable = (app_paintable != FALSE);
7703 if (widget->priv->app_paintable != app_paintable)
7705 widget->priv->app_paintable = app_paintable;
7707 if (gtk_widget_is_drawable (widget))
7708 gtk_widget_queue_draw (widget);
7710 g_object_notify (G_OBJECT (widget), "app-paintable");
7715 * gtk_widget_get_app_paintable:
7716 * @widget: a #GtkWidget
7718 * Determines whether the application intends to draw on the widget in
7719 * an #GtkWidget::draw handler.
7721 * See gtk_widget_set_app_paintable()
7723 * Return value: %TRUE if the widget is app paintable
7728 gtk_widget_get_app_paintable (GtkWidget *widget)
7730 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7732 return widget->priv->app_paintable;
7736 * gtk_widget_set_double_buffered:
7737 * @widget: a #GtkWidget
7738 * @double_buffered: %TRUE to double-buffer a widget
7740 * Widgets are double buffered by default; you can use this function
7741 * to turn off the buffering. "Double buffered" simply means that
7742 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7743 * automatically around expose events sent to the
7744 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7745 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7746 * buffer to the screen. The result is that users see the window
7747 * update in one smooth step, and don't see individual graphics
7748 * primitives being rendered.
7750 * In very simple terms, double buffered widgets don't flicker,
7751 * so you would only use this function to turn off double buffering
7752 * if you had special needs and really knew what you were doing.
7754 * Note: if you turn off double-buffering, you have to handle
7755 * expose events, since even the clearing to the background color or
7756 * pixmap will not happen automatically (as it is done in
7757 * gdk_window_begin_paint_region()).
7760 gtk_widget_set_double_buffered (GtkWidget *widget,
7761 gboolean double_buffered)
7763 g_return_if_fail (GTK_IS_WIDGET (widget));
7765 double_buffered = (double_buffered != FALSE);
7767 if (widget->priv->double_buffered != double_buffered)
7769 widget->priv->double_buffered = double_buffered;
7771 g_object_notify (G_OBJECT (widget), "double-buffered");
7776 * gtk_widget_get_double_buffered:
7777 * @widget: a #GtkWidget
7779 * Determines whether the widget is double buffered.
7781 * See gtk_widget_set_double_buffered()
7783 * Return value: %TRUE if the widget is double buffered
7788 gtk_widget_get_double_buffered (GtkWidget *widget)
7790 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7792 return widget->priv->double_buffered;
7796 * gtk_widget_set_redraw_on_allocate:
7797 * @widget: a #GtkWidget
7798 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7799 * when it is allocated to a new size. Otherwise, only the
7800 * new portion of the widget will be redrawn.
7802 * Sets whether the entire widget is queued for drawing when its size
7803 * allocation changes. By default, this setting is %TRUE and
7804 * the entire widget is redrawn on every size change. If your widget
7805 * leaves the upper left unchanged when made bigger, turning this
7806 * setting off will improve performance.
7808 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7809 * off all allocation on resizing: the widget will not even redraw if
7810 * its position changes; this is to allow containers that don't draw
7811 * anything to avoid excess invalidations. If you set this flag on a
7812 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7813 * you are responsible for invalidating both the old and new allocation
7814 * of the widget when the widget is moved and responsible for invalidating
7815 * regions newly when the widget increases size.
7818 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7819 gboolean redraw_on_allocate)
7821 g_return_if_fail (GTK_IS_WIDGET (widget));
7823 widget->priv->redraw_on_alloc = redraw_on_allocate;
7827 * gtk_widget_set_sensitive:
7828 * @widget: a #GtkWidget
7829 * @sensitive: %TRUE to make the widget sensitive
7831 * Sets the sensitivity of a widget. A widget is sensitive if the user
7832 * can interact with it. Insensitive widgets are "grayed out" and the
7833 * user can't interact with them. Insensitive widgets are known as
7834 * "inactive", "disabled", or "ghosted" in some other toolkits.
7837 gtk_widget_set_sensitive (GtkWidget *widget,
7840 GtkWidgetPrivate *priv;
7842 g_return_if_fail (GTK_IS_WIDGET (widget));
7844 priv = widget->priv;
7846 sensitive = (sensitive != FALSE);
7848 if (priv->sensitive == sensitive)
7851 priv->sensitive = sensitive;
7853 if (priv->parent == NULL
7854 || gtk_widget_is_sensitive (priv->parent))
7858 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7861 data.operation = STATE_CHANGE_UNSET;
7863 data.operation = STATE_CHANGE_SET;
7865 gtk_widget_propagate_state (widget, &data);
7867 gtk_widget_queue_resize (widget);
7870 g_object_notify (G_OBJECT (widget), "sensitive");
7874 * gtk_widget_get_sensitive:
7875 * @widget: a #GtkWidget
7877 * Returns the widget's sensitivity (in the sense of returning
7878 * the value that has been set using gtk_widget_set_sensitive()).
7880 * The effective sensitivity of a widget is however determined by both its
7881 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7883 * Returns: %TRUE if the widget is sensitive
7888 gtk_widget_get_sensitive (GtkWidget *widget)
7890 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7892 return widget->priv->sensitive;
7896 * gtk_widget_is_sensitive:
7897 * @widget: a #GtkWidget
7899 * Returns the widget's effective sensitivity, which means
7900 * it is sensitive itself and also its parent widget is sensitive
7902 * Returns: %TRUE if the widget is effectively sensitive
7907 gtk_widget_is_sensitive (GtkWidget *widget)
7909 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7911 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7915 * gtk_widget_set_parent:
7916 * @widget: a #GtkWidget
7917 * @parent: parent container
7919 * This function is useful only when implementing subclasses of
7921 * Sets the container as the parent of @widget, and takes care of
7922 * some details such as updating the state and style of the child
7923 * to reflect its new location. The opposite function is
7924 * gtk_widget_unparent().
7927 gtk_widget_set_parent (GtkWidget *widget,
7930 GtkStateFlags parent_flags;
7931 GtkWidgetPrivate *priv;
7934 g_return_if_fail (GTK_IS_WIDGET (widget));
7935 g_return_if_fail (GTK_IS_WIDGET (parent));
7936 g_return_if_fail (widget != parent);
7938 priv = widget->priv;
7940 if (priv->parent != NULL)
7942 g_warning ("Can't set a parent on widget which has a parent\n");
7945 if (gtk_widget_is_toplevel (widget))
7947 g_warning ("Can't set a parent on a toplevel widget\n");
7951 /* keep this function in sync with gtk_menu_attach_to_widget()
7954 g_object_ref_sink (widget);
7956 gtk_widget_push_verify_invariants (widget);
7958 priv->parent = parent;
7960 parent_flags = gtk_widget_get_state_flags (parent);
7962 /* Merge both old state and current parent state,
7963 * making sure to only propagate the right states */
7964 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7965 data.flags |= priv->state_flags;
7967 data.operation = STATE_CHANGE_REPLACE;
7968 gtk_widget_propagate_state (widget, &data);
7971 gtk_style_context_set_parent (priv->context,
7972 gtk_widget_get_style_context (parent));
7974 _gtk_widget_update_parent_muxer (widget);
7976 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7977 if (priv->parent->priv->anchored)
7978 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7979 g_object_notify (G_OBJECT (widget), "parent");
7981 /* Enforce realized/mapped invariants
7983 if (gtk_widget_get_realized (priv->parent))
7984 gtk_widget_realize (widget);
7986 if (gtk_widget_get_visible (priv->parent) &&
7987 gtk_widget_get_visible (widget))
7989 if (gtk_widget_get_child_visible (widget) &&
7990 gtk_widget_get_mapped (priv->parent))
7991 gtk_widget_map (widget);
7993 gtk_widget_queue_resize (widget);
7996 /* child may cause parent's expand to change, if the child is
7997 * expanded. If child is not expanded, then it can't modify the
7998 * parent's expand. If the child becomes expanded later then it will
7999 * queue compute_expand then. This optimization plus defaulting
8000 * newly-constructed widgets to need_compute_expand=FALSE should
8001 * mean that initially building a widget tree doesn't have to keep
8002 * walking up setting need_compute_expand on parents over and over.
8004 * We can't change a parent to need to expand unless we're visible.
8006 if (gtk_widget_get_visible (widget) &&
8007 (priv->need_compute_expand ||
8008 priv->computed_hexpand ||
8009 priv->computed_vexpand))
8011 gtk_widget_queue_compute_expand (parent);
8014 gtk_widget_pop_verify_invariants (widget);
8018 * gtk_widget_get_parent:
8019 * @widget: a #GtkWidget
8021 * Returns the parent container of @widget.
8023 * Return value: (transfer none): the parent container of @widget, or %NULL
8026 gtk_widget_get_parent (GtkWidget *widget)
8028 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8030 return widget->priv->parent;
8034 modifier_style_changed (GtkModifierStyle *style,
8037 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8040 static GtkModifierStyle *
8041 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8043 GtkModifierStyle *style;
8045 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8047 if (G_UNLIKELY (!style))
8049 GtkStyleContext *context;
8051 style = _gtk_modifier_style_new ();
8052 g_object_set_qdata_full (G_OBJECT (widget),
8053 quark_modifier_style,
8055 (GDestroyNotify) g_object_unref);
8057 g_signal_connect (style, "changed",
8058 G_CALLBACK (modifier_style_changed), widget);
8060 context = gtk_widget_get_style_context (widget);
8062 gtk_style_context_add_provider (context,
8063 GTK_STYLE_PROVIDER (style),
8064 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8071 * gtk_widget_override_color:
8072 * @widget: a #GtkWidget
8073 * @state: the state for which to set the color
8074 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8075 * of previous calls to gtk_widget_override_color()
8077 * Sets the color to use for a widget.
8079 * All other style values are left untouched.
8082 * This API is mostly meant as a quick way for applications to
8083 * change a widget appearance. If you are developing a widgets
8084 * library and intend this change to be themeable, it is better
8085 * done by setting meaningful CSS classes and regions in your
8086 * widget/container implementation through gtk_style_context_add_class()
8087 * and gtk_style_context_add_region().
8089 * This way, your widget library can install a #GtkCssProvider
8090 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8091 * to provide a default styling for those widgets that need so, and
8092 * this theming may fully overridden by the user's theme.
8095 * Note that for complex widgets this may bring in undesired
8096 * results (such as uniform background color everywhere), in
8097 * these cases it is better to fully style such widgets through a
8098 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8105 gtk_widget_override_color (GtkWidget *widget,
8106 GtkStateFlags state,
8107 const GdkRGBA *color)
8109 GtkModifierStyle *style;
8111 g_return_if_fail (GTK_IS_WIDGET (widget));
8113 style = _gtk_widget_get_modifier_properties (widget);
8114 _gtk_modifier_style_set_color (style, state, color);
8118 * gtk_widget_override_background_color:
8119 * @widget: a #GtkWidget
8120 * @state: the state for which to set the background color
8121 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8122 * of previous calls to gtk_widget_override_background_color()
8124 * Sets the background color to use for a widget.
8126 * All other style values are left untouched.
8127 * See gtk_widget_override_color().
8132 gtk_widget_override_background_color (GtkWidget *widget,
8133 GtkStateFlags state,
8134 const GdkRGBA *color)
8136 GtkModifierStyle *style;
8138 g_return_if_fail (GTK_IS_WIDGET (widget));
8140 style = _gtk_widget_get_modifier_properties (widget);
8141 _gtk_modifier_style_set_background_color (style, state, color);
8145 * gtk_widget_override_font:
8146 * @widget: a #GtkWidget
8147 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8148 * the effect of previous calls to gtk_widget_override_font()
8150 * Sets the font to use for a widget. All other style values are
8151 * left untouched. See gtk_widget_override_color().
8156 gtk_widget_override_font (GtkWidget *widget,
8157 const PangoFontDescription *font_desc)
8159 GtkModifierStyle *style;
8161 g_return_if_fail (GTK_IS_WIDGET (widget));
8163 style = _gtk_widget_get_modifier_properties (widget);
8164 _gtk_modifier_style_set_font (style, font_desc);
8168 * gtk_widget_override_symbolic_color:
8169 * @widget: a #GtkWidget
8170 * @name: the name of the symbolic color to modify
8171 * @color: (allow-none): the color to assign (does not need
8172 * to be allocated), or %NULL to undo the effect of previous
8173 * calls to gtk_widget_override_symbolic_color()
8175 * Sets a symbolic color for a widget.
8177 * All other style values are left untouched.
8178 * See gtk_widget_override_color() for overriding the foreground
8179 * or background color.
8184 gtk_widget_override_symbolic_color (GtkWidget *widget,
8186 const GdkRGBA *color)
8188 GtkModifierStyle *style;
8190 g_return_if_fail (GTK_IS_WIDGET (widget));
8192 style = _gtk_widget_get_modifier_properties (widget);
8193 _gtk_modifier_style_map_color (style, name, color);
8197 * gtk_widget_override_cursor:
8198 * @widget: a #GtkWidget
8199 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8200 * allocated), or %NULL to undo the effect of previous calls to
8201 * of gtk_widget_override_cursor().
8202 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8203 * need to be allocated), or %NULL to undo the effect of previous
8204 * calls to of gtk_widget_override_cursor().
8206 * Sets the cursor color to use in a widget, overriding the
8207 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8208 * style properties. All other style values are left untouched.
8209 * See also gtk_widget_modify_style().
8211 * Note that the underlying properties have the #GdkColor type,
8212 * so the alpha value in @primary and @secondary will be ignored.
8217 gtk_widget_override_cursor (GtkWidget *widget,
8218 const GdkRGBA *cursor,
8219 const GdkRGBA *secondary_cursor)
8221 GtkModifierStyle *style;
8223 g_return_if_fail (GTK_IS_WIDGET (widget));
8225 style = _gtk_widget_get_modifier_properties (widget);
8226 _gtk_modifier_style_set_color_property (style,
8228 "cursor-color", cursor);
8229 _gtk_modifier_style_set_color_property (style,
8231 "secondary-cursor-color",
8236 gtk_widget_real_direction_changed (GtkWidget *widget,
8237 GtkTextDirection previous_direction)
8239 gtk_widget_queue_resize (widget);
8243 gtk_widget_real_style_set (GtkWidget *widget,
8244 GtkStyle *previous_style)
8249 GtkWidget *previous_toplevel;
8250 GdkScreen *previous_screen;
8251 GdkScreen *new_screen;
8252 } HierarchyChangedInfo;
8255 do_screen_change (GtkWidget *widget,
8256 GdkScreen *old_screen,
8257 GdkScreen *new_screen)
8259 if (old_screen != new_screen)
8261 GtkWidgetPrivate *priv = widget->priv;
8265 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8267 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8270 _gtk_tooltip_hide (widget);
8272 if (new_screen && priv->context)
8273 gtk_style_context_set_screen (priv->context, new_screen);
8275 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8280 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8281 gpointer client_data)
8283 GtkWidgetPrivate *priv = widget->priv;
8284 HierarchyChangedInfo *info = client_data;
8285 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8286 (priv->parent && priv->parent->priv->anchored);
8288 if (priv->anchored != new_anchored)
8290 g_object_ref (widget);
8292 priv->anchored = new_anchored;
8294 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8295 do_screen_change (widget, info->previous_screen, info->new_screen);
8297 if (GTK_IS_CONTAINER (widget))
8298 gtk_container_forall (GTK_CONTAINER (widget),
8299 gtk_widget_propagate_hierarchy_changed_recurse,
8302 g_object_unref (widget);
8307 * _gtk_widget_propagate_hierarchy_changed:
8308 * @widget: a #GtkWidget
8309 * @previous_toplevel: Previous toplevel
8311 * Propagates changes in the anchored state to a widget and all
8312 * children, unsetting or setting the %ANCHORED flag, and
8313 * emitting #GtkWidget::hierarchy-changed.
8316 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8317 GtkWidget *previous_toplevel)
8319 GtkWidgetPrivate *priv = widget->priv;
8320 HierarchyChangedInfo info;
8322 info.previous_toplevel = previous_toplevel;
8323 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8325 if (gtk_widget_is_toplevel (widget) ||
8326 (priv->parent && priv->parent->priv->anchored))
8327 info.new_screen = gtk_widget_get_screen (widget);
8329 info.new_screen = NULL;
8331 if (info.previous_screen)
8332 g_object_ref (info.previous_screen);
8333 if (previous_toplevel)
8334 g_object_ref (previous_toplevel);
8336 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8338 if (previous_toplevel)
8339 g_object_unref (previous_toplevel);
8340 if (info.previous_screen)
8341 g_object_unref (info.previous_screen);
8345 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8346 gpointer client_data)
8348 HierarchyChangedInfo *info = client_data;
8350 g_object_ref (widget);
8352 do_screen_change (widget, info->previous_screen, info->new_screen);
8354 if (GTK_IS_CONTAINER (widget))
8355 gtk_container_forall (GTK_CONTAINER (widget),
8356 gtk_widget_propagate_screen_changed_recurse,
8359 g_object_unref (widget);
8363 * gtk_widget_is_composited:
8364 * @widget: a #GtkWidget
8366 * Whether @widget can rely on having its alpha channel
8367 * drawn correctly. On X11 this function returns whether a
8368 * compositing manager is running for @widget's screen.
8370 * Please note that the semantics of this call will change
8371 * in the future if used on a widget that has a composited
8372 * window in its hierarchy (as set by gdk_window_set_composited()).
8374 * Return value: %TRUE if the widget can rely on its alpha
8375 * channel being drawn correctly.
8380 gtk_widget_is_composited (GtkWidget *widget)
8384 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8386 screen = gtk_widget_get_screen (widget);
8388 return gdk_screen_is_composited (screen);
8392 propagate_composited_changed (GtkWidget *widget,
8395 if (GTK_IS_CONTAINER (widget))
8397 gtk_container_forall (GTK_CONTAINER (widget),
8398 propagate_composited_changed,
8402 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8406 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8408 propagate_composited_changed (widget, NULL);
8412 * _gtk_widget_propagate_screen_changed:
8413 * @widget: a #GtkWidget
8414 * @previous_screen: Previous screen
8416 * Propagates changes in the screen for a widget to all
8417 * children, emitting #GtkWidget::screen-changed.
8420 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8421 GdkScreen *previous_screen)
8423 HierarchyChangedInfo info;
8425 info.previous_screen = previous_screen;
8426 info.new_screen = gtk_widget_get_screen (widget);
8428 if (previous_screen)
8429 g_object_ref (previous_screen);
8431 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8433 if (previous_screen)
8434 g_object_unref (previous_screen);
8438 reset_style_recurse (GtkWidget *widget, gpointer data)
8440 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8442 if (GTK_IS_CONTAINER (widget))
8443 gtk_container_forall (GTK_CONTAINER (widget),
8444 reset_style_recurse,
8449 * gtk_widget_reset_style:
8450 * @widget: a #GtkWidget
8452 * Updates the style context of @widget and all descendents
8453 * by updating its widget path. #GtkContainer<!-- -->s may want
8454 * to use this on a child when reordering it in a way that a different
8455 * style might apply to it. See also gtk_container_get_path_for_child().
8460 gtk_widget_reset_style (GtkWidget *widget)
8462 g_return_if_fail (GTK_IS_WIDGET (widget));
8464 reset_style_recurse (widget, NULL);
8466 g_list_foreach (widget->priv->attached_windows,
8467 (GFunc) reset_style_recurse, NULL);
8470 #ifdef G_ENABLE_DEBUG
8472 /* Verify invariants, see docs/widget_system.txt for notes on much of
8473 * this. Invariants may be temporarily broken while we're in the
8474 * process of updating state, of course, so you can only
8475 * verify_invariants() after a given operation is complete.
8476 * Use push/pop_verify_invariants to help with that.
8479 gtk_widget_verify_invariants (GtkWidget *widget)
8483 if (widget->priv->verifying_invariants_count > 0)
8486 parent = widget->priv->parent;
8488 if (widget->priv->mapped)
8490 /* Mapped implies ... */
8492 if (!widget->priv->realized)
8493 g_warning ("%s %p is mapped but not realized",
8494 G_OBJECT_TYPE_NAME (widget), widget);
8496 if (!widget->priv->visible)
8497 g_warning ("%s %p is mapped but not visible",
8498 G_OBJECT_TYPE_NAME (widget), widget);
8500 if (!widget->priv->toplevel)
8502 if (!widget->priv->child_visible)
8503 g_warning ("%s %p is mapped but not child_visible",
8504 G_OBJECT_TYPE_NAME (widget), widget);
8509 /* Not mapped implies... */
8512 /* This check makes sense for normal toplevels, but for
8513 * something like a toplevel that is embedded within a clutter
8514 * state, mapping may depend on external factors.
8516 if (widget->priv->toplevel)
8518 if (widget->priv->visible)
8519 g_warning ("%s %p toplevel is visible but not mapped",
8520 G_OBJECT_TYPE_NAME (widget), widget);
8525 /* Parent related checks aren't possible if parent has
8526 * verifying_invariants_count > 0 because parent needs to recurse
8527 * children first before the invariants will hold.
8529 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8532 parent->priv->realized)
8534 /* Parent realized implies... */
8537 /* This is in widget_system.txt but appears to fail
8538 * because there's no gtk_container_realize() that
8539 * realizes all children... instead we just lazily
8540 * wait for map to fix things up.
8542 if (!widget->priv->realized)
8543 g_warning ("%s %p is realized but child %s %p is not realized",
8544 G_OBJECT_TYPE_NAME (parent), parent,
8545 G_OBJECT_TYPE_NAME (widget), widget);
8548 else if (!widget->priv->toplevel)
8550 /* No parent or parent not realized on non-toplevel implies... */
8552 if (widget->priv->realized && !widget->priv->in_reparent)
8553 g_warning ("%s %p is not realized but child %s %p is realized",
8554 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8555 G_OBJECT_TYPE_NAME (widget), widget);
8559 parent->priv->mapped &&
8560 widget->priv->visible &&
8561 widget->priv->child_visible)
8563 /* Parent mapped and we are visible implies... */
8565 if (!widget->priv->mapped)
8566 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8567 G_OBJECT_TYPE_NAME (parent), parent,
8568 G_OBJECT_TYPE_NAME (widget), widget);
8570 else if (!widget->priv->toplevel)
8572 /* No parent or parent not mapped on non-toplevel implies... */
8574 if (widget->priv->mapped && !widget->priv->in_reparent)
8575 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8576 G_OBJECT_TYPE_NAME (widget), widget,
8577 widget->priv->visible,
8578 widget->priv->child_visible,
8579 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8580 parent ? parent->priv->mapped : FALSE);
8584 if (!widget->priv->realized)
8586 /* Not realized implies... */
8589 /* widget_system.txt says these hold, but they don't. */
8590 if (widget->priv->alloc_needed)
8591 g_warning ("%s %p alloc needed but not realized",
8592 G_OBJECT_TYPE_NAME (widget), widget);
8594 if (widget->priv->width_request_needed)
8595 g_warning ("%s %p width request needed but not realized",
8596 G_OBJECT_TYPE_NAME (widget), widget);
8598 if (widget->priv->height_request_needed)
8599 g_warning ("%s %p height request needed but not realized",
8600 G_OBJECT_TYPE_NAME (widget), widget);
8605 /* The point of this push/pop is that invariants may not hold while
8606 * we're busy making changes. So we only check at the outermost call
8607 * on the call stack, after we finish updating everything.
8610 gtk_widget_push_verify_invariants (GtkWidget *widget)
8612 widget->priv->verifying_invariants_count += 1;
8616 gtk_widget_verify_child_invariants (GtkWidget *widget,
8617 gpointer client_data)
8619 /* We don't recurse further; this is a one-level check. */
8620 gtk_widget_verify_invariants (widget);
8624 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8626 g_assert (widget->priv->verifying_invariants_count > 0);
8628 widget->priv->verifying_invariants_count -= 1;
8630 if (widget->priv->verifying_invariants_count == 0)
8632 gtk_widget_verify_invariants (widget);
8634 if (GTK_IS_CONTAINER (widget))
8636 /* Check one level of children, because our
8637 * push_verify_invariants() will have prevented some of the
8638 * checks. This does not recurse because if recursion is
8639 * needed, it will happen naturally as each child has a
8640 * push/pop on that child. For example if we're recursively
8641 * mapping children, we'll push/pop on each child as we map
8644 gtk_container_forall (GTK_CONTAINER (widget),
8645 gtk_widget_verify_child_invariants,
8650 #endif /* G_ENABLE_DEBUG */
8652 static PangoContext *
8653 gtk_widget_peek_pango_context (GtkWidget *widget)
8655 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8659 * gtk_widget_get_pango_context:
8660 * @widget: a #GtkWidget
8662 * Gets a #PangoContext with the appropriate font map, font description,
8663 * and base direction for this widget. Unlike the context returned
8664 * by gtk_widget_create_pango_context(), this context is owned by
8665 * the widget (it can be used until the screen for the widget changes
8666 * or the widget is removed from its toplevel), and will be updated to
8667 * match any changes to the widget's attributes.
8669 * If you create and keep a #PangoLayout using this context, you must
8670 * deal with changes to the context by calling pango_layout_context_changed()
8671 * on the layout in response to the #GtkWidget::style-updated and
8672 * #GtkWidget::direction-changed signals for the widget.
8674 * Return value: (transfer none): the #PangoContext for the widget.
8677 gtk_widget_get_pango_context (GtkWidget *widget)
8679 PangoContext *context;
8681 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8683 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8686 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8687 g_object_set_qdata_full (G_OBJECT (widget),
8688 quark_pango_context,
8697 update_pango_context (GtkWidget *widget,
8698 PangoContext *context)
8700 const PangoFontDescription *font_desc;
8701 GtkStyleContext *style_context;
8703 style_context = gtk_widget_get_style_context (widget);
8705 font_desc = gtk_style_context_get_font (style_context,
8706 gtk_widget_get_state_flags (widget));
8708 pango_context_set_font_description (context, font_desc);
8709 pango_context_set_base_dir (context,
8710 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8711 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8715 gtk_widget_update_pango_context (GtkWidget *widget)
8717 PangoContext *context = gtk_widget_peek_pango_context (widget);
8723 update_pango_context (widget, context);
8725 screen = gtk_widget_get_screen_unchecked (widget);
8728 pango_cairo_context_set_resolution (context,
8729 gdk_screen_get_resolution (screen));
8730 pango_cairo_context_set_font_options (context,
8731 gdk_screen_get_font_options (screen));
8737 * gtk_widget_create_pango_context:
8738 * @widget: a #GtkWidget
8740 * Creates a new #PangoContext with the appropriate font map,
8741 * font description, and base direction for drawing text for
8742 * this widget. See also gtk_widget_get_pango_context().
8744 * Return value: (transfer full): the new #PangoContext
8747 gtk_widget_create_pango_context (GtkWidget *widget)
8750 PangoContext *context;
8752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8754 screen = gtk_widget_get_screen_unchecked (widget);
8757 GTK_NOTE (MULTIHEAD,
8758 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8760 screen = gdk_screen_get_default ();
8763 context = gdk_pango_context_get_for_screen (screen);
8765 update_pango_context (widget, context);
8766 pango_context_set_language (context, gtk_get_default_language ());
8772 * gtk_widget_create_pango_layout:
8773 * @widget: a #GtkWidget
8774 * @text: text to set on the layout (can be %NULL)
8776 * Creates a new #PangoLayout with the appropriate font map,
8777 * font description, and base direction for drawing text for
8780 * If you keep a #PangoLayout created in this way around, in order to
8781 * notify the layout of changes to the base direction or font of this
8782 * widget, you must call pango_layout_context_changed() in response to
8783 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8786 * Return value: (transfer full): the new #PangoLayout
8789 gtk_widget_create_pango_layout (GtkWidget *widget,
8792 PangoLayout *layout;
8793 PangoContext *context;
8795 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8797 context = gtk_widget_get_pango_context (widget);
8798 layout = pango_layout_new (context);
8801 pango_layout_set_text (layout, text, -1);
8807 * gtk_widget_render_icon_pixbuf:
8808 * @widget: a #GtkWidget
8809 * @stock_id: a stock ID
8810 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8811 * render at the size of the source and don't scale (if there are
8812 * multiple source sizes, GTK+ picks one of the available sizes).
8814 * A convenience function that uses the theme engine and style
8815 * settings for @widget to look up @stock_id and render it to
8816 * a pixbuf. @stock_id should be a stock icon ID such as
8817 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8818 * such as #GTK_ICON_SIZE_MENU.
8820 * The pixels in the returned #GdkPixbuf are shared with the rest of
8821 * the application and should not be modified. The pixbuf should be freed
8822 * after use with g_object_unref().
8824 * Return value: (transfer full): a new pixbuf, or %NULL if the
8825 * stock ID wasn't known
8830 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8831 const gchar *stock_id,
8834 GtkStyleContext *context;
8835 GtkIconSet *icon_set;
8837 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8838 g_return_val_if_fail (stock_id != NULL, NULL);
8839 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8841 context = gtk_widget_get_style_context (widget);
8842 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8844 if (icon_set == NULL)
8847 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8851 * gtk_widget_set_parent_window:
8852 * @widget: a #GtkWidget.
8853 * @parent_window: the new parent window.
8855 * Sets a non default parent window for @widget.
8857 * For GtkWindow classes, setting a @parent_window effects whether
8858 * the window is a toplevel window or can be embedded into other
8862 * For GtkWindow classes, this needs to be called before the
8863 * window is realized.
8868 gtk_widget_set_parent_window (GtkWidget *widget,
8869 GdkWindow *parent_window)
8871 GdkWindow *old_parent_window;
8873 g_return_if_fail (GTK_IS_WIDGET (widget));
8875 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8876 quark_parent_window);
8878 if (parent_window != old_parent_window)
8882 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8884 if (old_parent_window)
8885 g_object_unref (old_parent_window);
8887 g_object_ref (parent_window);
8889 /* Unset toplevel flag when adding a parent window to a widget,
8890 * this is the primary entry point to allow toplevels to be
8893 #ifdef GDK_WINDOWING_X11
8894 is_plug = GTK_IS_PLUG (widget);
8898 if (GTK_IS_WINDOW (widget) && !is_plug)
8899 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8904 * gtk_widget_get_parent_window:
8905 * @widget: a #GtkWidget.
8907 * Gets @widget's parent window.
8909 * Returns: (transfer none): the parent window of @widget.
8912 gtk_widget_get_parent_window (GtkWidget *widget)
8914 GtkWidgetPrivate *priv;
8915 GdkWindow *parent_window;
8917 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8919 priv = widget->priv;
8921 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8923 return (parent_window != NULL) ? parent_window :
8924 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8929 * gtk_widget_set_child_visible:
8930 * @widget: a #GtkWidget
8931 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8933 * Sets whether @widget should be mapped along with its when its parent
8934 * is mapped and @widget has been shown with gtk_widget_show().
8936 * The child visibility can be set for widget before it is added to
8937 * a container with gtk_widget_set_parent(), to avoid mapping
8938 * children unnecessary before immediately unmapping them. However
8939 * it will be reset to its default state of %TRUE when the widget
8940 * is removed from a container.
8942 * Note that changing the child visibility of a widget does not
8943 * queue a resize on the widget. Most of the time, the size of
8944 * a widget is computed from all visible children, whether or
8945 * not they are mapped. If this is not the case, the container
8946 * can queue a resize itself.
8948 * This function is only useful for container implementations and
8949 * never should be called by an application.
8952 gtk_widget_set_child_visible (GtkWidget *widget,
8953 gboolean is_visible)
8955 GtkWidgetPrivate *priv;
8957 g_return_if_fail (GTK_IS_WIDGET (widget));
8958 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8960 priv = widget->priv;
8962 g_object_ref (widget);
8963 gtk_widget_verify_invariants (widget);
8966 priv->child_visible = TRUE;
8969 GtkWidget *toplevel;
8971 priv->child_visible = FALSE;
8973 toplevel = gtk_widget_get_toplevel (widget);
8974 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8975 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8978 if (priv->parent && gtk_widget_get_realized (priv->parent))
8980 if (gtk_widget_get_mapped (priv->parent) &&
8981 priv->child_visible &&
8982 gtk_widget_get_visible (widget))
8983 gtk_widget_map (widget);
8985 gtk_widget_unmap (widget);
8988 gtk_widget_verify_invariants (widget);
8989 g_object_unref (widget);
8993 * gtk_widget_get_child_visible:
8994 * @widget: a #GtkWidget
8996 * Gets the value set with gtk_widget_set_child_visible().
8997 * If you feel a need to use this function, your code probably
8998 * needs reorganization.
9000 * This function is only useful for container implementations and
9001 * never should be called by an application.
9003 * Return value: %TRUE if the widget is mapped with the parent.
9006 gtk_widget_get_child_visible (GtkWidget *widget)
9008 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9010 return widget->priv->child_visible;
9014 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9016 GtkWidget *toplevel;
9018 toplevel = gtk_widget_get_toplevel (widget);
9020 if (gtk_widget_is_toplevel (toplevel))
9022 if (GTK_IS_WINDOW (toplevel))
9023 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9024 else if (GTK_IS_INVISIBLE (toplevel))
9025 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9032 * gtk_widget_get_screen:
9033 * @widget: a #GtkWidget
9035 * Get the #GdkScreen from the toplevel window associated with
9036 * this widget. This function can only be called after the widget
9037 * has been added to a widget hierarchy with a #GtkWindow
9040 * In general, you should only create screen specific
9041 * resources when a widget has been realized, and you should
9042 * free those resources when the widget is unrealized.
9044 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9049 gtk_widget_get_screen (GtkWidget *widget)
9053 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9055 screen = gtk_widget_get_screen_unchecked (widget);
9062 g_warning (G_STRLOC ": Can't get associated screen"
9063 " for a widget unless it is inside a toplevel GtkWindow\n"
9064 " widget type is %s associated top level type is %s",
9065 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9066 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9068 return gdk_screen_get_default ();
9073 * gtk_widget_has_screen:
9074 * @widget: a #GtkWidget
9076 * Checks whether there is a #GdkScreen is associated with
9077 * this widget. All toplevel widgets have an associated
9078 * screen, and all widgets added into a hierarchy with a toplevel
9079 * window at the top.
9081 * Return value: %TRUE if there is a #GdkScreen associcated
9087 gtk_widget_has_screen (GtkWidget *widget)
9089 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9091 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9095 * gtk_widget_get_display:
9096 * @widget: a #GtkWidget
9098 * Get the #GdkDisplay for the toplevel window associated with
9099 * this widget. This function can only be called after the widget
9100 * has been added to a widget hierarchy with a #GtkWindow at the top.
9102 * In general, you should only create display specific
9103 * resources when a widget has been realized, and you should
9104 * free those resources when the widget is unrealized.
9106 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9111 gtk_widget_get_display (GtkWidget *widget)
9113 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9115 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9119 * gtk_widget_get_root_window:
9120 * @widget: a #GtkWidget
9122 * Get the root window where this widget is located. This function can
9123 * only be called after the widget has been added to a widget
9124 * hierarchy with #GtkWindow at the top.
9126 * The root window is useful for such purposes as creating a popup
9127 * #GdkWindow associated with the window. In general, you should only
9128 * create display specific resources when a widget has been realized,
9129 * and you should free those resources when the widget is unrealized.
9131 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9136 gtk_widget_get_root_window (GtkWidget *widget)
9138 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9140 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9144 * gtk_widget_child_focus:
9145 * @widget: a #GtkWidget
9146 * @direction: direction of focus movement
9148 * This function is used by custom widget implementations; if you're
9149 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9150 * to a particular widget, and gtk_container_set_focus_chain() to
9151 * change the focus tab order. So you may want to investigate those
9152 * functions instead.
9154 * gtk_widget_child_focus() is called by containers as the user moves
9155 * around the window using keyboard shortcuts. @direction indicates
9156 * what kind of motion is taking place (up, down, left, right, tab
9157 * forward, tab backward). gtk_widget_child_focus() emits the
9158 * #GtkWidget::focus signal; widgets override the default handler
9159 * for this signal in order to implement appropriate focus behavior.
9161 * The default ::focus handler for a widget should return %TRUE if
9162 * moving in @direction left the focus on a focusable location inside
9163 * that widget, and %FALSE if moving in @direction moved the focus
9164 * outside the widget. If returning %TRUE, widgets normally
9165 * call gtk_widget_grab_focus() to place the focus accordingly;
9166 * if returning %FALSE, they don't modify the current focus location.
9168 * Return value: %TRUE if focus ended up inside @widget
9171 gtk_widget_child_focus (GtkWidget *widget,
9172 GtkDirectionType direction)
9174 gboolean return_val;
9176 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9178 if (!gtk_widget_get_visible (widget) ||
9179 !gtk_widget_is_sensitive (widget))
9182 /* child widgets must set CAN_FOCUS, containers
9183 * don't have to though.
9185 if (!GTK_IS_CONTAINER (widget) &&
9186 !gtk_widget_get_can_focus (widget))
9189 g_signal_emit (widget,
9190 widget_signals[FOCUS],
9192 direction, &return_val);
9198 * gtk_widget_keynav_failed:
9199 * @widget: a #GtkWidget
9200 * @direction: direction of focus movement
9202 * This function should be called whenever keyboard navigation within
9203 * a single widget hits a boundary. The function emits the
9204 * #GtkWidget::keynav-failed signal on the widget and its return
9205 * value should be interpreted in a way similar to the return value of
9206 * gtk_widget_child_focus():
9208 * When %TRUE is returned, stay in the widget, the failed keyboard
9209 * navigation is Ok and/or there is nowhere we can/should move the
9212 * When %FALSE is returned, the caller should continue with keyboard
9213 * navigation outside the widget, e.g. by calling
9214 * gtk_widget_child_focus() on the widget's toplevel.
9216 * The default ::keynav-failed handler returns %TRUE for
9217 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9218 * values of #GtkDirectionType, it looks at the
9219 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9220 * if the setting is %TRUE. This way the entire user interface
9221 * becomes cursor-navigatable on input devices such as mobile phones
9222 * which only have cursor keys but no tab key.
9224 * Whenever the default handler returns %TRUE, it also calls
9225 * gtk_widget_error_bell() to notify the user of the failed keyboard
9228 * A use case for providing an own implementation of ::keynav-failed
9229 * (either by connecting to it or by overriding it) would be a row of
9230 * #GtkEntry widgets where the user should be able to navigate the
9231 * entire row with the cursor keys, as e.g. known from user interfaces
9232 * that require entering license keys.
9234 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9235 * if the emitting widget should try to handle the keyboard
9236 * navigation attempt in its parent container(s).
9241 gtk_widget_keynav_failed (GtkWidget *widget,
9242 GtkDirectionType direction)
9244 gboolean return_val;
9246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9248 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9249 direction, &return_val);
9255 * gtk_widget_error_bell:
9256 * @widget: a #GtkWidget
9258 * Notifies the user about an input-related error on this widget.
9259 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9260 * gdk_window_beep(), otherwise it does nothing.
9262 * Note that the effect of gdk_window_beep() can be configured in many
9263 * ways, depending on the windowing backend and the desktop environment
9264 * or window manager that is used.
9269 gtk_widget_error_bell (GtkWidget *widget)
9271 GtkWidgetPrivate *priv;
9272 GtkSettings* settings;
9275 g_return_if_fail (GTK_IS_WIDGET (widget));
9277 priv = widget->priv;
9279 settings = gtk_widget_get_settings (widget);
9283 g_object_get (settings,
9284 "gtk-error-bell", &beep,
9287 if (beep && priv->window)
9288 gdk_window_beep (priv->window);
9292 gtk_widget_set_usize_internal (GtkWidget *widget,
9295 GtkQueueResizeFlags flags)
9297 GtkWidgetAuxInfo *aux_info;
9298 gboolean changed = FALSE;
9300 g_object_freeze_notify (G_OBJECT (widget));
9302 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9304 if (width > -2 && aux_info->width != width)
9306 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9307 g_object_notify (G_OBJECT (widget), "width-request");
9308 aux_info->width = width;
9311 if (height > -2 && aux_info->height != height)
9313 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9314 g_object_notify (G_OBJECT (widget), "height-request");
9315 aux_info->height = height;
9319 if (gtk_widget_get_visible (widget) && changed)
9321 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9322 gtk_widget_queue_resize (widget);
9324 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9327 g_object_thaw_notify (G_OBJECT (widget));
9331 * gtk_widget_set_size_request:
9332 * @widget: a #GtkWidget
9333 * @width: width @widget should request, or -1 to unset
9334 * @height: height @widget should request, or -1 to unset
9336 * Sets the minimum size of a widget; that is, the widget's size
9337 * request will be @width by @height. You can use this function to
9338 * force a widget to be either larger or smaller than it normally
9341 * In most cases, gtk_window_set_default_size() is a better choice for
9342 * toplevel windows than this function; setting the default size will
9343 * still allow users to shrink the window. Setting the size request
9344 * will force them to leave the window at least as large as the size
9345 * request. When dealing with window sizes,
9346 * gtk_window_set_geometry_hints() can be a useful function as well.
9348 * Note the inherent danger of setting any fixed size - themes,
9349 * translations into other languages, different fonts, and user action
9350 * can all change the appropriate size for a given widget. So, it's
9351 * basically impossible to hardcode a size that will always be
9354 * The size request of a widget is the smallest size a widget can
9355 * accept while still functioning well and drawing itself correctly.
9356 * However in some strange cases a widget may be allocated less than
9357 * its requested size, and in many cases a widget may be allocated more
9358 * space than it requested.
9360 * If the size request in a given direction is -1 (unset), then
9361 * the "natural" size request of the widget will be used instead.
9363 * Widgets can't actually be allocated a size less than 1 by 1, but
9364 * you can pass 0,0 to this function to mean "as small as possible."
9366 * The size request set here does not include any margin from the
9367 * #GtkWidget properties margin-left, margin-right, margin-top, and
9368 * margin-bottom, but it does include pretty much all other padding
9369 * or border properties set by any subclass of #GtkWidget.
9372 gtk_widget_set_size_request (GtkWidget *widget,
9376 g_return_if_fail (GTK_IS_WIDGET (widget));
9377 g_return_if_fail (width >= -1);
9378 g_return_if_fail (height >= -1);
9385 gtk_widget_set_usize_internal (widget, width, height, 0);
9390 * gtk_widget_get_size_request:
9391 * @widget: a #GtkWidget
9392 * @width: (out) (allow-none): return location for width, or %NULL
9393 * @height: (out) (allow-none): return location for height, or %NULL
9395 * Gets the size request that was explicitly set for the widget using
9396 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9397 * @height indicates that that dimension has not been set explicitly
9398 * and the natural requisition of the widget will be used intead. See
9399 * gtk_widget_set_size_request(). To get the size a widget will
9400 * actually request, call gtk_widget_get_preferred_size() instead of
9404 gtk_widget_get_size_request (GtkWidget *widget,
9408 const GtkWidgetAuxInfo *aux_info;
9410 g_return_if_fail (GTK_IS_WIDGET (widget));
9412 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9415 *width = aux_info->width;
9418 *height = aux_info->height;
9422 * _gtk_widget_override_size_request:
9423 * @widget: a #GtkWidget
9424 * @width: new forced minimum width
9425 * @height: new forced minimum height
9426 * @old_width: location to store previous forced minimum width
9427 * @old_height: location to store previous forced minumum height
9429 * Temporarily establishes a forced minimum size for a widget; this
9430 * is used by GtkWindow when calculating the size to add to the
9431 * window's geometry widget. Cached sizes for the widget and its
9432 * parents are invalidated, so that subsequent calls to the size
9433 * negotiation machinery produce the overriden result, but the
9434 * widget is not queued for relayout or redraw. The old size must
9435 * be restored with _gtk_widget_restore_size_request() or things
9439 _gtk_widget_override_size_request (GtkWidget *widget,
9445 gtk_widget_get_size_request (widget, old_width, old_height);
9446 gtk_widget_set_usize_internal (widget, width, height,
9447 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9451 * _gtk_widget_restore_size_request:
9452 * @widget: a #GtkWidget
9453 * @old_width: saved forced minimum size
9454 * @old_height: saved forced minimum size
9456 * Undoes the operation of_gtk_widget_override_size_request().
9459 _gtk_widget_restore_size_request (GtkWidget *widget,
9463 gtk_widget_set_usize_internal (widget, old_width, old_height,
9464 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9468 * gtk_widget_set_events:
9469 * @widget: a #GtkWidget
9470 * @events: event mask
9472 * Sets the event mask (see #GdkEventMask) for a widget. The event
9473 * mask determines which events a widget will receive. Keep in mind
9474 * that different widgets have different default event masks, and by
9475 * changing the event mask you may disrupt a widget's functionality,
9476 * so be careful. This function must be called while a widget is
9477 * unrealized. Consider gtk_widget_add_events() for widgets that are
9478 * already realized, or if you want to preserve the existing event
9479 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9480 * to get events on those widgets, place them inside a #GtkEventBox
9481 * and receive events on the event box.
9484 gtk_widget_set_events (GtkWidget *widget,
9487 g_return_if_fail (GTK_IS_WIDGET (widget));
9488 g_return_if_fail (!gtk_widget_get_realized (widget));
9490 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9491 GINT_TO_POINTER (events));
9492 g_object_notify (G_OBJECT (widget), "events");
9496 * gtk_widget_set_device_events:
9497 * @widget: a #GtkWidget
9498 * @device: a #GdkDevice
9499 * @events: event mask
9501 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9502 * mask determines which events a widget will receive from @device. Keep
9503 * in mind that different widgets have different default event masks, and by
9504 * changing the event mask you may disrupt a widget's functionality,
9505 * so be careful. This function must be called while a widget is
9506 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9507 * already realized, or if you want to preserve the existing event
9508 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9509 * to get events on those widgets, place them inside a #GtkEventBox
9510 * and receive events on the event box.
9515 gtk_widget_set_device_events (GtkWidget *widget,
9517 GdkEventMask events)
9519 GHashTable *device_events;
9521 g_return_if_fail (GTK_IS_WIDGET (widget));
9522 g_return_if_fail (GDK_IS_DEVICE (device));
9523 g_return_if_fail (!gtk_widget_get_realized (widget));
9525 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9527 if (G_UNLIKELY (!device_events))
9529 device_events = g_hash_table_new (NULL, NULL);
9530 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9531 (GDestroyNotify) g_hash_table_unref);
9534 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9538 * gtk_widget_set_device_enabled:
9539 * @widget: a #GtkWidget
9540 * @device: a #GdkDevice
9541 * @enabled: whether to enable the device
9543 * Enables or disables a #GdkDevice to interact with @widget
9544 * and all its children.
9546 * It does so by descending through the #GdkWindow hierarchy
9547 * and enabling the same mask that is has for core events
9548 * (i.e. the one that gdk_window_get_events() returns).
9553 gtk_widget_set_device_enabled (GtkWidget *widget,
9557 GList *enabled_devices;
9559 g_return_if_fail (GTK_IS_WIDGET (widget));
9560 g_return_if_fail (GDK_IS_DEVICE (device));
9562 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9563 enabled_devices = g_list_append (enabled_devices, device);
9565 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9566 enabled_devices, (GDestroyNotify) g_list_free);;
9568 if (gtk_widget_get_realized (widget))
9569 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9573 * gtk_widget_get_device_enabled:
9574 * @widget: a #GtkWidget
9575 * @device: a #GdkDevice
9577 * Returns whether @device can interact with @widget and its
9578 * children. See gtk_widget_set_device_enabled().
9580 * Return value: %TRUE is @device is enabled for @widget
9585 gtk_widget_get_device_enabled (GtkWidget *widget,
9588 GList *enabled_devices;
9590 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9591 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9593 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9595 return g_list_find (enabled_devices, device) != NULL;
9599 gtk_widget_add_events_internal_list (GtkWidget *widget,
9606 for (l = window_list; l != NULL; l = l->next)
9608 GdkWindow *window = l->data;
9611 gdk_window_get_user_data (window, &user_data);
9612 if (user_data == widget)
9617 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9619 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9621 children = gdk_window_get_children (window);
9622 gtk_widget_add_events_internal_list (widget, device, events, children);
9623 g_list_free (children);
9629 gtk_widget_add_events_internal (GtkWidget *widget,
9633 GtkWidgetPrivate *priv = widget->priv;
9636 if (!gtk_widget_get_has_window (widget))
9637 window_list = gdk_window_get_children (priv->window);
9639 window_list = g_list_prepend (NULL, priv->window);
9641 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9643 g_list_free (window_list);
9647 * gtk_widget_add_events:
9648 * @widget: a #GtkWidget
9649 * @events: an event mask, see #GdkEventMask
9651 * Adds the events in the bitfield @events to the event mask for
9652 * @widget. See gtk_widget_set_events() for details.
9655 gtk_widget_add_events (GtkWidget *widget,
9660 g_return_if_fail (GTK_IS_WIDGET (widget));
9662 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9663 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9664 GINT_TO_POINTER (old_events | events));
9666 if (gtk_widget_get_realized (widget))
9668 gtk_widget_add_events_internal (widget, NULL, events);
9669 gtk_widget_update_devices_mask (widget, FALSE);
9672 g_object_notify (G_OBJECT (widget), "events");
9676 * gtk_widget_add_device_events:
9677 * @widget: a #GtkWidget
9678 * @device: a #GdkDevice
9679 * @events: an event mask, see #GdkEventMask
9681 * Adds the device events in the bitfield @events to the event mask for
9682 * @widget. See gtk_widget_set_device_events() for details.
9687 gtk_widget_add_device_events (GtkWidget *widget,
9689 GdkEventMask events)
9691 GdkEventMask old_events;
9692 GHashTable *device_events;
9694 g_return_if_fail (GTK_IS_WIDGET (widget));
9695 g_return_if_fail (GDK_IS_DEVICE (device));
9697 old_events = gtk_widget_get_device_events (widget, device);
9699 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9701 if (G_UNLIKELY (!device_events))
9703 device_events = g_hash_table_new (NULL, NULL);
9704 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9705 (GDestroyNotify) g_hash_table_unref);
9708 g_hash_table_insert (device_events, device,
9709 GUINT_TO_POINTER (old_events | events));
9711 if (gtk_widget_get_realized (widget))
9712 gtk_widget_add_events_internal (widget, device, events);
9714 g_object_notify (G_OBJECT (widget), "events");
9718 * gtk_widget_get_toplevel:
9719 * @widget: a #GtkWidget
9721 * This function returns the topmost widget in the container hierarchy
9722 * @widget is a part of. If @widget has no parent widgets, it will be
9723 * returned as the topmost widget. No reference will be added to the
9724 * returned widget; it should not be unreferenced.
9726 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9727 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9729 * %NULL if @widget wasn't inside a toplevel window, and if the
9730 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9731 * inside the toplevel #GtkWindow. While the second case may
9732 * seem unlikely, it actually happens when a #GtkPlug is embedded
9733 * inside a #GtkSocket within the same application.
9735 * To reliably find the toplevel #GtkWindow, use
9736 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9737 * is set on the result.
9739 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9740 * if (gtk_widget_is_toplevel (toplevel))
9742 * /* Perform action on toplevel. */
9746 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9747 * if there's no ancestor.
9750 gtk_widget_get_toplevel (GtkWidget *widget)
9752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9754 while (widget->priv->parent)
9755 widget = widget->priv->parent;
9761 * gtk_widget_get_ancestor:
9762 * @widget: a #GtkWidget
9763 * @widget_type: ancestor type
9765 * Gets the first ancestor of @widget with type @widget_type. For example,
9766 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9767 * the first #GtkBox that's an ancestor of @widget. No reference will be
9768 * added to the returned widget; it should not be unreferenced. See note
9769 * about checking for a toplevel #GtkWindow in the docs for
9770 * gtk_widget_get_toplevel().
9772 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9773 * considers @widget to be an ancestor of itself.
9775 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9778 gtk_widget_get_ancestor (GtkWidget *widget,
9781 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9783 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9784 widget = widget->priv->parent;
9786 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9793 * gtk_widget_set_visual:
9794 * @widget: a #GtkWidget
9795 * @visual: visual to be used or %NULL to unset a previous one
9797 * Sets the visual that should be used for by widget and its children for
9798 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9799 * returned by gtk_widget_get_screen(), so handling the
9800 * #GtkWidget::screen-changed signal is necessary.
9802 * Setting a new @visual will not cause @widget to recreate its windows,
9803 * so you should call this function before @widget is realized.
9806 gtk_widget_set_visual (GtkWidget *widget,
9809 g_return_if_fail (GTK_IS_WIDGET (widget));
9810 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9813 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9816 g_object_set_qdata_full (G_OBJECT (widget),
9818 g_object_ref (visual),
9823 * gtk_widget_get_visual:
9824 * @widget: a #GtkWidget
9826 * Gets the visual that will be used to render @widget.
9828 * Return value: (transfer none): the visual for @widget
9831 gtk_widget_get_visual (GtkWidget *widget)
9837 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9839 if (gtk_widget_get_has_window (widget) &&
9840 widget->priv->window)
9841 return gdk_window_get_visual (widget->priv->window);
9843 screen = gtk_widget_get_screen (widget);
9845 for (w = widget; w != NULL; w = w->priv->parent)
9847 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9850 if (gdk_visual_get_screen (visual) == screen)
9853 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9854 gtk_widget_get_name (widget));
9858 return gdk_screen_get_system_visual (screen);
9862 * gtk_widget_get_settings:
9863 * @widget: a #GtkWidget
9865 * Gets the settings object holding the settings used for this widget.
9867 * Note that this function can only be called when the #GtkWidget
9868 * is attached to a toplevel, since the settings object is specific
9869 * to a particular #GdkScreen.
9871 * Return value: (transfer none): the relevant #GtkSettings object
9874 gtk_widget_get_settings (GtkWidget *widget)
9876 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9878 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9882 * gtk_widget_get_events:
9883 * @widget: a #GtkWidget
9885 * Returns the event mask for the widget (a bitfield containing flags
9886 * from the #GdkEventMask enumeration). These are the events that the widget
9889 * Return value: event mask for @widget
9892 gtk_widget_get_events (GtkWidget *widget)
9894 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9896 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9900 * gtk_widget_get_device_events:
9901 * @widget: a #GtkWidget
9902 * @device: a #GdkDevice
9904 * Returns the events mask for the widget corresponding to an specific device. These
9905 * are the events that the widget will receive when @device operates on it.
9907 * Returns: device event mask for @widget
9912 gtk_widget_get_device_events (GtkWidget *widget,
9915 GHashTable *device_events;
9917 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9918 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9920 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9925 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9929 * gtk_widget_get_pointer:
9930 * @widget: a #GtkWidget
9931 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9932 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9934 * Obtains the location of the mouse pointer in widget coordinates.
9935 * Widget coordinates are a bit odd; for historical reasons, they are
9936 * defined as @widget->window coordinates for widgets that are not
9937 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9938 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9940 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9943 gtk_widget_get_pointer (GtkWidget *widget,
9947 GtkWidgetPrivate *priv;
9949 g_return_if_fail (GTK_IS_WIDGET (widget));
9951 priv = widget->priv;
9958 if (gtk_widget_get_realized (widget))
9960 gdk_window_get_device_position (priv->window,
9961 gdk_device_manager_get_client_pointer (
9962 gdk_display_get_device_manager (
9963 gtk_widget_get_display (widget))),
9966 if (!gtk_widget_get_has_window (widget))
9969 *x -= priv->allocation.x;
9971 *y -= priv->allocation.y;
9977 * gtk_widget_is_ancestor:
9978 * @widget: a #GtkWidget
9979 * @ancestor: another #GtkWidget
9981 * Determines whether @widget is somewhere inside @ancestor, possibly with
9982 * intermediate containers.
9984 * Return value: %TRUE if @ancestor contains @widget as a child,
9985 * grandchild, great grandchild, etc.
9988 gtk_widget_is_ancestor (GtkWidget *widget,
9989 GtkWidget *ancestor)
9991 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9992 g_return_val_if_fail (ancestor != NULL, FALSE);
9996 if (widget->priv->parent == ancestor)
9998 widget = widget->priv->parent;
10004 static GQuark quark_composite_name = 0;
10007 * gtk_widget_set_composite_name:
10008 * @widget: a #GtkWidget.
10009 * @name: the name to set
10011 * Sets a widgets composite name. The widget must be
10012 * a composite child of its parent; see gtk_widget_push_composite_child().
10015 gtk_widget_set_composite_name (GtkWidget *widget,
10018 g_return_if_fail (GTK_IS_WIDGET (widget));
10019 g_return_if_fail (widget->priv->composite_child);
10020 g_return_if_fail (name != NULL);
10022 if (!quark_composite_name)
10023 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10025 g_object_set_qdata_full (G_OBJECT (widget),
10026 quark_composite_name,
10032 * gtk_widget_get_composite_name:
10033 * @widget: a #GtkWidget
10035 * Obtains the composite name of a widget.
10037 * Returns: the composite name of @widget, or %NULL if @widget is not
10038 * a composite child. The string should be freed when it is no
10042 gtk_widget_get_composite_name (GtkWidget *widget)
10044 GtkWidgetPrivate *priv;
10046 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10048 priv = widget->priv;
10050 if (widget->priv->composite_child && priv->parent)
10051 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10058 * gtk_widget_push_composite_child:
10060 * Makes all newly-created widgets as composite children until
10061 * the corresponding gtk_widget_pop_composite_child() call.
10063 * A composite child is a child that's an implementation detail of the
10064 * container it's inside and should not be visible to people using the
10065 * container. Composite children aren't treated differently by GTK (but
10066 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10067 * builders might want to treat them in a different way.
10069 * Here is a simple example:
10071 * gtk_widget_push_composite_child ();
10072 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10073 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10074 * gtk_widget_pop_composite_child ();
10075 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10076 * GTK_WIDGET (scrolled_window));
10077 * g_object_ref (scrolled_window->hscrollbar);
10081 gtk_widget_push_composite_child (void)
10083 composite_child_stack++;
10087 * gtk_widget_pop_composite_child:
10089 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10092 gtk_widget_pop_composite_child (void)
10094 if (composite_child_stack)
10095 composite_child_stack--;
10099 gtk_widget_emit_direction_changed (GtkWidget *widget,
10100 GtkTextDirection old_dir)
10102 gtk_widget_update_pango_context (widget);
10104 if (widget->priv->context)
10105 gtk_style_context_set_direction (widget->priv->context,
10106 gtk_widget_get_direction (widget));
10108 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10112 * gtk_widget_set_direction:
10113 * @widget: a #GtkWidget
10114 * @dir: the new direction
10116 * Sets the reading direction on a particular widget. This direction
10117 * controls the primary direction for widgets containing text,
10118 * and also the direction in which the children of a container are
10119 * packed. The ability to set the direction is present in order
10120 * so that correct localization into languages with right-to-left
10121 * reading directions can be done. Generally, applications will
10122 * let the default reading direction present, except for containers
10123 * where the containers are arranged in an order that is explicitely
10124 * visual rather than logical (such as buttons for text justification).
10126 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10127 * set by gtk_widget_set_default_direction() will be used.
10130 gtk_widget_set_direction (GtkWidget *widget,
10131 GtkTextDirection dir)
10133 GtkTextDirection old_dir;
10135 g_return_if_fail (GTK_IS_WIDGET (widget));
10136 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10138 old_dir = gtk_widget_get_direction (widget);
10140 widget->priv->direction = dir;
10142 if (old_dir != gtk_widget_get_direction (widget))
10143 gtk_widget_emit_direction_changed (widget, old_dir);
10147 * gtk_widget_get_direction:
10148 * @widget: a #GtkWidget
10150 * Gets the reading direction for a particular widget. See
10151 * gtk_widget_set_direction().
10153 * Return value: the reading direction for the widget.
10156 gtk_widget_get_direction (GtkWidget *widget)
10158 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10160 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10161 return gtk_default_direction;
10163 return widget->priv->direction;
10167 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10169 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10171 g_object_ref (widget);
10173 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10174 gtk_widget_emit_direction_changed (widget, old_dir);
10176 if (GTK_IS_CONTAINER (widget))
10177 gtk_container_forall (GTK_CONTAINER (widget),
10178 gtk_widget_set_default_direction_recurse,
10181 g_object_unref (widget);
10185 * gtk_widget_set_default_direction:
10186 * @dir: the new default direction. This cannot be
10187 * %GTK_TEXT_DIR_NONE.
10189 * Sets the default reading direction for widgets where the
10190 * direction has not been explicitly set by gtk_widget_set_direction().
10193 gtk_widget_set_default_direction (GtkTextDirection dir)
10195 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10197 if (dir != gtk_default_direction)
10199 GList *toplevels, *tmp_list;
10200 GtkTextDirection old_dir = gtk_default_direction;
10202 gtk_default_direction = dir;
10204 tmp_list = toplevels = gtk_window_list_toplevels ();
10205 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10209 gtk_widget_set_default_direction_recurse (tmp_list->data,
10210 GUINT_TO_POINTER (old_dir));
10211 g_object_unref (tmp_list->data);
10212 tmp_list = tmp_list->next;
10215 g_list_free (toplevels);
10220 * gtk_widget_get_default_direction:
10222 * Obtains the current default reading direction. See
10223 * gtk_widget_set_default_direction().
10225 * Return value: the current default direction.
10228 gtk_widget_get_default_direction (void)
10230 return gtk_default_direction;
10234 gtk_widget_constructed (GObject *object)
10236 GtkWidget *widget = GTK_WIDGET (object);
10237 GtkWidgetPrivate *priv = widget->priv;
10239 /* As strange as it may seem, this may happen on object construction.
10240 * init() implementations of parent types may eventually call this function,
10241 * each with its corresponding GType, which could leave a child
10242 * implementation with a wrong widget type in the widget path
10245 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10247 gtk_widget_path_free (priv->path);
10251 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10255 gtk_widget_dispose (GObject *object)
10257 GtkWidget *widget = GTK_WIDGET (object);
10258 GtkWidgetPrivate *priv = widget->priv;
10261 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10262 else if (gtk_widget_get_visible (widget))
10263 gtk_widget_hide (widget);
10265 priv->visible = FALSE;
10266 if (gtk_widget_get_realized (widget))
10267 gtk_widget_unrealize (widget);
10269 if (!priv->in_destruction)
10271 priv->in_destruction = TRUE;
10272 g_signal_emit (object, widget_signals[DESTROY], 0);
10273 priv->in_destruction = FALSE;
10276 g_clear_object (&priv->muxer);
10278 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10282 gtk_widget_real_destroy (GtkWidget *object)
10284 /* gtk_object_destroy() will already hold a refcount on object */
10285 GtkWidget *widget = GTK_WIDGET (object);
10286 GtkWidgetPrivate *priv = widget->priv;
10288 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10290 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10294 gtk_accessible_set_widget (accessible, NULL);
10295 g_object_unref (accessible);
10299 /* wipe accelerator closures (keep order) */
10300 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10301 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10303 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10304 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10306 gtk_grab_remove (widget);
10309 g_object_unref (priv->style);
10310 priv->style = gtk_widget_get_default_style ();
10311 g_object_ref (priv->style);
10315 gtk_widget_finalize (GObject *object)
10317 GtkWidget *widget = GTK_WIDGET (object);
10318 GtkWidgetPrivate *priv = widget->priv;
10319 GtkWidgetAuxInfo *aux_info;
10320 GtkAccessible *accessible;
10322 gtk_grab_remove (widget);
10324 g_object_unref (priv->style);
10325 priv->style = NULL;
10327 g_free (priv->name);
10329 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10331 gtk_widget_aux_info_destroy (aux_info);
10333 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10335 g_object_unref (accessible);
10338 gtk_widget_path_free (priv->path);
10342 _gtk_style_context_set_widget (priv->context, NULL);
10343 g_object_unref (priv->context);
10346 _gtk_widget_free_cached_sizes (widget);
10348 if (g_object_is_floating (object))
10349 g_warning ("A floating object was finalized. This means that someone\n"
10350 "called g_object_unref() on an object that had only a floating\n"
10351 "reference; the initial floating reference is not owned by anyone\n"
10352 "and must be removed with g_object_ref_sink().");
10354 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10357 /*****************************************
10358 * gtk_widget_real_map:
10363 *****************************************/
10366 gtk_widget_real_map (GtkWidget *widget)
10368 GtkWidgetPrivate *priv = widget->priv;
10370 g_assert (gtk_widget_get_realized (widget));
10372 if (!gtk_widget_get_mapped (widget))
10374 gtk_widget_set_mapped (widget, TRUE);
10376 if (gtk_widget_get_has_window (widget))
10377 gdk_window_show (priv->window);
10381 /*****************************************
10382 * gtk_widget_real_unmap:
10387 *****************************************/
10390 gtk_widget_real_unmap (GtkWidget *widget)
10392 GtkWidgetPrivate *priv = widget->priv;
10394 if (gtk_widget_get_mapped (widget))
10396 gtk_widget_set_mapped (widget, FALSE);
10398 if (gtk_widget_get_has_window (widget))
10399 gdk_window_hide (priv->window);
10403 /*****************************************
10404 * gtk_widget_real_realize:
10409 *****************************************/
10412 gtk_widget_real_realize (GtkWidget *widget)
10414 GtkWidgetPrivate *priv = widget->priv;
10416 g_assert (!gtk_widget_get_has_window (widget));
10418 gtk_widget_set_realized (widget, TRUE);
10421 priv->window = gtk_widget_get_parent_window (widget);
10422 g_object_ref (priv->window);
10426 /*****************************************
10427 * gtk_widget_real_unrealize:
10432 *****************************************/
10435 gtk_widget_real_unrealize (GtkWidget *widget)
10437 GtkWidgetPrivate *priv = widget->priv;
10439 g_assert (!widget->priv->mapped);
10441 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10444 /* We must do unrealize child widget BEFORE container widget.
10445 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10446 * So, unrealizing container widget bofore its children causes the problem
10447 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10450 if (GTK_IS_CONTAINER (widget))
10451 gtk_container_forall (GTK_CONTAINER (widget),
10452 (GtkCallback) gtk_widget_unrealize,
10455 if (gtk_widget_get_has_window (widget))
10457 gdk_window_set_user_data (priv->window, NULL);
10458 gdk_window_destroy (priv->window);
10459 priv->window = NULL;
10463 g_object_unref (priv->window);
10464 priv->window = NULL;
10467 gtk_selection_remove_all (widget);
10469 gtk_widget_set_realized (widget, FALSE);
10473 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10474 GtkOrientation orientation,
10475 gint *minimum_size,
10476 gint *natural_size)
10478 const GtkWidgetAuxInfo *aux_info;
10480 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10482 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10483 aux_info->width > 0)
10485 *minimum_size = MAX (*minimum_size, aux_info->width);
10487 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10488 aux_info->height > 0)
10490 *minimum_size = MAX (*minimum_size, aux_info->height);
10493 /* Fix it if set_size_request made natural size smaller than min size.
10494 * This would also silently fix broken widgets, but we warn about them
10495 * in gtksizerequest.c when calling their size request vfuncs.
10497 *natural_size = MAX (*natural_size, *minimum_size);
10499 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10501 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10502 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10506 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10507 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10512 * _gtk_widget_peek_request_cache:
10514 * Returns the address of the widget's request cache (strictly for
10515 * internal use in gtksizerequest.c)
10517 * Return value: the address of @widget's size request cache.
10520 _gtk_widget_peek_request_cache (GtkWidget *widget)
10522 /* Don't bother slowing things down with the return_if_fail guards here */
10523 return &widget->priv->requests;
10527 * _gtk_widget_set_device_window:
10528 * @widget: a #GtkWidget
10529 * @device: a #GdkDevice
10530 * @window: the new device window
10532 * Sets pointer window for @widget and @device.
10533 * Does not ref @window.
10536 _gtk_widget_set_device_window (GtkWidget *widget,
10540 GHashTable *device_window;
10542 g_return_if_fail (GTK_IS_WIDGET (widget));
10543 g_return_if_fail (GDK_IS_DEVICE (device));
10544 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10546 if (!gtk_widget_get_mapped (widget))
10549 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10551 if (!device_window && window)
10553 device_window = g_hash_table_new (NULL, NULL);
10554 g_object_set_qdata_full (G_OBJECT (widget),
10555 quark_pointer_window,
10557 (GDestroyNotify) g_hash_table_destroy);
10561 g_hash_table_insert (device_window, device, window);
10562 else if (device_window)
10564 g_hash_table_remove (device_window, device);
10566 if (g_hash_table_size (device_window) == 0)
10567 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10572 * _gtk_widget_get_device_window:
10573 * @widget: a #GtkWidget
10574 * @device: a #GdkDevice
10576 * Return value: the device window set on @widget, or %NULL
10579 _gtk_widget_get_device_window (GtkWidget *widget,
10582 GHashTable *device_window;
10584 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10585 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10587 if (!gtk_widget_get_mapped (widget))
10590 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10592 if (!device_window)
10595 return g_hash_table_lookup (device_window, device);
10599 * _gtk_widget_list_devices:
10600 * @widget: a #GtkWidget
10602 * Returns the list of #GdkDevices that is currently on top
10603 * of any window belonging to @widget.
10604 * Free the list with g_list_free(), the elements are owned
10605 * by GTK+ and must not be freed.
10608 _gtk_widget_list_devices (GtkWidget *widget)
10610 GHashTableIter iter;
10611 GHashTable *device_window;
10612 GList *devices = NULL;
10613 gpointer key, value;
10615 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10617 if (!gtk_widget_get_mapped (widget))
10620 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10622 if (G_UNLIKELY (!device_window))
10625 g_hash_table_iter_init (&iter, device_window);
10627 while (g_hash_table_iter_next (&iter, &key, &value))
10628 devices = g_list_prepend (devices, key);
10634 synth_crossing (GtkWidget *widget,
10638 GdkCrossingMode mode,
10639 GdkNotifyType detail)
10643 event = gdk_event_new (type);
10645 event->crossing.window = g_object_ref (window);
10646 event->crossing.send_event = TRUE;
10647 event->crossing.subwindow = g_object_ref (window);
10648 event->crossing.time = GDK_CURRENT_TIME;
10649 event->crossing.x = event->crossing.y = 0;
10650 event->crossing.x_root = event->crossing.y_root = 0;
10651 event->crossing.mode = mode;
10652 event->crossing.detail = detail;
10653 event->crossing.focus = FALSE;
10654 event->crossing.state = 0;
10655 gdk_event_set_device (event, device);
10658 widget = gtk_get_event_widget (event);
10661 gtk_widget_event_internal (widget, event);
10663 gdk_event_free (event);
10667 * _gtk_widget_synthesize_crossing:
10668 * @from: the #GtkWidget the virtual pointer is leaving.
10669 * @to: the #GtkWidget the virtual pointer is moving to.
10670 * @mode: the #GdkCrossingMode to place on the synthesized events.
10672 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10674 * The real pointer window is the window that most recently received an enter notify
10675 * event. Windows that don't select for crossing events can't become the real
10676 * poiner window. The real pointer widget that owns the real pointer window. The
10677 * effective pointer window is the same as the real pointer window unless the real
10678 * pointer widget is either insensitive or there is a grab on a widget that is not
10679 * an ancestor of the real pointer widget (in which case the effective pointer
10680 * window should be the root window).
10682 * When the effective pointer window is the same as the real poiner window, we
10683 * receive crossing events from the windowing system. When the effective pointer
10684 * window changes to become different from the real pointer window we synthesize
10685 * crossing events, attempting to follow X protocol rules:
10687 * When the root window becomes the effective pointer window:
10688 * - leave notify on real pointer window, detail Ancestor
10689 * - leave notify on all of its ancestors, detail Virtual
10690 * - enter notify on root window, detail Inferior
10692 * When the root window ceases to be the effective pointer window:
10693 * - leave notify on root window, detail Inferior
10694 * - enter notify on all ancestors of real pointer window, detail Virtual
10695 * - enter notify on real pointer window, detail Ancestor
10698 _gtk_widget_synthesize_crossing (GtkWidget *from,
10701 GdkCrossingMode mode)
10703 GdkWindow *from_window = NULL, *to_window = NULL;
10705 g_return_if_fail (from != NULL || to != NULL);
10709 from_window = _gtk_widget_get_device_window (from, device);
10712 from_window = from->priv->window;
10717 to_window = _gtk_widget_get_device_window (to, device);
10720 to_window = to->priv->window;
10723 if (from_window == NULL && to_window == NULL)
10725 else if (from_window != NULL && to_window == NULL)
10727 GList *from_ancestors = NULL, *list;
10728 GdkWindow *from_ancestor = from_window;
10730 while (from_ancestor != NULL)
10732 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10733 if (from_ancestor == NULL)
10735 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10738 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10739 device, mode, GDK_NOTIFY_ANCESTOR);
10740 for (list = g_list_last (from_ancestors); list; list = list->prev)
10742 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10743 device, mode, GDK_NOTIFY_VIRTUAL);
10746 /* XXX: enter/inferior on root window? */
10748 g_list_free (from_ancestors);
10750 else if (from_window == NULL && to_window != NULL)
10752 GList *to_ancestors = NULL, *list;
10753 GdkWindow *to_ancestor = to_window;
10755 while (to_ancestor != NULL)
10757 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10758 if (to_ancestor == NULL)
10760 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10763 /* XXX: leave/inferior on root window? */
10765 for (list = to_ancestors; list; list = list->next)
10767 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10768 device, mode, GDK_NOTIFY_VIRTUAL);
10770 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10771 device, mode, GDK_NOTIFY_ANCESTOR);
10773 g_list_free (to_ancestors);
10775 else if (from_window == to_window)
10779 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10780 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10782 while (from_ancestor != NULL || to_ancestor != NULL)
10784 if (from_ancestor != NULL)
10786 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10787 if (from_ancestor == to_window)
10790 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10792 if (to_ancestor != NULL)
10794 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10795 if (to_ancestor == from_window)
10798 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10801 if (to_ancestor == from_window)
10803 if (mode != GDK_CROSSING_GTK_UNGRAB)
10804 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10805 device, mode, GDK_NOTIFY_INFERIOR);
10806 for (list = to_ancestors; list; list = list->next)
10807 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10808 device, mode, GDK_NOTIFY_VIRTUAL);
10809 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10810 device, mode, GDK_NOTIFY_ANCESTOR);
10812 else if (from_ancestor == to_window)
10814 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10815 device, mode, GDK_NOTIFY_ANCESTOR);
10816 for (list = g_list_last (from_ancestors); list; list = list->prev)
10818 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10819 device, mode, GDK_NOTIFY_VIRTUAL);
10821 if (mode != GDK_CROSSING_GTK_GRAB)
10822 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10823 device, mode, GDK_NOTIFY_INFERIOR);
10827 while (from_ancestors != NULL && to_ancestors != NULL
10828 && from_ancestors->data == to_ancestors->data)
10830 from_ancestors = g_list_delete_link (from_ancestors,
10832 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10835 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10836 device, mode, GDK_NOTIFY_NONLINEAR);
10838 for (list = g_list_last (from_ancestors); list; list = list->prev)
10840 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10841 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10843 for (list = to_ancestors; list; list = list->next)
10845 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10846 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10848 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10849 device, mode, GDK_NOTIFY_NONLINEAR);
10851 g_list_free (from_ancestors);
10852 g_list_free (to_ancestors);
10857 gtk_widget_propagate_state (GtkWidget *widget,
10858 GtkStateData *data)
10860 GtkWidgetPrivate *priv = widget->priv;
10861 GtkStateFlags new_flags, old_flags = priv->state_flags;
10862 GtkStateType old_state;
10864 old_state = gtk_widget_get_state (widget);
10866 switch (data->operation)
10868 case STATE_CHANGE_REPLACE:
10869 priv->state_flags = data->flags;
10871 case STATE_CHANGE_SET:
10872 priv->state_flags |= data->flags;
10874 case STATE_CHANGE_UNSET:
10875 priv->state_flags &= ~(data->flags);
10879 /* make insensitivity unoverridable */
10880 if (!priv->sensitive)
10881 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10883 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10887 window = gtk_widget_get_toplevel (widget);
10889 if (window && gtk_widget_is_toplevel (window))
10890 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10893 new_flags = priv->state_flags;
10895 if (old_flags != new_flags)
10897 g_object_ref (widget);
10899 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10900 gtk_grab_remove (widget);
10902 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10904 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10905 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10907 if (!priv->shadowed &&
10908 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10910 GList *event_windows = NULL;
10911 GList *devices, *d;
10913 devices = _gtk_widget_list_devices (widget);
10915 for (d = devices; d; d = d->next)
10921 window = _gtk_widget_get_device_window (widget, device);
10923 /* Do not propagate more than once to the
10924 * same window if non-multidevice aware.
10926 if (!gdk_window_get_support_multidevice (window) &&
10927 g_list_find (event_windows, window))
10930 if (!gtk_widget_is_sensitive (widget))
10931 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10932 GDK_CROSSING_STATE_CHANGED);
10934 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10935 GDK_CROSSING_STATE_CHANGED);
10937 event_windows = g_list_prepend (event_windows, window);
10940 g_list_free (event_windows);
10941 g_list_free (devices);
10944 if (GTK_IS_CONTAINER (widget))
10946 GtkStateData child_data = *data;
10948 /* Make sure to only propate the right states further */
10949 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10951 gtk_container_forall (GTK_CONTAINER (widget),
10952 (GtkCallback) gtk_widget_propagate_state,
10956 g_object_unref (widget);
10960 static const GtkWidgetAuxInfo default_aux_info = {
10968 * gtk_widget_get_aux_info:
10969 * @widget: a #GtkWidget
10970 * @create: if %TRUE, create the structure if it doesn't exist
10972 * Get the #GtkWidgetAuxInfo structure for the widget.
10974 * Return value: the #GtkAuxInfo structure for the widget, or
10975 * %NULL if @create is %FALSE and one doesn't already exist.
10977 static GtkWidgetAuxInfo *
10978 gtk_widget_get_aux_info (GtkWidget *widget,
10981 GtkWidgetAuxInfo *aux_info;
10983 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10984 if (!aux_info && create)
10986 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10988 *aux_info = default_aux_info;
10990 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10996 static const GtkWidgetAuxInfo*
10997 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10999 GtkWidgetAuxInfo *aux_info;
11001 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11002 if (aux_info == NULL)
11004 return &default_aux_info;
11012 /*****************************************
11013 * gtk_widget_aux_info_destroy:
11018 *****************************************/
11021 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11023 g_slice_free (GtkWidgetAuxInfo, aux_info);
11027 * gtk_widget_shape_combine_region:
11028 * @widget: a #GtkWidget
11029 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11031 * Sets a shape for this widget's GDK window. This allows for
11032 * transparent windows etc., see gdk_window_shape_combine_region()
11033 * for more information.
11038 gtk_widget_shape_combine_region (GtkWidget *widget,
11039 cairo_region_t *region)
11041 GtkWidgetPrivate *priv;
11043 g_return_if_fail (GTK_IS_WIDGET (widget));
11044 /* set_shape doesn't work on widgets without gdk window */
11045 g_return_if_fail (gtk_widget_get_has_window (widget));
11047 priv = widget->priv;
11049 if (region == NULL)
11051 priv->has_shape_mask = FALSE;
11054 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11056 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11060 priv->has_shape_mask = TRUE;
11062 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11063 cairo_region_copy (region),
11064 (GDestroyNotify) cairo_region_destroy);
11066 /* set shape if widget has a gdk window already.
11067 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11070 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11075 * gtk_widget_input_shape_combine_region:
11076 * @widget: a #GtkWidget
11077 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11079 * Sets an input shape for this widget's GDK window. This allows for
11080 * windows which react to mouse click in a nonrectangular region, see
11081 * gdk_window_input_shape_combine_region() for more information.
11086 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11087 cairo_region_t *region)
11089 GtkWidgetPrivate *priv;
11091 g_return_if_fail (GTK_IS_WIDGET (widget));
11092 /* set_shape doesn't work on widgets without gdk window */
11093 g_return_if_fail (gtk_widget_get_has_window (widget));
11095 priv = widget->priv;
11097 if (region == NULL)
11100 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11102 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11106 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11107 cairo_region_copy (region),
11108 (GDestroyNotify) cairo_region_destroy);
11110 /* set shape if widget has a gdk window already.
11111 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11114 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11119 /* style properties
11123 * gtk_widget_class_install_style_property_parser: (skip)
11124 * @klass: a #GtkWidgetClass
11125 * @pspec: the #GParamSpec for the style property
11126 * @parser: the parser for the style property
11128 * Installs a style property on a widget class.
11131 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11133 GtkRcPropertyParser parser)
11135 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11136 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11137 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11138 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11140 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11142 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11143 G_OBJECT_CLASS_NAME (klass),
11148 g_param_spec_ref_sink (pspec);
11149 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11150 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11154 * gtk_widget_class_install_style_property:
11155 * @klass: a #GtkWidgetClass
11156 * @pspec: the #GParamSpec for the property
11158 * Installs a style property on a widget class. The parser for the
11159 * style property is determined by the value type of @pspec.
11162 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11165 GtkRcPropertyParser parser;
11167 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11168 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11170 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11172 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11176 * gtk_widget_class_find_style_property:
11177 * @klass: a #GtkWidgetClass
11178 * @property_name: the name of the style property to find
11180 * Finds a style property of a widget class by name.
11182 * Returns: (transfer none): the #GParamSpec of the style property or
11183 * %NULL if @class has no style property with that name.
11188 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11189 const gchar *property_name)
11191 g_return_val_if_fail (property_name != NULL, NULL);
11193 return g_param_spec_pool_lookup (style_property_spec_pool,
11195 G_OBJECT_CLASS_TYPE (klass),
11200 * gtk_widget_class_list_style_properties:
11201 * @klass: a #GtkWidgetClass
11202 * @n_properties: location to return the number of style properties found
11204 * Returns all style properties of a widget class.
11206 * Returns: (array length=n_properties) (transfer container): a
11207 * newly allocated array of #GParamSpec*. The array must be
11208 * freed with g_free().
11213 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11214 guint *n_properties)
11216 GParamSpec **pspecs;
11219 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11220 G_OBJECT_CLASS_TYPE (klass),
11229 * gtk_widget_style_get_property:
11230 * @widget: a #GtkWidget
11231 * @property_name: the name of a style property
11232 * @value: location to return the property value
11234 * Gets the value of a style property of @widget.
11237 gtk_widget_style_get_property (GtkWidget *widget,
11238 const gchar *property_name,
11243 g_return_if_fail (GTK_IS_WIDGET (widget));
11244 g_return_if_fail (property_name != NULL);
11245 g_return_if_fail (G_IS_VALUE (value));
11247 g_object_ref (widget);
11248 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11250 G_OBJECT_TYPE (widget),
11253 g_warning ("%s: widget class `%s' has no property named `%s'",
11255 G_OBJECT_TYPE_NAME (widget),
11259 GtkStyleContext *context;
11260 const GValue *peek_value;
11261 GtkStateFlags state;
11263 context = gtk_widget_get_style_context (widget);
11264 state = gtk_widget_get_state_flags (widget);
11266 peek_value = _gtk_style_context_peek_style_property (context,
11267 G_OBJECT_TYPE (widget),
11270 /* auto-conversion of the caller's value type
11272 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11273 g_value_copy (peek_value, value);
11274 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11275 g_value_transform (peek_value, value);
11277 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11279 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11280 G_VALUE_TYPE_NAME (value));
11282 g_object_unref (widget);
11286 * gtk_widget_style_get_valist:
11287 * @widget: a #GtkWidget
11288 * @first_property_name: the name of the first property to get
11289 * @var_args: a <type>va_list</type> of pairs of property names and
11290 * locations to return the property values, starting with the location
11291 * for @first_property_name.
11293 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11297 gtk_widget_style_get_valist (GtkWidget *widget,
11298 const gchar *first_property_name,
11301 GtkStyleContext *context;
11302 GtkStateFlags state;
11305 g_return_if_fail (GTK_IS_WIDGET (widget));
11307 g_object_ref (widget);
11308 context = gtk_widget_get_style_context (widget);
11309 state = gtk_widget_get_state_flags (widget);
11311 name = first_property_name;
11314 const GValue *peek_value;
11318 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11320 G_OBJECT_TYPE (widget),
11324 g_warning ("%s: widget class `%s' has no property named `%s'",
11326 G_OBJECT_TYPE_NAME (widget),
11330 /* style pspecs are always readable so we can spare that check here */
11332 peek_value = _gtk_style_context_peek_style_property (context,
11333 G_OBJECT_TYPE (widget),
11336 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11339 g_warning ("%s: %s", G_STRLOC, error);
11344 name = va_arg (var_args, gchar*);
11347 g_object_unref (widget);
11351 * gtk_widget_style_get:
11352 * @widget: a #GtkWidget
11353 * @first_property_name: the name of the first property to get
11354 * @...: pairs of property names and locations to return the
11355 * property values, starting with the location for
11356 * @first_property_name, terminated by %NULL.
11358 * Gets the values of a multiple style properties of @widget.
11361 gtk_widget_style_get (GtkWidget *widget,
11362 const gchar *first_property_name,
11367 g_return_if_fail (GTK_IS_WIDGET (widget));
11369 va_start (var_args, first_property_name);
11370 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11375 * gtk_requisition_new:
11377 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11379 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11380 * be freed with gtk_requisition_free().
11385 gtk_requisition_new (void)
11387 return g_slice_new0 (GtkRequisition);
11391 * gtk_requisition_copy:
11392 * @requisition: a #GtkRequisition
11394 * Copies a #GtkRequisition.
11396 * Returns: a copy of @requisition
11399 gtk_requisition_copy (const GtkRequisition *requisition)
11401 return g_slice_dup (GtkRequisition, requisition);
11405 * gtk_requisition_free:
11406 * @requisition: a #GtkRequisition
11408 * Frees a #GtkRequisition.
11411 gtk_requisition_free (GtkRequisition *requisition)
11413 g_slice_free (GtkRequisition, requisition);
11416 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11417 gtk_requisition_copy,
11418 gtk_requisition_free)
11421 * gtk_widget_class_set_accessible_type:
11422 * @widget_class: class to set the accessible type for
11423 * @type: The object type that implements the accessible for @widget_class
11425 * Sets the type to be used for creating accessibles for widgets of
11426 * @widget_class. The given @type must be a subtype of the type used for
11427 * accessibles of the parent class.
11429 * This function should only be called from class init functions of widgets.
11434 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11437 GtkWidgetClassPrivate *priv;
11439 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11440 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11442 priv = widget_class->priv;
11444 priv->accessible_type = type;
11445 /* reset this - honoring the type's role is better. */
11446 priv->accessible_role = ATK_ROLE_INVALID;
11450 * gtk_widget_class_set_accessible_role:
11451 * @widget_class: class to set the accessible role for
11452 * @role: The role to use for accessibles created for @widget_class
11454 * Sets the default #AtkRole to be set on accessibles created for
11455 * widgets of @widget_class. Accessibles may decide to not honor this
11456 * setting if their role reporting is more refined. Calls to
11457 * gtk_widget_class_set_accessible_type() will reset this value.
11459 * In cases where you want more fine-grained control over the role of
11460 * accessibles created for @widget_class, you should provide your own
11461 * accessible type and use gtk_widget_class_set_accessible_type()
11464 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11465 * and the accessible's default role will be used instead.
11467 * This function should only be called from class init functions of widgets.
11472 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11475 GtkWidgetClassPrivate *priv;
11477 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11479 priv = widget_class->priv;
11481 priv->accessible_role = role;
11485 * _gtk_widget_peek_accessible:
11486 * @widget: a #GtkWidget
11488 * Gets the accessible for @widget, if it has been created yet.
11489 * Otherwise, this function returns %NULL. If the @widget's implementation
11490 * does not use the default way to create accessibles, %NULL will always be
11493 * Returns: the accessible for @widget or %NULL if none has been
11497 _gtk_widget_peek_accessible (GtkWidget *widget)
11499 return g_object_get_qdata (G_OBJECT (widget),
11500 quark_accessible_object);
11504 * gtk_widget_get_accessible:
11505 * @widget: a #GtkWidget
11507 * Returns the accessible object that describes the widget to an
11508 * assistive technology.
11510 * If accessibility support is not available, this #AtkObject
11511 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11512 * implementation is available for the widget instance in question,
11513 * it will inherit an #AtkObject implementation from the first ancestor
11514 * class for which such an implementation is defined.
11516 * The documentation of the
11517 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11518 * library contains more information about accessible objects and their uses.
11520 * Returns: (transfer none): the #AtkObject associated with @widget
11523 gtk_widget_get_accessible (GtkWidget *widget)
11525 GtkWidgetClass *klass;
11527 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11529 klass = GTK_WIDGET_GET_CLASS (widget);
11531 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11533 return klass->get_accessible (widget);
11537 gtk_widget_real_get_accessible (GtkWidget *widget)
11539 AtkObject* accessible;
11541 accessible = g_object_get_qdata (G_OBJECT (widget),
11542 quark_accessible_object);
11545 GtkWidgetClass *widget_class;
11546 GtkWidgetClassPrivate *priv;
11547 AtkObjectFactory *factory;
11548 AtkRegistry *default_registry;
11550 widget_class = GTK_WIDGET_GET_CLASS (widget);
11551 priv = widget_class->priv;
11553 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11555 default_registry = atk_get_default_registry ();
11556 factory = atk_registry_get_factory (default_registry,
11557 G_TYPE_FROM_INSTANCE (widget));
11559 atk_object_factory_create_accessible (factory,
11560 G_OBJECT (widget));
11562 if (priv->accessible_role != ATK_ROLE_INVALID)
11563 atk_object_set_role (accessible, priv->accessible_role);
11565 g_object_set_qdata (G_OBJECT (widget),
11566 quark_accessible_object,
11571 accessible = g_object_new (priv->accessible_type,
11574 if (priv->accessible_role != ATK_ROLE_INVALID)
11575 atk_object_set_role (accessible, priv->accessible_role);
11577 g_object_set_qdata (G_OBJECT (widget),
11578 quark_accessible_object,
11581 atk_object_initialize (accessible, widget);
11583 /* Set the role again, since we don't want a role set
11584 * in some parent initialize() function to override
11587 if (priv->accessible_role != ATK_ROLE_INVALID)
11588 atk_object_set_role (accessible, priv->accessible_role);
11595 * Initialize a AtkImplementorIface instance's virtual pointers as
11596 * appropriate to this implementor's class (GtkWidget).
11599 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11601 iface->ref_accessible = gtk_widget_ref_accessible;
11605 gtk_widget_ref_accessible (AtkImplementor *implementor)
11607 AtkObject *accessible;
11609 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11611 g_object_ref (accessible);
11616 * Expand flag management
11620 gtk_widget_update_computed_expand (GtkWidget *widget)
11622 GtkWidgetPrivate *priv;
11624 priv = widget->priv;
11626 if (priv->need_compute_expand)
11630 if (priv->hexpand_set)
11635 if (priv->vexpand_set)
11640 /* we don't need to use compute_expand if both expands are
11641 * forced by the app
11643 if (!(priv->hexpand_set && priv->vexpand_set))
11645 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11649 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11650 priv->hexpand_set ? &ignored : &h,
11651 priv->vexpand_set ? &ignored : &v);
11655 priv->need_compute_expand = FALSE;
11656 priv->computed_hexpand = h != FALSE;
11657 priv->computed_vexpand = v != FALSE;
11662 * gtk_widget_queue_compute_expand:
11663 * @widget: a #GtkWidget
11665 * Mark @widget as needing to recompute its expand flags. Call
11666 * this function when setting legacy expand child properties
11667 * on the child of a container.
11669 * See gtk_widget_compute_expand().
11672 gtk_widget_queue_compute_expand (GtkWidget *widget)
11675 gboolean changed_anything;
11677 if (widget->priv->need_compute_expand)
11680 changed_anything = FALSE;
11682 while (parent != NULL)
11684 if (!parent->priv->need_compute_expand)
11686 parent->priv->need_compute_expand = TRUE;
11687 changed_anything = TRUE;
11690 /* Note: if we had an invariant that "if a child needs to
11691 * compute expand, its parents also do" then we could stop going
11692 * up when we got to a parent that already needed to
11693 * compute. However, in general we compute expand lazily (as
11694 * soon as we see something in a subtree that is expand, we know
11695 * we're expanding) and so this invariant does not hold and we
11696 * have to always walk all the way up in case some ancestor
11697 * is not currently need_compute_expand.
11700 parent = parent->priv->parent;
11703 /* recomputing expand always requires
11704 * a relayout as well
11706 if (changed_anything)
11707 gtk_widget_queue_resize (widget);
11711 * gtk_widget_compute_expand:
11712 * @widget: the widget
11713 * @orientation: expand direction
11715 * Computes whether a container should give this widget extra space
11716 * when possible. Containers should check this, rather than
11717 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11719 * This function already checks whether the widget is visible, so
11720 * visibility does not need to be checked separately. Non-visible
11721 * widgets are not expanded.
11723 * The computed expand value uses either the expand setting explicitly
11724 * set on the widget itself, or, if none has been explicitly set,
11725 * the widget may expand if some of its children do.
11727 * Return value: whether widget tree rooted here should be expanded
11730 gtk_widget_compute_expand (GtkWidget *widget,
11731 GtkOrientation orientation)
11733 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11735 /* We never make a widget expand if not even showing. */
11736 if (!gtk_widget_get_visible (widget))
11739 gtk_widget_update_computed_expand (widget);
11741 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11743 return widget->priv->computed_hexpand;
11747 return widget->priv->computed_vexpand;
11752 gtk_widget_set_expand (GtkWidget *widget,
11753 GtkOrientation orientation,
11756 const char *expand_prop;
11757 const char *expand_set_prop;
11759 GtkWidgetPrivate *priv;
11761 g_return_if_fail (GTK_IS_WIDGET (widget));
11763 priv = widget->priv;
11765 expand = expand != FALSE;
11767 was_both = priv->hexpand && priv->vexpand;
11769 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11771 if (priv->hexpand_set &&
11772 priv->hexpand == expand)
11775 priv->hexpand_set = TRUE;
11776 priv->hexpand = expand;
11778 expand_prop = "hexpand";
11779 expand_set_prop = "hexpand-set";
11783 if (priv->vexpand_set &&
11784 priv->vexpand == expand)
11787 priv->vexpand_set = TRUE;
11788 priv->vexpand = expand;
11790 expand_prop = "vexpand";
11791 expand_set_prop = "vexpand-set";
11794 gtk_widget_queue_compute_expand (widget);
11796 g_object_freeze_notify (G_OBJECT (widget));
11797 g_object_notify (G_OBJECT (widget), expand_prop);
11798 g_object_notify (G_OBJECT (widget), expand_set_prop);
11799 if (was_both != (priv->hexpand && priv->vexpand))
11800 g_object_notify (G_OBJECT (widget), "expand");
11801 g_object_thaw_notify (G_OBJECT (widget));
11805 gtk_widget_set_expand_set (GtkWidget *widget,
11806 GtkOrientation orientation,
11809 GtkWidgetPrivate *priv;
11812 priv = widget->priv;
11814 set = set != FALSE;
11816 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11818 if (set == priv->hexpand_set)
11821 priv->hexpand_set = set;
11822 prop = "hexpand-set";
11826 if (set == priv->vexpand_set)
11829 priv->vexpand_set = set;
11830 prop = "vexpand-set";
11833 gtk_widget_queue_compute_expand (widget);
11835 g_object_notify (G_OBJECT (widget), prop);
11839 * gtk_widget_get_hexpand:
11840 * @widget: the widget
11842 * Gets whether the widget would like any available extra horizontal
11843 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11844 * generally receive the extra space. For example, a list or
11845 * scrollable area or document in your window would often be set to
11848 * Containers should use gtk_widget_compute_expand() rather than
11849 * this function, to see whether a widget, or any of its children,
11850 * has the expand flag set. If any child of a widget wants to
11851 * expand, the parent may ask to expand also.
11853 * This function only looks at the widget's own hexpand flag, rather
11854 * than computing whether the entire widget tree rooted at this widget
11857 * Return value: whether hexpand flag is set
11860 gtk_widget_get_hexpand (GtkWidget *widget)
11862 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11864 return widget->priv->hexpand;
11868 * gtk_widget_set_hexpand:
11869 * @widget: the widget
11870 * @expand: whether to expand
11872 * Sets whether the widget would like any available extra horizontal
11873 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11874 * generally receive the extra space. For example, a list or
11875 * scrollable area or document in your window would often be set to
11878 * Call this function to set the expand flag if you would like your
11879 * widget to become larger horizontally when the window has extra
11882 * By default, widgets automatically expand if any of their children
11883 * want to expand. (To see if a widget will automatically expand given
11884 * its current children and state, call gtk_widget_compute_expand(). A
11885 * container can decide how the expandability of children affects the
11886 * expansion of the container by overriding the compute_expand virtual
11887 * method on #GtkWidget.).
11889 * Setting hexpand explicitly with this function will override the
11890 * automatic expand behavior.
11892 * This function forces the widget to expand or not to expand,
11893 * regardless of children. The override occurs because
11894 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11895 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11896 * value to be used, rather than looking at children and widget state.
11899 gtk_widget_set_hexpand (GtkWidget *widget,
11902 g_return_if_fail (GTK_IS_WIDGET (widget));
11904 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11908 * gtk_widget_get_hexpand_set:
11909 * @widget: the widget
11911 * Gets whether gtk_widget_set_hexpand() has been used to
11912 * explicitly set the expand flag on this widget.
11914 * If hexpand is set, then it overrides any computed
11915 * expand value based on child widgets. If hexpand is not
11916 * set, then the expand value depends on whether any
11917 * children of the widget would like to expand.
11919 * There are few reasons to use this function, but it's here
11920 * for completeness and consistency.
11922 * Return value: whether hexpand has been explicitly set
11925 gtk_widget_get_hexpand_set (GtkWidget *widget)
11927 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11929 return widget->priv->hexpand_set;
11933 * gtk_widget_set_hexpand_set:
11934 * @widget: the widget
11935 * @set: value for hexpand-set property
11937 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11940 * The hexpand-set property will be set automatically when you call
11941 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11942 * reason to use this function would be to unset an explicit expand
11945 * If hexpand is set, then it overrides any computed
11946 * expand value based on child widgets. If hexpand is not
11947 * set, then the expand value depends on whether any
11948 * children of the widget would like to expand.
11950 * There are few reasons to use this function, but it's here
11951 * for completeness and consistency.
11954 gtk_widget_set_hexpand_set (GtkWidget *widget,
11957 g_return_if_fail (GTK_IS_WIDGET (widget));
11959 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11964 * gtk_widget_get_vexpand:
11965 * @widget: the widget
11967 * Gets whether the widget would like any available extra vertical
11970 * See gtk_widget_get_hexpand() for more detail.
11972 * Return value: whether vexpand flag is set
11975 gtk_widget_get_vexpand (GtkWidget *widget)
11977 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11979 return widget->priv->vexpand;
11983 * gtk_widget_set_vexpand:
11984 * @widget: the widget
11985 * @expand: whether to expand
11987 * Sets whether the widget would like any available extra vertical
11990 * See gtk_widget_set_hexpand() for more detail.
11993 gtk_widget_set_vexpand (GtkWidget *widget,
11996 g_return_if_fail (GTK_IS_WIDGET (widget));
11998 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12002 * gtk_widget_get_vexpand_set:
12003 * @widget: the widget
12005 * Gets whether gtk_widget_set_vexpand() has been used to
12006 * explicitly set the expand flag on this widget.
12008 * See gtk_widget_get_hexpand_set() for more detail.
12010 * Return value: whether vexpand has been explicitly set
12013 gtk_widget_get_vexpand_set (GtkWidget *widget)
12015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12017 return widget->priv->vexpand_set;
12021 * gtk_widget_set_vexpand_set:
12022 * @widget: the widget
12023 * @set: value for vexpand-set property
12025 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12028 * See gtk_widget_set_hexpand_set() for more detail.
12031 gtk_widget_set_vexpand_set (GtkWidget *widget,
12034 g_return_if_fail (GTK_IS_WIDGET (widget));
12036 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12040 * GtkBuildable implementation
12042 static GQuark quark_builder_has_default = 0;
12043 static GQuark quark_builder_has_focus = 0;
12044 static GQuark quark_builder_atk_relations = 0;
12045 static GQuark quark_builder_set_name = 0;
12048 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12050 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12051 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12052 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12053 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12055 iface->set_name = gtk_widget_buildable_set_name;
12056 iface->get_name = gtk_widget_buildable_get_name;
12057 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12058 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12059 iface->parser_finished = gtk_widget_buildable_parser_finished;
12060 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12061 iface->custom_finished = gtk_widget_buildable_custom_finished;
12065 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12068 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12069 g_strdup (name), g_free);
12072 static const gchar *
12073 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12075 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12079 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12080 GtkBuilder *builder,
12081 const gchar *childname)
12083 if (strcmp (childname, "accessible") == 0)
12084 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12090 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12091 GtkBuilder *builder,
12093 const GValue *value)
12095 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12096 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12097 GINT_TO_POINTER (TRUE));
12098 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12099 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12100 GINT_TO_POINTER (TRUE));
12102 g_object_set_property (G_OBJECT (buildable), name, value);
12107 gchar *action_name;
12108 GString *description;
12110 gboolean translatable;
12120 free_action (AtkActionData *data, gpointer user_data)
12122 g_free (data->action_name);
12123 g_string_free (data->description, TRUE);
12124 g_free (data->context);
12125 g_slice_free (AtkActionData, data);
12129 free_relation (AtkRelationData *data, gpointer user_data)
12131 g_free (data->target);
12132 g_free (data->type);
12133 g_slice_free (AtkRelationData, data);
12137 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12138 GtkBuilder *builder)
12140 GSList *atk_relations;
12142 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12143 gtk_widget_grab_default (GTK_WIDGET (buildable));
12144 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12145 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12147 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12148 quark_builder_atk_relations);
12151 AtkObject *accessible;
12152 AtkRelationSet *relation_set;
12155 AtkRelationType relation_type;
12156 AtkObject *target_accessible;
12158 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12159 relation_set = atk_object_ref_relation_set (accessible);
12161 for (l = atk_relations; l; l = l->next)
12163 AtkRelationData *relation = (AtkRelationData*)l->data;
12165 target = gtk_builder_get_object (builder, relation->target);
12168 g_warning ("Target object %s in <relation> does not exist",
12172 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12173 g_assert (target_accessible != NULL);
12175 relation_type = atk_relation_type_for_name (relation->type);
12176 if (relation_type == ATK_RELATION_NULL)
12178 g_warning ("<relation> type %s not found",
12182 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12183 target_accessible);
12185 g_object_unref (relation_set);
12187 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12188 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12197 } AccessibilitySubParserData;
12200 accessibility_start_element (GMarkupParseContext *context,
12201 const gchar *element_name,
12202 const gchar **names,
12203 const gchar **values,
12204 gpointer user_data,
12207 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12209 gint line_number, char_number;
12211 if (strcmp (element_name, "relation") == 0)
12213 gchar *target = NULL;
12214 gchar *type = NULL;
12215 AtkRelationData *relation;
12217 for (i = 0; names[i]; i++)
12219 if (strcmp (names[i], "target") == 0)
12220 target = g_strdup (values[i]);
12221 else if (strcmp (names[i], "type") == 0)
12222 type = g_strdup (values[i]);
12225 g_markup_parse_context_get_position (context,
12228 g_set_error (error,
12230 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12231 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12233 line_number, char_number, names[i], "relation");
12240 if (!target || !type)
12242 g_markup_parse_context_get_position (context,
12245 g_set_error (error,
12247 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12248 "%s:%d:%d <%s> requires attribute \"%s\"",
12250 line_number, char_number, "relation",
12251 type ? "target" : "type");
12257 relation = g_slice_new (AtkRelationData);
12258 relation->target = target;
12259 relation->type = type;
12261 data->relations = g_slist_prepend (data->relations, relation);
12263 else if (strcmp (element_name, "action") == 0)
12265 const gchar *action_name = NULL;
12266 const gchar *description = NULL;
12267 const gchar *msg_context = NULL;
12268 gboolean translatable = FALSE;
12269 AtkActionData *action;
12271 for (i = 0; names[i]; i++)
12273 if (strcmp (names[i], "action_name") == 0)
12274 action_name = values[i];
12275 else if (strcmp (names[i], "description") == 0)
12276 description = values[i];
12277 else if (strcmp (names[i], "translatable") == 0)
12279 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12282 else if (strcmp (names[i], "comments") == 0)
12284 /* do nothing, comments are for translators */
12286 else if (strcmp (names[i], "context") == 0)
12287 msg_context = values[i];
12290 g_markup_parse_context_get_position (context,
12293 g_set_error (error,
12295 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12296 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12298 line_number, char_number, names[i], "action");
12305 g_markup_parse_context_get_position (context,
12308 g_set_error (error,
12310 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12311 "%s:%d:%d <%s> requires attribute \"%s\"",
12313 line_number, char_number, "action",
12318 action = g_slice_new (AtkActionData);
12319 action->action_name = g_strdup (action_name);
12320 action->description = g_string_new (description);
12321 action->context = g_strdup (msg_context);
12322 action->translatable = translatable;
12324 data->actions = g_slist_prepend (data->actions, action);
12326 else if (strcmp (element_name, "accessibility") == 0)
12329 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12333 accessibility_text (GMarkupParseContext *context,
12336 gpointer user_data,
12339 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12341 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12343 AtkActionData *action = data->actions->data;
12345 g_string_append_len (action->description, text, text_len);
12349 static const GMarkupParser accessibility_parser =
12351 accessibility_start_element,
12353 accessibility_text,
12362 } AccelGroupParserData;
12365 accel_group_start_element (GMarkupParseContext *context,
12366 const gchar *element_name,
12367 const gchar **names,
12368 const gchar **values,
12369 gpointer user_data,
12374 guint modifiers = 0;
12375 gchar *signal = NULL;
12376 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12378 for (i = 0; names[i]; i++)
12380 if (strcmp (names[i], "key") == 0)
12381 key = gdk_keyval_from_name (values[i]);
12382 else if (strcmp (names[i], "modifiers") == 0)
12384 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12390 else if (strcmp (names[i], "signal") == 0)
12391 signal = g_strdup (values[i]);
12394 if (key == 0 || signal == NULL)
12396 g_warning ("<accelerator> requires key and signal attributes");
12399 parser_data->key = key;
12400 parser_data->modifiers = modifiers;
12401 parser_data->signal = signal;
12404 static const GMarkupParser accel_group_parser =
12406 accel_group_start_element,
12415 style_start_element (GMarkupParseContext *context,
12416 const gchar *element_name,
12417 const gchar **names,
12418 const gchar **values,
12419 gpointer user_data,
12422 StyleParserData *style_data = (StyleParserData *)user_data;
12425 if (strcmp (element_name, "class") == 0)
12427 if (g_markup_collect_attributes (element_name,
12431 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12432 G_MARKUP_COLLECT_INVALID))
12434 style_data->classes = g_slist_append (style_data->classes, class_name);
12437 else if (strcmp (element_name, "style") == 0)
12440 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12443 static const GMarkupParser style_parser =
12445 style_start_element,
12449 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12450 GtkBuilder *builder,
12452 const gchar *tagname,
12453 GMarkupParser *parser,
12456 g_assert (buildable);
12458 if (strcmp (tagname, "accelerator") == 0)
12460 AccelGroupParserData *parser_data;
12462 parser_data = g_slice_new0 (AccelGroupParserData);
12463 parser_data->object = g_object_ref (buildable);
12464 *parser = accel_group_parser;
12465 *data = parser_data;
12468 if (strcmp (tagname, "accessibility") == 0)
12470 AccessibilitySubParserData *parser_data;
12472 parser_data = g_slice_new0 (AccessibilitySubParserData);
12473 *parser = accessibility_parser;
12474 *data = parser_data;
12477 if (strcmp (tagname, "style") == 0)
12479 StyleParserData *parser_data;
12481 parser_data = g_slice_new0 (StyleParserData);
12482 *parser = style_parser;
12483 *data = parser_data;
12491 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12492 GtkWidget *toplevel,
12493 gpointer user_data)
12495 AccelGroupParserData *accel_data;
12496 GSList *accel_groups;
12497 GtkAccelGroup *accel_group;
12499 g_return_if_fail (GTK_IS_WIDGET (widget));
12500 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12501 g_return_if_fail (user_data != NULL);
12503 accel_data = (AccelGroupParserData*)user_data;
12504 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12505 if (g_slist_length (accel_groups) == 0)
12507 accel_group = gtk_accel_group_new ();
12508 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12512 g_assert (g_slist_length (accel_groups) == 1);
12513 accel_group = g_slist_nth_data (accel_groups, 0);
12516 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12517 accel_data->signal,
12520 accel_data->modifiers,
12521 GTK_ACCEL_VISIBLE);
12523 g_object_unref (accel_data->object);
12524 g_free (accel_data->signal);
12525 g_slice_free (AccelGroupParserData, accel_data);
12529 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12530 GtkBuilder *builder,
12532 const gchar *tagname,
12533 gpointer user_data)
12535 if (strcmp (tagname, "accelerator") == 0)
12537 AccelGroupParserData *accel_data;
12538 GtkWidget *toplevel;
12540 accel_data = (AccelGroupParserData*)user_data;
12541 g_assert (accel_data->object);
12543 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12545 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12547 else if (strcmp (tagname, "accessibility") == 0)
12549 AccessibilitySubParserData *a11y_data;
12551 a11y_data = (AccessibilitySubParserData*)user_data;
12553 if (a11y_data->actions)
12555 AtkObject *accessible;
12560 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12562 if (ATK_IS_ACTION (accessible))
12564 action = ATK_ACTION (accessible);
12565 n_actions = atk_action_get_n_actions (action);
12567 for (l = a11y_data->actions; l; l = l->next)
12569 AtkActionData *action_data = (AtkActionData*)l->data;
12571 for (i = 0; i < n_actions; i++)
12572 if (strcmp (atk_action_get_name (action, i),
12573 action_data->action_name) == 0)
12578 gchar *description;
12580 if (action_data->translatable && action_data->description->len)
12581 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12582 action_data->context,
12583 action_data->description->str);
12585 description = action_data->description->str;
12587 atk_action_set_description (action, i, description);
12592 g_warning ("accessibility action on a widget that does not implement AtkAction");
12594 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12597 if (a11y_data->relations)
12598 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12599 a11y_data->relations);
12601 g_slice_free (AccessibilitySubParserData, a11y_data);
12603 else if (strcmp (tagname, "style") == 0)
12605 StyleParserData *style_data = (StyleParserData *)user_data;
12606 GtkStyleContext *context;
12609 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12611 for (l = style_data->classes; l; l = l->next)
12612 gtk_style_context_add_class (context, (const gchar *)l->data);
12614 gtk_widget_reset_style (GTK_WIDGET (buildable));
12616 g_slist_free_full (style_data->classes, g_free);
12617 g_slice_free (StyleParserData, style_data);
12621 static GtkSizeRequestMode
12622 gtk_widget_real_get_request_mode (GtkWidget *widget)
12624 /* By default widgets dont trade size at all. */
12625 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12629 gtk_widget_real_get_width (GtkWidget *widget,
12630 gint *minimum_size,
12631 gint *natural_size)
12641 gtk_widget_real_get_height (GtkWidget *widget,
12642 gint *minimum_size,
12643 gint *natural_size)
12653 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12655 gint *minimum_height,
12656 gint *natural_height)
12658 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12662 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12664 gint *minimum_width,
12665 gint *natural_width)
12667 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12671 * gtk_widget_get_halign:
12672 * @widget: a #GtkWidget
12674 * Gets the value of the #GtkWidget:halign property.
12676 * Returns: the horizontal alignment of @widget
12679 gtk_widget_get_halign (GtkWidget *widget)
12681 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12682 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12686 * gtk_widget_set_halign:
12687 * @widget: a #GtkWidget
12688 * @align: the horizontal alignment
12690 * Sets the horizontal alignment of @widget.
12691 * See the #GtkWidget:halign property.
12694 gtk_widget_set_halign (GtkWidget *widget,
12697 GtkWidgetAuxInfo *aux_info;
12699 g_return_if_fail (GTK_IS_WIDGET (widget));
12701 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12703 if (aux_info->halign == align)
12706 aux_info->halign = align;
12707 gtk_widget_queue_resize (widget);
12708 g_object_notify (G_OBJECT (widget), "halign");
12712 * gtk_widget_get_valign:
12713 * @widget: a #GtkWidget
12715 * Gets the value of the #GtkWidget:valign property.
12717 * Returns: the vertical alignment of @widget
12720 gtk_widget_get_valign (GtkWidget *widget)
12722 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12723 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12727 * gtk_widget_set_valign:
12728 * @widget: a #GtkWidget
12729 * @align: the vertical alignment
12731 * Sets the vertical alignment of @widget.
12732 * See the #GtkWidget:valign property.
12735 gtk_widget_set_valign (GtkWidget *widget,
12738 GtkWidgetAuxInfo *aux_info;
12740 g_return_if_fail (GTK_IS_WIDGET (widget));
12742 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12744 if (aux_info->valign == align)
12747 aux_info->valign = align;
12748 gtk_widget_queue_resize (widget);
12749 g_object_notify (G_OBJECT (widget), "valign");
12753 * gtk_widget_get_margin_left:
12754 * @widget: a #GtkWidget
12756 * Gets the value of the #GtkWidget:margin-left property.
12758 * Returns: The left margin of @widget
12763 gtk_widget_get_margin_left (GtkWidget *widget)
12765 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12767 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12771 * gtk_widget_set_margin_left:
12772 * @widget: a #GtkWidget
12773 * @margin: the left margin
12775 * Sets the left margin of @widget.
12776 * See the #GtkWidget:margin-left property.
12781 gtk_widget_set_margin_left (GtkWidget *widget,
12784 GtkWidgetAuxInfo *aux_info;
12786 g_return_if_fail (GTK_IS_WIDGET (widget));
12787 g_return_if_fail (margin <= G_MAXINT16);
12789 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12791 if (aux_info->margin.left == margin)
12794 aux_info->margin.left = margin;
12795 gtk_widget_queue_resize (widget);
12796 g_object_notify (G_OBJECT (widget), "margin-left");
12800 * gtk_widget_get_margin_right:
12801 * @widget: a #GtkWidget
12803 * Gets the value of the #GtkWidget:margin-right property.
12805 * Returns: The right margin of @widget
12810 gtk_widget_get_margin_right (GtkWidget *widget)
12812 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12814 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12818 * gtk_widget_set_margin_right:
12819 * @widget: a #GtkWidget
12820 * @margin: the right margin
12822 * Sets the right margin of @widget.
12823 * See the #GtkWidget:margin-right property.
12828 gtk_widget_set_margin_right (GtkWidget *widget,
12831 GtkWidgetAuxInfo *aux_info;
12833 g_return_if_fail (GTK_IS_WIDGET (widget));
12834 g_return_if_fail (margin <= G_MAXINT16);
12836 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12838 if (aux_info->margin.right == margin)
12841 aux_info->margin.right = margin;
12842 gtk_widget_queue_resize (widget);
12843 g_object_notify (G_OBJECT (widget), "margin-right");
12847 * gtk_widget_get_margin_top:
12848 * @widget: a #GtkWidget
12850 * Gets the value of the #GtkWidget:margin-top property.
12852 * Returns: The top margin of @widget
12857 gtk_widget_get_margin_top (GtkWidget *widget)
12859 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12861 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12865 * gtk_widget_set_margin_top:
12866 * @widget: a #GtkWidget
12867 * @margin: the top margin
12869 * Sets the top margin of @widget.
12870 * See the #GtkWidget:margin-top property.
12875 gtk_widget_set_margin_top (GtkWidget *widget,
12878 GtkWidgetAuxInfo *aux_info;
12880 g_return_if_fail (GTK_IS_WIDGET (widget));
12881 g_return_if_fail (margin <= G_MAXINT16);
12883 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12885 if (aux_info->margin.top == margin)
12888 aux_info->margin.top = margin;
12889 gtk_widget_queue_resize (widget);
12890 g_object_notify (G_OBJECT (widget), "margin-top");
12894 * gtk_widget_get_margin_bottom:
12895 * @widget: a #GtkWidget
12897 * Gets the value of the #GtkWidget:margin-bottom property.
12899 * Returns: The bottom margin of @widget
12904 gtk_widget_get_margin_bottom (GtkWidget *widget)
12906 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12908 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12912 * gtk_widget_set_margin_bottom:
12913 * @widget: a #GtkWidget
12914 * @margin: the bottom margin
12916 * Sets the bottom margin of @widget.
12917 * See the #GtkWidget:margin-bottom property.
12922 gtk_widget_set_margin_bottom (GtkWidget *widget,
12925 GtkWidgetAuxInfo *aux_info;
12927 g_return_if_fail (GTK_IS_WIDGET (widget));
12928 g_return_if_fail (margin <= G_MAXINT16);
12930 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12932 if (aux_info->margin.bottom == margin)
12935 aux_info->margin.bottom = margin;
12936 gtk_widget_queue_resize (widget);
12937 g_object_notify (G_OBJECT (widget), "margin-bottom");
12941 * gtk_widget_get_clipboard:
12942 * @widget: a #GtkWidget
12943 * @selection: a #GdkAtom which identifies the clipboard
12944 * to use. %GDK_SELECTION_CLIPBOARD gives the
12945 * default clipboard. Another common value
12946 * is %GDK_SELECTION_PRIMARY, which gives
12947 * the primary X selection.
12949 * Returns the clipboard object for the given selection to
12950 * be used with @widget. @widget must have a #GdkDisplay
12951 * associated with it, so must be attached to a toplevel
12954 * Return value: (transfer none): the appropriate clipboard object. If no
12955 * clipboard already exists, a new one will
12956 * be created. Once a clipboard object has
12957 * been created, it is persistent for all time.
12962 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12964 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12965 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12967 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12972 * gtk_widget_list_mnemonic_labels:
12973 * @widget: a #GtkWidget
12975 * Returns a newly allocated list of the widgets, normally labels, for
12976 * which this widget is the target of a mnemonic (see for example,
12977 * gtk_label_set_mnemonic_widget()).
12979 * The widgets in the list are not individually referenced. If you
12980 * want to iterate through the list and perform actions involving
12981 * callbacks that might destroy the widgets, you
12982 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12983 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12984 * widgets afterwards.
12986 * Return value: (element-type GtkWidget) (transfer container): the list of
12987 * mnemonic labels; free this list
12988 * with g_list_free() when you are done with it.
12993 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12995 GList *list = NULL;
12998 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13000 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13001 list = g_list_prepend (list, l->data);
13007 * gtk_widget_add_mnemonic_label:
13008 * @widget: a #GtkWidget
13009 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13011 * Adds a widget to the list of mnemonic labels for
13012 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13013 * list of mnemonic labels for the widget is cleared when the
13014 * widget is destroyed, so the caller must make sure to update
13015 * its internal state at this point as well, by using a connection
13016 * to the #GtkWidget::destroy signal or a weak notifier.
13021 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13024 GSList *old_list, *new_list;
13026 g_return_if_fail (GTK_IS_WIDGET (widget));
13027 g_return_if_fail (GTK_IS_WIDGET (label));
13029 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13030 new_list = g_slist_prepend (old_list, label);
13032 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13033 new_list, (GDestroyNotify) g_slist_free);
13037 * gtk_widget_remove_mnemonic_label:
13038 * @widget: a #GtkWidget
13039 * @label: a #GtkWidget that was previously set as a mnemnic label for
13040 * @widget with gtk_widget_add_mnemonic_label().
13042 * Removes a widget from the list of mnemonic labels for
13043 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13044 * must have previously been added to the list with
13045 * gtk_widget_add_mnemonic_label().
13050 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13053 GSList *old_list, *new_list;
13055 g_return_if_fail (GTK_IS_WIDGET (widget));
13056 g_return_if_fail (GTK_IS_WIDGET (label));
13058 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13059 new_list = g_slist_remove (old_list, label);
13062 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13063 new_list, (GDestroyNotify) g_slist_free);
13067 * gtk_widget_get_no_show_all:
13068 * @widget: a #GtkWidget
13070 * Returns the current value of the #GtkWidget:no-show-all property,
13071 * which determines whether calls to gtk_widget_show_all()
13072 * will affect this widget.
13074 * Return value: the current value of the "no-show-all" property.
13079 gtk_widget_get_no_show_all (GtkWidget *widget)
13081 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13083 return widget->priv->no_show_all;
13087 * gtk_widget_set_no_show_all:
13088 * @widget: a #GtkWidget
13089 * @no_show_all: the new value for the "no-show-all" property
13091 * Sets the #GtkWidget:no-show-all property, which determines whether
13092 * calls to gtk_widget_show_all() will affect this widget.
13094 * This is mostly for use in constructing widget hierarchies with externally
13095 * controlled visibility, see #GtkUIManager.
13100 gtk_widget_set_no_show_all (GtkWidget *widget,
13101 gboolean no_show_all)
13103 g_return_if_fail (GTK_IS_WIDGET (widget));
13105 no_show_all = (no_show_all != FALSE);
13107 if (widget->priv->no_show_all != no_show_all)
13109 widget->priv->no_show_all = no_show_all;
13111 g_object_notify (G_OBJECT (widget), "no-show-all");
13117 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13118 gboolean has_tooltip,
13121 GtkWidgetPrivate *priv = widget->priv;
13122 gboolean priv_has_tooltip;
13124 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13125 quark_has_tooltip));
13127 if (priv_has_tooltip != has_tooltip || force)
13129 priv_has_tooltip = has_tooltip;
13131 if (priv_has_tooltip)
13133 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13134 gdk_window_set_events (priv->window,
13135 gdk_window_get_events (priv->window) |
13136 GDK_LEAVE_NOTIFY_MASK |
13137 GDK_POINTER_MOTION_MASK |
13138 GDK_POINTER_MOTION_HINT_MASK);
13140 if (gtk_widget_get_has_window (widget))
13141 gtk_widget_add_events (widget,
13142 GDK_LEAVE_NOTIFY_MASK |
13143 GDK_POINTER_MOTION_MASK |
13144 GDK_POINTER_MOTION_HINT_MASK);
13147 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13148 GUINT_TO_POINTER (priv_has_tooltip));
13153 * gtk_widget_set_tooltip_window:
13154 * @widget: a #GtkWidget
13155 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13157 * Replaces the default, usually yellow, window used for displaying
13158 * tooltips with @custom_window. GTK+ will take care of showing and
13159 * hiding @custom_window at the right moment, to behave likewise as
13160 * the default tooltip window. If @custom_window is %NULL, the default
13161 * tooltip window will be used.
13163 * If the custom window should have the default theming it needs to
13164 * have the name "gtk-tooltip", see gtk_widget_set_name().
13169 gtk_widget_set_tooltip_window (GtkWidget *widget,
13170 GtkWindow *custom_window)
13172 gboolean has_tooltip;
13173 gchar *tooltip_markup;
13175 g_return_if_fail (GTK_IS_WIDGET (widget));
13176 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13178 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13181 g_object_ref (custom_window);
13183 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13184 custom_window, g_object_unref);
13186 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13187 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13189 if (has_tooltip && gtk_widget_get_visible (widget))
13190 gtk_widget_queue_tooltip_query (widget);
13194 * gtk_widget_get_tooltip_window:
13195 * @widget: a #GtkWidget
13197 * Returns the #GtkWindow of the current tooltip. This can be the
13198 * GtkWindow created by default, or the custom tooltip window set
13199 * using gtk_widget_set_tooltip_window().
13201 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13206 gtk_widget_get_tooltip_window (GtkWidget *widget)
13208 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13210 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13214 * gtk_widget_trigger_tooltip_query:
13215 * @widget: a #GtkWidget
13217 * Triggers a tooltip query on the display where the toplevel of @widget
13218 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13224 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13226 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13229 static guint tooltip_query_id;
13230 static GSList *tooltip_query_displays;
13233 tooltip_query_idle (gpointer data)
13235 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13236 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13237 g_slist_free (tooltip_query_displays);
13239 tooltip_query_displays = NULL;
13240 tooltip_query_id = 0;
13246 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13248 GdkDisplay *display;
13250 display = gtk_widget_get_display (widget);
13252 if (!g_slist_find (tooltip_query_displays, display))
13253 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13255 if (tooltip_query_id == 0)
13256 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13260 * gtk_widget_set_tooltip_text:
13261 * @widget: a #GtkWidget
13262 * @text: the contents of the tooltip for @widget
13264 * Sets @text as the contents of the tooltip. This function will take
13265 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13266 * handler for the #GtkWidget::query-tooltip signal.
13268 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13273 gtk_widget_set_tooltip_text (GtkWidget *widget,
13276 g_return_if_fail (GTK_IS_WIDGET (widget));
13278 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13282 * gtk_widget_get_tooltip_text:
13283 * @widget: a #GtkWidget
13285 * Gets the contents of the tooltip for @widget.
13287 * Return value: the tooltip text, or %NULL. You should free the
13288 * returned string with g_free() when done.
13293 gtk_widget_get_tooltip_text (GtkWidget *widget)
13295 gchar *text = NULL;
13297 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13299 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13305 * gtk_widget_set_tooltip_markup:
13306 * @widget: a #GtkWidget
13307 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13309 * Sets @markup as the contents of the tooltip, which is marked up with
13310 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13312 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13313 * and of the default handler for the #GtkWidget::query-tooltip signal.
13315 * See also the #GtkWidget:tooltip-markup property and
13316 * gtk_tooltip_set_markup().
13321 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13322 const gchar *markup)
13324 g_return_if_fail (GTK_IS_WIDGET (widget));
13326 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13330 * gtk_widget_get_tooltip_markup:
13331 * @widget: a #GtkWidget
13333 * Gets the contents of the tooltip for @widget.
13335 * Return value: the tooltip text, or %NULL. You should free the
13336 * returned string with g_free() when done.
13341 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13343 gchar *text = NULL;
13345 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13347 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13353 * gtk_widget_set_has_tooltip:
13354 * @widget: a #GtkWidget
13355 * @has_tooltip: whether or not @widget has a tooltip.
13357 * Sets the has-tooltip property on @widget to @has_tooltip. See
13358 * #GtkWidget:has-tooltip for more information.
13363 gtk_widget_set_has_tooltip (GtkWidget *widget,
13364 gboolean has_tooltip)
13366 g_return_if_fail (GTK_IS_WIDGET (widget));
13368 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13372 * gtk_widget_get_has_tooltip:
13373 * @widget: a #GtkWidget
13375 * Returns the current value of the has-tooltip property. See
13376 * #GtkWidget:has-tooltip for more information.
13378 * Return value: current value of has-tooltip on @widget.
13383 gtk_widget_get_has_tooltip (GtkWidget *widget)
13385 gboolean has_tooltip = FALSE;
13387 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13389 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13391 return has_tooltip;
13395 * gtk_widget_get_allocation:
13396 * @widget: a #GtkWidget
13397 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13399 * Retrieves the widget's allocation.
13401 * Note, when implementing a #GtkContainer: a widget's allocation will
13402 * be its "adjusted" allocation, that is, the widget's parent
13403 * container typically calls gtk_widget_size_allocate() with an
13404 * allocation, and that allocation is then adjusted (to handle margin
13405 * and alignment for example) before assignment to the widget.
13406 * gtk_widget_get_allocation() returns the adjusted allocation that
13407 * was actually assigned to the widget. The adjusted allocation is
13408 * guaranteed to be completely contained within the
13409 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13410 * is guaranteed that its children stay inside the assigned bounds,
13411 * but not that they have exactly the bounds the container assigned.
13412 * There is no way to get the original allocation assigned by
13413 * gtk_widget_size_allocate(), since it isn't stored; if a container
13414 * implementation needs that information it will have to track it itself.
13419 gtk_widget_get_allocation (GtkWidget *widget,
13420 GtkAllocation *allocation)
13422 GtkWidgetPrivate *priv;
13424 g_return_if_fail (GTK_IS_WIDGET (widget));
13425 g_return_if_fail (allocation != NULL);
13427 priv = widget->priv;
13429 *allocation = priv->allocation;
13433 * gtk_widget_set_allocation:
13434 * @widget: a #GtkWidget
13435 * @allocation: a pointer to a #GtkAllocation to copy from
13437 * Sets the widget's allocation. This should not be used
13438 * directly, but from within a widget's size_allocate method.
13440 * The allocation set should be the "adjusted" or actual
13441 * allocation. If you're implementing a #GtkContainer, you want to use
13442 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13443 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13444 * allocation inside gtk_widget_size_allocate() to create an adjusted
13450 gtk_widget_set_allocation (GtkWidget *widget,
13451 const GtkAllocation *allocation)
13453 GtkWidgetPrivate *priv;
13455 g_return_if_fail (GTK_IS_WIDGET (widget));
13456 g_return_if_fail (allocation != NULL);
13458 priv = widget->priv;
13460 priv->allocation = *allocation;
13464 * gtk_widget_get_allocated_width:
13465 * @widget: the widget to query
13467 * Returns the width that has currently been allocated to @widget.
13468 * This function is intended to be used when implementing handlers
13469 * for the #GtkWidget::draw function.
13471 * Returns: the width of the @widget
13474 gtk_widget_get_allocated_width (GtkWidget *widget)
13476 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13478 return widget->priv->allocation.width;
13482 * gtk_widget_get_allocated_height:
13483 * @widget: the widget to query
13485 * Returns the height that has currently been allocated to @widget.
13486 * This function is intended to be used when implementing handlers
13487 * for the #GtkWidget::draw function.
13489 * Returns: the height of the @widget
13492 gtk_widget_get_allocated_height (GtkWidget *widget)
13494 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13496 return widget->priv->allocation.height;
13500 * gtk_widget_get_requisition:
13501 * @widget: a #GtkWidget
13502 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13504 * Retrieves the widget's requisition.
13506 * This function should only be used by widget implementations in
13507 * order to figure whether the widget's requisition has actually
13508 * changed after some internal state change (so that they can call
13509 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13511 * Normally, gtk_widget_size_request() should be used.
13515 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13516 * removed, If you need to cache sizes across requests and allocations,
13517 * add an explicit cache to the widget in question instead.
13520 gtk_widget_get_requisition (GtkWidget *widget,
13521 GtkRequisition *requisition)
13523 g_return_if_fail (GTK_IS_WIDGET (widget));
13524 g_return_if_fail (requisition != NULL);
13526 gtk_widget_get_preferred_size (widget, requisition, NULL);
13530 * gtk_widget_set_window:
13531 * @widget: a #GtkWidget
13532 * @window: (transfer full): a #GdkWindow
13534 * Sets a widget's window. This function should only be used in a
13535 * widget's #GtkWidget::realize implementation. The %window passed is
13536 * usually either new window created with gdk_window_new(), or the
13537 * window of its parent widget as returned by
13538 * gtk_widget_get_parent_window().
13540 * Widgets must indicate whether they will create their own #GdkWindow
13541 * by calling gtk_widget_set_has_window(). This is usually done in the
13542 * widget's init() function.
13544 * <note><para>This function does not add any reference to @window.</para></note>
13549 gtk_widget_set_window (GtkWidget *widget,
13552 GtkWidgetPrivate *priv;
13554 g_return_if_fail (GTK_IS_WIDGET (widget));
13555 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13557 priv = widget->priv;
13559 if (priv->window != window)
13561 priv->window = window;
13562 g_object_notify (G_OBJECT (widget), "window");
13567 * gtk_widget_get_window:
13568 * @widget: a #GtkWidget
13570 * Returns the widget's window if it is realized, %NULL otherwise
13572 * Return value: (transfer none): @widget's window.
13577 gtk_widget_get_window (GtkWidget *widget)
13579 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13581 return widget->priv->window;
13585 * gtk_widget_get_support_multidevice:
13586 * @widget: a #GtkWidget
13588 * Returns %TRUE if @widget is multiple pointer aware. See
13589 * gtk_widget_set_support_multidevice() for more information.
13591 * Returns: %TRUE if @widget is multidevice aware.
13594 gtk_widget_get_support_multidevice (GtkWidget *widget)
13596 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13598 return widget->priv->multidevice;
13602 * gtk_widget_set_support_multidevice:
13603 * @widget: a #GtkWidget
13604 * @support_multidevice: %TRUE to support input from multiple devices.
13606 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13607 * @widget will start receiving multiple, per device enter/leave events. Note
13608 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13609 * gdk_window_set_support_multidevice() will have to be called manually on them.
13614 gtk_widget_set_support_multidevice (GtkWidget *widget,
13615 gboolean support_multidevice)
13617 GtkWidgetPrivate *priv;
13619 g_return_if_fail (GTK_IS_WIDGET (widget));
13621 priv = widget->priv;
13622 priv->multidevice = (support_multidevice == TRUE);
13624 if (gtk_widget_get_realized (widget))
13625 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13629 _gtk_widget_set_has_focus (GtkWidget *widget,
13630 gboolean has_focus)
13632 widget->priv->has_focus = has_focus;
13635 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13637 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13641 * gtk_widget_send_focus_change:
13642 * @widget: a #GtkWidget
13643 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13645 * Sends the focus change @event to @widget
13647 * This function is not meant to be used by applications. The only time it
13648 * should be used is when it is necessary for a #GtkWidget to assign focus
13649 * to a widget that is semantically owned by the first widget even though
13650 * it's not a direct child - for instance, a search entry in a floating
13651 * window similar to the quick search in #GtkTreeView.
13653 * An example of its usage is:
13656 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13658 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13659 * fevent->focus_change.in = TRUE;
13660 * fevent->focus_change.window = gtk_widget_get_window (widget);
13661 * if (fevent->focus_change.window != NULL)
13662 * g_object_ref (fevent->focus_change.window);
13664 * gtk_widget_send_focus_change (widget, fevent);
13666 * gdk_event_free (event);
13669 * Return value: the return value from the event signal emission: %TRUE
13670 * if the event was handled, and %FALSE otherwise
13675 gtk_widget_send_focus_change (GtkWidget *widget,
13680 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13681 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13683 g_object_ref (widget);
13685 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13687 res = gtk_widget_event (widget, event);
13689 g_object_notify (G_OBJECT (widget), "has-focus");
13691 g_object_unref (widget);
13697 * gtk_widget_in_destruction:
13698 * @widget: a #GtkWidget
13700 * Returns whether the widget is currently being destroyed.
13701 * This information can sometimes be used to avoid doing
13702 * unnecessary work.
13704 * Returns: %TRUE if @widget is being destroyed
13707 gtk_widget_in_destruction (GtkWidget *widget)
13709 return widget->priv->in_destruction;
13713 _gtk_widget_get_in_reparent (GtkWidget *widget)
13715 return widget->priv->in_reparent;
13719 _gtk_widget_set_in_reparent (GtkWidget *widget,
13720 gboolean in_reparent)
13722 widget->priv->in_reparent = in_reparent;
13726 _gtk_widget_get_anchored (GtkWidget *widget)
13728 return widget->priv->anchored;
13732 _gtk_widget_set_anchored (GtkWidget *widget,
13735 widget->priv->anchored = anchored;
13739 _gtk_widget_get_shadowed (GtkWidget *widget)
13741 return widget->priv->shadowed;
13745 _gtk_widget_set_shadowed (GtkWidget *widget,
13748 widget->priv->shadowed = shadowed;
13752 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13754 return widget->priv->alloc_needed;
13758 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13759 gboolean alloc_needed)
13761 widget->priv->alloc_needed = alloc_needed;
13765 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13767 return widget->priv->width_request_needed;
13771 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13772 gboolean width_request_needed)
13774 widget->priv->width_request_needed = width_request_needed;
13778 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13780 return widget->priv->height_request_needed;
13784 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13785 gboolean height_request_needed)
13787 widget->priv->height_request_needed = height_request_needed;
13791 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13793 return widget->priv->sizegroup_visited;
13797 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13800 widget->priv->sizegroup_visited = visited;
13804 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13806 return widget->priv->sizegroup_bumping;
13810 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13813 widget->priv->sizegroup_bumping = bumping;
13817 _gtk_widget_add_sizegroup (GtkWidget *widget,
13822 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13823 groups = g_slist_prepend (groups, group);
13824 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13826 widget->priv->have_size_groups = TRUE;
13830 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13835 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13836 groups = g_slist_remove (groups, group);
13837 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13839 widget->priv->have_size_groups = groups != NULL;
13843 _gtk_widget_get_sizegroups (GtkWidget *widget)
13845 if (widget->priv->have_size_groups)
13846 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13852 _gtk_widget_add_attached_window (GtkWidget *widget,
13855 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13859 _gtk_widget_remove_attached_window (GtkWidget *widget,
13862 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13866 * gtk_widget_path_append_for_widget:
13867 * @path: a widget path
13868 * @widget: the widget to append to the widget path
13870 * Appends the data from @widget to the widget hierarchy represented
13871 * by @path. This function is a shortcut for adding information from
13872 * @widget to the given @path. This includes setting the name or
13873 * adding the style classes from @widget.
13875 * Returns: the position where the data was inserted
13880 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13885 g_return_val_if_fail (path != NULL, 0);
13886 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13888 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13890 if (widget->priv->name)
13891 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13893 if (widget->priv->context)
13895 GList *classes, *l;
13897 /* Also add any persistent classes in
13898 * the style context the widget path
13900 classes = gtk_style_context_list_classes (widget->priv->context);
13902 for (l = classes; l; l = l->next)
13903 gtk_widget_path_iter_add_class (path, pos, l->data);
13905 g_list_free (classes);
13912 _gtk_widget_create_path (GtkWidget *widget)
13916 parent = widget->priv->parent;
13919 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13922 /* Widget is either toplevel or unparented, treat both
13923 * as toplevels style wise, since there are situations
13924 * where style properties might be retrieved on that
13927 GtkWidget *attach_widget = NULL;
13928 GtkWidgetPath *result;
13930 if (GTK_IS_WINDOW (widget))
13931 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13933 if (attach_widget != NULL)
13934 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13936 result = gtk_widget_path_new ();
13938 gtk_widget_path_append_for_widget (result, widget);
13945 * gtk_widget_get_path:
13946 * @widget: a #GtkWidget
13948 * Returns the #GtkWidgetPath representing @widget, if the widget
13949 * is not connected to a toplevel widget, a partial path will be
13952 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13955 gtk_widget_get_path (GtkWidget *widget)
13957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13959 if (!widget->priv->path)
13960 widget->priv->path = _gtk_widget_create_path (widget);
13962 return widget->priv->path;
13966 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13968 if (widget->priv->path)
13970 gtk_widget_path_free (widget->priv->path);
13971 widget->priv->path = NULL;
13974 if (gtk_widget_get_realized (widget))
13975 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13978 /* Compress all style updates so it
13979 * is only emitted once pre-realize.
13981 widget->priv->style_update_pending = TRUE;
13984 if (widget->priv->anchored)
13985 gtk_widget_queue_resize (widget);
13989 * gtk_widget_get_style_context:
13990 * @widget: a #GtkWidget
13992 * Returns the style context associated to @widget.
13994 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13995 * must not be freed.
13998 gtk_widget_get_style_context (GtkWidget *widget)
14000 GtkWidgetPrivate *priv;
14002 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14004 priv = widget->priv;
14006 if (G_UNLIKELY (priv->context == NULL))
14010 priv->context = gtk_style_context_new ();
14012 gtk_style_context_set_direction (priv->context, gtk_widget_get_direction (widget));
14014 screen = gtk_widget_get_screen (widget);
14016 gtk_style_context_set_screen (priv->context, screen);
14019 gtk_style_context_set_parent (priv->context,
14020 gtk_widget_get_style_context (priv->parent));
14022 _gtk_style_context_set_widget (priv->context, widget);
14025 return widget->priv->context;
14029 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14030 GtkCssChange change)
14032 GtkWidgetPrivate *priv;
14034 priv = widget->priv;
14036 if (priv->context == NULL)
14039 _gtk_style_context_queue_invalidate (priv->context, change);
14043 * gtk_widget_get_modifier_mask:
14044 * @widget: a #GtkWidget
14045 * @intent: the use case for the modifier mask
14047 * Returns the modifier mask the @widget's windowing system backend
14048 * uses for a particular purpose.
14050 * See gdk_keymap_get_modifier_mask().
14052 * Returns: the modifier mask used for @intent.
14057 gtk_widget_get_modifier_mask (GtkWidget *widget,
14058 GdkModifierIntent intent)
14060 GdkDisplay *display;
14062 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14064 display = gtk_widget_get_display (widget);
14066 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14071 _gtk_widget_get_style (GtkWidget *widget)
14073 return widget->priv->style;
14077 _gtk_widget_set_style (GtkWidget *widget,
14080 widget->priv->style = style;
14084 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14087 GActionMuxer *parent_muxer;
14089 if (widget->priv->muxer == NULL)
14092 if (GTK_IS_MENU (widget))
14093 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14095 parent = gtk_widget_get_parent (widget);
14097 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14099 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14103 _gtk_widget_get_action_muxer (GtkWidget *widget)
14105 if (widget->priv->muxer == NULL)
14107 widget->priv->muxer = g_action_muxer_new ();
14108 _gtk_widget_update_parent_muxer (widget);
14111 return widget->priv->muxer;
14115 * gtk_widget_insert_action_group:
14116 * @widget: a #GtkWidget
14117 * @name: the prefix for actions in @group
14118 * @group: a #GActionGroup
14120 * Inserts @group into @widget. Children of @widget that implement
14121 * #GtkActionable can then be associated with actions in @group by
14122 * setting their 'action-name' to
14123 * @prefix.<replaceable>action-name</replaceable>.
14128 gtk_widget_insert_action_group (GtkWidget *widget,
14130 GActionGroup *group)
14132 GActionMuxer *muxer;
14134 g_return_if_fail (GTK_IS_WIDGET (widget));
14135 g_return_if_fail (name != NULL);
14137 muxer = _gtk_widget_get_action_muxer (widget);
14140 g_action_muxer_insert (muxer, name, group);
14142 g_action_muxer_remove (muxer, name);