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 "gtkcssstylepropertyprivate.h"
39 #include "gtkiconfactory.h"
41 #include "gtkmarshalers.h"
42 #include "gtkselectionprivate.h"
43 #include "gtksettingsprivate.h"
44 #include "gtksizegroup-private.h"
45 #include "gtksizerequestcacheprivate.h"
46 #include "gtkwidget.h"
47 #include "gtkwidgetprivate.h"
48 #include "gtkwindowprivate.h"
49 #include "gtkcontainerprivate.h"
50 #include "gtkbindings.h"
51 #include "gtkprivate.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltip.h"
54 #include "gtkinvisible.h"
55 #include "gtkbuildable.h"
56 #include "gtkbuilderprivate.h"
57 #include "gtksizerequest.h"
58 #include "gtkstylecontextprivate.h"
59 #include "gtkcssprovider.h"
60 #include "gtkmodifierstyle.h"
61 #include "gtkversion.h"
64 #include "gtktypebuiltins.h"
65 #include "a11y/gtkwidgetaccessible.h"
69 * @Short_description: Base class for all widgets
72 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
73 * widget lifecycle, states and style.
75 * <refsect2 id="geometry-management">
76 * <title>Height-for-width Geometry Management</title>
78 * GTK+ uses a height-for-width (and width-for-height) geometry management
79 * system. Height-for-width means that a widget can change how much
80 * vertical space it needs, depending on the amount of horizontal space
81 * that it is given (and similar for width-for-height). The most common
82 * example is a label that reflows to fill up the available width, wraps
83 * to fewer lines, and therefore needs less height.
85 * Height-for-width geometry management is implemented in GTK+ by way
86 * of five virtual methods:
88 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
95 * There are some important things to keep in mind when implementing
96 * height-for-width and when using it in container implementations.
98 * The geometry management system will query a widget hierarchy in
99 * only one orientation at a time. When widgets are initially queried
100 * for their minimum sizes it is generally done in two initial passes
101 * in the #GtkSizeRequestMode chosen by the toplevel.
103 * For example, when queried in the normal
104 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
105 * First, the default minimum and natural width for each widget
106 * in the interface will be computed using gtk_widget_get_preferred_width().
107 * Because the preferred widths for each container depend on the preferred
108 * widths of their children, this information propagates up the hierarchy,
109 * and finally a minimum and natural width is determined for the entire
110 * toplevel. Next, the toplevel will use the minimum width to query for the
111 * minimum height contextual to that width using
112 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
113 * recursive operation. The minimum height for the minimum width is normally
114 * used to set the minimum size constraint on the toplevel
115 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
117 * After the toplevel window has initially requested its size in both
118 * dimensions it can go on to allocate itself a reasonable size (or a size
119 * previously specified with gtk_window_set_default_size()). During the
120 * recursive allocation process it's important to note that request cycles
121 * will be recursively executed while container widgets allocate their children.
122 * Each container widget, once allocated a size, will go on to first share the
123 * space in one orientation among its children and then request each child's
124 * height for its target allocated width or its width for allocated height,
125 * depending. In this way a #GtkWidget will typically be requested its size
126 * a number of times before actually being allocated a size. The size a
127 * widget is finally allocated can of course differ from the size it has
128 * requested. For this reason, #GtkWidget caches a small number of results
129 * to avoid re-querying for the same sizes in one allocation cycle.
131 * See <link linkend="container-geometry-management">GtkContainer's
132 * geometry management section</link>
133 * to learn more about how height-for-width allocations are performed
134 * by container widgets.
136 * If a widget does move content around to intelligently use up the
137 * allocated size then it must support the request in both
138 * #GtkSizeRequestModes even if the widget in question only
139 * trades sizes in a single orientation.
141 * For instance, a #GtkLabel that does height-for-width word wrapping
142 * will not expect to have #GtkWidgetClass.get_preferred_height() called
143 * because that call is specific to a width-for-height request. In this
144 * case the label must return the height required for its own minimum
145 * possible width. By following this rule any widget that handles
146 * height-for-width or width-for-height requests will always be allocated
147 * at least enough space to fit its own content.
149 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
150 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
152 * <programlisting><![CDATA[
154 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
156 * if (i_am_in_height_for_width_mode)
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
162 * min_height, nat_height);
166 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
167 * it will return the minimum and natural height for the rotated label here.
170 * ]]></programlisting>
172 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
173 * the minimum and natural width:
175 * <programlisting><![CDATA[
177 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
178 * gint *min_width, gint *nat_width)
180 * if (i_am_in_height_for_width_mode)
182 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
186 * ... again if a widget is sometimes operating in width-for-height mode
187 * (like a rotated GtkLabel) it can go ahead and do its real width for
188 * height calculation here.
191 * ]]></programlisting>
193 * Often a widget needs to get its own request during size request or
194 * allocation. For example, when computing height it may need to also
195 * compute width. Or when deciding how to use an allocation, the widget
196 * may need to know its natural size. In these cases, the widget should
197 * be careful to call its virtual methods directly, like this:
199 * <title>Widget calling its own size request method.</title>
201 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
206 * It will not work to use the wrapper functions, such as
207 * gtk_widget_get_preferred_width() inside your own size request
208 * implementation. These return a request adjusted by #GtkSizeGroup
209 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
210 * widget used the wrappers inside its virtual method implementations,
211 * then the adjustments (such as widget margins) would be applied
212 * twice. GTK+ therefore does not allow this and will warn if you try
215 * Of course if you are getting the size request for
216 * <emphasis>another</emphasis> widget, such as a child of a
217 * container, you <emphasis>must</emphasis> use the wrapper APIs.
218 * Otherwise, you would not properly consider widget margins,
219 * #GtkSizeGroup, and so forth.
222 * <refsect2 id="style-properties">
223 * <title>Style Properties</title>
225 * <structname>GtkWidget</structname> introduces <firstterm>style
226 * properties</firstterm> - these are basically object properties that are stored
227 * not on the object, but in the style object associated to the widget. Style
228 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
229 * This mechanism is used for configuring such things as the location of the
230 * scrollbar arrows through the theme, giving theme authors more control over the
231 * look of applications without the need to write a theme engine in C.
234 * Use gtk_widget_class_install_style_property() to install style properties for
235 * a widget class, gtk_widget_class_find_style_property() or
236 * gtk_widget_class_list_style_properties() to get information about existing
237 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
238 * gtk_widget_style_get_valist() to obtain the value of a style property.
241 * <refsect2 id="GtkWidget-BUILDER-UI">
242 * <title>GtkWidget as GtkBuildable</title>
244 * The GtkWidget implementation of the GtkBuildable interface supports a
245 * custom <accelerator> element, which has attributes named key,
246 * modifiers and signal and allows to specify accelerators.
249 * <title>A UI definition fragment specifying an accelerator</title>
250 * <programlisting><![CDATA[
251 * <object class="GtkButton">
252 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
254 * ]]></programlisting>
257 * In addition to accelerators, <structname>GtkWidget</structname> also support a
258 * custom <accessible> element, which supports actions and relations.
259 * Properties on the accessible implementation of an object can be set by accessing the
260 * internal child "accessible" of a <structname>GtkWidget</structname>.
263 * <title>A UI definition fragment specifying an accessible</title>
264 * <programlisting><![CDATA[
265 * <object class="GtkButton" id="label1"/>
266 * <property name="label">I am a Label for a Button</property>
268 * <object class="GtkButton" id="button1">
270 * <action action_name="click" translatable="yes">Click the button.</action>
271 * <relation target="label1" type="labelled-by"/>
273 * <child internal-child="accessible">
274 * <object class="AtkObject" id="a11y-button1">
275 * <property name="AtkObject::name">Clickable Button</property>
279 * ]]></programlisting>
282 * Finally, GtkWidget allows style information such as style classes to
283 * be associated with widgets, using the custom <style> element:
285 * <title>A UI definition fragment specifying an style class</title>
286 * <programlisting><![CDATA[
287 * <object class="GtkButton" id="button1">
289 * <class name="my-special-button-class"/>
290 * <class name="dark-button"/>
293 * ]]></programlisting>
299 /* Add flags here that should not be propagated to children. By default,
300 * all flags will be set on children (think prelight or active), but we
301 * might want to not do this for some.
303 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
304 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
306 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
308 #define GTK_STATE_FLAGS_BITS 9
310 struct _GtkWidgetPrivate
312 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
313 * (defined in "gtkenums.h").
315 guint state_flags : GTK_STATE_FLAGS_BITS;
319 guint in_destruction : 1;
322 guint composite_child : 1;
330 guint can_default : 1;
331 guint has_default : 1;
332 guint receives_default : 1;
335 guint style_update_pending : 1;
336 guint app_paintable : 1;
337 guint double_buffered : 1;
338 guint redraw_on_alloc : 1;
339 guint no_show_all : 1;
340 guint child_visible : 1;
341 guint multidevice : 1;
342 guint has_shape_mask : 1;
343 guint in_reparent : 1;
345 /* Queue-resize related flags */
346 guint alloc_needed : 1;
348 /* Expand-related flags */
349 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
350 guint computed_hexpand : 1; /* computed results (composite of child flags) */
351 guint computed_vexpand : 1;
352 guint hexpand : 1; /* application-forced expand */
354 guint hexpand_set : 1; /* whether to use application-forced */
355 guint vexpand_set : 1; /* instead of computing from children */
357 /* SizeGroup related flags */
358 guint have_size_groups : 1;
360 /* The widget's name. If the widget does not have a name
361 * (the name is NULL), then its name (as returned by
362 * "gtk_widget_get_name") is its class's name.
363 * Among other things, the widget name is used to determine
364 * the style to use for a widget.
368 /* The list of attached windows to this widget.
369 * We keep a list in order to call reset_style to all of them,
371 GList *attached_windows;
373 /* The style for the widget. The style contains the
374 * colors the widget should be drawn in for each state
375 * along with graphics contexts used to draw with and
376 * the font to use for text.
379 GtkStyleContext *context;
381 /* Widget's path for styling */
384 /* The widget's allocated size */
385 GtkAllocation allocation;
387 /* The widget's requested sizes */
388 SizeRequestCache requests;
390 /* actions attached to this or any parent widget */
393 /* The widget's window or its parent window if it does
394 * not have a window. (Which will be indicated by the
395 * GTK_NO_WINDOW flag being set).
399 /* The widget's parent */
402 #ifdef G_ENABLE_DEBUG
403 /* Number of gtk_widget_push_verify_invariants () */
404 guint verifying_invariants_count;
405 #endif /* G_ENABLE_DEBUG */
408 struct _GtkWidgetClassPrivate
410 GType accessible_type;
411 AtkRole accessible_role;
440 BUTTON_RELEASE_EVENT,
454 PROPERTY_NOTIFY_EVENT,
455 SELECTION_CLEAR_EVENT,
456 SELECTION_REQUEST_EVENT,
457 SELECTION_NOTIFY_EVENT,
462 VISIBILITY_NOTIFY_EVENT,
476 ACCEL_CLOSURES_CHANGED,
501 PROP_RECEIVES_DEFAULT,
502 PROP_COMPOSITE_CHILD,
510 PROP_DOUBLE_BUFFERED,
525 typedef struct _GtkStateData GtkStateData;
530 guint flags_to_unset;
533 /* --- prototypes --- */
534 static void gtk_widget_base_class_init (gpointer g_class);
535 static void gtk_widget_class_init (GtkWidgetClass *klass);
536 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
537 static void gtk_widget_init (GtkWidget *widget);
538 static void gtk_widget_set_property (GObject *object,
542 static void gtk_widget_get_property (GObject *object,
546 static void gtk_widget_constructed (GObject *object);
547 static void gtk_widget_dispose (GObject *object);
548 static void gtk_widget_real_destroy (GtkWidget *object);
549 static void gtk_widget_finalize (GObject *object);
550 static void gtk_widget_real_show (GtkWidget *widget);
551 static void gtk_widget_real_hide (GtkWidget *widget);
552 static void gtk_widget_real_map (GtkWidget *widget);
553 static void gtk_widget_real_unmap (GtkWidget *widget);
554 static void gtk_widget_real_realize (GtkWidget *widget);
555 static void gtk_widget_real_unrealize (GtkWidget *widget);
556 static void gtk_widget_real_size_allocate (GtkWidget *widget,
557 GtkAllocation *allocation);
558 static void gtk_widget_real_style_set (GtkWidget *widget,
559 GtkStyle *previous_style);
560 static void gtk_widget_real_direction_changed(GtkWidget *widget,
561 GtkTextDirection previous_direction);
563 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
564 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
567 gboolean keyboard_tip,
568 GtkTooltip *tooltip);
569 static void gtk_widget_real_style_updated (GtkWidget *widget);
570 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
571 GtkWidgetHelpType help_type);
573 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
575 GParamSpec **pspecs);
576 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
578 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
580 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
581 GdkEventFocus *event);
582 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
583 GdkEventFocus *event);
584 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
585 GdkEventTouch *event);
586 static gboolean gtk_widget_real_focus (GtkWidget *widget,
587 GtkDirectionType direction);
588 static void gtk_widget_real_move_focus (GtkWidget *widget,
589 GtkDirectionType direction);
590 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
591 GtkDirectionType direction);
592 #ifdef G_ENABLE_DEBUG
593 static void gtk_widget_verify_invariants (GtkWidget *widget);
594 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
595 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
597 #define gtk_widget_verify_invariants(widget)
598 #define gtk_widget_push_verify_invariants(widget)
599 #define gtk_widget_pop_verify_invariants(widget)
601 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
602 static void gtk_widget_update_pango_context (GtkWidget *widget);
603 static void gtk_widget_propagate_state (GtkWidget *widget,
606 static gint gtk_widget_event_internal (GtkWidget *widget,
608 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
609 gboolean group_cycling);
610 static void gtk_widget_real_get_width (GtkWidget *widget,
613 static void gtk_widget_real_get_height (GtkWidget *widget,
616 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
618 gint *minimum_height,
619 gint *natural_height);
620 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
623 gint *natural_width);
624 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
625 GtkStateFlags old_state);
626 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
627 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
629 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
630 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
631 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
632 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
633 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
634 cairo_region_t *region);
635 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
636 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
639 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
640 gboolean has_tooltip,
642 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
643 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
645 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
646 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
648 const gchar *childname);
649 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
652 const GValue *value);
653 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
656 const gchar *tagname,
657 GMarkupParser *parser,
659 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
662 const gchar *tagname,
664 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
665 GtkBuilder *builder);
667 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
668 static void gtk_widget_real_get_width (GtkWidget *widget,
671 static void gtk_widget_real_get_height (GtkWidget *widget,
675 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
678 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
679 GtkOrientation orientation,
682 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
683 GtkOrientation orientation,
687 gint *allocated_size);
689 static void gtk_widget_set_usize_internal (GtkWidget *widget,
692 GtkQueueResizeFlags flags);
694 static void gtk_widget_add_events_internal (GtkWidget *widget,
697 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
701 static gboolean event_window_is_still_viewable (GdkEvent *event);
703 /* --- variables --- */
704 static gpointer gtk_widget_parent_class = NULL;
705 static guint widget_signals[LAST_SIGNAL] = { 0 };
706 static guint composite_child_stack = 0;
707 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
708 static GParamSpecPool *style_property_spec_pool = NULL;
710 static GQuark quark_property_parser = 0;
711 static GQuark quark_aux_info = 0;
712 static GQuark quark_accel_path = 0;
713 static GQuark quark_accel_closures = 0;
714 static GQuark quark_event_mask = 0;
715 static GQuark quark_device_event_mask = 0;
716 static GQuark quark_parent_window = 0;
717 static GQuark quark_pointer_window = 0;
718 static GQuark quark_shape_info = 0;
719 static GQuark quark_input_shape_info = 0;
720 static GQuark quark_pango_context = 0;
721 static GQuark quark_accessible_object = 0;
722 static GQuark quark_mnemonic_labels = 0;
723 static GQuark quark_tooltip_markup = 0;
724 static GQuark quark_has_tooltip = 0;
725 static GQuark quark_tooltip_window = 0;
726 static GQuark quark_visual = 0;
727 static GQuark quark_modifier_style = 0;
728 static GQuark quark_enabled_devices = 0;
729 static GQuark quark_size_groups = 0;
730 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
731 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
733 /* --- functions --- */
735 gtk_widget_get_type (void)
737 static GType widget_type = 0;
739 if (G_UNLIKELY (widget_type == 0))
741 const GTypeInfo widget_info =
743 sizeof (GtkWidgetClass),
744 gtk_widget_base_class_init,
745 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
746 (GClassInitFunc) gtk_widget_class_init,
747 NULL, /* class_finalize */
748 NULL, /* class_init */
751 (GInstanceInitFunc) gtk_widget_init,
752 NULL, /* value_table */
755 const GInterfaceInfo accessibility_info =
757 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
758 (GInterfaceFinalizeFunc) NULL,
759 NULL /* interface data */
762 const GInterfaceInfo buildable_info =
764 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
765 (GInterfaceFinalizeFunc) NULL,
766 NULL /* interface data */
769 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
770 &widget_info, G_TYPE_FLAG_ABSTRACT);
772 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
774 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
775 &accessibility_info) ;
776 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
784 gtk_widget_base_class_init (gpointer g_class)
786 GtkWidgetClass *klass = g_class;
788 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
792 child_property_notify_dispatcher (GObject *object,
796 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
799 /* We guard against the draw signal callbacks modifying the state of the
800 * cairo context by surounding it with save/restore.
801 * Maybe we should also cairo_new_path() just to be sure?
804 gtk_widget_draw_marshaller (GClosure *closure,
805 GValue *return_value,
806 guint n_param_values,
807 const GValue *param_values,
808 gpointer invocation_hint,
809 gpointer marshal_data)
811 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
815 _gtk_marshal_BOOLEAN__BOXED (closure,
826 gtk_widget_draw_marshallerv (GClosure *closure,
827 GValue *return_value,
830 gpointer marshal_data,
837 G_VA_COPY (args_copy, args);
838 cr = va_arg (args_copy, gpointer);
842 _gtk_marshal_BOOLEAN__BOXEDv (closure,
856 gtk_widget_class_init (GtkWidgetClass *klass)
858 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
859 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
860 GtkBindingSet *binding_set;
862 gtk_widget_parent_class = g_type_class_peek_parent (klass);
864 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
865 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
866 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
867 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
868 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
869 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
870 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
871 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
872 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
873 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
874 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
875 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
876 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
877 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
878 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
879 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
880 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
881 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
882 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
883 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
885 style_property_spec_pool = g_param_spec_pool_new (FALSE);
886 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
887 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
888 cpn_context.dispatcher = child_property_notify_dispatcher;
889 _gtk_widget_child_property_notify_context = &cpn_context;
891 gobject_class->constructed = gtk_widget_constructed;
892 gobject_class->dispose = gtk_widget_dispose;
893 gobject_class->finalize = gtk_widget_finalize;
894 gobject_class->set_property = gtk_widget_set_property;
895 gobject_class->get_property = gtk_widget_get_property;
897 klass->destroy = gtk_widget_real_destroy;
899 klass->activate_signal = 0;
900 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
901 klass->show = gtk_widget_real_show;
902 klass->show_all = gtk_widget_show;
903 klass->hide = gtk_widget_real_hide;
904 klass->map = gtk_widget_real_map;
905 klass->unmap = gtk_widget_real_unmap;
906 klass->realize = gtk_widget_real_realize;
907 klass->unrealize = gtk_widget_real_unrealize;
908 klass->size_allocate = gtk_widget_real_size_allocate;
909 klass->get_request_mode = gtk_widget_real_get_request_mode;
910 klass->get_preferred_width = gtk_widget_real_get_width;
911 klass->get_preferred_height = gtk_widget_real_get_height;
912 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
913 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
914 klass->state_changed = NULL;
915 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
916 klass->parent_set = NULL;
917 klass->hierarchy_changed = NULL;
918 klass->style_set = gtk_widget_real_style_set;
919 klass->direction_changed = gtk_widget_real_direction_changed;
920 klass->grab_notify = NULL;
921 klass->child_notify = NULL;
923 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
924 klass->grab_focus = gtk_widget_real_grab_focus;
925 klass->focus = gtk_widget_real_focus;
926 klass->move_focus = gtk_widget_real_move_focus;
927 klass->keynav_failed = gtk_widget_real_keynav_failed;
929 klass->button_press_event = NULL;
930 klass->button_release_event = NULL;
931 klass->motion_notify_event = NULL;
932 klass->touch_event = gtk_widget_real_touch_event;
933 klass->delete_event = NULL;
934 klass->destroy_event = NULL;
935 klass->key_press_event = gtk_widget_real_key_press_event;
936 klass->key_release_event = gtk_widget_real_key_release_event;
937 klass->enter_notify_event = NULL;
938 klass->leave_notify_event = NULL;
939 klass->configure_event = NULL;
940 klass->focus_in_event = gtk_widget_real_focus_in_event;
941 klass->focus_out_event = gtk_widget_real_focus_out_event;
942 klass->map_event = NULL;
943 klass->unmap_event = NULL;
944 klass->window_state_event = NULL;
945 klass->property_notify_event = _gtk_selection_property_notify;
946 klass->selection_clear_event = _gtk_selection_clear;
947 klass->selection_request_event = _gtk_selection_request;
948 klass->selection_notify_event = _gtk_selection_notify;
949 klass->selection_received = NULL;
950 klass->proximity_in_event = NULL;
951 klass->proximity_out_event = NULL;
952 klass->drag_begin = NULL;
953 klass->drag_end = NULL;
954 klass->drag_data_delete = NULL;
955 klass->drag_leave = NULL;
956 klass->drag_motion = NULL;
957 klass->drag_drop = NULL;
958 klass->drag_data_received = NULL;
959 klass->screen_changed = NULL;
960 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
961 klass->grab_broken_event = NULL;
962 klass->query_tooltip = gtk_widget_real_query_tooltip;
963 klass->style_updated = gtk_widget_real_style_updated;
965 klass->show_help = gtk_widget_real_show_help;
967 /* Accessibility support */
968 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
969 klass->priv->accessible_role = ATK_ROLE_INVALID;
970 klass->get_accessible = gtk_widget_real_get_accessible;
972 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
973 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
975 g_object_class_install_property (gobject_class,
977 g_param_spec_string ("name",
979 P_("The name of the widget"),
981 GTK_PARAM_READWRITE));
982 g_object_class_install_property (gobject_class,
984 g_param_spec_object ("parent",
986 P_("The parent widget of this widget. Must be a Container widget"),
988 GTK_PARAM_READWRITE));
990 g_object_class_install_property (gobject_class,
992 g_param_spec_int ("width-request",
994 P_("Override for width request of the widget, or -1 if natural request should be used"),
998 GTK_PARAM_READWRITE));
999 g_object_class_install_property (gobject_class,
1000 PROP_HEIGHT_REQUEST,
1001 g_param_spec_int ("height-request",
1002 P_("Height request"),
1003 P_("Override for height request of the widget, or -1 if natural request should be used"),
1007 GTK_PARAM_READWRITE));
1008 g_object_class_install_property (gobject_class,
1010 g_param_spec_boolean ("visible",
1012 P_("Whether the widget is visible"),
1014 GTK_PARAM_READWRITE));
1015 g_object_class_install_property (gobject_class,
1017 g_param_spec_boolean ("sensitive",
1019 P_("Whether the widget responds to input"),
1021 GTK_PARAM_READWRITE));
1022 g_object_class_install_property (gobject_class,
1024 g_param_spec_boolean ("app-paintable",
1025 P_("Application paintable"),
1026 P_("Whether the application will paint directly on the widget"),
1028 GTK_PARAM_READWRITE));
1029 g_object_class_install_property (gobject_class,
1031 g_param_spec_boolean ("can-focus",
1033 P_("Whether the widget can accept the input focus"),
1035 GTK_PARAM_READWRITE));
1036 g_object_class_install_property (gobject_class,
1038 g_param_spec_boolean ("has-focus",
1040 P_("Whether the widget has the input focus"),
1042 GTK_PARAM_READWRITE));
1043 g_object_class_install_property (gobject_class,
1045 g_param_spec_boolean ("is-focus",
1047 P_("Whether the widget is the focus widget within the toplevel"),
1049 GTK_PARAM_READWRITE));
1050 g_object_class_install_property (gobject_class,
1052 g_param_spec_boolean ("can-default",
1054 P_("Whether the widget can be the default widget"),
1056 GTK_PARAM_READWRITE));
1057 g_object_class_install_property (gobject_class,
1059 g_param_spec_boolean ("has-default",
1061 P_("Whether the widget is the default widget"),
1063 GTK_PARAM_READWRITE));
1064 g_object_class_install_property (gobject_class,
1065 PROP_RECEIVES_DEFAULT,
1066 g_param_spec_boolean ("receives-default",
1067 P_("Receives default"),
1068 P_("If TRUE, the widget will receive the default action when it is focused"),
1070 GTK_PARAM_READWRITE));
1071 g_object_class_install_property (gobject_class,
1072 PROP_COMPOSITE_CHILD,
1073 g_param_spec_boolean ("composite-child",
1074 P_("Composite child"),
1075 P_("Whether the widget is part of a composite widget"),
1077 GTK_PARAM_READABLE));
1078 g_object_class_install_property (gobject_class,
1080 g_param_spec_object ("style",
1082 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1084 GTK_PARAM_READWRITE));
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_flags ("events",
1089 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1090 GDK_TYPE_EVENT_MASK,
1092 GTK_PARAM_READWRITE));
1093 g_object_class_install_property (gobject_class,
1095 g_param_spec_boolean ("no-show-all",
1097 P_("Whether gtk_widget_show_all() should not affect this widget"),
1099 GTK_PARAM_READWRITE));
1102 * GtkWidget:has-tooltip:
1104 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1105 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1106 * the widget will be queried using #GtkWidget::query-tooltip to determine
1107 * whether it will provide a tooltip or not.
1109 * Note that setting this property to %TRUE for the first time will change
1110 * the event masks of the GdkWindows of this widget to include leave-notify
1111 * and motion-notify events. This cannot and will not be undone when the
1112 * property is set to %FALSE again.
1116 g_object_class_install_property (gobject_class,
1118 g_param_spec_boolean ("has-tooltip",
1120 P_("Whether this widget has a tooltip"),
1122 GTK_PARAM_READWRITE));
1124 * GtkWidget:tooltip-text:
1126 * Sets the text of tooltip to be the given string.
1128 * Also see gtk_tooltip_set_text().
1130 * This is a convenience property which will take care of getting the
1131 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1132 * will automatically be set to %TRUE and there will be taken care of
1133 * #GtkWidget::query-tooltip in the default signal handler.
1137 g_object_class_install_property (gobject_class,
1139 g_param_spec_string ("tooltip-text",
1141 P_("The contents of the tooltip for this widget"),
1143 GTK_PARAM_READWRITE));
1145 * GtkWidget:tooltip-markup:
1147 * Sets the text of tooltip to be the given string, which is marked up
1148 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1149 * Also see gtk_tooltip_set_markup().
1151 * This is a convenience property which will take care of getting the
1152 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1153 * will automatically be set to %TRUE and there will be taken care of
1154 * #GtkWidget::query-tooltip in the default signal handler.
1158 g_object_class_install_property (gobject_class,
1159 PROP_TOOLTIP_MARKUP,
1160 g_param_spec_string ("tooltip-markup",
1161 P_("Tooltip markup"),
1162 P_("The contents of the tooltip for this widget"),
1164 GTK_PARAM_READWRITE));
1169 * The widget's window if it is realized, %NULL otherwise.
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_object ("window",
1177 P_("The widget's window if it is realized"),
1179 GTK_PARAM_READABLE));
1182 * GtkWidget:double-buffered:
1184 * Whether the widget is double buffered.
1188 g_object_class_install_property (gobject_class,
1189 PROP_DOUBLE_BUFFERED,
1190 g_param_spec_boolean ("double-buffered",
1191 P_("Double Buffered"),
1192 P_("Whether the widget is double buffered"),
1194 GTK_PARAM_READWRITE));
1199 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1203 g_object_class_install_property (gobject_class,
1205 g_param_spec_enum ("halign",
1206 P_("Horizontal Alignment"),
1207 P_("How to position in extra horizontal space"),
1210 GTK_PARAM_READWRITE));
1215 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1219 g_object_class_install_property (gobject_class,
1221 g_param_spec_enum ("valign",
1222 P_("Vertical Alignment"),
1223 P_("How to position in extra vertical space"),
1226 GTK_PARAM_READWRITE));
1229 * GtkWidget:margin-left:
1231 * Margin on left side of widget.
1233 * This property adds margin outside of the widget's normal size
1234 * request, the margin will be added in addition to the size from
1235 * gtk_widget_set_size_request() for example.
1239 g_object_class_install_property (gobject_class,
1241 g_param_spec_int ("margin-left",
1242 P_("Margin on Left"),
1243 P_("Pixels of extra space on the left side"),
1247 GTK_PARAM_READWRITE));
1250 * GtkWidget:margin-right:
1252 * Margin on right side of widget.
1254 * This property adds margin outside of the widget's normal size
1255 * request, the margin will be added in addition to the size from
1256 * gtk_widget_set_size_request() for example.
1260 g_object_class_install_property (gobject_class,
1262 g_param_spec_int ("margin-right",
1263 P_("Margin on Right"),
1264 P_("Pixels of extra space on the right side"),
1268 GTK_PARAM_READWRITE));
1271 * GtkWidget:margin-top:
1273 * Margin on top side of widget.
1275 * This property adds margin outside of the widget's normal size
1276 * request, the margin will be added in addition to the size from
1277 * gtk_widget_set_size_request() for example.
1281 g_object_class_install_property (gobject_class,
1283 g_param_spec_int ("margin-top",
1284 P_("Margin on Top"),
1285 P_("Pixels of extra space on the top side"),
1289 GTK_PARAM_READWRITE));
1292 * GtkWidget:margin-bottom:
1294 * Margin on bottom side of widget.
1296 * This property adds margin outside of the widget's normal size
1297 * request, the margin will be added in addition to the size from
1298 * gtk_widget_set_size_request() for example.
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_int ("margin-bottom",
1305 P_("Margin on Bottom"),
1306 P_("Pixels of extra space on the bottom side"),
1310 GTK_PARAM_READWRITE));
1315 * Sets all four sides' margin at once. If read, returns max
1316 * margin on any side.
1320 g_object_class_install_property (gobject_class,
1322 g_param_spec_int ("margin",
1324 P_("Pixels of extra space on all four sides"),
1328 GTK_PARAM_READWRITE));
1331 * GtkWidget::destroy:
1332 * @object: the object which received the signal
1334 * Signals that all holders of a reference to the widget should release
1335 * the reference that they hold. May result in finalization of the widget
1336 * if all references are released.
1338 widget_signals[DESTROY] =
1339 g_signal_new (I_("destroy"),
1340 G_TYPE_FROM_CLASS (gobject_class),
1341 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1342 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1344 _gtk_marshal_VOID__VOID,
1348 * GtkWidget:hexpand:
1350 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_boolean ("hexpand",
1357 P_("Horizontal Expand"),
1358 P_("Whether widget wants more horizontal space"),
1360 GTK_PARAM_READWRITE));
1363 * GtkWidget:hexpand-set:
1365 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1369 g_object_class_install_property (gobject_class,
1371 g_param_spec_boolean ("hexpand-set",
1372 P_("Horizontal Expand Set"),
1373 P_("Whether to use the hexpand property"),
1375 GTK_PARAM_READWRITE));
1378 * GtkWidget:vexpand:
1380 * Whether to expand vertically. See gtk_widget_set_vexpand().
1384 g_object_class_install_property (gobject_class,
1386 g_param_spec_boolean ("vexpand",
1387 P_("Vertical Expand"),
1388 P_("Whether widget wants more vertical space"),
1390 GTK_PARAM_READWRITE));
1393 * GtkWidget:vexpand-set:
1395 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1399 g_object_class_install_property (gobject_class,
1401 g_param_spec_boolean ("vexpand-set",
1402 P_("Vertical Expand Set"),
1403 P_("Whether to use the vexpand property"),
1405 GTK_PARAM_READWRITE));
1410 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1414 g_object_class_install_property (gobject_class,
1416 g_param_spec_boolean ("expand",
1418 P_("Whether widget wants to expand in both directions"),
1420 GTK_PARAM_READWRITE));
1424 * @widget: the object which received the signal.
1426 widget_signals[SHOW] =
1427 g_signal_new (I_("show"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, show),
1432 _gtk_marshal_VOID__VOID,
1437 * @widget: the object which received the signal.
1439 widget_signals[HIDE] =
1440 g_signal_new (I_("hide"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1445 _gtk_marshal_VOID__VOID,
1450 * @widget: the object which received the signal.
1452 widget_signals[MAP] =
1453 g_signal_new (I_("map"),
1454 G_TYPE_FROM_CLASS (gobject_class),
1456 G_STRUCT_OFFSET (GtkWidgetClass, map),
1458 _gtk_marshal_VOID__VOID,
1463 * @widget: the object which received the signal.
1465 widget_signals[UNMAP] =
1466 g_signal_new (I_("unmap"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1471 _gtk_marshal_VOID__VOID,
1475 * GtkWidget::realize:
1476 * @widget: the object which received the signal.
1478 widget_signals[REALIZE] =
1479 g_signal_new (I_("realize"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1482 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1484 _gtk_marshal_VOID__VOID,
1488 * GtkWidget::unrealize:
1489 * @widget: the object which received the signal.
1491 widget_signals[UNREALIZE] =
1492 g_signal_new (I_("unrealize"),
1493 G_TYPE_FROM_CLASS (gobject_class),
1495 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1497 _gtk_marshal_VOID__VOID,
1501 * GtkWidget::size-allocate:
1502 * @widget: the object which received the signal.
1505 widget_signals[SIZE_ALLOCATE] =
1506 g_signal_new (I_("size-allocate"),
1507 G_TYPE_FROM_CLASS (gobject_class),
1509 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1511 _gtk_marshal_VOID__BOXED,
1513 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1516 * GtkWidget::state-changed:
1517 * @widget: the object which received the signal.
1518 * @state: the previous state
1520 * The ::state-changed signal is emitted when the widget state changes.
1521 * See gtk_widget_get_state().
1523 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1525 widget_signals[STATE_CHANGED] =
1526 g_signal_new (I_("state-changed"),
1527 G_TYPE_FROM_CLASS (gobject_class),
1529 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1531 _gtk_marshal_VOID__ENUM,
1533 GTK_TYPE_STATE_TYPE);
1536 * GtkWidget::state-flags-changed:
1537 * @widget: the object which received the signal.
1538 * @flags: The previous state flags.
1540 * The ::state-flags-changed signal is emitted when the widget state
1541 * changes, see gtk_widget_get_state_flags().
1545 widget_signals[STATE_FLAGS_CHANGED] =
1546 g_signal_new (I_("state-flags-changed"),
1547 G_TYPE_FROM_CLASS (gobject_class),
1549 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1551 _gtk_marshal_VOID__FLAGS,
1553 GTK_TYPE_STATE_FLAGS);
1556 * GtkWidget::parent-set:
1557 * @widget: the object on which the signal is emitted
1558 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1559 * just got its initial parent.
1561 * The ::parent-set signal is emitted when a new parent
1562 * has been set on a widget.
1564 widget_signals[PARENT_SET] =
1565 g_signal_new (I_("parent-set"),
1566 G_TYPE_FROM_CLASS (gobject_class),
1568 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1570 _gtk_marshal_VOID__OBJECT,
1575 * GtkWidget::hierarchy-changed:
1576 * @widget: the object on which the signal is emitted
1577 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1578 * if the widget was previously unanchored
1580 * The ::hierarchy-changed signal is emitted when the
1581 * anchored state of a widget changes. A widget is
1582 * <firstterm>anchored</firstterm> when its toplevel
1583 * ancestor is a #GtkWindow. This signal is emitted when
1584 * a widget changes from un-anchored to anchored or vice-versa.
1586 widget_signals[HIERARCHY_CHANGED] =
1587 g_signal_new (I_("hierarchy-changed"),
1588 G_TYPE_FROM_CLASS (gobject_class),
1590 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1592 _gtk_marshal_VOID__OBJECT,
1597 * GtkWidget::style-set:
1598 * @widget: the object on which the signal is emitted
1599 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1600 * just got its initial style
1602 * The ::style-set signal is emitted when a new style has been set
1603 * on a widget. Note that style-modifying functions like
1604 * gtk_widget_modify_base() also cause this signal to be emitted.
1606 * Note that this signal is emitted for changes to the deprecated
1607 * #GtkStyle. To track changes to the #GtkStyleContext associated
1608 * with a widget, use the #GtkWidget::style-updated signal.
1610 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1612 widget_signals[STYLE_SET] =
1613 g_signal_new (I_("style-set"),
1614 G_TYPE_FROM_CLASS (gobject_class),
1616 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1618 _gtk_marshal_VOID__OBJECT,
1623 * GtkWidget::style-updated:
1624 * @widget: the object on which the signal is emitted
1626 * The ::style-updated signal is emitted when the #GtkStyleContext
1627 * of a widget is changed. Note that style-modifying functions like
1628 * gtk_widget_override_color() also cause this signal to be emitted.
1632 widget_signals[STYLE_UPDATED] =
1633 g_signal_new (I_("style-updated"),
1634 G_TYPE_FROM_CLASS (gobject_class),
1636 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1638 g_cclosure_marshal_VOID__VOID,
1642 * GtkWidget::direction-changed:
1643 * @widget: the object on which the signal is emitted
1644 * @previous_direction: the previous text direction of @widget
1646 * The ::direction-changed signal is emitted when the text direction
1647 * of a widget changes.
1649 widget_signals[DIRECTION_CHANGED] =
1650 g_signal_new (I_("direction-changed"),
1651 G_TYPE_FROM_CLASS (gobject_class),
1653 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1655 _gtk_marshal_VOID__ENUM,
1657 GTK_TYPE_TEXT_DIRECTION);
1660 * GtkWidget::grab-notify:
1661 * @widget: the object which received the signal
1662 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1663 * if it becomes unshadowed
1665 * The ::grab-notify signal is emitted when a widget becomes
1666 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1667 * another widget, or when it becomes unshadowed due to a grab
1670 * A widget is shadowed by a gtk_grab_add() when the topmost
1671 * grab widget in the grab stack of its window group is not
1674 widget_signals[GRAB_NOTIFY] =
1675 g_signal_new (I_("grab-notify"),
1676 G_TYPE_FROM_CLASS (gobject_class),
1678 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1680 _gtk_marshal_VOID__BOOLEAN,
1685 * GtkWidget::child-notify:
1686 * @widget: the object which received the signal
1687 * @child_property: the #GParamSpec of the changed child property
1689 * The ::child-notify signal is emitted for each
1690 * <link linkend="child-properties">child property</link> that has
1691 * changed on an object. The signal's detail holds the property name.
1693 widget_signals[CHILD_NOTIFY] =
1694 g_signal_new (I_("child-notify"),
1695 G_TYPE_FROM_CLASS (gobject_class),
1696 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1697 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1699 g_cclosure_marshal_VOID__PARAM,
1705 * @widget: the object which received the signal
1706 * @cr: the cairo context to draw to
1708 * This signal is emitted when a widget is supposed to render itself.
1709 * The @widget's top left corner must be painted at the origin of
1710 * the passed in context and be sized to the values returned by
1711 * gtk_widget_get_allocated_width() and
1712 * gtk_widget_get_allocated_height().
1714 * Signal handlers connected to this signal can modify the cairo
1715 * context passed as @cr in any way they like and don't need to
1716 * restore it. The signal emission takes care of calling cairo_save()
1717 * before and cairo_restore() after invoking the handler.
1719 * Returns: %TRUE to stop other handlers from being invoked for the event.
1720 % %FALSE to propagate the event further.
1724 widget_signals[DRAW] =
1725 g_signal_new (I_("draw"),
1726 G_TYPE_FROM_CLASS (gobject_class),
1728 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1729 _gtk_boolean_handled_accumulator, NULL,
1730 gtk_widget_draw_marshaller,
1732 CAIRO_GOBJECT_TYPE_CONTEXT);
1733 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1734 gtk_widget_draw_marshallerv);
1737 * GtkWidget::mnemonic-activate:
1738 * @widget: the object which received the signal.
1741 * Returns: %TRUE to stop other handlers from being invoked for the event.
1742 * %FALSE to propagate the event further.
1744 widget_signals[MNEMONIC_ACTIVATE] =
1745 g_signal_new (I_("mnemonic-activate"),
1746 G_TYPE_FROM_CLASS (gobject_class),
1748 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1749 _gtk_boolean_handled_accumulator, NULL,
1750 _gtk_marshal_BOOLEAN__BOOLEAN,
1755 * GtkWidget::grab-focus:
1756 * @widget: the object which received the signal.
1758 widget_signals[GRAB_FOCUS] =
1759 g_signal_new (I_("grab-focus"),
1760 G_TYPE_FROM_CLASS (gobject_class),
1761 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1762 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1764 _gtk_marshal_VOID__VOID,
1769 * @widget: the object which received the signal.
1772 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1774 widget_signals[FOCUS] =
1775 g_signal_new (I_("focus"),
1776 G_TYPE_FROM_CLASS (klass),
1778 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1779 _gtk_boolean_handled_accumulator, NULL,
1780 _gtk_marshal_BOOLEAN__ENUM,
1782 GTK_TYPE_DIRECTION_TYPE);
1785 * GtkWidget::move-focus:
1786 * @widget: the object which received the signal.
1789 widget_signals[MOVE_FOCUS] =
1790 g_signal_new (I_("move-focus"),
1791 G_TYPE_FROM_CLASS (klass),
1792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1793 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1795 _gtk_marshal_VOID__ENUM,
1798 GTK_TYPE_DIRECTION_TYPE);
1801 * GtkWidget::keynav-failed:
1802 * @widget: the object which received the signal
1803 * @direction: the direction of movement
1805 * Gets emitted if keyboard navigation fails.
1806 * See gtk_widget_keynav_failed() for details.
1808 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1809 * if the emitting widget should try to handle the keyboard
1810 * navigation attempt in its parent container(s).
1814 widget_signals[KEYNAV_FAILED] =
1815 g_signal_new (I_("keynav-failed"),
1816 G_TYPE_FROM_CLASS (klass),
1818 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1819 _gtk_boolean_handled_accumulator, NULL,
1820 _gtk_marshal_BOOLEAN__ENUM,
1822 GTK_TYPE_DIRECTION_TYPE);
1826 * @widget: the object which received the signal.
1827 * @event: the #GdkEvent which triggered this signal
1829 * The GTK+ main loop will emit three signals for each GDK event delivered
1830 * to a widget: one generic ::event signal, another, more specific,
1831 * signal that matches the type of event delivered (e.g.
1832 * #GtkWidget::key-press-event) and finally a generic
1833 * #GtkWidget::event-after signal.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event
1836 * and to cancel the emission of the second specific ::event signal.
1837 * %FALSE to propagate the event further and to allow the emission of
1838 * the second signal. The ::event-after signal is emitted regardless of
1841 widget_signals[EVENT] =
1842 g_signal_new (I_("event"),
1843 G_TYPE_FROM_CLASS (klass),
1845 G_STRUCT_OFFSET (GtkWidgetClass, event),
1846 _gtk_boolean_handled_accumulator, NULL,
1847 _gtk_marshal_BOOLEAN__BOXED,
1849 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1850 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1851 _gtk_marshal_BOOLEAN__BOXEDv);
1854 * GtkWidget::event-after:
1855 * @widget: the object which received the signal.
1856 * @event: the #GdkEvent which triggered this signal
1858 * After the emission of the #GtkWidget::event signal and (optionally)
1859 * the second more specific signal, ::event-after will be emitted
1860 * regardless of the previous two signals handlers return values.
1863 widget_signals[EVENT_AFTER] =
1864 g_signal_new (I_("event-after"),
1865 G_TYPE_FROM_CLASS (klass),
1869 _gtk_marshal_VOID__BOXED,
1871 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1872 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1873 _gtk_marshal_BOOLEAN__BOXEDv);
1876 * GtkWidget::button-press-event:
1877 * @widget: the object which received the signal.
1878 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1881 * The ::button-press-event signal will be emitted when a button
1882 * (typically from a mouse) is pressed.
1884 * To receive this signal, the #GdkWindow associated to the
1885 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1887 * This signal will be sent to the grab widget if there is one.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[BUTTON_PRESS_EVENT] =
1893 g_signal_new (I_("button-press-event"),
1894 G_TYPE_FROM_CLASS (klass),
1896 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1901 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1902 _gtk_marshal_BOOLEAN__BOXEDv);
1905 * GtkWidget::button-release-event:
1906 * @widget: the object which received the signal.
1907 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1910 * The ::button-release-event signal will be emitted when a button
1911 * (typically from a mouse) is released.
1913 * To receive this signal, the #GdkWindow associated to the
1914 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1916 * This signal will be sent to the grab widget if there is one.
1918 * Returns: %TRUE to stop other handlers from being invoked for the event.
1919 * %FALSE to propagate the event further.
1921 widget_signals[BUTTON_RELEASE_EVENT] =
1922 g_signal_new (I_("button-release-event"),
1923 G_TYPE_FROM_CLASS (klass),
1925 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1926 _gtk_boolean_handled_accumulator, NULL,
1927 _gtk_marshal_BOOLEAN__BOXED,
1929 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1930 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1931 _gtk_marshal_BOOLEAN__BOXEDv);
1933 widget_signals[TOUCH_EVENT] =
1934 g_signal_new (I_("touch-event"),
1935 G_TYPE_FROM_CLASS (klass),
1937 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1938 _gtk_boolean_handled_accumulator, NULL,
1939 _gtk_marshal_BOOLEAN__BOXED,
1941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1942 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1943 _gtk_marshal_BOOLEAN__BOXEDv);
1946 * GtkWidget::scroll-event:
1947 * @widget: the object which received the signal.
1948 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1951 * The ::scroll-event signal is emitted when a button in the 4 to 7
1952 * range is pressed. Wheel mice are usually configured to generate
1953 * button press events for buttons 4 and 5 when the wheel is turned.
1955 * To receive this signal, the #GdkWindow associated to the widget needs
1956 * to enable the #GDK_SCROLL_MASK mask.
1958 * This signal will be sent to the grab widget if there is one.
1960 * Returns: %TRUE to stop other handlers from being invoked for the event.
1961 * %FALSE to propagate the event further.
1963 widget_signals[SCROLL_EVENT] =
1964 g_signal_new (I_("scroll-event"),
1965 G_TYPE_FROM_CLASS (klass),
1967 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1968 _gtk_boolean_handled_accumulator, NULL,
1969 _gtk_marshal_BOOLEAN__BOXED,
1971 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1972 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1973 _gtk_marshal_BOOLEAN__BOXEDv);
1976 * GtkWidget::motion-notify-event:
1977 * @widget: the object which received the signal.
1978 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1981 * The ::motion-notify-event signal is emitted when the pointer moves
1982 * over the widget's #GdkWindow.
1984 * To receive this signal, the #GdkWindow associated to the widget
1985 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1987 * This signal will be sent to the grab widget if there is one.
1989 * Returns: %TRUE to stop other handlers from being invoked for the event.
1990 * %FALSE to propagate the event further.
1992 widget_signals[MOTION_NOTIFY_EVENT] =
1993 g_signal_new (I_("motion-notify-event"),
1994 G_TYPE_FROM_CLASS (klass),
1996 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1997 _gtk_boolean_handled_accumulator, NULL,
1998 _gtk_marshal_BOOLEAN__BOXED,
2000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2001 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2002 _gtk_marshal_BOOLEAN__BOXEDv);
2005 * GtkWidget::composited-changed:
2006 * @widget: the object on which the signal is emitted
2008 * The ::composited-changed signal is emitted when the composited
2009 * status of @widget<!-- -->s screen changes.
2010 * See gdk_screen_is_composited().
2012 widget_signals[COMPOSITED_CHANGED] =
2013 g_signal_new (I_("composited-changed"),
2014 G_TYPE_FROM_CLASS (klass),
2015 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2016 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2018 _gtk_marshal_VOID__VOID,
2022 * GtkWidget::delete-event:
2023 * @widget: the object which received the signal
2024 * @event: the event which triggered this signal
2026 * The ::delete-event signal is emitted if a user requests that
2027 * a toplevel window is closed. The default handler for this signal
2028 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2029 * this signal will cause the window to be hidden instead, so that
2030 * it can later be shown again without reconstructing it.
2032 * Returns: %TRUE to stop other handlers from being invoked for the event.
2033 * %FALSE to propagate the event further.
2035 widget_signals[DELETE_EVENT] =
2036 g_signal_new (I_("delete-event"),
2037 G_TYPE_FROM_CLASS (klass),
2039 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2040 _gtk_boolean_handled_accumulator, NULL,
2041 _gtk_marshal_BOOLEAN__BOXED,
2043 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2045 _gtk_marshal_BOOLEAN__BOXEDv);
2048 * GtkWidget::destroy-event:
2049 * @widget: the object which received the signal.
2050 * @event: the event which triggered this signal
2052 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2053 * You rarely get this signal, because most widgets disconnect themselves
2054 * from their window before they destroy it, so no widget owns the
2055 * window at destroy time.
2057 * To receive this signal, the #GdkWindow associated to the widget needs
2058 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2059 * automatically for all new windows.
2061 * Returns: %TRUE to stop other handlers from being invoked for the event.
2062 * %FALSE to propagate the event further.
2064 widget_signals[DESTROY_EVENT] =
2065 g_signal_new (I_("destroy-event"),
2066 G_TYPE_FROM_CLASS (klass),
2068 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2069 _gtk_boolean_handled_accumulator, NULL,
2070 _gtk_marshal_BOOLEAN__BOXED,
2072 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2073 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2074 _gtk_marshal_BOOLEAN__BOXEDv);
2077 * GtkWidget::key-press-event:
2078 * @widget: the object which received the signal
2079 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2081 * The ::key-press-event signal is emitted when a key is pressed. The signal
2082 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2084 * To receive this signal, the #GdkWindow associated to the widget needs
2085 * to enable the #GDK_KEY_PRESS_MASK mask.
2087 * This signal will be sent to the grab widget if there is one.
2089 * Returns: %TRUE to stop other handlers from being invoked for the event.
2090 * %FALSE to propagate the event further.
2092 widget_signals[KEY_PRESS_EVENT] =
2093 g_signal_new (I_("key-press-event"),
2094 G_TYPE_FROM_CLASS (klass),
2096 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2097 _gtk_boolean_handled_accumulator, NULL,
2098 _gtk_marshal_BOOLEAN__BOXED,
2100 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2101 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2102 _gtk_marshal_BOOLEAN__BOXEDv);
2105 * GtkWidget::key-release-event:
2106 * @widget: the object which received the signal
2107 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2109 * The ::key-release-event signal is emitted when a key is released.
2111 * To receive this signal, the #GdkWindow associated to the widget needs
2112 * to enable the #GDK_KEY_RELEASE_MASK mask.
2114 * This signal will be sent to the grab widget if there is one.
2116 * Returns: %TRUE to stop other handlers from being invoked for the event.
2117 * %FALSE to propagate the event further.
2119 widget_signals[KEY_RELEASE_EVENT] =
2120 g_signal_new (I_("key-release-event"),
2121 G_TYPE_FROM_CLASS (klass),
2123 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2124 _gtk_boolean_handled_accumulator, NULL,
2125 _gtk_marshal_BOOLEAN__BOXED,
2127 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2128 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2129 _gtk_marshal_BOOLEAN__BOXEDv);
2132 * GtkWidget::enter-notify-event:
2133 * @widget: the object which received the signal
2134 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2137 * The ::enter-notify-event will be emitted when the pointer enters
2138 * the @widget's window.
2140 * To receive this signal, the #GdkWindow associated to the widget needs
2141 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2143 * This signal will be sent to the grab widget if there is one.
2145 * Returns: %TRUE to stop other handlers from being invoked for the event.
2146 * %FALSE to propagate the event further.
2148 widget_signals[ENTER_NOTIFY_EVENT] =
2149 g_signal_new (I_("enter-notify-event"),
2150 G_TYPE_FROM_CLASS (klass),
2152 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2153 _gtk_boolean_handled_accumulator, NULL,
2154 _gtk_marshal_BOOLEAN__BOXED,
2156 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2157 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2158 _gtk_marshal_BOOLEAN__BOXEDv);
2161 * GtkWidget::leave-notify-event:
2162 * @widget: the object which received the signal
2163 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2166 * The ::leave-notify-event will be emitted when the pointer leaves
2167 * the @widget's window.
2169 * To receive this signal, the #GdkWindow associated to the widget needs
2170 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2172 * This signal will be sent to the grab widget if there is one.
2174 * Returns: %TRUE to stop other handlers from being invoked for the event.
2175 * %FALSE to propagate the event further.
2177 widget_signals[LEAVE_NOTIFY_EVENT] =
2178 g_signal_new (I_("leave-notify-event"),
2179 G_TYPE_FROM_CLASS (klass),
2181 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2182 _gtk_boolean_handled_accumulator, NULL,
2183 _gtk_marshal_BOOLEAN__BOXED,
2185 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2186 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2187 _gtk_marshal_BOOLEAN__BOXEDv);
2190 * GtkWidget::configure-event:
2191 * @widget: the object which received the signal
2192 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2195 * The ::configure-event signal will be emitted when the size, position or
2196 * stacking of the @widget's window has changed.
2198 * To receive this signal, the #GdkWindow associated to the widget needs
2199 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2200 * automatically for all new windows.
2202 * Returns: %TRUE to stop other handlers from being invoked for the event.
2203 * %FALSE to propagate the event further.
2205 widget_signals[CONFIGURE_EVENT] =
2206 g_signal_new (I_("configure-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2214 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2215 _gtk_marshal_BOOLEAN__BOXEDv);
2218 * GtkWidget::focus-in-event:
2219 * @widget: the object which received the signal
2220 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2223 * The ::focus-in-event signal will be emitted when the keyboard focus
2224 * enters the @widget's window.
2226 * To receive this signal, the #GdkWindow associated to the widget needs
2227 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2229 * Returns: %TRUE to stop other handlers from being invoked for the event.
2230 * %FALSE to propagate the event further.
2232 widget_signals[FOCUS_IN_EVENT] =
2233 g_signal_new (I_("focus-in-event"),
2234 G_TYPE_FROM_CLASS (klass),
2236 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2237 _gtk_boolean_handled_accumulator, NULL,
2238 _gtk_marshal_BOOLEAN__BOXED,
2240 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2241 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2242 _gtk_marshal_BOOLEAN__BOXEDv);
2245 * GtkWidget::focus-out-event:
2246 * @widget: the object which received the signal
2247 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2250 * The ::focus-out-event signal will be emitted when the keyboard focus
2251 * leaves the @widget's window.
2253 * To receive this signal, the #GdkWindow associated to the widget needs
2254 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2256 * Returns: %TRUE to stop other handlers from being invoked for the event.
2257 * %FALSE to propagate the event further.
2259 widget_signals[FOCUS_OUT_EVENT] =
2260 g_signal_new (I_("focus-out-event"),
2261 G_TYPE_FROM_CLASS (klass),
2263 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2264 _gtk_boolean_handled_accumulator, NULL,
2265 _gtk_marshal_BOOLEAN__BOXED,
2267 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2268 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2269 _gtk_marshal_BOOLEAN__BOXEDv);
2272 * GtkWidget::map-event:
2273 * @widget: the object which received the signal
2274 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2276 * The ::map-event signal will be emitted when the @widget's window is
2277 * mapped. A window is mapped when it becomes visible on the screen.
2279 * To receive this signal, the #GdkWindow associated to the widget needs
2280 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2281 * automatically for all new windows.
2283 * Returns: %TRUE to stop other handlers from being invoked for the event.
2284 * %FALSE to propagate the event further.
2286 widget_signals[MAP_EVENT] =
2287 g_signal_new (I_("map-event"),
2288 G_TYPE_FROM_CLASS (klass),
2290 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2291 _gtk_boolean_handled_accumulator, NULL,
2292 _gtk_marshal_BOOLEAN__BOXED,
2294 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2295 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2296 _gtk_marshal_BOOLEAN__BOXEDv);
2299 * GtkWidget::unmap-event:
2300 * @widget: the object which received the signal
2301 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2303 * The ::unmap-event signal will be emitted when the @widget's window is
2304 * unmapped. A window is unmapped when it becomes invisible on the screen.
2306 * To receive this signal, the #GdkWindow associated to the widget needs
2307 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2308 * automatically for all new windows.
2310 * Returns: %TRUE to stop other handlers from being invoked for the event.
2311 * %FALSE to propagate the event further.
2313 widget_signals[UNMAP_EVENT] =
2314 g_signal_new (I_("unmap-event"),
2315 G_TYPE_FROM_CLASS (klass),
2317 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2318 _gtk_boolean_handled_accumulator, NULL,
2319 _gtk_marshal_BOOLEAN__BOXED,
2321 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2322 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2323 _gtk_marshal_BOOLEAN__BOXEDv);
2326 * GtkWidget::property-notify-event:
2327 * @widget: the object which received the signal
2328 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2331 * The ::property-notify-event signal will be emitted when a property on
2332 * the @widget's window has been changed or deleted.
2334 * To receive this signal, the #GdkWindow associated to the widget needs
2335 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2337 * Returns: %TRUE to stop other handlers from being invoked for the event.
2338 * %FALSE to propagate the event further.
2340 widget_signals[PROPERTY_NOTIFY_EVENT] =
2341 g_signal_new (I_("property-notify-event"),
2342 G_TYPE_FROM_CLASS (klass),
2344 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2345 _gtk_boolean_handled_accumulator, NULL,
2346 _gtk_marshal_BOOLEAN__BOXED,
2348 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2349 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2350 _gtk_marshal_BOOLEAN__BOXEDv);
2353 * GtkWidget::selection-clear-event:
2354 * @widget: the object which received the signal
2355 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2358 * The ::selection-clear-event signal will be emitted when the
2359 * the @widget's window has lost ownership of a selection.
2361 * Returns: %TRUE to stop other handlers from being invoked for the event.
2362 * %FALSE to propagate the event further.
2364 widget_signals[SELECTION_CLEAR_EVENT] =
2365 g_signal_new (I_("selection-clear-event"),
2366 G_TYPE_FROM_CLASS (klass),
2368 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2369 _gtk_boolean_handled_accumulator, NULL,
2370 _gtk_marshal_BOOLEAN__BOXED,
2372 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2373 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2374 _gtk_marshal_BOOLEAN__BOXEDv);
2377 * GtkWidget::selection-request-event:
2378 * @widget: the object which received the signal
2379 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2382 * The ::selection-request-event signal will be emitted when
2383 * another client requests ownership of the selection owned by
2384 * the @widget's window.
2386 * Returns: %TRUE to stop other handlers from being invoked for the event.
2387 * %FALSE to propagate the event further.
2389 widget_signals[SELECTION_REQUEST_EVENT] =
2390 g_signal_new (I_("selection-request-event"),
2391 G_TYPE_FROM_CLASS (klass),
2393 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2394 _gtk_boolean_handled_accumulator, NULL,
2395 _gtk_marshal_BOOLEAN__BOXED,
2397 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2398 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2399 _gtk_marshal_BOOLEAN__BOXEDv);
2402 * GtkWidget::selection-notify-event:
2403 * @widget: the object which received the signal.
2404 * @event: (type Gdk.EventSelection):
2406 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2408 widget_signals[SELECTION_NOTIFY_EVENT] =
2409 g_signal_new (I_("selection-notify-event"),
2410 G_TYPE_FROM_CLASS (klass),
2412 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2413 _gtk_boolean_handled_accumulator, NULL,
2414 _gtk_marshal_BOOLEAN__BOXED,
2416 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2417 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2418 _gtk_marshal_BOOLEAN__BOXEDv);
2421 * GtkWidget::selection-received:
2422 * @widget: the object which received the signal.
2426 widget_signals[SELECTION_RECEIVED] =
2427 g_signal_new (I_("selection-received"),
2428 G_TYPE_FROM_CLASS (klass),
2430 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2432 _gtk_marshal_VOID__BOXED_UINT,
2434 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2438 * GtkWidget::selection-get:
2439 * @widget: the object which received the signal.
2444 widget_signals[SELECTION_GET] =
2445 g_signal_new (I_("selection-get"),
2446 G_TYPE_FROM_CLASS (klass),
2448 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2450 _gtk_marshal_VOID__BOXED_UINT_UINT,
2452 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2457 * GtkWidget::proximity-in-event:
2458 * @widget: the object which received the signal
2459 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2462 * To receive this signal the #GdkWindow associated to the widget needs
2463 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2465 * This signal will be sent to the grab widget if there is one.
2467 * Returns: %TRUE to stop other handlers from being invoked for the event.
2468 * %FALSE to propagate the event further.
2470 widget_signals[PROXIMITY_IN_EVENT] =
2471 g_signal_new (I_("proximity-in-event"),
2472 G_TYPE_FROM_CLASS (klass),
2474 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2475 _gtk_boolean_handled_accumulator, NULL,
2476 _gtk_marshal_BOOLEAN__BOXED,
2478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2479 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2480 _gtk_marshal_BOOLEAN__BOXEDv);
2483 * GtkWidget::proximity-out-event:
2484 * @widget: the object which received the signal
2485 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2488 * To receive this signal the #GdkWindow associated to the widget needs
2489 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2491 * This signal will be sent to the grab widget if there is one.
2493 * Returns: %TRUE to stop other handlers from being invoked for the event.
2494 * %FALSE to propagate the event further.
2496 widget_signals[PROXIMITY_OUT_EVENT] =
2497 g_signal_new (I_("proximity-out-event"),
2498 G_TYPE_FROM_CLASS (klass),
2500 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2501 _gtk_boolean_handled_accumulator, NULL,
2502 _gtk_marshal_BOOLEAN__BOXED,
2504 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2505 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2506 _gtk_marshal_BOOLEAN__BOXEDv);
2509 * GtkWidget::drag-leave:
2510 * @widget: the object which received the signal.
2511 * @context: the drag context
2512 * @time: the timestamp of the motion event
2514 * The ::drag-leave signal is emitted on the drop site when the cursor
2515 * leaves the widget. A typical reason to connect to this signal is to
2516 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2517 * with gtk_drag_unhighlight()
2519 widget_signals[DRAG_LEAVE] =
2520 g_signal_new (I_("drag-leave"),
2521 G_TYPE_FROM_CLASS (klass),
2523 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2525 _gtk_marshal_VOID__OBJECT_UINT,
2527 GDK_TYPE_DRAG_CONTEXT,
2531 * GtkWidget::drag-begin:
2532 * @widget: the object which received the signal
2533 * @context: the drag context
2535 * The ::drag-begin signal is emitted on the drag source when a drag is
2536 * started. A typical reason to connect to this signal is to set up a
2537 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2539 * Note that some widgets set up a drag icon in the default handler of
2540 * this signal, so you may have to use g_signal_connect_after() to
2541 * override what the default handler did.
2543 widget_signals[DRAG_BEGIN] =
2544 g_signal_new (I_("drag-begin"),
2545 G_TYPE_FROM_CLASS (klass),
2547 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2549 _gtk_marshal_VOID__OBJECT,
2551 GDK_TYPE_DRAG_CONTEXT);
2554 * GtkWidget::drag-end:
2555 * @widget: the object which received the signal
2556 * @context: the drag context
2558 * The ::drag-end signal is emitted on the drag source when a drag is
2559 * finished. A typical reason to connect to this signal is to undo
2560 * things done in #GtkWidget::drag-begin.
2562 widget_signals[DRAG_END] =
2563 g_signal_new (I_("drag-end"),
2564 G_TYPE_FROM_CLASS (klass),
2566 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2568 _gtk_marshal_VOID__OBJECT,
2570 GDK_TYPE_DRAG_CONTEXT);
2573 * GtkWidget::drag-data-delete:
2574 * @widget: the object which received the signal
2575 * @context: the drag context
2577 * The ::drag-data-delete signal is emitted on the drag source when a drag
2578 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2579 * handler is responsible for deleting the data that has been dropped. What
2580 * "delete" means depends on the context of the drag operation.
2582 widget_signals[DRAG_DATA_DELETE] =
2583 g_signal_new (I_("drag-data-delete"),
2584 G_TYPE_FROM_CLASS (klass),
2586 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2588 _gtk_marshal_VOID__OBJECT,
2590 GDK_TYPE_DRAG_CONTEXT);
2593 * GtkWidget::drag-failed:
2594 * @widget: the object which received the signal
2595 * @context: the drag context
2596 * @result: the result of the drag operation
2598 * The ::drag-failed signal is emitted on the drag source when a drag has
2599 * failed. The signal handler may hook custom code to handle a failed DND
2600 * operation based on the type of error, it returns %TRUE is the failure has
2601 * been already handled (not showing the default "drag operation failed"
2602 * animation), otherwise it returns %FALSE.
2604 * Return value: %TRUE if the failed drag operation has been already handled.
2608 widget_signals[DRAG_FAILED] =
2609 g_signal_new (I_("drag-failed"),
2610 G_TYPE_FROM_CLASS (klass),
2612 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2613 _gtk_boolean_handled_accumulator, NULL,
2614 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2616 GDK_TYPE_DRAG_CONTEXT,
2617 GTK_TYPE_DRAG_RESULT);
2620 * GtkWidget::drag-motion:
2621 * @widget: the object which received the signal
2622 * @context: the drag context
2623 * @x: the x coordinate of the current cursor position
2624 * @y: the y coordinate of the current cursor position
2625 * @time: the timestamp of the motion event
2627 * The ::drag-motion signal is emitted on the drop site when the user
2628 * moves the cursor over the widget during a drag. The signal handler
2629 * must determine whether the cursor position is in a drop zone or not.
2630 * If it is not in a drop zone, it returns %FALSE and no further processing
2631 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2632 * handler is responsible for providing the necessary information for
2633 * displaying feedback to the user, by calling gdk_drag_status().
2635 * If the decision whether the drop will be accepted or rejected can't be
2636 * made based solely on the cursor position and the type of the data, the
2637 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2638 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2639 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2640 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2641 * when using the drag-motion signal that way.
2643 * Also note that there is no drag-enter signal. The drag receiver has to
2644 * keep track of whether he has received any drag-motion signals since the
2645 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2646 * an "enter" signal. Upon an "enter", the handler will typically highlight
2647 * the drop site with gtk_drag_highlight().
2650 * drag_motion (GtkWidget *widget,
2651 * GdkDragContext *context,
2658 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2660 * if (!private_data->drag_highlight)
2662 * private_data->drag_highlight = 1;
2663 * gtk_drag_highlight (widget);
2666 * target = gtk_drag_dest_find_target (widget, context, NULL);
2667 * if (target == GDK_NONE)
2668 * gdk_drag_status (context, 0, time);
2671 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2672 * gtk_drag_get_data (widget, context, target, time);
2679 * drag_data_received (GtkWidget *widget,
2680 * GdkDragContext *context,
2683 * GtkSelectionData *selection_data,
2687 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2689 * if (private_data->suggested_action)
2691 * private_data->suggested_action = 0;
2693 * /* We are getting this data due to a request in drag_motion,
2694 * * rather than due to a request in drag_drop, so we are just
2695 * * supposed to call gdk_drag_status(), not actually paste in
2698 * str = gtk_selection_data_get_text (selection_data);
2699 * if (!data_is_acceptable (str))
2700 * gdk_drag_status (context, 0, time);
2702 * gdk_drag_status (context, private_data->suggested_action, time);
2706 * /* accept the drop */
2711 * Returns: whether the cursor position is in a drop zone
2713 widget_signals[DRAG_MOTION] =
2714 g_signal_new (I_("drag-motion"),
2715 G_TYPE_FROM_CLASS (klass),
2717 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2718 _gtk_boolean_handled_accumulator, NULL,
2719 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2721 GDK_TYPE_DRAG_CONTEXT,
2727 * GtkWidget::drag-drop:
2728 * @widget: the object which received the signal
2729 * @context: the drag context
2730 * @x: the x coordinate of the current cursor position
2731 * @y: the y coordinate of the current cursor position
2732 * @time: the timestamp of the motion event
2734 * The ::drag-drop signal is emitted on the drop site when the user drops
2735 * the data onto the widget. The signal handler must determine whether
2736 * the cursor position is in a drop zone or not. If it is not in a drop
2737 * zone, it returns %FALSE and no further processing is necessary.
2738 * Otherwise, the handler returns %TRUE. In this case, the handler must
2739 * ensure that gtk_drag_finish() is called to let the source know that
2740 * the drop is done. The call to gtk_drag_finish() can be done either
2741 * directly or in a #GtkWidget::drag-data-received handler which gets
2742 * triggered by calling gtk_drag_get_data() to receive the data for one
2743 * or more of the supported targets.
2745 * Returns: whether the cursor position is in a drop zone
2747 widget_signals[DRAG_DROP] =
2748 g_signal_new (I_("drag-drop"),
2749 G_TYPE_FROM_CLASS (klass),
2751 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2752 _gtk_boolean_handled_accumulator, NULL,
2753 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2755 GDK_TYPE_DRAG_CONTEXT,
2761 * GtkWidget::drag-data-get:
2762 * @widget: the object which received the signal
2763 * @context: the drag context
2764 * @data: the #GtkSelectionData to be filled with the dragged data
2765 * @info: the info that has been registered with the target in the
2767 * @time: the timestamp at which the data was requested
2769 * The ::drag-data-get signal is emitted on the drag source when the drop
2770 * site requests the data which is dragged. It is the responsibility of
2771 * the signal handler to fill @data with the data in the format which
2772 * is indicated by @info. See gtk_selection_data_set() and
2773 * gtk_selection_data_set_text().
2775 widget_signals[DRAG_DATA_GET] =
2776 g_signal_new (I_("drag-data-get"),
2777 G_TYPE_FROM_CLASS (klass),
2779 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2781 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2783 GDK_TYPE_DRAG_CONTEXT,
2784 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2789 * GtkWidget::drag-data-received:
2790 * @widget: the object which received the signal
2791 * @context: the drag context
2792 * @x: where the drop happened
2793 * @y: where the drop happened
2794 * @data: the received data
2795 * @info: the info that has been registered with the target in the
2797 * @time: the timestamp at which the data was received
2799 * The ::drag-data-received signal is emitted on the drop site when the
2800 * dragged data has been received. If the data was received in order to
2801 * determine whether the drop will be accepted, the handler is expected
2802 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2803 * If the data was received in response to a #GtkWidget::drag-drop signal
2804 * (and this is the last target to be received), the handler for this
2805 * signal is expected to process the received data and then call
2806 * gtk_drag_finish(), setting the @success parameter depending on
2807 * whether the data was processed successfully.
2809 * The handler may inspect the selected action with
2810 * gdk_drag_context_get_selected_action() before calling
2811 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2812 * shown in the following example:
2815 * drag_data_received (GtkWidget *widget,
2816 * GdkDragContext *context,
2819 * GtkSelectionData *data,
2823 * if ((data->length >= 0) && (data->format == 8))
2825 * GdkDragAction action;
2827 * /* handle data here */
2829 * action = gdk_drag_context_get_selected_action (context);
2830 * if (action == GDK_ACTION_ASK)
2832 * GtkWidget *dialog;
2835 * dialog = gtk_message_dialog_new (NULL,
2836 * GTK_DIALOG_MODAL |
2837 * GTK_DIALOG_DESTROY_WITH_PARENT,
2839 * GTK_BUTTONS_YES_NO,
2840 * "Move the data ?\n");
2841 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2842 * gtk_widget_destroy (dialog);
2844 * if (response == GTK_RESPONSE_YES)
2845 * action = GDK_ACTION_MOVE;
2847 * action = GDK_ACTION_COPY;
2850 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2853 * gtk_drag_finish (context, FALSE, FALSE, time);
2857 widget_signals[DRAG_DATA_RECEIVED] =
2858 g_signal_new (I_("drag-data-received"),
2859 G_TYPE_FROM_CLASS (klass),
2861 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2863 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2865 GDK_TYPE_DRAG_CONTEXT,
2868 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2873 * GtkWidget::visibility-notify-event:
2874 * @widget: the object which received the signal
2875 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2876 * triggered this signal.
2878 * The ::visibility-notify-event will be emitted when the @widget's window
2879 * is obscured or unobscured.
2881 * To receive this signal the #GdkWindow associated to the widget needs
2882 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2884 * Returns: %TRUE to stop other handlers from being invoked for the event.
2885 * %FALSE to propagate the event further.
2887 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2888 g_signal_new (I_("visibility-notify-event"),
2889 G_TYPE_FROM_CLASS (klass),
2891 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2892 _gtk_boolean_handled_accumulator, NULL,
2893 _gtk_marshal_BOOLEAN__BOXED,
2895 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2898 * GtkWidget::window-state-event:
2899 * @widget: the object which received the signal
2900 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2901 * triggered this signal.
2903 * The ::window-state-event will be emitted when the state of the
2904 * toplevel window associated to the @widget changes.
2906 * To receive this signal the #GdkWindow associated to the widget
2907 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2908 * this mask automatically for all new windows.
2910 * Returns: %TRUE to stop other handlers from being invoked for the
2911 * event. %FALSE to propagate the event further.
2913 widget_signals[WINDOW_STATE_EVENT] =
2914 g_signal_new (I_("window-state-event"),
2915 G_TYPE_FROM_CLASS (klass),
2917 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2918 _gtk_boolean_handled_accumulator, NULL,
2919 _gtk_marshal_BOOLEAN__BOXED,
2921 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2922 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2923 _gtk_marshal_BOOLEAN__BOXEDv);
2926 * GtkWidget::damage-event:
2927 * @widget: the object which received the signal
2928 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2930 * Emitted when a redirected window belonging to @widget gets drawn into.
2931 * The region/area members of the event shows what area of the redirected
2932 * drawable was drawn into.
2934 * Returns: %TRUE to stop other handlers from being invoked for the event.
2935 * %FALSE to propagate the event further.
2939 widget_signals[DAMAGE_EVENT] =
2940 g_signal_new (I_("damage-event"),
2941 G_TYPE_FROM_CLASS (klass),
2943 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2944 _gtk_boolean_handled_accumulator, NULL,
2945 _gtk_marshal_BOOLEAN__BOXED,
2947 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2948 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2949 _gtk_marshal_BOOLEAN__BOXEDv);
2952 * GtkWidget::grab-broken-event:
2953 * @widget: the object which received the signal
2954 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2956 * Emitted when a pointer or keyboard grab on a window belonging
2957 * to @widget gets broken.
2959 * On X11, this happens when the grab window becomes unviewable
2960 * (i.e. it or one of its ancestors is unmapped), or if the same
2961 * application grabs the pointer or keyboard again.
2963 * Returns: %TRUE to stop other handlers from being invoked for
2964 * the event. %FALSE to propagate the event further.
2968 widget_signals[GRAB_BROKEN_EVENT] =
2969 g_signal_new (I_("grab-broken-event"),
2970 G_TYPE_FROM_CLASS (klass),
2972 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2973 _gtk_boolean_handled_accumulator, NULL,
2974 _gtk_marshal_BOOLEAN__BOXED,
2976 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2977 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2978 _gtk_marshal_BOOLEAN__BOXEDv);
2981 * GtkWidget::query-tooltip:
2982 * @widget: the object which received the signal
2983 * @x: the x coordinate of the cursor position where the request has
2984 * been emitted, relative to @widget's left side
2985 * @y: the y coordinate of the cursor position where the request has
2986 * been emitted, relative to @widget's top
2987 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2988 * @tooltip: a #GtkTooltip
2990 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2991 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2992 * focus in keyboard mode.
2994 * Using the given coordinates, the signal handler should determine
2995 * whether a tooltip should be shown for @widget. If this is the case
2996 * %TRUE should be returned, %FALSE otherwise. Note that if
2997 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2998 * should not be used.
3000 * The signal handler is free to manipulate @tooltip with the therefore
3001 * destined function calls.
3003 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3007 widget_signals[QUERY_TOOLTIP] =
3008 g_signal_new (I_("query-tooltip"),
3009 G_TYPE_FROM_CLASS (klass),
3011 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3012 _gtk_boolean_handled_accumulator, NULL,
3013 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3021 * GtkWidget::popup-menu:
3022 * @widget: the object which received the signal
3024 * This signal gets emitted whenever a widget should pop up a context
3025 * menu. This usually happens through the standard key binding mechanism;
3026 * by pressing a certain key while a widget is focused, the user can cause
3027 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3028 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3029 * for an example of how to use this signal.
3031 * Returns: %TRUE if a menu was activated
3033 widget_signals[POPUP_MENU] =
3034 g_signal_new (I_("popup-menu"),
3035 G_TYPE_FROM_CLASS (klass),
3036 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3037 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3038 _gtk_boolean_handled_accumulator, NULL,
3039 _gtk_marshal_BOOLEAN__VOID,
3043 * GtkWidget::show-help:
3044 * @widget: the object which received the signal.
3047 * Returns: %TRUE to stop other handlers from being invoked for the event.
3048 * %FALSE to propagate the event further.
3050 widget_signals[SHOW_HELP] =
3051 g_signal_new (I_("show-help"),
3052 G_TYPE_FROM_CLASS (klass),
3053 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3054 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3055 _gtk_boolean_handled_accumulator, NULL,
3056 _gtk_marshal_BOOLEAN__ENUM,
3058 GTK_TYPE_WIDGET_HELP_TYPE);
3061 * GtkWidget::accel-closures-changed:
3062 * @widget: the object which received the signal.
3064 widget_signals[ACCEL_CLOSURES_CHANGED] =
3065 g_signal_new (I_("accel-closures-changed"),
3066 G_TYPE_FROM_CLASS (klass),
3070 _gtk_marshal_VOID__VOID,
3074 * GtkWidget::screen-changed:
3075 * @widget: the object on which the signal is emitted
3076 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3077 * widget was not associated with a screen before
3079 * The ::screen-changed signal gets emitted when the
3080 * screen of a widget has changed.
3082 widget_signals[SCREEN_CHANGED] =
3083 g_signal_new (I_("screen-changed"),
3084 G_TYPE_FROM_CLASS (klass),
3086 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3088 _gtk_marshal_VOID__OBJECT,
3093 * GtkWidget::can-activate-accel:
3094 * @widget: the object which received the signal
3095 * @signal_id: the ID of a signal installed on @widget
3097 * Determines whether an accelerator that activates the signal
3098 * identified by @signal_id can currently be activated.
3099 * This signal is present to allow applications and derived
3100 * widgets to override the default #GtkWidget handling
3101 * for determining whether an accelerator can be activated.
3103 * Returns: %TRUE if the signal can be activated.
3105 widget_signals[CAN_ACTIVATE_ACCEL] =
3106 g_signal_new (I_("can-activate-accel"),
3107 G_TYPE_FROM_CLASS (klass),
3109 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3110 _gtk_boolean_handled_accumulator, NULL,
3111 _gtk_marshal_BOOLEAN__UINT,
3112 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3114 binding_set = gtk_binding_set_by_class (klass);
3115 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3117 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3120 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3122 GTK_TYPE_WIDGET_HELP_TYPE,
3123 GTK_WIDGET_HELP_TOOLTIP);
3124 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3126 GTK_TYPE_WIDGET_HELP_TYPE,
3127 GTK_WIDGET_HELP_TOOLTIP);
3128 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3130 GTK_TYPE_WIDGET_HELP_TYPE,
3131 GTK_WIDGET_HELP_WHATS_THIS);
3132 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3134 GTK_TYPE_WIDGET_HELP_TYPE,
3135 GTK_WIDGET_HELP_WHATS_THIS);
3137 gtk_widget_class_install_style_property (klass,
3138 g_param_spec_boolean ("interior-focus",
3139 P_("Interior Focus"),
3140 P_("Whether to draw the focus indicator inside widgets"),
3142 GTK_PARAM_READABLE));
3144 gtk_widget_class_install_style_property (klass,
3145 g_param_spec_int ("focus-line-width",
3146 P_("Focus linewidth"),
3147 P_("Width, in pixels, of the focus indicator line"),
3149 GTK_PARAM_READABLE));
3151 gtk_widget_class_install_style_property (klass,
3152 g_param_spec_string ("focus-line-pattern",
3153 P_("Focus line dash pattern"),
3154 P_("Dash pattern used to draw the focus indicator"),
3156 GTK_PARAM_READABLE));
3157 gtk_widget_class_install_style_property (klass,
3158 g_param_spec_int ("focus-padding",
3159 P_("Focus padding"),
3160 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3162 GTK_PARAM_READABLE));
3163 gtk_widget_class_install_style_property (klass,
3164 g_param_spec_boxed ("cursor-color",
3166 P_("Color with which to draw insertion cursor"),
3168 GTK_PARAM_READABLE));
3169 gtk_widget_class_install_style_property (klass,
3170 g_param_spec_boxed ("secondary-cursor-color",
3171 P_("Secondary cursor color"),
3172 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3174 GTK_PARAM_READABLE));
3175 gtk_widget_class_install_style_property (klass,
3176 g_param_spec_float ("cursor-aspect-ratio",
3177 P_("Cursor line aspect ratio"),
3178 P_("Aspect ratio with which to draw insertion cursor"),
3180 GTK_PARAM_READABLE));
3182 gtk_widget_class_install_style_property (klass,
3183 g_param_spec_boolean ("window-dragging",
3184 P_("Window dragging"),
3185 P_("Whether windows can be dragged by clicking on empty areas"),
3187 GTK_PARAM_READABLE));
3190 * GtkWidget:link-color:
3192 * The "link-color" style property defines the color of unvisited links.
3196 gtk_widget_class_install_style_property (klass,
3197 g_param_spec_boxed ("link-color",
3198 P_("Unvisited Link Color"),
3199 P_("Color of unvisited links"),
3201 GTK_PARAM_READABLE));
3204 * GtkWidget:visited-link-color:
3206 * The "visited-link-color" style property defines the color of visited links.
3210 gtk_widget_class_install_style_property (klass,
3211 g_param_spec_boxed ("visited-link-color",
3212 P_("Visited Link Color"),
3213 P_("Color of visited links"),
3215 GTK_PARAM_READABLE));
3218 * GtkWidget:wide-separators:
3220 * The "wide-separators" style property defines whether separators have
3221 * configurable width and should be drawn using a box instead of a line.
3225 gtk_widget_class_install_style_property (klass,
3226 g_param_spec_boolean ("wide-separators",
3227 P_("Wide Separators"),
3228 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3230 GTK_PARAM_READABLE));
3233 * GtkWidget:separator-width:
3235 * The "separator-width" style property defines the width of separators.
3236 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3240 gtk_widget_class_install_style_property (klass,
3241 g_param_spec_int ("separator-width",
3242 P_("Separator Width"),
3243 P_("The width of separators if wide-separators is TRUE"),
3245 GTK_PARAM_READABLE));
3248 * GtkWidget:separator-height:
3250 * The "separator-height" style property defines the height of separators.
3251 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3255 gtk_widget_class_install_style_property (klass,
3256 g_param_spec_int ("separator-height",
3257 P_("Separator Height"),
3258 P_("The height of separators if \"wide-separators\" is TRUE"),
3260 GTK_PARAM_READABLE));
3263 * GtkWidget:scroll-arrow-hlength:
3265 * The "scroll-arrow-hlength" style property defines the length of
3266 * horizontal scroll arrows.
3270 gtk_widget_class_install_style_property (klass,
3271 g_param_spec_int ("scroll-arrow-hlength",
3272 P_("Horizontal Scroll Arrow Length"),
3273 P_("The length of horizontal scroll arrows"),
3275 GTK_PARAM_READABLE));
3278 * GtkWidget:scroll-arrow-vlength:
3280 * The "scroll-arrow-vlength" style property defines the length of
3281 * vertical scroll arrows.
3285 gtk_widget_class_install_style_property (klass,
3286 g_param_spec_int ("scroll-arrow-vlength",
3287 P_("Vertical Scroll Arrow Length"),
3288 P_("The length of vertical scroll arrows"),
3290 GTK_PARAM_READABLE));
3292 gtk_widget_class_install_style_property (klass,
3293 g_param_spec_int ("text-handle-width",
3294 P_("Width of text selection handles"),
3295 P_("Width of text selection handles"),
3297 GTK_PARAM_READABLE));
3298 gtk_widget_class_install_style_property (klass,
3299 g_param_spec_int ("text-handle-height",
3300 P_("Height of text selection handles"),
3301 P_("Height of text selection handles"),
3303 GTK_PARAM_READABLE));
3305 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3307 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3311 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3315 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3316 for (node = list; node; node = node->next)
3318 GParamSpec *pspec = node->data;
3320 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3321 g_param_spec_unref (pspec);
3327 gtk_widget_set_property (GObject *object,
3329 const GValue *value,
3332 GtkWidget *widget = GTK_WIDGET (object);
3337 gchar *tooltip_markup;
3338 const gchar *tooltip_text;
3339 GtkWindow *tooltip_window;
3342 gtk_widget_set_name (widget, g_value_get_string (value));
3345 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3347 case PROP_WIDTH_REQUEST:
3348 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3350 case PROP_HEIGHT_REQUEST:
3351 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3354 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3356 case PROP_SENSITIVE:
3357 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3359 case PROP_APP_PAINTABLE:
3360 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3362 case PROP_CAN_FOCUS:
3363 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3365 case PROP_HAS_FOCUS:
3366 if (g_value_get_boolean (value))
3367 gtk_widget_grab_focus (widget);
3370 if (g_value_get_boolean (value))
3371 gtk_widget_grab_focus (widget);
3373 case PROP_CAN_DEFAULT:
3374 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3376 case PROP_HAS_DEFAULT:
3377 if (g_value_get_boolean (value))
3378 gtk_widget_grab_default (widget);
3380 case PROP_RECEIVES_DEFAULT:
3381 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3384 gtk_widget_set_style (widget, g_value_get_object (value));
3387 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3388 gtk_widget_set_events (widget, g_value_get_flags (value));
3390 case PROP_NO_SHOW_ALL:
3391 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3393 case PROP_HAS_TOOLTIP:
3394 gtk_widget_real_set_has_tooltip (widget,
3395 g_value_get_boolean (value), FALSE);
3397 case PROP_TOOLTIP_MARKUP:
3398 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3399 tooltip_markup = g_value_dup_string (value);
3401 /* Treat an empty string as a NULL string,
3402 * because an empty string would be useless for a tooltip:
3404 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3406 g_free (tooltip_markup);
3407 tooltip_markup = NULL;
3410 g_object_set_qdata_full (object, quark_tooltip_markup,
3411 tooltip_markup, g_free);
3413 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3414 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3415 if (gtk_widget_get_visible (widget))
3416 gtk_widget_queue_tooltip_query (widget);
3418 case PROP_TOOLTIP_TEXT:
3419 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3421 tooltip_text = g_value_get_string (value);
3423 /* Treat an empty string as a NULL string,
3424 * because an empty string would be useless for a tooltip:
3426 if (tooltip_text && (strlen (tooltip_text) == 0))
3427 tooltip_text = NULL;
3429 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3431 g_object_set_qdata_full (object, quark_tooltip_markup,
3432 tooltip_markup, g_free);
3434 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3435 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3436 if (gtk_widget_get_visible (widget))
3437 gtk_widget_queue_tooltip_query (widget);
3439 case PROP_DOUBLE_BUFFERED:
3440 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3443 gtk_widget_set_halign (widget, g_value_get_enum (value));
3446 gtk_widget_set_valign (widget, g_value_get_enum (value));
3448 case PROP_MARGIN_LEFT:
3449 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3451 case PROP_MARGIN_RIGHT:
3452 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3454 case PROP_MARGIN_TOP:
3455 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3457 case PROP_MARGIN_BOTTOM:
3458 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3461 g_object_freeze_notify (G_OBJECT (widget));
3462 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3463 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3464 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3465 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3466 g_object_thaw_notify (G_OBJECT (widget));
3469 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3471 case PROP_HEXPAND_SET:
3472 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3475 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3477 case PROP_VEXPAND_SET:
3478 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3481 g_object_freeze_notify (G_OBJECT (widget));
3482 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3483 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3484 g_object_thaw_notify (G_OBJECT (widget));
3487 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3493 gtk_widget_get_property (GObject *object,
3498 GtkWidget *widget = GTK_WIDGET (object);
3499 GtkWidgetPrivate *priv = widget->priv;
3507 g_value_set_string (value, priv->name);
3509 g_value_set_static_string (value, "");
3512 g_value_set_object (value, priv->parent);
3514 case PROP_WIDTH_REQUEST:
3517 gtk_widget_get_size_request (widget, &w, NULL);
3518 g_value_set_int (value, w);
3521 case PROP_HEIGHT_REQUEST:
3524 gtk_widget_get_size_request (widget, NULL, &h);
3525 g_value_set_int (value, h);
3529 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3531 case PROP_SENSITIVE:
3532 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3534 case PROP_APP_PAINTABLE:
3535 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3537 case PROP_CAN_FOCUS:
3538 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3540 case PROP_HAS_FOCUS:
3541 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3544 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3546 case PROP_CAN_DEFAULT:
3547 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3549 case PROP_HAS_DEFAULT:
3550 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3552 case PROP_RECEIVES_DEFAULT:
3553 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3555 case PROP_COMPOSITE_CHILD:
3556 g_value_set_boolean (value, widget->priv->composite_child);
3559 g_value_set_object (value, gtk_widget_get_style (widget));
3562 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3563 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3565 case PROP_NO_SHOW_ALL:
3566 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3568 case PROP_HAS_TOOLTIP:
3569 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3571 case PROP_TOOLTIP_TEXT:
3573 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3576 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3577 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3579 g_value_take_string (value, text);
3582 case PROP_TOOLTIP_MARKUP:
3583 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3586 g_value_set_object (value, gtk_widget_get_window (widget));
3588 case PROP_DOUBLE_BUFFERED:
3589 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3592 g_value_set_enum (value, gtk_widget_get_halign (widget));
3595 g_value_set_enum (value, gtk_widget_get_valign (widget));
3597 case PROP_MARGIN_LEFT:
3598 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3600 case PROP_MARGIN_RIGHT:
3601 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3603 case PROP_MARGIN_TOP:
3604 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3606 case PROP_MARGIN_BOTTOM:
3607 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3611 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3612 if (aux_info == NULL)
3614 g_value_set_int (value, 0);
3618 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3619 aux_info->margin.right),
3620 MAX (aux_info->margin.top,
3621 aux_info->margin.bottom)));
3626 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3628 case PROP_HEXPAND_SET:
3629 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3632 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3634 case PROP_VEXPAND_SET:
3635 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3638 g_value_set_boolean (value,
3639 gtk_widget_get_hexpand (widget) &&
3640 gtk_widget_get_vexpand (widget));
3643 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3649 gtk_widget_init (GtkWidget *widget)
3651 GtkWidgetPrivate *priv;
3653 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3656 priv = widget->priv;
3658 priv->child_visible = TRUE;
3660 priv->allocation.x = -1;
3661 priv->allocation.y = -1;
3662 priv->allocation.width = 1;
3663 priv->allocation.height = 1;
3664 priv->window = NULL;
3665 priv->parent = NULL;
3667 priv->sensitive = TRUE;
3668 priv->composite_child = composite_child_stack != 0;
3669 priv->double_buffered = TRUE;
3670 priv->redraw_on_alloc = TRUE;
3671 priv->alloc_needed = TRUE;
3673 switch (gtk_widget_get_direction (widget))
3675 case GTK_TEXT_DIR_LTR:
3676 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3679 case GTK_TEXT_DIR_RTL:
3680 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3683 case GTK_TEXT_DIR_NONE:
3685 g_assert_not_reached ();
3690 /* this will be set to TRUE if the widget gets a child or if the
3691 * expand flag is set on the widget, but until one of those happen
3692 * we know the expand is already properly FALSE.
3694 * We really want to default FALSE here to avoid computing expand
3695 * all over the place while initially building a widget tree.
3697 priv->need_compute_expand = FALSE;
3699 _gtk_size_request_cache_init (&priv->requests);
3701 priv->style = gtk_widget_get_default_style ();
3702 g_object_ref (priv->style);
3707 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3709 GParamSpec **pspecs)
3711 GtkWidgetPrivate *priv = widget->priv;
3712 GtkWidget *container = priv->parent;
3715 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3716 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3720 * gtk_widget_freeze_child_notify:
3721 * @widget: a #GtkWidget
3723 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3724 * signals are queued until gtk_widget_thaw_child_notify() is called
3727 * This is the analogue of g_object_freeze_notify() for child properties.
3730 gtk_widget_freeze_child_notify (GtkWidget *widget)
3732 g_return_if_fail (GTK_IS_WIDGET (widget));
3734 if (!G_OBJECT (widget)->ref_count)
3737 g_object_ref (widget);
3738 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3739 g_object_unref (widget);
3743 * gtk_widget_child_notify:
3744 * @widget: a #GtkWidget
3745 * @child_property: the name of a child property installed on the
3746 * class of @widget<!-- -->'s parent
3748 * Emits a #GtkWidget::child-notify signal for the
3749 * <link linkend="child-properties">child property</link> @child_property
3752 * This is the analogue of g_object_notify() for child properties.
3754 * Also see gtk_container_child_notify().
3757 gtk_widget_child_notify (GtkWidget *widget,
3758 const gchar *child_property)
3760 if (widget->priv->parent == NULL)
3763 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3767 * gtk_widget_thaw_child_notify:
3768 * @widget: a #GtkWidget
3770 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3771 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3775 gtk_widget_thaw_child_notify (GtkWidget *widget)
3777 GObjectNotifyQueue *nqueue;
3779 g_return_if_fail (GTK_IS_WIDGET (widget));
3781 if (!G_OBJECT (widget)->ref_count)
3784 g_object_ref (widget);
3785 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3786 if (!nqueue || !nqueue->freeze_count)
3787 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3788 G_OBJECT_TYPE_NAME (widget), widget);
3790 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3791 g_object_unref (widget);
3797 * @type: type ID of the widget to create
3798 * @first_property_name: name of first property to set
3799 * @...: value of first property, followed by more properties,
3802 * This is a convenience function for creating a widget and setting
3803 * its properties in one go. For example you might write:
3804 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3805 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3806 * g_object_new(), but returns a widget so you don't have to
3807 * cast the object yourself.
3809 * Return value: a new #GtkWidget of type @widget_type
3812 gtk_widget_new (GType type,
3813 const gchar *first_property_name,
3819 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3821 va_start (var_args, first_property_name);
3822 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3829 gtk_widget_queue_draw_child (GtkWidget *widget)
3831 GtkWidgetPrivate *priv = widget->priv;
3834 parent = priv->parent;
3835 if (parent && gtk_widget_is_drawable (parent))
3836 gtk_widget_queue_draw_area (parent,
3839 priv->allocation.width,
3840 priv->allocation.height);
3844 * gtk_widget_unparent:
3845 * @widget: a #GtkWidget
3847 * This function is only for use in widget implementations.
3848 * Should be called by implementations of the remove method
3849 * on #GtkContainer, to dissociate a child from the container.
3852 gtk_widget_unparent (GtkWidget *widget)
3854 GtkWidgetPrivate *priv;
3855 GObjectNotifyQueue *nqueue;
3856 GtkWidget *toplevel;
3857 GtkWidget *old_parent;
3859 g_return_if_fail (GTK_IS_WIDGET (widget));
3861 priv = widget->priv;
3863 if (priv->parent == NULL)
3866 /* keep this function in sync with gtk_menu_detach() */
3868 gtk_widget_push_verify_invariants (widget);
3870 g_object_freeze_notify (G_OBJECT (widget));
3871 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3873 toplevel = gtk_widget_get_toplevel (widget);
3874 if (gtk_widget_is_toplevel (toplevel))
3875 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3877 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3878 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3880 gtk_widget_queue_draw_child (widget);
3882 /* Reset the width and height here, to force reallocation if we
3883 * get added back to a new parent. This won't work if our new
3884 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3885 * (would 0x0 be OK here?)
3887 priv->allocation.width = 1;
3888 priv->allocation.height = 1;
3890 if (gtk_widget_get_realized (widget))
3892 if (priv->in_reparent)
3893 gtk_widget_unmap (widget);
3895 gtk_widget_unrealize (widget);
3898 /* If we are unanchoring the child, we save around the toplevel
3899 * to emit hierarchy changed
3901 if (priv->parent->priv->anchored)
3902 g_object_ref (toplevel);
3906 /* Removing a widget from a container restores the child visible
3907 * flag to the default state, so it doesn't affect the child
3908 * in the next parent.
3910 priv->child_visible = TRUE;
3912 old_parent = priv->parent;
3913 priv->parent = NULL;
3915 /* parent may no longer expand if the removed
3916 * child was expand=TRUE and could therefore
3919 if (gtk_widget_get_visible (widget) &&
3920 (priv->need_compute_expand ||
3921 priv->computed_hexpand ||
3922 priv->computed_vexpand))
3924 gtk_widget_queue_compute_expand (old_parent);
3927 /* Unset BACKDROP since we are no longer inside a toplevel window */
3928 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3930 gtk_style_context_set_parent (priv->context, NULL);
3932 _gtk_widget_update_parent_muxer (widget);
3934 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3937 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3938 g_object_unref (toplevel);
3941 /* Now that the parent pointer is nullified and the hierarchy-changed
3942 * already passed, go ahead and unset the parent window, if we are unparenting
3943 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3944 * will fire again for the new subhierarchy.
3946 gtk_widget_set_parent_window (widget, NULL);
3948 g_object_notify (G_OBJECT (widget), "parent");
3949 g_object_thaw_notify (G_OBJECT (widget));
3951 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3952 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3954 gtk_widget_pop_verify_invariants (widget);
3955 g_object_unref (widget);
3959 * gtk_widget_destroy:
3960 * @widget: a #GtkWidget
3962 * Destroys a widget.
3965 * destroyed, it will break any references it holds to other objects.
3966 * If the widget is inside a container, the widget will be removed
3967 * from the container. If the widget is a toplevel (derived from
3968 * #GtkWindow), it will be removed from the list of toplevels, and the
3969 * reference GTK+ holds to it will be removed. Removing a
3970 * widget from its container or the list of toplevels results in the
3971 * widget being finalized, unless you've added additional references
3972 * to the widget with g_object_ref().
3974 * In most cases, only toplevel widgets (windows) require explicit
3975 * destruction, because when you destroy a toplevel its children will
3976 * be destroyed as well.
3979 gtk_widget_destroy (GtkWidget *widget)
3981 g_return_if_fail (GTK_IS_WIDGET (widget));
3983 if (!widget->priv->in_destruction)
3984 g_object_run_dispose (G_OBJECT (widget));
3988 * gtk_widget_destroyed:
3989 * @widget: a #GtkWidget
3990 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3992 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3993 * %NULL. It's intended to be used as a callback connected to the
3994 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3995 * as a signal handler, and pass the address of your widget variable
3996 * as user data. Then when the widget is destroyed, the variable will
3997 * be set to %NULL. Useful for example to avoid multiple copies
3998 * of the same dialog.
4001 gtk_widget_destroyed (GtkWidget *widget,
4002 GtkWidget **widget_pointer)
4004 /* Don't make any assumptions about the
4006 * Even check widget_pointer.
4009 *widget_pointer = NULL;
4014 * @widget: a #GtkWidget
4016 * Flags a widget to be displayed. Any widget that isn't shown will
4017 * not appear on the screen. If you want to show all the widgets in a
4018 * container, it's easier to call gtk_widget_show_all() on the
4019 * container, instead of individually showing the widgets.
4021 * Remember that you have to show the containers containing a widget,
4022 * in addition to the widget itself, before it will appear onscreen.
4024 * When a toplevel container is shown, it is immediately realized and
4025 * mapped; other shown widgets are realized and mapped when their
4026 * toplevel container is realized and mapped.
4029 gtk_widget_show (GtkWidget *widget)
4031 g_return_if_fail (GTK_IS_WIDGET (widget));
4033 if (!gtk_widget_get_visible (widget))
4035 g_object_ref (widget);
4036 gtk_widget_push_verify_invariants (widget);
4038 if (!gtk_widget_is_toplevel (widget))
4039 gtk_widget_queue_resize (widget);
4041 /* see comment in set_parent() for why this should and can be
4044 if (widget->priv->need_compute_expand ||
4045 widget->priv->computed_hexpand ||
4046 widget->priv->computed_vexpand)
4048 if (widget->priv->parent != NULL)
4049 gtk_widget_queue_compute_expand (widget->priv->parent);
4052 g_signal_emit (widget, widget_signals[SHOW], 0);
4053 g_object_notify (G_OBJECT (widget), "visible");
4055 gtk_widget_pop_verify_invariants (widget);
4056 g_object_unref (widget);
4061 gtk_widget_real_show (GtkWidget *widget)
4063 GtkWidgetPrivate *priv = widget->priv;
4065 if (!gtk_widget_get_visible (widget))
4067 priv->visible = TRUE;
4070 gtk_widget_get_mapped (priv->parent) &&
4071 gtk_widget_get_child_visible (widget) &&
4072 !gtk_widget_get_mapped (widget))
4073 gtk_widget_map (widget);
4078 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4081 g_signal_handlers_disconnect_by_func (widget,
4082 gtk_widget_show_map_callback,
4087 * gtk_widget_show_now:
4088 * @widget: a #GtkWidget
4090 * Shows a widget. If the widget is an unmapped toplevel widget
4091 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4092 * loop and wait for the window to actually be mapped. Be careful;
4093 * because the main loop is running, anything can happen during
4097 gtk_widget_show_now (GtkWidget *widget)
4101 g_return_if_fail (GTK_IS_WIDGET (widget));
4103 /* make sure we will get event */
4104 if (!gtk_widget_get_mapped (widget) &&
4105 gtk_widget_is_toplevel (widget))
4107 gtk_widget_show (widget);
4109 g_signal_connect (widget, "map-event",
4110 G_CALLBACK (gtk_widget_show_map_callback),
4114 gtk_main_iteration ();
4117 gtk_widget_show (widget);
4122 * @widget: a #GtkWidget
4124 * Reverses the effects of gtk_widget_show(), causing the widget to be
4125 * hidden (invisible to the user).
4128 gtk_widget_hide (GtkWidget *widget)
4130 g_return_if_fail (GTK_IS_WIDGET (widget));
4132 if (gtk_widget_get_visible (widget))
4134 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4136 g_object_ref (widget);
4137 gtk_widget_push_verify_invariants (widget);
4139 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4140 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4142 /* a parent may now be expand=FALSE since we're hidden. */
4143 if (widget->priv->need_compute_expand ||
4144 widget->priv->computed_hexpand ||
4145 widget->priv->computed_vexpand)
4147 gtk_widget_queue_compute_expand (widget);
4150 g_signal_emit (widget, widget_signals[HIDE], 0);
4151 if (!gtk_widget_is_toplevel (widget))
4152 gtk_widget_queue_resize (widget);
4153 g_object_notify (G_OBJECT (widget), "visible");
4155 gtk_widget_pop_verify_invariants (widget);
4156 g_object_unref (widget);
4161 gtk_widget_real_hide (GtkWidget *widget)
4163 if (gtk_widget_get_visible (widget))
4165 widget->priv->visible = FALSE;
4167 if (gtk_widget_get_mapped (widget))
4168 gtk_widget_unmap (widget);
4173 * gtk_widget_hide_on_delete:
4174 * @widget: a #GtkWidget
4176 * Utility function; intended to be connected to the #GtkWidget::delete-event
4177 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4178 * argument, then returns %TRUE. If connected to ::delete-event, the
4179 * result is that clicking the close button for a window (on the
4180 * window frame, top right corner usually) will hide but not destroy
4181 * the window. By default, GTK+ destroys windows when ::delete-event
4184 * Return value: %TRUE
4187 gtk_widget_hide_on_delete (GtkWidget *widget)
4189 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4191 gtk_widget_hide (widget);
4197 * gtk_widget_show_all:
4198 * @widget: a #GtkWidget
4200 * Recursively shows a widget, and any child widgets (if the widget is
4204 gtk_widget_show_all (GtkWidget *widget)
4206 GtkWidgetClass *class;
4208 g_return_if_fail (GTK_IS_WIDGET (widget));
4210 if (gtk_widget_get_no_show_all (widget))
4213 class = GTK_WIDGET_GET_CLASS (widget);
4215 if (class->show_all)
4216 class->show_all (widget);
4221 * @widget: a #GtkWidget
4223 * This function is only for use in widget implementations. Causes
4224 * a widget to be mapped if it isn't already.
4227 gtk_widget_map (GtkWidget *widget)
4229 GtkWidgetPrivate *priv;
4231 g_return_if_fail (GTK_IS_WIDGET (widget));
4232 g_return_if_fail (gtk_widget_get_visible (widget));
4233 g_return_if_fail (gtk_widget_get_child_visible (widget));
4235 priv = widget->priv;
4237 if (!gtk_widget_get_mapped (widget))
4239 gtk_widget_push_verify_invariants (widget);
4241 if (!gtk_widget_get_realized (widget))
4242 gtk_widget_realize (widget);
4244 g_signal_emit (widget, widget_signals[MAP], 0);
4246 if (!gtk_widget_get_has_window (widget))
4247 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4249 if (widget->priv->context)
4250 _gtk_style_context_update_animating (widget->priv->context);
4252 gtk_widget_pop_verify_invariants (widget);
4258 * @widget: a #GtkWidget
4260 * This function is only for use in widget implementations. Causes
4261 * a widget to be unmapped if it's currently mapped.
4264 gtk_widget_unmap (GtkWidget *widget)
4266 GtkWidgetPrivate *priv;
4268 g_return_if_fail (GTK_IS_WIDGET (widget));
4270 priv = widget->priv;
4272 if (gtk_widget_get_mapped (widget))
4274 gtk_widget_push_verify_invariants (widget);
4276 if (!gtk_widget_get_has_window (widget))
4277 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4278 _gtk_tooltip_hide (widget);
4280 if (widget->priv->context)
4281 _gtk_style_context_update_animating (widget->priv->context);
4283 g_signal_emit (widget, widget_signals[UNMAP], 0);
4285 gtk_widget_pop_verify_invariants (widget);
4287 /* Unset pointer/window info */
4288 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4293 _gtk_widget_enable_device_events (GtkWidget *widget)
4295 GHashTable *device_events;
4296 GHashTableIter iter;
4297 gpointer key, value;
4299 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4304 g_hash_table_iter_init (&iter, device_events);
4306 while (g_hash_table_iter_next (&iter, &key, &value))
4309 GdkEventMask event_mask;
4312 event_mask = GPOINTER_TO_UINT (value);
4313 gtk_widget_add_events_internal (widget, device, event_mask);
4318 get_widget_windows (GtkWidget *widget)
4320 GList *window_list, *last, *l, *children, *ret;
4322 if (gtk_widget_get_has_window (widget))
4323 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4325 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4327 last = g_list_last (window_list);
4330 for (l = window_list; l; l = l->next)
4332 GtkWidget *window_widget = NULL;
4334 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4336 if (widget != window_widget)
4339 ret = g_list_prepend (ret, l->data);
4340 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4344 last = g_list_concat (last, children);
4345 last = g_list_last (last);
4349 g_list_free (window_list);
4355 device_enable_foreach (GtkWidget *widget,
4358 GdkDevice *device = user_data;
4359 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4363 device_disable_foreach (GtkWidget *widget,
4366 GdkDevice *device = user_data;
4367 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4371 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4376 GList *window_list, *l;
4378 window_list = get_widget_windows (widget);
4380 for (l = window_list; l; l = l->next)
4382 GdkEventMask events = 0;
4388 events = gdk_window_get_events (window);
4390 gdk_window_set_device_events (window, device, events);
4393 if (recurse && GTK_IS_CONTAINER (widget))
4396 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4398 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4401 g_list_free (window_list);
4405 gtk_widget_update_devices_mask (GtkWidget *widget,
4408 GList *enabled_devices, *l;
4410 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4412 for (l = enabled_devices; l; l = l->next)
4413 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4417 * gtk_widget_realize:
4418 * @widget: a #GtkWidget
4420 * Creates the GDK (windowing system) resources associated with a
4421 * widget. For example, @widget->window will be created when a widget
4422 * is realized. Normally realization happens implicitly; if you show
4423 * a widget and all its parent containers, then the widget will be
4424 * realized and mapped automatically.
4426 * Realizing a widget requires all
4427 * the widget's parent widgets to be realized; calling
4428 * gtk_widget_realize() realizes the widget's parents in addition to
4429 * @widget itself. If a widget is not yet inside a toplevel window
4430 * when you realize it, bad things will happen.
4432 * This function is primarily used in widget implementations, and
4433 * isn't very useful otherwise. Many times when you think you might
4434 * need it, a better approach is to connect to a signal that will be
4435 * called after the widget is realized automatically, such as
4436 * #GtkWidget::draw. Or simply g_signal_connect () to the
4437 * #GtkWidget::realize signal.
4440 gtk_widget_realize (GtkWidget *widget)
4442 GtkWidgetPrivate *priv;
4443 cairo_region_t *region;
4445 g_return_if_fail (GTK_IS_WIDGET (widget));
4446 g_return_if_fail (widget->priv->anchored ||
4447 GTK_IS_INVISIBLE (widget));
4449 priv = widget->priv;
4451 if (!gtk_widget_get_realized (widget))
4453 gtk_widget_push_verify_invariants (widget);
4456 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4457 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4460 if (priv->parent == NULL &&
4461 !gtk_widget_is_toplevel (widget))
4462 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4463 "inside a toplevel window is not going to work very well. "
4464 "Widgets must be inside a toplevel container before realizing them.");
4466 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4467 gtk_widget_realize (priv->parent);
4469 gtk_widget_ensure_style (widget);
4471 if (priv->style_update_pending)
4472 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4474 g_signal_emit (widget, widget_signals[REALIZE], 0);
4476 gtk_widget_real_set_has_tooltip (widget,
4477 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4480 if (priv->has_shape_mask)
4482 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4483 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4486 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4488 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4490 if (priv->multidevice)
4491 gdk_window_set_support_multidevice (priv->window, TRUE);
4493 _gtk_widget_enable_device_events (widget);
4494 gtk_widget_update_devices_mask (widget, TRUE);
4496 gtk_widget_pop_verify_invariants (widget);
4501 * gtk_widget_unrealize:
4502 * @widget: a #GtkWidget
4504 * This function is only useful in widget implementations.
4505 * Causes a widget to be unrealized (frees all GDK resources
4506 * associated with the widget, such as @widget->window).
4509 gtk_widget_unrealize (GtkWidget *widget)
4511 g_return_if_fail (GTK_IS_WIDGET (widget));
4513 gtk_widget_push_verify_invariants (widget);
4515 if (widget->priv->has_shape_mask)
4516 gtk_widget_shape_combine_region (widget, NULL);
4518 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4519 gtk_widget_input_shape_combine_region (widget, NULL);
4521 if (gtk_widget_get_realized (widget))
4523 g_object_ref (widget);
4525 if (widget->priv->mapped)
4526 gtk_widget_unmap (widget);
4528 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4529 g_assert (!widget->priv->mapped);
4530 gtk_widget_set_realized (widget, FALSE);
4532 g_object_unref (widget);
4535 gtk_widget_pop_verify_invariants (widget);
4538 /*****************************************
4540 *****************************************/
4543 * gtk_widget_queue_draw_region:
4544 * @widget: a #GtkWidget
4545 * @region: region to draw
4547 * Invalidates the rectangular area of @widget defined by @region by
4548 * calling gdk_window_invalidate_region() on the widget's window and
4549 * all its child windows. Once the main loop becomes idle (after the
4550 * current batch of events has been processed, roughly), the window
4551 * will receive expose events for the union of all regions that have
4554 * Normally you would only use this function in widget
4555 * implementations. You might also use it to schedule a redraw of a
4556 * #GtkDrawingArea or some portion thereof.
4561 gtk_widget_queue_draw_region (GtkWidget *widget,
4562 const cairo_region_t *region)
4564 GtkWidgetPrivate *priv;
4567 g_return_if_fail (GTK_IS_WIDGET (widget));
4569 priv = widget->priv;
4571 if (!gtk_widget_get_realized (widget))
4574 /* Just return if the widget or one of its ancestors isn't mapped */
4575 for (w = widget; w != NULL; w = w->priv->parent)
4576 if (!gtk_widget_get_mapped (w))
4579 gdk_window_invalidate_region (priv->window, region, TRUE);
4583 * gtk_widget_queue_draw_area:
4584 * @widget: a #GtkWidget
4585 * @x: x coordinate of upper-left corner of rectangle to redraw
4586 * @y: y coordinate of upper-left corner of rectangle to redraw
4587 * @width: width of region to draw
4588 * @height: height of region to draw
4590 * Convenience function that calls gtk_widget_queue_draw_region() on
4591 * the region created from the given coordinates.
4593 * The region here is specified in widget coordinates.
4594 * Widget coordinates are a bit odd; for historical reasons, they are
4595 * defined as @widget->window coordinates for widgets that are not
4596 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4597 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4600 gtk_widget_queue_draw_area (GtkWidget *widget,
4607 cairo_region_t *region;
4609 g_return_if_fail (GTK_IS_WIDGET (widget));
4614 rect.height = height;
4616 region = cairo_region_create_rectangle (&rect);
4617 gtk_widget_queue_draw_region (widget, region);
4618 cairo_region_destroy (region);
4622 * gtk_widget_queue_draw:
4623 * @widget: a #GtkWidget
4625 * Equivalent to calling gtk_widget_queue_draw_area() for the
4626 * entire area of a widget.
4629 gtk_widget_queue_draw (GtkWidget *widget)
4633 g_return_if_fail (GTK_IS_WIDGET (widget));
4635 gtk_widget_get_allocation (widget, &rect);
4637 if (!gtk_widget_get_has_window (widget))
4638 gtk_widget_queue_draw_area (widget,
4639 rect.x, rect.y, rect.width, rect.height);
4641 gtk_widget_queue_draw_area (widget,
4642 0, 0, rect.width, rect.height);
4646 * gtk_widget_queue_resize:
4647 * @widget: a #GtkWidget
4649 * This function is only for use in widget implementations.
4650 * Flags a widget to have its size renegotiated; should
4651 * be called when a widget for some reason has a new size request.
4652 * For example, when you change the text in a #GtkLabel, #GtkLabel
4653 * queues a resize to ensure there's enough space for the new text.
4655 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4656 * from inside its implementation of the GtkWidgetClass::size_allocate
4657 * virtual method. Calls to gtk_widget_queue_resize() from inside
4658 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4661 gtk_widget_queue_resize (GtkWidget *widget)
4663 g_return_if_fail (GTK_IS_WIDGET (widget));
4665 if (gtk_widget_get_realized (widget))
4666 gtk_widget_queue_draw (widget);
4668 _gtk_size_group_queue_resize (widget, 0);
4672 * gtk_widget_queue_resize_no_redraw:
4673 * @widget: a #GtkWidget
4675 * This function works like gtk_widget_queue_resize(),
4676 * except that the widget is not invalidated.
4681 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4683 g_return_if_fail (GTK_IS_WIDGET (widget));
4685 _gtk_size_group_queue_resize (widget, 0);
4689 * gtk_widget_size_request:
4690 * @widget: a #GtkWidget
4691 * @requisition: (out): a #GtkRequisition to be filled in
4693 * This function is typically used when implementing a #GtkContainer
4694 * subclass. Obtains the preferred size of a widget. The container
4695 * uses this information to arrange its child widgets and decide what
4696 * size allocations to give them with gtk_widget_size_allocate().
4698 * You can also call this function from an application, with some
4699 * caveats. Most notably, getting a size request requires the widget
4700 * to be associated with a screen, because font information may be
4701 * needed. Multihead-aware applications should keep this in mind.
4703 * Also remember that the size request is not necessarily the size
4704 * a widget will actually be allocated.
4706 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4709 gtk_widget_size_request (GtkWidget *widget,
4710 GtkRequisition *requisition)
4712 g_return_if_fail (GTK_IS_WIDGET (widget));
4714 gtk_widget_get_preferred_size (widget, requisition, NULL);
4718 * gtk_widget_get_child_requisition:
4719 * @widget: a #GtkWidget
4720 * @requisition: (out): a #GtkRequisition to be filled in
4722 * This function is only for use in widget implementations. Obtains
4723 * @widget->requisition, unless someone has forced a particular
4724 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4725 * in which case it returns that geometry instead of the widget's
4728 * This function differs from gtk_widget_size_request() in that
4729 * it retrieves the last size request value from @widget->requisition,
4730 * while gtk_widget_size_request() actually calls the "size_request" method
4731 * on @widget to compute the size request and fill in @widget->requisition,
4732 * and only then returns @widget->requisition.
4734 * Because this function does not call the "size_request" method, it
4735 * can only be used when you know that @widget->requisition is
4736 * up-to-date, that is, gtk_widget_size_request() has been called
4737 * since the last time a resize was queued. In general, only container
4738 * implementations have this information; applications should use
4739 * gtk_widget_size_request().
4742 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4745 gtk_widget_get_child_requisition (GtkWidget *widget,
4746 GtkRequisition *requisition)
4748 gtk_widget_get_preferred_size (widget, requisition, NULL);
4752 invalidate_predicate (GdkWindow *window,
4757 gdk_window_get_user_data (window, &user_data);
4759 return (user_data == data);
4762 /* Invalidate @region in widget->window and all children
4763 * of widget->window owned by widget. @region is in the
4764 * same coordinates as widget->allocation and will be
4765 * modified by this call.
4768 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4769 cairo_region_t *region)
4771 GtkWidgetPrivate *priv = widget->priv;
4773 if (!gtk_widget_get_realized (widget))
4776 if (gtk_widget_get_has_window (widget) && priv->parent)
4780 gdk_window_get_position (priv->window, &x, &y);
4781 cairo_region_translate (region, -x, -y);
4784 gdk_window_invalidate_maybe_recurse (priv->window, region,
4785 invalidate_predicate, widget);
4789 * gtk_widget_size_allocate:
4790 * @widget: a #GtkWidget
4791 * @allocation: position and size to be allocated to @widget
4793 * This function is only used by #GtkContainer subclasses, to assign a size
4794 * and position to their child widgets.
4796 * In this function, the allocation may be adjusted. It will be forced
4797 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4798 * method on the child will be used to adjust the allocation. Standard
4799 * adjustments include removing the widget's margins, and applying the
4800 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4803 gtk_widget_size_allocate (GtkWidget *widget,
4804 GtkAllocation *allocation)
4806 GtkWidgetPrivate *priv;
4807 GdkRectangle real_allocation;
4808 GdkRectangle old_allocation;
4809 GdkRectangle adjusted_allocation;
4810 gboolean alloc_needed;
4811 gboolean size_changed;
4812 gboolean position_changed;
4813 gint natural_width, natural_height, dummy;
4814 gint min_width, min_height;
4816 priv = widget->priv;
4818 g_return_if_fail (GTK_IS_WIDGET (widget));
4820 gtk_widget_push_verify_invariants (widget);
4822 #ifdef G_ENABLE_DEBUG
4823 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4834 parent = gtk_widget_get_parent (parent);
4837 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4838 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4839 2 * depth, " ", name,
4840 allocation->width, allocation->height);
4842 #endif /* G_ENABLE_DEBUG */
4844 alloc_needed = priv->alloc_needed;
4845 /* Preserve request/allocate ordering */
4846 priv->alloc_needed = FALSE;
4848 old_allocation = priv->allocation;
4849 real_allocation = *allocation;
4851 adjusted_allocation = real_allocation;
4852 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4854 /* Go ahead and request the height for allocated width, note that the internals
4855 * of get_height_for_width will internally limit the for_size to natural size
4856 * when aligning implicitly.
4858 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4859 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4863 /* Go ahead and request the width for allocated height, note that the internals
4864 * of get_width_for_height will internally limit the for_size to natural size
4865 * when aligning implicitly.
4867 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4868 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4871 #ifdef G_ENABLE_DEBUG
4872 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4874 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4875 !GTK_IS_SCROLLABLE (widget))
4876 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4877 "Allocation is %dx%d, but minimum required size is %dx%d.",
4878 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4879 G_OBJECT_TYPE_NAME (widget), widget,
4880 real_allocation.width, real_allocation.height,
4881 min_width, min_height);
4884 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4885 * allocated sizes and possibly limit them to the natural sizes */
4886 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4887 GTK_ORIENTATION_HORIZONTAL,
4890 &adjusted_allocation.x,
4891 &adjusted_allocation.width);
4892 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4893 GTK_ORIENTATION_VERTICAL,
4896 &adjusted_allocation.y,
4897 &adjusted_allocation.height);
4899 if (adjusted_allocation.x < real_allocation.x ||
4900 adjusted_allocation.y < real_allocation.y ||
4901 (adjusted_allocation.x + adjusted_allocation.width) >
4902 (real_allocation.x + real_allocation.width) ||
4903 (adjusted_allocation.y + adjusted_allocation.height >
4904 real_allocation.y + real_allocation.height))
4906 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",
4907 G_OBJECT_TYPE_NAME (widget), widget,
4908 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4909 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4910 adjusted_allocation = real_allocation; /* veto it */
4914 real_allocation = adjusted_allocation;
4917 if (real_allocation.width < 0 || real_allocation.height < 0)
4919 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4920 real_allocation.width,
4921 real_allocation.height);
4924 real_allocation.width = MAX (real_allocation.width, 1);
4925 real_allocation.height = MAX (real_allocation.height, 1);
4927 size_changed = (old_allocation.width != real_allocation.width ||
4928 old_allocation.height != real_allocation.height);
4929 position_changed = (old_allocation.x != real_allocation.x ||
4930 old_allocation.y != real_allocation.y);
4932 if (!alloc_needed && !size_changed && !position_changed)
4935 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4937 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4938 priv->alloc_needed = FALSE;
4940 if (gtk_widget_get_mapped (widget))
4942 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4944 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4946 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4947 cairo_region_union_rectangle (invalidate, &old_allocation);
4949 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4950 cairo_region_destroy (invalidate);
4955 if (priv->redraw_on_alloc)
4957 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4959 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4960 cairo_region_union_rectangle (invalidate, &old_allocation);
4962 gtk_widget_invalidate_widget_windows (widget, invalidate);
4963 cairo_region_destroy (invalidate);
4968 if ((size_changed || position_changed) && priv->parent &&
4969 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4971 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4972 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4973 cairo_region_destroy (invalidate);
4977 gtk_widget_pop_verify_invariants (widget);
4981 * gtk_widget_common_ancestor:
4982 * @widget_a: a #GtkWidget
4983 * @widget_b: a #GtkWidget
4985 * Find the common ancestor of @widget_a and @widget_b that
4986 * is closest to the two widgets.
4988 * Return value: the closest common ancestor of @widget_a and
4989 * @widget_b or %NULL if @widget_a and @widget_b do not
4990 * share a common ancestor.
4993 gtk_widget_common_ancestor (GtkWidget *widget_a,
4994 GtkWidget *widget_b)
4996 GtkWidget *parent_a;
4997 GtkWidget *parent_b;
5001 parent_a = widget_a;
5002 while (parent_a->priv->parent)
5004 parent_a = parent_a->priv->parent;
5008 parent_b = widget_b;
5009 while (parent_b->priv->parent)
5011 parent_b = parent_b->priv->parent;
5015 if (parent_a != parent_b)
5018 while (depth_a > depth_b)
5020 widget_a = widget_a->priv->parent;
5024 while (depth_b > depth_a)
5026 widget_b = widget_b->priv->parent;
5030 while (widget_a != widget_b)
5032 widget_a = widget_a->priv->parent;
5033 widget_b = widget_b->priv->parent;
5040 * gtk_widget_translate_coordinates:
5041 * @src_widget: a #GtkWidget
5042 * @dest_widget: a #GtkWidget
5043 * @src_x: X position relative to @src_widget
5044 * @src_y: Y position relative to @src_widget
5045 * @dest_x: (out): location to store X position relative to @dest_widget
5046 * @dest_y: (out): location to store Y position relative to @dest_widget
5048 * Translate coordinates relative to @src_widget's allocation to coordinates
5049 * relative to @dest_widget's allocations. In order to perform this
5050 * operation, both widgets must be realized, and must share a common
5053 * Return value: %FALSE if either widget was not realized, or there
5054 * was no common ancestor. In this case, nothing is stored in
5055 * *@dest_x and *@dest_y. Otherwise %TRUE.
5058 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5059 GtkWidget *dest_widget,
5065 GtkWidgetPrivate *src_priv = src_widget->priv;
5066 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5067 GtkWidget *ancestor;
5069 GList *dest_list = NULL;
5071 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5072 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5074 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5075 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5078 /* Translate from allocation relative to window relative */
5079 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5082 gdk_window_get_position (src_priv->window, &wx, &wy);
5084 src_x -= wx - src_priv->allocation.x;
5085 src_y -= wy - src_priv->allocation.y;
5089 src_x += src_priv->allocation.x;
5090 src_y += src_priv->allocation.y;
5093 /* Translate to the common ancestor */
5094 window = src_priv->window;
5095 while (window != ancestor->priv->window)
5099 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5104 window = gdk_window_get_effective_parent (window);
5106 if (!window) /* Handle GtkHandleBox */
5111 window = dest_priv->window;
5112 while (window != ancestor->priv->window)
5114 dest_list = g_list_prepend (dest_list, window);
5116 window = gdk_window_get_effective_parent (window);
5118 if (!window) /* Handle GtkHandleBox */
5120 g_list_free (dest_list);
5129 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5134 dest_list = g_list_remove (dest_list, dest_list->data);
5137 /* Translate from window relative to allocation relative */
5138 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5141 gdk_window_get_position (dest_priv->window, &wx, &wy);
5143 src_x += wx - dest_priv->allocation.x;
5144 src_y += wy - dest_priv->allocation.y;
5148 src_x -= dest_priv->allocation.x;
5149 src_y -= dest_priv->allocation.y;
5161 gtk_widget_real_size_allocate (GtkWidget *widget,
5162 GtkAllocation *allocation)
5164 GtkWidgetPrivate *priv = widget->priv;
5166 priv->allocation = *allocation;
5168 if (gtk_widget_get_realized (widget) &&
5169 gtk_widget_get_has_window (widget))
5171 gdk_window_move_resize (priv->window,
5172 allocation->x, allocation->y,
5173 allocation->width, allocation->height);
5177 /* translate initial/final into start/end */
5179 effective_align (GtkAlign align,
5180 GtkTextDirection direction)
5184 case GTK_ALIGN_START:
5185 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5187 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5194 adjust_for_align (GtkAlign align,
5196 gint *allocated_pos,
5197 gint *allocated_size)
5201 case GTK_ALIGN_FILL:
5202 /* change nothing */
5204 case GTK_ALIGN_START:
5205 /* keep *allocated_pos where it is */
5206 *allocated_size = MIN (*allocated_size, *natural_size);
5209 if (*allocated_size > *natural_size)
5211 *allocated_pos += (*allocated_size - *natural_size);
5212 *allocated_size = *natural_size;
5215 case GTK_ALIGN_CENTER:
5216 if (*allocated_size > *natural_size)
5218 *allocated_pos += (*allocated_size - *natural_size) / 2;
5219 *allocated_size = MIN (*allocated_size, *natural_size);
5226 adjust_for_margin(gint start_margin,
5230 gint *allocated_pos,
5231 gint *allocated_size)
5233 *minimum_size -= (start_margin + end_margin);
5234 *natural_size -= (start_margin + end_margin);
5235 *allocated_pos += start_margin;
5236 *allocated_size -= (start_margin + end_margin);
5240 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5241 GtkOrientation orientation,
5244 gint *allocated_pos,
5245 gint *allocated_size)
5247 const GtkWidgetAuxInfo *aux_info;
5249 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5251 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5253 adjust_for_margin (aux_info->margin.left,
5254 aux_info->margin.right,
5255 minimum_size, natural_size,
5256 allocated_pos, allocated_size);
5257 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5258 natural_size, allocated_pos, allocated_size);
5262 adjust_for_margin (aux_info->margin.top,
5263 aux_info->margin.bottom,
5264 minimum_size, natural_size,
5265 allocated_pos, allocated_size);
5266 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5267 natural_size, allocated_pos, allocated_size);
5272 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5275 GtkWidgetPrivate *priv = widget->priv;
5277 /* widgets must be onscreen for accels to take effect */
5278 return gtk_widget_is_sensitive (widget) &&
5279 gtk_widget_is_drawable (widget) &&
5280 gdk_window_is_viewable (priv->window);
5284 * gtk_widget_can_activate_accel:
5285 * @widget: a #GtkWidget
5286 * @signal_id: the ID of a signal installed on @widget
5288 * Determines whether an accelerator that activates the signal
5289 * identified by @signal_id can currently be activated.
5290 * This is done by emitting the #GtkWidget::can-activate-accel
5291 * signal on @widget; if the signal isn't overridden by a
5292 * handler or in a derived widget, then the default check is
5293 * that the widget must be sensitive, and the widget and all
5294 * its ancestors mapped.
5296 * Return value: %TRUE if the accelerator can be activated.
5301 gtk_widget_can_activate_accel (GtkWidget *widget,
5304 gboolean can_activate = FALSE;
5305 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5306 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5307 return can_activate;
5316 closure_accel_activate (GClosure *closure,
5317 GValue *return_value,
5318 guint n_param_values,
5319 const GValue *param_values,
5320 gpointer invocation_hint,
5321 gpointer marshal_data)
5323 AccelClosure *aclosure = (AccelClosure*) closure;
5324 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5327 g_signal_emit (closure->data, aclosure->signal_id, 0);
5329 /* whether accelerator was handled */
5330 g_value_set_boolean (return_value, can_activate);
5334 closures_destroy (gpointer data)
5336 GSList *slist, *closures = data;
5338 for (slist = closures; slist; slist = slist->next)
5340 g_closure_invalidate (slist->data);
5341 g_closure_unref (slist->data);
5343 g_slist_free (closures);
5347 widget_new_accel_closure (GtkWidget *widget,
5350 AccelClosure *aclosure;
5351 GClosure *closure = NULL;
5352 GSList *slist, *closures;
5354 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5355 for (slist = closures; slist; slist = slist->next)
5356 if (!gtk_accel_group_from_accel_closure (slist->data))
5358 /* reuse this closure */
5359 closure = slist->data;
5364 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5365 closures = g_slist_prepend (closures, g_closure_ref (closure));
5366 g_closure_sink (closure);
5367 g_closure_set_marshal (closure, closure_accel_activate);
5369 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5371 aclosure = (AccelClosure*) closure;
5372 g_assert (closure->data == widget);
5373 g_assert (closure->marshal == closure_accel_activate);
5374 aclosure->signal_id = signal_id;
5380 * gtk_widget_add_accelerator:
5381 * @widget: widget to install an accelerator on
5382 * @accel_signal: widget signal to emit on accelerator activation
5383 * @accel_group: accel group for this widget, added to its toplevel
5384 * @accel_key: GDK keyval of the accelerator
5385 * @accel_mods: modifier key combination of the accelerator
5386 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5388 * Installs an accelerator for this @widget in @accel_group that causes
5389 * @accel_signal to be emitted if the accelerator is activated.
5390 * The @accel_group needs to be added to the widget's toplevel via
5391 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5392 * Accelerators added through this function are not user changeable during
5393 * runtime. If you want to support accelerators that can be changed by the
5394 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5395 * gtk_menu_item_set_accel_path() instead.
5398 gtk_widget_add_accelerator (GtkWidget *widget,
5399 const gchar *accel_signal,
5400 GtkAccelGroup *accel_group,
5402 GdkModifierType accel_mods,
5403 GtkAccelFlags accel_flags)
5408 g_return_if_fail (GTK_IS_WIDGET (widget));
5409 g_return_if_fail (accel_signal != NULL);
5410 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5412 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5413 if (!query.signal_id ||
5414 !(query.signal_flags & G_SIGNAL_ACTION) ||
5415 query.return_type != G_TYPE_NONE ||
5418 /* hmm, should be elaborate enough */
5419 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5420 G_OBJECT_TYPE_NAME (widget), accel_signal);
5424 closure = widget_new_accel_closure (widget, query.signal_id);
5426 g_object_ref (widget);
5428 /* install the accelerator. since we don't map this onto an accel_path,
5429 * the accelerator will automatically be locked.
5431 gtk_accel_group_connect (accel_group,
5434 accel_flags | GTK_ACCEL_LOCKED,
5437 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5439 g_object_unref (widget);
5443 * gtk_widget_remove_accelerator:
5444 * @widget: widget to install an accelerator on
5445 * @accel_group: accel group for this widget
5446 * @accel_key: GDK keyval of the accelerator
5447 * @accel_mods: modifier key combination of the accelerator
5449 * Removes an accelerator from @widget, previously installed with
5450 * gtk_widget_add_accelerator().
5452 * Returns: whether an accelerator was installed and could be removed
5455 gtk_widget_remove_accelerator (GtkWidget *widget,
5456 GtkAccelGroup *accel_group,
5458 GdkModifierType accel_mods)
5460 GtkAccelGroupEntry *ag_entry;
5461 GList *slist, *clist;
5464 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5465 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5467 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5468 clist = gtk_widget_list_accel_closures (widget);
5469 for (slist = clist; slist; slist = slist->next)
5473 for (i = 0; i < n; i++)
5474 if (slist->data == (gpointer) ag_entry[i].closure)
5476 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5478 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5480 g_list_free (clist);
5485 g_list_free (clist);
5487 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5488 accel_key, accel_mods, accel_group,
5489 G_OBJECT_TYPE_NAME (widget), widget);
5495 * gtk_widget_list_accel_closures:
5496 * @widget: widget to list accelerator closures for
5498 * Lists the closures used by @widget for accelerator group connections
5499 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5500 * The closures can be used to monitor accelerator changes on @widget,
5501 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5502 * #GtkAccelGroup of a closure which can be found out with
5503 * gtk_accel_group_from_accel_closure().
5505 * Return value: (transfer container) (element-type GClosure):
5506 * a newly allocated #GList of closures
5509 gtk_widget_list_accel_closures (GtkWidget *widget)
5512 GList *clist = NULL;
5514 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5516 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5517 if (gtk_accel_group_from_accel_closure (slist->data))
5518 clist = g_list_prepend (clist, slist->data);
5524 GtkAccelGroup *accel_group;
5529 destroy_accel_path (gpointer data)
5531 AccelPath *apath = data;
5533 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5535 /* closures_destroy takes care of unrefing the closure */
5536 g_object_unref (apath->accel_group);
5538 g_slice_free (AccelPath, apath);
5543 * gtk_widget_set_accel_path:
5544 * @widget: a #GtkWidget
5545 * @accel_path: (allow-none): path used to look up the accelerator
5546 * @accel_group: (allow-none): a #GtkAccelGroup.
5548 * Given an accelerator group, @accel_group, and an accelerator path,
5549 * @accel_path, sets up an accelerator in @accel_group so whenever the
5550 * key binding that is defined for @accel_path is pressed, @widget
5551 * will be activated. This removes any accelerators (for any
5552 * accelerator group) installed by previous calls to
5553 * gtk_widget_set_accel_path(). Associating accelerators with
5554 * paths allows them to be modified by the user and the modifications
5555 * to be saved for future use. (See gtk_accel_map_save().)
5557 * This function is a low level function that would most likely
5558 * be used by a menu creation system like #GtkUIManager. If you
5559 * use #GtkUIManager, setting up accelerator paths will be done
5562 * Even when you you aren't using #GtkUIManager, if you only want to
5563 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5564 * provides a somewhat more convenient interface.
5566 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5567 * pass a static string, you can save some memory by interning it first with
5568 * g_intern_static_string().
5571 gtk_widget_set_accel_path (GtkWidget *widget,
5572 const gchar *accel_path,
5573 GtkAccelGroup *accel_group)
5577 g_return_if_fail (GTK_IS_WIDGET (widget));
5578 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5582 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5583 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5585 gtk_accel_map_add_entry (accel_path, 0, 0);
5586 apath = g_slice_new (AccelPath);
5587 apath->accel_group = g_object_ref (accel_group);
5588 apath->path_quark = g_quark_from_string (accel_path);
5589 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5594 /* also removes possible old settings */
5595 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5598 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5600 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5604 _gtk_widget_get_accel_path (GtkWidget *widget,
5609 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5611 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5613 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5614 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5618 * gtk_widget_mnemonic_activate:
5619 * @widget: a #GtkWidget
5620 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5622 * Emits the #GtkWidget::mnemonic-activate signal.
5624 * The default handler for this signal activates the @widget if
5625 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5628 * Returns: %TRUE if the signal has been handled
5631 gtk_widget_mnemonic_activate (GtkWidget *widget,
5632 gboolean group_cycling)
5636 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5638 group_cycling = group_cycling != FALSE;
5639 if (!gtk_widget_is_sensitive (widget))
5642 g_signal_emit (widget,
5643 widget_signals[MNEMONIC_ACTIVATE],
5651 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5652 gboolean group_cycling)
5654 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5655 gtk_widget_activate (widget);
5656 else if (gtk_widget_get_can_focus (widget))
5657 gtk_widget_grab_focus (widget);
5660 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5661 G_OBJECT_TYPE_NAME (widget));
5662 gtk_widget_error_bell (widget);
5667 static const cairo_user_data_key_t event_key;
5670 _gtk_cairo_get_event (cairo_t *cr)
5672 g_return_val_if_fail (cr != NULL, NULL);
5674 return cairo_get_user_data (cr, &event_key);
5678 gtk_cairo_set_event (cairo_t *cr,
5679 GdkEventExpose *event)
5681 cairo_set_user_data (cr, &event_key, event, NULL);
5685 * gtk_cairo_should_draw_window:
5686 * @cr: a cairo context
5687 * @window: the window to check. @window may not be an input-only
5690 * This function is supposed to be called in #GtkWidget::draw
5691 * implementations for widgets that support multiple windows.
5692 * @cr must be untransformed from invoking of the draw function.
5693 * This function will return %TRUE if the contents of the given
5694 * @window are supposed to be drawn and %FALSE otherwise. Note
5695 * that when the drawing was not initiated by the windowing
5696 * system this function will return %TRUE for all windows, so
5697 * you need to draw the bottommost window first. Also, do not
5698 * use "else if" statements to check which window should be drawn.
5700 * Returns: %TRUE if @window should be drawn
5705 gtk_cairo_should_draw_window (cairo_t *cr,
5708 GdkEventExpose *event;
5710 g_return_val_if_fail (cr != NULL, FALSE);
5711 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5713 event = _gtk_cairo_get_event (cr);
5715 return event == NULL ||
5716 event->window == window;
5720 gtk_widget_get_clip_draw (GtkWidget *widget)
5722 /* labels are not clipped, because clipping them would cause
5723 * mnemonics to not appear on characters that go beyond the
5725 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5727 if (GTK_IS_LABEL (widget))
5733 /* code shared by gtk_container_propagate_draw() and
5737 _gtk_widget_draw_internal (GtkWidget *widget,
5739 gboolean clip_to_size)
5741 if (!gtk_widget_is_drawable (widget))
5744 clip_to_size &= gtk_widget_get_clip_draw (widget);
5748 cairo_rectangle (cr,
5750 widget->priv->allocation.width,
5751 widget->priv->allocation.height);
5755 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5759 g_signal_emit (widget, widget_signals[DRAW],
5763 if (cairo_status (cr) &&
5764 _gtk_cairo_get_event (cr))
5766 /* We check the event so we only warn about internal GTK calls.
5767 * Errors might come from PDF streams having write failures and
5768 * we don't want to spam stderr in that case.
5769 * We do want to catch errors from
5771 g_warning ("drawing failure for widget `%s': %s",
5772 G_OBJECT_TYPE_NAME (widget),
5773 cairo_status_to_string (cairo_status (cr)));
5780 * @widget: the widget to draw. It must be drawable (see
5781 * gtk_widget_is_drawable()) and a size must have been allocated.
5782 * @cr: a cairo context to draw to
5784 * Draws @widget to @cr. The top left corner of the widget will be
5785 * drawn to the currently set origin point of @cr.
5787 * You should pass a cairo context as @cr argument that is in an
5788 * original state. Otherwise the resulting drawing is undefined. For
5789 * example changing the operator using cairo_set_operator() or the
5790 * line width using cairo_set_line_width() might have unwanted side
5792 * You may however change the context's transform matrix - like with
5793 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5794 * region with cairo_clip() prior to calling this function. Also, it
5795 * is fine to modify the context with cairo_save() and
5796 * cairo_push_group() prior to calling this function.
5798 * <note><para>Special purpose widgets may contain special code for
5799 * rendering to the screen and might appear differently on screen
5800 * and when rendered using gtk_widget_draw().</para></note>
5805 gtk_widget_draw (GtkWidget *widget,
5808 GdkEventExpose *tmp_event;
5810 g_return_if_fail (GTK_IS_WIDGET (widget));
5811 g_return_if_fail (!widget->priv->alloc_needed);
5812 g_return_if_fail (cr != NULL);
5815 /* We have to reset the event here so that draw functions can call
5816 * gtk_widget_draw() on random other widgets and get the desired
5817 * effect: Drawing all contents, not just the current window.
5819 tmp_event = _gtk_cairo_get_event (cr);
5820 gtk_cairo_set_event (cr, NULL);
5822 _gtk_widget_draw_internal (widget, cr, TRUE);
5824 gtk_cairo_set_event (cr, tmp_event);
5829 gtk_widget_real_key_press_event (GtkWidget *widget,
5832 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5836 gtk_widget_real_key_release_event (GtkWidget *widget,
5839 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5843 gtk_widget_real_focus_in_event (GtkWidget *widget,
5844 GdkEventFocus *event)
5846 gtk_widget_queue_draw (widget);
5852 gtk_widget_real_focus_out_event (GtkWidget *widget,
5853 GdkEventFocus *event)
5855 gtk_widget_queue_draw (widget);
5861 gtk_widget_real_touch_event (GtkWidget *widget,
5862 GdkEventTouch *event)
5865 gboolean return_val;
5868 if (!event->emulating_pointer)
5871 if (event->type == GDK_TOUCH_BEGIN ||
5872 event->type == GDK_TOUCH_END)
5876 if (event->type == GDK_TOUCH_BEGIN)
5878 type = GDK_BUTTON_PRESS;
5879 signum = BUTTON_PRESS_EVENT;
5883 type = GDK_BUTTON_RELEASE;
5884 signum = BUTTON_RELEASE_EVENT;
5886 bevent = gdk_event_new (type);
5887 bevent->any.window = g_object_ref (event->window);
5888 bevent->any.send_event = FALSE;
5889 bevent->button.time = event->time;
5890 bevent->button.state = event->state;
5891 bevent->button.button = 1;
5892 bevent->button.x_root = event->x_root;
5893 bevent->button.y_root = event->y_root;
5894 bevent->button.x = event->x;
5895 bevent->button.y = event->y;
5896 bevent->button.device = event->device;
5897 bevent->button.axes = g_memdup (event->axes,
5898 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5899 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5901 else if (event->type == GDK_TOUCH_UPDATE)
5903 signum = MOTION_NOTIFY_EVENT;
5904 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5905 bevent->any.window = g_object_ref (event->window);
5906 bevent->any.send_event = FALSE;
5907 bevent->motion.time = event->time;
5908 bevent->motion.state = event->state;
5909 bevent->motion.x_root = event->x_root;
5910 bevent->motion.y_root = event->y_root;
5911 bevent->motion.x = event->x;
5912 bevent->motion.y = event->y;
5913 bevent->motion.device = event->device;
5914 bevent->motion.is_hint = FALSE;
5915 bevent->motion.axes = g_memdup (event->axes,
5916 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5917 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5922 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5924 gdk_event_free (bevent);
5930 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5931 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5935 * @widget: a #GtkWidget
5936 * @event: a #GdkEvent
5938 * Rarely-used function. This function is used to emit
5939 * the event signals on a widget (those signals should never
5940 * be emitted without using this function to do so).
5941 * If you want to synthesize an event though, don't use this function;
5942 * instead, use gtk_main_do_event() so the event will behave as if
5943 * it were in the event queue. Don't synthesize expose events; instead,
5944 * use gdk_window_invalidate_rect() to invalidate a region of the
5947 * Return value: return from the event signal emission (%TRUE if
5948 * the event was handled)
5951 gtk_widget_event (GtkWidget *widget,
5954 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5955 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5957 if (event->type == GDK_EXPOSE)
5959 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5960 "the same effect, call gdk_window_invalidate_rect/region(), "
5961 "followed by gdk_window_process_updates().");
5965 return gtk_widget_event_internal (widget, event);
5969 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5970 GtkCapturedEventHandler callback)
5972 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5976 _gtk_widget_captured_event (GtkWidget *widget,
5979 gboolean return_val = FALSE;
5980 GtkCapturedEventHandler handler;
5982 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5983 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5985 if (event->type == GDK_EXPOSE)
5987 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5988 "the same effect, call gdk_window_invalidate_rect/region(), "
5989 "followed by gdk_window_process_updates().");
5993 if (!event_window_is_still_viewable (event))
5996 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6000 g_object_ref (widget);
6002 return_val = handler (widget, event);
6003 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6005 /* The widget that was originally to receive the event
6006 * handles motion hints, but the capturing widget might
6007 * not, so ensure we get further motion events.
6010 event->type == GDK_MOTION_NOTIFY &&
6011 event->motion.is_hint &&
6012 (gdk_window_get_events (event->any.window) &
6013 GDK_POINTER_MOTION_HINT_MASK) != 0)
6014 gdk_event_request_motions (&event->motion);
6016 g_object_unref (widget);
6021 /* Returns TRUE if a translation should be done */
6023 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6028 GdkWindow *w, *widget_window;
6030 if (!gtk_widget_get_has_window (widget))
6032 *x = -widget->priv->allocation.x;
6033 *y = -widget->priv->allocation.y;
6041 widget_window = gtk_widget_get_window (widget);
6043 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6046 gdk_window_get_position (w, &wx, &wy);
6063 * gtk_cairo_transform_to_window:
6064 * @cr: the cairo context to transform
6065 * @widget: the widget the context is currently centered for
6066 * @window: the window to transform the context to
6068 * Transforms the given cairo context @cr that from @widget-relative
6069 * coordinates to @window-relative coordinates.
6070 * If the @widget's window is not an ancestor of @window, no
6071 * modification will be applied.
6073 * This is the inverse to the transformation GTK applies when
6074 * preparing an expose event to be emitted with the #GtkWidget::draw
6075 * signal. It is intended to help porting multiwindow widgets from
6076 * GTK+ 2 to the rendering architecture of GTK+ 3.
6081 gtk_cairo_transform_to_window (cairo_t *cr,
6087 g_return_if_fail (cr != NULL);
6088 g_return_if_fail (GTK_IS_WIDGET (widget));
6089 g_return_if_fail (GDK_IS_WINDOW (window));
6091 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6092 cairo_translate (cr, x, y);
6096 * gtk_widget_send_expose:
6097 * @widget: a #GtkWidget
6098 * @event: a expose #GdkEvent
6100 * Very rarely-used function. This function is used to emit
6101 * an expose event on a widget. This function is not normally used
6102 * directly. The only time it is used is when propagating an expose
6103 * event to a child %NO_WINDOW widget, and that is normally done
6104 * using gtk_container_propagate_draw().
6106 * If you want to force an area of a window to be redrawn,
6107 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6108 * To cause the redraw to be done immediately, follow that call
6109 * with a call to gdk_window_process_updates().
6111 * Return value: return from the event signal emission (%TRUE if
6112 * the event was handled)
6115 gtk_widget_send_expose (GtkWidget *widget,
6118 gboolean result = FALSE;
6123 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6124 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6125 g_return_val_if_fail (event != NULL, TRUE);
6126 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6128 cr = gdk_cairo_create (event->expose.window);
6129 gtk_cairo_set_event (cr, &event->expose);
6131 gdk_cairo_region (cr, event->expose.region);
6134 do_clip = _gtk_widget_get_translation_to_window (widget,
6135 event->expose.window,
6137 cairo_translate (cr, -x, -y);
6139 _gtk_widget_draw_internal (widget, cr, do_clip);
6141 /* unset here, so if someone keeps a reference to cr we
6142 * don't leak the window. */
6143 gtk_cairo_set_event (cr, NULL);
6150 event_window_is_still_viewable (GdkEvent *event)
6152 /* Check that we think the event's window is viewable before
6153 * delivering the event, to prevent suprises. We do this here
6154 * at the last moment, since the event may have been queued
6155 * up behind other events, held over a recursive main loop, etc.
6157 switch (event->type)
6160 case GDK_MOTION_NOTIFY:
6161 case GDK_BUTTON_PRESS:
6162 case GDK_2BUTTON_PRESS:
6163 case GDK_3BUTTON_PRESS:
6165 case GDK_ENTER_NOTIFY:
6166 case GDK_PROXIMITY_IN:
6168 return event->any.window && gdk_window_is_viewable (event->any.window);
6171 /* The following events are the second half of paired events;
6172 * we always deliver them to deal with widgets that clean up
6173 * on the second half.
6175 case GDK_BUTTON_RELEASE:
6176 case GDK_KEY_RELEASE:
6177 case GDK_LEAVE_NOTIFY:
6178 case GDK_PROXIMITY_OUT:
6182 /* Remaining events would make sense on an not-viewable window,
6183 * or don't have an associated window.
6190 gtk_widget_event_internal (GtkWidget *widget,
6193 gboolean return_val = FALSE;
6195 /* We check only once for is-still-visible; if someone
6196 * hides the window in on of the signals on the widget,
6197 * they are responsible for returning TRUE to terminate
6200 if (!event_window_is_still_viewable (event))
6203 g_object_ref (widget);
6205 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6206 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6211 switch (event->type)
6217 case GDK_BUTTON_PRESS:
6218 case GDK_2BUTTON_PRESS:
6219 case GDK_3BUTTON_PRESS:
6220 signal_num = BUTTON_PRESS_EVENT;
6222 case GDK_TOUCH_BEGIN:
6223 case GDK_TOUCH_UPDATE:
6225 case GDK_TOUCH_CANCEL:
6226 signal_num = TOUCH_EVENT;
6229 signal_num = SCROLL_EVENT;
6231 case GDK_BUTTON_RELEASE:
6232 signal_num = BUTTON_RELEASE_EVENT;
6234 case GDK_MOTION_NOTIFY:
6235 signal_num = MOTION_NOTIFY_EVENT;
6238 signal_num = DELETE_EVENT;
6241 signal_num = DESTROY_EVENT;
6242 _gtk_tooltip_hide (widget);
6245 signal_num = KEY_PRESS_EVENT;
6247 case GDK_KEY_RELEASE:
6248 signal_num = KEY_RELEASE_EVENT;
6250 case GDK_ENTER_NOTIFY:
6251 signal_num = ENTER_NOTIFY_EVENT;
6253 case GDK_LEAVE_NOTIFY:
6254 signal_num = LEAVE_NOTIFY_EVENT;
6256 case GDK_FOCUS_CHANGE:
6257 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6258 if (event->focus_change.in)
6259 _gtk_tooltip_focus_in (widget);
6261 _gtk_tooltip_focus_out (widget);
6264 signal_num = CONFIGURE_EVENT;
6267 signal_num = MAP_EVENT;
6270 signal_num = UNMAP_EVENT;
6272 case GDK_WINDOW_STATE:
6273 signal_num = WINDOW_STATE_EVENT;
6275 case GDK_PROPERTY_NOTIFY:
6276 signal_num = PROPERTY_NOTIFY_EVENT;
6278 case GDK_SELECTION_CLEAR:
6279 signal_num = SELECTION_CLEAR_EVENT;
6281 case GDK_SELECTION_REQUEST:
6282 signal_num = SELECTION_REQUEST_EVENT;
6284 case GDK_SELECTION_NOTIFY:
6285 signal_num = SELECTION_NOTIFY_EVENT;
6287 case GDK_PROXIMITY_IN:
6288 signal_num = PROXIMITY_IN_EVENT;
6290 case GDK_PROXIMITY_OUT:
6291 signal_num = PROXIMITY_OUT_EVENT;
6293 case GDK_VISIBILITY_NOTIFY:
6294 signal_num = VISIBILITY_NOTIFY_EVENT;
6296 case GDK_GRAB_BROKEN:
6297 signal_num = GRAB_BROKEN_EVENT;
6300 signal_num = DAMAGE_EVENT;
6303 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6307 if (signal_num != -1)
6308 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6310 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6311 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6315 g_object_unref (widget);
6321 * gtk_widget_activate:
6322 * @widget: a #GtkWidget that's activatable
6324 * For widgets that can be "activated" (buttons, menu items, etc.)
6325 * this function activates them. Activation is what happens when you
6326 * press Enter on a widget during key navigation. If @widget isn't
6327 * activatable, the function returns %FALSE.
6329 * Return value: %TRUE if the widget was activatable
6332 gtk_widget_activate (GtkWidget *widget)
6334 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6336 if (WIDGET_CLASS (widget)->activate_signal)
6338 /* FIXME: we should eventually check the signals signature here */
6339 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6348 gtk_widget_reparent_subwindows (GtkWidget *widget,
6349 GdkWindow *new_window)
6351 GtkWidgetPrivate *priv = widget->priv;
6353 if (!gtk_widget_get_has_window (widget))
6355 GList *children = gdk_window_get_children (priv->window);
6358 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6360 GdkWindow *window = tmp_list->data;
6363 gdk_window_get_user_data (window, &child);
6364 while (child && child != widget)
6365 child = ((GtkWidget*) child)->priv->parent;
6368 gdk_window_reparent (window, new_window, 0, 0);
6371 g_list_free (children);
6376 GList *tmp_list, *children;
6378 parent = gdk_window_get_parent (priv->window);
6381 gdk_window_reparent (priv->window, new_window, 0, 0);
6384 children = gdk_window_get_children (parent);
6386 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6388 GdkWindow *window = tmp_list->data;
6391 gdk_window_get_user_data (window, &child);
6393 if (child == widget)
6394 gdk_window_reparent (window, new_window, 0, 0);
6397 g_list_free (children);
6403 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6404 gpointer client_data)
6406 GtkWidgetPrivate *priv = widget->priv;
6408 g_assert (client_data != NULL);
6410 if (!gtk_widget_get_has_window (widget))
6413 g_object_unref (priv->window);
6414 priv->window = (GdkWindow*) client_data;
6416 g_object_ref (priv->window);
6418 if (GTK_IS_CONTAINER (widget))
6419 gtk_container_forall (GTK_CONTAINER (widget),
6420 gtk_widget_reparent_fixup_child,
6426 * gtk_widget_reparent:
6427 * @widget: a #GtkWidget
6428 * @new_parent: a #GtkContainer to move the widget into
6430 * Moves a widget from one #GtkContainer to another, handling reference
6431 * count issues to avoid destroying the widget.
6434 gtk_widget_reparent (GtkWidget *widget,
6435 GtkWidget *new_parent)
6437 GtkWidgetPrivate *priv;
6439 g_return_if_fail (GTK_IS_WIDGET (widget));
6440 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6441 priv = widget->priv;
6442 g_return_if_fail (priv->parent != NULL);
6444 if (priv->parent != new_parent)
6446 /* First try to see if we can get away without unrealizing
6447 * the widget as we reparent it. if so we set a flag so
6448 * that gtk_widget_unparent doesn't unrealize widget
6450 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6451 priv->in_reparent = TRUE;
6453 g_object_ref (widget);
6454 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6455 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6456 g_object_unref (widget);
6458 if (priv->in_reparent)
6460 priv->in_reparent = FALSE;
6462 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6463 gtk_widget_reparent_fixup_child (widget,
6464 gtk_widget_get_parent_window (widget));
6467 g_object_notify (G_OBJECT (widget), "parent");
6472 * gtk_widget_intersect:
6473 * @widget: a #GtkWidget
6474 * @area: a rectangle
6475 * @intersection: rectangle to store intersection of @widget and @area
6477 * Computes the intersection of a @widget's area and @area, storing
6478 * the intersection in @intersection, and returns %TRUE if there was
6479 * an intersection. @intersection may be %NULL if you're only
6480 * interested in whether there was an intersection.
6482 * Return value: %TRUE if there was an intersection
6485 gtk_widget_intersect (GtkWidget *widget,
6486 const GdkRectangle *area,
6487 GdkRectangle *intersection)
6489 GtkWidgetPrivate *priv;
6494 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6495 g_return_val_if_fail (area != NULL, FALSE);
6497 priv = widget->priv;
6500 dest = intersection;
6504 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6506 if (return_val && intersection && gtk_widget_get_has_window (widget))
6508 intersection->x -= priv->allocation.x;
6509 intersection->y -= priv->allocation.y;
6516 * gtk_widget_region_intersect:
6517 * @widget: a #GtkWidget
6518 * @region: a #cairo_region_t, in the same coordinate system as
6519 * @widget->allocation. That is, relative to @widget->window
6520 * for %NO_WINDOW widgets; relative to the parent window
6521 * of @widget->window for widgets with their own window.
6523 * Computes the intersection of a @widget's area and @region, returning
6524 * the intersection. The result may be empty, use cairo_region_is_empty() to
6527 * Returns: A newly allocated region holding the intersection of @widget
6528 * and @region. The coordinates of the return value are relative to
6529 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6530 * window of @widget->window for widgets with their own window.
6533 gtk_widget_region_intersect (GtkWidget *widget,
6534 const cairo_region_t *region)
6537 cairo_region_t *dest;
6539 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6540 g_return_val_if_fail (region != NULL, NULL);
6542 gtk_widget_get_allocation (widget, &rect);
6544 dest = cairo_region_create_rectangle (&rect);
6546 cairo_region_intersect (dest, region);
6552 * _gtk_widget_grab_notify:
6553 * @widget: a #GtkWidget
6554 * @was_grabbed: whether a grab is now in effect
6556 * Emits the #GtkWidget::grab-notify signal on @widget.
6561 _gtk_widget_grab_notify (GtkWidget *widget,
6562 gboolean was_grabbed)
6564 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6568 * gtk_widget_grab_focus:
6569 * @widget: a #GtkWidget
6571 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6572 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6573 * something like #GtkFrame won't work.
6575 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6576 * gtk_widget_set_can_focus() to modify that flag.
6578 * The widget also needs to be realized and mapped. This is indicated by the
6579 * related signals. Grabbing the focus immediately after creating the widget
6580 * will likely fail and cause critical warnings.
6583 gtk_widget_grab_focus (GtkWidget *widget)
6585 g_return_if_fail (GTK_IS_WIDGET (widget));
6587 if (!gtk_widget_is_sensitive (widget))
6590 g_object_ref (widget);
6591 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6592 g_object_notify (G_OBJECT (widget), "has-focus");
6593 g_object_unref (widget);
6597 reset_focus_recurse (GtkWidget *widget,
6600 if (GTK_IS_CONTAINER (widget))
6602 GtkContainer *container;
6604 container = GTK_CONTAINER (widget);
6605 gtk_container_set_focus_child (container, NULL);
6607 gtk_container_foreach (container,
6608 reset_focus_recurse,
6614 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6616 if (gtk_widget_get_can_focus (focus_widget))
6618 GtkWidget *toplevel;
6621 /* clear the current focus setting, break if the current widget
6622 * is the focus widget's parent, since containers above that will
6623 * be set by the next loop.
6625 toplevel = gtk_widget_get_toplevel (focus_widget);
6626 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6628 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6630 if (widget == focus_widget)
6632 /* We call _gtk_window_internal_set_focus() here so that the
6633 * toplevel window can request the focus if necessary.
6634 * This is needed when the toplevel is a GtkPlug
6636 if (!gtk_widget_has_focus (widget))
6637 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6644 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6646 if (widget != common_ancestor)
6648 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6650 widget = widget->priv->parent;
6651 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6656 else if (toplevel != focus_widget)
6658 /* gtk_widget_grab_focus() operates on a tree without window...
6659 * actually, this is very questionable behaviour.
6662 gtk_container_foreach (GTK_CONTAINER (toplevel),
6663 reset_focus_recurse,
6667 /* now propagate the new focus up the widget tree and finally
6668 * set it on the window
6670 widget = focus_widget;
6671 while (widget->priv->parent)
6673 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6674 widget = widget->priv->parent;
6676 if (GTK_IS_WINDOW (widget))
6677 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6682 gtk_widget_real_query_tooltip (GtkWidget *widget,
6685 gboolean keyboard_tip,
6686 GtkTooltip *tooltip)
6688 gchar *tooltip_markup;
6689 gboolean has_tooltip;
6691 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6692 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6694 if (has_tooltip && tooltip_markup)
6696 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6704 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6705 GtkStateFlags old_state)
6707 gtk_widget_update_pango_context (widget);
6711 gtk_widget_real_style_updated (GtkWidget *widget)
6713 GtkWidgetPrivate *priv = widget->priv;
6715 gtk_widget_update_pango_context (widget);
6717 if (priv->style != NULL &&
6718 priv->style != gtk_widget_get_default_style ())
6720 /* Trigger ::style-set for old
6721 * widgets not listening to this
6723 g_signal_emit (widget,
6724 widget_signals[STYLE_SET],
6726 widget->priv->style);
6729 if (widget->priv->context)
6731 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6733 if (gtk_widget_get_realized (widget) &&
6734 gtk_widget_get_has_window (widget) &&
6735 !gtk_widget_get_app_paintable (widget))
6736 gtk_style_context_set_background (widget->priv->context,
6737 widget->priv->window);
6739 if (widget->priv->anchored)
6741 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6742 gtk_widget_queue_resize (widget);
6744 gtk_widget_queue_draw (widget);
6749 if (widget->priv->anchored)
6750 gtk_widget_queue_resize (widget);
6755 gtk_widget_real_show_help (GtkWidget *widget,
6756 GtkWidgetHelpType help_type)
6758 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6760 _gtk_tooltip_toggle_keyboard_mode (widget);
6769 gtk_widget_real_focus (GtkWidget *widget,
6770 GtkDirectionType direction)
6772 if (!gtk_widget_get_can_focus (widget))
6775 if (!gtk_widget_is_focus (widget))
6777 gtk_widget_grab_focus (widget);
6785 gtk_widget_real_move_focus (GtkWidget *widget,
6786 GtkDirectionType direction)
6788 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6790 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6792 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6798 gtk_widget_real_keynav_failed (GtkWidget *widget,
6799 GtkDirectionType direction)
6801 gboolean cursor_only;
6805 case GTK_DIR_TAB_FORWARD:
6806 case GTK_DIR_TAB_BACKWARD:
6813 g_object_get (gtk_widget_get_settings (widget),
6814 "gtk-keynav-cursor-only", &cursor_only,
6821 gtk_widget_error_bell (widget);
6827 * gtk_widget_set_can_focus:
6828 * @widget: a #GtkWidget
6829 * @can_focus: whether or not @widget can own the input focus.
6831 * Specifies whether @widget can own the input focus. See
6832 * gtk_widget_grab_focus() for actually setting the input focus on a
6838 gtk_widget_set_can_focus (GtkWidget *widget,
6841 g_return_if_fail (GTK_IS_WIDGET (widget));
6843 if (widget->priv->can_focus != can_focus)
6845 widget->priv->can_focus = can_focus;
6847 gtk_widget_queue_resize (widget);
6848 g_object_notify (G_OBJECT (widget), "can-focus");
6853 * gtk_widget_get_can_focus:
6854 * @widget: a #GtkWidget
6856 * Determines whether @widget can own the input focus. See
6857 * gtk_widget_set_can_focus().
6859 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6864 gtk_widget_get_can_focus (GtkWidget *widget)
6866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6868 return widget->priv->can_focus;
6872 * gtk_widget_has_focus:
6873 * @widget: a #GtkWidget
6875 * Determines if the widget has the global input focus. See
6876 * gtk_widget_is_focus() for the difference between having the global
6877 * input focus, and only having the focus within a toplevel.
6879 * Return value: %TRUE if the widget has the global input focus.
6884 gtk_widget_has_focus (GtkWidget *widget)
6886 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6888 return widget->priv->has_focus;
6892 * gtk_widget_has_visible_focus:
6893 * @widget: a #GtkWidget
6895 * Determines if the widget should show a visible indication that
6896 * it has the global input focus. This is a convenience function for
6897 * use in ::draw handlers that takes into account whether focus
6898 * indication should currently be shown in the toplevel window of
6899 * @widget. See gtk_window_get_focus_visible() for more information
6900 * about focus indication.
6902 * To find out if the widget has the global input focus, use
6903 * gtk_widget_has_focus().
6905 * Return value: %TRUE if the widget should display a 'focus rectangle'
6910 gtk_widget_has_visible_focus (GtkWidget *widget)
6912 gboolean draw_focus;
6914 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6916 if (widget->priv->has_focus)
6918 GtkWidget *toplevel;
6920 toplevel = gtk_widget_get_toplevel (widget);
6922 if (GTK_IS_WINDOW (toplevel))
6923 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6934 * gtk_widget_is_focus:
6935 * @widget: a #GtkWidget
6937 * Determines if the widget is the focus widget within its
6938 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6939 * necessarily set; %HAS_FOCUS will only be set if the
6940 * toplevel widget additionally has the global input focus.)
6942 * Return value: %TRUE if the widget is the focus widget.
6945 gtk_widget_is_focus (GtkWidget *widget)
6947 GtkWidget *toplevel;
6949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6951 toplevel = gtk_widget_get_toplevel (widget);
6953 if (GTK_IS_WINDOW (toplevel))
6954 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6960 * gtk_widget_set_can_default:
6961 * @widget: a #GtkWidget
6962 * @can_default: whether or not @widget can be a default widget.
6964 * Specifies whether @widget can be a default widget. See
6965 * gtk_widget_grab_default() for details about the meaning of
6971 gtk_widget_set_can_default (GtkWidget *widget,
6972 gboolean can_default)
6974 g_return_if_fail (GTK_IS_WIDGET (widget));
6976 if (widget->priv->can_default != can_default)
6978 widget->priv->can_default = can_default;
6980 gtk_widget_queue_resize (widget);
6981 g_object_notify (G_OBJECT (widget), "can-default");
6986 * gtk_widget_get_can_default:
6987 * @widget: a #GtkWidget
6989 * Determines whether @widget can be a default widget. See
6990 * gtk_widget_set_can_default().
6992 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6997 gtk_widget_get_can_default (GtkWidget *widget)
6999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7001 return widget->priv->can_default;
7005 * gtk_widget_has_default:
7006 * @widget: a #GtkWidget
7008 * Determines whether @widget is the current default widget within its
7009 * toplevel. See gtk_widget_set_can_default().
7011 * Return value: %TRUE if @widget is the current default widget within
7012 * its toplevel, %FALSE otherwise
7017 gtk_widget_has_default (GtkWidget *widget)
7019 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7021 return widget->priv->has_default;
7025 _gtk_widget_set_has_default (GtkWidget *widget,
7026 gboolean has_default)
7028 GtkStyleContext *context;
7030 widget->priv->has_default = has_default;
7032 context = gtk_widget_get_style_context (widget);
7035 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7037 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7041 * gtk_widget_grab_default:
7042 * @widget: a #GtkWidget
7044 * Causes @widget to become the default widget. @widget must be able to be
7045 * a default widget; typically you would ensure this yourself
7046 * by calling gtk_widget_set_can_default() with a %TRUE value.
7047 * The default widget is activated when
7048 * the user presses Enter in a window. Default widgets must be
7049 * activatable, that is, gtk_widget_activate() should affect them. Note
7050 * that #GtkEntry widgets require the "activates-default" property
7051 * set to %TRUE before they activate the default widget when Enter
7052 * is pressed and the #GtkEntry is focused.
7055 gtk_widget_grab_default (GtkWidget *widget)
7059 g_return_if_fail (GTK_IS_WIDGET (widget));
7060 g_return_if_fail (gtk_widget_get_can_default (widget));
7062 window = gtk_widget_get_toplevel (widget);
7064 if (window && gtk_widget_is_toplevel (window))
7065 gtk_window_set_default (GTK_WINDOW (window), widget);
7067 g_warning (G_STRLOC ": widget not within a GtkWindow");
7071 * gtk_widget_set_receives_default:
7072 * @widget: a #GtkWidget
7073 * @receives_default: whether or not @widget can be a default widget.
7075 * Specifies whether @widget will be treated as the default widget
7076 * within its toplevel when it has the focus, even if another widget
7079 * See gtk_widget_grab_default() for details about the meaning of
7085 gtk_widget_set_receives_default (GtkWidget *widget,
7086 gboolean receives_default)
7088 g_return_if_fail (GTK_IS_WIDGET (widget));
7090 if (widget->priv->receives_default != receives_default)
7092 widget->priv->receives_default = receives_default;
7094 g_object_notify (G_OBJECT (widget), "receives-default");
7099 * gtk_widget_get_receives_default:
7100 * @widget: a #GtkWidget
7102 * Determines whether @widget is alyways treated as default widget
7103 * withing its toplevel when it has the focus, even if another widget
7106 * See gtk_widget_set_receives_default().
7108 * Return value: %TRUE if @widget acts as default widget when focussed,
7114 gtk_widget_get_receives_default (GtkWidget *widget)
7116 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7118 return widget->priv->receives_default;
7122 * gtk_widget_has_grab:
7123 * @widget: a #GtkWidget
7125 * Determines whether the widget is currently grabbing events, so it
7126 * is the only widget receiving input events (keyboard and mouse).
7128 * See also gtk_grab_add().
7130 * Return value: %TRUE if the widget is in the grab_widgets stack
7135 gtk_widget_has_grab (GtkWidget *widget)
7137 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7139 return widget->priv->has_grab;
7143 _gtk_widget_set_has_grab (GtkWidget *widget,
7146 widget->priv->has_grab = has_grab;
7150 * gtk_widget_device_is_shadowed:
7151 * @widget: a #GtkWidget
7152 * @device: a #GdkDevice
7154 * Returns %TRUE if @device has been shadowed by a GTK+
7155 * device grab on another widget, so it would stop sending
7156 * events to @widget. This may be used in the
7157 * #GtkWidget::grab-notify signal to check for specific
7158 * devices. See gtk_device_grab_add().
7160 * Returns: %TRUE if there is an ongoing grab on @device
7161 * by another #GtkWidget than @widget.
7166 gtk_widget_device_is_shadowed (GtkWidget *widget,
7169 GtkWindowGroup *group;
7170 GtkWidget *grab_widget, *toplevel;
7172 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7173 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7175 if (!gtk_widget_get_realized (widget))
7178 toplevel = gtk_widget_get_toplevel (widget);
7180 if (GTK_IS_WINDOW (toplevel))
7181 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7183 group = gtk_window_get_group (NULL);
7185 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7187 /* Widget not inside the hierarchy of grab_widget */
7189 widget != grab_widget &&
7190 !gtk_widget_is_ancestor (widget, grab_widget))
7193 grab_widget = gtk_window_group_get_current_grab (group);
7194 if (grab_widget && widget != grab_widget &&
7195 !gtk_widget_is_ancestor (widget, grab_widget))
7202 * gtk_widget_set_name:
7203 * @widget: a #GtkWidget
7204 * @name: name for the widget
7206 * Widgets can be named, which allows you to refer to them from a
7207 * CSS file. You can apply a style to widgets with a particular name
7208 * in the CSS file. See the documentation for the CSS syntax (on the
7209 * same page as the docs for #GtkStyleContext).
7211 * Note that the CSS syntax has certain special characters to delimit
7212 * and represent elements in a selector (period, #, >, *...),
7213 * so using these will make your widget impossible to match by name.
7214 * Any combination of alphanumeric symbols, dashes and underscores will
7218 gtk_widget_set_name (GtkWidget *widget,
7221 GtkWidgetPrivate *priv;
7224 g_return_if_fail (GTK_IS_WIDGET (widget));
7226 priv = widget->priv;
7228 new_name = g_strdup (name);
7229 g_free (priv->name);
7230 priv->name = new_name;
7232 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7234 g_object_notify (G_OBJECT (widget), "name");
7238 * gtk_widget_get_name:
7239 * @widget: a #GtkWidget
7241 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7242 * significance of widget names.
7244 * Return value: name of the widget. This string is owned by GTK+ and
7245 * should not be modified or freed
7248 gtk_widget_get_name (GtkWidget *widget)
7250 GtkWidgetPrivate *priv;
7252 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7254 priv = widget->priv;
7258 return G_OBJECT_TYPE_NAME (widget);
7262 gtk_widget_update_state_flags (GtkWidget *widget,
7263 GtkStateFlags flags_to_set,
7264 GtkStateFlags flags_to_unset)
7266 GtkWidgetPrivate *priv;
7268 priv = widget->priv;
7270 /* Handle insensitive first, since it is propagated
7271 * differently throughout the widget hierarchy.
7273 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7274 gtk_widget_set_sensitive (widget, TRUE);
7275 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7276 gtk_widget_set_sensitive (widget, FALSE);
7278 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7279 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7281 if (flags_to_set != 0 || flags_to_unset != 0)
7285 data.flags_to_set = flags_to_set;
7286 data.flags_to_unset = flags_to_unset;
7288 gtk_widget_propagate_state (widget, &data);
7293 * gtk_widget_set_state_flags:
7294 * @widget: a #GtkWidget
7295 * @flags: State flags to turn on
7296 * @clear: Whether to clear state before turning on @flags
7298 * This function is for use in widget implementations. Turns on flag
7299 * values in the current widget state (insensitive, prelighted, etc.).
7301 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7302 * will be propagated down to all non-internal children if @widget is a
7303 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7304 * down to all #GtkContainer children by different means than turning on the
7305 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7306 * gtk_widget_is_sensitive() will make use of these.
7311 gtk_widget_set_state_flags (GtkWidget *widget,
7312 GtkStateFlags flags,
7315 g_return_if_fail (GTK_IS_WIDGET (widget));
7317 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7318 (clear && widget->priv->state_flags == flags))
7322 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7324 gtk_widget_update_state_flags (widget, flags, 0);
7328 * gtk_widget_unset_state_flags:
7329 * @widget: a #GtkWidget
7330 * @flags: State flags to turn off
7332 * This function is for use in widget implementations. Turns off flag
7333 * values for the current widget state (insensitive, prelighted, etc.).
7334 * See gtk_widget_set_state_flags().
7339 gtk_widget_unset_state_flags (GtkWidget *widget,
7340 GtkStateFlags flags)
7342 g_return_if_fail (GTK_IS_WIDGET (widget));
7344 if ((widget->priv->state_flags & flags) == 0)
7347 gtk_widget_update_state_flags (widget, 0, flags);
7351 * gtk_widget_get_state_flags:
7352 * @widget: a #GtkWidget
7354 * Returns the widget state as a flag set. It is worth mentioning
7355 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7356 * returned, that is, also based on parent insensitivity, even if
7357 * @widget itself is sensitive.
7359 * Returns: The state flags for widget
7364 gtk_widget_get_state_flags (GtkWidget *widget)
7366 GtkStateFlags flags;
7368 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7370 flags = widget->priv->state_flags;
7372 if (gtk_widget_has_focus (widget))
7373 flags |= GTK_STATE_FLAG_FOCUSED;
7379 * gtk_widget_set_state:
7380 * @widget: a #GtkWidget
7381 * @state: new state for @widget
7383 * This function is for use in widget implementations. Sets the state
7384 * of a widget (insensitive, prelighted, etc.) Usually you should set
7385 * the state using wrapper functions such as gtk_widget_set_sensitive().
7387 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7390 gtk_widget_set_state (GtkWidget *widget,
7393 GtkStateFlags flags;
7395 if (state == gtk_widget_get_state (widget))
7400 case GTK_STATE_ACTIVE:
7401 flags = GTK_STATE_FLAG_ACTIVE;
7403 case GTK_STATE_PRELIGHT:
7404 flags = GTK_STATE_FLAG_PRELIGHT;
7406 case GTK_STATE_SELECTED:
7407 flags = GTK_STATE_FLAG_SELECTED;
7409 case GTK_STATE_INSENSITIVE:
7410 flags = GTK_STATE_FLAG_INSENSITIVE;
7412 case GTK_STATE_INCONSISTENT:
7413 flags = GTK_STATE_FLAG_INCONSISTENT;
7415 case GTK_STATE_FOCUSED:
7416 flags = GTK_STATE_FLAG_FOCUSED;
7418 case GTK_STATE_NORMAL:
7424 gtk_widget_update_state_flags (widget,
7426 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7427 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7431 * gtk_widget_get_state:
7432 * @widget: a #GtkWidget
7434 * Returns the widget's state. See gtk_widget_set_state().
7436 * Returns: the state of @widget.
7440 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7443 gtk_widget_get_state (GtkWidget *widget)
7445 GtkStateFlags flags;
7447 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7449 flags = gtk_widget_get_state_flags (widget);
7451 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7452 return GTK_STATE_INSENSITIVE;
7453 else if (flags & GTK_STATE_FLAG_ACTIVE)
7454 return GTK_STATE_ACTIVE;
7455 else if (flags & GTK_STATE_FLAG_SELECTED)
7456 return GTK_STATE_SELECTED;
7457 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7458 return GTK_STATE_PRELIGHT;
7460 return GTK_STATE_NORMAL;
7464 * gtk_widget_set_visible:
7465 * @widget: a #GtkWidget
7466 * @visible: whether the widget should be shown or not
7468 * Sets the visibility state of @widget. Note that setting this to
7469 * %TRUE doesn't mean the widget is actually viewable, see
7470 * gtk_widget_get_visible().
7472 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7473 * but is nicer to use when the visibility of the widget depends on
7479 gtk_widget_set_visible (GtkWidget *widget,
7482 g_return_if_fail (GTK_IS_WIDGET (widget));
7484 if (visible != gtk_widget_get_visible (widget))
7487 gtk_widget_show (widget);
7489 gtk_widget_hide (widget);
7494 _gtk_widget_set_visible_flag (GtkWidget *widget,
7497 widget->priv->visible = visible;
7501 * gtk_widget_get_visible:
7502 * @widget: a #GtkWidget
7504 * Determines whether the widget is visible. If you want to
7505 * take into account whether the widget's parent is also marked as
7506 * visible, use gtk_widget_is_visible() instead.
7508 * This function does not check if the widget is obscured in any way.
7510 * See gtk_widget_set_visible().
7512 * Return value: %TRUE if the widget is visible
7517 gtk_widget_get_visible (GtkWidget *widget)
7519 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7521 return widget->priv->visible;
7525 * gtk_widget_is_visible:
7526 * @widget: a #GtkWidget
7528 * Determines whether the widget and all its parents are marked as
7531 * This function does not check if the widget is obscured in any way.
7533 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7535 * Return value: %TRUE if the widget and all its parents are visible
7540 gtk_widget_is_visible (GtkWidget *widget)
7542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7546 GtkWidgetPrivate *priv = widget->priv;
7551 widget = priv->parent;
7558 * gtk_widget_set_has_window:
7559 * @widget: a #GtkWidget
7560 * @has_window: whether or not @widget has a window.
7562 * Specifies whether @widget has a #GdkWindow of its own. Note that
7563 * all realized widgets have a non-%NULL "window" pointer
7564 * (gtk_widget_get_window() never returns a %NULL window when a widget
7565 * is realized), but for many of them it's actually the #GdkWindow of
7566 * one of its parent widgets. Widgets that do not create a %window for
7567 * themselves in #GtkWidget::realize must announce this by
7568 * calling this function with @has_window = %FALSE.
7570 * This function should only be called by widget implementations,
7571 * and they should call it in their init() function.
7576 gtk_widget_set_has_window (GtkWidget *widget,
7577 gboolean has_window)
7579 g_return_if_fail (GTK_IS_WIDGET (widget));
7581 widget->priv->no_window = !has_window;
7585 * gtk_widget_get_has_window:
7586 * @widget: a #GtkWidget
7588 * Determines whether @widget has a #GdkWindow of its own. See
7589 * gtk_widget_set_has_window().
7591 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7596 gtk_widget_get_has_window (GtkWidget *widget)
7598 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7600 return ! widget->priv->no_window;
7604 * gtk_widget_is_toplevel:
7605 * @widget: a #GtkWidget
7607 * Determines whether @widget is a toplevel widget.
7609 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7610 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7613 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7618 gtk_widget_is_toplevel (GtkWidget *widget)
7620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7622 return widget->priv->toplevel;
7626 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7627 gboolean is_toplevel)
7629 widget->priv->toplevel = is_toplevel;
7633 * gtk_widget_is_drawable:
7634 * @widget: a #GtkWidget
7636 * Determines whether @widget can be drawn to. A widget can be drawn
7637 * to if it is mapped and visible.
7639 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7644 gtk_widget_is_drawable (GtkWidget *widget)
7646 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7648 return (gtk_widget_get_visible (widget) &&
7649 gtk_widget_get_mapped (widget));
7653 * gtk_widget_get_realized:
7654 * @widget: a #GtkWidget
7656 * Determines whether @widget is realized.
7658 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7663 gtk_widget_get_realized (GtkWidget *widget)
7665 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7667 return widget->priv->realized;
7671 * gtk_widget_set_realized:
7672 * @widget: a #GtkWidget
7673 * @realized: %TRUE to mark the widget as realized
7675 * Marks the widget as being realized.
7677 * This function should only ever be called in a derived widget's
7678 * "realize" or "unrealize" implementation.
7683 gtk_widget_set_realized (GtkWidget *widget,
7686 g_return_if_fail (GTK_IS_WIDGET (widget));
7688 widget->priv->realized = realized;
7692 * gtk_widget_get_mapped:
7693 * @widget: a #GtkWidget
7695 * Whether the widget is mapped.
7697 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7702 gtk_widget_get_mapped (GtkWidget *widget)
7704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7706 return widget->priv->mapped;
7710 * gtk_widget_set_mapped:
7711 * @widget: a #GtkWidget
7712 * @mapped: %TRUE to mark the widget as mapped
7714 * Marks the widget as being realized.
7716 * This function should only ever be called in a derived widget's
7717 * "map" or "unmap" implementation.
7722 gtk_widget_set_mapped (GtkWidget *widget,
7725 g_return_if_fail (GTK_IS_WIDGET (widget));
7727 widget->priv->mapped = mapped;
7731 * gtk_widget_set_app_paintable:
7732 * @widget: a #GtkWidget
7733 * @app_paintable: %TRUE if the application will paint on the widget
7735 * Sets whether the application intends to draw on the widget in
7736 * an #GtkWidget::draw handler.
7738 * This is a hint to the widget and does not affect the behavior of
7739 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7740 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7741 * the effect is to suppress default themed drawing of the widget's
7742 * background. (Children of the widget will still be drawn.) The application
7743 * is then entirely responsible for drawing the widget background.
7745 * Note that the background is still drawn when the widget is mapped.
7748 gtk_widget_set_app_paintable (GtkWidget *widget,
7749 gboolean app_paintable)
7751 g_return_if_fail (GTK_IS_WIDGET (widget));
7753 app_paintable = (app_paintable != FALSE);
7755 if (widget->priv->app_paintable != app_paintable)
7757 widget->priv->app_paintable = app_paintable;
7759 if (gtk_widget_is_drawable (widget))
7760 gtk_widget_queue_draw (widget);
7762 g_object_notify (G_OBJECT (widget), "app-paintable");
7767 * gtk_widget_get_app_paintable:
7768 * @widget: a #GtkWidget
7770 * Determines whether the application intends to draw on the widget in
7771 * an #GtkWidget::draw handler.
7773 * See gtk_widget_set_app_paintable()
7775 * Return value: %TRUE if the widget is app paintable
7780 gtk_widget_get_app_paintable (GtkWidget *widget)
7782 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7784 return widget->priv->app_paintable;
7788 * gtk_widget_set_double_buffered:
7789 * @widget: a #GtkWidget
7790 * @double_buffered: %TRUE to double-buffer a widget
7792 * Widgets are double buffered by default; you can use this function
7793 * to turn off the buffering. "Double buffered" simply means that
7794 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7795 * automatically around expose events sent to the
7796 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7797 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7798 * buffer to the screen. The result is that users see the window
7799 * update in one smooth step, and don't see individual graphics
7800 * primitives being rendered.
7802 * In very simple terms, double buffered widgets don't flicker,
7803 * so you would only use this function to turn off double buffering
7804 * if you had special needs and really knew what you were doing.
7806 * Note: if you turn off double-buffering, you have to handle
7807 * expose events, since even the clearing to the background color or
7808 * pixmap will not happen automatically (as it is done in
7809 * gdk_window_begin_paint_region()).
7812 gtk_widget_set_double_buffered (GtkWidget *widget,
7813 gboolean double_buffered)
7815 g_return_if_fail (GTK_IS_WIDGET (widget));
7817 double_buffered = (double_buffered != FALSE);
7819 if (widget->priv->double_buffered != double_buffered)
7821 widget->priv->double_buffered = double_buffered;
7823 g_object_notify (G_OBJECT (widget), "double-buffered");
7828 * gtk_widget_get_double_buffered:
7829 * @widget: a #GtkWidget
7831 * Determines whether the widget is double buffered.
7833 * See gtk_widget_set_double_buffered()
7835 * Return value: %TRUE if the widget is double buffered
7840 gtk_widget_get_double_buffered (GtkWidget *widget)
7842 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7844 return widget->priv->double_buffered;
7848 * gtk_widget_set_redraw_on_allocate:
7849 * @widget: a #GtkWidget
7850 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7851 * when it is allocated to a new size. Otherwise, only the
7852 * new portion of the widget will be redrawn.
7854 * Sets whether the entire widget is queued for drawing when its size
7855 * allocation changes. By default, this setting is %TRUE and
7856 * the entire widget is redrawn on every size change. If your widget
7857 * leaves the upper left unchanged when made bigger, turning this
7858 * setting off will improve performance.
7860 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7861 * off all allocation on resizing: the widget will not even redraw if
7862 * its position changes; this is to allow containers that don't draw
7863 * anything to avoid excess invalidations. If you set this flag on a
7864 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7865 * you are responsible for invalidating both the old and new allocation
7866 * of the widget when the widget is moved and responsible for invalidating
7867 * regions newly when the widget increases size.
7870 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7871 gboolean redraw_on_allocate)
7873 g_return_if_fail (GTK_IS_WIDGET (widget));
7875 widget->priv->redraw_on_alloc = redraw_on_allocate;
7879 * gtk_widget_set_sensitive:
7880 * @widget: a #GtkWidget
7881 * @sensitive: %TRUE to make the widget sensitive
7883 * Sets the sensitivity of a widget. A widget is sensitive if the user
7884 * can interact with it. Insensitive widgets are "grayed out" and the
7885 * user can't interact with them. Insensitive widgets are known as
7886 * "inactive", "disabled", or "ghosted" in some other toolkits.
7889 gtk_widget_set_sensitive (GtkWidget *widget,
7892 GtkWidgetPrivate *priv;
7894 g_return_if_fail (GTK_IS_WIDGET (widget));
7896 priv = widget->priv;
7898 sensitive = (sensitive != FALSE);
7900 if (priv->sensitive == sensitive)
7903 priv->sensitive = sensitive;
7905 if (priv->parent == NULL
7906 || gtk_widget_is_sensitive (priv->parent))
7912 data.flags_to_set = 0;
7913 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
7917 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
7918 data.flags_to_unset = 0;
7921 gtk_widget_propagate_state (widget, &data);
7923 gtk_widget_queue_resize (widget);
7926 g_object_notify (G_OBJECT (widget), "sensitive");
7930 * gtk_widget_get_sensitive:
7931 * @widget: a #GtkWidget
7933 * Returns the widget's sensitivity (in the sense of returning
7934 * the value that has been set using gtk_widget_set_sensitive()).
7936 * The effective sensitivity of a widget is however determined by both its
7937 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7939 * Returns: %TRUE if the widget is sensitive
7944 gtk_widget_get_sensitive (GtkWidget *widget)
7946 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7948 return widget->priv->sensitive;
7952 * gtk_widget_is_sensitive:
7953 * @widget: a #GtkWidget
7955 * Returns the widget's effective sensitivity, which means
7956 * it is sensitive itself and also its parent widget is sensitive
7958 * Returns: %TRUE if the widget is effectively sensitive
7963 gtk_widget_is_sensitive (GtkWidget *widget)
7965 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7967 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7971 * gtk_widget_set_parent:
7972 * @widget: a #GtkWidget
7973 * @parent: parent container
7975 * This function is useful only when implementing subclasses of
7977 * Sets the container as the parent of @widget, and takes care of
7978 * some details such as updating the state and style of the child
7979 * to reflect its new location. The opposite function is
7980 * gtk_widget_unparent().
7983 gtk_widget_set_parent (GtkWidget *widget,
7986 GtkStateFlags parent_flags;
7987 GtkWidgetPrivate *priv;
7990 g_return_if_fail (GTK_IS_WIDGET (widget));
7991 g_return_if_fail (GTK_IS_WIDGET (parent));
7992 g_return_if_fail (widget != parent);
7994 priv = widget->priv;
7996 if (priv->parent != NULL)
7998 g_warning ("Can't set a parent on widget which has a parent\n");
8001 if (gtk_widget_is_toplevel (widget))
8003 g_warning ("Can't set a parent on a toplevel widget\n");
8007 /* keep this function in sync with gtk_menu_attach_to_widget()
8010 g_object_ref_sink (widget);
8012 gtk_widget_push_verify_invariants (widget);
8014 priv->parent = parent;
8016 parent_flags = gtk_widget_get_state_flags (parent);
8018 /* Merge both old state and current parent state,
8019 * making sure to only propagate the right states */
8020 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8021 data.flags_to_unset = 0;
8022 gtk_widget_propagate_state (widget, &data);
8025 gtk_style_context_set_parent (priv->context,
8026 gtk_widget_get_style_context (parent));
8028 _gtk_widget_update_parent_muxer (widget);
8030 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8031 if (priv->parent->priv->anchored)
8032 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8033 g_object_notify (G_OBJECT (widget), "parent");
8035 /* Enforce realized/mapped invariants
8037 if (gtk_widget_get_realized (priv->parent))
8038 gtk_widget_realize (widget);
8040 if (gtk_widget_get_visible (priv->parent) &&
8041 gtk_widget_get_visible (widget))
8043 if (gtk_widget_get_child_visible (widget) &&
8044 gtk_widget_get_mapped (priv->parent))
8045 gtk_widget_map (widget);
8047 gtk_widget_queue_resize (widget);
8050 /* child may cause parent's expand to change, if the child is
8051 * expanded. If child is not expanded, then it can't modify the
8052 * parent's expand. If the child becomes expanded later then it will
8053 * queue compute_expand then. This optimization plus defaulting
8054 * newly-constructed widgets to need_compute_expand=FALSE should
8055 * mean that initially building a widget tree doesn't have to keep
8056 * walking up setting need_compute_expand on parents over and over.
8058 * We can't change a parent to need to expand unless we're visible.
8060 if (gtk_widget_get_visible (widget) &&
8061 (priv->need_compute_expand ||
8062 priv->computed_hexpand ||
8063 priv->computed_vexpand))
8065 gtk_widget_queue_compute_expand (parent);
8068 gtk_widget_pop_verify_invariants (widget);
8072 * gtk_widget_get_parent:
8073 * @widget: a #GtkWidget
8075 * Returns the parent container of @widget.
8077 * Return value: (transfer none): the parent container of @widget, or %NULL
8080 gtk_widget_get_parent (GtkWidget *widget)
8082 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8084 return widget->priv->parent;
8088 modifier_style_changed (GtkModifierStyle *style,
8091 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8094 static GtkModifierStyle *
8095 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8097 GtkModifierStyle *style;
8099 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8101 if (G_UNLIKELY (!style))
8103 GtkStyleContext *context;
8105 style = _gtk_modifier_style_new ();
8106 g_object_set_qdata_full (G_OBJECT (widget),
8107 quark_modifier_style,
8109 (GDestroyNotify) g_object_unref);
8111 g_signal_connect (style, "changed",
8112 G_CALLBACK (modifier_style_changed), widget);
8114 context = gtk_widget_get_style_context (widget);
8116 gtk_style_context_add_provider (context,
8117 GTK_STYLE_PROVIDER (style),
8118 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8125 * gtk_widget_override_color:
8126 * @widget: a #GtkWidget
8127 * @state: the state for which to set the color
8128 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8129 * of previous calls to gtk_widget_override_color()
8131 * Sets the color to use for a widget.
8133 * All other style values are left untouched.
8136 * This API is mostly meant as a quick way for applications to
8137 * change a widget appearance. If you are developing a widgets
8138 * library and intend this change to be themeable, it is better
8139 * done by setting meaningful CSS classes and regions in your
8140 * widget/container implementation through gtk_style_context_add_class()
8141 * and gtk_style_context_add_region().
8143 * This way, your widget library can install a #GtkCssProvider
8144 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8145 * to provide a default styling for those widgets that need so, and
8146 * this theming may fully overridden by the user's theme.
8149 * Note that for complex widgets this may bring in undesired
8150 * results (such as uniform background color everywhere), in
8151 * these cases it is better to fully style such widgets through a
8152 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8159 gtk_widget_override_color (GtkWidget *widget,
8160 GtkStateFlags state,
8161 const GdkRGBA *color)
8163 GtkModifierStyle *style;
8165 g_return_if_fail (GTK_IS_WIDGET (widget));
8167 style = _gtk_widget_get_modifier_properties (widget);
8168 _gtk_modifier_style_set_color (style, state, color);
8172 * gtk_widget_override_background_color:
8173 * @widget: a #GtkWidget
8174 * @state: the state for which to set the background color
8175 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8176 * of previous calls to gtk_widget_override_background_color()
8178 * Sets the background color to use for a widget.
8180 * All other style values are left untouched.
8181 * See gtk_widget_override_color().
8186 gtk_widget_override_background_color (GtkWidget *widget,
8187 GtkStateFlags state,
8188 const GdkRGBA *color)
8190 GtkModifierStyle *style;
8192 g_return_if_fail (GTK_IS_WIDGET (widget));
8194 style = _gtk_widget_get_modifier_properties (widget);
8195 _gtk_modifier_style_set_background_color (style, state, color);
8199 * gtk_widget_override_font:
8200 * @widget: a #GtkWidget
8201 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8202 * the effect of previous calls to gtk_widget_override_font()
8204 * Sets the font to use for a widget. All other style values are
8205 * left untouched. See gtk_widget_override_color().
8210 gtk_widget_override_font (GtkWidget *widget,
8211 const PangoFontDescription *font_desc)
8213 GtkModifierStyle *style;
8215 g_return_if_fail (GTK_IS_WIDGET (widget));
8217 style = _gtk_widget_get_modifier_properties (widget);
8218 _gtk_modifier_style_set_font (style, font_desc);
8222 * gtk_widget_override_symbolic_color:
8223 * @widget: a #GtkWidget
8224 * @name: the name of the symbolic color to modify
8225 * @color: (allow-none): the color to assign (does not need
8226 * to be allocated), or %NULL to undo the effect of previous
8227 * calls to gtk_widget_override_symbolic_color()
8229 * Sets a symbolic color for a widget.
8231 * All other style values are left untouched.
8232 * See gtk_widget_override_color() for overriding the foreground
8233 * or background color.
8238 gtk_widget_override_symbolic_color (GtkWidget *widget,
8240 const GdkRGBA *color)
8242 GtkModifierStyle *style;
8244 g_return_if_fail (GTK_IS_WIDGET (widget));
8246 style = _gtk_widget_get_modifier_properties (widget);
8247 _gtk_modifier_style_map_color (style, name, color);
8251 * gtk_widget_override_cursor:
8252 * @widget: a #GtkWidget
8253 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8254 * allocated), or %NULL to undo the effect of previous calls to
8255 * of gtk_widget_override_cursor().
8256 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8257 * need to be allocated), or %NULL to undo the effect of previous
8258 * calls to of gtk_widget_override_cursor().
8260 * Sets the cursor color to use in a widget, overriding the
8261 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8262 * style properties. All other style values are left untouched.
8263 * See also gtk_widget_modify_style().
8265 * Note that the underlying properties have the #GdkColor type,
8266 * so the alpha value in @primary and @secondary will be ignored.
8271 gtk_widget_override_cursor (GtkWidget *widget,
8272 const GdkRGBA *cursor,
8273 const GdkRGBA *secondary_cursor)
8275 GtkModifierStyle *style;
8277 g_return_if_fail (GTK_IS_WIDGET (widget));
8279 style = _gtk_widget_get_modifier_properties (widget);
8280 _gtk_modifier_style_set_color_property (style,
8282 "cursor-color", cursor);
8283 _gtk_modifier_style_set_color_property (style,
8285 "secondary-cursor-color",
8290 gtk_widget_real_direction_changed (GtkWidget *widget,
8291 GtkTextDirection previous_direction)
8293 gtk_widget_queue_resize (widget);
8297 gtk_widget_real_style_set (GtkWidget *widget,
8298 GtkStyle *previous_style)
8303 GtkWidget *previous_toplevel;
8304 GdkScreen *previous_screen;
8305 GdkScreen *new_screen;
8306 } HierarchyChangedInfo;
8309 do_screen_change (GtkWidget *widget,
8310 GdkScreen *old_screen,
8311 GdkScreen *new_screen)
8313 if (old_screen != new_screen)
8315 GtkWidgetPrivate *priv = widget->priv;
8319 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8321 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8324 _gtk_tooltip_hide (widget);
8326 if (new_screen && priv->context)
8327 gtk_style_context_set_screen (priv->context, new_screen);
8329 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8334 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8335 gpointer client_data)
8337 GtkWidgetPrivate *priv = widget->priv;
8338 HierarchyChangedInfo *info = client_data;
8339 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8340 (priv->parent && priv->parent->priv->anchored);
8342 if (priv->anchored != new_anchored)
8344 g_object_ref (widget);
8346 priv->anchored = new_anchored;
8348 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8349 do_screen_change (widget, info->previous_screen, info->new_screen);
8351 if (GTK_IS_CONTAINER (widget))
8352 gtk_container_forall (GTK_CONTAINER (widget),
8353 gtk_widget_propagate_hierarchy_changed_recurse,
8356 g_object_unref (widget);
8361 * _gtk_widget_propagate_hierarchy_changed:
8362 * @widget: a #GtkWidget
8363 * @previous_toplevel: Previous toplevel
8365 * Propagates changes in the anchored state to a widget and all
8366 * children, unsetting or setting the %ANCHORED flag, and
8367 * emitting #GtkWidget::hierarchy-changed.
8370 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8371 GtkWidget *previous_toplevel)
8373 GtkWidgetPrivate *priv = widget->priv;
8374 HierarchyChangedInfo info;
8376 info.previous_toplevel = previous_toplevel;
8377 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8379 if (gtk_widget_is_toplevel (widget) ||
8380 (priv->parent && priv->parent->priv->anchored))
8381 info.new_screen = gtk_widget_get_screen (widget);
8383 info.new_screen = NULL;
8385 if (info.previous_screen)
8386 g_object_ref (info.previous_screen);
8387 if (previous_toplevel)
8388 g_object_ref (previous_toplevel);
8390 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8392 if (previous_toplevel)
8393 g_object_unref (previous_toplevel);
8394 if (info.previous_screen)
8395 g_object_unref (info.previous_screen);
8399 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8400 gpointer client_data)
8402 HierarchyChangedInfo *info = client_data;
8404 g_object_ref (widget);
8406 do_screen_change (widget, info->previous_screen, info->new_screen);
8408 if (GTK_IS_CONTAINER (widget))
8409 gtk_container_forall (GTK_CONTAINER (widget),
8410 gtk_widget_propagate_screen_changed_recurse,
8413 g_object_unref (widget);
8417 * gtk_widget_is_composited:
8418 * @widget: a #GtkWidget
8420 * Whether @widget can rely on having its alpha channel
8421 * drawn correctly. On X11 this function returns whether a
8422 * compositing manager is running for @widget's screen.
8424 * Please note that the semantics of this call will change
8425 * in the future if used on a widget that has a composited
8426 * window in its hierarchy (as set by gdk_window_set_composited()).
8428 * Return value: %TRUE if the widget can rely on its alpha
8429 * channel being drawn correctly.
8434 gtk_widget_is_composited (GtkWidget *widget)
8438 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8440 screen = gtk_widget_get_screen (widget);
8442 return gdk_screen_is_composited (screen);
8446 propagate_composited_changed (GtkWidget *widget,
8449 if (GTK_IS_CONTAINER (widget))
8451 gtk_container_forall (GTK_CONTAINER (widget),
8452 propagate_composited_changed,
8456 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8460 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8462 propagate_composited_changed (widget, NULL);
8466 * _gtk_widget_propagate_screen_changed:
8467 * @widget: a #GtkWidget
8468 * @previous_screen: Previous screen
8470 * Propagates changes in the screen for a widget to all
8471 * children, emitting #GtkWidget::screen-changed.
8474 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8475 GdkScreen *previous_screen)
8477 HierarchyChangedInfo info;
8479 info.previous_screen = previous_screen;
8480 info.new_screen = gtk_widget_get_screen (widget);
8482 if (previous_screen)
8483 g_object_ref (previous_screen);
8485 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8487 if (previous_screen)
8488 g_object_unref (previous_screen);
8492 reset_style_recurse (GtkWidget *widget, gpointer data)
8494 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8496 if (GTK_IS_CONTAINER (widget))
8497 gtk_container_forall (GTK_CONTAINER (widget),
8498 reset_style_recurse,
8503 * gtk_widget_reset_style:
8504 * @widget: a #GtkWidget
8506 * Updates the style context of @widget and all descendents
8507 * by updating its widget path. #GtkContainer<!-- -->s may want
8508 * to use this on a child when reordering it in a way that a different
8509 * style might apply to it. See also gtk_container_get_path_for_child().
8514 gtk_widget_reset_style (GtkWidget *widget)
8516 g_return_if_fail (GTK_IS_WIDGET (widget));
8518 reset_style_recurse (widget, NULL);
8520 g_list_foreach (widget->priv->attached_windows,
8521 (GFunc) reset_style_recurse, NULL);
8524 #ifdef G_ENABLE_DEBUG
8526 /* Verify invariants, see docs/widget_system.txt for notes on much of
8527 * this. Invariants may be temporarily broken while we're in the
8528 * process of updating state, of course, so you can only
8529 * verify_invariants() after a given operation is complete.
8530 * Use push/pop_verify_invariants to help with that.
8533 gtk_widget_verify_invariants (GtkWidget *widget)
8537 if (widget->priv->verifying_invariants_count > 0)
8540 parent = widget->priv->parent;
8542 if (widget->priv->mapped)
8544 /* Mapped implies ... */
8546 if (!widget->priv->realized)
8547 g_warning ("%s %p is mapped but not realized",
8548 G_OBJECT_TYPE_NAME (widget), widget);
8550 if (!widget->priv->visible)
8551 g_warning ("%s %p is mapped but not visible",
8552 G_OBJECT_TYPE_NAME (widget), widget);
8554 if (!widget->priv->toplevel)
8556 if (!widget->priv->child_visible)
8557 g_warning ("%s %p is mapped but not child_visible",
8558 G_OBJECT_TYPE_NAME (widget), widget);
8563 /* Not mapped implies... */
8566 /* This check makes sense for normal toplevels, but for
8567 * something like a toplevel that is embedded within a clutter
8568 * state, mapping may depend on external factors.
8570 if (widget->priv->toplevel)
8572 if (widget->priv->visible)
8573 g_warning ("%s %p toplevel is visible but not mapped",
8574 G_OBJECT_TYPE_NAME (widget), widget);
8579 /* Parent related checks aren't possible if parent has
8580 * verifying_invariants_count > 0 because parent needs to recurse
8581 * children first before the invariants will hold.
8583 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8586 parent->priv->realized)
8588 /* Parent realized implies... */
8591 /* This is in widget_system.txt but appears to fail
8592 * because there's no gtk_container_realize() that
8593 * realizes all children... instead we just lazily
8594 * wait for map to fix things up.
8596 if (!widget->priv->realized)
8597 g_warning ("%s %p is realized but child %s %p is not realized",
8598 G_OBJECT_TYPE_NAME (parent), parent,
8599 G_OBJECT_TYPE_NAME (widget), widget);
8602 else if (!widget->priv->toplevel)
8604 /* No parent or parent not realized on non-toplevel implies... */
8606 if (widget->priv->realized && !widget->priv->in_reparent)
8607 g_warning ("%s %p is not realized but child %s %p is realized",
8608 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8609 G_OBJECT_TYPE_NAME (widget), widget);
8613 parent->priv->mapped &&
8614 widget->priv->visible &&
8615 widget->priv->child_visible)
8617 /* Parent mapped and we are visible implies... */
8619 if (!widget->priv->mapped)
8620 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8621 G_OBJECT_TYPE_NAME (parent), parent,
8622 G_OBJECT_TYPE_NAME (widget), widget);
8624 else if (!widget->priv->toplevel)
8626 /* No parent or parent not mapped on non-toplevel implies... */
8628 if (widget->priv->mapped && !widget->priv->in_reparent)
8629 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8630 G_OBJECT_TYPE_NAME (widget), widget,
8631 widget->priv->visible,
8632 widget->priv->child_visible,
8633 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8634 parent ? parent->priv->mapped : FALSE);
8638 if (!widget->priv->realized)
8640 /* Not realized implies... */
8643 /* widget_system.txt says these hold, but they don't. */
8644 if (widget->priv->alloc_needed)
8645 g_warning ("%s %p alloc needed but not realized",
8646 G_OBJECT_TYPE_NAME (widget), widget);
8648 if (widget->priv->width_request_needed)
8649 g_warning ("%s %p width request needed but not realized",
8650 G_OBJECT_TYPE_NAME (widget), widget);
8652 if (widget->priv->height_request_needed)
8653 g_warning ("%s %p height request needed but not realized",
8654 G_OBJECT_TYPE_NAME (widget), widget);
8659 /* The point of this push/pop is that invariants may not hold while
8660 * we're busy making changes. So we only check at the outermost call
8661 * on the call stack, after we finish updating everything.
8664 gtk_widget_push_verify_invariants (GtkWidget *widget)
8666 widget->priv->verifying_invariants_count += 1;
8670 gtk_widget_verify_child_invariants (GtkWidget *widget,
8671 gpointer client_data)
8673 /* We don't recurse further; this is a one-level check. */
8674 gtk_widget_verify_invariants (widget);
8678 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8680 g_assert (widget->priv->verifying_invariants_count > 0);
8682 widget->priv->verifying_invariants_count -= 1;
8684 if (widget->priv->verifying_invariants_count == 0)
8686 gtk_widget_verify_invariants (widget);
8688 if (GTK_IS_CONTAINER (widget))
8690 /* Check one level of children, because our
8691 * push_verify_invariants() will have prevented some of the
8692 * checks. This does not recurse because if recursion is
8693 * needed, it will happen naturally as each child has a
8694 * push/pop on that child. For example if we're recursively
8695 * mapping children, we'll push/pop on each child as we map
8698 gtk_container_forall (GTK_CONTAINER (widget),
8699 gtk_widget_verify_child_invariants,
8704 #endif /* G_ENABLE_DEBUG */
8706 static PangoContext *
8707 gtk_widget_peek_pango_context (GtkWidget *widget)
8709 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8713 * gtk_widget_get_pango_context:
8714 * @widget: a #GtkWidget
8716 * Gets a #PangoContext with the appropriate font map, font description,
8717 * and base direction for this widget. Unlike the context returned
8718 * by gtk_widget_create_pango_context(), this context is owned by
8719 * the widget (it can be used until the screen for the widget changes
8720 * or the widget is removed from its toplevel), and will be updated to
8721 * match any changes to the widget's attributes. This can be tracked
8722 * by using the #GtkWidget::screen-changed signal on the widget.
8724 * Return value: (transfer none): the #PangoContext for the widget.
8727 gtk_widget_get_pango_context (GtkWidget *widget)
8729 PangoContext *context;
8731 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8733 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8736 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8737 g_object_set_qdata_full (G_OBJECT (widget),
8738 quark_pango_context,
8747 update_pango_context (GtkWidget *widget,
8748 PangoContext *context)
8750 PangoFontDescription *font_desc;
8751 GtkStyleContext *style_context;
8753 style_context = gtk_widget_get_style_context (widget);
8754 gtk_style_context_get (style_context,
8755 gtk_widget_get_state_flags (widget),
8759 pango_context_set_font_description (context, font_desc);
8760 pango_context_set_base_dir (context,
8761 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8762 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8764 pango_font_description_free (font_desc);
8768 gtk_widget_update_pango_context (GtkWidget *widget)
8770 PangoContext *context = gtk_widget_peek_pango_context (widget);
8776 update_pango_context (widget, context);
8778 screen = gtk_widget_get_screen_unchecked (widget);
8781 pango_cairo_context_set_resolution (context,
8782 gdk_screen_get_resolution (screen));
8783 pango_cairo_context_set_font_options (context,
8784 gdk_screen_get_font_options (screen));
8790 * gtk_widget_create_pango_context:
8791 * @widget: a #GtkWidget
8793 * Creates a new #PangoContext with the appropriate font map,
8794 * font description, and base direction for drawing text for
8795 * this widget. See also gtk_widget_get_pango_context().
8797 * Return value: (transfer full): the new #PangoContext
8800 gtk_widget_create_pango_context (GtkWidget *widget)
8803 PangoContext *context;
8805 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8807 screen = gtk_widget_get_screen_unchecked (widget);
8810 GTK_NOTE (MULTIHEAD,
8811 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8813 screen = gdk_screen_get_default ();
8816 context = gdk_pango_context_get_for_screen (screen);
8818 update_pango_context (widget, context);
8819 pango_context_set_language (context, gtk_get_default_language ());
8825 * gtk_widget_create_pango_layout:
8826 * @widget: a #GtkWidget
8827 * @text: text to set on the layout (can be %NULL)
8829 * Creates a new #PangoLayout with the appropriate font map,
8830 * font description, and base direction for drawing text for
8833 * If you keep a #PangoLayout created in this way around, you need
8834 * to re-create it when the widget #PangoContext is replaced.
8835 * This can be tracked by using the #GtkWidget::screen-changed signal
8838 * Return value: (transfer full): the new #PangoLayout
8841 gtk_widget_create_pango_layout (GtkWidget *widget,
8844 PangoLayout *layout;
8845 PangoContext *context;
8847 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8849 context = gtk_widget_get_pango_context (widget);
8850 layout = pango_layout_new (context);
8853 pango_layout_set_text (layout, text, -1);
8859 * gtk_widget_render_icon_pixbuf:
8860 * @widget: a #GtkWidget
8861 * @stock_id: a stock ID
8862 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8863 * render at the size of the source and don't scale (if there are
8864 * multiple source sizes, GTK+ picks one of the available sizes).
8866 * A convenience function that uses the theme engine and style
8867 * settings for @widget to look up @stock_id and render it to
8868 * a pixbuf. @stock_id should be a stock icon ID such as
8869 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8870 * such as #GTK_ICON_SIZE_MENU.
8872 * The pixels in the returned #GdkPixbuf are shared with the rest of
8873 * the application and should not be modified. The pixbuf should be freed
8874 * after use with g_object_unref().
8876 * Return value: (transfer full): a new pixbuf, or %NULL if the
8877 * stock ID wasn't known
8882 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8883 const gchar *stock_id,
8886 GtkStyleContext *context;
8887 GtkIconSet *icon_set;
8889 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8890 g_return_val_if_fail (stock_id != NULL, NULL);
8891 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8893 context = gtk_widget_get_style_context (widget);
8894 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8896 if (icon_set == NULL)
8899 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8903 * gtk_widget_set_parent_window:
8904 * @widget: a #GtkWidget.
8905 * @parent_window: the new parent window.
8907 * Sets a non default parent window for @widget.
8909 * For GtkWindow classes, setting a @parent_window effects whether
8910 * the window is a toplevel window or can be embedded into other
8914 * For GtkWindow classes, this needs to be called before the
8915 * window is realized.
8920 gtk_widget_set_parent_window (GtkWidget *widget,
8921 GdkWindow *parent_window)
8923 GdkWindow *old_parent_window;
8925 g_return_if_fail (GTK_IS_WIDGET (widget));
8927 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8928 quark_parent_window);
8930 if (parent_window != old_parent_window)
8934 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8936 if (old_parent_window)
8937 g_object_unref (old_parent_window);
8939 g_object_ref (parent_window);
8941 /* Unset toplevel flag when adding a parent window to a widget,
8942 * this is the primary entry point to allow toplevels to be
8945 #ifdef GDK_WINDOWING_X11
8946 is_plug = GTK_IS_PLUG (widget);
8950 if (GTK_IS_WINDOW (widget) && !is_plug)
8951 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8956 * gtk_widget_get_parent_window:
8957 * @widget: a #GtkWidget.
8959 * Gets @widget's parent window.
8961 * Returns: (transfer none): the parent window of @widget.
8964 gtk_widget_get_parent_window (GtkWidget *widget)
8966 GtkWidgetPrivate *priv;
8967 GdkWindow *parent_window;
8969 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8971 priv = widget->priv;
8973 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8975 return (parent_window != NULL) ? parent_window :
8976 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8981 * gtk_widget_set_child_visible:
8982 * @widget: a #GtkWidget
8983 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8985 * Sets whether @widget should be mapped along with its when its parent
8986 * is mapped and @widget has been shown with gtk_widget_show().
8988 * The child visibility can be set for widget before it is added to
8989 * a container with gtk_widget_set_parent(), to avoid mapping
8990 * children unnecessary before immediately unmapping them. However
8991 * it will be reset to its default state of %TRUE when the widget
8992 * is removed from a container.
8994 * Note that changing the child visibility of a widget does not
8995 * queue a resize on the widget. Most of the time, the size of
8996 * a widget is computed from all visible children, whether or
8997 * not they are mapped. If this is not the case, the container
8998 * can queue a resize itself.
9000 * This function is only useful for container implementations and
9001 * never should be called by an application.
9004 gtk_widget_set_child_visible (GtkWidget *widget,
9005 gboolean is_visible)
9007 GtkWidgetPrivate *priv;
9009 g_return_if_fail (GTK_IS_WIDGET (widget));
9010 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9012 priv = widget->priv;
9014 g_object_ref (widget);
9015 gtk_widget_verify_invariants (widget);
9018 priv->child_visible = TRUE;
9021 GtkWidget *toplevel;
9023 priv->child_visible = FALSE;
9025 toplevel = gtk_widget_get_toplevel (widget);
9026 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9027 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9030 if (priv->parent && gtk_widget_get_realized (priv->parent))
9032 if (gtk_widget_get_mapped (priv->parent) &&
9033 priv->child_visible &&
9034 gtk_widget_get_visible (widget))
9035 gtk_widget_map (widget);
9037 gtk_widget_unmap (widget);
9040 gtk_widget_verify_invariants (widget);
9041 g_object_unref (widget);
9045 * gtk_widget_get_child_visible:
9046 * @widget: a #GtkWidget
9048 * Gets the value set with gtk_widget_set_child_visible().
9049 * If you feel a need to use this function, your code probably
9050 * needs reorganization.
9052 * This function is only useful for container implementations and
9053 * never should be called by an application.
9055 * Return value: %TRUE if the widget is mapped with the parent.
9058 gtk_widget_get_child_visible (GtkWidget *widget)
9060 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9062 return widget->priv->child_visible;
9066 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9068 GtkWidget *toplevel;
9070 toplevel = gtk_widget_get_toplevel (widget);
9072 if (gtk_widget_is_toplevel (toplevel))
9074 if (GTK_IS_WINDOW (toplevel))
9075 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9076 else if (GTK_IS_INVISIBLE (toplevel))
9077 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9084 * gtk_widget_get_screen:
9085 * @widget: a #GtkWidget
9087 * Get the #GdkScreen from the toplevel window associated with
9088 * this widget. This function can only be called after the widget
9089 * has been added to a widget hierarchy with a #GtkWindow
9092 * In general, you should only create screen specific
9093 * resources when a widget has been realized, and you should
9094 * free those resources when the widget is unrealized.
9096 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9101 gtk_widget_get_screen (GtkWidget *widget)
9105 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9107 screen = gtk_widget_get_screen_unchecked (widget);
9114 g_warning (G_STRLOC ": Can't get associated screen"
9115 " for a widget unless it is inside a toplevel GtkWindow\n"
9116 " widget type is %s associated top level type is %s",
9117 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9118 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9120 return gdk_screen_get_default ();
9125 * gtk_widget_has_screen:
9126 * @widget: a #GtkWidget
9128 * Checks whether there is a #GdkScreen is associated with
9129 * this widget. All toplevel widgets have an associated
9130 * screen, and all widgets added into a hierarchy with a toplevel
9131 * window at the top.
9133 * Return value: %TRUE if there is a #GdkScreen associcated
9139 gtk_widget_has_screen (GtkWidget *widget)
9141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9143 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9147 * gtk_widget_get_display:
9148 * @widget: a #GtkWidget
9150 * Get the #GdkDisplay for the toplevel window associated with
9151 * this widget. This function can only be called after the widget
9152 * has been added to a widget hierarchy with a #GtkWindow at the top.
9154 * In general, you should only create display specific
9155 * resources when a widget has been realized, and you should
9156 * free those resources when the widget is unrealized.
9158 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9163 gtk_widget_get_display (GtkWidget *widget)
9165 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9167 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9171 * gtk_widget_get_root_window:
9172 * @widget: a #GtkWidget
9174 * Get the root window where this widget is located. This function can
9175 * only be called after the widget has been added to a widget
9176 * hierarchy with #GtkWindow at the top.
9178 * The root window is useful for such purposes as creating a popup
9179 * #GdkWindow associated with the window. In general, you should only
9180 * create display specific resources when a widget has been realized,
9181 * and you should free those resources when the widget is unrealized.
9183 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9188 gtk_widget_get_root_window (GtkWidget *widget)
9190 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9192 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9196 * gtk_widget_child_focus:
9197 * @widget: a #GtkWidget
9198 * @direction: direction of focus movement
9200 * This function is used by custom widget implementations; if you're
9201 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9202 * to a particular widget, and gtk_container_set_focus_chain() to
9203 * change the focus tab order. So you may want to investigate those
9204 * functions instead.
9206 * gtk_widget_child_focus() is called by containers as the user moves
9207 * around the window using keyboard shortcuts. @direction indicates
9208 * what kind of motion is taking place (up, down, left, right, tab
9209 * forward, tab backward). gtk_widget_child_focus() emits the
9210 * #GtkWidget::focus signal; widgets override the default handler
9211 * for this signal in order to implement appropriate focus behavior.
9213 * The default ::focus handler for a widget should return %TRUE if
9214 * moving in @direction left the focus on a focusable location inside
9215 * that widget, and %FALSE if moving in @direction moved the focus
9216 * outside the widget. If returning %TRUE, widgets normally
9217 * call gtk_widget_grab_focus() to place the focus accordingly;
9218 * if returning %FALSE, they don't modify the current focus location.
9220 * Return value: %TRUE if focus ended up inside @widget
9223 gtk_widget_child_focus (GtkWidget *widget,
9224 GtkDirectionType direction)
9226 gboolean return_val;
9228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9230 if (!gtk_widget_get_visible (widget) ||
9231 !gtk_widget_is_sensitive (widget))
9234 /* child widgets must set CAN_FOCUS, containers
9235 * don't have to though.
9237 if (!GTK_IS_CONTAINER (widget) &&
9238 !gtk_widget_get_can_focus (widget))
9241 g_signal_emit (widget,
9242 widget_signals[FOCUS],
9244 direction, &return_val);
9250 * gtk_widget_keynav_failed:
9251 * @widget: a #GtkWidget
9252 * @direction: direction of focus movement
9254 * This function should be called whenever keyboard navigation within
9255 * a single widget hits a boundary. The function emits the
9256 * #GtkWidget::keynav-failed signal on the widget and its return
9257 * value should be interpreted in a way similar to the return value of
9258 * gtk_widget_child_focus():
9260 * When %TRUE is returned, stay in the widget, the failed keyboard
9261 * navigation is Ok and/or there is nowhere we can/should move the
9264 * When %FALSE is returned, the caller should continue with keyboard
9265 * navigation outside the widget, e.g. by calling
9266 * gtk_widget_child_focus() on the widget's toplevel.
9268 * The default ::keynav-failed handler returns %TRUE for
9269 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9270 * values of #GtkDirectionType, it looks at the
9271 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9272 * if the setting is %TRUE. This way the entire user interface
9273 * becomes cursor-navigatable on input devices such as mobile phones
9274 * which only have cursor keys but no tab key.
9276 * Whenever the default handler returns %TRUE, it also calls
9277 * gtk_widget_error_bell() to notify the user of the failed keyboard
9280 * A use case for providing an own implementation of ::keynav-failed
9281 * (either by connecting to it or by overriding it) would be a row of
9282 * #GtkEntry widgets where the user should be able to navigate the
9283 * entire row with the cursor keys, as e.g. known from user interfaces
9284 * that require entering license keys.
9286 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9287 * if the emitting widget should try to handle the keyboard
9288 * navigation attempt in its parent container(s).
9293 gtk_widget_keynav_failed (GtkWidget *widget,
9294 GtkDirectionType direction)
9296 gboolean return_val;
9298 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9300 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9301 direction, &return_val);
9307 * gtk_widget_error_bell:
9308 * @widget: a #GtkWidget
9310 * Notifies the user about an input-related error on this widget.
9311 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9312 * gdk_window_beep(), otherwise it does nothing.
9314 * Note that the effect of gdk_window_beep() can be configured in many
9315 * ways, depending on the windowing backend and the desktop environment
9316 * or window manager that is used.
9321 gtk_widget_error_bell (GtkWidget *widget)
9323 GtkWidgetPrivate *priv;
9324 GtkSettings* settings;
9327 g_return_if_fail (GTK_IS_WIDGET (widget));
9329 priv = widget->priv;
9331 settings = gtk_widget_get_settings (widget);
9335 g_object_get (settings,
9336 "gtk-error-bell", &beep,
9339 if (beep && priv->window)
9340 gdk_window_beep (priv->window);
9344 gtk_widget_set_usize_internal (GtkWidget *widget,
9347 GtkQueueResizeFlags flags)
9349 GtkWidgetAuxInfo *aux_info;
9350 gboolean changed = FALSE;
9352 g_object_freeze_notify (G_OBJECT (widget));
9354 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9356 if (width > -2 && aux_info->width != width)
9358 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9359 g_object_notify (G_OBJECT (widget), "width-request");
9360 aux_info->width = width;
9363 if (height > -2 && aux_info->height != height)
9365 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9366 g_object_notify (G_OBJECT (widget), "height-request");
9367 aux_info->height = height;
9371 if (gtk_widget_get_visible (widget) && changed)
9373 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9374 gtk_widget_queue_resize (widget);
9376 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9379 g_object_thaw_notify (G_OBJECT (widget));
9383 * gtk_widget_set_size_request:
9384 * @widget: a #GtkWidget
9385 * @width: width @widget should request, or -1 to unset
9386 * @height: height @widget should request, or -1 to unset
9388 * Sets the minimum size of a widget; that is, the widget's size
9389 * request will be at least @width by @height. You can use this
9390 * function to force a widget to be larger than it normally would be.
9392 * In most cases, gtk_window_set_default_size() is a better choice for
9393 * toplevel windows than this function; setting the default size will
9394 * still allow users to shrink the window. Setting the size request
9395 * will force them to leave the window at least as large as the size
9396 * request. When dealing with window sizes,
9397 * gtk_window_set_geometry_hints() can be a useful function as well.
9399 * Note the inherent danger of setting any fixed size - themes,
9400 * translations into other languages, different fonts, and user action
9401 * can all change the appropriate size for a given widget. So, it's
9402 * basically impossible to hardcode a size that will always be
9405 * The size request of a widget is the smallest size a widget can
9406 * accept while still functioning well and drawing itself correctly.
9407 * However in some strange cases a widget may be allocated less than
9408 * its requested size, and in many cases a widget may be allocated more
9409 * space than it requested.
9411 * If the size request in a given direction is -1 (unset), then
9412 * the "natural" size request of the widget will be used instead.
9414 * The size request set here does not include any margin from the
9415 * #GtkWidget properties margin-left, margin-right, margin-top, and
9416 * margin-bottom, but it does include pretty much all other padding
9417 * or border properties set by any subclass of #GtkWidget.
9420 gtk_widget_set_size_request (GtkWidget *widget,
9424 g_return_if_fail (GTK_IS_WIDGET (widget));
9425 g_return_if_fail (width >= -1);
9426 g_return_if_fail (height >= -1);
9433 gtk_widget_set_usize_internal (widget, width, height, 0);
9438 * gtk_widget_get_size_request:
9439 * @widget: a #GtkWidget
9440 * @width: (out) (allow-none): return location for width, or %NULL
9441 * @height: (out) (allow-none): return location for height, or %NULL
9443 * Gets the size request that was explicitly set for the widget using
9444 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9445 * @height indicates that that dimension has not been set explicitly
9446 * and the natural requisition of the widget will be used intead. See
9447 * gtk_widget_set_size_request(). To get the size a widget will
9448 * actually request, call gtk_widget_get_preferred_size() instead of
9452 gtk_widget_get_size_request (GtkWidget *widget,
9456 const GtkWidgetAuxInfo *aux_info;
9458 g_return_if_fail (GTK_IS_WIDGET (widget));
9460 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9463 *width = aux_info->width;
9466 *height = aux_info->height;
9470 * _gtk_widget_override_size_request:
9471 * @widget: a #GtkWidget
9472 * @width: new forced minimum width
9473 * @height: new forced minimum height
9474 * @old_width: location to store previous forced minimum width
9475 * @old_height: location to store previous forced minumum height
9477 * Temporarily establishes a forced minimum size for a widget; this
9478 * is used by GtkWindow when calculating the size to add to the
9479 * window's geometry widget. Cached sizes for the widget and its
9480 * parents are invalidated, so that subsequent calls to the size
9481 * negotiation machinery produce the overriden result, but the
9482 * widget is not queued for relayout or redraw. The old size must
9483 * be restored with _gtk_widget_restore_size_request() or things
9487 _gtk_widget_override_size_request (GtkWidget *widget,
9493 gtk_widget_get_size_request (widget, old_width, old_height);
9494 gtk_widget_set_usize_internal (widget, width, height,
9495 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9499 * _gtk_widget_restore_size_request:
9500 * @widget: a #GtkWidget
9501 * @old_width: saved forced minimum size
9502 * @old_height: saved forced minimum size
9504 * Undoes the operation of_gtk_widget_override_size_request().
9507 _gtk_widget_restore_size_request (GtkWidget *widget,
9511 gtk_widget_set_usize_internal (widget, old_width, old_height,
9512 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9516 * gtk_widget_set_events:
9517 * @widget: a #GtkWidget
9518 * @events: event mask
9520 * Sets the event mask (see #GdkEventMask) for a widget. The event
9521 * mask determines which events a widget will receive. Keep in mind
9522 * that different widgets have different default event masks, and by
9523 * changing the event mask you may disrupt a widget's functionality,
9524 * so be careful. This function must be called while a widget is
9525 * unrealized. Consider gtk_widget_add_events() for widgets that are
9526 * already realized, or if you want to preserve the existing event
9527 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9528 * to get events on those widgets, place them inside a #GtkEventBox
9529 * and receive events on the event box.
9532 gtk_widget_set_events (GtkWidget *widget,
9535 g_return_if_fail (GTK_IS_WIDGET (widget));
9536 g_return_if_fail (!gtk_widget_get_realized (widget));
9538 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9539 GINT_TO_POINTER (events));
9540 g_object_notify (G_OBJECT (widget), "events");
9544 * gtk_widget_set_device_events:
9545 * @widget: a #GtkWidget
9546 * @device: a #GdkDevice
9547 * @events: event mask
9549 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9550 * mask determines which events a widget will receive from @device. Keep
9551 * in mind that different widgets have different default event masks, and by
9552 * changing the event mask you may disrupt a widget's functionality,
9553 * so be careful. This function must be called while a widget is
9554 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9555 * already realized, or if you want to preserve the existing event
9556 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9557 * to get events on those widgets, place them inside a #GtkEventBox
9558 * and receive events on the event box.
9563 gtk_widget_set_device_events (GtkWidget *widget,
9565 GdkEventMask events)
9567 GHashTable *device_events;
9569 g_return_if_fail (GTK_IS_WIDGET (widget));
9570 g_return_if_fail (GDK_IS_DEVICE (device));
9571 g_return_if_fail (!gtk_widget_get_realized (widget));
9573 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9575 if (G_UNLIKELY (!device_events))
9577 device_events = g_hash_table_new (NULL, NULL);
9578 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9579 (GDestroyNotify) g_hash_table_unref);
9582 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9586 * gtk_widget_set_device_enabled:
9587 * @widget: a #GtkWidget
9588 * @device: a #GdkDevice
9589 * @enabled: whether to enable the device
9591 * Enables or disables a #GdkDevice to interact with @widget
9592 * and all its children.
9594 * It does so by descending through the #GdkWindow hierarchy
9595 * and enabling the same mask that is has for core events
9596 * (i.e. the one that gdk_window_get_events() returns).
9601 gtk_widget_set_device_enabled (GtkWidget *widget,
9605 GList *enabled_devices;
9607 g_return_if_fail (GTK_IS_WIDGET (widget));
9608 g_return_if_fail (GDK_IS_DEVICE (device));
9610 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9611 enabled_devices = g_list_append (enabled_devices, device);
9613 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9614 enabled_devices, (GDestroyNotify) g_list_free);;
9616 if (gtk_widget_get_realized (widget))
9617 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9621 * gtk_widget_get_device_enabled:
9622 * @widget: a #GtkWidget
9623 * @device: a #GdkDevice
9625 * Returns whether @device can interact with @widget and its
9626 * children. See gtk_widget_set_device_enabled().
9628 * Return value: %TRUE is @device is enabled for @widget
9633 gtk_widget_get_device_enabled (GtkWidget *widget,
9636 GList *enabled_devices;
9638 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9639 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9641 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9643 return g_list_find (enabled_devices, device) != NULL;
9647 gtk_widget_add_events_internal_list (GtkWidget *widget,
9654 for (l = window_list; l != NULL; l = l->next)
9656 GdkWindow *window = l->data;
9659 gdk_window_get_user_data (window, &user_data);
9660 if (user_data == widget)
9665 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9667 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9669 children = gdk_window_get_children (window);
9670 gtk_widget_add_events_internal_list (widget, device, events, children);
9671 g_list_free (children);
9677 gtk_widget_add_events_internal (GtkWidget *widget,
9681 GtkWidgetPrivate *priv = widget->priv;
9684 if (!gtk_widget_get_has_window (widget))
9685 window_list = gdk_window_get_children (priv->window);
9687 window_list = g_list_prepend (NULL, priv->window);
9689 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9691 g_list_free (window_list);
9695 * gtk_widget_add_events:
9696 * @widget: a #GtkWidget
9697 * @events: an event mask, see #GdkEventMask
9699 * Adds the events in the bitfield @events to the event mask for
9700 * @widget. See gtk_widget_set_events() for details.
9703 gtk_widget_add_events (GtkWidget *widget,
9708 g_return_if_fail (GTK_IS_WIDGET (widget));
9710 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9711 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9712 GINT_TO_POINTER (old_events | events));
9714 if (gtk_widget_get_realized (widget))
9716 gtk_widget_add_events_internal (widget, NULL, events);
9717 gtk_widget_update_devices_mask (widget, FALSE);
9720 g_object_notify (G_OBJECT (widget), "events");
9724 * gtk_widget_add_device_events:
9725 * @widget: a #GtkWidget
9726 * @device: a #GdkDevice
9727 * @events: an event mask, see #GdkEventMask
9729 * Adds the device events in the bitfield @events to the event mask for
9730 * @widget. See gtk_widget_set_device_events() for details.
9735 gtk_widget_add_device_events (GtkWidget *widget,
9737 GdkEventMask events)
9739 GdkEventMask old_events;
9740 GHashTable *device_events;
9742 g_return_if_fail (GTK_IS_WIDGET (widget));
9743 g_return_if_fail (GDK_IS_DEVICE (device));
9745 old_events = gtk_widget_get_device_events (widget, device);
9747 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9749 if (G_UNLIKELY (!device_events))
9751 device_events = g_hash_table_new (NULL, NULL);
9752 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9753 (GDestroyNotify) g_hash_table_unref);
9756 g_hash_table_insert (device_events, device,
9757 GUINT_TO_POINTER (old_events | events));
9759 if (gtk_widget_get_realized (widget))
9760 gtk_widget_add_events_internal (widget, device, events);
9762 g_object_notify (G_OBJECT (widget), "events");
9766 * gtk_widget_get_toplevel:
9767 * @widget: a #GtkWidget
9769 * This function returns the topmost widget in the container hierarchy
9770 * @widget is a part of. If @widget has no parent widgets, it will be
9771 * returned as the topmost widget. No reference will be added to the
9772 * returned widget; it should not be unreferenced.
9774 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9775 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9777 * %NULL if @widget wasn't inside a toplevel window, and if the
9778 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9779 * inside the toplevel #GtkWindow. While the second case may
9780 * seem unlikely, it actually happens when a #GtkPlug is embedded
9781 * inside a #GtkSocket within the same application.
9783 * To reliably find the toplevel #GtkWindow, use
9784 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9785 * is set on the result.
9787 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9788 * if (gtk_widget_is_toplevel (toplevel))
9790 * /* Perform action on toplevel. */
9794 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9795 * if there's no ancestor.
9798 gtk_widget_get_toplevel (GtkWidget *widget)
9800 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9802 while (widget->priv->parent)
9803 widget = widget->priv->parent;
9809 * gtk_widget_get_ancestor:
9810 * @widget: a #GtkWidget
9811 * @widget_type: ancestor type
9813 * Gets the first ancestor of @widget with type @widget_type. For example,
9814 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9815 * the first #GtkBox that's an ancestor of @widget. No reference will be
9816 * added to the returned widget; it should not be unreferenced. See note
9817 * about checking for a toplevel #GtkWindow in the docs for
9818 * gtk_widget_get_toplevel().
9820 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9821 * considers @widget to be an ancestor of itself.
9823 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9826 gtk_widget_get_ancestor (GtkWidget *widget,
9829 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9831 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9832 widget = widget->priv->parent;
9834 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9841 * gtk_widget_set_visual:
9842 * @widget: a #GtkWidget
9843 * @visual: visual to be used or %NULL to unset a previous one
9845 * Sets the visual that should be used for by widget and its children for
9846 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9847 * returned by gtk_widget_get_screen(), so handling the
9848 * #GtkWidget::screen-changed signal is necessary.
9850 * Setting a new @visual will not cause @widget to recreate its windows,
9851 * so you should call this function before @widget is realized.
9854 gtk_widget_set_visual (GtkWidget *widget,
9857 g_return_if_fail (GTK_IS_WIDGET (widget));
9858 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9861 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9864 g_object_set_qdata_full (G_OBJECT (widget),
9866 g_object_ref (visual),
9871 * gtk_widget_get_visual:
9872 * @widget: a #GtkWidget
9874 * Gets the visual that will be used to render @widget.
9876 * Return value: (transfer none): the visual for @widget
9879 gtk_widget_get_visual (GtkWidget *widget)
9885 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9887 if (gtk_widget_get_has_window (widget) &&
9888 widget->priv->window)
9889 return gdk_window_get_visual (widget->priv->window);
9891 screen = gtk_widget_get_screen (widget);
9893 for (w = widget; w != NULL; w = w->priv->parent)
9895 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9898 if (gdk_visual_get_screen (visual) == screen)
9901 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9902 gtk_widget_get_name (widget));
9906 return gdk_screen_get_system_visual (screen);
9910 * gtk_widget_get_settings:
9911 * @widget: a #GtkWidget
9913 * Gets the settings object holding the settings used for this widget.
9915 * Note that this function can only be called when the #GtkWidget
9916 * is attached to a toplevel, since the settings object is specific
9917 * to a particular #GdkScreen.
9919 * Return value: (transfer none): the relevant #GtkSettings object
9922 gtk_widget_get_settings (GtkWidget *widget)
9924 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9926 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9930 * gtk_widget_get_events:
9931 * @widget: a #GtkWidget
9933 * Returns the event mask for the widget (a bitfield containing flags
9934 * from the #GdkEventMask enumeration). These are the events that the widget
9937 * Return value: event mask for @widget
9940 gtk_widget_get_events (GtkWidget *widget)
9942 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9944 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9948 * gtk_widget_get_device_events:
9949 * @widget: a #GtkWidget
9950 * @device: a #GdkDevice
9952 * Returns the events mask for the widget corresponding to an specific device. These
9953 * are the events that the widget will receive when @device operates on it.
9955 * Returns: device event mask for @widget
9960 gtk_widget_get_device_events (GtkWidget *widget,
9963 GHashTable *device_events;
9965 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9966 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9968 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9973 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9977 * gtk_widget_get_pointer:
9978 * @widget: a #GtkWidget
9979 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9980 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9982 * Obtains the location of the mouse pointer in widget coordinates.
9983 * Widget coordinates are a bit odd; for historical reasons, they are
9984 * defined as @widget->window coordinates for widgets that are not
9985 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9986 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9988 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9991 gtk_widget_get_pointer (GtkWidget *widget,
9995 GtkWidgetPrivate *priv;
9997 g_return_if_fail (GTK_IS_WIDGET (widget));
9999 priv = widget->priv;
10006 if (gtk_widget_get_realized (widget))
10008 gdk_window_get_device_position (priv->window,
10009 gdk_device_manager_get_client_pointer (
10010 gdk_display_get_device_manager (
10011 gtk_widget_get_display (widget))),
10014 if (!gtk_widget_get_has_window (widget))
10017 *x -= priv->allocation.x;
10019 *y -= priv->allocation.y;
10025 * gtk_widget_is_ancestor:
10026 * @widget: a #GtkWidget
10027 * @ancestor: another #GtkWidget
10029 * Determines whether @widget is somewhere inside @ancestor, possibly with
10030 * intermediate containers.
10032 * Return value: %TRUE if @ancestor contains @widget as a child,
10033 * grandchild, great grandchild, etc.
10036 gtk_widget_is_ancestor (GtkWidget *widget,
10037 GtkWidget *ancestor)
10039 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10040 g_return_val_if_fail (ancestor != NULL, FALSE);
10044 if (widget->priv->parent == ancestor)
10046 widget = widget->priv->parent;
10052 static GQuark quark_composite_name = 0;
10055 * gtk_widget_set_composite_name:
10056 * @widget: a #GtkWidget.
10057 * @name: the name to set
10059 * Sets a widgets composite name. The widget must be
10060 * a composite child of its parent; see gtk_widget_push_composite_child().
10063 gtk_widget_set_composite_name (GtkWidget *widget,
10066 g_return_if_fail (GTK_IS_WIDGET (widget));
10067 g_return_if_fail (widget->priv->composite_child);
10068 g_return_if_fail (name != NULL);
10070 if (!quark_composite_name)
10071 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10073 g_object_set_qdata_full (G_OBJECT (widget),
10074 quark_composite_name,
10080 * gtk_widget_get_composite_name:
10081 * @widget: a #GtkWidget
10083 * Obtains the composite name of a widget.
10085 * Returns: the composite name of @widget, or %NULL if @widget is not
10086 * a composite child. The string should be freed when it is no
10090 gtk_widget_get_composite_name (GtkWidget *widget)
10092 GtkWidgetPrivate *priv;
10094 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10096 priv = widget->priv;
10098 if (widget->priv->composite_child && priv->parent)
10099 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10106 * gtk_widget_push_composite_child:
10108 * Makes all newly-created widgets as composite children until
10109 * the corresponding gtk_widget_pop_composite_child() call.
10111 * A composite child is a child that's an implementation detail of the
10112 * container it's inside and should not be visible to people using the
10113 * container. Composite children aren't treated differently by GTK (but
10114 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10115 * builders might want to treat them in a different way.
10117 * Here is a simple example:
10119 * gtk_widget_push_composite_child ();
10120 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10121 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10122 * gtk_widget_pop_composite_child ();
10123 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10124 * GTK_WIDGET (scrolled_window));
10125 * g_object_ref (scrolled_window->hscrollbar);
10129 gtk_widget_push_composite_child (void)
10131 composite_child_stack++;
10135 * gtk_widget_pop_composite_child:
10137 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10140 gtk_widget_pop_composite_child (void)
10142 if (composite_child_stack)
10143 composite_child_stack--;
10147 gtk_widget_emit_direction_changed (GtkWidget *widget,
10148 GtkTextDirection old_dir)
10150 GtkTextDirection direction;
10151 GtkStateFlags state;
10153 gtk_widget_update_pango_context (widget);
10155 direction = gtk_widget_get_direction (widget);
10156 state = widget->priv->state_flags;
10157 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10161 case GTK_TEXT_DIR_LTR:
10162 state |= GTK_STATE_FLAG_DIR_LTR;
10165 case GTK_TEXT_DIR_RTL:
10166 state |= GTK_STATE_FLAG_DIR_RTL;
10169 case GTK_TEXT_DIR_NONE:
10171 g_assert_not_reached ();
10175 gtk_widget_set_state_flags (widget, state, TRUE);
10177 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10181 * gtk_widget_set_direction:
10182 * @widget: a #GtkWidget
10183 * @dir: the new direction
10185 * Sets the reading direction on a particular widget. This direction
10186 * controls the primary direction for widgets containing text,
10187 * and also the direction in which the children of a container are
10188 * packed. The ability to set the direction is present in order
10189 * so that correct localization into languages with right-to-left
10190 * reading directions can be done. Generally, applications will
10191 * let the default reading direction present, except for containers
10192 * where the containers are arranged in an order that is explicitely
10193 * visual rather than logical (such as buttons for text justification).
10195 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10196 * set by gtk_widget_set_default_direction() will be used.
10199 gtk_widget_set_direction (GtkWidget *widget,
10200 GtkTextDirection dir)
10202 GtkTextDirection old_dir;
10204 g_return_if_fail (GTK_IS_WIDGET (widget));
10205 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10207 old_dir = gtk_widget_get_direction (widget);
10209 widget->priv->direction = dir;
10211 if (old_dir != gtk_widget_get_direction (widget))
10212 gtk_widget_emit_direction_changed (widget, old_dir);
10216 * gtk_widget_get_direction:
10217 * @widget: a #GtkWidget
10219 * Gets the reading direction for a particular widget. See
10220 * gtk_widget_set_direction().
10222 * Return value: the reading direction for the widget.
10225 gtk_widget_get_direction (GtkWidget *widget)
10227 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10229 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10230 return gtk_default_direction;
10232 return widget->priv->direction;
10236 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10238 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10240 g_object_ref (widget);
10242 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10243 gtk_widget_emit_direction_changed (widget, old_dir);
10245 if (GTK_IS_CONTAINER (widget))
10246 gtk_container_forall (GTK_CONTAINER (widget),
10247 gtk_widget_set_default_direction_recurse,
10250 g_object_unref (widget);
10254 * gtk_widget_set_default_direction:
10255 * @dir: the new default direction. This cannot be
10256 * %GTK_TEXT_DIR_NONE.
10258 * Sets the default reading direction for widgets where the
10259 * direction has not been explicitly set by gtk_widget_set_direction().
10262 gtk_widget_set_default_direction (GtkTextDirection dir)
10264 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10266 if (dir != gtk_default_direction)
10268 GList *toplevels, *tmp_list;
10269 GtkTextDirection old_dir = gtk_default_direction;
10271 gtk_default_direction = dir;
10273 tmp_list = toplevels = gtk_window_list_toplevels ();
10274 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10278 gtk_widget_set_default_direction_recurse (tmp_list->data,
10279 GUINT_TO_POINTER (old_dir));
10280 g_object_unref (tmp_list->data);
10281 tmp_list = tmp_list->next;
10284 g_list_free (toplevels);
10289 * gtk_widget_get_default_direction:
10291 * Obtains the current default reading direction. See
10292 * gtk_widget_set_default_direction().
10294 * Return value: the current default direction.
10297 gtk_widget_get_default_direction (void)
10299 return gtk_default_direction;
10303 gtk_widget_constructed (GObject *object)
10305 GtkWidget *widget = GTK_WIDGET (object);
10306 GtkWidgetPrivate *priv = widget->priv;
10308 /* As strange as it may seem, this may happen on object construction.
10309 * init() implementations of parent types may eventually call this function,
10310 * each with its corresponding GType, which could leave a child
10311 * implementation with a wrong widget type in the widget path
10314 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10316 gtk_widget_path_free (priv->path);
10320 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10324 gtk_widget_dispose (GObject *object)
10326 GtkWidget *widget = GTK_WIDGET (object);
10327 GtkWidgetPrivate *priv = widget->priv;
10330 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10331 else if (gtk_widget_get_visible (widget))
10332 gtk_widget_hide (widget);
10334 priv->visible = FALSE;
10335 if (gtk_widget_get_realized (widget))
10336 gtk_widget_unrealize (widget);
10338 if (!priv->in_destruction)
10340 priv->in_destruction = TRUE;
10341 g_signal_emit (object, widget_signals[DESTROY], 0);
10342 priv->in_destruction = FALSE;
10345 g_clear_object (&priv->muxer);
10347 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10351 gtk_widget_real_destroy (GtkWidget *object)
10353 /* gtk_object_destroy() will already hold a refcount on object */
10354 GtkWidget *widget = GTK_WIDGET (object);
10355 GtkWidgetPrivate *priv = widget->priv;
10357 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10359 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10363 gtk_accessible_set_widget (accessible, NULL);
10364 g_object_unref (accessible);
10368 /* wipe accelerator closures (keep order) */
10369 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10370 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10372 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10373 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10375 gtk_grab_remove (widget);
10378 g_object_unref (priv->style);
10379 priv->style = gtk_widget_get_default_style ();
10380 g_object_ref (priv->style);
10384 gtk_widget_finalize (GObject *object)
10386 GtkWidget *widget = GTK_WIDGET (object);
10387 GtkWidgetPrivate *priv = widget->priv;
10388 GtkWidgetAuxInfo *aux_info;
10389 GtkAccessible *accessible;
10391 gtk_grab_remove (widget);
10393 g_object_unref (priv->style);
10394 priv->style = NULL;
10396 g_free (priv->name);
10398 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10400 gtk_widget_aux_info_destroy (aux_info);
10402 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10404 g_object_unref (accessible);
10407 gtk_widget_path_free (priv->path);
10411 _gtk_style_context_set_widget (priv->context, NULL);
10412 g_object_unref (priv->context);
10415 _gtk_size_request_cache_free (&priv->requests);
10417 if (g_object_is_floating (object))
10418 g_warning ("A floating object was finalized. This means that someone\n"
10419 "called g_object_unref() on an object that had only a floating\n"
10420 "reference; the initial floating reference is not owned by anyone\n"
10421 "and must be removed with g_object_ref_sink().");
10423 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10426 /*****************************************
10427 * gtk_widget_real_map:
10432 *****************************************/
10435 gtk_widget_real_map (GtkWidget *widget)
10437 GtkWidgetPrivate *priv = widget->priv;
10439 g_assert (gtk_widget_get_realized (widget));
10441 if (!gtk_widget_get_mapped (widget))
10443 gtk_widget_set_mapped (widget, TRUE);
10445 if (gtk_widget_get_has_window (widget))
10446 gdk_window_show (priv->window);
10450 /*****************************************
10451 * gtk_widget_real_unmap:
10456 *****************************************/
10459 gtk_widget_real_unmap (GtkWidget *widget)
10461 GtkWidgetPrivate *priv = widget->priv;
10463 if (gtk_widget_get_mapped (widget))
10465 gtk_widget_set_mapped (widget, FALSE);
10467 if (gtk_widget_get_has_window (widget))
10468 gdk_window_hide (priv->window);
10472 /*****************************************
10473 * gtk_widget_real_realize:
10478 *****************************************/
10481 gtk_widget_real_realize (GtkWidget *widget)
10483 GtkWidgetPrivate *priv = widget->priv;
10485 g_assert (!gtk_widget_get_has_window (widget));
10487 gtk_widget_set_realized (widget, TRUE);
10490 priv->window = gtk_widget_get_parent_window (widget);
10491 g_object_ref (priv->window);
10495 /*****************************************
10496 * gtk_widget_real_unrealize:
10501 *****************************************/
10504 gtk_widget_real_unrealize (GtkWidget *widget)
10506 GtkWidgetPrivate *priv = widget->priv;
10508 g_assert (!widget->priv->mapped);
10510 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10513 /* We must do unrealize child widget BEFORE container widget.
10514 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10515 * So, unrealizing container widget bofore its children causes the problem
10516 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10519 if (GTK_IS_CONTAINER (widget))
10520 gtk_container_forall (GTK_CONTAINER (widget),
10521 (GtkCallback) gtk_widget_unrealize,
10524 if (gtk_widget_get_has_window (widget))
10526 gdk_window_set_user_data (priv->window, NULL);
10527 gdk_window_destroy (priv->window);
10528 priv->window = NULL;
10532 g_object_unref (priv->window);
10533 priv->window = NULL;
10536 gtk_selection_remove_all (widget);
10538 gtk_widget_set_realized (widget, FALSE);
10542 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10543 GtkOrientation orientation,
10544 gint *minimum_size,
10545 gint *natural_size)
10547 const GtkWidgetAuxInfo *aux_info;
10549 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10551 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10552 aux_info->width > 0)
10554 *minimum_size = MAX (*minimum_size, aux_info->width);
10556 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10557 aux_info->height > 0)
10559 *minimum_size = MAX (*minimum_size, aux_info->height);
10562 /* Fix it if set_size_request made natural size smaller than min size.
10563 * This would also silently fix broken widgets, but we warn about them
10564 * in gtksizerequest.c when calling their size request vfuncs.
10566 *natural_size = MAX (*natural_size, *minimum_size);
10568 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10570 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10571 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10575 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10576 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10581 * _gtk_widget_peek_request_cache:
10583 * Returns the address of the widget's request cache (strictly for
10584 * internal use in gtksizerequest.c)
10586 * Return value: the address of @widget's size request cache.
10589 _gtk_widget_peek_request_cache (GtkWidget *widget)
10591 /* Don't bother slowing things down with the return_if_fail guards here */
10592 return &widget->priv->requests;
10596 * _gtk_widget_set_device_window:
10597 * @widget: a #GtkWidget
10598 * @device: a #GdkDevice
10599 * @window: the new device window
10601 * Sets pointer window for @widget and @device.
10602 * Does not ref @window.
10605 _gtk_widget_set_device_window (GtkWidget *widget,
10609 GHashTable *device_window;
10611 g_return_if_fail (GTK_IS_WIDGET (widget));
10612 g_return_if_fail (GDK_IS_DEVICE (device));
10613 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10615 if (!gtk_widget_get_mapped (widget))
10618 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10620 if (!device_window && window)
10622 device_window = g_hash_table_new (NULL, NULL);
10623 g_object_set_qdata_full (G_OBJECT (widget),
10624 quark_pointer_window,
10626 (GDestroyNotify) g_hash_table_destroy);
10630 g_hash_table_insert (device_window, device, window);
10631 else if (device_window)
10633 g_hash_table_remove (device_window, device);
10635 if (g_hash_table_size (device_window) == 0)
10636 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10641 * _gtk_widget_get_device_window:
10642 * @widget: a #GtkWidget
10643 * @device: a #GdkDevice
10645 * Return value: the device window set on @widget, or %NULL
10648 _gtk_widget_get_device_window (GtkWidget *widget,
10651 GHashTable *device_window;
10653 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10654 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10656 if (!gtk_widget_get_mapped (widget))
10659 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10661 if (!device_window)
10664 return g_hash_table_lookup (device_window, device);
10668 * _gtk_widget_list_devices:
10669 * @widget: a #GtkWidget
10671 * Returns the list of #GdkDevices that is currently on top
10672 * of any window belonging to @widget.
10673 * Free the list with g_list_free(), the elements are owned
10674 * by GTK+ and must not be freed.
10677 _gtk_widget_list_devices (GtkWidget *widget)
10679 GHashTableIter iter;
10680 GHashTable *device_window;
10681 GList *devices = NULL;
10682 gpointer key, value;
10684 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10686 if (!gtk_widget_get_mapped (widget))
10689 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10691 if (G_UNLIKELY (!device_window))
10694 g_hash_table_iter_init (&iter, device_window);
10696 while (g_hash_table_iter_next (&iter, &key, &value))
10697 devices = g_list_prepend (devices, key);
10703 synth_crossing (GtkWidget *widget,
10707 GdkCrossingMode mode,
10708 GdkNotifyType detail)
10712 event = gdk_event_new (type);
10714 event->crossing.window = g_object_ref (window);
10715 event->crossing.send_event = TRUE;
10716 event->crossing.subwindow = g_object_ref (window);
10717 event->crossing.time = GDK_CURRENT_TIME;
10718 event->crossing.x = event->crossing.y = 0;
10719 event->crossing.x_root = event->crossing.y_root = 0;
10720 event->crossing.mode = mode;
10721 event->crossing.detail = detail;
10722 event->crossing.focus = FALSE;
10723 event->crossing.state = 0;
10724 gdk_event_set_device (event, device);
10727 widget = gtk_get_event_widget (event);
10730 gtk_widget_event_internal (widget, event);
10732 gdk_event_free (event);
10736 * _gtk_widget_synthesize_crossing:
10737 * @from: the #GtkWidget the virtual pointer is leaving.
10738 * @to: the #GtkWidget the virtual pointer is moving to.
10739 * @mode: the #GdkCrossingMode to place on the synthesized events.
10741 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10743 * The real pointer window is the window that most recently received an enter notify
10744 * event. Windows that don't select for crossing events can't become the real
10745 * poiner window. The real pointer widget that owns the real pointer window. The
10746 * effective pointer window is the same as the real pointer window unless the real
10747 * pointer widget is either insensitive or there is a grab on a widget that is not
10748 * an ancestor of the real pointer widget (in which case the effective pointer
10749 * window should be the root window).
10751 * When the effective pointer window is the same as the real poiner window, we
10752 * receive crossing events from the windowing system. When the effective pointer
10753 * window changes to become different from the real pointer window we synthesize
10754 * crossing events, attempting to follow X protocol rules:
10756 * When the root window becomes the effective pointer window:
10757 * - leave notify on real pointer window, detail Ancestor
10758 * - leave notify on all of its ancestors, detail Virtual
10759 * - enter notify on root window, detail Inferior
10761 * When the root window ceases to be the effective pointer window:
10762 * - leave notify on root window, detail Inferior
10763 * - enter notify on all ancestors of real pointer window, detail Virtual
10764 * - enter notify on real pointer window, detail Ancestor
10767 _gtk_widget_synthesize_crossing (GtkWidget *from,
10770 GdkCrossingMode mode)
10772 GdkWindow *from_window = NULL, *to_window = NULL;
10774 g_return_if_fail (from != NULL || to != NULL);
10778 from_window = _gtk_widget_get_device_window (from, device);
10781 from_window = from->priv->window;
10786 to_window = _gtk_widget_get_device_window (to, device);
10789 to_window = to->priv->window;
10792 if (from_window == NULL && to_window == NULL)
10794 else if (from_window != NULL && to_window == NULL)
10796 GList *from_ancestors = NULL, *list;
10797 GdkWindow *from_ancestor = from_window;
10799 while (from_ancestor != NULL)
10801 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10802 if (from_ancestor == NULL)
10804 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10807 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10808 device, mode, GDK_NOTIFY_ANCESTOR);
10809 for (list = g_list_last (from_ancestors); list; list = list->prev)
10811 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10812 device, mode, GDK_NOTIFY_VIRTUAL);
10815 /* XXX: enter/inferior on root window? */
10817 g_list_free (from_ancestors);
10819 else if (from_window == NULL && to_window != NULL)
10821 GList *to_ancestors = NULL, *list;
10822 GdkWindow *to_ancestor = to_window;
10824 while (to_ancestor != NULL)
10826 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10827 if (to_ancestor == NULL)
10829 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10832 /* XXX: leave/inferior on root window? */
10834 for (list = to_ancestors; list; list = list->next)
10836 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10837 device, mode, GDK_NOTIFY_VIRTUAL);
10839 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10840 device, mode, GDK_NOTIFY_ANCESTOR);
10842 g_list_free (to_ancestors);
10844 else if (from_window == to_window)
10848 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10849 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10851 while (from_ancestor != NULL || to_ancestor != NULL)
10853 if (from_ancestor != NULL)
10855 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10856 if (from_ancestor == to_window)
10859 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10861 if (to_ancestor != NULL)
10863 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10864 if (to_ancestor == from_window)
10867 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10870 if (to_ancestor == from_window)
10872 if (mode != GDK_CROSSING_GTK_UNGRAB)
10873 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10874 device, mode, GDK_NOTIFY_INFERIOR);
10875 for (list = to_ancestors; list; list = list->next)
10876 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10877 device, mode, GDK_NOTIFY_VIRTUAL);
10878 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10879 device, mode, GDK_NOTIFY_ANCESTOR);
10881 else if (from_ancestor == to_window)
10883 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10884 device, mode, GDK_NOTIFY_ANCESTOR);
10885 for (list = g_list_last (from_ancestors); list; list = list->prev)
10887 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10888 device, mode, GDK_NOTIFY_VIRTUAL);
10890 if (mode != GDK_CROSSING_GTK_GRAB)
10891 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10892 device, mode, GDK_NOTIFY_INFERIOR);
10896 while (from_ancestors != NULL && to_ancestors != NULL
10897 && from_ancestors->data == to_ancestors->data)
10899 from_ancestors = g_list_delete_link (from_ancestors,
10901 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10904 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10905 device, mode, GDK_NOTIFY_NONLINEAR);
10907 for (list = g_list_last (from_ancestors); list; list = list->prev)
10909 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10910 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10912 for (list = to_ancestors; list; list = list->next)
10914 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10915 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10917 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10918 device, mode, GDK_NOTIFY_NONLINEAR);
10920 g_list_free (from_ancestors);
10921 g_list_free (to_ancestors);
10926 gtk_widget_propagate_state (GtkWidget *widget,
10927 GtkStateData *data)
10929 GtkWidgetPrivate *priv = widget->priv;
10930 GtkStateFlags new_flags, old_flags = priv->state_flags;
10931 GtkStateType old_state;
10933 old_state = gtk_widget_get_state (widget);
10935 priv->state_flags |= data->flags_to_set;
10936 priv->state_flags &= ~(data->flags_to_unset);
10938 /* make insensitivity unoverridable */
10939 if (!priv->sensitive)
10940 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10942 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10946 window = gtk_widget_get_toplevel (widget);
10948 if (window && gtk_widget_is_toplevel (window))
10949 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10952 new_flags = priv->state_flags;
10954 if (old_flags != new_flags)
10956 g_object_ref (widget);
10958 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10959 gtk_grab_remove (widget);
10961 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10963 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10964 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10966 if (!priv->shadowed &&
10967 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10969 GList *event_windows = NULL;
10970 GList *devices, *d;
10972 devices = _gtk_widget_list_devices (widget);
10974 for (d = devices; d; d = d->next)
10980 window = _gtk_widget_get_device_window (widget, device);
10982 /* Do not propagate more than once to the
10983 * same window if non-multidevice aware.
10985 if (!gdk_window_get_support_multidevice (window) &&
10986 g_list_find (event_windows, window))
10989 if (!gtk_widget_is_sensitive (widget))
10990 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10991 GDK_CROSSING_STATE_CHANGED);
10993 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10994 GDK_CROSSING_STATE_CHANGED);
10996 event_windows = g_list_prepend (event_windows, window);
10999 g_list_free (event_windows);
11000 g_list_free (devices);
11003 if (GTK_IS_CONTAINER (widget))
11005 GtkStateData child_data;
11007 /* Make sure to only propate the right states further */
11008 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11009 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11011 gtk_container_forall (GTK_CONTAINER (widget),
11012 (GtkCallback) gtk_widget_propagate_state,
11016 g_object_unref (widget);
11020 static const GtkWidgetAuxInfo default_aux_info = {
11028 * gtk_widget_get_aux_info:
11029 * @widget: a #GtkWidget
11030 * @create: if %TRUE, create the structure if it doesn't exist
11032 * Get the #GtkWidgetAuxInfo structure for the widget.
11034 * Return value: the #GtkAuxInfo structure for the widget, or
11035 * %NULL if @create is %FALSE and one doesn't already exist.
11037 static GtkWidgetAuxInfo *
11038 gtk_widget_get_aux_info (GtkWidget *widget,
11041 GtkWidgetAuxInfo *aux_info;
11043 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11044 if (!aux_info && create)
11046 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11048 *aux_info = default_aux_info;
11050 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11056 static const GtkWidgetAuxInfo*
11057 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11059 GtkWidgetAuxInfo *aux_info;
11061 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11062 if (aux_info == NULL)
11064 return &default_aux_info;
11072 /*****************************************
11073 * gtk_widget_aux_info_destroy:
11078 *****************************************/
11081 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11083 g_slice_free (GtkWidgetAuxInfo, aux_info);
11087 * gtk_widget_shape_combine_region:
11088 * @widget: a #GtkWidget
11089 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11091 * Sets a shape for this widget's GDK window. This allows for
11092 * transparent windows etc., see gdk_window_shape_combine_region()
11093 * for more information.
11098 gtk_widget_shape_combine_region (GtkWidget *widget,
11099 cairo_region_t *region)
11101 GtkWidgetPrivate *priv;
11103 g_return_if_fail (GTK_IS_WIDGET (widget));
11104 /* set_shape doesn't work on widgets without gdk window */
11105 g_return_if_fail (gtk_widget_get_has_window (widget));
11107 priv = widget->priv;
11109 if (region == NULL)
11111 priv->has_shape_mask = FALSE;
11114 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11116 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11120 priv->has_shape_mask = TRUE;
11122 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11123 cairo_region_copy (region),
11124 (GDestroyNotify) cairo_region_destroy);
11126 /* set shape if widget has a gdk window already.
11127 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11130 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11135 * gtk_widget_input_shape_combine_region:
11136 * @widget: a #GtkWidget
11137 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11139 * Sets an input shape for this widget's GDK window. This allows for
11140 * windows which react to mouse click in a nonrectangular region, see
11141 * gdk_window_input_shape_combine_region() for more information.
11146 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11147 cairo_region_t *region)
11149 GtkWidgetPrivate *priv;
11151 g_return_if_fail (GTK_IS_WIDGET (widget));
11152 /* set_shape doesn't work on widgets without gdk window */
11153 g_return_if_fail (gtk_widget_get_has_window (widget));
11155 priv = widget->priv;
11157 if (region == NULL)
11160 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11162 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11166 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11167 cairo_region_copy (region),
11168 (GDestroyNotify) cairo_region_destroy);
11170 /* set shape if widget has a gdk window already.
11171 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11174 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11179 /* style properties
11183 * gtk_widget_class_install_style_property_parser: (skip)
11184 * @klass: a #GtkWidgetClass
11185 * @pspec: the #GParamSpec for the style property
11186 * @parser: the parser for the style property
11188 * Installs a style property on a widget class.
11191 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11193 GtkRcPropertyParser parser)
11195 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11196 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11197 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11198 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11200 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11202 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11203 G_OBJECT_CLASS_NAME (klass),
11208 g_param_spec_ref_sink (pspec);
11209 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11210 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11214 * gtk_widget_class_install_style_property:
11215 * @klass: a #GtkWidgetClass
11216 * @pspec: the #GParamSpec for the property
11218 * Installs a style property on a widget class. The parser for the
11219 * style property is determined by the value type of @pspec.
11222 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11225 GtkRcPropertyParser parser;
11227 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11228 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11230 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11232 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11236 * gtk_widget_class_find_style_property:
11237 * @klass: a #GtkWidgetClass
11238 * @property_name: the name of the style property to find
11240 * Finds a style property of a widget class by name.
11242 * Returns: (transfer none): the #GParamSpec of the style property or
11243 * %NULL if @class has no style property with that name.
11248 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11249 const gchar *property_name)
11251 g_return_val_if_fail (property_name != NULL, NULL);
11253 return g_param_spec_pool_lookup (style_property_spec_pool,
11255 G_OBJECT_CLASS_TYPE (klass),
11260 * gtk_widget_class_list_style_properties:
11261 * @klass: a #GtkWidgetClass
11262 * @n_properties: location to return the number of style properties found
11264 * Returns all style properties of a widget class.
11266 * Returns: (array length=n_properties) (transfer container): a
11267 * newly allocated array of #GParamSpec*. The array must be
11268 * freed with g_free().
11273 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11274 guint *n_properties)
11276 GParamSpec **pspecs;
11279 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11280 G_OBJECT_CLASS_TYPE (klass),
11289 * gtk_widget_style_get_property:
11290 * @widget: a #GtkWidget
11291 * @property_name: the name of a style property
11292 * @value: location to return the property value
11294 * Gets the value of a style property of @widget.
11297 gtk_widget_style_get_property (GtkWidget *widget,
11298 const gchar *property_name,
11303 g_return_if_fail (GTK_IS_WIDGET (widget));
11304 g_return_if_fail (property_name != NULL);
11305 g_return_if_fail (G_IS_VALUE (value));
11307 g_object_ref (widget);
11308 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11310 G_OBJECT_TYPE (widget),
11313 g_warning ("%s: widget class `%s' has no property named `%s'",
11315 G_OBJECT_TYPE_NAME (widget),
11319 GtkStyleContext *context;
11320 const GValue *peek_value;
11321 GtkStateFlags state;
11323 context = gtk_widget_get_style_context (widget);
11324 state = gtk_widget_get_state_flags (widget);
11326 peek_value = _gtk_style_context_peek_style_property (context,
11327 G_OBJECT_TYPE (widget),
11330 /* auto-conversion of the caller's value type
11332 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11333 g_value_copy (peek_value, value);
11334 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11335 g_value_transform (peek_value, value);
11337 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11339 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11340 G_VALUE_TYPE_NAME (value));
11342 g_object_unref (widget);
11346 * gtk_widget_style_get_valist:
11347 * @widget: a #GtkWidget
11348 * @first_property_name: the name of the first property to get
11349 * @var_args: a <type>va_list</type> of pairs of property names and
11350 * locations to return the property values, starting with the location
11351 * for @first_property_name.
11353 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11357 gtk_widget_style_get_valist (GtkWidget *widget,
11358 const gchar *first_property_name,
11361 GtkStyleContext *context;
11362 GtkStateFlags state;
11365 g_return_if_fail (GTK_IS_WIDGET (widget));
11367 g_object_ref (widget);
11368 context = gtk_widget_get_style_context (widget);
11369 state = gtk_widget_get_state_flags (widget);
11371 name = first_property_name;
11374 const GValue *peek_value;
11378 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11380 G_OBJECT_TYPE (widget),
11384 g_warning ("%s: widget class `%s' has no property named `%s'",
11386 G_OBJECT_TYPE_NAME (widget),
11390 /* style pspecs are always readable so we can spare that check here */
11392 peek_value = _gtk_style_context_peek_style_property (context,
11393 G_OBJECT_TYPE (widget),
11396 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11399 g_warning ("%s: %s", G_STRLOC, error);
11404 name = va_arg (var_args, gchar*);
11407 g_object_unref (widget);
11411 * gtk_widget_style_get:
11412 * @widget: a #GtkWidget
11413 * @first_property_name: the name of the first property to get
11414 * @...: pairs of property names and locations to return the
11415 * property values, starting with the location for
11416 * @first_property_name, terminated by %NULL.
11418 * Gets the values of a multiple style properties of @widget.
11421 gtk_widget_style_get (GtkWidget *widget,
11422 const gchar *first_property_name,
11427 g_return_if_fail (GTK_IS_WIDGET (widget));
11429 va_start (var_args, first_property_name);
11430 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11435 * gtk_requisition_new:
11437 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11439 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11440 * be freed with gtk_requisition_free().
11445 gtk_requisition_new (void)
11447 return g_slice_new0 (GtkRequisition);
11451 * gtk_requisition_copy:
11452 * @requisition: a #GtkRequisition
11454 * Copies a #GtkRequisition.
11456 * Returns: a copy of @requisition
11459 gtk_requisition_copy (const GtkRequisition *requisition)
11461 return g_slice_dup (GtkRequisition, requisition);
11465 * gtk_requisition_free:
11466 * @requisition: a #GtkRequisition
11468 * Frees a #GtkRequisition.
11471 gtk_requisition_free (GtkRequisition *requisition)
11473 g_slice_free (GtkRequisition, requisition);
11476 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11477 gtk_requisition_copy,
11478 gtk_requisition_free)
11481 * gtk_widget_class_set_accessible_type:
11482 * @widget_class: class to set the accessible type for
11483 * @type: The object type that implements the accessible for @widget_class
11485 * Sets the type to be used for creating accessibles for widgets of
11486 * @widget_class. The given @type must be a subtype of the type used for
11487 * accessibles of the parent class.
11489 * This function should only be called from class init functions of widgets.
11494 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11497 GtkWidgetClassPrivate *priv;
11499 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11500 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11502 priv = widget_class->priv;
11504 priv->accessible_type = type;
11505 /* reset this - honoring the type's role is better. */
11506 priv->accessible_role = ATK_ROLE_INVALID;
11510 * gtk_widget_class_set_accessible_role:
11511 * @widget_class: class to set the accessible role for
11512 * @role: The role to use for accessibles created for @widget_class
11514 * Sets the default #AtkRole to be set on accessibles created for
11515 * widgets of @widget_class. Accessibles may decide to not honor this
11516 * setting if their role reporting is more refined. Calls to
11517 * gtk_widget_class_set_accessible_type() will reset this value.
11519 * In cases where you want more fine-grained control over the role of
11520 * accessibles created for @widget_class, you should provide your own
11521 * accessible type and use gtk_widget_class_set_accessible_type()
11524 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11525 * and the accessible's default role will be used instead.
11527 * This function should only be called from class init functions of widgets.
11532 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11535 GtkWidgetClassPrivate *priv;
11537 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11539 priv = widget_class->priv;
11541 priv->accessible_role = role;
11545 * _gtk_widget_peek_accessible:
11546 * @widget: a #GtkWidget
11548 * Gets the accessible for @widget, if it has been created yet.
11549 * Otherwise, this function returns %NULL. If the @widget's implementation
11550 * does not use the default way to create accessibles, %NULL will always be
11553 * Returns: the accessible for @widget or %NULL if none has been
11557 _gtk_widget_peek_accessible (GtkWidget *widget)
11559 return g_object_get_qdata (G_OBJECT (widget),
11560 quark_accessible_object);
11564 * gtk_widget_get_accessible:
11565 * @widget: a #GtkWidget
11567 * Returns the accessible object that describes the widget to an
11568 * assistive technology.
11570 * If accessibility support is not available, this #AtkObject
11571 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11572 * implementation is available for the widget instance in question,
11573 * it will inherit an #AtkObject implementation from the first ancestor
11574 * class for which such an implementation is defined.
11576 * The documentation of the
11577 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11578 * library contains more information about accessible objects and their uses.
11580 * Returns: (transfer none): the #AtkObject associated with @widget
11583 gtk_widget_get_accessible (GtkWidget *widget)
11585 GtkWidgetClass *klass;
11587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11589 klass = GTK_WIDGET_GET_CLASS (widget);
11591 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11593 return klass->get_accessible (widget);
11597 gtk_widget_real_get_accessible (GtkWidget *widget)
11599 AtkObject* accessible;
11601 accessible = g_object_get_qdata (G_OBJECT (widget),
11602 quark_accessible_object);
11605 GtkWidgetClass *widget_class;
11606 GtkWidgetClassPrivate *priv;
11607 AtkObjectFactory *factory;
11608 AtkRegistry *default_registry;
11610 widget_class = GTK_WIDGET_GET_CLASS (widget);
11611 priv = widget_class->priv;
11613 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11615 default_registry = atk_get_default_registry ();
11616 factory = atk_registry_get_factory (default_registry,
11617 G_TYPE_FROM_INSTANCE (widget));
11619 atk_object_factory_create_accessible (factory,
11620 G_OBJECT (widget));
11622 if (priv->accessible_role != ATK_ROLE_INVALID)
11623 atk_object_set_role (accessible, priv->accessible_role);
11625 g_object_set_qdata (G_OBJECT (widget),
11626 quark_accessible_object,
11631 accessible = g_object_new (priv->accessible_type,
11634 if (priv->accessible_role != ATK_ROLE_INVALID)
11635 atk_object_set_role (accessible, priv->accessible_role);
11637 g_object_set_qdata (G_OBJECT (widget),
11638 quark_accessible_object,
11641 atk_object_initialize (accessible, widget);
11643 /* Set the role again, since we don't want a role set
11644 * in some parent initialize() function to override
11647 if (priv->accessible_role != ATK_ROLE_INVALID)
11648 atk_object_set_role (accessible, priv->accessible_role);
11655 * Initialize a AtkImplementorIface instance's virtual pointers as
11656 * appropriate to this implementor's class (GtkWidget).
11659 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11661 iface->ref_accessible = gtk_widget_ref_accessible;
11665 gtk_widget_ref_accessible (AtkImplementor *implementor)
11667 AtkObject *accessible;
11669 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11671 g_object_ref (accessible);
11676 * Expand flag management
11680 gtk_widget_update_computed_expand (GtkWidget *widget)
11682 GtkWidgetPrivate *priv;
11684 priv = widget->priv;
11686 if (priv->need_compute_expand)
11690 if (priv->hexpand_set)
11695 if (priv->vexpand_set)
11700 /* we don't need to use compute_expand if both expands are
11701 * forced by the app
11703 if (!(priv->hexpand_set && priv->vexpand_set))
11705 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11709 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11710 priv->hexpand_set ? &ignored : &h,
11711 priv->vexpand_set ? &ignored : &v);
11715 priv->need_compute_expand = FALSE;
11716 priv->computed_hexpand = h != FALSE;
11717 priv->computed_vexpand = v != FALSE;
11722 * gtk_widget_queue_compute_expand:
11723 * @widget: a #GtkWidget
11725 * Mark @widget as needing to recompute its expand flags. Call
11726 * this function when setting legacy expand child properties
11727 * on the child of a container.
11729 * See gtk_widget_compute_expand().
11732 gtk_widget_queue_compute_expand (GtkWidget *widget)
11735 gboolean changed_anything;
11737 if (widget->priv->need_compute_expand)
11740 changed_anything = FALSE;
11742 while (parent != NULL)
11744 if (!parent->priv->need_compute_expand)
11746 parent->priv->need_compute_expand = TRUE;
11747 changed_anything = TRUE;
11750 /* Note: if we had an invariant that "if a child needs to
11751 * compute expand, its parents also do" then we could stop going
11752 * up when we got to a parent that already needed to
11753 * compute. However, in general we compute expand lazily (as
11754 * soon as we see something in a subtree that is expand, we know
11755 * we're expanding) and so this invariant does not hold and we
11756 * have to always walk all the way up in case some ancestor
11757 * is not currently need_compute_expand.
11760 parent = parent->priv->parent;
11763 /* recomputing expand always requires
11764 * a relayout as well
11766 if (changed_anything)
11767 gtk_widget_queue_resize (widget);
11771 * gtk_widget_compute_expand:
11772 * @widget: the widget
11773 * @orientation: expand direction
11775 * Computes whether a container should give this widget extra space
11776 * when possible. Containers should check this, rather than
11777 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11779 * This function already checks whether the widget is visible, so
11780 * visibility does not need to be checked separately. Non-visible
11781 * widgets are not expanded.
11783 * The computed expand value uses either the expand setting explicitly
11784 * set on the widget itself, or, if none has been explicitly set,
11785 * the widget may expand if some of its children do.
11787 * Return value: whether widget tree rooted here should be expanded
11790 gtk_widget_compute_expand (GtkWidget *widget,
11791 GtkOrientation orientation)
11793 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11795 /* We never make a widget expand if not even showing. */
11796 if (!gtk_widget_get_visible (widget))
11799 gtk_widget_update_computed_expand (widget);
11801 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11803 return widget->priv->computed_hexpand;
11807 return widget->priv->computed_vexpand;
11812 gtk_widget_set_expand (GtkWidget *widget,
11813 GtkOrientation orientation,
11816 const char *expand_prop;
11817 const char *expand_set_prop;
11819 GtkWidgetPrivate *priv;
11821 g_return_if_fail (GTK_IS_WIDGET (widget));
11823 priv = widget->priv;
11825 expand = expand != FALSE;
11827 was_both = priv->hexpand && priv->vexpand;
11829 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11831 if (priv->hexpand_set &&
11832 priv->hexpand == expand)
11835 priv->hexpand_set = TRUE;
11836 priv->hexpand = expand;
11838 expand_prop = "hexpand";
11839 expand_set_prop = "hexpand-set";
11843 if (priv->vexpand_set &&
11844 priv->vexpand == expand)
11847 priv->vexpand_set = TRUE;
11848 priv->vexpand = expand;
11850 expand_prop = "vexpand";
11851 expand_set_prop = "vexpand-set";
11854 gtk_widget_queue_compute_expand (widget);
11856 g_object_freeze_notify (G_OBJECT (widget));
11857 g_object_notify (G_OBJECT (widget), expand_prop);
11858 g_object_notify (G_OBJECT (widget), expand_set_prop);
11859 if (was_both != (priv->hexpand && priv->vexpand))
11860 g_object_notify (G_OBJECT (widget), "expand");
11861 g_object_thaw_notify (G_OBJECT (widget));
11865 gtk_widget_set_expand_set (GtkWidget *widget,
11866 GtkOrientation orientation,
11869 GtkWidgetPrivate *priv;
11872 priv = widget->priv;
11874 set = set != FALSE;
11876 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11878 if (set == priv->hexpand_set)
11881 priv->hexpand_set = set;
11882 prop = "hexpand-set";
11886 if (set == priv->vexpand_set)
11889 priv->vexpand_set = set;
11890 prop = "vexpand-set";
11893 gtk_widget_queue_compute_expand (widget);
11895 g_object_notify (G_OBJECT (widget), prop);
11899 * gtk_widget_get_hexpand:
11900 * @widget: the widget
11902 * Gets whether the widget would like any available extra horizontal
11903 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11904 * generally receive the extra space. For example, a list or
11905 * scrollable area or document in your window would often be set to
11908 * Containers should use gtk_widget_compute_expand() rather than
11909 * this function, to see whether a widget, or any of its children,
11910 * has the expand flag set. If any child of a widget wants to
11911 * expand, the parent may ask to expand also.
11913 * This function only looks at the widget's own hexpand flag, rather
11914 * than computing whether the entire widget tree rooted at this widget
11917 * Return value: whether hexpand flag is set
11920 gtk_widget_get_hexpand (GtkWidget *widget)
11922 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11924 return widget->priv->hexpand;
11928 * gtk_widget_set_hexpand:
11929 * @widget: the widget
11930 * @expand: whether to expand
11932 * Sets whether the widget would like any available extra horizontal
11933 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11934 * generally receive the extra space. For example, a list or
11935 * scrollable area or document in your window would often be set to
11938 * Call this function to set the expand flag if you would like your
11939 * widget to become larger horizontally when the window has extra
11942 * By default, widgets automatically expand if any of their children
11943 * want to expand. (To see if a widget will automatically expand given
11944 * its current children and state, call gtk_widget_compute_expand(). A
11945 * container can decide how the expandability of children affects the
11946 * expansion of the container by overriding the compute_expand virtual
11947 * method on #GtkWidget.).
11949 * Setting hexpand explicitly with this function will override the
11950 * automatic expand behavior.
11952 * This function forces the widget to expand or not to expand,
11953 * regardless of children. The override occurs because
11954 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11955 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11956 * value to be used, rather than looking at children and widget state.
11959 gtk_widget_set_hexpand (GtkWidget *widget,
11962 g_return_if_fail (GTK_IS_WIDGET (widget));
11964 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11968 * gtk_widget_get_hexpand_set:
11969 * @widget: the widget
11971 * Gets whether gtk_widget_set_hexpand() has been used to
11972 * explicitly set the expand flag on this widget.
11974 * If hexpand is set, then it overrides any computed
11975 * expand value based on child widgets. If hexpand is not
11976 * set, then the expand value depends on whether any
11977 * children of the widget would like to expand.
11979 * There are few reasons to use this function, but it's here
11980 * for completeness and consistency.
11982 * Return value: whether hexpand has been explicitly set
11985 gtk_widget_get_hexpand_set (GtkWidget *widget)
11987 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11989 return widget->priv->hexpand_set;
11993 * gtk_widget_set_hexpand_set:
11994 * @widget: the widget
11995 * @set: value for hexpand-set property
11997 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12000 * The hexpand-set property will be set automatically when you call
12001 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12002 * reason to use this function would be to unset an explicit expand
12005 * If hexpand is set, then it overrides any computed
12006 * expand value based on child widgets. If hexpand is not
12007 * set, then the expand value depends on whether any
12008 * children of the widget would like to expand.
12010 * There are few reasons to use this function, but it's here
12011 * for completeness and consistency.
12014 gtk_widget_set_hexpand_set (GtkWidget *widget,
12017 g_return_if_fail (GTK_IS_WIDGET (widget));
12019 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12024 * gtk_widget_get_vexpand:
12025 * @widget: the widget
12027 * Gets whether the widget would like any available extra vertical
12030 * See gtk_widget_get_hexpand() for more detail.
12032 * Return value: whether vexpand flag is set
12035 gtk_widget_get_vexpand (GtkWidget *widget)
12037 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12039 return widget->priv->vexpand;
12043 * gtk_widget_set_vexpand:
12044 * @widget: the widget
12045 * @expand: whether to expand
12047 * Sets whether the widget would like any available extra vertical
12050 * See gtk_widget_set_hexpand() for more detail.
12053 gtk_widget_set_vexpand (GtkWidget *widget,
12056 g_return_if_fail (GTK_IS_WIDGET (widget));
12058 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12062 * gtk_widget_get_vexpand_set:
12063 * @widget: the widget
12065 * Gets whether gtk_widget_set_vexpand() has been used to
12066 * explicitly set the expand flag on this widget.
12068 * See gtk_widget_get_hexpand_set() for more detail.
12070 * Return value: whether vexpand has been explicitly set
12073 gtk_widget_get_vexpand_set (GtkWidget *widget)
12075 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12077 return widget->priv->vexpand_set;
12081 * gtk_widget_set_vexpand_set:
12082 * @widget: the widget
12083 * @set: value for vexpand-set property
12085 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12088 * See gtk_widget_set_hexpand_set() for more detail.
12091 gtk_widget_set_vexpand_set (GtkWidget *widget,
12094 g_return_if_fail (GTK_IS_WIDGET (widget));
12096 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12100 * GtkBuildable implementation
12102 static GQuark quark_builder_has_default = 0;
12103 static GQuark quark_builder_has_focus = 0;
12104 static GQuark quark_builder_atk_relations = 0;
12105 static GQuark quark_builder_set_name = 0;
12108 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12110 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12111 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12112 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12113 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12115 iface->set_name = gtk_widget_buildable_set_name;
12116 iface->get_name = gtk_widget_buildable_get_name;
12117 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12118 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12119 iface->parser_finished = gtk_widget_buildable_parser_finished;
12120 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12121 iface->custom_finished = gtk_widget_buildable_custom_finished;
12125 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12128 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12129 g_strdup (name), g_free);
12132 static const gchar *
12133 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12135 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12139 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12140 GtkBuilder *builder,
12141 const gchar *childname)
12143 if (strcmp (childname, "accessible") == 0)
12144 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12150 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12151 GtkBuilder *builder,
12153 const GValue *value)
12155 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12156 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12157 GINT_TO_POINTER (TRUE));
12158 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12159 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12160 GINT_TO_POINTER (TRUE));
12162 g_object_set_property (G_OBJECT (buildable), name, value);
12167 gchar *action_name;
12168 GString *description;
12170 gboolean translatable;
12180 free_action (AtkActionData *data, gpointer user_data)
12182 g_free (data->action_name);
12183 g_string_free (data->description, TRUE);
12184 g_free (data->context);
12185 g_slice_free (AtkActionData, data);
12189 free_relation (AtkRelationData *data, gpointer user_data)
12191 g_free (data->target);
12192 g_free (data->type);
12193 g_slice_free (AtkRelationData, data);
12197 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12198 GtkBuilder *builder)
12200 GSList *atk_relations;
12202 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12203 gtk_widget_grab_default (GTK_WIDGET (buildable));
12204 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12205 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12207 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12208 quark_builder_atk_relations);
12211 AtkObject *accessible;
12212 AtkRelationSet *relation_set;
12215 AtkRelationType relation_type;
12216 AtkObject *target_accessible;
12218 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12219 relation_set = atk_object_ref_relation_set (accessible);
12221 for (l = atk_relations; l; l = l->next)
12223 AtkRelationData *relation = (AtkRelationData*)l->data;
12225 target = gtk_builder_get_object (builder, relation->target);
12228 g_warning ("Target object %s in <relation> does not exist",
12232 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12233 g_assert (target_accessible != NULL);
12235 relation_type = atk_relation_type_for_name (relation->type);
12236 if (relation_type == ATK_RELATION_NULL)
12238 g_warning ("<relation> type %s not found",
12242 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12243 target_accessible);
12245 g_object_unref (relation_set);
12247 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12248 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12257 } AccessibilitySubParserData;
12260 accessibility_start_element (GMarkupParseContext *context,
12261 const gchar *element_name,
12262 const gchar **names,
12263 const gchar **values,
12264 gpointer user_data,
12267 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12269 gint line_number, char_number;
12271 if (strcmp (element_name, "relation") == 0)
12273 gchar *target = NULL;
12274 gchar *type = NULL;
12275 AtkRelationData *relation;
12277 for (i = 0; names[i]; i++)
12279 if (strcmp (names[i], "target") == 0)
12280 target = g_strdup (values[i]);
12281 else if (strcmp (names[i], "type") == 0)
12282 type = g_strdup (values[i]);
12285 g_markup_parse_context_get_position (context,
12288 g_set_error (error,
12290 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12291 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12293 line_number, char_number, names[i], "relation");
12300 if (!target || !type)
12302 g_markup_parse_context_get_position (context,
12305 g_set_error (error,
12307 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12308 "%s:%d:%d <%s> requires attribute \"%s\"",
12310 line_number, char_number, "relation",
12311 type ? "target" : "type");
12317 relation = g_slice_new (AtkRelationData);
12318 relation->target = target;
12319 relation->type = type;
12321 data->relations = g_slist_prepend (data->relations, relation);
12323 else if (strcmp (element_name, "action") == 0)
12325 const gchar *action_name = NULL;
12326 const gchar *description = NULL;
12327 const gchar *msg_context = NULL;
12328 gboolean translatable = FALSE;
12329 AtkActionData *action;
12331 for (i = 0; names[i]; i++)
12333 if (strcmp (names[i], "action_name") == 0)
12334 action_name = values[i];
12335 else if (strcmp (names[i], "description") == 0)
12336 description = values[i];
12337 else if (strcmp (names[i], "translatable") == 0)
12339 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12342 else if (strcmp (names[i], "comments") == 0)
12344 /* do nothing, comments are for translators */
12346 else if (strcmp (names[i], "context") == 0)
12347 msg_context = values[i];
12350 g_markup_parse_context_get_position (context,
12353 g_set_error (error,
12355 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12356 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12358 line_number, char_number, names[i], "action");
12365 g_markup_parse_context_get_position (context,
12368 g_set_error (error,
12370 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12371 "%s:%d:%d <%s> requires attribute \"%s\"",
12373 line_number, char_number, "action",
12378 action = g_slice_new (AtkActionData);
12379 action->action_name = g_strdup (action_name);
12380 action->description = g_string_new (description);
12381 action->context = g_strdup (msg_context);
12382 action->translatable = translatable;
12384 data->actions = g_slist_prepend (data->actions, action);
12386 else if (strcmp (element_name, "accessibility") == 0)
12389 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12393 accessibility_text (GMarkupParseContext *context,
12396 gpointer user_data,
12399 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12401 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12403 AtkActionData *action = data->actions->data;
12405 g_string_append_len (action->description, text, text_len);
12409 static const GMarkupParser accessibility_parser =
12411 accessibility_start_element,
12413 accessibility_text,
12422 } AccelGroupParserData;
12425 accel_group_start_element (GMarkupParseContext *context,
12426 const gchar *element_name,
12427 const gchar **names,
12428 const gchar **values,
12429 gpointer user_data,
12434 guint modifiers = 0;
12435 gchar *signal = NULL;
12436 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12438 for (i = 0; names[i]; i++)
12440 if (strcmp (names[i], "key") == 0)
12441 key = gdk_keyval_from_name (values[i]);
12442 else if (strcmp (names[i], "modifiers") == 0)
12444 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12450 else if (strcmp (names[i], "signal") == 0)
12451 signal = g_strdup (values[i]);
12454 if (key == 0 || signal == NULL)
12456 g_warning ("<accelerator> requires key and signal attributes");
12459 parser_data->key = key;
12460 parser_data->modifiers = modifiers;
12461 parser_data->signal = signal;
12464 static const GMarkupParser accel_group_parser =
12466 accel_group_start_element,
12475 style_start_element (GMarkupParseContext *context,
12476 const gchar *element_name,
12477 const gchar **names,
12478 const gchar **values,
12479 gpointer user_data,
12482 StyleParserData *style_data = (StyleParserData *)user_data;
12485 if (strcmp (element_name, "class") == 0)
12487 if (g_markup_collect_attributes (element_name,
12491 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12492 G_MARKUP_COLLECT_INVALID))
12494 style_data->classes = g_slist_append (style_data->classes, class_name);
12497 else if (strcmp (element_name, "style") == 0)
12500 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12503 static const GMarkupParser style_parser =
12505 style_start_element,
12509 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12510 GtkBuilder *builder,
12512 const gchar *tagname,
12513 GMarkupParser *parser,
12516 g_assert (buildable);
12518 if (strcmp (tagname, "accelerator") == 0)
12520 AccelGroupParserData *parser_data;
12522 parser_data = g_slice_new0 (AccelGroupParserData);
12523 parser_data->object = g_object_ref (buildable);
12524 *parser = accel_group_parser;
12525 *data = parser_data;
12528 if (strcmp (tagname, "accessibility") == 0)
12530 AccessibilitySubParserData *parser_data;
12532 parser_data = g_slice_new0 (AccessibilitySubParserData);
12533 *parser = accessibility_parser;
12534 *data = parser_data;
12537 if (strcmp (tagname, "style") == 0)
12539 StyleParserData *parser_data;
12541 parser_data = g_slice_new0 (StyleParserData);
12542 *parser = style_parser;
12543 *data = parser_data;
12551 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12552 GtkWidget *toplevel,
12553 gpointer user_data)
12555 AccelGroupParserData *accel_data;
12556 GSList *accel_groups;
12557 GtkAccelGroup *accel_group;
12559 g_return_if_fail (GTK_IS_WIDGET (widget));
12560 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12561 g_return_if_fail (user_data != NULL);
12563 accel_data = (AccelGroupParserData*)user_data;
12564 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12565 if (g_slist_length (accel_groups) == 0)
12567 accel_group = gtk_accel_group_new ();
12568 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12572 g_assert (g_slist_length (accel_groups) == 1);
12573 accel_group = g_slist_nth_data (accel_groups, 0);
12576 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12577 accel_data->signal,
12580 accel_data->modifiers,
12581 GTK_ACCEL_VISIBLE);
12583 g_object_unref (accel_data->object);
12584 g_free (accel_data->signal);
12585 g_slice_free (AccelGroupParserData, accel_data);
12589 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12590 GtkBuilder *builder,
12592 const gchar *tagname,
12593 gpointer user_data)
12595 if (strcmp (tagname, "accelerator") == 0)
12597 AccelGroupParserData *accel_data;
12598 GtkWidget *toplevel;
12600 accel_data = (AccelGroupParserData*)user_data;
12601 g_assert (accel_data->object);
12603 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12605 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12607 else if (strcmp (tagname, "accessibility") == 0)
12609 AccessibilitySubParserData *a11y_data;
12611 a11y_data = (AccessibilitySubParserData*)user_data;
12613 if (a11y_data->actions)
12615 AtkObject *accessible;
12620 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12622 if (ATK_IS_ACTION (accessible))
12624 action = ATK_ACTION (accessible);
12625 n_actions = atk_action_get_n_actions (action);
12627 for (l = a11y_data->actions; l; l = l->next)
12629 AtkActionData *action_data = (AtkActionData*)l->data;
12631 for (i = 0; i < n_actions; i++)
12632 if (strcmp (atk_action_get_name (action, i),
12633 action_data->action_name) == 0)
12638 gchar *description;
12640 if (action_data->translatable && action_data->description->len)
12641 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12642 action_data->context,
12643 action_data->description->str);
12645 description = action_data->description->str;
12647 atk_action_set_description (action, i, description);
12652 g_warning ("accessibility action on a widget that does not implement AtkAction");
12654 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12657 if (a11y_data->relations)
12658 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12659 a11y_data->relations);
12661 g_slice_free (AccessibilitySubParserData, a11y_data);
12663 else if (strcmp (tagname, "style") == 0)
12665 StyleParserData *style_data = (StyleParserData *)user_data;
12666 GtkStyleContext *context;
12669 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12671 for (l = style_data->classes; l; l = l->next)
12672 gtk_style_context_add_class (context, (const gchar *)l->data);
12674 gtk_widget_reset_style (GTK_WIDGET (buildable));
12676 g_slist_free_full (style_data->classes, g_free);
12677 g_slice_free (StyleParserData, style_data);
12681 static GtkSizeRequestMode
12682 gtk_widget_real_get_request_mode (GtkWidget *widget)
12684 /* By default widgets dont trade size at all. */
12685 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12689 gtk_widget_real_get_width (GtkWidget *widget,
12690 gint *minimum_size,
12691 gint *natural_size)
12701 gtk_widget_real_get_height (GtkWidget *widget,
12702 gint *minimum_size,
12703 gint *natural_size)
12713 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12715 gint *minimum_height,
12716 gint *natural_height)
12718 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12722 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12724 gint *minimum_width,
12725 gint *natural_width)
12727 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12731 * gtk_widget_get_halign:
12732 * @widget: a #GtkWidget
12734 * Gets the value of the #GtkWidget:halign property.
12736 * Returns: the horizontal alignment of @widget
12739 gtk_widget_get_halign (GtkWidget *widget)
12741 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12742 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12746 * gtk_widget_set_halign:
12747 * @widget: a #GtkWidget
12748 * @align: the horizontal alignment
12750 * Sets the horizontal alignment of @widget.
12751 * See the #GtkWidget:halign property.
12754 gtk_widget_set_halign (GtkWidget *widget,
12757 GtkWidgetAuxInfo *aux_info;
12759 g_return_if_fail (GTK_IS_WIDGET (widget));
12761 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12763 if (aux_info->halign == align)
12766 aux_info->halign = align;
12767 gtk_widget_queue_resize (widget);
12768 g_object_notify (G_OBJECT (widget), "halign");
12772 * gtk_widget_get_valign:
12773 * @widget: a #GtkWidget
12775 * Gets the value of the #GtkWidget:valign property.
12777 * Returns: the vertical alignment of @widget
12780 gtk_widget_get_valign (GtkWidget *widget)
12782 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12783 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12787 * gtk_widget_set_valign:
12788 * @widget: a #GtkWidget
12789 * @align: the vertical alignment
12791 * Sets the vertical alignment of @widget.
12792 * See the #GtkWidget:valign property.
12795 gtk_widget_set_valign (GtkWidget *widget,
12798 GtkWidgetAuxInfo *aux_info;
12800 g_return_if_fail (GTK_IS_WIDGET (widget));
12802 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12804 if (aux_info->valign == align)
12807 aux_info->valign = align;
12808 gtk_widget_queue_resize (widget);
12809 g_object_notify (G_OBJECT (widget), "valign");
12813 * gtk_widget_get_margin_left:
12814 * @widget: a #GtkWidget
12816 * Gets the value of the #GtkWidget:margin-left property.
12818 * Returns: The left margin of @widget
12823 gtk_widget_get_margin_left (GtkWidget *widget)
12825 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12827 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12831 * gtk_widget_set_margin_left:
12832 * @widget: a #GtkWidget
12833 * @margin: the left margin
12835 * Sets the left margin of @widget.
12836 * See the #GtkWidget:margin-left property.
12841 gtk_widget_set_margin_left (GtkWidget *widget,
12844 GtkWidgetAuxInfo *aux_info;
12846 g_return_if_fail (GTK_IS_WIDGET (widget));
12847 g_return_if_fail (margin <= G_MAXINT16);
12849 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12851 if (aux_info->margin.left == margin)
12854 aux_info->margin.left = margin;
12855 gtk_widget_queue_resize (widget);
12856 g_object_notify (G_OBJECT (widget), "margin-left");
12860 * gtk_widget_get_margin_right:
12861 * @widget: a #GtkWidget
12863 * Gets the value of the #GtkWidget:margin-right property.
12865 * Returns: The right margin of @widget
12870 gtk_widget_get_margin_right (GtkWidget *widget)
12872 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12874 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12878 * gtk_widget_set_margin_right:
12879 * @widget: a #GtkWidget
12880 * @margin: the right margin
12882 * Sets the right margin of @widget.
12883 * See the #GtkWidget:margin-right property.
12888 gtk_widget_set_margin_right (GtkWidget *widget,
12891 GtkWidgetAuxInfo *aux_info;
12893 g_return_if_fail (GTK_IS_WIDGET (widget));
12894 g_return_if_fail (margin <= G_MAXINT16);
12896 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12898 if (aux_info->margin.right == margin)
12901 aux_info->margin.right = margin;
12902 gtk_widget_queue_resize (widget);
12903 g_object_notify (G_OBJECT (widget), "margin-right");
12907 * gtk_widget_get_margin_top:
12908 * @widget: a #GtkWidget
12910 * Gets the value of the #GtkWidget:margin-top property.
12912 * Returns: The top margin of @widget
12917 gtk_widget_get_margin_top (GtkWidget *widget)
12919 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12921 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12925 * gtk_widget_set_margin_top:
12926 * @widget: a #GtkWidget
12927 * @margin: the top margin
12929 * Sets the top margin of @widget.
12930 * See the #GtkWidget:margin-top property.
12935 gtk_widget_set_margin_top (GtkWidget *widget,
12938 GtkWidgetAuxInfo *aux_info;
12940 g_return_if_fail (GTK_IS_WIDGET (widget));
12941 g_return_if_fail (margin <= G_MAXINT16);
12943 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12945 if (aux_info->margin.top == margin)
12948 aux_info->margin.top = margin;
12949 gtk_widget_queue_resize (widget);
12950 g_object_notify (G_OBJECT (widget), "margin-top");
12954 * gtk_widget_get_margin_bottom:
12955 * @widget: a #GtkWidget
12957 * Gets the value of the #GtkWidget:margin-bottom property.
12959 * Returns: The bottom margin of @widget
12964 gtk_widget_get_margin_bottom (GtkWidget *widget)
12966 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12968 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12972 * gtk_widget_set_margin_bottom:
12973 * @widget: a #GtkWidget
12974 * @margin: the bottom margin
12976 * Sets the bottom margin of @widget.
12977 * See the #GtkWidget:margin-bottom property.
12982 gtk_widget_set_margin_bottom (GtkWidget *widget,
12985 GtkWidgetAuxInfo *aux_info;
12987 g_return_if_fail (GTK_IS_WIDGET (widget));
12988 g_return_if_fail (margin <= G_MAXINT16);
12990 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12992 if (aux_info->margin.bottom == margin)
12995 aux_info->margin.bottom = margin;
12996 gtk_widget_queue_resize (widget);
12997 g_object_notify (G_OBJECT (widget), "margin-bottom");
13001 * gtk_widget_get_clipboard:
13002 * @widget: a #GtkWidget
13003 * @selection: a #GdkAtom which identifies the clipboard
13004 * to use. %GDK_SELECTION_CLIPBOARD gives the
13005 * default clipboard. Another common value
13006 * is %GDK_SELECTION_PRIMARY, which gives
13007 * the primary X selection.
13009 * Returns the clipboard object for the given selection to
13010 * be used with @widget. @widget must have a #GdkDisplay
13011 * associated with it, so must be attached to a toplevel
13014 * Return value: (transfer none): the appropriate clipboard object. If no
13015 * clipboard already exists, a new one will
13016 * be created. Once a clipboard object has
13017 * been created, it is persistent for all time.
13022 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13024 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13025 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13027 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13032 * gtk_widget_list_mnemonic_labels:
13033 * @widget: a #GtkWidget
13035 * Returns a newly allocated list of the widgets, normally labels, for
13036 * which this widget is the target of a mnemonic (see for example,
13037 * gtk_label_set_mnemonic_widget()).
13039 * The widgets in the list are not individually referenced. If you
13040 * want to iterate through the list and perform actions involving
13041 * callbacks that might destroy the widgets, you
13042 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13043 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13044 * widgets afterwards.
13046 * Return value: (element-type GtkWidget) (transfer container): the list of
13047 * mnemonic labels; free this list
13048 * with g_list_free() when you are done with it.
13053 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13055 GList *list = NULL;
13058 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13060 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13061 list = g_list_prepend (list, l->data);
13067 * gtk_widget_add_mnemonic_label:
13068 * @widget: a #GtkWidget
13069 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13071 * Adds a widget to the list of mnemonic labels for
13072 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13073 * list of mnemonic labels for the widget is cleared when the
13074 * widget is destroyed, so the caller must make sure to update
13075 * its internal state at this point as well, by using a connection
13076 * to the #GtkWidget::destroy signal or a weak notifier.
13081 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13084 GSList *old_list, *new_list;
13086 g_return_if_fail (GTK_IS_WIDGET (widget));
13087 g_return_if_fail (GTK_IS_WIDGET (label));
13089 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13090 new_list = g_slist_prepend (old_list, label);
13092 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13093 new_list, (GDestroyNotify) g_slist_free);
13097 * gtk_widget_remove_mnemonic_label:
13098 * @widget: a #GtkWidget
13099 * @label: a #GtkWidget that was previously set as a mnemnic label for
13100 * @widget with gtk_widget_add_mnemonic_label().
13102 * Removes a widget from the list of mnemonic labels for
13103 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13104 * must have previously been added to the list with
13105 * gtk_widget_add_mnemonic_label().
13110 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13113 GSList *old_list, *new_list;
13115 g_return_if_fail (GTK_IS_WIDGET (widget));
13116 g_return_if_fail (GTK_IS_WIDGET (label));
13118 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13119 new_list = g_slist_remove (old_list, label);
13122 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13123 new_list, (GDestroyNotify) g_slist_free);
13127 * gtk_widget_get_no_show_all:
13128 * @widget: a #GtkWidget
13130 * Returns the current value of the #GtkWidget:no-show-all property,
13131 * which determines whether calls to gtk_widget_show_all()
13132 * will affect this widget.
13134 * Return value: the current value of the "no-show-all" property.
13139 gtk_widget_get_no_show_all (GtkWidget *widget)
13141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13143 return widget->priv->no_show_all;
13147 * gtk_widget_set_no_show_all:
13148 * @widget: a #GtkWidget
13149 * @no_show_all: the new value for the "no-show-all" property
13151 * Sets the #GtkWidget:no-show-all property, which determines whether
13152 * calls to gtk_widget_show_all() will affect this widget.
13154 * This is mostly for use in constructing widget hierarchies with externally
13155 * controlled visibility, see #GtkUIManager.
13160 gtk_widget_set_no_show_all (GtkWidget *widget,
13161 gboolean no_show_all)
13163 g_return_if_fail (GTK_IS_WIDGET (widget));
13165 no_show_all = (no_show_all != FALSE);
13167 if (widget->priv->no_show_all != no_show_all)
13169 widget->priv->no_show_all = no_show_all;
13171 g_object_notify (G_OBJECT (widget), "no-show-all");
13177 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13178 gboolean has_tooltip,
13181 GtkWidgetPrivate *priv = widget->priv;
13182 gboolean priv_has_tooltip;
13184 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13185 quark_has_tooltip));
13187 if (priv_has_tooltip != has_tooltip || force)
13189 priv_has_tooltip = has_tooltip;
13191 if (priv_has_tooltip)
13193 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13194 gdk_window_set_events (priv->window,
13195 gdk_window_get_events (priv->window) |
13196 GDK_LEAVE_NOTIFY_MASK |
13197 GDK_POINTER_MOTION_MASK |
13198 GDK_POINTER_MOTION_HINT_MASK);
13200 if (gtk_widget_get_has_window (widget))
13201 gtk_widget_add_events (widget,
13202 GDK_LEAVE_NOTIFY_MASK |
13203 GDK_POINTER_MOTION_MASK |
13204 GDK_POINTER_MOTION_HINT_MASK);
13207 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13208 GUINT_TO_POINTER (priv_has_tooltip));
13213 * gtk_widget_set_tooltip_window:
13214 * @widget: a #GtkWidget
13215 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13217 * Replaces the default, usually yellow, window used for displaying
13218 * tooltips with @custom_window. GTK+ will take care of showing and
13219 * hiding @custom_window at the right moment, to behave likewise as
13220 * the default tooltip window. If @custom_window is %NULL, the default
13221 * tooltip window will be used.
13223 * If the custom window should have the default theming it needs to
13224 * have the name "gtk-tooltip", see gtk_widget_set_name().
13229 gtk_widget_set_tooltip_window (GtkWidget *widget,
13230 GtkWindow *custom_window)
13232 gboolean has_tooltip;
13233 gchar *tooltip_markup;
13235 g_return_if_fail (GTK_IS_WIDGET (widget));
13236 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13238 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13241 g_object_ref (custom_window);
13243 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13244 custom_window, g_object_unref);
13246 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13247 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13249 if (has_tooltip && gtk_widget_get_visible (widget))
13250 gtk_widget_queue_tooltip_query (widget);
13254 * gtk_widget_get_tooltip_window:
13255 * @widget: a #GtkWidget
13257 * Returns the #GtkWindow of the current tooltip. This can be the
13258 * GtkWindow created by default, or the custom tooltip window set
13259 * using gtk_widget_set_tooltip_window().
13261 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13266 gtk_widget_get_tooltip_window (GtkWidget *widget)
13268 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13270 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13274 * gtk_widget_trigger_tooltip_query:
13275 * @widget: a #GtkWidget
13277 * Triggers a tooltip query on the display where the toplevel of @widget
13278 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13284 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13286 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13289 static guint tooltip_query_id;
13290 static GSList *tooltip_query_displays;
13293 tooltip_query_idle (gpointer data)
13295 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13296 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13297 g_slist_free (tooltip_query_displays);
13299 tooltip_query_displays = NULL;
13300 tooltip_query_id = 0;
13306 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13308 GdkDisplay *display;
13310 display = gtk_widget_get_display (widget);
13312 if (!g_slist_find (tooltip_query_displays, display))
13313 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13315 if (tooltip_query_id == 0)
13316 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13320 * gtk_widget_set_tooltip_text:
13321 * @widget: a #GtkWidget
13322 * @text: the contents of the tooltip for @widget
13324 * Sets @text as the contents of the tooltip. This function will take
13325 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13326 * handler for the #GtkWidget::query-tooltip signal.
13328 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13333 gtk_widget_set_tooltip_text (GtkWidget *widget,
13336 g_return_if_fail (GTK_IS_WIDGET (widget));
13338 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13342 * gtk_widget_get_tooltip_text:
13343 * @widget: a #GtkWidget
13345 * Gets the contents of the tooltip for @widget.
13347 * Return value: the tooltip text, or %NULL. You should free the
13348 * returned string with g_free() when done.
13353 gtk_widget_get_tooltip_text (GtkWidget *widget)
13355 gchar *text = NULL;
13357 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13359 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13365 * gtk_widget_set_tooltip_markup:
13366 * @widget: a #GtkWidget
13367 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13369 * Sets @markup as the contents of the tooltip, which is marked up with
13370 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13372 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13373 * and of the default handler for the #GtkWidget::query-tooltip signal.
13375 * See also the #GtkWidget:tooltip-markup property and
13376 * gtk_tooltip_set_markup().
13381 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13382 const gchar *markup)
13384 g_return_if_fail (GTK_IS_WIDGET (widget));
13386 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13390 * gtk_widget_get_tooltip_markup:
13391 * @widget: a #GtkWidget
13393 * Gets the contents of the tooltip for @widget.
13395 * Return value: the tooltip text, or %NULL. You should free the
13396 * returned string with g_free() when done.
13401 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13403 gchar *text = NULL;
13405 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13407 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13413 * gtk_widget_set_has_tooltip:
13414 * @widget: a #GtkWidget
13415 * @has_tooltip: whether or not @widget has a tooltip.
13417 * Sets the has-tooltip property on @widget to @has_tooltip. See
13418 * #GtkWidget:has-tooltip for more information.
13423 gtk_widget_set_has_tooltip (GtkWidget *widget,
13424 gboolean has_tooltip)
13426 g_return_if_fail (GTK_IS_WIDGET (widget));
13428 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13432 * gtk_widget_get_has_tooltip:
13433 * @widget: a #GtkWidget
13435 * Returns the current value of the has-tooltip property. See
13436 * #GtkWidget:has-tooltip for more information.
13438 * Return value: current value of has-tooltip on @widget.
13443 gtk_widget_get_has_tooltip (GtkWidget *widget)
13445 gboolean has_tooltip = FALSE;
13447 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13449 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13451 return has_tooltip;
13455 * gtk_widget_get_allocation:
13456 * @widget: a #GtkWidget
13457 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13459 * Retrieves the widget's allocation.
13461 * Note, when implementing a #GtkContainer: a widget's allocation will
13462 * be its "adjusted" allocation, that is, the widget's parent
13463 * container typically calls gtk_widget_size_allocate() with an
13464 * allocation, and that allocation is then adjusted (to handle margin
13465 * and alignment for example) before assignment to the widget.
13466 * gtk_widget_get_allocation() returns the adjusted allocation that
13467 * was actually assigned to the widget. The adjusted allocation is
13468 * guaranteed to be completely contained within the
13469 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13470 * is guaranteed that its children stay inside the assigned bounds,
13471 * but not that they have exactly the bounds the container assigned.
13472 * There is no way to get the original allocation assigned by
13473 * gtk_widget_size_allocate(), since it isn't stored; if a container
13474 * implementation needs that information it will have to track it itself.
13479 gtk_widget_get_allocation (GtkWidget *widget,
13480 GtkAllocation *allocation)
13482 GtkWidgetPrivate *priv;
13484 g_return_if_fail (GTK_IS_WIDGET (widget));
13485 g_return_if_fail (allocation != NULL);
13487 priv = widget->priv;
13489 *allocation = priv->allocation;
13493 * gtk_widget_set_allocation:
13494 * @widget: a #GtkWidget
13495 * @allocation: a pointer to a #GtkAllocation to copy from
13497 * Sets the widget's allocation. This should not be used
13498 * directly, but from within a widget's size_allocate method.
13500 * The allocation set should be the "adjusted" or actual
13501 * allocation. If you're implementing a #GtkContainer, you want to use
13502 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13503 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13504 * allocation inside gtk_widget_size_allocate() to create an adjusted
13510 gtk_widget_set_allocation (GtkWidget *widget,
13511 const GtkAllocation *allocation)
13513 GtkWidgetPrivate *priv;
13515 g_return_if_fail (GTK_IS_WIDGET (widget));
13516 g_return_if_fail (allocation != NULL);
13518 priv = widget->priv;
13520 priv->allocation = *allocation;
13524 * gtk_widget_get_allocated_width:
13525 * @widget: the widget to query
13527 * Returns the width that has currently been allocated to @widget.
13528 * This function is intended to be used when implementing handlers
13529 * for the #GtkWidget::draw function.
13531 * Returns: the width of the @widget
13534 gtk_widget_get_allocated_width (GtkWidget *widget)
13536 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13538 return widget->priv->allocation.width;
13542 * gtk_widget_get_allocated_height:
13543 * @widget: the widget to query
13545 * Returns the height that has currently been allocated to @widget.
13546 * This function is intended to be used when implementing handlers
13547 * for the #GtkWidget::draw function.
13549 * Returns: the height of the @widget
13552 gtk_widget_get_allocated_height (GtkWidget *widget)
13554 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13556 return widget->priv->allocation.height;
13560 * gtk_widget_get_requisition:
13561 * @widget: a #GtkWidget
13562 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13564 * Retrieves the widget's requisition.
13566 * This function should only be used by widget implementations in
13567 * order to figure whether the widget's requisition has actually
13568 * changed after some internal state change (so that they can call
13569 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13571 * Normally, gtk_widget_size_request() should be used.
13575 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13576 * removed, If you need to cache sizes across requests and allocations,
13577 * add an explicit cache to the widget in question instead.
13580 gtk_widget_get_requisition (GtkWidget *widget,
13581 GtkRequisition *requisition)
13583 g_return_if_fail (GTK_IS_WIDGET (widget));
13584 g_return_if_fail (requisition != NULL);
13586 gtk_widget_get_preferred_size (widget, requisition, NULL);
13590 * gtk_widget_set_window:
13591 * @widget: a #GtkWidget
13592 * @window: (transfer full): a #GdkWindow
13594 * Sets a widget's window. This function should only be used in a
13595 * widget's #GtkWidget::realize implementation. The %window passed is
13596 * usually either new window created with gdk_window_new(), or the
13597 * window of its parent widget as returned by
13598 * gtk_widget_get_parent_window().
13600 * Widgets must indicate whether they will create their own #GdkWindow
13601 * by calling gtk_widget_set_has_window(). This is usually done in the
13602 * widget's init() function.
13604 * <note><para>This function does not add any reference to @window.</para></note>
13609 gtk_widget_set_window (GtkWidget *widget,
13612 GtkWidgetPrivate *priv;
13614 g_return_if_fail (GTK_IS_WIDGET (widget));
13615 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13617 priv = widget->priv;
13619 if (priv->window != window)
13621 priv->window = window;
13622 g_object_notify (G_OBJECT (widget), "window");
13627 * gtk_widget_get_window:
13628 * @widget: a #GtkWidget
13630 * Returns the widget's window if it is realized, %NULL otherwise
13632 * Return value: (transfer none): @widget's window.
13637 gtk_widget_get_window (GtkWidget *widget)
13639 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13641 return widget->priv->window;
13645 * gtk_widget_get_support_multidevice:
13646 * @widget: a #GtkWidget
13648 * Returns %TRUE if @widget is multiple pointer aware. See
13649 * gtk_widget_set_support_multidevice() for more information.
13651 * Returns: %TRUE if @widget is multidevice aware.
13654 gtk_widget_get_support_multidevice (GtkWidget *widget)
13656 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13658 return widget->priv->multidevice;
13662 * gtk_widget_set_support_multidevice:
13663 * @widget: a #GtkWidget
13664 * @support_multidevice: %TRUE to support input from multiple devices.
13666 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13667 * @widget will start receiving multiple, per device enter/leave events. Note
13668 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13669 * gdk_window_set_support_multidevice() will have to be called manually on them.
13674 gtk_widget_set_support_multidevice (GtkWidget *widget,
13675 gboolean support_multidevice)
13677 GtkWidgetPrivate *priv;
13679 g_return_if_fail (GTK_IS_WIDGET (widget));
13681 priv = widget->priv;
13682 priv->multidevice = (support_multidevice == TRUE);
13684 if (gtk_widget_get_realized (widget))
13685 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13689 _gtk_widget_set_has_focus (GtkWidget *widget,
13690 gboolean has_focus)
13692 widget->priv->has_focus = has_focus;
13695 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13697 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13701 * gtk_widget_send_focus_change:
13702 * @widget: a #GtkWidget
13703 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13705 * Sends the focus change @event to @widget
13707 * This function is not meant to be used by applications. The only time it
13708 * should be used is when it is necessary for a #GtkWidget to assign focus
13709 * to a widget that is semantically owned by the first widget even though
13710 * it's not a direct child - for instance, a search entry in a floating
13711 * window similar to the quick search in #GtkTreeView.
13713 * An example of its usage is:
13716 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13718 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13719 * fevent->focus_change.in = TRUE;
13720 * fevent->focus_change.window = gtk_widget_get_window (widget);
13721 * if (fevent->focus_change.window != NULL)
13722 * g_object_ref (fevent->focus_change.window);
13724 * gtk_widget_send_focus_change (widget, fevent);
13726 * gdk_event_free (event);
13729 * Return value: the return value from the event signal emission: %TRUE
13730 * if the event was handled, and %FALSE otherwise
13735 gtk_widget_send_focus_change (GtkWidget *widget,
13740 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13741 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13743 g_object_ref (widget);
13745 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13747 res = gtk_widget_event (widget, event);
13749 g_object_notify (G_OBJECT (widget), "has-focus");
13751 g_object_unref (widget);
13757 * gtk_widget_in_destruction:
13758 * @widget: a #GtkWidget
13760 * Returns whether the widget is currently being destroyed.
13761 * This information can sometimes be used to avoid doing
13762 * unnecessary work.
13764 * Returns: %TRUE if @widget is being destroyed
13767 gtk_widget_in_destruction (GtkWidget *widget)
13769 return widget->priv->in_destruction;
13773 _gtk_widget_get_in_reparent (GtkWidget *widget)
13775 return widget->priv->in_reparent;
13779 _gtk_widget_set_in_reparent (GtkWidget *widget,
13780 gboolean in_reparent)
13782 widget->priv->in_reparent = in_reparent;
13786 _gtk_widget_get_anchored (GtkWidget *widget)
13788 return widget->priv->anchored;
13792 _gtk_widget_set_anchored (GtkWidget *widget,
13795 widget->priv->anchored = anchored;
13799 _gtk_widget_get_shadowed (GtkWidget *widget)
13801 return widget->priv->shadowed;
13805 _gtk_widget_set_shadowed (GtkWidget *widget,
13808 widget->priv->shadowed = shadowed;
13812 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13814 return widget->priv->alloc_needed;
13818 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13819 gboolean alloc_needed)
13821 widget->priv->alloc_needed = alloc_needed;
13825 _gtk_widget_add_sizegroup (GtkWidget *widget,
13830 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13831 groups = g_slist_prepend (groups, group);
13832 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13834 widget->priv->have_size_groups = TRUE;
13838 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13843 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13844 groups = g_slist_remove (groups, group);
13845 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13847 widget->priv->have_size_groups = groups != NULL;
13851 _gtk_widget_get_sizegroups (GtkWidget *widget)
13853 if (widget->priv->have_size_groups)
13854 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13860 _gtk_widget_add_attached_window (GtkWidget *widget,
13863 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13867 _gtk_widget_remove_attached_window (GtkWidget *widget,
13870 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13874 * gtk_widget_path_append_for_widget:
13875 * @path: a widget path
13876 * @widget: the widget to append to the widget path
13878 * Appends the data from @widget to the widget hierarchy represented
13879 * by @path. This function is a shortcut for adding information from
13880 * @widget to the given @path. This includes setting the name or
13881 * adding the style classes from @widget.
13883 * Returns: the position where the data was inserted
13888 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13893 g_return_val_if_fail (path != NULL, 0);
13894 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13896 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13898 if (widget->priv->name)
13899 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13901 if (widget->priv->context)
13903 GList *classes, *l;
13905 /* Also add any persistent classes in
13906 * the style context the widget path
13908 classes = gtk_style_context_list_classes (widget->priv->context);
13910 for (l = classes; l; l = l->next)
13911 gtk_widget_path_iter_add_class (path, pos, l->data);
13913 g_list_free (classes);
13920 _gtk_widget_create_path (GtkWidget *widget)
13924 parent = widget->priv->parent;
13927 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13930 /* Widget is either toplevel or unparented, treat both
13931 * as toplevels style wise, since there are situations
13932 * where style properties might be retrieved on that
13935 GtkWidget *attach_widget = NULL;
13936 GtkWidgetPath *result;
13938 if (GTK_IS_WINDOW (widget))
13939 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
13941 if (attach_widget != NULL)
13942 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
13944 result = gtk_widget_path_new ();
13946 gtk_widget_path_append_for_widget (result, widget);
13953 * gtk_widget_get_path:
13954 * @widget: a #GtkWidget
13956 * Returns the #GtkWidgetPath representing @widget, if the widget
13957 * is not connected to a toplevel widget, a partial path will be
13960 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13963 gtk_widget_get_path (GtkWidget *widget)
13965 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13967 if (!widget->priv->path)
13968 widget->priv->path = _gtk_widget_create_path (widget);
13970 return widget->priv->path;
13974 _gtk_widget_style_context_invalidated (GtkWidget *widget)
13976 if (widget->priv->path)
13978 gtk_widget_path_free (widget->priv->path);
13979 widget->priv->path = NULL;
13982 if (gtk_widget_get_realized (widget))
13983 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13986 /* Compress all style updates so it
13987 * is only emitted once pre-realize.
13989 widget->priv->style_update_pending = TRUE;
13994 * gtk_widget_get_style_context:
13995 * @widget: a #GtkWidget
13997 * Returns the style context associated to @widget.
13999 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14000 * must not be freed.
14003 gtk_widget_get_style_context (GtkWidget *widget)
14005 GtkWidgetPrivate *priv;
14007 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14009 priv = widget->priv;
14011 if (G_UNLIKELY (priv->context == NULL))
14015 priv->context = gtk_style_context_new ();
14017 gtk_style_context_set_state (priv->context, priv->state_flags);
14019 screen = gtk_widget_get_screen (widget);
14021 gtk_style_context_set_screen (priv->context, screen);
14024 gtk_style_context_set_parent (priv->context,
14025 gtk_widget_get_style_context (priv->parent));
14027 _gtk_style_context_set_widget (priv->context, widget);
14030 return widget->priv->context;
14034 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14035 GtkCssChange change)
14037 GtkWidgetPrivate *priv;
14039 priv = widget->priv;
14041 if (priv->context == NULL)
14044 _gtk_style_context_queue_invalidate (priv->context, change);
14048 * gtk_widget_get_modifier_mask:
14049 * @widget: a #GtkWidget
14050 * @intent: the use case for the modifier mask
14052 * Returns the modifier mask the @widget's windowing system backend
14053 * uses for a particular purpose.
14055 * See gdk_keymap_get_modifier_mask().
14057 * Returns: the modifier mask used for @intent.
14062 gtk_widget_get_modifier_mask (GtkWidget *widget,
14063 GdkModifierIntent intent)
14065 GdkDisplay *display;
14067 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14069 display = gtk_widget_get_display (widget);
14071 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14076 _gtk_widget_get_style (GtkWidget *widget)
14078 return widget->priv->style;
14082 _gtk_widget_set_style (GtkWidget *widget,
14085 widget->priv->style = style;
14089 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14092 GActionMuxer *parent_muxer;
14094 if (widget->priv->muxer == NULL)
14097 if (GTK_IS_MENU (widget))
14098 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14100 parent = gtk_widget_get_parent (widget);
14102 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14104 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14108 _gtk_widget_get_action_muxer (GtkWidget *widget)
14110 if (widget->priv->muxer == NULL)
14112 widget->priv->muxer = g_action_muxer_new ();
14113 _gtk_widget_update_parent_muxer (widget);
14116 return widget->priv->muxer;
14120 * gtk_widget_insert_action_group:
14121 * @widget: a #GtkWidget
14122 * @name: the prefix for actions in @group
14123 * @group: a #GActionGroup
14125 * Inserts @group into @widget. Children of @widget that implement
14126 * #GtkActionable can then be associated with actions in @group by
14127 * setting their 'action-name' to
14128 * @prefix.<replaceable>action-name</replaceable>.
14133 gtk_widget_insert_action_group (GtkWidget *widget,
14135 GActionGroup *group)
14137 GActionMuxer *muxer;
14139 g_return_if_fail (GTK_IS_WIDGET (widget));
14140 g_return_if_fail (name != NULL);
14142 muxer = _gtk_widget_get_action_muxer (widget);
14145 g_action_muxer_insert (muxer, name, group);
14147 g_action_muxer_remove (muxer, name);