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).
398 GList *registered_windows;
400 /* The widget's parent */
403 #ifdef G_ENABLE_DEBUG
404 /* Number of gtk_widget_push_verify_invariants () */
405 guint verifying_invariants_count;
406 #endif /* G_ENABLE_DEBUG */
409 struct _GtkWidgetClassPrivate
411 GType accessible_type;
412 AtkRole accessible_role;
441 BUTTON_RELEASE_EVENT,
455 PROPERTY_NOTIFY_EVENT,
456 SELECTION_CLEAR_EVENT,
457 SELECTION_REQUEST_EVENT,
458 SELECTION_NOTIFY_EVENT,
463 VISIBILITY_NOTIFY_EVENT,
477 ACCEL_CLOSURES_CHANGED,
502 PROP_RECEIVES_DEFAULT,
503 PROP_COMPOSITE_CHILD,
511 PROP_DOUBLE_BUFFERED,
526 typedef struct _GtkStateData GtkStateData;
531 guint flags_to_unset;
534 /* --- prototypes --- */
535 static void gtk_widget_base_class_init (gpointer g_class);
536 static void gtk_widget_class_init (GtkWidgetClass *klass);
537 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
538 static void gtk_widget_init (GtkWidget *widget);
539 static void gtk_widget_set_property (GObject *object,
543 static void gtk_widget_get_property (GObject *object,
547 static void gtk_widget_constructed (GObject *object);
548 static void gtk_widget_dispose (GObject *object);
549 static void gtk_widget_real_destroy (GtkWidget *object);
550 static void gtk_widget_finalize (GObject *object);
551 static void gtk_widget_real_show (GtkWidget *widget);
552 static void gtk_widget_real_hide (GtkWidget *widget);
553 static void gtk_widget_real_map (GtkWidget *widget);
554 static void gtk_widget_real_unmap (GtkWidget *widget);
555 static void gtk_widget_real_realize (GtkWidget *widget);
556 static void gtk_widget_real_unrealize (GtkWidget *widget);
557 static void gtk_widget_real_size_allocate (GtkWidget *widget,
558 GtkAllocation *allocation);
559 static void gtk_widget_real_style_set (GtkWidget *widget,
560 GtkStyle *previous_style);
561 static void gtk_widget_real_direction_changed(GtkWidget *widget,
562 GtkTextDirection previous_direction);
564 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
565 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
568 gboolean keyboard_tip,
569 GtkTooltip *tooltip);
570 static void gtk_widget_real_style_updated (GtkWidget *widget);
571 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
572 GtkWidgetHelpType help_type);
574 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
576 GParamSpec **pspecs);
577 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
579 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
581 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
582 GdkEventFocus *event);
583 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
584 GdkEventFocus *event);
585 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
586 GdkEventTouch *event);
587 static gboolean gtk_widget_real_focus (GtkWidget *widget,
588 GtkDirectionType direction);
589 static void gtk_widget_real_move_focus (GtkWidget *widget,
590 GtkDirectionType direction);
591 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
592 GtkDirectionType direction);
593 #ifdef G_ENABLE_DEBUG
594 static void gtk_widget_verify_invariants (GtkWidget *widget);
595 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
596 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
598 #define gtk_widget_verify_invariants(widget)
599 #define gtk_widget_push_verify_invariants(widget)
600 #define gtk_widget_pop_verify_invariants(widget)
602 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
603 static void gtk_widget_update_pango_context (GtkWidget *widget);
604 static void gtk_widget_propagate_state (GtkWidget *widget,
607 static gint gtk_widget_event_internal (GtkWidget *widget,
609 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
610 gboolean group_cycling);
611 static void gtk_widget_real_get_width (GtkWidget *widget,
614 static void gtk_widget_real_get_height (GtkWidget *widget,
617 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
619 gint *minimum_height,
620 gint *natural_height);
621 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
624 gint *natural_width);
625 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
626 GtkStateFlags old_state);
627 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
628 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
630 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
631 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
632 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
633 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
634 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
635 cairo_region_t *region);
636 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
637 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
640 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
641 gboolean has_tooltip,
643 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
644 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
646 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
647 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
649 const gchar *childname);
650 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
653 const GValue *value);
654 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
657 const gchar *tagname,
658 GMarkupParser *parser,
660 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
663 const gchar *tagname,
665 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
666 GtkBuilder *builder);
668 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
669 static void gtk_widget_real_get_width (GtkWidget *widget,
672 static void gtk_widget_real_get_height (GtkWidget *widget,
676 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
679 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
680 GtkOrientation orientation,
683 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
684 GtkOrientation orientation,
688 gint *allocated_size);
690 static void gtk_widget_set_usize_internal (GtkWidget *widget,
693 GtkQueueResizeFlags flags);
695 static void gtk_widget_add_events_internal (GtkWidget *widget,
698 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
702 static gboolean event_window_is_still_viewable (GdkEvent *event);
704 /* --- variables --- */
705 static gpointer gtk_widget_parent_class = NULL;
706 static guint widget_signals[LAST_SIGNAL] = { 0 };
707 static guint composite_child_stack = 0;
708 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
709 static GParamSpecPool *style_property_spec_pool = NULL;
711 static GQuark quark_property_parser = 0;
712 static GQuark quark_aux_info = 0;
713 static GQuark quark_accel_path = 0;
714 static GQuark quark_accel_closures = 0;
715 static GQuark quark_event_mask = 0;
716 static GQuark quark_device_event_mask = 0;
717 static GQuark quark_parent_window = 0;
718 static GQuark quark_pointer_window = 0;
719 static GQuark quark_shape_info = 0;
720 static GQuark quark_input_shape_info = 0;
721 static GQuark quark_pango_context = 0;
722 static GQuark quark_accessible_object = 0;
723 static GQuark quark_mnemonic_labels = 0;
724 static GQuark quark_tooltip_markup = 0;
725 static GQuark quark_has_tooltip = 0;
726 static GQuark quark_tooltip_window = 0;
727 static GQuark quark_visual = 0;
728 static GQuark quark_modifier_style = 0;
729 static GQuark quark_enabled_devices = 0;
730 static GQuark quark_size_groups = 0;
731 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
732 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
734 /* --- functions --- */
736 gtk_widget_get_type (void)
738 static GType widget_type = 0;
740 if (G_UNLIKELY (widget_type == 0))
742 const GTypeInfo widget_info =
744 sizeof (GtkWidgetClass),
745 gtk_widget_base_class_init,
746 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
747 (GClassInitFunc) gtk_widget_class_init,
748 NULL, /* class_finalize */
749 NULL, /* class_init */
752 (GInstanceInitFunc) gtk_widget_init,
753 NULL, /* value_table */
756 const GInterfaceInfo accessibility_info =
758 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
759 (GInterfaceFinalizeFunc) NULL,
760 NULL /* interface data */
763 const GInterfaceInfo buildable_info =
765 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
766 (GInterfaceFinalizeFunc) NULL,
767 NULL /* interface data */
770 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
771 &widget_info, G_TYPE_FLAG_ABSTRACT);
773 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
775 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
776 &accessibility_info) ;
777 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
785 gtk_widget_base_class_init (gpointer g_class)
787 GtkWidgetClass *klass = g_class;
789 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
793 child_property_notify_dispatcher (GObject *object,
797 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
800 /* We guard against the draw signal callbacks modifying the state of the
801 * cairo context by surounding it with save/restore.
802 * Maybe we should also cairo_new_path() just to be sure?
805 gtk_widget_draw_marshaller (GClosure *closure,
806 GValue *return_value,
807 guint n_param_values,
808 const GValue *param_values,
809 gpointer invocation_hint,
810 gpointer marshal_data)
812 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
816 _gtk_marshal_BOOLEAN__BOXED (closure,
827 gtk_widget_draw_marshallerv (GClosure *closure,
828 GValue *return_value,
831 gpointer marshal_data,
838 G_VA_COPY (args_copy, args);
839 cr = va_arg (args_copy, gpointer);
843 _gtk_marshal_BOOLEAN__BOXEDv (closure,
857 gtk_widget_class_init (GtkWidgetClass *klass)
859 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
860 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
861 GtkBindingSet *binding_set;
863 gtk_widget_parent_class = g_type_class_peek_parent (klass);
865 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
866 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
867 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
868 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
869 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
870 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
871 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
872 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
873 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
874 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
875 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
876 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
877 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
878 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
879 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
880 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
881 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
882 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
883 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
884 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
886 style_property_spec_pool = g_param_spec_pool_new (FALSE);
887 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
888 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
889 cpn_context.dispatcher = child_property_notify_dispatcher;
890 _gtk_widget_child_property_notify_context = &cpn_context;
892 gobject_class->constructed = gtk_widget_constructed;
893 gobject_class->dispose = gtk_widget_dispose;
894 gobject_class->finalize = gtk_widget_finalize;
895 gobject_class->set_property = gtk_widget_set_property;
896 gobject_class->get_property = gtk_widget_get_property;
898 klass->destroy = gtk_widget_real_destroy;
900 klass->activate_signal = 0;
901 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
902 klass->show = gtk_widget_real_show;
903 klass->show_all = gtk_widget_show;
904 klass->hide = gtk_widget_real_hide;
905 klass->map = gtk_widget_real_map;
906 klass->unmap = gtk_widget_real_unmap;
907 klass->realize = gtk_widget_real_realize;
908 klass->unrealize = gtk_widget_real_unrealize;
909 klass->size_allocate = gtk_widget_real_size_allocate;
910 klass->get_request_mode = gtk_widget_real_get_request_mode;
911 klass->get_preferred_width = gtk_widget_real_get_width;
912 klass->get_preferred_height = gtk_widget_real_get_height;
913 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
914 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
915 klass->state_changed = NULL;
916 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
917 klass->parent_set = NULL;
918 klass->hierarchy_changed = NULL;
919 klass->style_set = gtk_widget_real_style_set;
920 klass->direction_changed = gtk_widget_real_direction_changed;
921 klass->grab_notify = NULL;
922 klass->child_notify = NULL;
924 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
925 klass->grab_focus = gtk_widget_real_grab_focus;
926 klass->focus = gtk_widget_real_focus;
927 klass->move_focus = gtk_widget_real_move_focus;
928 klass->keynav_failed = gtk_widget_real_keynav_failed;
930 klass->button_press_event = NULL;
931 klass->button_release_event = NULL;
932 klass->motion_notify_event = NULL;
933 klass->touch_event = gtk_widget_real_touch_event;
934 klass->delete_event = NULL;
935 klass->destroy_event = NULL;
936 klass->key_press_event = gtk_widget_real_key_press_event;
937 klass->key_release_event = gtk_widget_real_key_release_event;
938 klass->enter_notify_event = NULL;
939 klass->leave_notify_event = NULL;
940 klass->configure_event = NULL;
941 klass->focus_in_event = gtk_widget_real_focus_in_event;
942 klass->focus_out_event = gtk_widget_real_focus_out_event;
943 klass->map_event = NULL;
944 klass->unmap_event = NULL;
945 klass->window_state_event = NULL;
946 klass->property_notify_event = _gtk_selection_property_notify;
947 klass->selection_clear_event = _gtk_selection_clear;
948 klass->selection_request_event = _gtk_selection_request;
949 klass->selection_notify_event = _gtk_selection_notify;
950 klass->selection_received = NULL;
951 klass->proximity_in_event = NULL;
952 klass->proximity_out_event = NULL;
953 klass->drag_begin = NULL;
954 klass->drag_end = NULL;
955 klass->drag_data_delete = NULL;
956 klass->drag_leave = NULL;
957 klass->drag_motion = NULL;
958 klass->drag_drop = NULL;
959 klass->drag_data_received = NULL;
960 klass->screen_changed = NULL;
961 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
962 klass->grab_broken_event = NULL;
963 klass->query_tooltip = gtk_widget_real_query_tooltip;
964 klass->style_updated = gtk_widget_real_style_updated;
966 klass->show_help = gtk_widget_real_show_help;
968 /* Accessibility support */
969 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
970 klass->priv->accessible_role = ATK_ROLE_INVALID;
971 klass->get_accessible = gtk_widget_real_get_accessible;
973 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
974 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
976 g_object_class_install_property (gobject_class,
978 g_param_spec_string ("name",
980 P_("The name of the widget"),
982 GTK_PARAM_READWRITE));
983 g_object_class_install_property (gobject_class,
985 g_param_spec_object ("parent",
987 P_("The parent widget of this widget. Must be a Container widget"),
989 GTK_PARAM_READWRITE));
991 g_object_class_install_property (gobject_class,
993 g_param_spec_int ("width-request",
995 P_("Override for width request of the widget, or -1 if natural request should be used"),
999 GTK_PARAM_READWRITE));
1000 g_object_class_install_property (gobject_class,
1001 PROP_HEIGHT_REQUEST,
1002 g_param_spec_int ("height-request",
1003 P_("Height request"),
1004 P_("Override for height request of the widget, or -1 if natural request should be used"),
1008 GTK_PARAM_READWRITE));
1009 g_object_class_install_property (gobject_class,
1011 g_param_spec_boolean ("visible",
1013 P_("Whether the widget is visible"),
1015 GTK_PARAM_READWRITE));
1016 g_object_class_install_property (gobject_class,
1018 g_param_spec_boolean ("sensitive",
1020 P_("Whether the widget responds to input"),
1022 GTK_PARAM_READWRITE));
1023 g_object_class_install_property (gobject_class,
1025 g_param_spec_boolean ("app-paintable",
1026 P_("Application paintable"),
1027 P_("Whether the application will paint directly on the widget"),
1029 GTK_PARAM_READWRITE));
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_boolean ("can-focus",
1034 P_("Whether the widget can accept the input focus"),
1036 GTK_PARAM_READWRITE));
1037 g_object_class_install_property (gobject_class,
1039 g_param_spec_boolean ("has-focus",
1041 P_("Whether the widget has the input focus"),
1043 GTK_PARAM_READWRITE));
1044 g_object_class_install_property (gobject_class,
1046 g_param_spec_boolean ("is-focus",
1048 P_("Whether the widget is the focus widget within the toplevel"),
1050 GTK_PARAM_READWRITE));
1051 g_object_class_install_property (gobject_class,
1053 g_param_spec_boolean ("can-default",
1055 P_("Whether the widget can be the default widget"),
1057 GTK_PARAM_READWRITE));
1058 g_object_class_install_property (gobject_class,
1060 g_param_spec_boolean ("has-default",
1062 P_("Whether the widget is the default widget"),
1064 GTK_PARAM_READWRITE));
1065 g_object_class_install_property (gobject_class,
1066 PROP_RECEIVES_DEFAULT,
1067 g_param_spec_boolean ("receives-default",
1068 P_("Receives default"),
1069 P_("If TRUE, the widget will receive the default action when it is focused"),
1071 GTK_PARAM_READWRITE));
1072 g_object_class_install_property (gobject_class,
1073 PROP_COMPOSITE_CHILD,
1074 g_param_spec_boolean ("composite-child",
1075 P_("Composite child"),
1076 P_("Whether the widget is part of a composite widget"),
1078 GTK_PARAM_READABLE));
1079 g_object_class_install_property (gobject_class,
1081 g_param_spec_object ("style",
1083 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1085 GTK_PARAM_READWRITE));
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_flags ("events",
1090 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1091 GDK_TYPE_EVENT_MASK,
1093 GTK_PARAM_READWRITE));
1094 g_object_class_install_property (gobject_class,
1096 g_param_spec_boolean ("no-show-all",
1098 P_("Whether gtk_widget_show_all() should not affect this widget"),
1100 GTK_PARAM_READWRITE));
1103 * GtkWidget:has-tooltip:
1105 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1106 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1107 * the widget will be queried using #GtkWidget::query-tooltip to determine
1108 * whether it will provide a tooltip or not.
1110 * Note that setting this property to %TRUE for the first time will change
1111 * the event masks of the GdkWindows of this widget to include leave-notify
1112 * and motion-notify events. This cannot and will not be undone when the
1113 * property is set to %FALSE again.
1117 g_object_class_install_property (gobject_class,
1119 g_param_spec_boolean ("has-tooltip",
1121 P_("Whether this widget has a tooltip"),
1123 GTK_PARAM_READWRITE));
1125 * GtkWidget:tooltip-text:
1127 * Sets the text of tooltip to be the given string.
1129 * Also see gtk_tooltip_set_text().
1131 * This is a convenience property which will take care of getting the
1132 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1133 * will automatically be set to %TRUE and there will be taken care of
1134 * #GtkWidget::query-tooltip in the default signal handler.
1138 g_object_class_install_property (gobject_class,
1140 g_param_spec_string ("tooltip-text",
1142 P_("The contents of the tooltip for this widget"),
1144 GTK_PARAM_READWRITE));
1146 * GtkWidget:tooltip-markup:
1148 * Sets the text of tooltip to be the given string, which is marked up
1149 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1150 * Also see gtk_tooltip_set_markup().
1152 * This is a convenience property which will take care of getting the
1153 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1154 * will automatically be set to %TRUE and there will be taken care of
1155 * #GtkWidget::query-tooltip in the default signal handler.
1159 g_object_class_install_property (gobject_class,
1160 PROP_TOOLTIP_MARKUP,
1161 g_param_spec_string ("tooltip-markup",
1162 P_("Tooltip markup"),
1163 P_("The contents of the tooltip for this widget"),
1165 GTK_PARAM_READWRITE));
1170 * The widget's window if it is realized, %NULL otherwise.
1174 g_object_class_install_property (gobject_class,
1176 g_param_spec_object ("window",
1178 P_("The widget's window if it is realized"),
1180 GTK_PARAM_READABLE));
1183 * GtkWidget:double-buffered:
1185 * Whether the widget is double buffered.
1189 g_object_class_install_property (gobject_class,
1190 PROP_DOUBLE_BUFFERED,
1191 g_param_spec_boolean ("double-buffered",
1192 P_("Double Buffered"),
1193 P_("Whether the widget is double buffered"),
1195 GTK_PARAM_READWRITE));
1200 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1204 g_object_class_install_property (gobject_class,
1206 g_param_spec_enum ("halign",
1207 P_("Horizontal Alignment"),
1208 P_("How to position in extra horizontal space"),
1211 GTK_PARAM_READWRITE));
1216 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1220 g_object_class_install_property (gobject_class,
1222 g_param_spec_enum ("valign",
1223 P_("Vertical Alignment"),
1224 P_("How to position in extra vertical space"),
1227 GTK_PARAM_READWRITE));
1230 * GtkWidget:margin-left:
1232 * Margin on left side of widget.
1234 * This property adds margin outside of the widget's normal size
1235 * request, the margin will be added in addition to the size from
1236 * gtk_widget_set_size_request() for example.
1240 g_object_class_install_property (gobject_class,
1242 g_param_spec_int ("margin-left",
1243 P_("Margin on Left"),
1244 P_("Pixels of extra space on the left side"),
1248 GTK_PARAM_READWRITE));
1251 * GtkWidget:margin-right:
1253 * Margin on right side of widget.
1255 * This property adds margin outside of the widget's normal size
1256 * request, the margin will be added in addition to the size from
1257 * gtk_widget_set_size_request() for example.
1261 g_object_class_install_property (gobject_class,
1263 g_param_spec_int ("margin-right",
1264 P_("Margin on Right"),
1265 P_("Pixels of extra space on the right side"),
1269 GTK_PARAM_READWRITE));
1272 * GtkWidget:margin-top:
1274 * Margin on top side of widget.
1276 * This property adds margin outside of the widget's normal size
1277 * request, the margin will be added in addition to the size from
1278 * gtk_widget_set_size_request() for example.
1282 g_object_class_install_property (gobject_class,
1284 g_param_spec_int ("margin-top",
1285 P_("Margin on Top"),
1286 P_("Pixels of extra space on the top side"),
1290 GTK_PARAM_READWRITE));
1293 * GtkWidget:margin-bottom:
1295 * Margin on bottom side of widget.
1297 * This property adds margin outside of the widget's normal size
1298 * request, the margin will be added in addition to the size from
1299 * gtk_widget_set_size_request() for example.
1303 g_object_class_install_property (gobject_class,
1305 g_param_spec_int ("margin-bottom",
1306 P_("Margin on Bottom"),
1307 P_("Pixels of extra space on the bottom side"),
1311 GTK_PARAM_READWRITE));
1316 * Sets all four sides' margin at once. If read, returns max
1317 * margin on any side.
1321 g_object_class_install_property (gobject_class,
1323 g_param_spec_int ("margin",
1325 P_("Pixels of extra space on all four sides"),
1329 GTK_PARAM_READWRITE));
1332 * GtkWidget::destroy:
1333 * @object: the object which received the signal
1335 * Signals that all holders of a reference to the widget should release
1336 * the reference that they hold. May result in finalization of the widget
1337 * if all references are released.
1339 widget_signals[DESTROY] =
1340 g_signal_new (I_("destroy"),
1341 G_TYPE_FROM_CLASS (gobject_class),
1342 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1343 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1345 _gtk_marshal_VOID__VOID,
1349 * GtkWidget:hexpand:
1351 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1355 g_object_class_install_property (gobject_class,
1357 g_param_spec_boolean ("hexpand",
1358 P_("Horizontal Expand"),
1359 P_("Whether widget wants more horizontal space"),
1361 GTK_PARAM_READWRITE));
1364 * GtkWidget:hexpand-set:
1366 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1370 g_object_class_install_property (gobject_class,
1372 g_param_spec_boolean ("hexpand-set",
1373 P_("Horizontal Expand Set"),
1374 P_("Whether to use the hexpand property"),
1376 GTK_PARAM_READWRITE));
1379 * GtkWidget:vexpand:
1381 * Whether to expand vertically. See gtk_widget_set_vexpand().
1385 g_object_class_install_property (gobject_class,
1387 g_param_spec_boolean ("vexpand",
1388 P_("Vertical Expand"),
1389 P_("Whether widget wants more vertical space"),
1391 GTK_PARAM_READWRITE));
1394 * GtkWidget:vexpand-set:
1396 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1400 g_object_class_install_property (gobject_class,
1402 g_param_spec_boolean ("vexpand-set",
1403 P_("Vertical Expand Set"),
1404 P_("Whether to use the vexpand property"),
1406 GTK_PARAM_READWRITE));
1411 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1415 g_object_class_install_property (gobject_class,
1417 g_param_spec_boolean ("expand",
1419 P_("Whether widget wants to expand in both directions"),
1421 GTK_PARAM_READWRITE));
1425 * @widget: the object which received the signal.
1427 widget_signals[SHOW] =
1428 g_signal_new (I_("show"),
1429 G_TYPE_FROM_CLASS (gobject_class),
1431 G_STRUCT_OFFSET (GtkWidgetClass, show),
1433 _gtk_marshal_VOID__VOID,
1438 * @widget: the object which received the signal.
1440 widget_signals[HIDE] =
1441 g_signal_new (I_("hide"),
1442 G_TYPE_FROM_CLASS (gobject_class),
1444 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1446 _gtk_marshal_VOID__VOID,
1451 * @widget: the object which received the signal.
1453 widget_signals[MAP] =
1454 g_signal_new (I_("map"),
1455 G_TYPE_FROM_CLASS (gobject_class),
1457 G_STRUCT_OFFSET (GtkWidgetClass, map),
1459 _gtk_marshal_VOID__VOID,
1464 * @widget: the object which received the signal.
1466 widget_signals[UNMAP] =
1467 g_signal_new (I_("unmap"),
1468 G_TYPE_FROM_CLASS (gobject_class),
1470 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1472 _gtk_marshal_VOID__VOID,
1476 * GtkWidget::realize:
1477 * @widget: the object which received the signal.
1479 widget_signals[REALIZE] =
1480 g_signal_new (I_("realize"),
1481 G_TYPE_FROM_CLASS (gobject_class),
1483 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1485 _gtk_marshal_VOID__VOID,
1489 * GtkWidget::unrealize:
1490 * @widget: the object which received the signal.
1492 widget_signals[UNREALIZE] =
1493 g_signal_new (I_("unrealize"),
1494 G_TYPE_FROM_CLASS (gobject_class),
1496 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1498 _gtk_marshal_VOID__VOID,
1502 * GtkWidget::size-allocate:
1503 * @widget: the object which received the signal.
1506 widget_signals[SIZE_ALLOCATE] =
1507 g_signal_new (I_("size-allocate"),
1508 G_TYPE_FROM_CLASS (gobject_class),
1510 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1512 _gtk_marshal_VOID__BOXED,
1514 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1517 * GtkWidget::state-changed:
1518 * @widget: the object which received the signal.
1519 * @state: the previous state
1521 * The ::state-changed signal is emitted when the widget state changes.
1522 * See gtk_widget_get_state().
1524 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1526 widget_signals[STATE_CHANGED] =
1527 g_signal_new (I_("state-changed"),
1528 G_TYPE_FROM_CLASS (gobject_class),
1530 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1532 _gtk_marshal_VOID__ENUM,
1534 GTK_TYPE_STATE_TYPE);
1537 * GtkWidget::state-flags-changed:
1538 * @widget: the object which received the signal.
1539 * @flags: The previous state flags.
1541 * The ::state-flags-changed signal is emitted when the widget state
1542 * changes, see gtk_widget_get_state_flags().
1546 widget_signals[STATE_FLAGS_CHANGED] =
1547 g_signal_new (I_("state-flags-changed"),
1548 G_TYPE_FROM_CLASS (gobject_class),
1550 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1552 _gtk_marshal_VOID__FLAGS,
1554 GTK_TYPE_STATE_FLAGS);
1557 * GtkWidget::parent-set:
1558 * @widget: the object on which the signal is emitted
1559 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1560 * just got its initial parent.
1562 * The ::parent-set signal is emitted when a new parent
1563 * has been set on a widget.
1565 widget_signals[PARENT_SET] =
1566 g_signal_new (I_("parent-set"),
1567 G_TYPE_FROM_CLASS (gobject_class),
1569 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1571 _gtk_marshal_VOID__OBJECT,
1576 * GtkWidget::hierarchy-changed:
1577 * @widget: the object on which the signal is emitted
1578 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1579 * if the widget was previously unanchored
1581 * The ::hierarchy-changed signal is emitted when the
1582 * anchored state of a widget changes. A widget is
1583 * <firstterm>anchored</firstterm> when its toplevel
1584 * ancestor is a #GtkWindow. This signal is emitted when
1585 * a widget changes from un-anchored to anchored or vice-versa.
1587 widget_signals[HIERARCHY_CHANGED] =
1588 g_signal_new (I_("hierarchy-changed"),
1589 G_TYPE_FROM_CLASS (gobject_class),
1591 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1593 _gtk_marshal_VOID__OBJECT,
1598 * GtkWidget::style-set:
1599 * @widget: the object on which the signal is emitted
1600 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1601 * just got its initial style
1603 * The ::style-set signal is emitted when a new style has been set
1604 * on a widget. Note that style-modifying functions like
1605 * gtk_widget_modify_base() also cause this signal to be emitted.
1607 * Note that this signal is emitted for changes to the deprecated
1608 * #GtkStyle. To track changes to the #GtkStyleContext associated
1609 * with a widget, use the #GtkWidget::style-updated signal.
1611 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1613 widget_signals[STYLE_SET] =
1614 g_signal_new (I_("style-set"),
1615 G_TYPE_FROM_CLASS (gobject_class),
1617 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1619 _gtk_marshal_VOID__OBJECT,
1624 * GtkWidget::style-updated:
1625 * @widget: the object on which the signal is emitted
1627 * The ::style-updated signal is emitted when the #GtkStyleContext
1628 * of a widget is changed. Note that style-modifying functions like
1629 * gtk_widget_override_color() also cause this signal to be emitted.
1633 widget_signals[STYLE_UPDATED] =
1634 g_signal_new (I_("style-updated"),
1635 G_TYPE_FROM_CLASS (gobject_class),
1637 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1639 g_cclosure_marshal_VOID__VOID,
1643 * GtkWidget::direction-changed:
1644 * @widget: the object on which the signal is emitted
1645 * @previous_direction: the previous text direction of @widget
1647 * The ::direction-changed signal is emitted when the text direction
1648 * of a widget changes.
1650 widget_signals[DIRECTION_CHANGED] =
1651 g_signal_new (I_("direction-changed"),
1652 G_TYPE_FROM_CLASS (gobject_class),
1654 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1656 _gtk_marshal_VOID__ENUM,
1658 GTK_TYPE_TEXT_DIRECTION);
1661 * GtkWidget::grab-notify:
1662 * @widget: the object which received the signal
1663 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1664 * if it becomes unshadowed
1666 * The ::grab-notify signal is emitted when a widget becomes
1667 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1668 * another widget, or when it becomes unshadowed due to a grab
1671 * A widget is shadowed by a gtk_grab_add() when the topmost
1672 * grab widget in the grab stack of its window group is not
1675 widget_signals[GRAB_NOTIFY] =
1676 g_signal_new (I_("grab-notify"),
1677 G_TYPE_FROM_CLASS (gobject_class),
1679 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1681 _gtk_marshal_VOID__BOOLEAN,
1686 * GtkWidget::child-notify:
1687 * @widget: the object which received the signal
1688 * @child_property: the #GParamSpec of the changed child property
1690 * The ::child-notify signal is emitted for each
1691 * <link linkend="child-properties">child property</link> that has
1692 * changed on an object. The signal's detail holds the property name.
1694 widget_signals[CHILD_NOTIFY] =
1695 g_signal_new (I_("child-notify"),
1696 G_TYPE_FROM_CLASS (gobject_class),
1697 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1698 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1700 g_cclosure_marshal_VOID__PARAM,
1706 * @widget: the object which received the signal
1707 * @cr: the cairo context to draw to
1709 * This signal is emitted when a widget is supposed to render itself.
1710 * The @widget's top left corner must be painted at the origin of
1711 * the passed in context and be sized to the values returned by
1712 * gtk_widget_get_allocated_width() and
1713 * gtk_widget_get_allocated_height().
1715 * Signal handlers connected to this signal can modify the cairo
1716 * context passed as @cr in any way they like and don't need to
1717 * restore it. The signal emission takes care of calling cairo_save()
1718 * before and cairo_restore() after invoking the handler.
1720 * Returns: %TRUE to stop other handlers from being invoked for the event.
1721 % %FALSE to propagate the event further.
1725 widget_signals[DRAW] =
1726 g_signal_new (I_("draw"),
1727 G_TYPE_FROM_CLASS (gobject_class),
1729 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1730 _gtk_boolean_handled_accumulator, NULL,
1731 gtk_widget_draw_marshaller,
1733 CAIRO_GOBJECT_TYPE_CONTEXT);
1734 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1735 gtk_widget_draw_marshallerv);
1738 * GtkWidget::mnemonic-activate:
1739 * @widget: the object which received the signal.
1742 * Returns: %TRUE to stop other handlers from being invoked for the event.
1743 * %FALSE to propagate the event further.
1745 widget_signals[MNEMONIC_ACTIVATE] =
1746 g_signal_new (I_("mnemonic-activate"),
1747 G_TYPE_FROM_CLASS (gobject_class),
1749 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1750 _gtk_boolean_handled_accumulator, NULL,
1751 _gtk_marshal_BOOLEAN__BOOLEAN,
1756 * GtkWidget::grab-focus:
1757 * @widget: the object which received the signal.
1759 widget_signals[GRAB_FOCUS] =
1760 g_signal_new (I_("grab-focus"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1763 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1765 _gtk_marshal_VOID__VOID,
1770 * @widget: the object which received the signal.
1773 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1775 widget_signals[FOCUS] =
1776 g_signal_new (I_("focus"),
1777 G_TYPE_FROM_CLASS (klass),
1779 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1780 _gtk_boolean_handled_accumulator, NULL,
1781 _gtk_marshal_BOOLEAN__ENUM,
1783 GTK_TYPE_DIRECTION_TYPE);
1786 * GtkWidget::move-focus:
1787 * @widget: the object which received the signal.
1790 widget_signals[MOVE_FOCUS] =
1791 g_signal_new (I_("move-focus"),
1792 G_TYPE_FROM_CLASS (klass),
1793 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1794 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1796 _gtk_marshal_VOID__ENUM,
1799 GTK_TYPE_DIRECTION_TYPE);
1802 * GtkWidget::keynav-failed:
1803 * @widget: the object which received the signal
1804 * @direction: the direction of movement
1806 * Gets emitted if keyboard navigation fails.
1807 * See gtk_widget_keynav_failed() for details.
1809 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1810 * if the emitting widget should try to handle the keyboard
1811 * navigation attempt in its parent container(s).
1815 widget_signals[KEYNAV_FAILED] =
1816 g_signal_new (I_("keynav-failed"),
1817 G_TYPE_FROM_CLASS (klass),
1819 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1820 _gtk_boolean_handled_accumulator, NULL,
1821 _gtk_marshal_BOOLEAN__ENUM,
1823 GTK_TYPE_DIRECTION_TYPE);
1827 * @widget: the object which received the signal.
1828 * @event: the #GdkEvent which triggered this signal
1830 * The GTK+ main loop will emit three signals for each GDK event delivered
1831 * to a widget: one generic ::event signal, another, more specific,
1832 * signal that matches the type of event delivered (e.g.
1833 * #GtkWidget::key-press-event) and finally a generic
1834 * #GtkWidget::event-after signal.
1836 * Returns: %TRUE to stop other handlers from being invoked for the event
1837 * and to cancel the emission of the second specific ::event signal.
1838 * %FALSE to propagate the event further and to allow the emission of
1839 * the second signal. The ::event-after signal is emitted regardless of
1842 widget_signals[EVENT] =
1843 g_signal_new (I_("event"),
1844 G_TYPE_FROM_CLASS (klass),
1846 G_STRUCT_OFFSET (GtkWidgetClass, event),
1847 _gtk_boolean_handled_accumulator, NULL,
1848 _gtk_marshal_BOOLEAN__BOXED,
1850 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1851 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1852 _gtk_marshal_BOOLEAN__BOXEDv);
1855 * GtkWidget::event-after:
1856 * @widget: the object which received the signal.
1857 * @event: the #GdkEvent which triggered this signal
1859 * After the emission of the #GtkWidget::event signal and (optionally)
1860 * the second more specific signal, ::event-after will be emitted
1861 * regardless of the previous two signals handlers return values.
1864 widget_signals[EVENT_AFTER] =
1865 g_signal_new (I_("event-after"),
1866 G_TYPE_FROM_CLASS (klass),
1870 _gtk_marshal_VOID__BOXED,
1872 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1873 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1874 _gtk_marshal_BOOLEAN__BOXEDv);
1877 * GtkWidget::button-press-event:
1878 * @widget: the object which received the signal.
1879 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1882 * The ::button-press-event signal will be emitted when a button
1883 * (typically from a mouse) is pressed.
1885 * To receive this signal, the #GdkWindow associated to the
1886 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1888 * This signal will be sent to the grab widget if there is one.
1890 * Returns: %TRUE to stop other handlers from being invoked for the event.
1891 * %FALSE to propagate the event further.
1893 widget_signals[BUTTON_PRESS_EVENT] =
1894 g_signal_new (I_("button-press-event"),
1895 G_TYPE_FROM_CLASS (klass),
1897 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1898 _gtk_boolean_handled_accumulator, NULL,
1899 _gtk_marshal_BOOLEAN__BOXED,
1901 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1902 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1903 _gtk_marshal_BOOLEAN__BOXEDv);
1906 * GtkWidget::button-release-event:
1907 * @widget: the object which received the signal.
1908 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1911 * The ::button-release-event signal will be emitted when a button
1912 * (typically from a mouse) is released.
1914 * To receive this signal, the #GdkWindow associated to the
1915 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1917 * This signal will be sent to the grab widget if there is one.
1919 * Returns: %TRUE to stop other handlers from being invoked for the event.
1920 * %FALSE to propagate the event further.
1922 widget_signals[BUTTON_RELEASE_EVENT] =
1923 g_signal_new (I_("button-release-event"),
1924 G_TYPE_FROM_CLASS (klass),
1926 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1927 _gtk_boolean_handled_accumulator, NULL,
1928 _gtk_marshal_BOOLEAN__BOXED,
1930 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1931 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
1932 _gtk_marshal_BOOLEAN__BOXEDv);
1934 widget_signals[TOUCH_EVENT] =
1935 g_signal_new (I_("touch-event"),
1936 G_TYPE_FROM_CLASS (klass),
1938 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
1939 _gtk_boolean_handled_accumulator, NULL,
1940 _gtk_marshal_BOOLEAN__BOXED,
1942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
1944 _gtk_marshal_BOOLEAN__BOXEDv);
1947 * GtkWidget::scroll-event:
1948 * @widget: the object which received the signal.
1949 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1952 * The ::scroll-event signal is emitted when a button in the 4 to 7
1953 * range is pressed. Wheel mice are usually configured to generate
1954 * button press events for buttons 4 and 5 when the wheel is turned.
1956 * To receive this signal, the #GdkWindow associated to the widget needs
1957 * to enable the #GDK_SCROLL_MASK mask.
1959 * This signal will be sent to the grab widget if there is one.
1961 * Returns: %TRUE to stop other handlers from being invoked for the event.
1962 * %FALSE to propagate the event further.
1964 widget_signals[SCROLL_EVENT] =
1965 g_signal_new (I_("scroll-event"),
1966 G_TYPE_FROM_CLASS (klass),
1968 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1969 _gtk_boolean_handled_accumulator, NULL,
1970 _gtk_marshal_BOOLEAN__BOXED,
1972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1973 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
1974 _gtk_marshal_BOOLEAN__BOXEDv);
1977 * GtkWidget::motion-notify-event:
1978 * @widget: the object which received the signal.
1979 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1982 * The ::motion-notify-event signal is emitted when the pointer moves
1983 * over the widget's #GdkWindow.
1985 * To receive this signal, the #GdkWindow associated to the widget
1986 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1988 * This signal will be sent to the grab widget if there is one.
1990 * Returns: %TRUE to stop other handlers from being invoked for the event.
1991 * %FALSE to propagate the event further.
1993 widget_signals[MOTION_NOTIFY_EVENT] =
1994 g_signal_new (I_("motion-notify-event"),
1995 G_TYPE_FROM_CLASS (klass),
1997 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1998 _gtk_boolean_handled_accumulator, NULL,
1999 _gtk_marshal_BOOLEAN__BOXED,
2001 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2002 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2003 _gtk_marshal_BOOLEAN__BOXEDv);
2006 * GtkWidget::composited-changed:
2007 * @widget: the object on which the signal is emitted
2009 * The ::composited-changed signal is emitted when the composited
2010 * status of @widget<!-- -->s screen changes.
2011 * See gdk_screen_is_composited().
2013 widget_signals[COMPOSITED_CHANGED] =
2014 g_signal_new (I_("composited-changed"),
2015 G_TYPE_FROM_CLASS (klass),
2016 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2017 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2019 _gtk_marshal_VOID__VOID,
2023 * GtkWidget::delete-event:
2024 * @widget: the object which received the signal
2025 * @event: the event which triggered this signal
2027 * The ::delete-event signal is emitted if a user requests that
2028 * a toplevel window is closed. The default handler for this signal
2029 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2030 * this signal will cause the window to be hidden instead, so that
2031 * it can later be shown again without reconstructing it.
2033 * Returns: %TRUE to stop other handlers from being invoked for the event.
2034 * %FALSE to propagate the event further.
2036 widget_signals[DELETE_EVENT] =
2037 g_signal_new (I_("delete-event"),
2038 G_TYPE_FROM_CLASS (klass),
2040 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2041 _gtk_boolean_handled_accumulator, NULL,
2042 _gtk_marshal_BOOLEAN__BOXED,
2044 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2045 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2046 _gtk_marshal_BOOLEAN__BOXEDv);
2049 * GtkWidget::destroy-event:
2050 * @widget: the object which received the signal.
2051 * @event: the event which triggered this signal
2053 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2054 * You rarely get this signal, because most widgets disconnect themselves
2055 * from their window before they destroy it, so no widget owns the
2056 * window at destroy time.
2058 * To receive this signal, the #GdkWindow associated to the widget needs
2059 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2060 * automatically for all new windows.
2062 * Returns: %TRUE to stop other handlers from being invoked for the event.
2063 * %FALSE to propagate the event further.
2065 widget_signals[DESTROY_EVENT] =
2066 g_signal_new (I_("destroy-event"),
2067 G_TYPE_FROM_CLASS (klass),
2069 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2070 _gtk_boolean_handled_accumulator, NULL,
2071 _gtk_marshal_BOOLEAN__BOXED,
2073 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2074 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2075 _gtk_marshal_BOOLEAN__BOXEDv);
2078 * GtkWidget::key-press-event:
2079 * @widget: the object which received the signal
2080 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2082 * The ::key-press-event signal is emitted when a key is pressed. The signal
2083 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2085 * To receive this signal, the #GdkWindow associated to the widget needs
2086 * to enable the #GDK_KEY_PRESS_MASK mask.
2088 * This signal will be sent to the grab widget if there is one.
2090 * Returns: %TRUE to stop other handlers from being invoked for the event.
2091 * %FALSE to propagate the event further.
2093 widget_signals[KEY_PRESS_EVENT] =
2094 g_signal_new (I_("key-press-event"),
2095 G_TYPE_FROM_CLASS (klass),
2097 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2098 _gtk_boolean_handled_accumulator, NULL,
2099 _gtk_marshal_BOOLEAN__BOXED,
2101 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2102 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2103 _gtk_marshal_BOOLEAN__BOXEDv);
2106 * GtkWidget::key-release-event:
2107 * @widget: the object which received the signal
2108 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2110 * The ::key-release-event signal is emitted when a key is released.
2112 * To receive this signal, the #GdkWindow associated to the widget needs
2113 * to enable the #GDK_KEY_RELEASE_MASK mask.
2115 * This signal will be sent to the grab widget if there is one.
2117 * Returns: %TRUE to stop other handlers from being invoked for the event.
2118 * %FALSE to propagate the event further.
2120 widget_signals[KEY_RELEASE_EVENT] =
2121 g_signal_new (I_("key-release-event"),
2122 G_TYPE_FROM_CLASS (klass),
2124 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2125 _gtk_boolean_handled_accumulator, NULL,
2126 _gtk_marshal_BOOLEAN__BOXED,
2128 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2129 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2130 _gtk_marshal_BOOLEAN__BOXEDv);
2133 * GtkWidget::enter-notify-event:
2134 * @widget: the object which received the signal
2135 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2138 * The ::enter-notify-event will be emitted when the pointer enters
2139 * the @widget's window.
2141 * To receive this signal, the #GdkWindow associated to the widget needs
2142 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2144 * This signal will be sent to the grab widget if there is one.
2146 * Returns: %TRUE to stop other handlers from being invoked for the event.
2147 * %FALSE to propagate the event further.
2149 widget_signals[ENTER_NOTIFY_EVENT] =
2150 g_signal_new (I_("enter-notify-event"),
2151 G_TYPE_FROM_CLASS (klass),
2153 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2154 _gtk_boolean_handled_accumulator, NULL,
2155 _gtk_marshal_BOOLEAN__BOXED,
2157 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2158 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2159 _gtk_marshal_BOOLEAN__BOXEDv);
2162 * GtkWidget::leave-notify-event:
2163 * @widget: the object which received the signal
2164 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2167 * The ::leave-notify-event will be emitted when the pointer leaves
2168 * the @widget's window.
2170 * To receive this signal, the #GdkWindow associated to the widget needs
2171 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2173 * This signal will be sent to the grab widget if there is one.
2175 * Returns: %TRUE to stop other handlers from being invoked for the event.
2176 * %FALSE to propagate the event further.
2178 widget_signals[LEAVE_NOTIFY_EVENT] =
2179 g_signal_new (I_("leave-notify-event"),
2180 G_TYPE_FROM_CLASS (klass),
2182 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2183 _gtk_boolean_handled_accumulator, NULL,
2184 _gtk_marshal_BOOLEAN__BOXED,
2186 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2187 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2188 _gtk_marshal_BOOLEAN__BOXEDv);
2191 * GtkWidget::configure-event:
2192 * @widget: the object which received the signal
2193 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2196 * The ::configure-event signal will be emitted when the size, position or
2197 * stacking of the @widget's window has changed.
2199 * To receive this signal, the #GdkWindow associated to the widget needs
2200 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2201 * automatically for all new windows.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event.
2204 * %FALSE to propagate the event further.
2206 widget_signals[CONFIGURE_EVENT] =
2207 g_signal_new (I_("configure-event"),
2208 G_TYPE_FROM_CLASS (klass),
2210 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2215 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2216 _gtk_marshal_BOOLEAN__BOXEDv);
2219 * GtkWidget::focus-in-event:
2220 * @widget: the object which received the signal
2221 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2224 * The ::focus-in-event signal will be emitted when the keyboard focus
2225 * enters the @widget's window.
2227 * To receive this signal, the #GdkWindow associated to the widget needs
2228 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[FOCUS_IN_EVENT] =
2234 g_signal_new (I_("focus-in-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2243 _gtk_marshal_BOOLEAN__BOXEDv);
2246 * GtkWidget::focus-out-event:
2247 * @widget: the object which received the signal
2248 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2251 * The ::focus-out-event signal will be emitted when the keyboard focus
2252 * leaves the @widget's window.
2254 * To receive this signal, the #GdkWindow associated to the widget needs
2255 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2257 * Returns: %TRUE to stop other handlers from being invoked for the event.
2258 * %FALSE to propagate the event further.
2260 widget_signals[FOCUS_OUT_EVENT] =
2261 g_signal_new (I_("focus-out-event"),
2262 G_TYPE_FROM_CLASS (klass),
2264 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2265 _gtk_boolean_handled_accumulator, NULL,
2266 _gtk_marshal_BOOLEAN__BOXED,
2268 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2269 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2270 _gtk_marshal_BOOLEAN__BOXEDv);
2273 * GtkWidget::map-event:
2274 * @widget: the object which received the signal
2275 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2277 * The ::map-event signal will be emitted when the @widget's window is
2278 * mapped. A window is mapped when it becomes visible on the screen.
2280 * To receive this signal, the #GdkWindow associated to the widget needs
2281 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2282 * automatically for all new windows.
2284 * Returns: %TRUE to stop other handlers from being invoked for the event.
2285 * %FALSE to propagate the event further.
2287 widget_signals[MAP_EVENT] =
2288 g_signal_new (I_("map-event"),
2289 G_TYPE_FROM_CLASS (klass),
2291 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2292 _gtk_boolean_handled_accumulator, NULL,
2293 _gtk_marshal_BOOLEAN__BOXED,
2295 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2296 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2297 _gtk_marshal_BOOLEAN__BOXEDv);
2300 * GtkWidget::unmap-event:
2301 * @widget: the object which received the signal
2302 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2304 * The ::unmap-event signal will be emitted when the @widget's window is
2305 * unmapped. A window is unmapped when it becomes invisible on the screen.
2307 * To receive this signal, the #GdkWindow associated to the widget needs
2308 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2309 * automatically for all new windows.
2311 * Returns: %TRUE to stop other handlers from being invoked for the event.
2312 * %FALSE to propagate the event further.
2314 widget_signals[UNMAP_EVENT] =
2315 g_signal_new (I_("unmap-event"),
2316 G_TYPE_FROM_CLASS (klass),
2318 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__BOXED,
2322 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2323 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2324 _gtk_marshal_BOOLEAN__BOXEDv);
2327 * GtkWidget::property-notify-event:
2328 * @widget: the object which received the signal
2329 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2332 * The ::property-notify-event signal will be emitted when a property on
2333 * the @widget's window has been changed or deleted.
2335 * To receive this signal, the #GdkWindow associated to the widget needs
2336 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2338 * Returns: %TRUE to stop other handlers from being invoked for the event.
2339 * %FALSE to propagate the event further.
2341 widget_signals[PROPERTY_NOTIFY_EVENT] =
2342 g_signal_new (I_("property-notify-event"),
2343 G_TYPE_FROM_CLASS (klass),
2345 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2346 _gtk_boolean_handled_accumulator, NULL,
2347 _gtk_marshal_BOOLEAN__BOXED,
2349 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2350 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2351 _gtk_marshal_BOOLEAN__BOXEDv);
2354 * GtkWidget::selection-clear-event:
2355 * @widget: the object which received the signal
2356 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2359 * The ::selection-clear-event signal will be emitted when the
2360 * the @widget's window has lost ownership of a selection.
2362 * Returns: %TRUE to stop other handlers from being invoked for the event.
2363 * %FALSE to propagate the event further.
2365 widget_signals[SELECTION_CLEAR_EVENT] =
2366 g_signal_new (I_("selection-clear-event"),
2367 G_TYPE_FROM_CLASS (klass),
2369 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2370 _gtk_boolean_handled_accumulator, NULL,
2371 _gtk_marshal_BOOLEAN__BOXED,
2373 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2374 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2375 _gtk_marshal_BOOLEAN__BOXEDv);
2378 * GtkWidget::selection-request-event:
2379 * @widget: the object which received the signal
2380 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2383 * The ::selection-request-event signal will be emitted when
2384 * another client requests ownership of the selection owned by
2385 * the @widget's window.
2387 * Returns: %TRUE to stop other handlers from being invoked for the event.
2388 * %FALSE to propagate the event further.
2390 widget_signals[SELECTION_REQUEST_EVENT] =
2391 g_signal_new (I_("selection-request-event"),
2392 G_TYPE_FROM_CLASS (klass),
2394 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2395 _gtk_boolean_handled_accumulator, NULL,
2396 _gtk_marshal_BOOLEAN__BOXED,
2398 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2399 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2400 _gtk_marshal_BOOLEAN__BOXEDv);
2403 * GtkWidget::selection-notify-event:
2404 * @widget: the object which received the signal.
2405 * @event: (type Gdk.EventSelection):
2407 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2409 widget_signals[SELECTION_NOTIFY_EVENT] =
2410 g_signal_new (I_("selection-notify-event"),
2411 G_TYPE_FROM_CLASS (klass),
2413 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2414 _gtk_boolean_handled_accumulator, NULL,
2415 _gtk_marshal_BOOLEAN__BOXED,
2417 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2418 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2419 _gtk_marshal_BOOLEAN__BOXEDv);
2422 * GtkWidget::selection-received:
2423 * @widget: the object which received the signal.
2427 widget_signals[SELECTION_RECEIVED] =
2428 g_signal_new (I_("selection-received"),
2429 G_TYPE_FROM_CLASS (klass),
2431 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2433 _gtk_marshal_VOID__BOXED_UINT,
2435 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2439 * GtkWidget::selection-get:
2440 * @widget: the object which received the signal.
2445 widget_signals[SELECTION_GET] =
2446 g_signal_new (I_("selection-get"),
2447 G_TYPE_FROM_CLASS (klass),
2449 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2451 _gtk_marshal_VOID__BOXED_UINT_UINT,
2453 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2458 * GtkWidget::proximity-in-event:
2459 * @widget: the object which received the signal
2460 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2463 * To receive this signal the #GdkWindow associated to the widget needs
2464 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2466 * This signal will be sent to the grab widget if there is one.
2468 * Returns: %TRUE to stop other handlers from being invoked for the event.
2469 * %FALSE to propagate the event further.
2471 widget_signals[PROXIMITY_IN_EVENT] =
2472 g_signal_new (I_("proximity-in-event"),
2473 G_TYPE_FROM_CLASS (klass),
2475 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2476 _gtk_boolean_handled_accumulator, NULL,
2477 _gtk_marshal_BOOLEAN__BOXED,
2479 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2480 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2481 _gtk_marshal_BOOLEAN__BOXEDv);
2484 * GtkWidget::proximity-out-event:
2485 * @widget: the object which received the signal
2486 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2489 * To receive this signal the #GdkWindow associated to the widget needs
2490 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2492 * This signal will be sent to the grab widget if there is one.
2494 * Returns: %TRUE to stop other handlers from being invoked for the event.
2495 * %FALSE to propagate the event further.
2497 widget_signals[PROXIMITY_OUT_EVENT] =
2498 g_signal_new (I_("proximity-out-event"),
2499 G_TYPE_FROM_CLASS (klass),
2501 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2502 _gtk_boolean_handled_accumulator, NULL,
2503 _gtk_marshal_BOOLEAN__BOXED,
2505 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2506 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2507 _gtk_marshal_BOOLEAN__BOXEDv);
2510 * GtkWidget::drag-leave:
2511 * @widget: the object which received the signal.
2512 * @context: the drag context
2513 * @time: the timestamp of the motion event
2515 * The ::drag-leave signal is emitted on the drop site when the cursor
2516 * leaves the widget. A typical reason to connect to this signal is to
2517 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2518 * with gtk_drag_unhighlight()
2520 widget_signals[DRAG_LEAVE] =
2521 g_signal_new (I_("drag-leave"),
2522 G_TYPE_FROM_CLASS (klass),
2524 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2526 _gtk_marshal_VOID__OBJECT_UINT,
2528 GDK_TYPE_DRAG_CONTEXT,
2532 * GtkWidget::drag-begin:
2533 * @widget: the object which received the signal
2534 * @context: the drag context
2536 * The ::drag-begin signal is emitted on the drag source when a drag is
2537 * started. A typical reason to connect to this signal is to set up a
2538 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2540 * Note that some widgets set up a drag icon in the default handler of
2541 * this signal, so you may have to use g_signal_connect_after() to
2542 * override what the default handler did.
2544 widget_signals[DRAG_BEGIN] =
2545 g_signal_new (I_("drag-begin"),
2546 G_TYPE_FROM_CLASS (klass),
2548 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2550 _gtk_marshal_VOID__OBJECT,
2552 GDK_TYPE_DRAG_CONTEXT);
2555 * GtkWidget::drag-end:
2556 * @widget: the object which received the signal
2557 * @context: the drag context
2559 * The ::drag-end signal is emitted on the drag source when a drag is
2560 * finished. A typical reason to connect to this signal is to undo
2561 * things done in #GtkWidget::drag-begin.
2563 widget_signals[DRAG_END] =
2564 g_signal_new (I_("drag-end"),
2565 G_TYPE_FROM_CLASS (klass),
2567 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2569 _gtk_marshal_VOID__OBJECT,
2571 GDK_TYPE_DRAG_CONTEXT);
2574 * GtkWidget::drag-data-delete:
2575 * @widget: the object which received the signal
2576 * @context: the drag context
2578 * The ::drag-data-delete signal is emitted on the drag source when a drag
2579 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2580 * handler is responsible for deleting the data that has been dropped. What
2581 * "delete" means depends on the context of the drag operation.
2583 widget_signals[DRAG_DATA_DELETE] =
2584 g_signal_new (I_("drag-data-delete"),
2585 G_TYPE_FROM_CLASS (klass),
2587 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2589 _gtk_marshal_VOID__OBJECT,
2591 GDK_TYPE_DRAG_CONTEXT);
2594 * GtkWidget::drag-failed:
2595 * @widget: the object which received the signal
2596 * @context: the drag context
2597 * @result: the result of the drag operation
2599 * The ::drag-failed signal is emitted on the drag source when a drag has
2600 * failed. The signal handler may hook custom code to handle a failed DND
2601 * operation based on the type of error, it returns %TRUE is the failure has
2602 * been already handled (not showing the default "drag operation failed"
2603 * animation), otherwise it returns %FALSE.
2605 * Return value: %TRUE if the failed drag operation has been already handled.
2609 widget_signals[DRAG_FAILED] =
2610 g_signal_new (I_("drag-failed"),
2611 G_TYPE_FROM_CLASS (klass),
2613 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2614 _gtk_boolean_handled_accumulator, NULL,
2615 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2617 GDK_TYPE_DRAG_CONTEXT,
2618 GTK_TYPE_DRAG_RESULT);
2621 * GtkWidget::drag-motion:
2622 * @widget: the object which received the signal
2623 * @context: the drag context
2624 * @x: the x coordinate of the current cursor position
2625 * @y: the y coordinate of the current cursor position
2626 * @time: the timestamp of the motion event
2628 * The ::drag-motion signal is emitted on the drop site when the user
2629 * moves the cursor over the widget during a drag. The signal handler
2630 * must determine whether the cursor position is in a drop zone or not.
2631 * If it is not in a drop zone, it returns %FALSE and no further processing
2632 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2633 * handler is responsible for providing the necessary information for
2634 * displaying feedback to the user, by calling gdk_drag_status().
2636 * If the decision whether the drop will be accepted or rejected can't be
2637 * made based solely on the cursor position and the type of the data, the
2638 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2639 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2640 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2641 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2642 * when using the drag-motion signal that way.
2644 * Also note that there is no drag-enter signal. The drag receiver has to
2645 * keep track of whether he has received any drag-motion signals since the
2646 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2647 * an "enter" signal. Upon an "enter", the handler will typically highlight
2648 * the drop site with gtk_drag_highlight().
2651 * drag_motion (GtkWidget *widget,
2652 * GdkDragContext *context,
2659 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2661 * if (!private_data->drag_highlight)
2663 * private_data->drag_highlight = 1;
2664 * gtk_drag_highlight (widget);
2667 * target = gtk_drag_dest_find_target (widget, context, NULL);
2668 * if (target == GDK_NONE)
2669 * gdk_drag_status (context, 0, time);
2672 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2673 * gtk_drag_get_data (widget, context, target, time);
2680 * drag_data_received (GtkWidget *widget,
2681 * GdkDragContext *context,
2684 * GtkSelectionData *selection_data,
2688 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2690 * if (private_data->suggested_action)
2692 * private_data->suggested_action = 0;
2694 * /* We are getting this data due to a request in drag_motion,
2695 * * rather than due to a request in drag_drop, so we are just
2696 * * supposed to call gdk_drag_status(), not actually paste in
2699 * str = gtk_selection_data_get_text (selection_data);
2700 * if (!data_is_acceptable (str))
2701 * gdk_drag_status (context, 0, time);
2703 * gdk_drag_status (context, private_data->suggested_action, time);
2707 * /* accept the drop */
2712 * Returns: whether the cursor position is in a drop zone
2714 widget_signals[DRAG_MOTION] =
2715 g_signal_new (I_("drag-motion"),
2716 G_TYPE_FROM_CLASS (klass),
2718 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2719 _gtk_boolean_handled_accumulator, NULL,
2720 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2722 GDK_TYPE_DRAG_CONTEXT,
2728 * GtkWidget::drag-drop:
2729 * @widget: the object which received the signal
2730 * @context: the drag context
2731 * @x: the x coordinate of the current cursor position
2732 * @y: the y coordinate of the current cursor position
2733 * @time: the timestamp of the motion event
2735 * The ::drag-drop signal is emitted on the drop site when the user drops
2736 * the data onto the widget. The signal handler must determine whether
2737 * the cursor position is in a drop zone or not. If it is not in a drop
2738 * zone, it returns %FALSE and no further processing is necessary.
2739 * Otherwise, the handler returns %TRUE. In this case, the handler must
2740 * ensure that gtk_drag_finish() is called to let the source know that
2741 * the drop is done. The call to gtk_drag_finish() can be done either
2742 * directly or in a #GtkWidget::drag-data-received handler which gets
2743 * triggered by calling gtk_drag_get_data() to receive the data for one
2744 * or more of the supported targets.
2746 * Returns: whether the cursor position is in a drop zone
2748 widget_signals[DRAG_DROP] =
2749 g_signal_new (I_("drag-drop"),
2750 G_TYPE_FROM_CLASS (klass),
2752 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2753 _gtk_boolean_handled_accumulator, NULL,
2754 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2756 GDK_TYPE_DRAG_CONTEXT,
2762 * GtkWidget::drag-data-get:
2763 * @widget: the object which received the signal
2764 * @context: the drag context
2765 * @data: the #GtkSelectionData to be filled with the dragged data
2766 * @info: the info that has been registered with the target in the
2768 * @time: the timestamp at which the data was requested
2770 * The ::drag-data-get signal is emitted on the drag source when the drop
2771 * site requests the data which is dragged. It is the responsibility of
2772 * the signal handler to fill @data with the data in the format which
2773 * is indicated by @info. See gtk_selection_data_set() and
2774 * gtk_selection_data_set_text().
2776 widget_signals[DRAG_DATA_GET] =
2777 g_signal_new (I_("drag-data-get"),
2778 G_TYPE_FROM_CLASS (klass),
2780 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2782 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2784 GDK_TYPE_DRAG_CONTEXT,
2785 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2790 * GtkWidget::drag-data-received:
2791 * @widget: the object which received the signal
2792 * @context: the drag context
2793 * @x: where the drop happened
2794 * @y: where the drop happened
2795 * @data: the received data
2796 * @info: the info that has been registered with the target in the
2798 * @time: the timestamp at which the data was received
2800 * The ::drag-data-received signal is emitted on the drop site when the
2801 * dragged data has been received. If the data was received in order to
2802 * determine whether the drop will be accepted, the handler is expected
2803 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2804 * If the data was received in response to a #GtkWidget::drag-drop signal
2805 * (and this is the last target to be received), the handler for this
2806 * signal is expected to process the received data and then call
2807 * gtk_drag_finish(), setting the @success parameter depending on
2808 * whether the data was processed successfully.
2810 * The handler may inspect the selected action with
2811 * gdk_drag_context_get_selected_action() before calling
2812 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2813 * shown in the following example:
2816 * drag_data_received (GtkWidget *widget,
2817 * GdkDragContext *context,
2820 * GtkSelectionData *data,
2824 * if ((data->length >= 0) && (data->format == 8))
2826 * GdkDragAction action;
2828 * /* handle data here */
2830 * action = gdk_drag_context_get_selected_action (context);
2831 * if (action == GDK_ACTION_ASK)
2833 * GtkWidget *dialog;
2836 * dialog = gtk_message_dialog_new (NULL,
2837 * GTK_DIALOG_MODAL |
2838 * GTK_DIALOG_DESTROY_WITH_PARENT,
2840 * GTK_BUTTONS_YES_NO,
2841 * "Move the data ?\n");
2842 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2843 * gtk_widget_destroy (dialog);
2845 * if (response == GTK_RESPONSE_YES)
2846 * action = GDK_ACTION_MOVE;
2848 * action = GDK_ACTION_COPY;
2851 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2854 * gtk_drag_finish (context, FALSE, FALSE, time);
2858 widget_signals[DRAG_DATA_RECEIVED] =
2859 g_signal_new (I_("drag-data-received"),
2860 G_TYPE_FROM_CLASS (klass),
2862 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2864 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2866 GDK_TYPE_DRAG_CONTEXT,
2869 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2874 * GtkWidget::visibility-notify-event:
2875 * @widget: the object which received the signal
2876 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2877 * triggered this signal.
2879 * The ::visibility-notify-event will be emitted when the @widget's window
2880 * is obscured or unobscured.
2882 * To receive this signal the #GdkWindow associated to the widget needs
2883 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2885 * Returns: %TRUE to stop other handlers from being invoked for the event.
2886 * %FALSE to propagate the event further.
2888 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2889 g_signal_new (I_("visibility-notify-event"),
2890 G_TYPE_FROM_CLASS (klass),
2892 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2893 _gtk_boolean_handled_accumulator, NULL,
2894 _gtk_marshal_BOOLEAN__BOXED,
2896 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2899 * GtkWidget::window-state-event:
2900 * @widget: the object which received the signal
2901 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2902 * triggered this signal.
2904 * The ::window-state-event will be emitted when the state of the
2905 * toplevel window associated to the @widget changes.
2907 * To receive this signal the #GdkWindow associated to the widget
2908 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2909 * this mask automatically for all new windows.
2911 * Returns: %TRUE to stop other handlers from being invoked for the
2912 * event. %FALSE to propagate the event further.
2914 widget_signals[WINDOW_STATE_EVENT] =
2915 g_signal_new (I_("window-state-event"),
2916 G_TYPE_FROM_CLASS (klass),
2918 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2919 _gtk_boolean_handled_accumulator, NULL,
2920 _gtk_marshal_BOOLEAN__BOXED,
2922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2923 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2924 _gtk_marshal_BOOLEAN__BOXEDv);
2927 * GtkWidget::damage-event:
2928 * @widget: the object which received the signal
2929 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2931 * Emitted when a redirected window belonging to @widget gets drawn into.
2932 * The region/area members of the event shows what area of the redirected
2933 * drawable was drawn into.
2935 * Returns: %TRUE to stop other handlers from being invoked for the event.
2936 * %FALSE to propagate the event further.
2940 widget_signals[DAMAGE_EVENT] =
2941 g_signal_new (I_("damage-event"),
2942 G_TYPE_FROM_CLASS (klass),
2944 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2945 _gtk_boolean_handled_accumulator, NULL,
2946 _gtk_marshal_BOOLEAN__BOXED,
2948 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2949 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
2950 _gtk_marshal_BOOLEAN__BOXEDv);
2953 * GtkWidget::grab-broken-event:
2954 * @widget: the object which received the signal
2955 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2957 * Emitted when a pointer or keyboard grab on a window belonging
2958 * to @widget gets broken.
2960 * On X11, this happens when the grab window becomes unviewable
2961 * (i.e. it or one of its ancestors is unmapped), or if the same
2962 * application grabs the pointer or keyboard again.
2964 * Returns: %TRUE to stop other handlers from being invoked for
2965 * the event. %FALSE to propagate the event further.
2969 widget_signals[GRAB_BROKEN_EVENT] =
2970 g_signal_new (I_("grab-broken-event"),
2971 G_TYPE_FROM_CLASS (klass),
2973 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2974 _gtk_boolean_handled_accumulator, NULL,
2975 _gtk_marshal_BOOLEAN__BOXED,
2977 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2978 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
2979 _gtk_marshal_BOOLEAN__BOXEDv);
2982 * GtkWidget::query-tooltip:
2983 * @widget: the object which received the signal
2984 * @x: the x coordinate of the cursor position where the request has
2985 * been emitted, relative to @widget's left side
2986 * @y: the y coordinate of the cursor position where the request has
2987 * been emitted, relative to @widget's top
2988 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2989 * @tooltip: a #GtkTooltip
2991 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2992 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2993 * focus in keyboard mode.
2995 * Using the given coordinates, the signal handler should determine
2996 * whether a tooltip should be shown for @widget. If this is the case
2997 * %TRUE should be returned, %FALSE otherwise. Note that if
2998 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2999 * should not be used.
3001 * The signal handler is free to manipulate @tooltip with the therefore
3002 * destined function calls.
3004 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3008 widget_signals[QUERY_TOOLTIP] =
3009 g_signal_new (I_("query-tooltip"),
3010 G_TYPE_FROM_CLASS (klass),
3012 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3013 _gtk_boolean_handled_accumulator, NULL,
3014 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3022 * GtkWidget::popup-menu:
3023 * @widget: the object which received the signal
3025 * This signal gets emitted whenever a widget should pop up a context
3026 * menu. This usually happens through the standard key binding mechanism;
3027 * by pressing a certain key while a widget is focused, the user can cause
3028 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3029 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3030 * for an example of how to use this signal.
3032 * Returns: %TRUE if a menu was activated
3034 widget_signals[POPUP_MENU] =
3035 g_signal_new (I_("popup-menu"),
3036 G_TYPE_FROM_CLASS (klass),
3037 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3038 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3039 _gtk_boolean_handled_accumulator, NULL,
3040 _gtk_marshal_BOOLEAN__VOID,
3044 * GtkWidget::show-help:
3045 * @widget: the object which received the signal.
3048 * Returns: %TRUE to stop other handlers from being invoked for the event.
3049 * %FALSE to propagate the event further.
3051 widget_signals[SHOW_HELP] =
3052 g_signal_new (I_("show-help"),
3053 G_TYPE_FROM_CLASS (klass),
3054 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3055 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3056 _gtk_boolean_handled_accumulator, NULL,
3057 _gtk_marshal_BOOLEAN__ENUM,
3059 GTK_TYPE_WIDGET_HELP_TYPE);
3062 * GtkWidget::accel-closures-changed:
3063 * @widget: the object which received the signal.
3065 widget_signals[ACCEL_CLOSURES_CHANGED] =
3066 g_signal_new (I_("accel-closures-changed"),
3067 G_TYPE_FROM_CLASS (klass),
3071 _gtk_marshal_VOID__VOID,
3075 * GtkWidget::screen-changed:
3076 * @widget: the object on which the signal is emitted
3077 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3078 * widget was not associated with a screen before
3080 * The ::screen-changed signal gets emitted when the
3081 * screen of a widget has changed.
3083 widget_signals[SCREEN_CHANGED] =
3084 g_signal_new (I_("screen-changed"),
3085 G_TYPE_FROM_CLASS (klass),
3087 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3089 _gtk_marshal_VOID__OBJECT,
3094 * GtkWidget::can-activate-accel:
3095 * @widget: the object which received the signal
3096 * @signal_id: the ID of a signal installed on @widget
3098 * Determines whether an accelerator that activates the signal
3099 * identified by @signal_id can currently be activated.
3100 * This signal is present to allow applications and derived
3101 * widgets to override the default #GtkWidget handling
3102 * for determining whether an accelerator can be activated.
3104 * Returns: %TRUE if the signal can be activated.
3106 widget_signals[CAN_ACTIVATE_ACCEL] =
3107 g_signal_new (I_("can-activate-accel"),
3108 G_TYPE_FROM_CLASS (klass),
3110 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3111 _gtk_boolean_handled_accumulator, NULL,
3112 _gtk_marshal_BOOLEAN__UINT,
3113 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3115 binding_set = gtk_binding_set_by_class (klass);
3116 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3118 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3121 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3123 GTK_TYPE_WIDGET_HELP_TYPE,
3124 GTK_WIDGET_HELP_TOOLTIP);
3125 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3127 GTK_TYPE_WIDGET_HELP_TYPE,
3128 GTK_WIDGET_HELP_TOOLTIP);
3129 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3131 GTK_TYPE_WIDGET_HELP_TYPE,
3132 GTK_WIDGET_HELP_WHATS_THIS);
3133 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3135 GTK_TYPE_WIDGET_HELP_TYPE,
3136 GTK_WIDGET_HELP_WHATS_THIS);
3138 gtk_widget_class_install_style_property (klass,
3139 g_param_spec_boolean ("interior-focus",
3140 P_("Interior Focus"),
3141 P_("Whether to draw the focus indicator inside widgets"),
3143 GTK_PARAM_READABLE));
3145 gtk_widget_class_install_style_property (klass,
3146 g_param_spec_int ("focus-line-width",
3147 P_("Focus linewidth"),
3148 P_("Width, in pixels, of the focus indicator line"),
3150 GTK_PARAM_READABLE));
3152 gtk_widget_class_install_style_property (klass,
3153 g_param_spec_string ("focus-line-pattern",
3154 P_("Focus line dash pattern"),
3155 P_("Dash pattern used to draw the focus indicator"),
3157 GTK_PARAM_READABLE));
3158 gtk_widget_class_install_style_property (klass,
3159 g_param_spec_int ("focus-padding",
3160 P_("Focus padding"),
3161 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3163 GTK_PARAM_READABLE));
3164 gtk_widget_class_install_style_property (klass,
3165 g_param_spec_boxed ("cursor-color",
3167 P_("Color with which to draw insertion cursor"),
3169 GTK_PARAM_READABLE));
3170 gtk_widget_class_install_style_property (klass,
3171 g_param_spec_boxed ("secondary-cursor-color",
3172 P_("Secondary cursor color"),
3173 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3175 GTK_PARAM_READABLE));
3176 gtk_widget_class_install_style_property (klass,
3177 g_param_spec_float ("cursor-aspect-ratio",
3178 P_("Cursor line aspect ratio"),
3179 P_("Aspect ratio with which to draw insertion cursor"),
3181 GTK_PARAM_READABLE));
3183 gtk_widget_class_install_style_property (klass,
3184 g_param_spec_boolean ("window-dragging",
3185 P_("Window dragging"),
3186 P_("Whether windows can be dragged by clicking on empty areas"),
3188 GTK_PARAM_READABLE));
3191 * GtkWidget:link-color:
3193 * The "link-color" style property defines the color of unvisited links.
3197 gtk_widget_class_install_style_property (klass,
3198 g_param_spec_boxed ("link-color",
3199 P_("Unvisited Link Color"),
3200 P_("Color of unvisited links"),
3202 GTK_PARAM_READABLE));
3205 * GtkWidget:visited-link-color:
3207 * The "visited-link-color" style property defines the color of visited links.
3211 gtk_widget_class_install_style_property (klass,
3212 g_param_spec_boxed ("visited-link-color",
3213 P_("Visited Link Color"),
3214 P_("Color of visited links"),
3216 GTK_PARAM_READABLE));
3219 * GtkWidget:wide-separators:
3221 * The "wide-separators" style property defines whether separators have
3222 * configurable width and should be drawn using a box instead of a line.
3226 gtk_widget_class_install_style_property (klass,
3227 g_param_spec_boolean ("wide-separators",
3228 P_("Wide Separators"),
3229 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3231 GTK_PARAM_READABLE));
3234 * GtkWidget:separator-width:
3236 * The "separator-width" style property defines the width of separators.
3237 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3241 gtk_widget_class_install_style_property (klass,
3242 g_param_spec_int ("separator-width",
3243 P_("Separator Width"),
3244 P_("The width of separators if wide-separators is TRUE"),
3246 GTK_PARAM_READABLE));
3249 * GtkWidget:separator-height:
3251 * The "separator-height" style property defines the height of separators.
3252 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3256 gtk_widget_class_install_style_property (klass,
3257 g_param_spec_int ("separator-height",
3258 P_("Separator Height"),
3259 P_("The height of separators if \"wide-separators\" is TRUE"),
3261 GTK_PARAM_READABLE));
3264 * GtkWidget:scroll-arrow-hlength:
3266 * The "scroll-arrow-hlength" style property defines the length of
3267 * horizontal scroll arrows.
3271 gtk_widget_class_install_style_property (klass,
3272 g_param_spec_int ("scroll-arrow-hlength",
3273 P_("Horizontal Scroll Arrow Length"),
3274 P_("The length of horizontal scroll arrows"),
3276 GTK_PARAM_READABLE));
3279 * GtkWidget:scroll-arrow-vlength:
3281 * The "scroll-arrow-vlength" style property defines the length of
3282 * vertical scroll arrows.
3286 gtk_widget_class_install_style_property (klass,
3287 g_param_spec_int ("scroll-arrow-vlength",
3288 P_("Vertical Scroll Arrow Length"),
3289 P_("The length of vertical scroll arrows"),
3291 GTK_PARAM_READABLE));
3293 gtk_widget_class_install_style_property (klass,
3294 g_param_spec_int ("text-handle-width",
3295 P_("Width of text selection handles"),
3296 P_("Width of text selection handles"),
3298 GTK_PARAM_READABLE));
3299 gtk_widget_class_install_style_property (klass,
3300 g_param_spec_int ("text-handle-height",
3301 P_("Height of text selection handles"),
3302 P_("Height of text selection handles"),
3304 GTK_PARAM_READABLE));
3306 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3308 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3312 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3316 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3317 for (node = list; node; node = node->next)
3319 GParamSpec *pspec = node->data;
3321 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3322 g_param_spec_unref (pspec);
3328 gtk_widget_set_property (GObject *object,
3330 const GValue *value,
3333 GtkWidget *widget = GTK_WIDGET (object);
3338 gchar *tooltip_markup;
3339 const gchar *tooltip_text;
3340 GtkWindow *tooltip_window;
3343 gtk_widget_set_name (widget, g_value_get_string (value));
3346 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3348 case PROP_WIDTH_REQUEST:
3349 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3351 case PROP_HEIGHT_REQUEST:
3352 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3355 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3357 case PROP_SENSITIVE:
3358 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3360 case PROP_APP_PAINTABLE:
3361 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3363 case PROP_CAN_FOCUS:
3364 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3366 case PROP_HAS_FOCUS:
3367 if (g_value_get_boolean (value))
3368 gtk_widget_grab_focus (widget);
3371 if (g_value_get_boolean (value))
3372 gtk_widget_grab_focus (widget);
3374 case PROP_CAN_DEFAULT:
3375 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3377 case PROP_HAS_DEFAULT:
3378 if (g_value_get_boolean (value))
3379 gtk_widget_grab_default (widget);
3381 case PROP_RECEIVES_DEFAULT:
3382 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3385 gtk_widget_set_style (widget, g_value_get_object (value));
3388 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3389 gtk_widget_set_events (widget, g_value_get_flags (value));
3391 case PROP_NO_SHOW_ALL:
3392 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3394 case PROP_HAS_TOOLTIP:
3395 gtk_widget_real_set_has_tooltip (widget,
3396 g_value_get_boolean (value), FALSE);
3398 case PROP_TOOLTIP_MARKUP:
3399 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3400 tooltip_markup = g_value_dup_string (value);
3402 /* Treat an empty string as a NULL string,
3403 * because an empty string would be useless for a tooltip:
3405 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3407 g_free (tooltip_markup);
3408 tooltip_markup = NULL;
3411 g_object_set_qdata_full (object, quark_tooltip_markup,
3412 tooltip_markup, g_free);
3414 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3415 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3416 if (gtk_widget_get_visible (widget))
3417 gtk_widget_queue_tooltip_query (widget);
3419 case PROP_TOOLTIP_TEXT:
3420 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3422 tooltip_text = g_value_get_string (value);
3424 /* Treat an empty string as a NULL string,
3425 * because an empty string would be useless for a tooltip:
3427 if (tooltip_text && (strlen (tooltip_text) == 0))
3428 tooltip_text = NULL;
3430 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3432 g_object_set_qdata_full (object, quark_tooltip_markup,
3433 tooltip_markup, g_free);
3435 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3436 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3437 if (gtk_widget_get_visible (widget))
3438 gtk_widget_queue_tooltip_query (widget);
3440 case PROP_DOUBLE_BUFFERED:
3441 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3444 gtk_widget_set_halign (widget, g_value_get_enum (value));
3447 gtk_widget_set_valign (widget, g_value_get_enum (value));
3449 case PROP_MARGIN_LEFT:
3450 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3452 case PROP_MARGIN_RIGHT:
3453 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3455 case PROP_MARGIN_TOP:
3456 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3458 case PROP_MARGIN_BOTTOM:
3459 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3462 g_object_freeze_notify (G_OBJECT (widget));
3463 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3464 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3465 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3466 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3467 g_object_thaw_notify (G_OBJECT (widget));
3470 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3472 case PROP_HEXPAND_SET:
3473 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3476 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3478 case PROP_VEXPAND_SET:
3479 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3482 g_object_freeze_notify (G_OBJECT (widget));
3483 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3484 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3485 g_object_thaw_notify (G_OBJECT (widget));
3488 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3494 gtk_widget_get_property (GObject *object,
3499 GtkWidget *widget = GTK_WIDGET (object);
3500 GtkWidgetPrivate *priv = widget->priv;
3508 g_value_set_string (value, priv->name);
3510 g_value_set_static_string (value, "");
3513 g_value_set_object (value, priv->parent);
3515 case PROP_WIDTH_REQUEST:
3518 gtk_widget_get_size_request (widget, &w, NULL);
3519 g_value_set_int (value, w);
3522 case PROP_HEIGHT_REQUEST:
3525 gtk_widget_get_size_request (widget, NULL, &h);
3526 g_value_set_int (value, h);
3530 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3532 case PROP_SENSITIVE:
3533 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3535 case PROP_APP_PAINTABLE:
3536 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3538 case PROP_CAN_FOCUS:
3539 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3541 case PROP_HAS_FOCUS:
3542 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3545 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3547 case PROP_CAN_DEFAULT:
3548 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3550 case PROP_HAS_DEFAULT:
3551 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3553 case PROP_RECEIVES_DEFAULT:
3554 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3556 case PROP_COMPOSITE_CHILD:
3557 g_value_set_boolean (value, widget->priv->composite_child);
3560 g_value_set_object (value, gtk_widget_get_style (widget));
3563 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3564 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3566 case PROP_NO_SHOW_ALL:
3567 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3569 case PROP_HAS_TOOLTIP:
3570 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3572 case PROP_TOOLTIP_TEXT:
3574 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3577 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3578 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3580 g_value_take_string (value, text);
3583 case PROP_TOOLTIP_MARKUP:
3584 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3587 g_value_set_object (value, gtk_widget_get_window (widget));
3589 case PROP_DOUBLE_BUFFERED:
3590 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3593 g_value_set_enum (value, gtk_widget_get_halign (widget));
3596 g_value_set_enum (value, gtk_widget_get_valign (widget));
3598 case PROP_MARGIN_LEFT:
3599 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3601 case PROP_MARGIN_RIGHT:
3602 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3604 case PROP_MARGIN_TOP:
3605 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3607 case PROP_MARGIN_BOTTOM:
3608 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3612 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3613 if (aux_info == NULL)
3615 g_value_set_int (value, 0);
3619 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3620 aux_info->margin.right),
3621 MAX (aux_info->margin.top,
3622 aux_info->margin.bottom)));
3627 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3629 case PROP_HEXPAND_SET:
3630 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3633 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3635 case PROP_VEXPAND_SET:
3636 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3639 g_value_set_boolean (value,
3640 gtk_widget_get_hexpand (widget) &&
3641 gtk_widget_get_vexpand (widget));
3644 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3650 gtk_widget_init (GtkWidget *widget)
3652 GtkWidgetPrivate *priv;
3654 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3657 priv = widget->priv;
3659 priv->child_visible = TRUE;
3661 priv->allocation.x = -1;
3662 priv->allocation.y = -1;
3663 priv->allocation.width = 1;
3664 priv->allocation.height = 1;
3665 priv->window = NULL;
3666 priv->parent = NULL;
3668 priv->sensitive = TRUE;
3669 priv->composite_child = composite_child_stack != 0;
3670 priv->double_buffered = TRUE;
3671 priv->redraw_on_alloc = TRUE;
3672 priv->alloc_needed = TRUE;
3674 switch (gtk_widget_get_direction (widget))
3676 case GTK_TEXT_DIR_LTR:
3677 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3680 case GTK_TEXT_DIR_RTL:
3681 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3684 case GTK_TEXT_DIR_NONE:
3686 g_assert_not_reached ();
3691 /* this will be set to TRUE if the widget gets a child or if the
3692 * expand flag is set on the widget, but until one of those happen
3693 * we know the expand is already properly FALSE.
3695 * We really want to default FALSE here to avoid computing expand
3696 * all over the place while initially building a widget tree.
3698 priv->need_compute_expand = FALSE;
3700 _gtk_size_request_cache_init (&priv->requests);
3702 priv->style = gtk_widget_get_default_style ();
3703 g_object_ref (priv->style);
3708 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3710 GParamSpec **pspecs)
3712 GtkWidgetPrivate *priv = widget->priv;
3713 GtkWidget *container = priv->parent;
3716 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3717 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3721 * gtk_widget_freeze_child_notify:
3722 * @widget: a #GtkWidget
3724 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3725 * signals are queued until gtk_widget_thaw_child_notify() is called
3728 * This is the analogue of g_object_freeze_notify() for child properties.
3731 gtk_widget_freeze_child_notify (GtkWidget *widget)
3733 g_return_if_fail (GTK_IS_WIDGET (widget));
3735 if (!G_OBJECT (widget)->ref_count)
3738 g_object_ref (widget);
3739 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3740 g_object_unref (widget);
3744 * gtk_widget_child_notify:
3745 * @widget: a #GtkWidget
3746 * @child_property: the name of a child property installed on the
3747 * class of @widget<!-- -->'s parent
3749 * Emits a #GtkWidget::child-notify signal for the
3750 * <link linkend="child-properties">child property</link> @child_property
3753 * This is the analogue of g_object_notify() for child properties.
3755 * Also see gtk_container_child_notify().
3758 gtk_widget_child_notify (GtkWidget *widget,
3759 const gchar *child_property)
3761 if (widget->priv->parent == NULL)
3764 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3768 * gtk_widget_thaw_child_notify:
3769 * @widget: a #GtkWidget
3771 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3772 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3776 gtk_widget_thaw_child_notify (GtkWidget *widget)
3778 GObjectNotifyQueue *nqueue;
3780 g_return_if_fail (GTK_IS_WIDGET (widget));
3782 if (!G_OBJECT (widget)->ref_count)
3785 g_object_ref (widget);
3786 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3787 if (!nqueue || !nqueue->freeze_count)
3788 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3789 G_OBJECT_TYPE_NAME (widget), widget);
3791 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3792 g_object_unref (widget);
3798 * @type: type ID of the widget to create
3799 * @first_property_name: name of first property to set
3800 * @...: value of first property, followed by more properties,
3803 * This is a convenience function for creating a widget and setting
3804 * its properties in one go. For example you might write:
3805 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3806 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3807 * g_object_new(), but returns a widget so you don't have to
3808 * cast the object yourself.
3810 * Return value: a new #GtkWidget of type @widget_type
3813 gtk_widget_new (GType type,
3814 const gchar *first_property_name,
3820 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3822 va_start (var_args, first_property_name);
3823 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3830 gtk_widget_queue_draw_child (GtkWidget *widget)
3832 GtkWidgetPrivate *priv = widget->priv;
3835 parent = priv->parent;
3836 if (parent && gtk_widget_is_drawable (parent))
3837 gtk_widget_queue_draw_area (parent,
3840 priv->allocation.width,
3841 priv->allocation.height);
3845 * gtk_widget_unparent:
3846 * @widget: a #GtkWidget
3848 * This function is only for use in widget implementations.
3849 * Should be called by implementations of the remove method
3850 * on #GtkContainer, to dissociate a child from the container.
3853 gtk_widget_unparent (GtkWidget *widget)
3855 GtkWidgetPrivate *priv;
3856 GObjectNotifyQueue *nqueue;
3857 GtkWidget *toplevel;
3858 GtkWidget *old_parent;
3860 g_return_if_fail (GTK_IS_WIDGET (widget));
3862 priv = widget->priv;
3864 if (priv->parent == NULL)
3867 /* keep this function in sync with gtk_menu_detach() */
3869 gtk_widget_push_verify_invariants (widget);
3871 g_object_freeze_notify (G_OBJECT (widget));
3872 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3874 toplevel = gtk_widget_get_toplevel (widget);
3875 if (gtk_widget_is_toplevel (toplevel))
3876 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3878 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3879 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3881 gtk_widget_queue_draw_child (widget);
3883 /* Reset the width and height here, to force reallocation if we
3884 * get added back to a new parent. This won't work if our new
3885 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3886 * (would 0x0 be OK here?)
3888 priv->allocation.width = 1;
3889 priv->allocation.height = 1;
3891 if (gtk_widget_get_realized (widget))
3893 if (priv->in_reparent)
3894 gtk_widget_unmap (widget);
3896 gtk_widget_unrealize (widget);
3899 /* If we are unanchoring the child, we save around the toplevel
3900 * to emit hierarchy changed
3902 if (priv->parent->priv->anchored)
3903 g_object_ref (toplevel);
3907 /* Removing a widget from a container restores the child visible
3908 * flag to the default state, so it doesn't affect the child
3909 * in the next parent.
3911 priv->child_visible = TRUE;
3913 old_parent = priv->parent;
3914 priv->parent = NULL;
3916 /* parent may no longer expand if the removed
3917 * child was expand=TRUE and could therefore
3920 if (gtk_widget_get_visible (widget) &&
3921 (priv->need_compute_expand ||
3922 priv->computed_hexpand ||
3923 priv->computed_vexpand))
3925 gtk_widget_queue_compute_expand (old_parent);
3928 /* Unset BACKDROP since we are no longer inside a toplevel window */
3929 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
3931 gtk_style_context_set_parent (priv->context, NULL);
3933 _gtk_widget_update_parent_muxer (widget);
3935 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3938 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3939 g_object_unref (toplevel);
3942 /* Now that the parent pointer is nullified and the hierarchy-changed
3943 * already passed, go ahead and unset the parent window, if we are unparenting
3944 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3945 * will fire again for the new subhierarchy.
3947 gtk_widget_set_parent_window (widget, NULL);
3949 g_object_notify (G_OBJECT (widget), "parent");
3950 g_object_thaw_notify (G_OBJECT (widget));
3952 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3953 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3955 gtk_widget_pop_verify_invariants (widget);
3956 g_object_unref (widget);
3960 * gtk_widget_destroy:
3961 * @widget: a #GtkWidget
3963 * Destroys a widget.
3966 * destroyed, it will break any references it holds to other objects.
3967 * If the widget is inside a container, the widget will be removed
3968 * from the container. If the widget is a toplevel (derived from
3969 * #GtkWindow), it will be removed from the list of toplevels, and the
3970 * reference GTK+ holds to it will be removed. Removing a
3971 * widget from its container or the list of toplevels results in the
3972 * widget being finalized, unless you've added additional references
3973 * to the widget with g_object_ref().
3975 * In most cases, only toplevel widgets (windows) require explicit
3976 * destruction, because when you destroy a toplevel its children will
3977 * be destroyed as well.
3980 gtk_widget_destroy (GtkWidget *widget)
3982 g_return_if_fail (GTK_IS_WIDGET (widget));
3984 if (!widget->priv->in_destruction)
3985 g_object_run_dispose (G_OBJECT (widget));
3989 * gtk_widget_destroyed:
3990 * @widget: a #GtkWidget
3991 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3993 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3994 * %NULL. It's intended to be used as a callback connected to the
3995 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3996 * as a signal handler, and pass the address of your widget variable
3997 * as user data. Then when the widget is destroyed, the variable will
3998 * be set to %NULL. Useful for example to avoid multiple copies
3999 * of the same dialog.
4002 gtk_widget_destroyed (GtkWidget *widget,
4003 GtkWidget **widget_pointer)
4005 /* Don't make any assumptions about the
4007 * Even check widget_pointer.
4010 *widget_pointer = NULL;
4015 * @widget: a #GtkWidget
4017 * Flags a widget to be displayed. Any widget that isn't shown will
4018 * not appear on the screen. If you want to show all the widgets in a
4019 * container, it's easier to call gtk_widget_show_all() on the
4020 * container, instead of individually showing the widgets.
4022 * Remember that you have to show the containers containing a widget,
4023 * in addition to the widget itself, before it will appear onscreen.
4025 * When a toplevel container is shown, it is immediately realized and
4026 * mapped; other shown widgets are realized and mapped when their
4027 * toplevel container is realized and mapped.
4030 gtk_widget_show (GtkWidget *widget)
4032 g_return_if_fail (GTK_IS_WIDGET (widget));
4034 if (!gtk_widget_get_visible (widget))
4036 g_object_ref (widget);
4037 gtk_widget_push_verify_invariants (widget);
4039 if (!gtk_widget_is_toplevel (widget))
4040 gtk_widget_queue_resize (widget);
4042 /* see comment in set_parent() for why this should and can be
4045 if (widget->priv->need_compute_expand ||
4046 widget->priv->computed_hexpand ||
4047 widget->priv->computed_vexpand)
4049 if (widget->priv->parent != NULL)
4050 gtk_widget_queue_compute_expand (widget->priv->parent);
4053 g_signal_emit (widget, widget_signals[SHOW], 0);
4054 g_object_notify (G_OBJECT (widget), "visible");
4056 gtk_widget_pop_verify_invariants (widget);
4057 g_object_unref (widget);
4062 gtk_widget_real_show (GtkWidget *widget)
4064 GtkWidgetPrivate *priv = widget->priv;
4066 if (!gtk_widget_get_visible (widget))
4068 priv->visible = TRUE;
4071 gtk_widget_get_mapped (priv->parent) &&
4072 gtk_widget_get_child_visible (widget) &&
4073 !gtk_widget_get_mapped (widget))
4074 gtk_widget_map (widget);
4079 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4082 g_signal_handlers_disconnect_by_func (widget,
4083 gtk_widget_show_map_callback,
4088 * gtk_widget_show_now:
4089 * @widget: a #GtkWidget
4091 * Shows a widget. If the widget is an unmapped toplevel widget
4092 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4093 * loop and wait for the window to actually be mapped. Be careful;
4094 * because the main loop is running, anything can happen during
4098 gtk_widget_show_now (GtkWidget *widget)
4102 g_return_if_fail (GTK_IS_WIDGET (widget));
4104 /* make sure we will get event */
4105 if (!gtk_widget_get_mapped (widget) &&
4106 gtk_widget_is_toplevel (widget))
4108 gtk_widget_show (widget);
4110 g_signal_connect (widget, "map-event",
4111 G_CALLBACK (gtk_widget_show_map_callback),
4115 gtk_main_iteration ();
4118 gtk_widget_show (widget);
4123 * @widget: a #GtkWidget
4125 * Reverses the effects of gtk_widget_show(), causing the widget to be
4126 * hidden (invisible to the user).
4129 gtk_widget_hide (GtkWidget *widget)
4131 g_return_if_fail (GTK_IS_WIDGET (widget));
4133 if (gtk_widget_get_visible (widget))
4135 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4137 g_object_ref (widget);
4138 gtk_widget_push_verify_invariants (widget);
4140 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4141 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4143 /* a parent may now be expand=FALSE since we're hidden. */
4144 if (widget->priv->need_compute_expand ||
4145 widget->priv->computed_hexpand ||
4146 widget->priv->computed_vexpand)
4148 gtk_widget_queue_compute_expand (widget);
4151 g_signal_emit (widget, widget_signals[HIDE], 0);
4152 if (!gtk_widget_is_toplevel (widget))
4153 gtk_widget_queue_resize (widget);
4154 g_object_notify (G_OBJECT (widget), "visible");
4156 gtk_widget_pop_verify_invariants (widget);
4157 g_object_unref (widget);
4162 gtk_widget_real_hide (GtkWidget *widget)
4164 if (gtk_widget_get_visible (widget))
4166 widget->priv->visible = FALSE;
4168 if (gtk_widget_get_mapped (widget))
4169 gtk_widget_unmap (widget);
4174 * gtk_widget_hide_on_delete:
4175 * @widget: a #GtkWidget
4177 * Utility function; intended to be connected to the #GtkWidget::delete-event
4178 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4179 * argument, then returns %TRUE. If connected to ::delete-event, the
4180 * result is that clicking the close button for a window (on the
4181 * window frame, top right corner usually) will hide but not destroy
4182 * the window. By default, GTK+ destroys windows when ::delete-event
4185 * Return value: %TRUE
4188 gtk_widget_hide_on_delete (GtkWidget *widget)
4190 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4192 gtk_widget_hide (widget);
4198 * gtk_widget_show_all:
4199 * @widget: a #GtkWidget
4201 * Recursively shows a widget, and any child widgets (if the widget is
4205 gtk_widget_show_all (GtkWidget *widget)
4207 GtkWidgetClass *class;
4209 g_return_if_fail (GTK_IS_WIDGET (widget));
4211 if (gtk_widget_get_no_show_all (widget))
4214 class = GTK_WIDGET_GET_CLASS (widget);
4216 if (class->show_all)
4217 class->show_all (widget);
4222 * @widget: a #GtkWidget
4224 * This function is only for use in widget implementations. Causes
4225 * a widget to be mapped if it isn't already.
4228 gtk_widget_map (GtkWidget *widget)
4230 GtkWidgetPrivate *priv;
4232 g_return_if_fail (GTK_IS_WIDGET (widget));
4233 g_return_if_fail (gtk_widget_get_visible (widget));
4234 g_return_if_fail (gtk_widget_get_child_visible (widget));
4236 priv = widget->priv;
4238 if (!gtk_widget_get_mapped (widget))
4240 gtk_widget_push_verify_invariants (widget);
4242 if (!gtk_widget_get_realized (widget))
4243 gtk_widget_realize (widget);
4245 g_signal_emit (widget, widget_signals[MAP], 0);
4247 if (!gtk_widget_get_has_window (widget))
4248 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4250 if (widget->priv->context)
4251 _gtk_style_context_update_animating (widget->priv->context);
4253 gtk_widget_pop_verify_invariants (widget);
4259 * @widget: a #GtkWidget
4261 * This function is only for use in widget implementations. Causes
4262 * a widget to be unmapped if it's currently mapped.
4265 gtk_widget_unmap (GtkWidget *widget)
4267 GtkWidgetPrivate *priv;
4269 g_return_if_fail (GTK_IS_WIDGET (widget));
4271 priv = widget->priv;
4273 if (gtk_widget_get_mapped (widget))
4275 gtk_widget_push_verify_invariants (widget);
4277 if (!gtk_widget_get_has_window (widget))
4278 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4279 _gtk_tooltip_hide (widget);
4281 if (widget->priv->context)
4282 _gtk_style_context_update_animating (widget->priv->context);
4284 g_signal_emit (widget, widget_signals[UNMAP], 0);
4286 gtk_widget_pop_verify_invariants (widget);
4288 /* Unset pointer/window info */
4289 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4294 _gtk_widget_enable_device_events (GtkWidget *widget)
4296 GHashTable *device_events;
4297 GHashTableIter iter;
4298 gpointer key, value;
4300 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4305 g_hash_table_iter_init (&iter, device_events);
4307 while (g_hash_table_iter_next (&iter, &key, &value))
4310 GdkEventMask event_mask;
4313 event_mask = GPOINTER_TO_UINT (value);
4314 gtk_widget_add_events_internal (widget, device, event_mask);
4319 get_widget_windows (GtkWidget *widget)
4321 GList *window_list, *last, *l, *children, *ret;
4323 if (gtk_widget_get_has_window (widget))
4324 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4326 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4328 last = g_list_last (window_list);
4331 for (l = window_list; l; l = l->next)
4333 GtkWidget *window_widget = NULL;
4335 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4337 if (widget != window_widget)
4340 ret = g_list_prepend (ret, l->data);
4341 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4345 last = g_list_concat (last, children);
4346 last = g_list_last (last);
4350 g_list_free (window_list);
4356 device_enable_foreach (GtkWidget *widget,
4359 GdkDevice *device = user_data;
4360 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4364 device_disable_foreach (GtkWidget *widget,
4367 GdkDevice *device = user_data;
4368 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4372 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4377 GList *window_list, *l;
4379 window_list = get_widget_windows (widget);
4381 for (l = window_list; l; l = l->next)
4383 GdkEventMask events = 0;
4389 events = gdk_window_get_events (window);
4391 gdk_window_set_device_events (window, device, events);
4394 if (recurse && GTK_IS_CONTAINER (widget))
4397 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4399 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4402 g_list_free (window_list);
4406 gtk_widget_update_devices_mask (GtkWidget *widget,
4409 GList *enabled_devices, *l;
4411 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4413 for (l = enabled_devices; l; l = l->next)
4414 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4418 * gtk_widget_realize:
4419 * @widget: a #GtkWidget
4421 * Creates the GDK (windowing system) resources associated with a
4422 * widget. For example, @widget->window will be created when a widget
4423 * is realized. Normally realization happens implicitly; if you show
4424 * a widget and all its parent containers, then the widget will be
4425 * realized and mapped automatically.
4427 * Realizing a widget requires all
4428 * the widget's parent widgets to be realized; calling
4429 * gtk_widget_realize() realizes the widget's parents in addition to
4430 * @widget itself. If a widget is not yet inside a toplevel window
4431 * when you realize it, bad things will happen.
4433 * This function is primarily used in widget implementations, and
4434 * isn't very useful otherwise. Many times when you think you might
4435 * need it, a better approach is to connect to a signal that will be
4436 * called after the widget is realized automatically, such as
4437 * #GtkWidget::draw. Or simply g_signal_connect () to the
4438 * #GtkWidget::realize signal.
4441 gtk_widget_realize (GtkWidget *widget)
4443 GtkWidgetPrivate *priv;
4444 cairo_region_t *region;
4446 g_return_if_fail (GTK_IS_WIDGET (widget));
4447 g_return_if_fail (widget->priv->anchored ||
4448 GTK_IS_INVISIBLE (widget));
4450 priv = widget->priv;
4452 if (!gtk_widget_get_realized (widget))
4454 gtk_widget_push_verify_invariants (widget);
4457 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4458 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4461 if (priv->parent == NULL &&
4462 !gtk_widget_is_toplevel (widget))
4463 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4464 "inside a toplevel window is not going to work very well. "
4465 "Widgets must be inside a toplevel container before realizing them.");
4467 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4468 gtk_widget_realize (priv->parent);
4470 gtk_widget_ensure_style (widget);
4472 if (priv->style_update_pending)
4473 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4475 g_signal_emit (widget, widget_signals[REALIZE], 0);
4477 gtk_widget_real_set_has_tooltip (widget,
4478 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4481 if (priv->has_shape_mask)
4483 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4484 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4487 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4489 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4491 if (priv->multidevice)
4492 gdk_window_set_support_multidevice (priv->window, TRUE);
4494 _gtk_widget_enable_device_events (widget);
4495 gtk_widget_update_devices_mask (widget, TRUE);
4497 gtk_widget_pop_verify_invariants (widget);
4502 * gtk_widget_unrealize:
4503 * @widget: a #GtkWidget
4505 * This function is only useful in widget implementations.
4506 * Causes a widget to be unrealized (frees all GDK resources
4507 * associated with the widget, such as @widget->window).
4510 gtk_widget_unrealize (GtkWidget *widget)
4512 g_return_if_fail (GTK_IS_WIDGET (widget));
4514 gtk_widget_push_verify_invariants (widget);
4516 if (widget->priv->has_shape_mask)
4517 gtk_widget_shape_combine_region (widget, NULL);
4519 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4520 gtk_widget_input_shape_combine_region (widget, NULL);
4522 if (gtk_widget_get_realized (widget))
4524 g_object_ref (widget);
4526 if (widget->priv->mapped)
4527 gtk_widget_unmap (widget);
4529 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4530 g_assert (!widget->priv->mapped);
4531 gtk_widget_set_realized (widget, FALSE);
4533 g_object_unref (widget);
4536 gtk_widget_pop_verify_invariants (widget);
4539 /*****************************************
4541 *****************************************/
4544 * gtk_widget_queue_draw_region:
4545 * @widget: a #GtkWidget
4546 * @region: region to draw
4548 * Invalidates the rectangular area of @widget defined by @region by
4549 * calling gdk_window_invalidate_region() on the widget's window and
4550 * all its child windows. Once the main loop becomes idle (after the
4551 * current batch of events has been processed, roughly), the window
4552 * will receive expose events for the union of all regions that have
4555 * Normally you would only use this function in widget
4556 * implementations. You might also use it to schedule a redraw of a
4557 * #GtkDrawingArea or some portion thereof.
4562 gtk_widget_queue_draw_region (GtkWidget *widget,
4563 const cairo_region_t *region)
4565 GtkWidgetPrivate *priv;
4568 g_return_if_fail (GTK_IS_WIDGET (widget));
4570 priv = widget->priv;
4572 if (!gtk_widget_get_realized (widget))
4575 /* Just return if the widget or one of its ancestors isn't mapped */
4576 for (w = widget; w != NULL; w = w->priv->parent)
4577 if (!gtk_widget_get_mapped (w))
4580 gdk_window_invalidate_region (priv->window, region, TRUE);
4584 * gtk_widget_queue_draw_area:
4585 * @widget: a #GtkWidget
4586 * @x: x coordinate of upper-left corner of rectangle to redraw
4587 * @y: y coordinate of upper-left corner of rectangle to redraw
4588 * @width: width of region to draw
4589 * @height: height of region to draw
4591 * Convenience function that calls gtk_widget_queue_draw_region() on
4592 * the region created from the given coordinates.
4594 * The region here is specified in widget coordinates.
4595 * Widget coordinates are a bit odd; for historical reasons, they are
4596 * defined as @widget->window coordinates for widgets that are not
4597 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4598 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4601 gtk_widget_queue_draw_area (GtkWidget *widget,
4608 cairo_region_t *region;
4610 g_return_if_fail (GTK_IS_WIDGET (widget));
4615 rect.height = height;
4617 region = cairo_region_create_rectangle (&rect);
4618 gtk_widget_queue_draw_region (widget, region);
4619 cairo_region_destroy (region);
4623 * gtk_widget_queue_draw:
4624 * @widget: a #GtkWidget
4626 * Equivalent to calling gtk_widget_queue_draw_area() for the
4627 * entire area of a widget.
4630 gtk_widget_queue_draw (GtkWidget *widget)
4634 g_return_if_fail (GTK_IS_WIDGET (widget));
4636 gtk_widget_get_allocation (widget, &rect);
4638 if (!gtk_widget_get_has_window (widget))
4639 gtk_widget_queue_draw_area (widget,
4640 rect.x, rect.y, rect.width, rect.height);
4642 gtk_widget_queue_draw_area (widget,
4643 0, 0, rect.width, rect.height);
4647 * gtk_widget_queue_resize:
4648 * @widget: a #GtkWidget
4650 * This function is only for use in widget implementations.
4651 * Flags a widget to have its size renegotiated; should
4652 * be called when a widget for some reason has a new size request.
4653 * For example, when you change the text in a #GtkLabel, #GtkLabel
4654 * queues a resize to ensure there's enough space for the new text.
4656 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4657 * from inside its implementation of the GtkWidgetClass::size_allocate
4658 * virtual method. Calls to gtk_widget_queue_resize() from inside
4659 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4662 gtk_widget_queue_resize (GtkWidget *widget)
4664 g_return_if_fail (GTK_IS_WIDGET (widget));
4666 if (gtk_widget_get_realized (widget))
4667 gtk_widget_queue_draw (widget);
4669 _gtk_size_group_queue_resize (widget, 0);
4673 * gtk_widget_queue_resize_no_redraw:
4674 * @widget: a #GtkWidget
4676 * This function works like gtk_widget_queue_resize(),
4677 * except that the widget is not invalidated.
4682 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4684 g_return_if_fail (GTK_IS_WIDGET (widget));
4686 _gtk_size_group_queue_resize (widget, 0);
4690 * gtk_widget_size_request:
4691 * @widget: a #GtkWidget
4692 * @requisition: (out): a #GtkRequisition to be filled in
4694 * This function is typically used when implementing a #GtkContainer
4695 * subclass. Obtains the preferred size of a widget. The container
4696 * uses this information to arrange its child widgets and decide what
4697 * size allocations to give them with gtk_widget_size_allocate().
4699 * You can also call this function from an application, with some
4700 * caveats. Most notably, getting a size request requires the widget
4701 * to be associated with a screen, because font information may be
4702 * needed. Multihead-aware applications should keep this in mind.
4704 * Also remember that the size request is not necessarily the size
4705 * a widget will actually be allocated.
4707 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4710 gtk_widget_size_request (GtkWidget *widget,
4711 GtkRequisition *requisition)
4713 g_return_if_fail (GTK_IS_WIDGET (widget));
4715 gtk_widget_get_preferred_size (widget, requisition, NULL);
4719 * gtk_widget_get_child_requisition:
4720 * @widget: a #GtkWidget
4721 * @requisition: (out): a #GtkRequisition to be filled in
4723 * This function is only for use in widget implementations. Obtains
4724 * @widget->requisition, unless someone has forced a particular
4725 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4726 * in which case it returns that geometry instead of the widget's
4729 * This function differs from gtk_widget_size_request() in that
4730 * it retrieves the last size request value from @widget->requisition,
4731 * while gtk_widget_size_request() actually calls the "size_request" method
4732 * on @widget to compute the size request and fill in @widget->requisition,
4733 * and only then returns @widget->requisition.
4735 * Because this function does not call the "size_request" method, it
4736 * can only be used when you know that @widget->requisition is
4737 * up-to-date, that is, gtk_widget_size_request() has been called
4738 * since the last time a resize was queued. In general, only container
4739 * implementations have this information; applications should use
4740 * gtk_widget_size_request().
4743 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4746 gtk_widget_get_child_requisition (GtkWidget *widget,
4747 GtkRequisition *requisition)
4749 gtk_widget_get_preferred_size (widget, requisition, NULL);
4753 invalidate_predicate (GdkWindow *window,
4758 gdk_window_get_user_data (window, &user_data);
4760 return (user_data == data);
4763 /* Invalidate @region in widget->window and all children
4764 * of widget->window owned by widget. @region is in the
4765 * same coordinates as widget->allocation and will be
4766 * modified by this call.
4769 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4770 cairo_region_t *region)
4772 GtkWidgetPrivate *priv = widget->priv;
4774 if (!gtk_widget_get_realized (widget))
4777 if (gtk_widget_get_has_window (widget) && priv->parent)
4781 gdk_window_get_position (priv->window, &x, &y);
4782 cairo_region_translate (region, -x, -y);
4785 gdk_window_invalidate_maybe_recurse (priv->window, region,
4786 invalidate_predicate, widget);
4790 * gtk_widget_size_allocate:
4791 * @widget: a #GtkWidget
4792 * @allocation: position and size to be allocated to @widget
4794 * This function is only used by #GtkContainer subclasses, to assign a size
4795 * and position to their child widgets.
4797 * In this function, the allocation may be adjusted. It will be forced
4798 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4799 * method on the child will be used to adjust the allocation. Standard
4800 * adjustments include removing the widget's margins, and applying the
4801 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4804 gtk_widget_size_allocate (GtkWidget *widget,
4805 GtkAllocation *allocation)
4807 GtkWidgetPrivate *priv;
4808 GdkRectangle real_allocation;
4809 GdkRectangle old_allocation;
4810 GdkRectangle adjusted_allocation;
4811 gboolean alloc_needed;
4812 gboolean size_changed;
4813 gboolean position_changed;
4814 gint natural_width, natural_height, dummy;
4815 gint min_width, min_height;
4817 priv = widget->priv;
4819 g_return_if_fail (GTK_IS_WIDGET (widget));
4821 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4824 gtk_widget_push_verify_invariants (widget);
4826 #ifdef G_ENABLE_DEBUG
4827 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4838 parent = gtk_widget_get_parent (parent);
4841 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4842 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4843 2 * depth, " ", name,
4844 allocation->width, allocation->height);
4846 #endif /* G_ENABLE_DEBUG */
4848 alloc_needed = priv->alloc_needed;
4849 /* Preserve request/allocate ordering */
4850 priv->alloc_needed = FALSE;
4852 old_allocation = priv->allocation;
4853 real_allocation = *allocation;
4855 adjusted_allocation = real_allocation;
4856 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4858 /* Go ahead and request the height for allocated width, note that the internals
4859 * of get_height_for_width will internally limit the for_size to natural size
4860 * when aligning implicitly.
4862 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4863 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4867 /* Go ahead and request the width for allocated height, note that the internals
4868 * of get_width_for_height will internally limit the for_size to natural size
4869 * when aligning implicitly.
4871 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4872 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4875 #ifdef G_ENABLE_DEBUG
4876 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4878 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4879 !GTK_IS_SCROLLABLE (widget))
4880 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4881 "Allocation is %dx%d, but minimum required size is %dx%d.",
4882 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4883 G_OBJECT_TYPE_NAME (widget), widget,
4884 real_allocation.width, real_allocation.height,
4885 min_width, min_height);
4888 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4889 * allocated sizes and possibly limit them to the natural sizes */
4890 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4891 GTK_ORIENTATION_HORIZONTAL,
4894 &adjusted_allocation.x,
4895 &adjusted_allocation.width);
4896 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4897 GTK_ORIENTATION_VERTICAL,
4900 &adjusted_allocation.y,
4901 &adjusted_allocation.height);
4903 if (adjusted_allocation.x < real_allocation.x ||
4904 adjusted_allocation.y < real_allocation.y ||
4905 (adjusted_allocation.x + adjusted_allocation.width) >
4906 (real_allocation.x + real_allocation.width) ||
4907 (adjusted_allocation.y + adjusted_allocation.height >
4908 real_allocation.y + real_allocation.height))
4910 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",
4911 G_OBJECT_TYPE_NAME (widget), widget,
4912 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4913 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4914 adjusted_allocation = real_allocation; /* veto it */
4918 real_allocation = adjusted_allocation;
4921 if (real_allocation.width < 0 || real_allocation.height < 0)
4923 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4924 real_allocation.width,
4925 real_allocation.height);
4928 real_allocation.width = MAX (real_allocation.width, 1);
4929 real_allocation.height = MAX (real_allocation.height, 1);
4931 size_changed = (old_allocation.width != real_allocation.width ||
4932 old_allocation.height != real_allocation.height);
4933 position_changed = (old_allocation.x != real_allocation.x ||
4934 old_allocation.y != real_allocation.y);
4936 if (!alloc_needed && !size_changed && !position_changed)
4939 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4941 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4942 priv->alloc_needed = FALSE;
4944 if (gtk_widget_get_mapped (widget))
4946 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4948 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4950 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4951 cairo_region_union_rectangle (invalidate, &old_allocation);
4953 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4954 cairo_region_destroy (invalidate);
4959 if (priv->redraw_on_alloc)
4961 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4963 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4964 cairo_region_union_rectangle (invalidate, &old_allocation);
4966 gtk_widget_invalidate_widget_windows (widget, invalidate);
4967 cairo_region_destroy (invalidate);
4972 if ((size_changed || position_changed) && priv->parent &&
4973 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4975 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4976 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4977 cairo_region_destroy (invalidate);
4981 gtk_widget_pop_verify_invariants (widget);
4985 * gtk_widget_common_ancestor:
4986 * @widget_a: a #GtkWidget
4987 * @widget_b: a #GtkWidget
4989 * Find the common ancestor of @widget_a and @widget_b that
4990 * is closest to the two widgets.
4992 * Return value: the closest common ancestor of @widget_a and
4993 * @widget_b or %NULL if @widget_a and @widget_b do not
4994 * share a common ancestor.
4997 gtk_widget_common_ancestor (GtkWidget *widget_a,
4998 GtkWidget *widget_b)
5000 GtkWidget *parent_a;
5001 GtkWidget *parent_b;
5005 parent_a = widget_a;
5006 while (parent_a->priv->parent)
5008 parent_a = parent_a->priv->parent;
5012 parent_b = widget_b;
5013 while (parent_b->priv->parent)
5015 parent_b = parent_b->priv->parent;
5019 if (parent_a != parent_b)
5022 while (depth_a > depth_b)
5024 widget_a = widget_a->priv->parent;
5028 while (depth_b > depth_a)
5030 widget_b = widget_b->priv->parent;
5034 while (widget_a != widget_b)
5036 widget_a = widget_a->priv->parent;
5037 widget_b = widget_b->priv->parent;
5044 * gtk_widget_translate_coordinates:
5045 * @src_widget: a #GtkWidget
5046 * @dest_widget: a #GtkWidget
5047 * @src_x: X position relative to @src_widget
5048 * @src_y: Y position relative to @src_widget
5049 * @dest_x: (out): location to store X position relative to @dest_widget
5050 * @dest_y: (out): location to store Y position relative to @dest_widget
5052 * Translate coordinates relative to @src_widget's allocation to coordinates
5053 * relative to @dest_widget's allocations. In order to perform this
5054 * operation, both widgets must be realized, and must share a common
5057 * Return value: %FALSE if either widget was not realized, or there
5058 * was no common ancestor. In this case, nothing is stored in
5059 * *@dest_x and *@dest_y. Otherwise %TRUE.
5062 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5063 GtkWidget *dest_widget,
5069 GtkWidgetPrivate *src_priv = src_widget->priv;
5070 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5071 GtkWidget *ancestor;
5073 GList *dest_list = NULL;
5075 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5076 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5078 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5079 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5082 /* Translate from allocation relative to window relative */
5083 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5086 gdk_window_get_position (src_priv->window, &wx, &wy);
5088 src_x -= wx - src_priv->allocation.x;
5089 src_y -= wy - src_priv->allocation.y;
5093 src_x += src_priv->allocation.x;
5094 src_y += src_priv->allocation.y;
5097 /* Translate to the common ancestor */
5098 window = src_priv->window;
5099 while (window != ancestor->priv->window)
5103 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5108 window = gdk_window_get_effective_parent (window);
5110 if (!window) /* Handle GtkHandleBox */
5115 window = dest_priv->window;
5116 while (window != ancestor->priv->window)
5118 dest_list = g_list_prepend (dest_list, window);
5120 window = gdk_window_get_effective_parent (window);
5122 if (!window) /* Handle GtkHandleBox */
5124 g_list_free (dest_list);
5133 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5138 dest_list = g_list_remove (dest_list, dest_list->data);
5141 /* Translate from window relative to allocation relative */
5142 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5145 gdk_window_get_position (dest_priv->window, &wx, &wy);
5147 src_x += wx - dest_priv->allocation.x;
5148 src_y += wy - dest_priv->allocation.y;
5152 src_x -= dest_priv->allocation.x;
5153 src_y -= dest_priv->allocation.y;
5165 gtk_widget_real_size_allocate (GtkWidget *widget,
5166 GtkAllocation *allocation)
5168 GtkWidgetPrivate *priv = widget->priv;
5170 priv->allocation = *allocation;
5172 if (gtk_widget_get_realized (widget) &&
5173 gtk_widget_get_has_window (widget))
5175 gdk_window_move_resize (priv->window,
5176 allocation->x, allocation->y,
5177 allocation->width, allocation->height);
5181 /* translate initial/final into start/end */
5183 effective_align (GtkAlign align,
5184 GtkTextDirection direction)
5188 case GTK_ALIGN_START:
5189 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5191 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5198 adjust_for_align (GtkAlign align,
5200 gint *allocated_pos,
5201 gint *allocated_size)
5205 case GTK_ALIGN_FILL:
5206 /* change nothing */
5208 case GTK_ALIGN_START:
5209 /* keep *allocated_pos where it is */
5210 *allocated_size = MIN (*allocated_size, *natural_size);
5213 if (*allocated_size > *natural_size)
5215 *allocated_pos += (*allocated_size - *natural_size);
5216 *allocated_size = *natural_size;
5219 case GTK_ALIGN_CENTER:
5220 if (*allocated_size > *natural_size)
5222 *allocated_pos += (*allocated_size - *natural_size) / 2;
5223 *allocated_size = MIN (*allocated_size, *natural_size);
5230 adjust_for_margin(gint start_margin,
5234 gint *allocated_pos,
5235 gint *allocated_size)
5237 *minimum_size -= (start_margin + end_margin);
5238 *natural_size -= (start_margin + end_margin);
5239 *allocated_pos += start_margin;
5240 *allocated_size -= (start_margin + end_margin);
5244 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5245 GtkOrientation orientation,
5248 gint *allocated_pos,
5249 gint *allocated_size)
5251 const GtkWidgetAuxInfo *aux_info;
5253 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5255 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5257 adjust_for_margin (aux_info->margin.left,
5258 aux_info->margin.right,
5259 minimum_size, natural_size,
5260 allocated_pos, allocated_size);
5261 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5262 natural_size, allocated_pos, allocated_size);
5266 adjust_for_margin (aux_info->margin.top,
5267 aux_info->margin.bottom,
5268 minimum_size, natural_size,
5269 allocated_pos, allocated_size);
5270 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5271 natural_size, allocated_pos, allocated_size);
5276 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5279 GtkWidgetPrivate *priv = widget->priv;
5281 /* widgets must be onscreen for accels to take effect */
5282 return gtk_widget_is_sensitive (widget) &&
5283 gtk_widget_is_drawable (widget) &&
5284 gdk_window_is_viewable (priv->window);
5288 * gtk_widget_can_activate_accel:
5289 * @widget: a #GtkWidget
5290 * @signal_id: the ID of a signal installed on @widget
5292 * Determines whether an accelerator that activates the signal
5293 * identified by @signal_id can currently be activated.
5294 * This is done by emitting the #GtkWidget::can-activate-accel
5295 * signal on @widget; if the signal isn't overridden by a
5296 * handler or in a derived widget, then the default check is
5297 * that the widget must be sensitive, and the widget and all
5298 * its ancestors mapped.
5300 * Return value: %TRUE if the accelerator can be activated.
5305 gtk_widget_can_activate_accel (GtkWidget *widget,
5308 gboolean can_activate = FALSE;
5309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5310 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5311 return can_activate;
5320 closure_accel_activate (GClosure *closure,
5321 GValue *return_value,
5322 guint n_param_values,
5323 const GValue *param_values,
5324 gpointer invocation_hint,
5325 gpointer marshal_data)
5327 AccelClosure *aclosure = (AccelClosure*) closure;
5328 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5331 g_signal_emit (closure->data, aclosure->signal_id, 0);
5333 /* whether accelerator was handled */
5334 g_value_set_boolean (return_value, can_activate);
5338 closures_destroy (gpointer data)
5340 GSList *slist, *closures = data;
5342 for (slist = closures; slist; slist = slist->next)
5344 g_closure_invalidate (slist->data);
5345 g_closure_unref (slist->data);
5347 g_slist_free (closures);
5351 widget_new_accel_closure (GtkWidget *widget,
5354 AccelClosure *aclosure;
5355 GClosure *closure = NULL;
5356 GSList *slist, *closures;
5358 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5359 for (slist = closures; slist; slist = slist->next)
5360 if (!gtk_accel_group_from_accel_closure (slist->data))
5362 /* reuse this closure */
5363 closure = slist->data;
5368 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5369 closures = g_slist_prepend (closures, g_closure_ref (closure));
5370 g_closure_sink (closure);
5371 g_closure_set_marshal (closure, closure_accel_activate);
5373 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5375 aclosure = (AccelClosure*) closure;
5376 g_assert (closure->data == widget);
5377 g_assert (closure->marshal == closure_accel_activate);
5378 aclosure->signal_id = signal_id;
5384 * gtk_widget_add_accelerator:
5385 * @widget: widget to install an accelerator on
5386 * @accel_signal: widget signal to emit on accelerator activation
5387 * @accel_group: accel group for this widget, added to its toplevel
5388 * @accel_key: GDK keyval of the accelerator
5389 * @accel_mods: modifier key combination of the accelerator
5390 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5392 * Installs an accelerator for this @widget in @accel_group that causes
5393 * @accel_signal to be emitted if the accelerator is activated.
5394 * The @accel_group needs to be added to the widget's toplevel via
5395 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5396 * Accelerators added through this function are not user changeable during
5397 * runtime. If you want to support accelerators that can be changed by the
5398 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5399 * gtk_menu_item_set_accel_path() instead.
5402 gtk_widget_add_accelerator (GtkWidget *widget,
5403 const gchar *accel_signal,
5404 GtkAccelGroup *accel_group,
5406 GdkModifierType accel_mods,
5407 GtkAccelFlags accel_flags)
5412 g_return_if_fail (GTK_IS_WIDGET (widget));
5413 g_return_if_fail (accel_signal != NULL);
5414 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5416 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5417 if (!query.signal_id ||
5418 !(query.signal_flags & G_SIGNAL_ACTION) ||
5419 query.return_type != G_TYPE_NONE ||
5422 /* hmm, should be elaborate enough */
5423 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5424 G_OBJECT_TYPE_NAME (widget), accel_signal);
5428 closure = widget_new_accel_closure (widget, query.signal_id);
5430 g_object_ref (widget);
5432 /* install the accelerator. since we don't map this onto an accel_path,
5433 * the accelerator will automatically be locked.
5435 gtk_accel_group_connect (accel_group,
5438 accel_flags | GTK_ACCEL_LOCKED,
5441 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5443 g_object_unref (widget);
5447 * gtk_widget_remove_accelerator:
5448 * @widget: widget to install an accelerator on
5449 * @accel_group: accel group for this widget
5450 * @accel_key: GDK keyval of the accelerator
5451 * @accel_mods: modifier key combination of the accelerator
5453 * Removes an accelerator from @widget, previously installed with
5454 * gtk_widget_add_accelerator().
5456 * Returns: whether an accelerator was installed and could be removed
5459 gtk_widget_remove_accelerator (GtkWidget *widget,
5460 GtkAccelGroup *accel_group,
5462 GdkModifierType accel_mods)
5464 GtkAccelGroupEntry *ag_entry;
5465 GList *slist, *clist;
5468 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5469 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5471 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5472 clist = gtk_widget_list_accel_closures (widget);
5473 for (slist = clist; slist; slist = slist->next)
5477 for (i = 0; i < n; i++)
5478 if (slist->data == (gpointer) ag_entry[i].closure)
5480 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5482 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5484 g_list_free (clist);
5489 g_list_free (clist);
5491 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5492 accel_key, accel_mods, accel_group,
5493 G_OBJECT_TYPE_NAME (widget), widget);
5499 * gtk_widget_list_accel_closures:
5500 * @widget: widget to list accelerator closures for
5502 * Lists the closures used by @widget for accelerator group connections
5503 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5504 * The closures can be used to monitor accelerator changes on @widget,
5505 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5506 * #GtkAccelGroup of a closure which can be found out with
5507 * gtk_accel_group_from_accel_closure().
5509 * Return value: (transfer container) (element-type GClosure):
5510 * a newly allocated #GList of closures
5513 gtk_widget_list_accel_closures (GtkWidget *widget)
5516 GList *clist = NULL;
5518 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5520 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5521 if (gtk_accel_group_from_accel_closure (slist->data))
5522 clist = g_list_prepend (clist, slist->data);
5528 GtkAccelGroup *accel_group;
5533 destroy_accel_path (gpointer data)
5535 AccelPath *apath = data;
5537 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5539 /* closures_destroy takes care of unrefing the closure */
5540 g_object_unref (apath->accel_group);
5542 g_slice_free (AccelPath, apath);
5547 * gtk_widget_set_accel_path:
5548 * @widget: a #GtkWidget
5549 * @accel_path: (allow-none): path used to look up the accelerator
5550 * @accel_group: (allow-none): a #GtkAccelGroup.
5552 * Given an accelerator group, @accel_group, and an accelerator path,
5553 * @accel_path, sets up an accelerator in @accel_group so whenever the
5554 * key binding that is defined for @accel_path is pressed, @widget
5555 * will be activated. This removes any accelerators (for any
5556 * accelerator group) installed by previous calls to
5557 * gtk_widget_set_accel_path(). Associating accelerators with
5558 * paths allows them to be modified by the user and the modifications
5559 * to be saved for future use. (See gtk_accel_map_save().)
5561 * This function is a low level function that would most likely
5562 * be used by a menu creation system like #GtkUIManager. If you
5563 * use #GtkUIManager, setting up accelerator paths will be done
5566 * Even when you you aren't using #GtkUIManager, if you only want to
5567 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5568 * provides a somewhat more convenient interface.
5570 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5571 * pass a static string, you can save some memory by interning it first with
5572 * g_intern_static_string().
5575 gtk_widget_set_accel_path (GtkWidget *widget,
5576 const gchar *accel_path,
5577 GtkAccelGroup *accel_group)
5581 g_return_if_fail (GTK_IS_WIDGET (widget));
5582 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5586 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5587 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5589 gtk_accel_map_add_entry (accel_path, 0, 0);
5590 apath = g_slice_new (AccelPath);
5591 apath->accel_group = g_object_ref (accel_group);
5592 apath->path_quark = g_quark_from_string (accel_path);
5593 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5598 /* also removes possible old settings */
5599 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5602 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5604 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5608 _gtk_widget_get_accel_path (GtkWidget *widget,
5613 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5615 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5617 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5618 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5622 * gtk_widget_mnemonic_activate:
5623 * @widget: a #GtkWidget
5624 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5626 * Emits the #GtkWidget::mnemonic-activate signal.
5628 * The default handler for this signal activates the @widget if
5629 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5632 * Returns: %TRUE if the signal has been handled
5635 gtk_widget_mnemonic_activate (GtkWidget *widget,
5636 gboolean group_cycling)
5640 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5642 group_cycling = group_cycling != FALSE;
5643 if (!gtk_widget_is_sensitive (widget))
5646 g_signal_emit (widget,
5647 widget_signals[MNEMONIC_ACTIVATE],
5655 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5656 gboolean group_cycling)
5658 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5659 gtk_widget_activate (widget);
5660 else if (gtk_widget_get_can_focus (widget))
5661 gtk_widget_grab_focus (widget);
5664 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5665 G_OBJECT_TYPE_NAME (widget));
5666 gtk_widget_error_bell (widget);
5671 static const cairo_user_data_key_t event_key;
5674 _gtk_cairo_get_event (cairo_t *cr)
5676 g_return_val_if_fail (cr != NULL, NULL);
5678 return cairo_get_user_data (cr, &event_key);
5682 gtk_cairo_set_event (cairo_t *cr,
5683 GdkEventExpose *event)
5685 cairo_set_user_data (cr, &event_key, event, NULL);
5689 * gtk_cairo_should_draw_window:
5690 * @cr: a cairo context
5691 * @window: the window to check. @window may not be an input-only
5694 * This function is supposed to be called in #GtkWidget::draw
5695 * implementations for widgets that support multiple windows.
5696 * @cr must be untransformed from invoking of the draw function.
5697 * This function will return %TRUE if the contents of the given
5698 * @window are supposed to be drawn and %FALSE otherwise. Note
5699 * that when the drawing was not initiated by the windowing
5700 * system this function will return %TRUE for all windows, so
5701 * you need to draw the bottommost window first. Also, do not
5702 * use "else if" statements to check which window should be drawn.
5704 * Returns: %TRUE if @window should be drawn
5709 gtk_cairo_should_draw_window (cairo_t *cr,
5712 GdkEventExpose *event;
5714 g_return_val_if_fail (cr != NULL, FALSE);
5715 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5717 event = _gtk_cairo_get_event (cr);
5719 return event == NULL ||
5720 event->window == window;
5724 gtk_widget_get_clip_draw (GtkWidget *widget)
5726 /* labels are not clipped, because clipping them would cause
5727 * mnemonics to not appear on characters that go beyond the
5729 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5731 if (GTK_IS_LABEL (widget))
5737 /* code shared by gtk_container_propagate_draw() and
5741 _gtk_widget_draw_internal (GtkWidget *widget,
5743 gboolean clip_to_size)
5745 if (!gtk_widget_is_drawable (widget))
5748 clip_to_size &= gtk_widget_get_clip_draw (widget);
5752 cairo_rectangle (cr,
5754 widget->priv->allocation.width,
5755 widget->priv->allocation.height);
5759 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5763 g_signal_emit (widget, widget_signals[DRAW],
5767 if (cairo_status (cr) &&
5768 _gtk_cairo_get_event (cr))
5770 /* We check the event so we only warn about internal GTK calls.
5771 * Errors might come from PDF streams having write failures and
5772 * we don't want to spam stderr in that case.
5773 * We do want to catch errors from
5775 g_warning ("drawing failure for widget `%s': %s",
5776 G_OBJECT_TYPE_NAME (widget),
5777 cairo_status_to_string (cairo_status (cr)));
5784 * @widget: the widget to draw. It must be drawable (see
5785 * gtk_widget_is_drawable()) and a size must have been allocated.
5786 * @cr: a cairo context to draw to
5788 * Draws @widget to @cr. The top left corner of the widget will be
5789 * drawn to the currently set origin point of @cr.
5791 * You should pass a cairo context as @cr argument that is in an
5792 * original state. Otherwise the resulting drawing is undefined. For
5793 * example changing the operator using cairo_set_operator() or the
5794 * line width using cairo_set_line_width() might have unwanted side
5796 * You may however change the context's transform matrix - like with
5797 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5798 * region with cairo_clip() prior to calling this function. Also, it
5799 * is fine to modify the context with cairo_save() and
5800 * cairo_push_group() prior to calling this function.
5802 * <note><para>Special purpose widgets may contain special code for
5803 * rendering to the screen and might appear differently on screen
5804 * and when rendered using gtk_widget_draw().</para></note>
5809 gtk_widget_draw (GtkWidget *widget,
5812 GdkEventExpose *tmp_event;
5814 g_return_if_fail (GTK_IS_WIDGET (widget));
5815 g_return_if_fail (!widget->priv->alloc_needed);
5816 g_return_if_fail (cr != NULL);
5819 /* We have to reset the event here so that draw functions can call
5820 * gtk_widget_draw() on random other widgets and get the desired
5821 * effect: Drawing all contents, not just the current window.
5823 tmp_event = _gtk_cairo_get_event (cr);
5824 gtk_cairo_set_event (cr, NULL);
5826 _gtk_widget_draw_internal (widget, cr, TRUE);
5828 gtk_cairo_set_event (cr, tmp_event);
5833 gtk_widget_real_key_press_event (GtkWidget *widget,
5836 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5840 gtk_widget_real_key_release_event (GtkWidget *widget,
5843 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5847 gtk_widget_real_focus_in_event (GtkWidget *widget,
5848 GdkEventFocus *event)
5850 gtk_widget_queue_draw (widget);
5856 gtk_widget_real_focus_out_event (GtkWidget *widget,
5857 GdkEventFocus *event)
5859 gtk_widget_queue_draw (widget);
5865 gtk_widget_real_touch_event (GtkWidget *widget,
5866 GdkEventTouch *event)
5869 gboolean return_val;
5872 if (!event->emulating_pointer)
5875 if (event->type == GDK_TOUCH_BEGIN ||
5876 event->type == GDK_TOUCH_END)
5880 if (event->type == GDK_TOUCH_BEGIN)
5882 type = GDK_BUTTON_PRESS;
5883 signum = BUTTON_PRESS_EVENT;
5887 type = GDK_BUTTON_RELEASE;
5888 signum = BUTTON_RELEASE_EVENT;
5890 bevent = gdk_event_new (type);
5891 bevent->any.window = g_object_ref (event->window);
5892 bevent->any.send_event = FALSE;
5893 bevent->button.time = event->time;
5894 bevent->button.state = event->state;
5895 bevent->button.button = 1;
5896 bevent->button.x_root = event->x_root;
5897 bevent->button.y_root = event->y_root;
5898 bevent->button.x = event->x;
5899 bevent->button.y = event->y;
5900 bevent->button.device = event->device;
5901 bevent->button.axes = g_memdup (event->axes,
5902 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5903 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5905 else if (event->type == GDK_TOUCH_UPDATE)
5907 signum = MOTION_NOTIFY_EVENT;
5908 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5909 bevent->any.window = g_object_ref (event->window);
5910 bevent->any.send_event = FALSE;
5911 bevent->motion.time = event->time;
5912 bevent->motion.state = event->state;
5913 bevent->motion.x_root = event->x_root;
5914 bevent->motion.y_root = event->y_root;
5915 bevent->motion.x = event->x;
5916 bevent->motion.y = event->y;
5917 bevent->motion.device = event->device;
5918 bevent->motion.is_hint = FALSE;
5919 bevent->motion.axes = g_memdup (event->axes,
5920 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5921 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5926 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
5928 gdk_event_free (bevent);
5934 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5935 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5939 * @widget: a #GtkWidget
5940 * @event: a #GdkEvent
5942 * Rarely-used function. This function is used to emit
5943 * the event signals on a widget (those signals should never
5944 * be emitted without using this function to do so).
5945 * If you want to synthesize an event though, don't use this function;
5946 * instead, use gtk_main_do_event() so the event will behave as if
5947 * it were in the event queue. Don't synthesize expose events; instead,
5948 * use gdk_window_invalidate_rect() to invalidate a region of the
5951 * Return value: return from the event signal emission (%TRUE if
5952 * the event was handled)
5955 gtk_widget_event (GtkWidget *widget,
5958 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5959 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5961 if (event->type == GDK_EXPOSE)
5963 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5964 "the same effect, call gdk_window_invalidate_rect/region(), "
5965 "followed by gdk_window_process_updates().");
5969 return gtk_widget_event_internal (widget, event);
5973 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
5974 GtkCapturedEventHandler callback)
5976 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
5980 _gtk_widget_captured_event (GtkWidget *widget,
5983 gboolean return_val = FALSE;
5984 GtkCapturedEventHandler handler;
5986 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5987 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5989 if (event->type == GDK_EXPOSE)
5991 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5992 "the same effect, call gdk_window_invalidate_rect/region(), "
5993 "followed by gdk_window_process_updates().");
5997 if (!event_window_is_still_viewable (event))
6000 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6004 g_object_ref (widget);
6006 return_val = handler (widget, event);
6007 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6009 /* The widget that was originally to receive the event
6010 * handles motion hints, but the capturing widget might
6011 * not, so ensure we get further motion events.
6014 event->type == GDK_MOTION_NOTIFY &&
6015 event->motion.is_hint &&
6016 (gdk_window_get_events (event->any.window) &
6017 GDK_POINTER_MOTION_HINT_MASK) != 0)
6018 gdk_event_request_motions (&event->motion);
6020 g_object_unref (widget);
6025 /* Returns TRUE if a translation should be done */
6027 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6032 GdkWindow *w, *widget_window;
6034 if (!gtk_widget_get_has_window (widget))
6036 *x = -widget->priv->allocation.x;
6037 *y = -widget->priv->allocation.y;
6045 widget_window = gtk_widget_get_window (widget);
6047 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6050 gdk_window_get_position (w, &wx, &wy);
6067 * gtk_cairo_transform_to_window:
6068 * @cr: the cairo context to transform
6069 * @widget: the widget the context is currently centered for
6070 * @window: the window to transform the context to
6072 * Transforms the given cairo context @cr that from @widget-relative
6073 * coordinates to @window-relative coordinates.
6074 * If the @widget's window is not an ancestor of @window, no
6075 * modification will be applied.
6077 * This is the inverse to the transformation GTK applies when
6078 * preparing an expose event to be emitted with the #GtkWidget::draw
6079 * signal. It is intended to help porting multiwindow widgets from
6080 * GTK+ 2 to the rendering architecture of GTK+ 3.
6085 gtk_cairo_transform_to_window (cairo_t *cr,
6091 g_return_if_fail (cr != NULL);
6092 g_return_if_fail (GTK_IS_WIDGET (widget));
6093 g_return_if_fail (GDK_IS_WINDOW (window));
6095 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6096 cairo_translate (cr, x, y);
6100 * gtk_widget_send_expose:
6101 * @widget: a #GtkWidget
6102 * @event: a expose #GdkEvent
6104 * Very rarely-used function. This function is used to emit
6105 * an expose event on a widget. This function is not normally used
6106 * directly. The only time it is used is when propagating an expose
6107 * event to a child %NO_WINDOW widget, and that is normally done
6108 * using gtk_container_propagate_draw().
6110 * If you want to force an area of a window to be redrawn,
6111 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6112 * To cause the redraw to be done immediately, follow that call
6113 * with a call to gdk_window_process_updates().
6115 * Return value: return from the event signal emission (%TRUE if
6116 * the event was handled)
6119 gtk_widget_send_expose (GtkWidget *widget,
6122 gboolean result = FALSE;
6127 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6128 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6129 g_return_val_if_fail (event != NULL, TRUE);
6130 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6132 cr = gdk_cairo_create (event->expose.window);
6133 gtk_cairo_set_event (cr, &event->expose);
6135 gdk_cairo_region (cr, event->expose.region);
6138 do_clip = _gtk_widget_get_translation_to_window (widget,
6139 event->expose.window,
6141 cairo_translate (cr, -x, -y);
6143 _gtk_widget_draw_internal (widget, cr, do_clip);
6145 /* unset here, so if someone keeps a reference to cr we
6146 * don't leak the window. */
6147 gtk_cairo_set_event (cr, NULL);
6154 event_window_is_still_viewable (GdkEvent *event)
6156 /* Check that we think the event's window is viewable before
6157 * delivering the event, to prevent suprises. We do this here
6158 * at the last moment, since the event may have been queued
6159 * up behind other events, held over a recursive main loop, etc.
6161 switch (event->type)
6164 case GDK_MOTION_NOTIFY:
6165 case GDK_BUTTON_PRESS:
6166 case GDK_2BUTTON_PRESS:
6167 case GDK_3BUTTON_PRESS:
6169 case GDK_ENTER_NOTIFY:
6170 case GDK_PROXIMITY_IN:
6172 return event->any.window && gdk_window_is_viewable (event->any.window);
6175 /* The following events are the second half of paired events;
6176 * we always deliver them to deal with widgets that clean up
6177 * on the second half.
6179 case GDK_BUTTON_RELEASE:
6180 case GDK_KEY_RELEASE:
6181 case GDK_LEAVE_NOTIFY:
6182 case GDK_PROXIMITY_OUT:
6186 /* Remaining events would make sense on an not-viewable window,
6187 * or don't have an associated window.
6194 gtk_widget_event_internal (GtkWidget *widget,
6197 gboolean return_val = FALSE;
6199 /* We check only once for is-still-visible; if someone
6200 * hides the window in on of the signals on the widget,
6201 * they are responsible for returning TRUE to terminate
6204 if (!event_window_is_still_viewable (event))
6207 g_object_ref (widget);
6209 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6210 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6215 switch (event->type)
6221 case GDK_BUTTON_PRESS:
6222 case GDK_2BUTTON_PRESS:
6223 case GDK_3BUTTON_PRESS:
6224 signal_num = BUTTON_PRESS_EVENT;
6226 case GDK_TOUCH_BEGIN:
6227 case GDK_TOUCH_UPDATE:
6229 case GDK_TOUCH_CANCEL:
6230 signal_num = TOUCH_EVENT;
6233 signal_num = SCROLL_EVENT;
6235 case GDK_BUTTON_RELEASE:
6236 signal_num = BUTTON_RELEASE_EVENT;
6238 case GDK_MOTION_NOTIFY:
6239 signal_num = MOTION_NOTIFY_EVENT;
6242 signal_num = DELETE_EVENT;
6245 signal_num = DESTROY_EVENT;
6246 _gtk_tooltip_hide (widget);
6249 signal_num = KEY_PRESS_EVENT;
6251 case GDK_KEY_RELEASE:
6252 signal_num = KEY_RELEASE_EVENT;
6254 case GDK_ENTER_NOTIFY:
6255 signal_num = ENTER_NOTIFY_EVENT;
6257 case GDK_LEAVE_NOTIFY:
6258 signal_num = LEAVE_NOTIFY_EVENT;
6260 case GDK_FOCUS_CHANGE:
6261 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6262 if (event->focus_change.in)
6263 _gtk_tooltip_focus_in (widget);
6265 _gtk_tooltip_focus_out (widget);
6268 signal_num = CONFIGURE_EVENT;
6271 signal_num = MAP_EVENT;
6274 signal_num = UNMAP_EVENT;
6276 case GDK_WINDOW_STATE:
6277 signal_num = WINDOW_STATE_EVENT;
6279 case GDK_PROPERTY_NOTIFY:
6280 signal_num = PROPERTY_NOTIFY_EVENT;
6282 case GDK_SELECTION_CLEAR:
6283 signal_num = SELECTION_CLEAR_EVENT;
6285 case GDK_SELECTION_REQUEST:
6286 signal_num = SELECTION_REQUEST_EVENT;
6288 case GDK_SELECTION_NOTIFY:
6289 signal_num = SELECTION_NOTIFY_EVENT;
6291 case GDK_PROXIMITY_IN:
6292 signal_num = PROXIMITY_IN_EVENT;
6294 case GDK_PROXIMITY_OUT:
6295 signal_num = PROXIMITY_OUT_EVENT;
6297 case GDK_VISIBILITY_NOTIFY:
6298 signal_num = VISIBILITY_NOTIFY_EVENT;
6300 case GDK_GRAB_BROKEN:
6301 signal_num = GRAB_BROKEN_EVENT;
6304 signal_num = DAMAGE_EVENT;
6307 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6311 if (signal_num != -1)
6312 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6314 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6315 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6319 g_object_unref (widget);
6325 * gtk_widget_activate:
6326 * @widget: a #GtkWidget that's activatable
6328 * For widgets that can be "activated" (buttons, menu items, etc.)
6329 * this function activates them. Activation is what happens when you
6330 * press Enter on a widget during key navigation. If @widget isn't
6331 * activatable, the function returns %FALSE.
6333 * Return value: %TRUE if the widget was activatable
6336 gtk_widget_activate (GtkWidget *widget)
6338 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6340 if (WIDGET_CLASS (widget)->activate_signal)
6342 /* FIXME: we should eventually check the signals signature here */
6343 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6352 gtk_widget_reparent_subwindows (GtkWidget *widget,
6353 GdkWindow *new_window)
6355 GtkWidgetPrivate *priv = widget->priv;
6357 if (!gtk_widget_get_has_window (widget))
6359 GList *children = gdk_window_get_children (priv->window);
6362 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6364 GdkWindow *window = tmp_list->data;
6367 gdk_window_get_user_data (window, &child);
6368 while (child && child != widget)
6369 child = ((GtkWidget*) child)->priv->parent;
6372 gdk_window_reparent (window, new_window, 0, 0);
6375 g_list_free (children);
6380 GList *tmp_list, *children;
6382 parent = gdk_window_get_parent (priv->window);
6385 gdk_window_reparent (priv->window, new_window, 0, 0);
6388 children = gdk_window_get_children (parent);
6390 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6392 GdkWindow *window = tmp_list->data;
6395 gdk_window_get_user_data (window, &child);
6397 if (child == widget)
6398 gdk_window_reparent (window, new_window, 0, 0);
6401 g_list_free (children);
6407 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6408 gpointer client_data)
6410 GtkWidgetPrivate *priv = widget->priv;
6412 g_assert (client_data != NULL);
6414 if (!gtk_widget_get_has_window (widget))
6417 g_object_unref (priv->window);
6418 priv->window = (GdkWindow*) client_data;
6420 g_object_ref (priv->window);
6422 if (GTK_IS_CONTAINER (widget))
6423 gtk_container_forall (GTK_CONTAINER (widget),
6424 gtk_widget_reparent_fixup_child,
6430 * gtk_widget_reparent:
6431 * @widget: a #GtkWidget
6432 * @new_parent: a #GtkContainer to move the widget into
6434 * Moves a widget from one #GtkContainer to another, handling reference
6435 * count issues to avoid destroying the widget.
6438 gtk_widget_reparent (GtkWidget *widget,
6439 GtkWidget *new_parent)
6441 GtkWidgetPrivate *priv;
6443 g_return_if_fail (GTK_IS_WIDGET (widget));
6444 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6445 priv = widget->priv;
6446 g_return_if_fail (priv->parent != NULL);
6448 if (priv->parent != new_parent)
6450 /* First try to see if we can get away without unrealizing
6451 * the widget as we reparent it. if so we set a flag so
6452 * that gtk_widget_unparent doesn't unrealize widget
6454 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6455 priv->in_reparent = TRUE;
6457 g_object_ref (widget);
6458 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6459 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6460 g_object_unref (widget);
6462 if (priv->in_reparent)
6464 priv->in_reparent = FALSE;
6466 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6467 gtk_widget_reparent_fixup_child (widget,
6468 gtk_widget_get_parent_window (widget));
6471 g_object_notify (G_OBJECT (widget), "parent");
6476 * gtk_widget_intersect:
6477 * @widget: a #GtkWidget
6478 * @area: a rectangle
6479 * @intersection: rectangle to store intersection of @widget and @area
6481 * Computes the intersection of a @widget's area and @area, storing
6482 * the intersection in @intersection, and returns %TRUE if there was
6483 * an intersection. @intersection may be %NULL if you're only
6484 * interested in whether there was an intersection.
6486 * Return value: %TRUE if there was an intersection
6489 gtk_widget_intersect (GtkWidget *widget,
6490 const GdkRectangle *area,
6491 GdkRectangle *intersection)
6493 GtkWidgetPrivate *priv;
6498 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6499 g_return_val_if_fail (area != NULL, FALSE);
6501 priv = widget->priv;
6504 dest = intersection;
6508 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6510 if (return_val && intersection && gtk_widget_get_has_window (widget))
6512 intersection->x -= priv->allocation.x;
6513 intersection->y -= priv->allocation.y;
6520 * gtk_widget_region_intersect:
6521 * @widget: a #GtkWidget
6522 * @region: a #cairo_region_t, in the same coordinate system as
6523 * @widget->allocation. That is, relative to @widget->window
6524 * for %NO_WINDOW widgets; relative to the parent window
6525 * of @widget->window for widgets with their own window.
6527 * Computes the intersection of a @widget's area and @region, returning
6528 * the intersection. The result may be empty, use cairo_region_is_empty() to
6531 * Returns: A newly allocated region holding the intersection of @widget
6532 * and @region. The coordinates of the return value are relative to
6533 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6534 * window of @widget->window for widgets with their own window.
6537 gtk_widget_region_intersect (GtkWidget *widget,
6538 const cairo_region_t *region)
6541 cairo_region_t *dest;
6543 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6544 g_return_val_if_fail (region != NULL, NULL);
6546 gtk_widget_get_allocation (widget, &rect);
6548 dest = cairo_region_create_rectangle (&rect);
6550 cairo_region_intersect (dest, region);
6556 * _gtk_widget_grab_notify:
6557 * @widget: a #GtkWidget
6558 * @was_grabbed: whether a grab is now in effect
6560 * Emits the #GtkWidget::grab-notify signal on @widget.
6565 _gtk_widget_grab_notify (GtkWidget *widget,
6566 gboolean was_grabbed)
6568 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6572 * gtk_widget_grab_focus:
6573 * @widget: a #GtkWidget
6575 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6576 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6577 * something like #GtkFrame won't work.
6579 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6580 * gtk_widget_set_can_focus() to modify that flag.
6582 * The widget also needs to be realized and mapped. This is indicated by the
6583 * related signals. Grabbing the focus immediately after creating the widget
6584 * will likely fail and cause critical warnings.
6587 gtk_widget_grab_focus (GtkWidget *widget)
6589 g_return_if_fail (GTK_IS_WIDGET (widget));
6591 if (!gtk_widget_is_sensitive (widget))
6594 g_object_ref (widget);
6595 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6596 g_object_notify (G_OBJECT (widget), "has-focus");
6597 g_object_unref (widget);
6601 reset_focus_recurse (GtkWidget *widget,
6604 if (GTK_IS_CONTAINER (widget))
6606 GtkContainer *container;
6608 container = GTK_CONTAINER (widget);
6609 gtk_container_set_focus_child (container, NULL);
6611 gtk_container_foreach (container,
6612 reset_focus_recurse,
6618 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6620 if (gtk_widget_get_can_focus (focus_widget))
6622 GtkWidget *toplevel;
6625 /* clear the current focus setting, break if the current widget
6626 * is the focus widget's parent, since containers above that will
6627 * be set by the next loop.
6629 toplevel = gtk_widget_get_toplevel (focus_widget);
6630 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6632 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6634 if (widget == focus_widget)
6636 /* We call _gtk_window_internal_set_focus() here so that the
6637 * toplevel window can request the focus if necessary.
6638 * This is needed when the toplevel is a GtkPlug
6640 if (!gtk_widget_has_focus (widget))
6641 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6648 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6650 if (widget != common_ancestor)
6652 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6654 widget = widget->priv->parent;
6655 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6660 else if (toplevel != focus_widget)
6662 /* gtk_widget_grab_focus() operates on a tree without window...
6663 * actually, this is very questionable behaviour.
6666 gtk_container_foreach (GTK_CONTAINER (toplevel),
6667 reset_focus_recurse,
6671 /* now propagate the new focus up the widget tree and finally
6672 * set it on the window
6674 widget = focus_widget;
6675 while (widget->priv->parent)
6677 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6678 widget = widget->priv->parent;
6680 if (GTK_IS_WINDOW (widget))
6681 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6686 gtk_widget_real_query_tooltip (GtkWidget *widget,
6689 gboolean keyboard_tip,
6690 GtkTooltip *tooltip)
6692 gchar *tooltip_markup;
6693 gboolean has_tooltip;
6695 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6696 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6698 if (has_tooltip && tooltip_markup)
6700 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6708 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6709 GtkStateFlags old_state)
6711 gtk_widget_update_pango_context (widget);
6715 gtk_widget_real_style_updated (GtkWidget *widget)
6717 GtkWidgetPrivate *priv = widget->priv;
6719 gtk_widget_update_pango_context (widget);
6721 if (priv->style != NULL &&
6722 priv->style != gtk_widget_get_default_style ())
6724 /* Trigger ::style-set for old
6725 * widgets not listening to this
6727 g_signal_emit (widget,
6728 widget_signals[STYLE_SET],
6730 widget->priv->style);
6733 if (widget->priv->context)
6735 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6737 if (gtk_widget_get_realized (widget) &&
6738 gtk_widget_get_has_window (widget) &&
6739 !gtk_widget_get_app_paintable (widget))
6740 gtk_style_context_set_background (widget->priv->context,
6741 widget->priv->window);
6743 if (widget->priv->anchored)
6745 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6746 gtk_widget_queue_resize (widget);
6748 gtk_widget_queue_draw (widget);
6753 if (widget->priv->anchored)
6754 gtk_widget_queue_resize (widget);
6759 gtk_widget_real_show_help (GtkWidget *widget,
6760 GtkWidgetHelpType help_type)
6762 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6764 _gtk_tooltip_toggle_keyboard_mode (widget);
6773 gtk_widget_real_focus (GtkWidget *widget,
6774 GtkDirectionType direction)
6776 if (!gtk_widget_get_can_focus (widget))
6779 if (!gtk_widget_is_focus (widget))
6781 gtk_widget_grab_focus (widget);
6789 gtk_widget_real_move_focus (GtkWidget *widget,
6790 GtkDirectionType direction)
6792 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6794 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6796 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6802 gtk_widget_real_keynav_failed (GtkWidget *widget,
6803 GtkDirectionType direction)
6805 gboolean cursor_only;
6809 case GTK_DIR_TAB_FORWARD:
6810 case GTK_DIR_TAB_BACKWARD:
6817 g_object_get (gtk_widget_get_settings (widget),
6818 "gtk-keynav-cursor-only", &cursor_only,
6825 gtk_widget_error_bell (widget);
6831 * gtk_widget_set_can_focus:
6832 * @widget: a #GtkWidget
6833 * @can_focus: whether or not @widget can own the input focus.
6835 * Specifies whether @widget can own the input focus. See
6836 * gtk_widget_grab_focus() for actually setting the input focus on a
6842 gtk_widget_set_can_focus (GtkWidget *widget,
6845 g_return_if_fail (GTK_IS_WIDGET (widget));
6847 if (widget->priv->can_focus != can_focus)
6849 widget->priv->can_focus = can_focus;
6851 gtk_widget_queue_resize (widget);
6852 g_object_notify (G_OBJECT (widget), "can-focus");
6857 * gtk_widget_get_can_focus:
6858 * @widget: a #GtkWidget
6860 * Determines whether @widget can own the input focus. See
6861 * gtk_widget_set_can_focus().
6863 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6868 gtk_widget_get_can_focus (GtkWidget *widget)
6870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6872 return widget->priv->can_focus;
6876 * gtk_widget_has_focus:
6877 * @widget: a #GtkWidget
6879 * Determines if the widget has the global input focus. See
6880 * gtk_widget_is_focus() for the difference between having the global
6881 * input focus, and only having the focus within a toplevel.
6883 * Return value: %TRUE if the widget has the global input focus.
6888 gtk_widget_has_focus (GtkWidget *widget)
6890 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6892 return widget->priv->has_focus;
6896 * gtk_widget_has_visible_focus:
6897 * @widget: a #GtkWidget
6899 * Determines if the widget should show a visible indication that
6900 * it has the global input focus. This is a convenience function for
6901 * use in ::draw handlers that takes into account whether focus
6902 * indication should currently be shown in the toplevel window of
6903 * @widget. See gtk_window_get_focus_visible() for more information
6904 * about focus indication.
6906 * To find out if the widget has the global input focus, use
6907 * gtk_widget_has_focus().
6909 * Return value: %TRUE if the widget should display a 'focus rectangle'
6914 gtk_widget_has_visible_focus (GtkWidget *widget)
6916 gboolean draw_focus;
6918 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6920 if (widget->priv->has_focus)
6922 GtkWidget *toplevel;
6924 toplevel = gtk_widget_get_toplevel (widget);
6926 if (GTK_IS_WINDOW (toplevel))
6927 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6938 * gtk_widget_is_focus:
6939 * @widget: a #GtkWidget
6941 * Determines if the widget is the focus widget within its
6942 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6943 * necessarily set; %HAS_FOCUS will only be set if the
6944 * toplevel widget additionally has the global input focus.)
6946 * Return value: %TRUE if the widget is the focus widget.
6949 gtk_widget_is_focus (GtkWidget *widget)
6951 GtkWidget *toplevel;
6953 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6955 toplevel = gtk_widget_get_toplevel (widget);
6957 if (GTK_IS_WINDOW (toplevel))
6958 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6964 * gtk_widget_set_can_default:
6965 * @widget: a #GtkWidget
6966 * @can_default: whether or not @widget can be a default widget.
6968 * Specifies whether @widget can be a default widget. See
6969 * gtk_widget_grab_default() for details about the meaning of
6975 gtk_widget_set_can_default (GtkWidget *widget,
6976 gboolean can_default)
6978 g_return_if_fail (GTK_IS_WIDGET (widget));
6980 if (widget->priv->can_default != can_default)
6982 widget->priv->can_default = can_default;
6984 gtk_widget_queue_resize (widget);
6985 g_object_notify (G_OBJECT (widget), "can-default");
6990 * gtk_widget_get_can_default:
6991 * @widget: a #GtkWidget
6993 * Determines whether @widget can be a default widget. See
6994 * gtk_widget_set_can_default().
6996 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7001 gtk_widget_get_can_default (GtkWidget *widget)
7003 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7005 return widget->priv->can_default;
7009 * gtk_widget_has_default:
7010 * @widget: a #GtkWidget
7012 * Determines whether @widget is the current default widget within its
7013 * toplevel. See gtk_widget_set_can_default().
7015 * Return value: %TRUE if @widget is the current default widget within
7016 * its toplevel, %FALSE otherwise
7021 gtk_widget_has_default (GtkWidget *widget)
7023 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7025 return widget->priv->has_default;
7029 _gtk_widget_set_has_default (GtkWidget *widget,
7030 gboolean has_default)
7032 GtkStyleContext *context;
7034 widget->priv->has_default = has_default;
7036 context = gtk_widget_get_style_context (widget);
7039 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7041 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7045 * gtk_widget_grab_default:
7046 * @widget: a #GtkWidget
7048 * Causes @widget to become the default widget. @widget must be able to be
7049 * a default widget; typically you would ensure this yourself
7050 * by calling gtk_widget_set_can_default() with a %TRUE value.
7051 * The default widget is activated when
7052 * the user presses Enter in a window. Default widgets must be
7053 * activatable, that is, gtk_widget_activate() should affect them. Note
7054 * that #GtkEntry widgets require the "activates-default" property
7055 * set to %TRUE before they activate the default widget when Enter
7056 * is pressed and the #GtkEntry is focused.
7059 gtk_widget_grab_default (GtkWidget *widget)
7063 g_return_if_fail (GTK_IS_WIDGET (widget));
7064 g_return_if_fail (gtk_widget_get_can_default (widget));
7066 window = gtk_widget_get_toplevel (widget);
7068 if (window && gtk_widget_is_toplevel (window))
7069 gtk_window_set_default (GTK_WINDOW (window), widget);
7071 g_warning (G_STRLOC ": widget not within a GtkWindow");
7075 * gtk_widget_set_receives_default:
7076 * @widget: a #GtkWidget
7077 * @receives_default: whether or not @widget can be a default widget.
7079 * Specifies whether @widget will be treated as the default widget
7080 * within its toplevel when it has the focus, even if another widget
7083 * See gtk_widget_grab_default() for details about the meaning of
7089 gtk_widget_set_receives_default (GtkWidget *widget,
7090 gboolean receives_default)
7092 g_return_if_fail (GTK_IS_WIDGET (widget));
7094 if (widget->priv->receives_default != receives_default)
7096 widget->priv->receives_default = receives_default;
7098 g_object_notify (G_OBJECT (widget), "receives-default");
7103 * gtk_widget_get_receives_default:
7104 * @widget: a #GtkWidget
7106 * Determines whether @widget is alyways treated as default widget
7107 * withing its toplevel when it has the focus, even if another widget
7110 * See gtk_widget_set_receives_default().
7112 * Return value: %TRUE if @widget acts as default widget when focussed,
7118 gtk_widget_get_receives_default (GtkWidget *widget)
7120 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7122 return widget->priv->receives_default;
7126 * gtk_widget_has_grab:
7127 * @widget: a #GtkWidget
7129 * Determines whether the widget is currently grabbing events, so it
7130 * is the only widget receiving input events (keyboard and mouse).
7132 * See also gtk_grab_add().
7134 * Return value: %TRUE if the widget is in the grab_widgets stack
7139 gtk_widget_has_grab (GtkWidget *widget)
7141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7143 return widget->priv->has_grab;
7147 _gtk_widget_set_has_grab (GtkWidget *widget,
7150 widget->priv->has_grab = has_grab;
7154 * gtk_widget_device_is_shadowed:
7155 * @widget: a #GtkWidget
7156 * @device: a #GdkDevice
7158 * Returns %TRUE if @device has been shadowed by a GTK+
7159 * device grab on another widget, so it would stop sending
7160 * events to @widget. This may be used in the
7161 * #GtkWidget::grab-notify signal to check for specific
7162 * devices. See gtk_device_grab_add().
7164 * Returns: %TRUE if there is an ongoing grab on @device
7165 * by another #GtkWidget than @widget.
7170 gtk_widget_device_is_shadowed (GtkWidget *widget,
7173 GtkWindowGroup *group;
7174 GtkWidget *grab_widget, *toplevel;
7176 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7177 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7179 if (!gtk_widget_get_realized (widget))
7182 toplevel = gtk_widget_get_toplevel (widget);
7184 if (GTK_IS_WINDOW (toplevel))
7185 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7187 group = gtk_window_get_group (NULL);
7189 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7191 /* Widget not inside the hierarchy of grab_widget */
7193 widget != grab_widget &&
7194 !gtk_widget_is_ancestor (widget, grab_widget))
7197 grab_widget = gtk_window_group_get_current_grab (group);
7198 if (grab_widget && widget != grab_widget &&
7199 !gtk_widget_is_ancestor (widget, grab_widget))
7206 * gtk_widget_set_name:
7207 * @widget: a #GtkWidget
7208 * @name: name for the widget
7210 * Widgets can be named, which allows you to refer to them from a
7211 * CSS file. You can apply a style to widgets with a particular name
7212 * in the CSS file. See the documentation for the CSS syntax (on the
7213 * same page as the docs for #GtkStyleContext).
7215 * Note that the CSS syntax has certain special characters to delimit
7216 * and represent elements in a selector (period, #, >, *...),
7217 * so using these will make your widget impossible to match by name.
7218 * Any combination of alphanumeric symbols, dashes and underscores will
7222 gtk_widget_set_name (GtkWidget *widget,
7225 GtkWidgetPrivate *priv;
7228 g_return_if_fail (GTK_IS_WIDGET (widget));
7230 priv = widget->priv;
7232 new_name = g_strdup (name);
7233 g_free (priv->name);
7234 priv->name = new_name;
7236 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7238 g_object_notify (G_OBJECT (widget), "name");
7242 * gtk_widget_get_name:
7243 * @widget: a #GtkWidget
7245 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7246 * significance of widget names.
7248 * Return value: name of the widget. This string is owned by GTK+ and
7249 * should not be modified or freed
7252 gtk_widget_get_name (GtkWidget *widget)
7254 GtkWidgetPrivate *priv;
7256 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7258 priv = widget->priv;
7262 return G_OBJECT_TYPE_NAME (widget);
7266 gtk_widget_update_state_flags (GtkWidget *widget,
7267 GtkStateFlags flags_to_set,
7268 GtkStateFlags flags_to_unset)
7270 GtkWidgetPrivate *priv;
7272 priv = widget->priv;
7274 /* Handle insensitive first, since it is propagated
7275 * differently throughout the widget hierarchy.
7277 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7278 gtk_widget_set_sensitive (widget, TRUE);
7279 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7280 gtk_widget_set_sensitive (widget, FALSE);
7282 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7283 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7285 if (flags_to_set != 0 || flags_to_unset != 0)
7289 data.flags_to_set = flags_to_set;
7290 data.flags_to_unset = flags_to_unset;
7292 gtk_widget_propagate_state (widget, &data);
7297 * gtk_widget_set_state_flags:
7298 * @widget: a #GtkWidget
7299 * @flags: State flags to turn on
7300 * @clear: Whether to clear state before turning on @flags
7302 * This function is for use in widget implementations. Turns on flag
7303 * values in the current widget state (insensitive, prelighted, etc.).
7305 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7306 * will be propagated down to all non-internal children if @widget is a
7307 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7308 * down to all #GtkContainer children by different means than turning on the
7309 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7310 * gtk_widget_is_sensitive() will make use of these.
7315 gtk_widget_set_state_flags (GtkWidget *widget,
7316 GtkStateFlags flags,
7319 g_return_if_fail (GTK_IS_WIDGET (widget));
7321 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7322 (clear && widget->priv->state_flags == flags))
7326 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7328 gtk_widget_update_state_flags (widget, flags, 0);
7332 * gtk_widget_unset_state_flags:
7333 * @widget: a #GtkWidget
7334 * @flags: State flags to turn off
7336 * This function is for use in widget implementations. Turns off flag
7337 * values for the current widget state (insensitive, prelighted, etc.).
7338 * See gtk_widget_set_state_flags().
7343 gtk_widget_unset_state_flags (GtkWidget *widget,
7344 GtkStateFlags flags)
7346 g_return_if_fail (GTK_IS_WIDGET (widget));
7348 if ((widget->priv->state_flags & flags) == 0)
7351 gtk_widget_update_state_flags (widget, 0, flags);
7355 * gtk_widget_get_state_flags:
7356 * @widget: a #GtkWidget
7358 * Returns the widget state as a flag set. It is worth mentioning
7359 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7360 * returned, that is, also based on parent insensitivity, even if
7361 * @widget itself is sensitive.
7363 * Returns: The state flags for widget
7368 gtk_widget_get_state_flags (GtkWidget *widget)
7370 GtkStateFlags flags;
7372 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7374 flags = widget->priv->state_flags;
7376 if (gtk_widget_has_focus (widget))
7377 flags |= GTK_STATE_FLAG_FOCUSED;
7383 * gtk_widget_set_state:
7384 * @widget: a #GtkWidget
7385 * @state: new state for @widget
7387 * This function is for use in widget implementations. Sets the state
7388 * of a widget (insensitive, prelighted, etc.) Usually you should set
7389 * the state using wrapper functions such as gtk_widget_set_sensitive().
7391 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7394 gtk_widget_set_state (GtkWidget *widget,
7397 GtkStateFlags flags;
7399 if (state == gtk_widget_get_state (widget))
7404 case GTK_STATE_ACTIVE:
7405 flags = GTK_STATE_FLAG_ACTIVE;
7407 case GTK_STATE_PRELIGHT:
7408 flags = GTK_STATE_FLAG_PRELIGHT;
7410 case GTK_STATE_SELECTED:
7411 flags = GTK_STATE_FLAG_SELECTED;
7413 case GTK_STATE_INSENSITIVE:
7414 flags = GTK_STATE_FLAG_INSENSITIVE;
7416 case GTK_STATE_INCONSISTENT:
7417 flags = GTK_STATE_FLAG_INCONSISTENT;
7419 case GTK_STATE_FOCUSED:
7420 flags = GTK_STATE_FLAG_FOCUSED;
7422 case GTK_STATE_NORMAL:
7428 gtk_widget_update_state_flags (widget,
7430 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7431 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7435 * gtk_widget_get_state:
7436 * @widget: a #GtkWidget
7438 * Returns the widget's state. See gtk_widget_set_state().
7440 * Returns: the state of @widget.
7444 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7447 gtk_widget_get_state (GtkWidget *widget)
7449 GtkStateFlags flags;
7451 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7453 flags = gtk_widget_get_state_flags (widget);
7455 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7456 return GTK_STATE_INSENSITIVE;
7457 else if (flags & GTK_STATE_FLAG_ACTIVE)
7458 return GTK_STATE_ACTIVE;
7459 else if (flags & GTK_STATE_FLAG_SELECTED)
7460 return GTK_STATE_SELECTED;
7461 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7462 return GTK_STATE_PRELIGHT;
7464 return GTK_STATE_NORMAL;
7468 * gtk_widget_set_visible:
7469 * @widget: a #GtkWidget
7470 * @visible: whether the widget should be shown or not
7472 * Sets the visibility state of @widget. Note that setting this to
7473 * %TRUE doesn't mean the widget is actually viewable, see
7474 * gtk_widget_get_visible().
7476 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7477 * but is nicer to use when the visibility of the widget depends on
7483 gtk_widget_set_visible (GtkWidget *widget,
7486 g_return_if_fail (GTK_IS_WIDGET (widget));
7488 if (visible != gtk_widget_get_visible (widget))
7491 gtk_widget_show (widget);
7493 gtk_widget_hide (widget);
7498 _gtk_widget_set_visible_flag (GtkWidget *widget,
7501 GtkWidgetPrivate *priv = widget->priv;
7503 priv->visible = visible;
7507 priv->allocation.x = -1;
7508 priv->allocation.y = -1;
7509 priv->allocation.width = 1;
7510 priv->allocation.height = 1;
7515 * gtk_widget_get_visible:
7516 * @widget: a #GtkWidget
7518 * Determines whether the widget is visible. If you want to
7519 * take into account whether the widget's parent is also marked as
7520 * visible, use gtk_widget_is_visible() instead.
7522 * This function does not check if the widget is obscured in any way.
7524 * See gtk_widget_set_visible().
7526 * Return value: %TRUE if the widget is visible
7531 gtk_widget_get_visible (GtkWidget *widget)
7533 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7535 return widget->priv->visible;
7539 * gtk_widget_is_visible:
7540 * @widget: a #GtkWidget
7542 * Determines whether the widget and all its parents are marked as
7545 * This function does not check if the widget is obscured in any way.
7547 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7549 * Return value: %TRUE if the widget and all its parents are visible
7554 gtk_widget_is_visible (GtkWidget *widget)
7556 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7560 GtkWidgetPrivate *priv = widget->priv;
7565 widget = priv->parent;
7572 * gtk_widget_set_has_window:
7573 * @widget: a #GtkWidget
7574 * @has_window: whether or not @widget has a window.
7576 * Specifies whether @widget has a #GdkWindow of its own. Note that
7577 * all realized widgets have a non-%NULL "window" pointer
7578 * (gtk_widget_get_window() never returns a %NULL window when a widget
7579 * is realized), but for many of them it's actually the #GdkWindow of
7580 * one of its parent widgets. Widgets that do not create a %window for
7581 * themselves in #GtkWidget::realize must announce this by
7582 * calling this function with @has_window = %FALSE.
7584 * This function should only be called by widget implementations,
7585 * and they should call it in their init() function.
7590 gtk_widget_set_has_window (GtkWidget *widget,
7591 gboolean has_window)
7593 g_return_if_fail (GTK_IS_WIDGET (widget));
7595 widget->priv->no_window = !has_window;
7599 * gtk_widget_get_has_window:
7600 * @widget: a #GtkWidget
7602 * Determines whether @widget has a #GdkWindow of its own. See
7603 * gtk_widget_set_has_window().
7605 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7610 gtk_widget_get_has_window (GtkWidget *widget)
7612 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7614 return ! widget->priv->no_window;
7618 * gtk_widget_is_toplevel:
7619 * @widget: a #GtkWidget
7621 * Determines whether @widget is a toplevel widget.
7623 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7624 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7627 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7632 gtk_widget_is_toplevel (GtkWidget *widget)
7634 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7636 return widget->priv->toplevel;
7640 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7641 gboolean is_toplevel)
7643 widget->priv->toplevel = is_toplevel;
7647 * gtk_widget_is_drawable:
7648 * @widget: a #GtkWidget
7650 * Determines whether @widget can be drawn to. A widget can be drawn
7651 * to if it is mapped and visible.
7653 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7658 gtk_widget_is_drawable (GtkWidget *widget)
7660 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7662 return (gtk_widget_get_visible (widget) &&
7663 gtk_widget_get_mapped (widget));
7667 * gtk_widget_get_realized:
7668 * @widget: a #GtkWidget
7670 * Determines whether @widget is realized.
7672 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7677 gtk_widget_get_realized (GtkWidget *widget)
7679 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7681 return widget->priv->realized;
7685 * gtk_widget_set_realized:
7686 * @widget: a #GtkWidget
7687 * @realized: %TRUE to mark the widget as realized
7689 * Marks the widget as being realized.
7691 * This function should only ever be called in a derived widget's
7692 * "realize" or "unrealize" implementation.
7697 gtk_widget_set_realized (GtkWidget *widget,
7700 g_return_if_fail (GTK_IS_WIDGET (widget));
7702 widget->priv->realized = realized;
7706 * gtk_widget_get_mapped:
7707 * @widget: a #GtkWidget
7709 * Whether the widget is mapped.
7711 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7716 gtk_widget_get_mapped (GtkWidget *widget)
7718 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7720 return widget->priv->mapped;
7724 * gtk_widget_set_mapped:
7725 * @widget: a #GtkWidget
7726 * @mapped: %TRUE to mark the widget as mapped
7728 * Marks the widget as being realized.
7730 * This function should only ever be called in a derived widget's
7731 * "map" or "unmap" implementation.
7736 gtk_widget_set_mapped (GtkWidget *widget,
7739 g_return_if_fail (GTK_IS_WIDGET (widget));
7741 widget->priv->mapped = mapped;
7745 * gtk_widget_set_app_paintable:
7746 * @widget: a #GtkWidget
7747 * @app_paintable: %TRUE if the application will paint on the widget
7749 * Sets whether the application intends to draw on the widget in
7750 * an #GtkWidget::draw handler.
7752 * This is a hint to the widget and does not affect the behavior of
7753 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7754 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7755 * the effect is to suppress default themed drawing of the widget's
7756 * background. (Children of the widget will still be drawn.) The application
7757 * is then entirely responsible for drawing the widget background.
7759 * Note that the background is still drawn when the widget is mapped.
7762 gtk_widget_set_app_paintable (GtkWidget *widget,
7763 gboolean app_paintable)
7765 g_return_if_fail (GTK_IS_WIDGET (widget));
7767 app_paintable = (app_paintable != FALSE);
7769 if (widget->priv->app_paintable != app_paintable)
7771 widget->priv->app_paintable = app_paintable;
7773 if (gtk_widget_is_drawable (widget))
7774 gtk_widget_queue_draw (widget);
7776 g_object_notify (G_OBJECT (widget), "app-paintable");
7781 * gtk_widget_get_app_paintable:
7782 * @widget: a #GtkWidget
7784 * Determines whether the application intends to draw on the widget in
7785 * an #GtkWidget::draw handler.
7787 * See gtk_widget_set_app_paintable()
7789 * Return value: %TRUE if the widget is app paintable
7794 gtk_widget_get_app_paintable (GtkWidget *widget)
7796 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7798 return widget->priv->app_paintable;
7802 * gtk_widget_set_double_buffered:
7803 * @widget: a #GtkWidget
7804 * @double_buffered: %TRUE to double-buffer a widget
7806 * Widgets are double buffered by default; you can use this function
7807 * to turn off the buffering. "Double buffered" simply means that
7808 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7809 * automatically around expose events sent to the
7810 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7811 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7812 * buffer to the screen. The result is that users see the window
7813 * update in one smooth step, and don't see individual graphics
7814 * primitives being rendered.
7816 * In very simple terms, double buffered widgets don't flicker,
7817 * so you would only use this function to turn off double buffering
7818 * if you had special needs and really knew what you were doing.
7820 * Note: if you turn off double-buffering, you have to handle
7821 * expose events, since even the clearing to the background color or
7822 * pixmap will not happen automatically (as it is done in
7823 * gdk_window_begin_paint_region()).
7826 gtk_widget_set_double_buffered (GtkWidget *widget,
7827 gboolean double_buffered)
7829 g_return_if_fail (GTK_IS_WIDGET (widget));
7831 double_buffered = (double_buffered != FALSE);
7833 if (widget->priv->double_buffered != double_buffered)
7835 widget->priv->double_buffered = double_buffered;
7837 g_object_notify (G_OBJECT (widget), "double-buffered");
7842 * gtk_widget_get_double_buffered:
7843 * @widget: a #GtkWidget
7845 * Determines whether the widget is double buffered.
7847 * See gtk_widget_set_double_buffered()
7849 * Return value: %TRUE if the widget is double buffered
7854 gtk_widget_get_double_buffered (GtkWidget *widget)
7856 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7858 return widget->priv->double_buffered;
7862 * gtk_widget_set_redraw_on_allocate:
7863 * @widget: a #GtkWidget
7864 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7865 * when it is allocated to a new size. Otherwise, only the
7866 * new portion of the widget will be redrawn.
7868 * Sets whether the entire widget is queued for drawing when its size
7869 * allocation changes. By default, this setting is %TRUE and
7870 * the entire widget is redrawn on every size change. If your widget
7871 * leaves the upper left unchanged when made bigger, turning this
7872 * setting off will improve performance.
7874 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7875 * off all allocation on resizing: the widget will not even redraw if
7876 * its position changes; this is to allow containers that don't draw
7877 * anything to avoid excess invalidations. If you set this flag on a
7878 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7879 * you are responsible for invalidating both the old and new allocation
7880 * of the widget when the widget is moved and responsible for invalidating
7881 * regions newly when the widget increases size.
7884 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7885 gboolean redraw_on_allocate)
7887 g_return_if_fail (GTK_IS_WIDGET (widget));
7889 widget->priv->redraw_on_alloc = redraw_on_allocate;
7893 * gtk_widget_set_sensitive:
7894 * @widget: a #GtkWidget
7895 * @sensitive: %TRUE to make the widget sensitive
7897 * Sets the sensitivity of a widget. A widget is sensitive if the user
7898 * can interact with it. Insensitive widgets are "grayed out" and the
7899 * user can't interact with them. Insensitive widgets are known as
7900 * "inactive", "disabled", or "ghosted" in some other toolkits.
7903 gtk_widget_set_sensitive (GtkWidget *widget,
7906 GtkWidgetPrivate *priv;
7908 g_return_if_fail (GTK_IS_WIDGET (widget));
7910 priv = widget->priv;
7912 sensitive = (sensitive != FALSE);
7914 if (priv->sensitive == sensitive)
7917 priv->sensitive = sensitive;
7919 if (priv->parent == NULL
7920 || gtk_widget_is_sensitive (priv->parent))
7926 data.flags_to_set = 0;
7927 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
7931 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
7932 data.flags_to_unset = 0;
7935 gtk_widget_propagate_state (widget, &data);
7937 gtk_widget_queue_resize (widget);
7940 g_object_notify (G_OBJECT (widget), "sensitive");
7944 * gtk_widget_get_sensitive:
7945 * @widget: a #GtkWidget
7947 * Returns the widget's sensitivity (in the sense of returning
7948 * the value that has been set using gtk_widget_set_sensitive()).
7950 * The effective sensitivity of a widget is however determined by both its
7951 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7953 * Returns: %TRUE if the widget is sensitive
7958 gtk_widget_get_sensitive (GtkWidget *widget)
7960 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7962 return widget->priv->sensitive;
7966 * gtk_widget_is_sensitive:
7967 * @widget: a #GtkWidget
7969 * Returns the widget's effective sensitivity, which means
7970 * it is sensitive itself and also its parent widget is sensitive
7972 * Returns: %TRUE if the widget is effectively sensitive
7977 gtk_widget_is_sensitive (GtkWidget *widget)
7979 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7981 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7985 * gtk_widget_set_parent:
7986 * @widget: a #GtkWidget
7987 * @parent: parent container
7989 * This function is useful only when implementing subclasses of
7991 * Sets the container as the parent of @widget, and takes care of
7992 * some details such as updating the state and style of the child
7993 * to reflect its new location. The opposite function is
7994 * gtk_widget_unparent().
7997 gtk_widget_set_parent (GtkWidget *widget,
8000 GtkStateFlags parent_flags;
8001 GtkWidgetPrivate *priv;
8004 g_return_if_fail (GTK_IS_WIDGET (widget));
8005 g_return_if_fail (GTK_IS_WIDGET (parent));
8006 g_return_if_fail (widget != parent);
8008 priv = widget->priv;
8010 if (priv->parent != NULL)
8012 g_warning ("Can't set a parent on widget which has a parent\n");
8015 if (gtk_widget_is_toplevel (widget))
8017 g_warning ("Can't set a parent on a toplevel widget\n");
8021 /* keep this function in sync with gtk_menu_attach_to_widget()
8024 g_object_ref_sink (widget);
8026 gtk_widget_push_verify_invariants (widget);
8028 priv->parent = parent;
8030 parent_flags = gtk_widget_get_state_flags (parent);
8032 /* Merge both old state and current parent state,
8033 * making sure to only propagate the right states */
8034 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8035 data.flags_to_unset = 0;
8036 gtk_widget_propagate_state (widget, &data);
8039 gtk_style_context_set_parent (priv->context,
8040 gtk_widget_get_style_context (parent));
8042 _gtk_widget_update_parent_muxer (widget);
8044 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8045 if (priv->parent->priv->anchored)
8046 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8047 g_object_notify (G_OBJECT (widget), "parent");
8049 /* Enforce realized/mapped invariants
8051 if (gtk_widget_get_realized (priv->parent))
8052 gtk_widget_realize (widget);
8054 if (gtk_widget_get_visible (priv->parent) &&
8055 gtk_widget_get_visible (widget))
8057 if (gtk_widget_get_child_visible (widget) &&
8058 gtk_widget_get_mapped (priv->parent))
8059 gtk_widget_map (widget);
8061 gtk_widget_queue_resize (widget);
8064 /* child may cause parent's expand to change, if the child is
8065 * expanded. If child is not expanded, then it can't modify the
8066 * parent's expand. If the child becomes expanded later then it will
8067 * queue compute_expand then. This optimization plus defaulting
8068 * newly-constructed widgets to need_compute_expand=FALSE should
8069 * mean that initially building a widget tree doesn't have to keep
8070 * walking up setting need_compute_expand on parents over and over.
8072 * We can't change a parent to need to expand unless we're visible.
8074 if (gtk_widget_get_visible (widget) &&
8075 (priv->need_compute_expand ||
8076 priv->computed_hexpand ||
8077 priv->computed_vexpand))
8079 gtk_widget_queue_compute_expand (parent);
8082 gtk_widget_pop_verify_invariants (widget);
8086 * gtk_widget_get_parent:
8087 * @widget: a #GtkWidget
8089 * Returns the parent container of @widget.
8091 * Return value: (transfer none): the parent container of @widget, or %NULL
8094 gtk_widget_get_parent (GtkWidget *widget)
8096 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8098 return widget->priv->parent;
8102 modifier_style_changed (GtkModifierStyle *style,
8105 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8108 static GtkModifierStyle *
8109 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8111 GtkModifierStyle *style;
8113 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8115 if (G_UNLIKELY (!style))
8117 GtkStyleContext *context;
8119 style = _gtk_modifier_style_new ();
8120 g_object_set_qdata_full (G_OBJECT (widget),
8121 quark_modifier_style,
8123 (GDestroyNotify) g_object_unref);
8125 g_signal_connect (style, "changed",
8126 G_CALLBACK (modifier_style_changed), widget);
8128 context = gtk_widget_get_style_context (widget);
8130 gtk_style_context_add_provider (context,
8131 GTK_STYLE_PROVIDER (style),
8132 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8139 * gtk_widget_override_color:
8140 * @widget: a #GtkWidget
8141 * @state: the state for which to set the color
8142 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8143 * of previous calls to gtk_widget_override_color()
8145 * Sets the color to use for a widget.
8147 * All other style values are left untouched.
8150 * This API is mostly meant as a quick way for applications to
8151 * change a widget appearance. If you are developing a widgets
8152 * library and intend this change to be themeable, it is better
8153 * done by setting meaningful CSS classes and regions in your
8154 * widget/container implementation through gtk_style_context_add_class()
8155 * and gtk_style_context_add_region().
8157 * This way, your widget library can install a #GtkCssProvider
8158 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8159 * to provide a default styling for those widgets that need so, and
8160 * this theming may fully overridden by the user's theme.
8163 * Note that for complex widgets this may bring in undesired
8164 * results (such as uniform background color everywhere), in
8165 * these cases it is better to fully style such widgets through a
8166 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8173 gtk_widget_override_color (GtkWidget *widget,
8174 GtkStateFlags state,
8175 const GdkRGBA *color)
8177 GtkModifierStyle *style;
8179 g_return_if_fail (GTK_IS_WIDGET (widget));
8181 style = _gtk_widget_get_modifier_properties (widget);
8182 _gtk_modifier_style_set_color (style, state, color);
8186 * gtk_widget_override_background_color:
8187 * @widget: a #GtkWidget
8188 * @state: the state for which to set the background color
8189 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8190 * of previous calls to gtk_widget_override_background_color()
8192 * Sets the background color to use for a widget.
8194 * All other style values are left untouched.
8195 * See gtk_widget_override_color().
8200 gtk_widget_override_background_color (GtkWidget *widget,
8201 GtkStateFlags state,
8202 const GdkRGBA *color)
8204 GtkModifierStyle *style;
8206 g_return_if_fail (GTK_IS_WIDGET (widget));
8208 style = _gtk_widget_get_modifier_properties (widget);
8209 _gtk_modifier_style_set_background_color (style, state, color);
8213 * gtk_widget_override_font:
8214 * @widget: a #GtkWidget
8215 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8216 * the effect of previous calls to gtk_widget_override_font()
8218 * Sets the font to use for a widget. All other style values are
8219 * left untouched. See gtk_widget_override_color().
8224 gtk_widget_override_font (GtkWidget *widget,
8225 const PangoFontDescription *font_desc)
8227 GtkModifierStyle *style;
8229 g_return_if_fail (GTK_IS_WIDGET (widget));
8231 style = _gtk_widget_get_modifier_properties (widget);
8232 _gtk_modifier_style_set_font (style, font_desc);
8236 * gtk_widget_override_symbolic_color:
8237 * @widget: a #GtkWidget
8238 * @name: the name of the symbolic color to modify
8239 * @color: (allow-none): the color to assign (does not need
8240 * to be allocated), or %NULL to undo the effect of previous
8241 * calls to gtk_widget_override_symbolic_color()
8243 * Sets a symbolic color for a widget.
8245 * All other style values are left untouched.
8246 * See gtk_widget_override_color() for overriding the foreground
8247 * or background color.
8252 gtk_widget_override_symbolic_color (GtkWidget *widget,
8254 const GdkRGBA *color)
8256 GtkModifierStyle *style;
8258 g_return_if_fail (GTK_IS_WIDGET (widget));
8260 style = _gtk_widget_get_modifier_properties (widget);
8261 _gtk_modifier_style_map_color (style, name, color);
8265 * gtk_widget_override_cursor:
8266 * @widget: a #GtkWidget
8267 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8268 * allocated), or %NULL to undo the effect of previous calls to
8269 * of gtk_widget_override_cursor().
8270 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8271 * need to be allocated), or %NULL to undo the effect of previous
8272 * calls to of gtk_widget_override_cursor().
8274 * Sets the cursor color to use in a widget, overriding the
8275 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8276 * style properties. All other style values are left untouched.
8277 * See also gtk_widget_modify_style().
8279 * Note that the underlying properties have the #GdkColor type,
8280 * so the alpha value in @primary and @secondary will be ignored.
8285 gtk_widget_override_cursor (GtkWidget *widget,
8286 const GdkRGBA *cursor,
8287 const GdkRGBA *secondary_cursor)
8289 GtkModifierStyle *style;
8291 g_return_if_fail (GTK_IS_WIDGET (widget));
8293 style = _gtk_widget_get_modifier_properties (widget);
8294 _gtk_modifier_style_set_color_property (style,
8296 "cursor-color", cursor);
8297 _gtk_modifier_style_set_color_property (style,
8299 "secondary-cursor-color",
8304 gtk_widget_real_direction_changed (GtkWidget *widget,
8305 GtkTextDirection previous_direction)
8307 gtk_widget_queue_resize (widget);
8311 gtk_widget_real_style_set (GtkWidget *widget,
8312 GtkStyle *previous_style)
8317 GtkWidget *previous_toplevel;
8318 GdkScreen *previous_screen;
8319 GdkScreen *new_screen;
8320 } HierarchyChangedInfo;
8323 do_screen_change (GtkWidget *widget,
8324 GdkScreen *old_screen,
8325 GdkScreen *new_screen)
8327 if (old_screen != new_screen)
8329 GtkWidgetPrivate *priv = widget->priv;
8333 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8335 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8338 _gtk_tooltip_hide (widget);
8340 if (new_screen && priv->context)
8341 gtk_style_context_set_screen (priv->context, new_screen);
8343 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8348 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8349 gpointer client_data)
8351 GtkWidgetPrivate *priv = widget->priv;
8352 HierarchyChangedInfo *info = client_data;
8353 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8354 (priv->parent && priv->parent->priv->anchored);
8356 if (priv->anchored != new_anchored)
8358 g_object_ref (widget);
8360 priv->anchored = new_anchored;
8362 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8363 do_screen_change (widget, info->previous_screen, info->new_screen);
8365 if (GTK_IS_CONTAINER (widget))
8366 gtk_container_forall (GTK_CONTAINER (widget),
8367 gtk_widget_propagate_hierarchy_changed_recurse,
8370 g_object_unref (widget);
8375 * _gtk_widget_propagate_hierarchy_changed:
8376 * @widget: a #GtkWidget
8377 * @previous_toplevel: Previous toplevel
8379 * Propagates changes in the anchored state to a widget and all
8380 * children, unsetting or setting the %ANCHORED flag, and
8381 * emitting #GtkWidget::hierarchy-changed.
8384 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8385 GtkWidget *previous_toplevel)
8387 GtkWidgetPrivate *priv = widget->priv;
8388 HierarchyChangedInfo info;
8390 info.previous_toplevel = previous_toplevel;
8391 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8393 if (gtk_widget_is_toplevel (widget) ||
8394 (priv->parent && priv->parent->priv->anchored))
8395 info.new_screen = gtk_widget_get_screen (widget);
8397 info.new_screen = NULL;
8399 if (info.previous_screen)
8400 g_object_ref (info.previous_screen);
8401 if (previous_toplevel)
8402 g_object_ref (previous_toplevel);
8404 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8406 if (previous_toplevel)
8407 g_object_unref (previous_toplevel);
8408 if (info.previous_screen)
8409 g_object_unref (info.previous_screen);
8413 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8414 gpointer client_data)
8416 HierarchyChangedInfo *info = client_data;
8418 g_object_ref (widget);
8420 do_screen_change (widget, info->previous_screen, info->new_screen);
8422 if (GTK_IS_CONTAINER (widget))
8423 gtk_container_forall (GTK_CONTAINER (widget),
8424 gtk_widget_propagate_screen_changed_recurse,
8427 g_object_unref (widget);
8431 * gtk_widget_is_composited:
8432 * @widget: a #GtkWidget
8434 * Whether @widget can rely on having its alpha channel
8435 * drawn correctly. On X11 this function returns whether a
8436 * compositing manager is running for @widget's screen.
8438 * Please note that the semantics of this call will change
8439 * in the future if used on a widget that has a composited
8440 * window in its hierarchy (as set by gdk_window_set_composited()).
8442 * Return value: %TRUE if the widget can rely on its alpha
8443 * channel being drawn correctly.
8448 gtk_widget_is_composited (GtkWidget *widget)
8452 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8454 screen = gtk_widget_get_screen (widget);
8456 return gdk_screen_is_composited (screen);
8460 propagate_composited_changed (GtkWidget *widget,
8463 if (GTK_IS_CONTAINER (widget))
8465 gtk_container_forall (GTK_CONTAINER (widget),
8466 propagate_composited_changed,
8470 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8474 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8476 propagate_composited_changed (widget, NULL);
8480 * _gtk_widget_propagate_screen_changed:
8481 * @widget: a #GtkWidget
8482 * @previous_screen: Previous screen
8484 * Propagates changes in the screen for a widget to all
8485 * children, emitting #GtkWidget::screen-changed.
8488 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8489 GdkScreen *previous_screen)
8491 HierarchyChangedInfo info;
8493 info.previous_screen = previous_screen;
8494 info.new_screen = gtk_widget_get_screen (widget);
8496 if (previous_screen)
8497 g_object_ref (previous_screen);
8499 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8501 if (previous_screen)
8502 g_object_unref (previous_screen);
8506 reset_style_recurse (GtkWidget *widget, gpointer data)
8508 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8510 if (GTK_IS_CONTAINER (widget))
8511 gtk_container_forall (GTK_CONTAINER (widget),
8512 reset_style_recurse,
8517 * gtk_widget_reset_style:
8518 * @widget: a #GtkWidget
8520 * Updates the style context of @widget and all descendents
8521 * by updating its widget path. #GtkContainer<!-- -->s may want
8522 * to use this on a child when reordering it in a way that a different
8523 * style might apply to it. See also gtk_container_get_path_for_child().
8528 gtk_widget_reset_style (GtkWidget *widget)
8530 g_return_if_fail (GTK_IS_WIDGET (widget));
8532 reset_style_recurse (widget, NULL);
8534 g_list_foreach (widget->priv->attached_windows,
8535 (GFunc) reset_style_recurse, NULL);
8538 #ifdef G_ENABLE_DEBUG
8540 /* Verify invariants, see docs/widget_system.txt for notes on much of
8541 * this. Invariants may be temporarily broken while we're in the
8542 * process of updating state, of course, so you can only
8543 * verify_invariants() after a given operation is complete.
8544 * Use push/pop_verify_invariants to help with that.
8547 gtk_widget_verify_invariants (GtkWidget *widget)
8551 if (widget->priv->verifying_invariants_count > 0)
8554 parent = widget->priv->parent;
8556 if (widget->priv->mapped)
8558 /* Mapped implies ... */
8560 if (!widget->priv->realized)
8561 g_warning ("%s %p is mapped but not realized",
8562 G_OBJECT_TYPE_NAME (widget), widget);
8564 if (!widget->priv->visible)
8565 g_warning ("%s %p is mapped but not visible",
8566 G_OBJECT_TYPE_NAME (widget), widget);
8568 if (!widget->priv->toplevel)
8570 if (!widget->priv->child_visible)
8571 g_warning ("%s %p is mapped but not child_visible",
8572 G_OBJECT_TYPE_NAME (widget), widget);
8577 /* Not mapped implies... */
8580 /* This check makes sense for normal toplevels, but for
8581 * something like a toplevel that is embedded within a clutter
8582 * state, mapping may depend on external factors.
8584 if (widget->priv->toplevel)
8586 if (widget->priv->visible)
8587 g_warning ("%s %p toplevel is visible but not mapped",
8588 G_OBJECT_TYPE_NAME (widget), widget);
8593 /* Parent related checks aren't possible if parent has
8594 * verifying_invariants_count > 0 because parent needs to recurse
8595 * children first before the invariants will hold.
8597 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8600 parent->priv->realized)
8602 /* Parent realized implies... */
8605 /* This is in widget_system.txt but appears to fail
8606 * because there's no gtk_container_realize() that
8607 * realizes all children... instead we just lazily
8608 * wait for map to fix things up.
8610 if (!widget->priv->realized)
8611 g_warning ("%s %p is realized but child %s %p is not realized",
8612 G_OBJECT_TYPE_NAME (parent), parent,
8613 G_OBJECT_TYPE_NAME (widget), widget);
8616 else if (!widget->priv->toplevel)
8618 /* No parent or parent not realized on non-toplevel implies... */
8620 if (widget->priv->realized && !widget->priv->in_reparent)
8621 g_warning ("%s %p is not realized but child %s %p is realized",
8622 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8623 G_OBJECT_TYPE_NAME (widget), widget);
8627 parent->priv->mapped &&
8628 widget->priv->visible &&
8629 widget->priv->child_visible)
8631 /* Parent mapped and we are visible implies... */
8633 if (!widget->priv->mapped)
8634 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8635 G_OBJECT_TYPE_NAME (parent), parent,
8636 G_OBJECT_TYPE_NAME (widget), widget);
8638 else if (!widget->priv->toplevel)
8640 /* No parent or parent not mapped on non-toplevel implies... */
8642 if (widget->priv->mapped && !widget->priv->in_reparent)
8643 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8644 G_OBJECT_TYPE_NAME (widget), widget,
8645 widget->priv->visible,
8646 widget->priv->child_visible,
8647 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8648 parent ? parent->priv->mapped : FALSE);
8652 if (!widget->priv->realized)
8654 /* Not realized implies... */
8657 /* widget_system.txt says these hold, but they don't. */
8658 if (widget->priv->alloc_needed)
8659 g_warning ("%s %p alloc needed but not realized",
8660 G_OBJECT_TYPE_NAME (widget), widget);
8662 if (widget->priv->width_request_needed)
8663 g_warning ("%s %p width request needed but not realized",
8664 G_OBJECT_TYPE_NAME (widget), widget);
8666 if (widget->priv->height_request_needed)
8667 g_warning ("%s %p height request needed but not realized",
8668 G_OBJECT_TYPE_NAME (widget), widget);
8673 /* The point of this push/pop is that invariants may not hold while
8674 * we're busy making changes. So we only check at the outermost call
8675 * on the call stack, after we finish updating everything.
8678 gtk_widget_push_verify_invariants (GtkWidget *widget)
8680 widget->priv->verifying_invariants_count += 1;
8684 gtk_widget_verify_child_invariants (GtkWidget *widget,
8685 gpointer client_data)
8687 /* We don't recurse further; this is a one-level check. */
8688 gtk_widget_verify_invariants (widget);
8692 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8694 g_assert (widget->priv->verifying_invariants_count > 0);
8696 widget->priv->verifying_invariants_count -= 1;
8698 if (widget->priv->verifying_invariants_count == 0)
8700 gtk_widget_verify_invariants (widget);
8702 if (GTK_IS_CONTAINER (widget))
8704 /* Check one level of children, because our
8705 * push_verify_invariants() will have prevented some of the
8706 * checks. This does not recurse because if recursion is
8707 * needed, it will happen naturally as each child has a
8708 * push/pop on that child. For example if we're recursively
8709 * mapping children, we'll push/pop on each child as we map
8712 gtk_container_forall (GTK_CONTAINER (widget),
8713 gtk_widget_verify_child_invariants,
8718 #endif /* G_ENABLE_DEBUG */
8720 static PangoContext *
8721 gtk_widget_peek_pango_context (GtkWidget *widget)
8723 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8727 * gtk_widget_get_pango_context:
8728 * @widget: a #GtkWidget
8730 * Gets a #PangoContext with the appropriate font map, font description,
8731 * and base direction for this widget. Unlike the context returned
8732 * by gtk_widget_create_pango_context(), this context is owned by
8733 * the widget (it can be used until the screen for the widget changes
8734 * or the widget is removed from its toplevel), and will be updated to
8735 * match any changes to the widget's attributes. This can be tracked
8736 * by using the #GtkWidget::screen-changed signal on the widget.
8738 * Return value: (transfer none): the #PangoContext for the widget.
8741 gtk_widget_get_pango_context (GtkWidget *widget)
8743 PangoContext *context;
8745 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8747 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8750 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8751 g_object_set_qdata_full (G_OBJECT (widget),
8752 quark_pango_context,
8761 update_pango_context (GtkWidget *widget,
8762 PangoContext *context)
8764 PangoFontDescription *font_desc;
8765 GtkStyleContext *style_context;
8767 style_context = gtk_widget_get_style_context (widget);
8768 gtk_style_context_get (style_context,
8769 gtk_widget_get_state_flags (widget),
8773 pango_context_set_font_description (context, font_desc);
8774 pango_context_set_base_dir (context,
8775 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8776 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8778 pango_font_description_free (font_desc);
8782 gtk_widget_update_pango_context (GtkWidget *widget)
8784 PangoContext *context = gtk_widget_peek_pango_context (widget);
8790 update_pango_context (widget, context);
8792 screen = gtk_widget_get_screen_unchecked (widget);
8795 pango_cairo_context_set_resolution (context,
8796 gdk_screen_get_resolution (screen));
8797 pango_cairo_context_set_font_options (context,
8798 gdk_screen_get_font_options (screen));
8804 * gtk_widget_create_pango_context:
8805 * @widget: a #GtkWidget
8807 * Creates a new #PangoContext with the appropriate font map,
8808 * font description, and base direction for drawing text for
8809 * this widget. See also gtk_widget_get_pango_context().
8811 * Return value: (transfer full): the new #PangoContext
8814 gtk_widget_create_pango_context (GtkWidget *widget)
8817 PangoContext *context;
8819 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8821 screen = gtk_widget_get_screen_unchecked (widget);
8824 GTK_NOTE (MULTIHEAD,
8825 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8827 screen = gdk_screen_get_default ();
8830 context = gdk_pango_context_get_for_screen (screen);
8832 update_pango_context (widget, context);
8833 pango_context_set_language (context, gtk_get_default_language ());
8839 * gtk_widget_create_pango_layout:
8840 * @widget: a #GtkWidget
8841 * @text: text to set on the layout (can be %NULL)
8843 * Creates a new #PangoLayout with the appropriate font map,
8844 * font description, and base direction for drawing text for
8847 * If you keep a #PangoLayout created in this way around, you need
8848 * to re-create it when the widget #PangoContext is replaced.
8849 * This can be tracked by using the #GtkWidget::screen-changed signal
8852 * Return value: (transfer full): the new #PangoLayout
8855 gtk_widget_create_pango_layout (GtkWidget *widget,
8858 PangoLayout *layout;
8859 PangoContext *context;
8861 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8863 context = gtk_widget_get_pango_context (widget);
8864 layout = pango_layout_new (context);
8867 pango_layout_set_text (layout, text, -1);
8873 * gtk_widget_render_icon_pixbuf:
8874 * @widget: a #GtkWidget
8875 * @stock_id: a stock ID
8876 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8877 * render at the size of the source and don't scale (if there are
8878 * multiple source sizes, GTK+ picks one of the available sizes).
8880 * A convenience function that uses the theme engine and style
8881 * settings for @widget to look up @stock_id and render it to
8882 * a pixbuf. @stock_id should be a stock icon ID such as
8883 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8884 * such as #GTK_ICON_SIZE_MENU.
8886 * The pixels in the returned #GdkPixbuf are shared with the rest of
8887 * the application and should not be modified. The pixbuf should be freed
8888 * after use with g_object_unref().
8890 * Return value: (transfer full): a new pixbuf, or %NULL if the
8891 * stock ID wasn't known
8896 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8897 const gchar *stock_id,
8900 GtkStyleContext *context;
8901 GtkIconSet *icon_set;
8903 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8904 g_return_val_if_fail (stock_id != NULL, NULL);
8905 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8907 context = gtk_widget_get_style_context (widget);
8908 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8910 if (icon_set == NULL)
8913 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8917 * gtk_widget_set_parent_window:
8918 * @widget: a #GtkWidget.
8919 * @parent_window: the new parent window.
8921 * Sets a non default parent window for @widget.
8923 * For GtkWindow classes, setting a @parent_window effects whether
8924 * the window is a toplevel window or can be embedded into other
8928 * For GtkWindow classes, this needs to be called before the
8929 * window is realized.
8934 gtk_widget_set_parent_window (GtkWidget *widget,
8935 GdkWindow *parent_window)
8937 GdkWindow *old_parent_window;
8939 g_return_if_fail (GTK_IS_WIDGET (widget));
8941 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8942 quark_parent_window);
8944 if (parent_window != old_parent_window)
8948 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8950 if (old_parent_window)
8951 g_object_unref (old_parent_window);
8953 g_object_ref (parent_window);
8955 /* Unset toplevel flag when adding a parent window to a widget,
8956 * this is the primary entry point to allow toplevels to be
8959 #ifdef GDK_WINDOWING_X11
8960 is_plug = GTK_IS_PLUG (widget);
8964 if (GTK_IS_WINDOW (widget) && !is_plug)
8965 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8970 * gtk_widget_get_parent_window:
8971 * @widget: a #GtkWidget.
8973 * Gets @widget's parent window.
8975 * Returns: (transfer none): the parent window of @widget.
8978 gtk_widget_get_parent_window (GtkWidget *widget)
8980 GtkWidgetPrivate *priv;
8981 GdkWindow *parent_window;
8983 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8985 priv = widget->priv;
8987 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8989 return (parent_window != NULL) ? parent_window :
8990 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8995 * gtk_widget_set_child_visible:
8996 * @widget: a #GtkWidget
8997 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8999 * Sets whether @widget should be mapped along with its when its parent
9000 * is mapped and @widget has been shown with gtk_widget_show().
9002 * The child visibility can be set for widget before it is added to
9003 * a container with gtk_widget_set_parent(), to avoid mapping
9004 * children unnecessary before immediately unmapping them. However
9005 * it will be reset to its default state of %TRUE when the widget
9006 * is removed from a container.
9008 * Note that changing the child visibility of a widget does not
9009 * queue a resize on the widget. Most of the time, the size of
9010 * a widget is computed from all visible children, whether or
9011 * not they are mapped. If this is not the case, the container
9012 * can queue a resize itself.
9014 * This function is only useful for container implementations and
9015 * never should be called by an application.
9018 gtk_widget_set_child_visible (GtkWidget *widget,
9019 gboolean is_visible)
9021 GtkWidgetPrivate *priv;
9023 g_return_if_fail (GTK_IS_WIDGET (widget));
9024 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9026 priv = widget->priv;
9028 g_object_ref (widget);
9029 gtk_widget_verify_invariants (widget);
9032 priv->child_visible = TRUE;
9035 GtkWidget *toplevel;
9037 priv->child_visible = FALSE;
9039 toplevel = gtk_widget_get_toplevel (widget);
9040 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9041 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9044 if (priv->parent && gtk_widget_get_realized (priv->parent))
9046 if (gtk_widget_get_mapped (priv->parent) &&
9047 priv->child_visible &&
9048 gtk_widget_get_visible (widget))
9049 gtk_widget_map (widget);
9051 gtk_widget_unmap (widget);
9054 gtk_widget_verify_invariants (widget);
9055 g_object_unref (widget);
9059 * gtk_widget_get_child_visible:
9060 * @widget: a #GtkWidget
9062 * Gets the value set with gtk_widget_set_child_visible().
9063 * If you feel a need to use this function, your code probably
9064 * needs reorganization.
9066 * This function is only useful for container implementations and
9067 * never should be called by an application.
9069 * Return value: %TRUE if the widget is mapped with the parent.
9072 gtk_widget_get_child_visible (GtkWidget *widget)
9074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9076 return widget->priv->child_visible;
9080 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9082 GtkWidget *toplevel;
9084 toplevel = gtk_widget_get_toplevel (widget);
9086 if (gtk_widget_is_toplevel (toplevel))
9088 if (GTK_IS_WINDOW (toplevel))
9089 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9090 else if (GTK_IS_INVISIBLE (toplevel))
9091 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9098 * gtk_widget_get_screen:
9099 * @widget: a #GtkWidget
9101 * Get the #GdkScreen from the toplevel window associated with
9102 * this widget. This function can only be called after the widget
9103 * has been added to a widget hierarchy with a #GtkWindow
9106 * In general, you should only create screen specific
9107 * resources when a widget has been realized, and you should
9108 * free those resources when the widget is unrealized.
9110 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9115 gtk_widget_get_screen (GtkWidget *widget)
9119 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9121 screen = gtk_widget_get_screen_unchecked (widget);
9128 g_warning (G_STRLOC ": Can't get associated screen"
9129 " for a widget unless it is inside a toplevel GtkWindow\n"
9130 " widget type is %s associated top level type is %s",
9131 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9132 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9134 return gdk_screen_get_default ();
9139 * gtk_widget_has_screen:
9140 * @widget: a #GtkWidget
9142 * Checks whether there is a #GdkScreen is associated with
9143 * this widget. All toplevel widgets have an associated
9144 * screen, and all widgets added into a hierarchy with a toplevel
9145 * window at the top.
9147 * Return value: %TRUE if there is a #GdkScreen associcated
9153 gtk_widget_has_screen (GtkWidget *widget)
9155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9157 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9161 * gtk_widget_get_display:
9162 * @widget: a #GtkWidget
9164 * Get the #GdkDisplay for the toplevel window associated with
9165 * this widget. This function can only be called after the widget
9166 * has been added to a widget hierarchy with a #GtkWindow at the top.
9168 * In general, you should only create display specific
9169 * resources when a widget has been realized, and you should
9170 * free those resources when the widget is unrealized.
9172 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9177 gtk_widget_get_display (GtkWidget *widget)
9179 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9181 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9185 * gtk_widget_get_root_window:
9186 * @widget: a #GtkWidget
9188 * Get the root window where this widget is located. This function can
9189 * only be called after the widget has been added to a widget
9190 * hierarchy with #GtkWindow at the top.
9192 * The root window is useful for such purposes as creating a popup
9193 * #GdkWindow associated with the window. In general, you should only
9194 * create display specific resources when a widget has been realized,
9195 * and you should free those resources when the widget is unrealized.
9197 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9202 gtk_widget_get_root_window (GtkWidget *widget)
9204 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9206 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9210 * gtk_widget_child_focus:
9211 * @widget: a #GtkWidget
9212 * @direction: direction of focus movement
9214 * This function is used by custom widget implementations; if you're
9215 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9216 * to a particular widget, and gtk_container_set_focus_chain() to
9217 * change the focus tab order. So you may want to investigate those
9218 * functions instead.
9220 * gtk_widget_child_focus() is called by containers as the user moves
9221 * around the window using keyboard shortcuts. @direction indicates
9222 * what kind of motion is taking place (up, down, left, right, tab
9223 * forward, tab backward). gtk_widget_child_focus() emits the
9224 * #GtkWidget::focus signal; widgets override the default handler
9225 * for this signal in order to implement appropriate focus behavior.
9227 * The default ::focus handler for a widget should return %TRUE if
9228 * moving in @direction left the focus on a focusable location inside
9229 * that widget, and %FALSE if moving in @direction moved the focus
9230 * outside the widget. If returning %TRUE, widgets normally
9231 * call gtk_widget_grab_focus() to place the focus accordingly;
9232 * if returning %FALSE, they don't modify the current focus location.
9234 * Return value: %TRUE if focus ended up inside @widget
9237 gtk_widget_child_focus (GtkWidget *widget,
9238 GtkDirectionType direction)
9240 gboolean return_val;
9242 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9244 if (!gtk_widget_get_visible (widget) ||
9245 !gtk_widget_is_sensitive (widget))
9248 /* child widgets must set CAN_FOCUS, containers
9249 * don't have to though.
9251 if (!GTK_IS_CONTAINER (widget) &&
9252 !gtk_widget_get_can_focus (widget))
9255 g_signal_emit (widget,
9256 widget_signals[FOCUS],
9258 direction, &return_val);
9264 * gtk_widget_keynav_failed:
9265 * @widget: a #GtkWidget
9266 * @direction: direction of focus movement
9268 * This function should be called whenever keyboard navigation within
9269 * a single widget hits a boundary. The function emits the
9270 * #GtkWidget::keynav-failed signal on the widget and its return
9271 * value should be interpreted in a way similar to the return value of
9272 * gtk_widget_child_focus():
9274 * When %TRUE is returned, stay in the widget, the failed keyboard
9275 * navigation is Ok and/or there is nowhere we can/should move the
9278 * When %FALSE is returned, the caller should continue with keyboard
9279 * navigation outside the widget, e.g. by calling
9280 * gtk_widget_child_focus() on the widget's toplevel.
9282 * The default ::keynav-failed handler returns %TRUE for
9283 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9284 * values of #GtkDirectionType, it looks at the
9285 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9286 * if the setting is %TRUE. This way the entire user interface
9287 * becomes cursor-navigatable on input devices such as mobile phones
9288 * which only have cursor keys but no tab key.
9290 * Whenever the default handler returns %TRUE, it also calls
9291 * gtk_widget_error_bell() to notify the user of the failed keyboard
9294 * A use case for providing an own implementation of ::keynav-failed
9295 * (either by connecting to it or by overriding it) would be a row of
9296 * #GtkEntry widgets where the user should be able to navigate the
9297 * entire row with the cursor keys, as e.g. known from user interfaces
9298 * that require entering license keys.
9300 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9301 * if the emitting widget should try to handle the keyboard
9302 * navigation attempt in its parent container(s).
9307 gtk_widget_keynav_failed (GtkWidget *widget,
9308 GtkDirectionType direction)
9310 gboolean return_val;
9312 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9314 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9315 direction, &return_val);
9321 * gtk_widget_error_bell:
9322 * @widget: a #GtkWidget
9324 * Notifies the user about an input-related error on this widget.
9325 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9326 * gdk_window_beep(), otherwise it does nothing.
9328 * Note that the effect of gdk_window_beep() can be configured in many
9329 * ways, depending on the windowing backend and the desktop environment
9330 * or window manager that is used.
9335 gtk_widget_error_bell (GtkWidget *widget)
9337 GtkWidgetPrivate *priv;
9338 GtkSettings* settings;
9341 g_return_if_fail (GTK_IS_WIDGET (widget));
9343 priv = widget->priv;
9345 settings = gtk_widget_get_settings (widget);
9349 g_object_get (settings,
9350 "gtk-error-bell", &beep,
9353 if (beep && priv->window)
9354 gdk_window_beep (priv->window);
9358 gtk_widget_set_usize_internal (GtkWidget *widget,
9361 GtkQueueResizeFlags flags)
9363 GtkWidgetAuxInfo *aux_info;
9364 gboolean changed = FALSE;
9366 g_object_freeze_notify (G_OBJECT (widget));
9368 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9370 if (width > -2 && aux_info->width != width)
9372 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9373 g_object_notify (G_OBJECT (widget), "width-request");
9374 aux_info->width = width;
9377 if (height > -2 && aux_info->height != height)
9379 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9380 g_object_notify (G_OBJECT (widget), "height-request");
9381 aux_info->height = height;
9385 if (gtk_widget_get_visible (widget) && changed)
9387 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9388 gtk_widget_queue_resize (widget);
9390 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9393 g_object_thaw_notify (G_OBJECT (widget));
9397 * gtk_widget_set_size_request:
9398 * @widget: a #GtkWidget
9399 * @width: width @widget should request, or -1 to unset
9400 * @height: height @widget should request, or -1 to unset
9402 * Sets the minimum size of a widget; that is, the widget's size
9403 * request will be at least @width by @height. You can use this
9404 * function to force a widget to be larger than it normally would be.
9406 * In most cases, gtk_window_set_default_size() is a better choice for
9407 * toplevel windows than this function; setting the default size will
9408 * still allow users to shrink the window. Setting the size request
9409 * will force them to leave the window at least as large as the size
9410 * request. When dealing with window sizes,
9411 * gtk_window_set_geometry_hints() can be a useful function as well.
9413 * Note the inherent danger of setting any fixed size - themes,
9414 * translations into other languages, different fonts, and user action
9415 * can all change the appropriate size for a given widget. So, it's
9416 * basically impossible to hardcode a size that will always be
9419 * The size request of a widget is the smallest size a widget can
9420 * accept while still functioning well and drawing itself correctly.
9421 * However in some strange cases a widget may be allocated less than
9422 * its requested size, and in many cases a widget may be allocated more
9423 * space than it requested.
9425 * If the size request in a given direction is -1 (unset), then
9426 * the "natural" size request of the widget will be used instead.
9428 * The size request set here does not include any margin from the
9429 * #GtkWidget properties margin-left, margin-right, margin-top, and
9430 * margin-bottom, but it does include pretty much all other padding
9431 * or border properties set by any subclass of #GtkWidget.
9434 gtk_widget_set_size_request (GtkWidget *widget,
9438 g_return_if_fail (GTK_IS_WIDGET (widget));
9439 g_return_if_fail (width >= -1);
9440 g_return_if_fail (height >= -1);
9447 gtk_widget_set_usize_internal (widget, width, height, 0);
9452 * gtk_widget_get_size_request:
9453 * @widget: a #GtkWidget
9454 * @width: (out) (allow-none): return location for width, or %NULL
9455 * @height: (out) (allow-none): return location for height, or %NULL
9457 * Gets the size request that was explicitly set for the widget using
9458 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9459 * @height indicates that that dimension has not been set explicitly
9460 * and the natural requisition of the widget will be used intead. See
9461 * gtk_widget_set_size_request(). To get the size a widget will
9462 * actually request, call gtk_widget_get_preferred_size() instead of
9466 gtk_widget_get_size_request (GtkWidget *widget,
9470 const GtkWidgetAuxInfo *aux_info;
9472 g_return_if_fail (GTK_IS_WIDGET (widget));
9474 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9477 *width = aux_info->width;
9480 *height = aux_info->height;
9484 * _gtk_widget_override_size_request:
9485 * @widget: a #GtkWidget
9486 * @width: new forced minimum width
9487 * @height: new forced minimum height
9488 * @old_width: location to store previous forced minimum width
9489 * @old_height: location to store previous forced minumum height
9491 * Temporarily establishes a forced minimum size for a widget; this
9492 * is used by GtkWindow when calculating the size to add to the
9493 * window's geometry widget. Cached sizes for the widget and its
9494 * parents are invalidated, so that subsequent calls to the size
9495 * negotiation machinery produce the overriden result, but the
9496 * widget is not queued for relayout or redraw. The old size must
9497 * be restored with _gtk_widget_restore_size_request() or things
9501 _gtk_widget_override_size_request (GtkWidget *widget,
9507 gtk_widget_get_size_request (widget, old_width, old_height);
9508 gtk_widget_set_usize_internal (widget, width, height,
9509 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9513 * _gtk_widget_restore_size_request:
9514 * @widget: a #GtkWidget
9515 * @old_width: saved forced minimum size
9516 * @old_height: saved forced minimum size
9518 * Undoes the operation of_gtk_widget_override_size_request().
9521 _gtk_widget_restore_size_request (GtkWidget *widget,
9525 gtk_widget_set_usize_internal (widget, old_width, old_height,
9526 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9530 * gtk_widget_set_events:
9531 * @widget: a #GtkWidget
9532 * @events: event mask
9534 * Sets the event mask (see #GdkEventMask) for a widget. The event
9535 * mask determines which events a widget will receive. Keep in mind
9536 * that different widgets have different default event masks, and by
9537 * changing the event mask you may disrupt a widget's functionality,
9538 * so be careful. This function must be called while a widget is
9539 * unrealized. Consider gtk_widget_add_events() for widgets that are
9540 * already realized, or if you want to preserve the existing event
9541 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9542 * to get events on those widgets, place them inside a #GtkEventBox
9543 * and receive events on the event box.
9546 gtk_widget_set_events (GtkWidget *widget,
9549 g_return_if_fail (GTK_IS_WIDGET (widget));
9550 g_return_if_fail (!gtk_widget_get_realized (widget));
9552 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9553 GINT_TO_POINTER (events));
9554 g_object_notify (G_OBJECT (widget), "events");
9558 * gtk_widget_set_device_events:
9559 * @widget: a #GtkWidget
9560 * @device: a #GdkDevice
9561 * @events: event mask
9563 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9564 * mask determines which events a widget will receive from @device. Keep
9565 * in mind that different widgets have different default event masks, and by
9566 * changing the event mask you may disrupt a widget's functionality,
9567 * so be careful. This function must be called while a widget is
9568 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9569 * already realized, or if you want to preserve the existing event
9570 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9571 * to get events on those widgets, place them inside a #GtkEventBox
9572 * and receive events on the event box.
9577 gtk_widget_set_device_events (GtkWidget *widget,
9579 GdkEventMask events)
9581 GHashTable *device_events;
9583 g_return_if_fail (GTK_IS_WIDGET (widget));
9584 g_return_if_fail (GDK_IS_DEVICE (device));
9585 g_return_if_fail (!gtk_widget_get_realized (widget));
9587 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9589 if (G_UNLIKELY (!device_events))
9591 device_events = g_hash_table_new (NULL, NULL);
9592 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9593 (GDestroyNotify) g_hash_table_unref);
9596 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9600 * gtk_widget_set_device_enabled:
9601 * @widget: a #GtkWidget
9602 * @device: a #GdkDevice
9603 * @enabled: whether to enable the device
9605 * Enables or disables a #GdkDevice to interact with @widget
9606 * and all its children.
9608 * It does so by descending through the #GdkWindow hierarchy
9609 * and enabling the same mask that is has for core events
9610 * (i.e. the one that gdk_window_get_events() returns).
9615 gtk_widget_set_device_enabled (GtkWidget *widget,
9619 GList *enabled_devices;
9621 g_return_if_fail (GTK_IS_WIDGET (widget));
9622 g_return_if_fail (GDK_IS_DEVICE (device));
9624 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9625 enabled_devices = g_list_append (enabled_devices, device);
9627 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9628 enabled_devices, (GDestroyNotify) g_list_free);;
9630 if (gtk_widget_get_realized (widget))
9631 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9635 * gtk_widget_get_device_enabled:
9636 * @widget: a #GtkWidget
9637 * @device: a #GdkDevice
9639 * Returns whether @device can interact with @widget and its
9640 * children. See gtk_widget_set_device_enabled().
9642 * Return value: %TRUE is @device is enabled for @widget
9647 gtk_widget_get_device_enabled (GtkWidget *widget,
9650 GList *enabled_devices;
9652 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9653 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9655 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9657 return g_list_find (enabled_devices, device) != NULL;
9661 gtk_widget_add_events_internal_list (GtkWidget *widget,
9668 for (l = window_list; l != NULL; l = l->next)
9670 GdkWindow *window = l->data;
9673 gdk_window_get_user_data (window, &user_data);
9674 if (user_data == widget)
9679 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9681 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9683 children = gdk_window_get_children (window);
9684 gtk_widget_add_events_internal_list (widget, device, events, children);
9685 g_list_free (children);
9691 gtk_widget_add_events_internal (GtkWidget *widget,
9695 GtkWidgetPrivate *priv = widget->priv;
9698 if (!gtk_widget_get_has_window (widget))
9699 window_list = gdk_window_get_children (priv->window);
9701 window_list = g_list_prepend (NULL, priv->window);
9703 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9705 g_list_free (window_list);
9709 * gtk_widget_add_events:
9710 * @widget: a #GtkWidget
9711 * @events: an event mask, see #GdkEventMask
9713 * Adds the events in the bitfield @events to the event mask for
9714 * @widget. See gtk_widget_set_events() for details.
9717 gtk_widget_add_events (GtkWidget *widget,
9722 g_return_if_fail (GTK_IS_WIDGET (widget));
9724 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9725 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9726 GINT_TO_POINTER (old_events | events));
9728 if (gtk_widget_get_realized (widget))
9730 gtk_widget_add_events_internal (widget, NULL, events);
9731 gtk_widget_update_devices_mask (widget, FALSE);
9734 g_object_notify (G_OBJECT (widget), "events");
9738 * gtk_widget_add_device_events:
9739 * @widget: a #GtkWidget
9740 * @device: a #GdkDevice
9741 * @events: an event mask, see #GdkEventMask
9743 * Adds the device events in the bitfield @events to the event mask for
9744 * @widget. See gtk_widget_set_device_events() for details.
9749 gtk_widget_add_device_events (GtkWidget *widget,
9751 GdkEventMask events)
9753 GdkEventMask old_events;
9754 GHashTable *device_events;
9756 g_return_if_fail (GTK_IS_WIDGET (widget));
9757 g_return_if_fail (GDK_IS_DEVICE (device));
9759 old_events = gtk_widget_get_device_events (widget, device);
9761 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9763 if (G_UNLIKELY (!device_events))
9765 device_events = g_hash_table_new (NULL, NULL);
9766 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9767 (GDestroyNotify) g_hash_table_unref);
9770 g_hash_table_insert (device_events, device,
9771 GUINT_TO_POINTER (old_events | events));
9773 if (gtk_widget_get_realized (widget))
9774 gtk_widget_add_events_internal (widget, device, events);
9776 g_object_notify (G_OBJECT (widget), "events");
9780 * gtk_widget_get_toplevel:
9781 * @widget: a #GtkWidget
9783 * This function returns the topmost widget in the container hierarchy
9784 * @widget is a part of. If @widget has no parent widgets, it will be
9785 * returned as the topmost widget. No reference will be added to the
9786 * returned widget; it should not be unreferenced.
9788 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9789 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9791 * %NULL if @widget wasn't inside a toplevel window, and if the
9792 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9793 * inside the toplevel #GtkWindow. While the second case may
9794 * seem unlikely, it actually happens when a #GtkPlug is embedded
9795 * inside a #GtkSocket within the same application.
9797 * To reliably find the toplevel #GtkWindow, use
9798 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9799 * is set on the result.
9801 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9802 * if (gtk_widget_is_toplevel (toplevel))
9804 * /* Perform action on toplevel. */
9808 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9809 * if there's no ancestor.
9812 gtk_widget_get_toplevel (GtkWidget *widget)
9814 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9816 while (widget->priv->parent)
9817 widget = widget->priv->parent;
9823 * gtk_widget_get_ancestor:
9824 * @widget: a #GtkWidget
9825 * @widget_type: ancestor type
9827 * Gets the first ancestor of @widget with type @widget_type. For example,
9828 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9829 * the first #GtkBox that's an ancestor of @widget. No reference will be
9830 * added to the returned widget; it should not be unreferenced. See note
9831 * about checking for a toplevel #GtkWindow in the docs for
9832 * gtk_widget_get_toplevel().
9834 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9835 * considers @widget to be an ancestor of itself.
9837 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9840 gtk_widget_get_ancestor (GtkWidget *widget,
9843 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9845 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9846 widget = widget->priv->parent;
9848 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9855 * gtk_widget_set_visual:
9856 * @widget: a #GtkWidget
9857 * @visual: visual to be used or %NULL to unset a previous one
9859 * Sets the visual that should be used for by widget and its children for
9860 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9861 * returned by gtk_widget_get_screen(), so handling the
9862 * #GtkWidget::screen-changed signal is necessary.
9864 * Setting a new @visual will not cause @widget to recreate its windows,
9865 * so you should call this function before @widget is realized.
9868 gtk_widget_set_visual (GtkWidget *widget,
9871 g_return_if_fail (GTK_IS_WIDGET (widget));
9872 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9875 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9878 g_object_set_qdata_full (G_OBJECT (widget),
9880 g_object_ref (visual),
9885 * gtk_widget_get_visual:
9886 * @widget: a #GtkWidget
9888 * Gets the visual that will be used to render @widget.
9890 * Return value: (transfer none): the visual for @widget
9893 gtk_widget_get_visual (GtkWidget *widget)
9899 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9901 if (gtk_widget_get_has_window (widget) &&
9902 widget->priv->window)
9903 return gdk_window_get_visual (widget->priv->window);
9905 screen = gtk_widget_get_screen (widget);
9907 for (w = widget; w != NULL; w = w->priv->parent)
9909 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9912 if (gdk_visual_get_screen (visual) == screen)
9915 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9916 gtk_widget_get_name (widget));
9920 return gdk_screen_get_system_visual (screen);
9924 * gtk_widget_get_settings:
9925 * @widget: a #GtkWidget
9927 * Gets the settings object holding the settings used for this widget.
9929 * Note that this function can only be called when the #GtkWidget
9930 * is attached to a toplevel, since the settings object is specific
9931 * to a particular #GdkScreen.
9933 * Return value: (transfer none): the relevant #GtkSettings object
9936 gtk_widget_get_settings (GtkWidget *widget)
9938 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9940 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9944 * gtk_widget_get_events:
9945 * @widget: a #GtkWidget
9947 * Returns the event mask for the widget (a bitfield containing flags
9948 * from the #GdkEventMask enumeration). These are the events that the widget
9951 * Return value: event mask for @widget
9954 gtk_widget_get_events (GtkWidget *widget)
9956 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9958 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9962 * gtk_widget_get_device_events:
9963 * @widget: a #GtkWidget
9964 * @device: a #GdkDevice
9966 * Returns the events mask for the widget corresponding to an specific device. These
9967 * are the events that the widget will receive when @device operates on it.
9969 * Returns: device event mask for @widget
9974 gtk_widget_get_device_events (GtkWidget *widget,
9977 GHashTable *device_events;
9979 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9980 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9982 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9987 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9991 * gtk_widget_get_pointer:
9992 * @widget: a #GtkWidget
9993 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9994 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9996 * Obtains the location of the mouse pointer in widget coordinates.
9997 * Widget coordinates are a bit odd; for historical reasons, they are
9998 * defined as @widget->window coordinates for widgets that are not
9999 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10000 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10002 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10005 gtk_widget_get_pointer (GtkWidget *widget,
10009 GtkWidgetPrivate *priv;
10011 g_return_if_fail (GTK_IS_WIDGET (widget));
10013 priv = widget->priv;
10020 if (gtk_widget_get_realized (widget))
10022 gdk_window_get_device_position (priv->window,
10023 gdk_device_manager_get_client_pointer (
10024 gdk_display_get_device_manager (
10025 gtk_widget_get_display (widget))),
10028 if (!gtk_widget_get_has_window (widget))
10031 *x -= priv->allocation.x;
10033 *y -= priv->allocation.y;
10039 * gtk_widget_is_ancestor:
10040 * @widget: a #GtkWidget
10041 * @ancestor: another #GtkWidget
10043 * Determines whether @widget is somewhere inside @ancestor, possibly with
10044 * intermediate containers.
10046 * Return value: %TRUE if @ancestor contains @widget as a child,
10047 * grandchild, great grandchild, etc.
10050 gtk_widget_is_ancestor (GtkWidget *widget,
10051 GtkWidget *ancestor)
10053 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10054 g_return_val_if_fail (ancestor != NULL, FALSE);
10058 if (widget->priv->parent == ancestor)
10060 widget = widget->priv->parent;
10066 static GQuark quark_composite_name = 0;
10069 * gtk_widget_set_composite_name:
10070 * @widget: a #GtkWidget.
10071 * @name: the name to set
10073 * Sets a widgets composite name. The widget must be
10074 * a composite child of its parent; see gtk_widget_push_composite_child().
10077 gtk_widget_set_composite_name (GtkWidget *widget,
10080 g_return_if_fail (GTK_IS_WIDGET (widget));
10081 g_return_if_fail (widget->priv->composite_child);
10082 g_return_if_fail (name != NULL);
10084 if (!quark_composite_name)
10085 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10087 g_object_set_qdata_full (G_OBJECT (widget),
10088 quark_composite_name,
10094 * gtk_widget_get_composite_name:
10095 * @widget: a #GtkWidget
10097 * Obtains the composite name of a widget.
10099 * Returns: the composite name of @widget, or %NULL if @widget is not
10100 * a composite child. The string should be freed when it is no
10104 gtk_widget_get_composite_name (GtkWidget *widget)
10106 GtkWidgetPrivate *priv;
10108 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10110 priv = widget->priv;
10112 if (widget->priv->composite_child && priv->parent)
10113 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10120 * gtk_widget_push_composite_child:
10122 * Makes all newly-created widgets as composite children until
10123 * the corresponding gtk_widget_pop_composite_child() call.
10125 * A composite child is a child that's an implementation detail of the
10126 * container it's inside and should not be visible to people using the
10127 * container. Composite children aren't treated differently by GTK (but
10128 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10129 * builders might want to treat them in a different way.
10131 * Here is a simple example:
10133 * gtk_widget_push_composite_child ();
10134 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10135 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10136 * gtk_widget_pop_composite_child ();
10137 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10138 * GTK_WIDGET (scrolled_window));
10139 * g_object_ref (scrolled_window->hscrollbar);
10143 gtk_widget_push_composite_child (void)
10145 composite_child_stack++;
10149 * gtk_widget_pop_composite_child:
10151 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10154 gtk_widget_pop_composite_child (void)
10156 if (composite_child_stack)
10157 composite_child_stack--;
10161 gtk_widget_emit_direction_changed (GtkWidget *widget,
10162 GtkTextDirection old_dir)
10164 GtkTextDirection direction;
10165 GtkStateFlags state;
10167 gtk_widget_update_pango_context (widget);
10169 direction = gtk_widget_get_direction (widget);
10170 state = widget->priv->state_flags;
10171 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10175 case GTK_TEXT_DIR_LTR:
10176 state |= GTK_STATE_FLAG_DIR_LTR;
10179 case GTK_TEXT_DIR_RTL:
10180 state |= GTK_STATE_FLAG_DIR_RTL;
10183 case GTK_TEXT_DIR_NONE:
10185 g_assert_not_reached ();
10189 gtk_widget_set_state_flags (widget, state, TRUE);
10191 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10195 * gtk_widget_set_direction:
10196 * @widget: a #GtkWidget
10197 * @dir: the new direction
10199 * Sets the reading direction on a particular widget. This direction
10200 * controls the primary direction for widgets containing text,
10201 * and also the direction in which the children of a container are
10202 * packed. The ability to set the direction is present in order
10203 * so that correct localization into languages with right-to-left
10204 * reading directions can be done. Generally, applications will
10205 * let the default reading direction present, except for containers
10206 * where the containers are arranged in an order that is explicitely
10207 * visual rather than logical (such as buttons for text justification).
10209 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10210 * set by gtk_widget_set_default_direction() will be used.
10213 gtk_widget_set_direction (GtkWidget *widget,
10214 GtkTextDirection dir)
10216 GtkTextDirection old_dir;
10218 g_return_if_fail (GTK_IS_WIDGET (widget));
10219 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10221 old_dir = gtk_widget_get_direction (widget);
10223 widget->priv->direction = dir;
10225 if (old_dir != gtk_widget_get_direction (widget))
10226 gtk_widget_emit_direction_changed (widget, old_dir);
10230 * gtk_widget_get_direction:
10231 * @widget: a #GtkWidget
10233 * Gets the reading direction for a particular widget. See
10234 * gtk_widget_set_direction().
10236 * Return value: the reading direction for the widget.
10239 gtk_widget_get_direction (GtkWidget *widget)
10241 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10243 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10244 return gtk_default_direction;
10246 return widget->priv->direction;
10250 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10252 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10254 g_object_ref (widget);
10256 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10257 gtk_widget_emit_direction_changed (widget, old_dir);
10259 if (GTK_IS_CONTAINER (widget))
10260 gtk_container_forall (GTK_CONTAINER (widget),
10261 gtk_widget_set_default_direction_recurse,
10264 g_object_unref (widget);
10268 * gtk_widget_set_default_direction:
10269 * @dir: the new default direction. This cannot be
10270 * %GTK_TEXT_DIR_NONE.
10272 * Sets the default reading direction for widgets where the
10273 * direction has not been explicitly set by gtk_widget_set_direction().
10276 gtk_widget_set_default_direction (GtkTextDirection dir)
10278 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10280 if (dir != gtk_default_direction)
10282 GList *toplevels, *tmp_list;
10283 GtkTextDirection old_dir = gtk_default_direction;
10285 gtk_default_direction = dir;
10287 tmp_list = toplevels = gtk_window_list_toplevels ();
10288 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10292 gtk_widget_set_default_direction_recurse (tmp_list->data,
10293 GUINT_TO_POINTER (old_dir));
10294 g_object_unref (tmp_list->data);
10295 tmp_list = tmp_list->next;
10298 g_list_free (toplevels);
10303 * gtk_widget_get_default_direction:
10305 * Obtains the current default reading direction. See
10306 * gtk_widget_set_default_direction().
10308 * Return value: the current default direction.
10311 gtk_widget_get_default_direction (void)
10313 return gtk_default_direction;
10317 gtk_widget_constructed (GObject *object)
10319 GtkWidget *widget = GTK_WIDGET (object);
10320 GtkWidgetPrivate *priv = widget->priv;
10322 /* As strange as it may seem, this may happen on object construction.
10323 * init() implementations of parent types may eventually call this function,
10324 * each with its corresponding GType, which could leave a child
10325 * implementation with a wrong widget type in the widget path
10328 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10330 gtk_widget_path_free (priv->path);
10334 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10338 gtk_widget_dispose (GObject *object)
10340 GtkWidget *widget = GTK_WIDGET (object);
10341 GtkWidgetPrivate *priv = widget->priv;
10344 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10345 else if (gtk_widget_get_visible (widget))
10346 gtk_widget_hide (widget);
10348 priv->visible = FALSE;
10349 if (gtk_widget_get_realized (widget))
10350 gtk_widget_unrealize (widget);
10352 if (!priv->in_destruction)
10354 priv->in_destruction = TRUE;
10355 g_signal_emit (object, widget_signals[DESTROY], 0);
10356 priv->in_destruction = FALSE;
10359 g_clear_object (&priv->muxer);
10361 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10365 gtk_widget_real_destroy (GtkWidget *object)
10367 /* gtk_object_destroy() will already hold a refcount on object */
10368 GtkWidget *widget = GTK_WIDGET (object);
10369 GtkWidgetPrivate *priv = widget->priv;
10371 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10373 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10377 gtk_accessible_set_widget (accessible, NULL);
10378 g_object_unref (accessible);
10382 /* wipe accelerator closures (keep order) */
10383 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10384 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10386 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10387 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10389 gtk_grab_remove (widget);
10392 g_object_unref (priv->style);
10393 priv->style = gtk_widget_get_default_style ();
10394 g_object_ref (priv->style);
10398 gtk_widget_finalize (GObject *object)
10400 GtkWidget *widget = GTK_WIDGET (object);
10401 GtkWidgetPrivate *priv = widget->priv;
10402 GtkWidgetAuxInfo *aux_info;
10403 GtkAccessible *accessible;
10405 gtk_grab_remove (widget);
10407 g_object_unref (priv->style);
10408 priv->style = NULL;
10410 g_free (priv->name);
10412 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10414 gtk_widget_aux_info_destroy (aux_info);
10416 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10418 g_object_unref (accessible);
10421 gtk_widget_path_free (priv->path);
10425 _gtk_style_context_set_widget (priv->context, NULL);
10426 g_object_unref (priv->context);
10429 _gtk_size_request_cache_free (&priv->requests);
10431 if (g_object_is_floating (object))
10432 g_warning ("A floating object was finalized. This means that someone\n"
10433 "called g_object_unref() on an object that had only a floating\n"
10434 "reference; the initial floating reference is not owned by anyone\n"
10435 "and must be removed with g_object_ref_sink().");
10437 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10440 /*****************************************
10441 * gtk_widget_real_map:
10446 *****************************************/
10449 gtk_widget_real_map (GtkWidget *widget)
10451 GtkWidgetPrivate *priv = widget->priv;
10453 g_assert (gtk_widget_get_realized (widget));
10455 if (!gtk_widget_get_mapped (widget))
10457 gtk_widget_set_mapped (widget, TRUE);
10459 if (gtk_widget_get_has_window (widget))
10460 gdk_window_show (priv->window);
10464 /*****************************************
10465 * gtk_widget_real_unmap:
10470 *****************************************/
10473 gtk_widget_real_unmap (GtkWidget *widget)
10475 GtkWidgetPrivate *priv = widget->priv;
10477 if (gtk_widget_get_mapped (widget))
10479 gtk_widget_set_mapped (widget, FALSE);
10481 if (gtk_widget_get_has_window (widget))
10482 gdk_window_hide (priv->window);
10486 /*****************************************
10487 * gtk_widget_real_realize:
10492 *****************************************/
10495 gtk_widget_real_realize (GtkWidget *widget)
10497 GtkWidgetPrivate *priv = widget->priv;
10499 g_assert (!gtk_widget_get_has_window (widget));
10501 gtk_widget_set_realized (widget, TRUE);
10504 priv->window = gtk_widget_get_parent_window (widget);
10505 g_object_ref (priv->window);
10509 /*****************************************
10510 * gtk_widget_real_unrealize:
10515 *****************************************/
10518 gtk_widget_real_unrealize (GtkWidget *widget)
10520 GtkWidgetPrivate *priv = widget->priv;
10522 g_assert (!widget->priv->mapped);
10524 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10527 /* We must do unrealize child widget BEFORE container widget.
10528 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10529 * So, unrealizing container widget bofore its children causes the problem
10530 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10533 if (GTK_IS_CONTAINER (widget))
10534 gtk_container_forall (GTK_CONTAINER (widget),
10535 (GtkCallback) gtk_widget_unrealize,
10538 if (gtk_widget_get_has_window (widget))
10540 gtk_widget_unregister_window (widget, priv->window);
10541 gdk_window_destroy (priv->window);
10542 priv->window = NULL;
10546 g_object_unref (priv->window);
10547 priv->window = NULL;
10550 gtk_selection_remove_all (widget);
10552 gtk_widget_set_realized (widget, FALSE);
10556 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10557 GtkOrientation orientation,
10558 gint *minimum_size,
10559 gint *natural_size)
10561 const GtkWidgetAuxInfo *aux_info;
10563 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10565 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10566 aux_info->width > 0)
10568 *minimum_size = MAX (*minimum_size, aux_info->width);
10570 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10571 aux_info->height > 0)
10573 *minimum_size = MAX (*minimum_size, aux_info->height);
10576 /* Fix it if set_size_request made natural size smaller than min size.
10577 * This would also silently fix broken widgets, but we warn about them
10578 * in gtksizerequest.c when calling their size request vfuncs.
10580 *natural_size = MAX (*natural_size, *minimum_size);
10582 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10584 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10585 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10589 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10590 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10595 * _gtk_widget_peek_request_cache:
10597 * Returns the address of the widget's request cache (strictly for
10598 * internal use in gtksizerequest.c)
10600 * Return value: the address of @widget's size request cache.
10603 _gtk_widget_peek_request_cache (GtkWidget *widget)
10605 /* Don't bother slowing things down with the return_if_fail guards here */
10606 return &widget->priv->requests;
10610 * _gtk_widget_set_device_window:
10611 * @widget: a #GtkWidget
10612 * @device: a #GdkDevice
10613 * @window: the new device window
10615 * Sets pointer window for @widget and @device.
10616 * Does not ref @window.
10619 _gtk_widget_set_device_window (GtkWidget *widget,
10623 GHashTable *device_window;
10625 g_return_if_fail (GTK_IS_WIDGET (widget));
10626 g_return_if_fail (GDK_IS_DEVICE (device));
10627 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10629 if (!gtk_widget_get_mapped (widget))
10632 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10634 if (!device_window && window)
10636 device_window = g_hash_table_new (NULL, NULL);
10637 g_object_set_qdata_full (G_OBJECT (widget),
10638 quark_pointer_window,
10640 (GDestroyNotify) g_hash_table_destroy);
10644 g_hash_table_insert (device_window, device, window);
10645 else if (device_window)
10647 g_hash_table_remove (device_window, device);
10649 if (g_hash_table_size (device_window) == 0)
10650 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10655 * _gtk_widget_get_device_window:
10656 * @widget: a #GtkWidget
10657 * @device: a #GdkDevice
10659 * Return value: the device window set on @widget, or %NULL
10662 _gtk_widget_get_device_window (GtkWidget *widget,
10665 GHashTable *device_window;
10667 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10668 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10670 if (!gtk_widget_get_mapped (widget))
10673 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10675 if (!device_window)
10678 return g_hash_table_lookup (device_window, device);
10682 * _gtk_widget_list_devices:
10683 * @widget: a #GtkWidget
10685 * Returns the list of #GdkDevices that is currently on top
10686 * of any window belonging to @widget.
10687 * Free the list with g_list_free(), the elements are owned
10688 * by GTK+ and must not be freed.
10691 _gtk_widget_list_devices (GtkWidget *widget)
10693 GHashTableIter iter;
10694 GHashTable *device_window;
10695 GList *devices = NULL;
10696 gpointer key, value;
10698 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10700 if (!gtk_widget_get_mapped (widget))
10703 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10705 if (G_UNLIKELY (!device_window))
10708 g_hash_table_iter_init (&iter, device_window);
10710 while (g_hash_table_iter_next (&iter, &key, &value))
10711 devices = g_list_prepend (devices, key);
10717 synth_crossing (GtkWidget *widget,
10721 GdkCrossingMode mode,
10722 GdkNotifyType detail)
10726 event = gdk_event_new (type);
10728 event->crossing.window = g_object_ref (window);
10729 event->crossing.send_event = TRUE;
10730 event->crossing.subwindow = g_object_ref (window);
10731 event->crossing.time = GDK_CURRENT_TIME;
10732 event->crossing.x = event->crossing.y = 0;
10733 event->crossing.x_root = event->crossing.y_root = 0;
10734 event->crossing.mode = mode;
10735 event->crossing.detail = detail;
10736 event->crossing.focus = FALSE;
10737 event->crossing.state = 0;
10738 gdk_event_set_device (event, device);
10741 widget = gtk_get_event_widget (event);
10744 gtk_widget_event_internal (widget, event);
10746 gdk_event_free (event);
10750 * _gtk_widget_synthesize_crossing:
10751 * @from: the #GtkWidget the virtual pointer is leaving.
10752 * @to: the #GtkWidget the virtual pointer is moving to.
10753 * @mode: the #GdkCrossingMode to place on the synthesized events.
10755 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10757 * The real pointer window is the window that most recently received an enter notify
10758 * event. Windows that don't select for crossing events can't become the real
10759 * poiner window. The real pointer widget that owns the real pointer window. The
10760 * effective pointer window is the same as the real pointer window unless the real
10761 * pointer widget is either insensitive or there is a grab on a widget that is not
10762 * an ancestor of the real pointer widget (in which case the effective pointer
10763 * window should be the root window).
10765 * When the effective pointer window is the same as the real poiner window, we
10766 * receive crossing events from the windowing system. When the effective pointer
10767 * window changes to become different from the real pointer window we synthesize
10768 * crossing events, attempting to follow X protocol rules:
10770 * When the root window becomes the effective pointer window:
10771 * - leave notify on real pointer window, detail Ancestor
10772 * - leave notify on all of its ancestors, detail Virtual
10773 * - enter notify on root window, detail Inferior
10775 * When the root window ceases to be the effective pointer window:
10776 * - leave notify on root window, detail Inferior
10777 * - enter notify on all ancestors of real pointer window, detail Virtual
10778 * - enter notify on real pointer window, detail Ancestor
10781 _gtk_widget_synthesize_crossing (GtkWidget *from,
10784 GdkCrossingMode mode)
10786 GdkWindow *from_window = NULL, *to_window = NULL;
10788 g_return_if_fail (from != NULL || to != NULL);
10792 from_window = _gtk_widget_get_device_window (from, device);
10795 from_window = from->priv->window;
10800 to_window = _gtk_widget_get_device_window (to, device);
10803 to_window = to->priv->window;
10806 if (from_window == NULL && to_window == NULL)
10808 else if (from_window != NULL && to_window == NULL)
10810 GList *from_ancestors = NULL, *list;
10811 GdkWindow *from_ancestor = from_window;
10813 while (from_ancestor != NULL)
10815 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10816 if (from_ancestor == NULL)
10818 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10821 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10822 device, mode, GDK_NOTIFY_ANCESTOR);
10823 for (list = g_list_last (from_ancestors); list; list = list->prev)
10825 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10826 device, mode, GDK_NOTIFY_VIRTUAL);
10829 /* XXX: enter/inferior on root window? */
10831 g_list_free (from_ancestors);
10833 else if (from_window == NULL && to_window != NULL)
10835 GList *to_ancestors = NULL, *list;
10836 GdkWindow *to_ancestor = to_window;
10838 while (to_ancestor != NULL)
10840 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10841 if (to_ancestor == NULL)
10843 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10846 /* XXX: leave/inferior on root window? */
10848 for (list = to_ancestors; list; list = list->next)
10850 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10851 device, mode, GDK_NOTIFY_VIRTUAL);
10853 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10854 device, mode, GDK_NOTIFY_ANCESTOR);
10856 g_list_free (to_ancestors);
10858 else if (from_window == to_window)
10862 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10863 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10865 while (from_ancestor != NULL || to_ancestor != NULL)
10867 if (from_ancestor != NULL)
10869 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10870 if (from_ancestor == to_window)
10873 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10875 if (to_ancestor != NULL)
10877 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10878 if (to_ancestor == from_window)
10881 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10884 if (to_ancestor == from_window)
10886 if (mode != GDK_CROSSING_GTK_UNGRAB)
10887 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10888 device, mode, GDK_NOTIFY_INFERIOR);
10889 for (list = to_ancestors; list; list = list->next)
10890 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10891 device, mode, GDK_NOTIFY_VIRTUAL);
10892 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10893 device, mode, GDK_NOTIFY_ANCESTOR);
10895 else if (from_ancestor == to_window)
10897 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10898 device, mode, GDK_NOTIFY_ANCESTOR);
10899 for (list = g_list_last (from_ancestors); list; list = list->prev)
10901 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10902 device, mode, GDK_NOTIFY_VIRTUAL);
10904 if (mode != GDK_CROSSING_GTK_GRAB)
10905 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10906 device, mode, GDK_NOTIFY_INFERIOR);
10910 while (from_ancestors != NULL && to_ancestors != NULL
10911 && from_ancestors->data == to_ancestors->data)
10913 from_ancestors = g_list_delete_link (from_ancestors,
10915 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10918 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10919 device, mode, GDK_NOTIFY_NONLINEAR);
10921 for (list = g_list_last (from_ancestors); list; list = list->prev)
10923 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10924 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10926 for (list = to_ancestors; list; list = list->next)
10928 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10929 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10931 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10932 device, mode, GDK_NOTIFY_NONLINEAR);
10934 g_list_free (from_ancestors);
10935 g_list_free (to_ancestors);
10940 gtk_widget_propagate_state (GtkWidget *widget,
10941 GtkStateData *data)
10943 GtkWidgetPrivate *priv = widget->priv;
10944 GtkStateFlags new_flags, old_flags = priv->state_flags;
10945 GtkStateType old_state;
10947 old_state = gtk_widget_get_state (widget);
10949 priv->state_flags |= data->flags_to_set;
10950 priv->state_flags &= ~(data->flags_to_unset);
10952 /* make insensitivity unoverridable */
10953 if (!priv->sensitive)
10954 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10956 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10960 window = gtk_widget_get_toplevel (widget);
10962 if (window && gtk_widget_is_toplevel (window))
10963 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10966 new_flags = priv->state_flags;
10968 if (old_flags != new_flags)
10970 g_object_ref (widget);
10972 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10973 gtk_grab_remove (widget);
10975 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10977 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10978 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10980 if (!priv->shadowed &&
10981 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10983 GList *event_windows = NULL;
10984 GList *devices, *d;
10986 devices = _gtk_widget_list_devices (widget);
10988 for (d = devices; d; d = d->next)
10994 window = _gtk_widget_get_device_window (widget, device);
10996 /* Do not propagate more than once to the
10997 * same window if non-multidevice aware.
10999 if (!gdk_window_get_support_multidevice (window) &&
11000 g_list_find (event_windows, window))
11003 if (!gtk_widget_is_sensitive (widget))
11004 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11005 GDK_CROSSING_STATE_CHANGED);
11007 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11008 GDK_CROSSING_STATE_CHANGED);
11010 event_windows = g_list_prepend (event_windows, window);
11013 g_list_free (event_windows);
11014 g_list_free (devices);
11017 if (GTK_IS_CONTAINER (widget))
11019 GtkStateData child_data;
11021 /* Make sure to only propate the right states further */
11022 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11023 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11025 gtk_container_forall (GTK_CONTAINER (widget),
11026 (GtkCallback) gtk_widget_propagate_state,
11030 g_object_unref (widget);
11034 static const GtkWidgetAuxInfo default_aux_info = {
11042 * gtk_widget_get_aux_info:
11043 * @widget: a #GtkWidget
11044 * @create: if %TRUE, create the structure if it doesn't exist
11046 * Get the #GtkWidgetAuxInfo structure for the widget.
11048 * Return value: the #GtkAuxInfo structure for the widget, or
11049 * %NULL if @create is %FALSE and one doesn't already exist.
11051 static GtkWidgetAuxInfo *
11052 gtk_widget_get_aux_info (GtkWidget *widget,
11055 GtkWidgetAuxInfo *aux_info;
11057 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11058 if (!aux_info && create)
11060 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11062 *aux_info = default_aux_info;
11064 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11070 static const GtkWidgetAuxInfo*
11071 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11073 GtkWidgetAuxInfo *aux_info;
11075 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11076 if (aux_info == NULL)
11078 return &default_aux_info;
11086 /*****************************************
11087 * gtk_widget_aux_info_destroy:
11092 *****************************************/
11095 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11097 g_slice_free (GtkWidgetAuxInfo, aux_info);
11101 * gtk_widget_shape_combine_region:
11102 * @widget: a #GtkWidget
11103 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11105 * Sets a shape for this widget's GDK window. This allows for
11106 * transparent windows etc., see gdk_window_shape_combine_region()
11107 * for more information.
11112 gtk_widget_shape_combine_region (GtkWidget *widget,
11113 cairo_region_t *region)
11115 GtkWidgetPrivate *priv;
11117 g_return_if_fail (GTK_IS_WIDGET (widget));
11118 /* set_shape doesn't work on widgets without gdk window */
11119 g_return_if_fail (gtk_widget_get_has_window (widget));
11121 priv = widget->priv;
11123 if (region == NULL)
11125 priv->has_shape_mask = FALSE;
11128 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11130 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11134 priv->has_shape_mask = TRUE;
11136 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11137 cairo_region_copy (region),
11138 (GDestroyNotify) cairo_region_destroy);
11140 /* set shape if widget has a gdk window already.
11141 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11144 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11149 * gtk_widget_input_shape_combine_region:
11150 * @widget: a #GtkWidget
11151 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11153 * Sets an input shape for this widget's GDK window. This allows for
11154 * windows which react to mouse click in a nonrectangular region, see
11155 * gdk_window_input_shape_combine_region() for more information.
11160 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11161 cairo_region_t *region)
11163 GtkWidgetPrivate *priv;
11165 g_return_if_fail (GTK_IS_WIDGET (widget));
11166 /* set_shape doesn't work on widgets without gdk window */
11167 g_return_if_fail (gtk_widget_get_has_window (widget));
11169 priv = widget->priv;
11171 if (region == NULL)
11174 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11176 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11180 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11181 cairo_region_copy (region),
11182 (GDestroyNotify) cairo_region_destroy);
11184 /* set shape if widget has a gdk window already.
11185 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11188 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11193 /* style properties
11197 * gtk_widget_class_install_style_property_parser: (skip)
11198 * @klass: a #GtkWidgetClass
11199 * @pspec: the #GParamSpec for the style property
11200 * @parser: the parser for the style property
11202 * Installs a style property on a widget class.
11205 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11207 GtkRcPropertyParser parser)
11209 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11210 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11211 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11212 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11214 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11216 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11217 G_OBJECT_CLASS_NAME (klass),
11222 g_param_spec_ref_sink (pspec);
11223 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11224 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11228 * gtk_widget_class_install_style_property:
11229 * @klass: a #GtkWidgetClass
11230 * @pspec: the #GParamSpec for the property
11232 * Installs a style property on a widget class. The parser for the
11233 * style property is determined by the value type of @pspec.
11236 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11239 GtkRcPropertyParser parser;
11241 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11242 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11244 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11246 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11250 * gtk_widget_class_find_style_property:
11251 * @klass: a #GtkWidgetClass
11252 * @property_name: the name of the style property to find
11254 * Finds a style property of a widget class by name.
11256 * Returns: (transfer none): the #GParamSpec of the style property or
11257 * %NULL if @class has no style property with that name.
11262 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11263 const gchar *property_name)
11265 g_return_val_if_fail (property_name != NULL, NULL);
11267 return g_param_spec_pool_lookup (style_property_spec_pool,
11269 G_OBJECT_CLASS_TYPE (klass),
11274 * gtk_widget_class_list_style_properties:
11275 * @klass: a #GtkWidgetClass
11276 * @n_properties: location to return the number of style properties found
11278 * Returns all style properties of a widget class.
11280 * Returns: (array length=n_properties) (transfer container): a
11281 * newly allocated array of #GParamSpec*. The array must be
11282 * freed with g_free().
11287 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11288 guint *n_properties)
11290 GParamSpec **pspecs;
11293 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11294 G_OBJECT_CLASS_TYPE (klass),
11303 * gtk_widget_style_get_property:
11304 * @widget: a #GtkWidget
11305 * @property_name: the name of a style property
11306 * @value: location to return the property value
11308 * Gets the value of a style property of @widget.
11311 gtk_widget_style_get_property (GtkWidget *widget,
11312 const gchar *property_name,
11317 g_return_if_fail (GTK_IS_WIDGET (widget));
11318 g_return_if_fail (property_name != NULL);
11319 g_return_if_fail (G_IS_VALUE (value));
11321 g_object_ref (widget);
11322 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11324 G_OBJECT_TYPE (widget),
11327 g_warning ("%s: widget class `%s' has no property named `%s'",
11329 G_OBJECT_TYPE_NAME (widget),
11333 GtkStyleContext *context;
11334 const GValue *peek_value;
11335 GtkStateFlags state;
11337 context = gtk_widget_get_style_context (widget);
11338 state = gtk_widget_get_state_flags (widget);
11340 peek_value = _gtk_style_context_peek_style_property (context,
11341 G_OBJECT_TYPE (widget),
11344 /* auto-conversion of the caller's value type
11346 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11347 g_value_copy (peek_value, value);
11348 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11349 g_value_transform (peek_value, value);
11351 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11353 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11354 G_VALUE_TYPE_NAME (value));
11356 g_object_unref (widget);
11360 * gtk_widget_style_get_valist:
11361 * @widget: a #GtkWidget
11362 * @first_property_name: the name of the first property to get
11363 * @var_args: a <type>va_list</type> of pairs of property names and
11364 * locations to return the property values, starting with the location
11365 * for @first_property_name.
11367 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11371 gtk_widget_style_get_valist (GtkWidget *widget,
11372 const gchar *first_property_name,
11375 GtkStyleContext *context;
11376 GtkStateFlags state;
11379 g_return_if_fail (GTK_IS_WIDGET (widget));
11381 g_object_ref (widget);
11382 context = gtk_widget_get_style_context (widget);
11383 state = gtk_widget_get_state_flags (widget);
11385 name = first_property_name;
11388 const GValue *peek_value;
11392 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11394 G_OBJECT_TYPE (widget),
11398 g_warning ("%s: widget class `%s' has no property named `%s'",
11400 G_OBJECT_TYPE_NAME (widget),
11404 /* style pspecs are always readable so we can spare that check here */
11406 peek_value = _gtk_style_context_peek_style_property (context,
11407 G_OBJECT_TYPE (widget),
11410 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11413 g_warning ("%s: %s", G_STRLOC, error);
11418 name = va_arg (var_args, gchar*);
11421 g_object_unref (widget);
11425 * gtk_widget_style_get:
11426 * @widget: a #GtkWidget
11427 * @first_property_name: the name of the first property to get
11428 * @...: pairs of property names and locations to return the
11429 * property values, starting with the location for
11430 * @first_property_name, terminated by %NULL.
11432 * Gets the values of a multiple style properties of @widget.
11435 gtk_widget_style_get (GtkWidget *widget,
11436 const gchar *first_property_name,
11441 g_return_if_fail (GTK_IS_WIDGET (widget));
11443 va_start (var_args, first_property_name);
11444 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11449 * gtk_requisition_new:
11451 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11453 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11454 * be freed with gtk_requisition_free().
11459 gtk_requisition_new (void)
11461 return g_slice_new0 (GtkRequisition);
11465 * gtk_requisition_copy:
11466 * @requisition: a #GtkRequisition
11468 * Copies a #GtkRequisition.
11470 * Returns: a copy of @requisition
11473 gtk_requisition_copy (const GtkRequisition *requisition)
11475 return g_slice_dup (GtkRequisition, requisition);
11479 * gtk_requisition_free:
11480 * @requisition: a #GtkRequisition
11482 * Frees a #GtkRequisition.
11485 gtk_requisition_free (GtkRequisition *requisition)
11487 g_slice_free (GtkRequisition, requisition);
11490 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11491 gtk_requisition_copy,
11492 gtk_requisition_free)
11495 * gtk_widget_class_set_accessible_type:
11496 * @widget_class: class to set the accessible type for
11497 * @type: The object type that implements the accessible for @widget_class
11499 * Sets the type to be used for creating accessibles for widgets of
11500 * @widget_class. The given @type must be a subtype of the type used for
11501 * accessibles of the parent class.
11503 * This function should only be called from class init functions of widgets.
11508 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11511 GtkWidgetClassPrivate *priv;
11513 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11514 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11516 priv = widget_class->priv;
11518 priv->accessible_type = type;
11519 /* reset this - honoring the type's role is better. */
11520 priv->accessible_role = ATK_ROLE_INVALID;
11524 * gtk_widget_class_set_accessible_role:
11525 * @widget_class: class to set the accessible role for
11526 * @role: The role to use for accessibles created for @widget_class
11528 * Sets the default #AtkRole to be set on accessibles created for
11529 * widgets of @widget_class. Accessibles may decide to not honor this
11530 * setting if their role reporting is more refined. Calls to
11531 * gtk_widget_class_set_accessible_type() will reset this value.
11533 * In cases where you want more fine-grained control over the role of
11534 * accessibles created for @widget_class, you should provide your own
11535 * accessible type and use gtk_widget_class_set_accessible_type()
11538 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11539 * and the accessible's default role will be used instead.
11541 * This function should only be called from class init functions of widgets.
11546 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11549 GtkWidgetClassPrivate *priv;
11551 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11553 priv = widget_class->priv;
11555 priv->accessible_role = role;
11559 * _gtk_widget_peek_accessible:
11560 * @widget: a #GtkWidget
11562 * Gets the accessible for @widget, if it has been created yet.
11563 * Otherwise, this function returns %NULL. If the @widget's implementation
11564 * does not use the default way to create accessibles, %NULL will always be
11567 * Returns: the accessible for @widget or %NULL if none has been
11571 _gtk_widget_peek_accessible (GtkWidget *widget)
11573 return g_object_get_qdata (G_OBJECT (widget),
11574 quark_accessible_object);
11578 * gtk_widget_get_accessible:
11579 * @widget: a #GtkWidget
11581 * Returns the accessible object that describes the widget to an
11582 * assistive technology.
11584 * If accessibility support is not available, this #AtkObject
11585 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11586 * implementation is available for the widget instance in question,
11587 * it will inherit an #AtkObject implementation from the first ancestor
11588 * class for which such an implementation is defined.
11590 * The documentation of the
11591 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11592 * library contains more information about accessible objects and their uses.
11594 * Returns: (transfer none): the #AtkObject associated with @widget
11597 gtk_widget_get_accessible (GtkWidget *widget)
11599 GtkWidgetClass *klass;
11601 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11603 klass = GTK_WIDGET_GET_CLASS (widget);
11605 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11607 return klass->get_accessible (widget);
11611 gtk_widget_real_get_accessible (GtkWidget *widget)
11613 AtkObject* accessible;
11615 accessible = g_object_get_qdata (G_OBJECT (widget),
11616 quark_accessible_object);
11619 GtkWidgetClass *widget_class;
11620 GtkWidgetClassPrivate *priv;
11621 AtkObjectFactory *factory;
11622 AtkRegistry *default_registry;
11624 widget_class = GTK_WIDGET_GET_CLASS (widget);
11625 priv = widget_class->priv;
11627 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11629 default_registry = atk_get_default_registry ();
11630 factory = atk_registry_get_factory (default_registry,
11631 G_TYPE_FROM_INSTANCE (widget));
11633 atk_object_factory_create_accessible (factory,
11634 G_OBJECT (widget));
11636 if (priv->accessible_role != ATK_ROLE_INVALID)
11637 atk_object_set_role (accessible, priv->accessible_role);
11639 g_object_set_qdata (G_OBJECT (widget),
11640 quark_accessible_object,
11645 accessible = g_object_new (priv->accessible_type,
11648 if (priv->accessible_role != ATK_ROLE_INVALID)
11649 atk_object_set_role (accessible, priv->accessible_role);
11651 g_object_set_qdata (G_OBJECT (widget),
11652 quark_accessible_object,
11655 atk_object_initialize (accessible, widget);
11657 /* Set the role again, since we don't want a role set
11658 * in some parent initialize() function to override
11661 if (priv->accessible_role != ATK_ROLE_INVALID)
11662 atk_object_set_role (accessible, priv->accessible_role);
11669 * Initialize a AtkImplementorIface instance's virtual pointers as
11670 * appropriate to this implementor's class (GtkWidget).
11673 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11675 iface->ref_accessible = gtk_widget_ref_accessible;
11679 gtk_widget_ref_accessible (AtkImplementor *implementor)
11681 AtkObject *accessible;
11683 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11685 g_object_ref (accessible);
11690 * Expand flag management
11694 gtk_widget_update_computed_expand (GtkWidget *widget)
11696 GtkWidgetPrivate *priv;
11698 priv = widget->priv;
11700 if (priv->need_compute_expand)
11704 if (priv->hexpand_set)
11709 if (priv->vexpand_set)
11714 /* we don't need to use compute_expand if both expands are
11715 * forced by the app
11717 if (!(priv->hexpand_set && priv->vexpand_set))
11719 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11723 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11724 priv->hexpand_set ? &ignored : &h,
11725 priv->vexpand_set ? &ignored : &v);
11729 priv->need_compute_expand = FALSE;
11730 priv->computed_hexpand = h != FALSE;
11731 priv->computed_vexpand = v != FALSE;
11736 * gtk_widget_queue_compute_expand:
11737 * @widget: a #GtkWidget
11739 * Mark @widget as needing to recompute its expand flags. Call
11740 * this function when setting legacy expand child properties
11741 * on the child of a container.
11743 * See gtk_widget_compute_expand().
11746 gtk_widget_queue_compute_expand (GtkWidget *widget)
11749 gboolean changed_anything;
11751 if (widget->priv->need_compute_expand)
11754 changed_anything = FALSE;
11756 while (parent != NULL)
11758 if (!parent->priv->need_compute_expand)
11760 parent->priv->need_compute_expand = TRUE;
11761 changed_anything = TRUE;
11764 /* Note: if we had an invariant that "if a child needs to
11765 * compute expand, its parents also do" then we could stop going
11766 * up when we got to a parent that already needed to
11767 * compute. However, in general we compute expand lazily (as
11768 * soon as we see something in a subtree that is expand, we know
11769 * we're expanding) and so this invariant does not hold and we
11770 * have to always walk all the way up in case some ancestor
11771 * is not currently need_compute_expand.
11774 parent = parent->priv->parent;
11777 /* recomputing expand always requires
11778 * a relayout as well
11780 if (changed_anything)
11781 gtk_widget_queue_resize (widget);
11785 * gtk_widget_compute_expand:
11786 * @widget: the widget
11787 * @orientation: expand direction
11789 * Computes whether a container should give this widget extra space
11790 * when possible. Containers should check this, rather than
11791 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11793 * This function already checks whether the widget is visible, so
11794 * visibility does not need to be checked separately. Non-visible
11795 * widgets are not expanded.
11797 * The computed expand value uses either the expand setting explicitly
11798 * set on the widget itself, or, if none has been explicitly set,
11799 * the widget may expand if some of its children do.
11801 * Return value: whether widget tree rooted here should be expanded
11804 gtk_widget_compute_expand (GtkWidget *widget,
11805 GtkOrientation orientation)
11807 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11809 /* We never make a widget expand if not even showing. */
11810 if (!gtk_widget_get_visible (widget))
11813 gtk_widget_update_computed_expand (widget);
11815 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11817 return widget->priv->computed_hexpand;
11821 return widget->priv->computed_vexpand;
11826 gtk_widget_set_expand (GtkWidget *widget,
11827 GtkOrientation orientation,
11830 const char *expand_prop;
11831 const char *expand_set_prop;
11833 GtkWidgetPrivate *priv;
11835 g_return_if_fail (GTK_IS_WIDGET (widget));
11837 priv = widget->priv;
11839 expand = expand != FALSE;
11841 was_both = priv->hexpand && priv->vexpand;
11843 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11845 if (priv->hexpand_set &&
11846 priv->hexpand == expand)
11849 priv->hexpand_set = TRUE;
11850 priv->hexpand = expand;
11852 expand_prop = "hexpand";
11853 expand_set_prop = "hexpand-set";
11857 if (priv->vexpand_set &&
11858 priv->vexpand == expand)
11861 priv->vexpand_set = TRUE;
11862 priv->vexpand = expand;
11864 expand_prop = "vexpand";
11865 expand_set_prop = "vexpand-set";
11868 gtk_widget_queue_compute_expand (widget);
11870 g_object_freeze_notify (G_OBJECT (widget));
11871 g_object_notify (G_OBJECT (widget), expand_prop);
11872 g_object_notify (G_OBJECT (widget), expand_set_prop);
11873 if (was_both != (priv->hexpand && priv->vexpand))
11874 g_object_notify (G_OBJECT (widget), "expand");
11875 g_object_thaw_notify (G_OBJECT (widget));
11879 gtk_widget_set_expand_set (GtkWidget *widget,
11880 GtkOrientation orientation,
11883 GtkWidgetPrivate *priv;
11886 priv = widget->priv;
11888 set = set != FALSE;
11890 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11892 if (set == priv->hexpand_set)
11895 priv->hexpand_set = set;
11896 prop = "hexpand-set";
11900 if (set == priv->vexpand_set)
11903 priv->vexpand_set = set;
11904 prop = "vexpand-set";
11907 gtk_widget_queue_compute_expand (widget);
11909 g_object_notify (G_OBJECT (widget), prop);
11913 * gtk_widget_get_hexpand:
11914 * @widget: the widget
11916 * Gets whether the widget would like any available extra horizontal
11917 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11918 * generally receive the extra space. For example, a list or
11919 * scrollable area or document in your window would often be set to
11922 * Containers should use gtk_widget_compute_expand() rather than
11923 * this function, to see whether a widget, or any of its children,
11924 * has the expand flag set. If any child of a widget wants to
11925 * expand, the parent may ask to expand also.
11927 * This function only looks at the widget's own hexpand flag, rather
11928 * than computing whether the entire widget tree rooted at this widget
11931 * Return value: whether hexpand flag is set
11934 gtk_widget_get_hexpand (GtkWidget *widget)
11936 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11938 return widget->priv->hexpand;
11942 * gtk_widget_set_hexpand:
11943 * @widget: the widget
11944 * @expand: whether to expand
11946 * Sets whether the widget would like any available extra horizontal
11947 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11948 * generally receive the extra space. For example, a list or
11949 * scrollable area or document in your window would often be set to
11952 * Call this function to set the expand flag if you would like your
11953 * widget to become larger horizontally when the window has extra
11956 * By default, widgets automatically expand if any of their children
11957 * want to expand. (To see if a widget will automatically expand given
11958 * its current children and state, call gtk_widget_compute_expand(). A
11959 * container can decide how the expandability of children affects the
11960 * expansion of the container by overriding the compute_expand virtual
11961 * method on #GtkWidget.).
11963 * Setting hexpand explicitly with this function will override the
11964 * automatic expand behavior.
11966 * This function forces the widget to expand or not to expand,
11967 * regardless of children. The override occurs because
11968 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11969 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11970 * value to be used, rather than looking at children and widget state.
11973 gtk_widget_set_hexpand (GtkWidget *widget,
11976 g_return_if_fail (GTK_IS_WIDGET (widget));
11978 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11982 * gtk_widget_get_hexpand_set:
11983 * @widget: the widget
11985 * Gets whether gtk_widget_set_hexpand() has been used to
11986 * explicitly set the expand flag on this widget.
11988 * If hexpand is set, then it overrides any computed
11989 * expand value based on child widgets. If hexpand is not
11990 * set, then the expand value depends on whether any
11991 * children of the widget would like to expand.
11993 * There are few reasons to use this function, but it's here
11994 * for completeness and consistency.
11996 * Return value: whether hexpand has been explicitly set
11999 gtk_widget_get_hexpand_set (GtkWidget *widget)
12001 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12003 return widget->priv->hexpand_set;
12007 * gtk_widget_set_hexpand_set:
12008 * @widget: the widget
12009 * @set: value for hexpand-set property
12011 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12014 * The hexpand-set property will be set automatically when you call
12015 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12016 * reason to use this function would be to unset an explicit expand
12019 * If hexpand is set, then it overrides any computed
12020 * expand value based on child widgets. If hexpand is not
12021 * set, then the expand value depends on whether any
12022 * children of the widget would like to expand.
12024 * There are few reasons to use this function, but it's here
12025 * for completeness and consistency.
12028 gtk_widget_set_hexpand_set (GtkWidget *widget,
12031 g_return_if_fail (GTK_IS_WIDGET (widget));
12033 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12038 * gtk_widget_get_vexpand:
12039 * @widget: the widget
12041 * Gets whether the widget would like any available extra vertical
12044 * See gtk_widget_get_hexpand() for more detail.
12046 * Return value: whether vexpand flag is set
12049 gtk_widget_get_vexpand (GtkWidget *widget)
12051 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12053 return widget->priv->vexpand;
12057 * gtk_widget_set_vexpand:
12058 * @widget: the widget
12059 * @expand: whether to expand
12061 * Sets whether the widget would like any available extra vertical
12064 * See gtk_widget_set_hexpand() for more detail.
12067 gtk_widget_set_vexpand (GtkWidget *widget,
12070 g_return_if_fail (GTK_IS_WIDGET (widget));
12072 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12076 * gtk_widget_get_vexpand_set:
12077 * @widget: the widget
12079 * Gets whether gtk_widget_set_vexpand() has been used to
12080 * explicitly set the expand flag on this widget.
12082 * See gtk_widget_get_hexpand_set() for more detail.
12084 * Return value: whether vexpand has been explicitly set
12087 gtk_widget_get_vexpand_set (GtkWidget *widget)
12089 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12091 return widget->priv->vexpand_set;
12095 * gtk_widget_set_vexpand_set:
12096 * @widget: the widget
12097 * @set: value for vexpand-set property
12099 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12102 * See gtk_widget_set_hexpand_set() for more detail.
12105 gtk_widget_set_vexpand_set (GtkWidget *widget,
12108 g_return_if_fail (GTK_IS_WIDGET (widget));
12110 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12114 * GtkBuildable implementation
12116 static GQuark quark_builder_has_default = 0;
12117 static GQuark quark_builder_has_focus = 0;
12118 static GQuark quark_builder_atk_relations = 0;
12119 static GQuark quark_builder_set_name = 0;
12122 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12124 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12125 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12126 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12127 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12129 iface->set_name = gtk_widget_buildable_set_name;
12130 iface->get_name = gtk_widget_buildable_get_name;
12131 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12132 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12133 iface->parser_finished = gtk_widget_buildable_parser_finished;
12134 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12135 iface->custom_finished = gtk_widget_buildable_custom_finished;
12139 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12142 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12143 g_strdup (name), g_free);
12146 static const gchar *
12147 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12149 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12153 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12154 GtkBuilder *builder,
12155 const gchar *childname)
12157 if (strcmp (childname, "accessible") == 0)
12158 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12164 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12165 GtkBuilder *builder,
12167 const GValue *value)
12169 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12170 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12171 GINT_TO_POINTER (TRUE));
12172 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12173 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12174 GINT_TO_POINTER (TRUE));
12176 g_object_set_property (G_OBJECT (buildable), name, value);
12181 gchar *action_name;
12182 GString *description;
12184 gboolean translatable;
12194 free_action (AtkActionData *data, gpointer user_data)
12196 g_free (data->action_name);
12197 g_string_free (data->description, TRUE);
12198 g_free (data->context);
12199 g_slice_free (AtkActionData, data);
12203 free_relation (AtkRelationData *data, gpointer user_data)
12205 g_free (data->target);
12206 g_free (data->type);
12207 g_slice_free (AtkRelationData, data);
12211 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12212 GtkBuilder *builder)
12214 GSList *atk_relations;
12216 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12217 gtk_widget_grab_default (GTK_WIDGET (buildable));
12218 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12219 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12221 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12222 quark_builder_atk_relations);
12225 AtkObject *accessible;
12226 AtkRelationSet *relation_set;
12229 AtkRelationType relation_type;
12230 AtkObject *target_accessible;
12232 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12233 relation_set = atk_object_ref_relation_set (accessible);
12235 for (l = atk_relations; l; l = l->next)
12237 AtkRelationData *relation = (AtkRelationData*)l->data;
12239 target = gtk_builder_get_object (builder, relation->target);
12242 g_warning ("Target object %s in <relation> does not exist",
12246 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12247 g_assert (target_accessible != NULL);
12249 relation_type = atk_relation_type_for_name (relation->type);
12250 if (relation_type == ATK_RELATION_NULL)
12252 g_warning ("<relation> type %s not found",
12256 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12257 target_accessible);
12259 g_object_unref (relation_set);
12261 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12262 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12271 } AccessibilitySubParserData;
12274 accessibility_start_element (GMarkupParseContext *context,
12275 const gchar *element_name,
12276 const gchar **names,
12277 const gchar **values,
12278 gpointer user_data,
12281 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12283 gint line_number, char_number;
12285 if (strcmp (element_name, "relation") == 0)
12287 gchar *target = NULL;
12288 gchar *type = NULL;
12289 AtkRelationData *relation;
12291 for (i = 0; names[i]; i++)
12293 if (strcmp (names[i], "target") == 0)
12294 target = g_strdup (values[i]);
12295 else if (strcmp (names[i], "type") == 0)
12296 type = g_strdup (values[i]);
12299 g_markup_parse_context_get_position (context,
12302 g_set_error (error,
12304 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12305 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12307 line_number, char_number, names[i], "relation");
12314 if (!target || !type)
12316 g_markup_parse_context_get_position (context,
12319 g_set_error (error,
12321 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12322 "%s:%d:%d <%s> requires attribute \"%s\"",
12324 line_number, char_number, "relation",
12325 type ? "target" : "type");
12331 relation = g_slice_new (AtkRelationData);
12332 relation->target = target;
12333 relation->type = type;
12335 data->relations = g_slist_prepend (data->relations, relation);
12337 else if (strcmp (element_name, "action") == 0)
12339 const gchar *action_name = NULL;
12340 const gchar *description = NULL;
12341 const gchar *msg_context = NULL;
12342 gboolean translatable = FALSE;
12343 AtkActionData *action;
12345 for (i = 0; names[i]; i++)
12347 if (strcmp (names[i], "action_name") == 0)
12348 action_name = values[i];
12349 else if (strcmp (names[i], "description") == 0)
12350 description = values[i];
12351 else if (strcmp (names[i], "translatable") == 0)
12353 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12356 else if (strcmp (names[i], "comments") == 0)
12358 /* do nothing, comments are for translators */
12360 else if (strcmp (names[i], "context") == 0)
12361 msg_context = values[i];
12364 g_markup_parse_context_get_position (context,
12367 g_set_error (error,
12369 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12370 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12372 line_number, char_number, names[i], "action");
12379 g_markup_parse_context_get_position (context,
12382 g_set_error (error,
12384 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12385 "%s:%d:%d <%s> requires attribute \"%s\"",
12387 line_number, char_number, "action",
12392 action = g_slice_new (AtkActionData);
12393 action->action_name = g_strdup (action_name);
12394 action->description = g_string_new (description);
12395 action->context = g_strdup (msg_context);
12396 action->translatable = translatable;
12398 data->actions = g_slist_prepend (data->actions, action);
12400 else if (strcmp (element_name, "accessibility") == 0)
12403 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12407 accessibility_text (GMarkupParseContext *context,
12410 gpointer user_data,
12413 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12415 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12417 AtkActionData *action = data->actions->data;
12419 g_string_append_len (action->description, text, text_len);
12423 static const GMarkupParser accessibility_parser =
12425 accessibility_start_element,
12427 accessibility_text,
12436 } AccelGroupParserData;
12439 accel_group_start_element (GMarkupParseContext *context,
12440 const gchar *element_name,
12441 const gchar **names,
12442 const gchar **values,
12443 gpointer user_data,
12448 guint modifiers = 0;
12449 gchar *signal = NULL;
12450 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12452 for (i = 0; names[i]; i++)
12454 if (strcmp (names[i], "key") == 0)
12455 key = gdk_keyval_from_name (values[i]);
12456 else if (strcmp (names[i], "modifiers") == 0)
12458 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12464 else if (strcmp (names[i], "signal") == 0)
12465 signal = g_strdup (values[i]);
12468 if (key == 0 || signal == NULL)
12470 g_warning ("<accelerator> requires key and signal attributes");
12473 parser_data->key = key;
12474 parser_data->modifiers = modifiers;
12475 parser_data->signal = signal;
12478 static const GMarkupParser accel_group_parser =
12480 accel_group_start_element,
12489 style_start_element (GMarkupParseContext *context,
12490 const gchar *element_name,
12491 const gchar **names,
12492 const gchar **values,
12493 gpointer user_data,
12496 StyleParserData *style_data = (StyleParserData *)user_data;
12499 if (strcmp (element_name, "class") == 0)
12501 if (g_markup_collect_attributes (element_name,
12505 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12506 G_MARKUP_COLLECT_INVALID))
12508 style_data->classes = g_slist_append (style_data->classes, class_name);
12511 else if (strcmp (element_name, "style") == 0)
12514 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12517 static const GMarkupParser style_parser =
12519 style_start_element,
12523 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12524 GtkBuilder *builder,
12526 const gchar *tagname,
12527 GMarkupParser *parser,
12530 g_assert (buildable);
12532 if (strcmp (tagname, "accelerator") == 0)
12534 AccelGroupParserData *parser_data;
12536 parser_data = g_slice_new0 (AccelGroupParserData);
12537 parser_data->object = g_object_ref (buildable);
12538 *parser = accel_group_parser;
12539 *data = parser_data;
12542 if (strcmp (tagname, "accessibility") == 0)
12544 AccessibilitySubParserData *parser_data;
12546 parser_data = g_slice_new0 (AccessibilitySubParserData);
12547 *parser = accessibility_parser;
12548 *data = parser_data;
12551 if (strcmp (tagname, "style") == 0)
12553 StyleParserData *parser_data;
12555 parser_data = g_slice_new0 (StyleParserData);
12556 *parser = style_parser;
12557 *data = parser_data;
12565 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12566 GtkWidget *toplevel,
12567 gpointer user_data)
12569 AccelGroupParserData *accel_data;
12570 GSList *accel_groups;
12571 GtkAccelGroup *accel_group;
12573 g_return_if_fail (GTK_IS_WIDGET (widget));
12574 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12575 g_return_if_fail (user_data != NULL);
12577 accel_data = (AccelGroupParserData*)user_data;
12578 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12579 if (g_slist_length (accel_groups) == 0)
12581 accel_group = gtk_accel_group_new ();
12582 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12586 g_assert (g_slist_length (accel_groups) == 1);
12587 accel_group = g_slist_nth_data (accel_groups, 0);
12590 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12591 accel_data->signal,
12594 accel_data->modifiers,
12595 GTK_ACCEL_VISIBLE);
12597 g_object_unref (accel_data->object);
12598 g_free (accel_data->signal);
12599 g_slice_free (AccelGroupParserData, accel_data);
12603 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12604 GtkBuilder *builder,
12606 const gchar *tagname,
12607 gpointer user_data)
12609 if (strcmp (tagname, "accelerator") == 0)
12611 AccelGroupParserData *accel_data;
12612 GtkWidget *toplevel;
12614 accel_data = (AccelGroupParserData*)user_data;
12615 g_assert (accel_data->object);
12617 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12619 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12621 else if (strcmp (tagname, "accessibility") == 0)
12623 AccessibilitySubParserData *a11y_data;
12625 a11y_data = (AccessibilitySubParserData*)user_data;
12627 if (a11y_data->actions)
12629 AtkObject *accessible;
12634 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12636 if (ATK_IS_ACTION (accessible))
12638 action = ATK_ACTION (accessible);
12639 n_actions = atk_action_get_n_actions (action);
12641 for (l = a11y_data->actions; l; l = l->next)
12643 AtkActionData *action_data = (AtkActionData*)l->data;
12645 for (i = 0; i < n_actions; i++)
12646 if (strcmp (atk_action_get_name (action, i),
12647 action_data->action_name) == 0)
12652 gchar *description;
12654 if (action_data->translatable && action_data->description->len)
12655 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12656 action_data->context,
12657 action_data->description->str);
12659 description = action_data->description->str;
12661 atk_action_set_description (action, i, description);
12666 g_warning ("accessibility action on a widget that does not implement AtkAction");
12668 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12671 if (a11y_data->relations)
12672 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12673 a11y_data->relations);
12675 g_slice_free (AccessibilitySubParserData, a11y_data);
12677 else if (strcmp (tagname, "style") == 0)
12679 StyleParserData *style_data = (StyleParserData *)user_data;
12680 GtkStyleContext *context;
12683 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12685 for (l = style_data->classes; l; l = l->next)
12686 gtk_style_context_add_class (context, (const gchar *)l->data);
12688 gtk_widget_reset_style (GTK_WIDGET (buildable));
12690 g_slist_free_full (style_data->classes, g_free);
12691 g_slice_free (StyleParserData, style_data);
12695 static GtkSizeRequestMode
12696 gtk_widget_real_get_request_mode (GtkWidget *widget)
12698 /* By default widgets dont trade size at all. */
12699 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12703 gtk_widget_real_get_width (GtkWidget *widget,
12704 gint *minimum_size,
12705 gint *natural_size)
12715 gtk_widget_real_get_height (GtkWidget *widget,
12716 gint *minimum_size,
12717 gint *natural_size)
12727 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12729 gint *minimum_height,
12730 gint *natural_height)
12732 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12736 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12738 gint *minimum_width,
12739 gint *natural_width)
12741 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12745 * gtk_widget_get_halign:
12746 * @widget: a #GtkWidget
12748 * Gets the value of the #GtkWidget:halign property.
12750 * Returns: the horizontal alignment of @widget
12753 gtk_widget_get_halign (GtkWidget *widget)
12755 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12756 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12760 * gtk_widget_set_halign:
12761 * @widget: a #GtkWidget
12762 * @align: the horizontal alignment
12764 * Sets the horizontal alignment of @widget.
12765 * See the #GtkWidget:halign property.
12768 gtk_widget_set_halign (GtkWidget *widget,
12771 GtkWidgetAuxInfo *aux_info;
12773 g_return_if_fail (GTK_IS_WIDGET (widget));
12775 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12777 if (aux_info->halign == align)
12780 aux_info->halign = align;
12781 gtk_widget_queue_resize (widget);
12782 g_object_notify (G_OBJECT (widget), "halign");
12786 * gtk_widget_get_valign:
12787 * @widget: a #GtkWidget
12789 * Gets the value of the #GtkWidget:valign property.
12791 * Returns: the vertical alignment of @widget
12794 gtk_widget_get_valign (GtkWidget *widget)
12796 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12797 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12801 * gtk_widget_set_valign:
12802 * @widget: a #GtkWidget
12803 * @align: the vertical alignment
12805 * Sets the vertical alignment of @widget.
12806 * See the #GtkWidget:valign property.
12809 gtk_widget_set_valign (GtkWidget *widget,
12812 GtkWidgetAuxInfo *aux_info;
12814 g_return_if_fail (GTK_IS_WIDGET (widget));
12816 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12818 if (aux_info->valign == align)
12821 aux_info->valign = align;
12822 gtk_widget_queue_resize (widget);
12823 g_object_notify (G_OBJECT (widget), "valign");
12827 * gtk_widget_get_margin_left:
12828 * @widget: a #GtkWidget
12830 * Gets the value of the #GtkWidget:margin-left property.
12832 * Returns: The left margin of @widget
12837 gtk_widget_get_margin_left (GtkWidget *widget)
12839 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12841 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12845 * gtk_widget_set_margin_left:
12846 * @widget: a #GtkWidget
12847 * @margin: the left margin
12849 * Sets the left margin of @widget.
12850 * See the #GtkWidget:margin-left property.
12855 gtk_widget_set_margin_left (GtkWidget *widget,
12858 GtkWidgetAuxInfo *aux_info;
12860 g_return_if_fail (GTK_IS_WIDGET (widget));
12861 g_return_if_fail (margin <= G_MAXINT16);
12863 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12865 if (aux_info->margin.left == margin)
12868 aux_info->margin.left = margin;
12869 gtk_widget_queue_resize (widget);
12870 g_object_notify (G_OBJECT (widget), "margin-left");
12874 * gtk_widget_get_margin_right:
12875 * @widget: a #GtkWidget
12877 * Gets the value of the #GtkWidget:margin-right property.
12879 * Returns: The right margin of @widget
12884 gtk_widget_get_margin_right (GtkWidget *widget)
12886 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12888 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12892 * gtk_widget_set_margin_right:
12893 * @widget: a #GtkWidget
12894 * @margin: the right margin
12896 * Sets the right margin of @widget.
12897 * See the #GtkWidget:margin-right property.
12902 gtk_widget_set_margin_right (GtkWidget *widget,
12905 GtkWidgetAuxInfo *aux_info;
12907 g_return_if_fail (GTK_IS_WIDGET (widget));
12908 g_return_if_fail (margin <= G_MAXINT16);
12910 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12912 if (aux_info->margin.right == margin)
12915 aux_info->margin.right = margin;
12916 gtk_widget_queue_resize (widget);
12917 g_object_notify (G_OBJECT (widget), "margin-right");
12921 * gtk_widget_get_margin_top:
12922 * @widget: a #GtkWidget
12924 * Gets the value of the #GtkWidget:margin-top property.
12926 * Returns: The top margin of @widget
12931 gtk_widget_get_margin_top (GtkWidget *widget)
12933 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12935 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12939 * gtk_widget_set_margin_top:
12940 * @widget: a #GtkWidget
12941 * @margin: the top margin
12943 * Sets the top margin of @widget.
12944 * See the #GtkWidget:margin-top property.
12949 gtk_widget_set_margin_top (GtkWidget *widget,
12952 GtkWidgetAuxInfo *aux_info;
12954 g_return_if_fail (GTK_IS_WIDGET (widget));
12955 g_return_if_fail (margin <= G_MAXINT16);
12957 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12959 if (aux_info->margin.top == margin)
12962 aux_info->margin.top = margin;
12963 gtk_widget_queue_resize (widget);
12964 g_object_notify (G_OBJECT (widget), "margin-top");
12968 * gtk_widget_get_margin_bottom:
12969 * @widget: a #GtkWidget
12971 * Gets the value of the #GtkWidget:margin-bottom property.
12973 * Returns: The bottom margin of @widget
12978 gtk_widget_get_margin_bottom (GtkWidget *widget)
12980 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12982 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12986 * gtk_widget_set_margin_bottom:
12987 * @widget: a #GtkWidget
12988 * @margin: the bottom margin
12990 * Sets the bottom margin of @widget.
12991 * See the #GtkWidget:margin-bottom property.
12996 gtk_widget_set_margin_bottom (GtkWidget *widget,
12999 GtkWidgetAuxInfo *aux_info;
13001 g_return_if_fail (GTK_IS_WIDGET (widget));
13002 g_return_if_fail (margin <= G_MAXINT16);
13004 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13006 if (aux_info->margin.bottom == margin)
13009 aux_info->margin.bottom = margin;
13010 gtk_widget_queue_resize (widget);
13011 g_object_notify (G_OBJECT (widget), "margin-bottom");
13015 * gtk_widget_get_clipboard:
13016 * @widget: a #GtkWidget
13017 * @selection: a #GdkAtom which identifies the clipboard
13018 * to use. %GDK_SELECTION_CLIPBOARD gives the
13019 * default clipboard. Another common value
13020 * is %GDK_SELECTION_PRIMARY, which gives
13021 * the primary X selection.
13023 * Returns the clipboard object for the given selection to
13024 * be used with @widget. @widget must have a #GdkDisplay
13025 * associated with it, so must be attached to a toplevel
13028 * Return value: (transfer none): the appropriate clipboard object. If no
13029 * clipboard already exists, a new one will
13030 * be created. Once a clipboard object has
13031 * been created, it is persistent for all time.
13036 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13038 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13039 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13041 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13046 * gtk_widget_list_mnemonic_labels:
13047 * @widget: a #GtkWidget
13049 * Returns a newly allocated list of the widgets, normally labels, for
13050 * which this widget is the target of a mnemonic (see for example,
13051 * gtk_label_set_mnemonic_widget()).
13053 * The widgets in the list are not individually referenced. If you
13054 * want to iterate through the list and perform actions involving
13055 * callbacks that might destroy the widgets, you
13056 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13057 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13058 * widgets afterwards.
13060 * Return value: (element-type GtkWidget) (transfer container): the list of
13061 * mnemonic labels; free this list
13062 * with g_list_free() when you are done with it.
13067 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13069 GList *list = NULL;
13072 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13074 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13075 list = g_list_prepend (list, l->data);
13081 * gtk_widget_add_mnemonic_label:
13082 * @widget: a #GtkWidget
13083 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13085 * Adds a widget to the list of mnemonic labels for
13086 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13087 * list of mnemonic labels for the widget is cleared when the
13088 * widget is destroyed, so the caller must make sure to update
13089 * its internal state at this point as well, by using a connection
13090 * to the #GtkWidget::destroy signal or a weak notifier.
13095 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13098 GSList *old_list, *new_list;
13100 g_return_if_fail (GTK_IS_WIDGET (widget));
13101 g_return_if_fail (GTK_IS_WIDGET (label));
13103 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13104 new_list = g_slist_prepend (old_list, label);
13106 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13107 new_list, (GDestroyNotify) g_slist_free);
13111 * gtk_widget_remove_mnemonic_label:
13112 * @widget: a #GtkWidget
13113 * @label: a #GtkWidget that was previously set as a mnemnic label for
13114 * @widget with gtk_widget_add_mnemonic_label().
13116 * Removes a widget from the list of mnemonic labels for
13117 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13118 * must have previously been added to the list with
13119 * gtk_widget_add_mnemonic_label().
13124 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13127 GSList *old_list, *new_list;
13129 g_return_if_fail (GTK_IS_WIDGET (widget));
13130 g_return_if_fail (GTK_IS_WIDGET (label));
13132 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13133 new_list = g_slist_remove (old_list, label);
13136 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13137 new_list, (GDestroyNotify) g_slist_free);
13141 * gtk_widget_get_no_show_all:
13142 * @widget: a #GtkWidget
13144 * Returns the current value of the #GtkWidget:no-show-all property,
13145 * which determines whether calls to gtk_widget_show_all()
13146 * will affect this widget.
13148 * Return value: the current value of the "no-show-all" property.
13153 gtk_widget_get_no_show_all (GtkWidget *widget)
13155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13157 return widget->priv->no_show_all;
13161 * gtk_widget_set_no_show_all:
13162 * @widget: a #GtkWidget
13163 * @no_show_all: the new value for the "no-show-all" property
13165 * Sets the #GtkWidget:no-show-all property, which determines whether
13166 * calls to gtk_widget_show_all() will affect this widget.
13168 * This is mostly for use in constructing widget hierarchies with externally
13169 * controlled visibility, see #GtkUIManager.
13174 gtk_widget_set_no_show_all (GtkWidget *widget,
13175 gboolean no_show_all)
13177 g_return_if_fail (GTK_IS_WIDGET (widget));
13179 no_show_all = (no_show_all != FALSE);
13181 if (widget->priv->no_show_all != no_show_all)
13183 widget->priv->no_show_all = no_show_all;
13185 g_object_notify (G_OBJECT (widget), "no-show-all");
13191 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13192 gboolean has_tooltip,
13195 GtkWidgetPrivate *priv = widget->priv;
13196 gboolean priv_has_tooltip;
13198 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13199 quark_has_tooltip));
13201 if (priv_has_tooltip != has_tooltip || force)
13203 priv_has_tooltip = has_tooltip;
13205 if (priv_has_tooltip)
13207 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13208 gdk_window_set_events (priv->window,
13209 gdk_window_get_events (priv->window) |
13210 GDK_LEAVE_NOTIFY_MASK |
13211 GDK_POINTER_MOTION_MASK |
13212 GDK_POINTER_MOTION_HINT_MASK);
13214 if (gtk_widget_get_has_window (widget))
13215 gtk_widget_add_events (widget,
13216 GDK_LEAVE_NOTIFY_MASK |
13217 GDK_POINTER_MOTION_MASK |
13218 GDK_POINTER_MOTION_HINT_MASK);
13221 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13222 GUINT_TO_POINTER (priv_has_tooltip));
13227 * gtk_widget_set_tooltip_window:
13228 * @widget: a #GtkWidget
13229 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13231 * Replaces the default, usually yellow, window used for displaying
13232 * tooltips with @custom_window. GTK+ will take care of showing and
13233 * hiding @custom_window at the right moment, to behave likewise as
13234 * the default tooltip window. If @custom_window is %NULL, the default
13235 * tooltip window will be used.
13237 * If the custom window should have the default theming it needs to
13238 * have the name "gtk-tooltip", see gtk_widget_set_name().
13243 gtk_widget_set_tooltip_window (GtkWidget *widget,
13244 GtkWindow *custom_window)
13246 gboolean has_tooltip;
13247 gchar *tooltip_markup;
13249 g_return_if_fail (GTK_IS_WIDGET (widget));
13250 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13252 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13255 g_object_ref (custom_window);
13257 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13258 custom_window, g_object_unref);
13260 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13261 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13263 if (has_tooltip && gtk_widget_get_visible (widget))
13264 gtk_widget_queue_tooltip_query (widget);
13268 * gtk_widget_get_tooltip_window:
13269 * @widget: a #GtkWidget
13271 * Returns the #GtkWindow of the current tooltip. This can be the
13272 * GtkWindow created by default, or the custom tooltip window set
13273 * using gtk_widget_set_tooltip_window().
13275 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13280 gtk_widget_get_tooltip_window (GtkWidget *widget)
13282 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13284 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13288 * gtk_widget_trigger_tooltip_query:
13289 * @widget: a #GtkWidget
13291 * Triggers a tooltip query on the display where the toplevel of @widget
13292 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13298 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13300 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13303 static guint tooltip_query_id;
13304 static GSList *tooltip_query_displays;
13307 tooltip_query_idle (gpointer data)
13309 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13310 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13311 g_slist_free (tooltip_query_displays);
13313 tooltip_query_displays = NULL;
13314 tooltip_query_id = 0;
13320 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13322 GdkDisplay *display;
13324 display = gtk_widget_get_display (widget);
13326 if (!g_slist_find (tooltip_query_displays, display))
13327 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13329 if (tooltip_query_id == 0)
13330 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13334 * gtk_widget_set_tooltip_text:
13335 * @widget: a #GtkWidget
13336 * @text: (allow-none): the contents of the tooltip for @widget
13338 * Sets @text as the contents of the tooltip. This function will take
13339 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13340 * handler for the #GtkWidget::query-tooltip signal.
13342 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13347 gtk_widget_set_tooltip_text (GtkWidget *widget,
13350 g_return_if_fail (GTK_IS_WIDGET (widget));
13352 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13356 * gtk_widget_get_tooltip_text:
13357 * @widget: a #GtkWidget
13359 * Gets the contents of the tooltip for @widget.
13361 * Return value: the tooltip text, or %NULL. You should free the
13362 * returned string with g_free() when done.
13367 gtk_widget_get_tooltip_text (GtkWidget *widget)
13369 gchar *text = NULL;
13371 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13373 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13379 * gtk_widget_set_tooltip_markup:
13380 * @widget: a #GtkWidget
13381 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13383 * Sets @markup as the contents of the tooltip, which is marked up with
13384 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13386 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13387 * and of the default handler for the #GtkWidget::query-tooltip signal.
13389 * See also the #GtkWidget:tooltip-markup property and
13390 * gtk_tooltip_set_markup().
13395 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13396 const gchar *markup)
13398 g_return_if_fail (GTK_IS_WIDGET (widget));
13400 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13404 * gtk_widget_get_tooltip_markup:
13405 * @widget: a #GtkWidget
13407 * Gets the contents of the tooltip for @widget.
13409 * Return value: the tooltip text, or %NULL. You should free the
13410 * returned string with g_free() when done.
13415 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13417 gchar *text = NULL;
13419 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13421 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13427 * gtk_widget_set_has_tooltip:
13428 * @widget: a #GtkWidget
13429 * @has_tooltip: whether or not @widget has a tooltip.
13431 * Sets the has-tooltip property on @widget to @has_tooltip. See
13432 * #GtkWidget:has-tooltip for more information.
13437 gtk_widget_set_has_tooltip (GtkWidget *widget,
13438 gboolean has_tooltip)
13440 g_return_if_fail (GTK_IS_WIDGET (widget));
13442 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13446 * gtk_widget_get_has_tooltip:
13447 * @widget: a #GtkWidget
13449 * Returns the current value of the has-tooltip property. See
13450 * #GtkWidget:has-tooltip for more information.
13452 * Return value: current value of has-tooltip on @widget.
13457 gtk_widget_get_has_tooltip (GtkWidget *widget)
13459 gboolean has_tooltip = FALSE;
13461 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13463 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13465 return has_tooltip;
13469 * gtk_widget_get_allocation:
13470 * @widget: a #GtkWidget
13471 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13473 * Retrieves the widget's allocation.
13475 * Note, when implementing a #GtkContainer: a widget's allocation will
13476 * be its "adjusted" allocation, that is, the widget's parent
13477 * container typically calls gtk_widget_size_allocate() with an
13478 * allocation, and that allocation is then adjusted (to handle margin
13479 * and alignment for example) before assignment to the widget.
13480 * gtk_widget_get_allocation() returns the adjusted allocation that
13481 * was actually assigned to the widget. The adjusted allocation is
13482 * guaranteed to be completely contained within the
13483 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13484 * is guaranteed that its children stay inside the assigned bounds,
13485 * but not that they have exactly the bounds the container assigned.
13486 * There is no way to get the original allocation assigned by
13487 * gtk_widget_size_allocate(), since it isn't stored; if a container
13488 * implementation needs that information it will have to track it itself.
13493 gtk_widget_get_allocation (GtkWidget *widget,
13494 GtkAllocation *allocation)
13496 GtkWidgetPrivate *priv;
13498 g_return_if_fail (GTK_IS_WIDGET (widget));
13499 g_return_if_fail (allocation != NULL);
13501 priv = widget->priv;
13503 *allocation = priv->allocation;
13507 * gtk_widget_set_allocation:
13508 * @widget: a #GtkWidget
13509 * @allocation: a pointer to a #GtkAllocation to copy from
13511 * Sets the widget's allocation. This should not be used
13512 * directly, but from within a widget's size_allocate method.
13514 * The allocation set should be the "adjusted" or actual
13515 * allocation. If you're implementing a #GtkContainer, you want to use
13516 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13517 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13518 * allocation inside gtk_widget_size_allocate() to create an adjusted
13524 gtk_widget_set_allocation (GtkWidget *widget,
13525 const GtkAllocation *allocation)
13527 GtkWidgetPrivate *priv;
13529 g_return_if_fail (GTK_IS_WIDGET (widget));
13530 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13531 g_return_if_fail (allocation != NULL);
13533 priv = widget->priv;
13535 priv->allocation = *allocation;
13539 * gtk_widget_get_allocated_width:
13540 * @widget: the widget to query
13542 * Returns the width that has currently been allocated to @widget.
13543 * This function is intended to be used when implementing handlers
13544 * for the #GtkWidget::draw function.
13546 * Returns: the width of the @widget
13549 gtk_widget_get_allocated_width (GtkWidget *widget)
13551 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13553 return widget->priv->allocation.width;
13557 * gtk_widget_get_allocated_height:
13558 * @widget: the widget to query
13560 * Returns the height that has currently been allocated to @widget.
13561 * This function is intended to be used when implementing handlers
13562 * for the #GtkWidget::draw function.
13564 * Returns: the height of the @widget
13567 gtk_widget_get_allocated_height (GtkWidget *widget)
13569 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13571 return widget->priv->allocation.height;
13575 * gtk_widget_get_requisition:
13576 * @widget: a #GtkWidget
13577 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13579 * Retrieves the widget's requisition.
13581 * This function should only be used by widget implementations in
13582 * order to figure whether the widget's requisition has actually
13583 * changed after some internal state change (so that they can call
13584 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13586 * Normally, gtk_widget_size_request() should be used.
13590 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13591 * removed, If you need to cache sizes across requests and allocations,
13592 * add an explicit cache to the widget in question instead.
13595 gtk_widget_get_requisition (GtkWidget *widget,
13596 GtkRequisition *requisition)
13598 g_return_if_fail (GTK_IS_WIDGET (widget));
13599 g_return_if_fail (requisition != NULL);
13601 gtk_widget_get_preferred_size (widget, requisition, NULL);
13605 * gtk_widget_set_window:
13606 * @widget: a #GtkWidget
13607 * @window: (transfer full): a #GdkWindow
13609 * Sets a widget's window. This function should only be used in a
13610 * widget's #GtkWidget::realize implementation. The %window passed is
13611 * usually either new window created with gdk_window_new(), or the
13612 * window of its parent widget as returned by
13613 * gtk_widget_get_parent_window().
13615 * Widgets must indicate whether they will create their own #GdkWindow
13616 * by calling gtk_widget_set_has_window(). This is usually done in the
13617 * widget's init() function.
13619 * <note><para>This function does not add any reference to @window.</para></note>
13624 gtk_widget_set_window (GtkWidget *widget,
13627 GtkWidgetPrivate *priv;
13629 g_return_if_fail (GTK_IS_WIDGET (widget));
13630 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13632 priv = widget->priv;
13634 if (priv->window != window)
13636 priv->window = window;
13637 g_object_notify (G_OBJECT (widget), "window");
13642 * gtk_widget_register_window:
13643 * @widget: a #GtkWidget
13644 * @window: a #GdkWindow
13646 * Registers a #GdkWindow with the widget and sets it up so that
13647 * the widget recieves events for it. Call gtk_widget_unregister_window()
13648 * when destroying the window.
13650 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13651 * this up. This is now deprecated and you should use gtk_widget_register_window()
13652 * instead. Old code will keep working as is, although some new features like
13653 * transparency might not work perfectly.
13658 gtk_widget_register_window (GtkWidget *widget,
13661 GtkWidgetPrivate *priv;
13662 gpointer user_data;
13664 g_return_if_fail (GTK_IS_WIDGET (widget));
13665 g_return_if_fail (GDK_IS_WINDOW (window));
13667 gdk_window_get_user_data (window, &user_data);
13668 g_assert (user_data == NULL);
13670 priv = widget->priv;
13672 gdk_window_set_user_data (window, widget);
13673 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13677 * gtk_widget_unregister_window:
13678 * @widget: a #GtkWidget
13679 * @window: a #GdkWindow
13681 * Unregisters a #GdkWindow from the widget that was previously set up with
13682 * gtk_widget_register_window(). You need to call this when the window is
13683 * no longer used by the widget, such as when you destroy it.
13688 gtk_widget_unregister_window (GtkWidget *widget,
13691 GtkWidgetPrivate *priv;
13692 gpointer user_data;
13694 g_return_if_fail (GTK_IS_WIDGET (widget));
13695 g_return_if_fail (GDK_IS_WINDOW (window));
13697 priv = widget->priv;
13699 gdk_window_get_user_data (window, &user_data);
13700 g_assert (user_data == widget);
13701 gdk_window_set_user_data (window, NULL);
13702 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13706 * gtk_widget_get_window:
13707 * @widget: a #GtkWidget
13709 * Returns the widget's window if it is realized, %NULL otherwise
13711 * Return value: (transfer none): @widget's window.
13716 gtk_widget_get_window (GtkWidget *widget)
13718 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13720 return widget->priv->window;
13724 * gtk_widget_get_support_multidevice:
13725 * @widget: a #GtkWidget
13727 * Returns %TRUE if @widget is multiple pointer aware. See
13728 * gtk_widget_set_support_multidevice() for more information.
13730 * Returns: %TRUE if @widget is multidevice aware.
13733 gtk_widget_get_support_multidevice (GtkWidget *widget)
13735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13737 return widget->priv->multidevice;
13741 * gtk_widget_set_support_multidevice:
13742 * @widget: a #GtkWidget
13743 * @support_multidevice: %TRUE to support input from multiple devices.
13745 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13746 * @widget will start receiving multiple, per device enter/leave events. Note
13747 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13748 * gdk_window_set_support_multidevice() will have to be called manually on them.
13753 gtk_widget_set_support_multidevice (GtkWidget *widget,
13754 gboolean support_multidevice)
13756 GtkWidgetPrivate *priv;
13758 g_return_if_fail (GTK_IS_WIDGET (widget));
13760 priv = widget->priv;
13761 priv->multidevice = (support_multidevice == TRUE);
13763 if (gtk_widget_get_realized (widget))
13764 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13768 _gtk_widget_set_has_focus (GtkWidget *widget,
13769 gboolean has_focus)
13771 widget->priv->has_focus = has_focus;
13774 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13776 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13780 * gtk_widget_send_focus_change:
13781 * @widget: a #GtkWidget
13782 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13784 * Sends the focus change @event to @widget
13786 * This function is not meant to be used by applications. The only time it
13787 * should be used is when it is necessary for a #GtkWidget to assign focus
13788 * to a widget that is semantically owned by the first widget even though
13789 * it's not a direct child - for instance, a search entry in a floating
13790 * window similar to the quick search in #GtkTreeView.
13792 * An example of its usage is:
13795 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13797 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13798 * fevent->focus_change.in = TRUE;
13799 * fevent->focus_change.window = gtk_widget_get_window (widget);
13800 * if (fevent->focus_change.window != NULL)
13801 * g_object_ref (fevent->focus_change.window);
13803 * gtk_widget_send_focus_change (widget, fevent);
13805 * gdk_event_free (event);
13808 * Return value: the return value from the event signal emission: %TRUE
13809 * if the event was handled, and %FALSE otherwise
13814 gtk_widget_send_focus_change (GtkWidget *widget,
13819 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13820 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13822 g_object_ref (widget);
13824 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13826 res = gtk_widget_event (widget, event);
13828 g_object_notify (G_OBJECT (widget), "has-focus");
13830 g_object_unref (widget);
13836 * gtk_widget_in_destruction:
13837 * @widget: a #GtkWidget
13839 * Returns whether the widget is currently being destroyed.
13840 * This information can sometimes be used to avoid doing
13841 * unnecessary work.
13843 * Returns: %TRUE if @widget is being destroyed
13846 gtk_widget_in_destruction (GtkWidget *widget)
13848 return widget->priv->in_destruction;
13852 _gtk_widget_get_in_reparent (GtkWidget *widget)
13854 return widget->priv->in_reparent;
13858 _gtk_widget_set_in_reparent (GtkWidget *widget,
13859 gboolean in_reparent)
13861 widget->priv->in_reparent = in_reparent;
13865 _gtk_widget_get_anchored (GtkWidget *widget)
13867 return widget->priv->anchored;
13871 _gtk_widget_set_anchored (GtkWidget *widget,
13874 widget->priv->anchored = anchored;
13878 _gtk_widget_get_shadowed (GtkWidget *widget)
13880 return widget->priv->shadowed;
13884 _gtk_widget_set_shadowed (GtkWidget *widget,
13887 widget->priv->shadowed = shadowed;
13891 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13893 return widget->priv->alloc_needed;
13897 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13898 gboolean alloc_needed)
13900 widget->priv->alloc_needed = alloc_needed;
13904 _gtk_widget_add_sizegroup (GtkWidget *widget,
13909 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13910 groups = g_slist_prepend (groups, group);
13911 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13913 widget->priv->have_size_groups = TRUE;
13917 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13922 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13923 groups = g_slist_remove (groups, group);
13924 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13926 widget->priv->have_size_groups = groups != NULL;
13930 _gtk_widget_get_sizegroups (GtkWidget *widget)
13932 if (widget->priv->have_size_groups)
13933 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13939 _gtk_widget_add_attached_window (GtkWidget *widget,
13942 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
13946 _gtk_widget_remove_attached_window (GtkWidget *widget,
13949 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
13953 * gtk_widget_path_append_for_widget:
13954 * @path: a widget path
13955 * @widget: the widget to append to the widget path
13957 * Appends the data from @widget to the widget hierarchy represented
13958 * by @path. This function is a shortcut for adding information from
13959 * @widget to the given @path. This includes setting the name or
13960 * adding the style classes from @widget.
13962 * Returns: the position where the data was inserted
13967 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13972 g_return_val_if_fail (path != NULL, 0);
13973 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13975 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13977 if (widget->priv->name)
13978 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13980 if (widget->priv->context)
13982 GList *classes, *l;
13984 /* Also add any persistent classes in
13985 * the style context the widget path
13987 classes = gtk_style_context_list_classes (widget->priv->context);
13989 for (l = classes; l; l = l->next)
13990 gtk_widget_path_iter_add_class (path, pos, l->data);
13992 g_list_free (classes);
13999 _gtk_widget_create_path (GtkWidget *widget)
14003 parent = widget->priv->parent;
14006 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14009 /* Widget is either toplevel or unparented, treat both
14010 * as toplevels style wise, since there are situations
14011 * where style properties might be retrieved on that
14014 GtkWidget *attach_widget = NULL;
14015 GtkWidgetPath *result;
14017 if (GTK_IS_WINDOW (widget))
14018 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14020 if (attach_widget != NULL)
14021 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14023 result = gtk_widget_path_new ();
14025 gtk_widget_path_append_for_widget (result, widget);
14032 * gtk_widget_get_path:
14033 * @widget: a #GtkWidget
14035 * Returns the #GtkWidgetPath representing @widget, if the widget
14036 * is not connected to a toplevel widget, a partial path will be
14039 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14042 gtk_widget_get_path (GtkWidget *widget)
14044 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14046 if (!widget->priv->path)
14047 widget->priv->path = _gtk_widget_create_path (widget);
14049 return widget->priv->path;
14053 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14055 if (widget->priv->path)
14057 gtk_widget_path_free (widget->priv->path);
14058 widget->priv->path = NULL;
14061 if (gtk_widget_get_realized (widget))
14062 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14065 /* Compress all style updates so it
14066 * is only emitted once pre-realize.
14068 widget->priv->style_update_pending = TRUE;
14073 * gtk_widget_get_style_context:
14074 * @widget: a #GtkWidget
14076 * Returns the style context associated to @widget.
14078 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14079 * must not be freed.
14082 gtk_widget_get_style_context (GtkWidget *widget)
14084 GtkWidgetPrivate *priv;
14086 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14088 priv = widget->priv;
14090 if (G_UNLIKELY (priv->context == NULL))
14094 priv->context = gtk_style_context_new ();
14096 gtk_style_context_set_state (priv->context, priv->state_flags);
14098 screen = gtk_widget_get_screen (widget);
14100 gtk_style_context_set_screen (priv->context, screen);
14103 gtk_style_context_set_parent (priv->context,
14104 gtk_widget_get_style_context (priv->parent));
14106 _gtk_style_context_set_widget (priv->context, widget);
14109 return widget->priv->context;
14113 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14114 GtkCssChange change)
14116 GtkWidgetPrivate *priv;
14118 priv = widget->priv;
14120 if (priv->context == NULL)
14123 _gtk_style_context_queue_invalidate (priv->context, change);
14127 * gtk_widget_get_modifier_mask:
14128 * @widget: a #GtkWidget
14129 * @intent: the use case for the modifier mask
14131 * Returns the modifier mask the @widget's windowing system backend
14132 * uses for a particular purpose.
14134 * See gdk_keymap_get_modifier_mask().
14136 * Returns: the modifier mask used for @intent.
14141 gtk_widget_get_modifier_mask (GtkWidget *widget,
14142 GdkModifierIntent intent)
14144 GdkDisplay *display;
14146 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14148 display = gtk_widget_get_display (widget);
14150 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14155 _gtk_widget_get_style (GtkWidget *widget)
14157 return widget->priv->style;
14161 _gtk_widget_set_style (GtkWidget *widget,
14164 widget->priv->style = style;
14168 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14171 GActionMuxer *parent_muxer;
14173 if (widget->priv->muxer == NULL)
14176 if (GTK_IS_MENU (widget))
14177 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14179 parent = gtk_widget_get_parent (widget);
14181 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14183 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14187 _gtk_widget_get_action_muxer (GtkWidget *widget)
14189 if (widget->priv->muxer == NULL)
14191 widget->priv->muxer = g_action_muxer_new ();
14192 _gtk_widget_update_parent_muxer (widget);
14195 return widget->priv->muxer;
14199 * gtk_widget_insert_action_group:
14200 * @widget: a #GtkWidget
14201 * @name: the prefix for actions in @group
14202 * @group: a #GActionGroup
14204 * Inserts @group into @widget. Children of @widget that implement
14205 * #GtkActionable can then be associated with actions in @group by
14206 * setting their 'action-name' to
14207 * @prefix.<replaceable>action-name</replaceable>.
14212 gtk_widget_insert_action_group (GtkWidget *widget,
14214 GActionGroup *group)
14216 GActionMuxer *muxer;
14218 g_return_if_fail (GTK_IS_WIDGET (widget));
14219 g_return_if_fail (name != NULL);
14221 muxer = _gtk_widget_get_action_muxer (widget);
14224 g_action_muxer_insert (muxer, name, group);
14226 g_action_muxer_remove (muxer, name);