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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include <gobject/gvaluecollector.h>
34 #include <gobject/gobjectnotifyqueue.c>
35 #include <cairo-gobject.h>
37 #include "gtkcontainer.h"
38 #include "gtkaccelmapprivate.h"
39 #include "gtkclipboard.h"
40 #include "gtkiconfactory.h"
42 #include "gtkmarshalers.h"
43 #include "gtkselectionprivate.h"
44 #include "gtksettingsprivate.h"
45 #include "gtksizegroup-private.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 "gtksymboliccolor.h"
60 #include "gtkcssprovider.h"
61 #include "gtkanimationdescription.h"
62 #include "gtkmodifierstyle.h"
63 #include "gtkversion.h"
66 #include "gtktypebuiltins.h"
67 #include "a11y/gtkwidgetaccessible.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_widget_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="AtkObject::name">Clickable Button</property>
281 * ]]></programlisting>
284 * Finally, GtkWidget allows style information such as style classes to
285 * be associated with widgets, using the custom <style> element:
287 * <title>A UI definition fragment specifying an style class</title>
288 * <programlisting><![CDATA[
289 * <object class="GtkButton" id="button1">
291 * <class name="my-special-button-class"/>
292 * <class name="dark-button"/>
295 * ]]></programlisting>
301 /* Add flags here that should not be propagated to children. By default,
302 * all flags will be set on children (think prelight or active), but we
303 * might want to not do this for some.
305 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED)
306 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
308 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
310 #define GTK_STATE_FLAGS_BITS 7
312 struct _GtkWidgetPrivate
314 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
315 * (defined in "gtkenums.h").
317 guint state_flags : GTK_STATE_FLAGS_BITS;
321 guint in_destruction : 1;
324 guint composite_child : 1;
332 guint can_default : 1;
333 guint has_default : 1;
334 guint receives_default : 1;
337 guint style_update_pending : 1;
338 guint app_paintable : 1;
339 guint double_buffered : 1;
340 guint redraw_on_alloc : 1;
341 guint no_show_all : 1;
342 guint child_visible : 1;
343 guint multidevice : 1;
344 guint has_shape_mask : 1;
345 guint in_reparent : 1;
347 /* Queue-resize related flags */
348 guint resize_pending : 1;
349 guint alloc_needed : 1;
350 guint width_request_needed : 1;
351 guint height_request_needed : 1;
353 /* Expand-related flags */
354 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
355 guint computed_hexpand : 1; /* computed results (composite of child flags) */
356 guint computed_vexpand : 1;
357 guint hexpand : 1; /* application-forced expand */
359 guint hexpand_set : 1; /* whether to use application-forced */
360 guint vexpand_set : 1; /* instead of computing from children */
362 /* SizeGroup related flags */
363 guint sizegroup_visited : 1;
364 guint sizegroup_bumping : 1;
365 guint have_size_groups : 1;
367 /* The widget's name. If the widget does not have a name
368 * (the name is NULL), then its name (as returned by
369 * "gtk_widget_get_name") is its class's name.
370 * Among other things, the widget name is used to determine
371 * the style to use for a widget.
375 /* The style for the widget. The style contains the
376 * colors the widget should be drawn in for each state
377 * along with graphics contexts used to draw with and
378 * the font to use for text.
381 GtkStyleContext *context;
383 /* Widget's path for styling */
386 /* The widget's allocated size */
387 GtkAllocation allocation;
389 /* The widget's requested sizes */
390 SizeRequestCache requests;
392 /* The widget's window or its parent window if it does
393 * not have a window. (Which will be indicated by the
394 * GTK_NO_WINDOW flag being set).
398 /* The widget's parent */
401 #ifdef G_ENABLE_DEBUG
402 /* Number of gtk_widget_push_verify_invariants () */
403 guint verifying_invariants_count;
404 #endif /* G_ENABLE_DEBUG */
407 struct _GtkWidgetClassPrivate
409 GType accessible_type;
410 AtkRole accessible_role;
439 BUTTON_RELEASE_EVENT,
453 PROPERTY_NOTIFY_EVENT,
454 SELECTION_CLEAR_EVENT,
455 SELECTION_REQUEST_EVENT,
456 SELECTION_NOTIFY_EVENT,
461 VISIBILITY_NOTIFY_EVENT,
475 ACCEL_CLOSURES_CHANGED,
499 PROP_RECEIVES_DEFAULT,
500 PROP_COMPOSITE_CHILD,
508 PROP_DOUBLE_BUFFERED,
523 typedef struct _GtkStateData GtkStateData;
526 STATE_CHANGE_REPLACE,
533 guint flags : GTK_STATE_FLAGS_BITS;
537 /* --- prototypes --- */
538 static void gtk_widget_base_class_init (gpointer g_class);
539 static void gtk_widget_class_init (GtkWidgetClass *klass);
540 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
541 static void gtk_widget_init (GtkWidget *widget);
542 static void gtk_widget_set_property (GObject *object,
546 static void gtk_widget_get_property (GObject *object,
550 static void gtk_widget_dispose (GObject *object);
551 static void gtk_widget_real_destroy (GtkWidget *object);
552 static void gtk_widget_finalize (GObject *object);
553 static void gtk_widget_real_show (GtkWidget *widget);
554 static void gtk_widget_real_hide (GtkWidget *widget);
555 static void gtk_widget_real_map (GtkWidget *widget);
556 static void gtk_widget_real_unmap (GtkWidget *widget);
557 static void gtk_widget_real_realize (GtkWidget *widget);
558 static void gtk_widget_real_unrealize (GtkWidget *widget);
559 static void gtk_widget_real_size_allocate (GtkWidget *widget,
560 GtkAllocation *allocation);
561 static void gtk_widget_real_style_set (GtkWidget *widget,
562 GtkStyle *previous_style);
563 static void gtk_widget_real_direction_changed(GtkWidget *widget,
564 GtkTextDirection previous_direction);
566 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
567 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
570 gboolean keyboard_tip,
571 GtkTooltip *tooltip);
572 static void gtk_widget_real_style_updated (GtkWidget *widget);
573 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
574 GtkWidgetHelpType help_type);
576 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
578 GParamSpec **pspecs);
579 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
581 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
583 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
584 GdkEventFocus *event);
585 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
586 GdkEventFocus *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 void gtk_widget_queue_shallow_draw (GtkWidget *widget);
638 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
641 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
642 gboolean has_tooltip,
644 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
645 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
647 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
648 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
650 const gchar *childname);
651 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
654 const GValue *value);
655 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
658 const gchar *tagname,
659 GMarkupParser *parser,
661 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
664 const gchar *tagname,
666 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
667 GtkBuilder *builder);
669 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
670 static void gtk_widget_real_get_width (GtkWidget *widget,
673 static void gtk_widget_real_get_height (GtkWidget *widget,
677 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
680 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
681 GtkOrientation orientation,
684 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
685 GtkOrientation orientation,
689 gint *allocated_size);
691 static void gtk_widget_set_usize_internal (GtkWidget *widget,
694 GtkQueueResizeFlags flags);
696 static void gtk_widget_add_events_internal (GtkWidget *widget,
699 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
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_class_init (GtkWidgetClass *klass)
829 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
830 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
831 GtkBindingSet *binding_set;
833 gtk_widget_parent_class = g_type_class_peek_parent (klass);
835 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
836 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
837 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
838 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
839 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
840 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
841 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
842 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
843 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
844 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
845 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
846 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
847 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
848 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
849 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
850 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
851 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
852 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
853 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
854 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
856 style_property_spec_pool = g_param_spec_pool_new (FALSE);
857 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
858 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
859 cpn_context.dispatcher = child_property_notify_dispatcher;
860 _gtk_widget_child_property_notify_context = &cpn_context;
862 gobject_class->dispose = gtk_widget_dispose;
863 gobject_class->finalize = gtk_widget_finalize;
864 gobject_class->set_property = gtk_widget_set_property;
865 gobject_class->get_property = gtk_widget_get_property;
867 klass->destroy = gtk_widget_real_destroy;
869 klass->activate_signal = 0;
870 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
871 klass->show = gtk_widget_real_show;
872 klass->show_all = gtk_widget_show;
873 klass->hide = gtk_widget_real_hide;
874 klass->map = gtk_widget_real_map;
875 klass->unmap = gtk_widget_real_unmap;
876 klass->realize = gtk_widget_real_realize;
877 klass->unrealize = gtk_widget_real_unrealize;
878 klass->size_allocate = gtk_widget_real_size_allocate;
879 klass->get_request_mode = gtk_widget_real_get_request_mode;
880 klass->get_preferred_width = gtk_widget_real_get_width;
881 klass->get_preferred_height = gtk_widget_real_get_height;
882 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
883 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
884 klass->state_changed = NULL;
885 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
886 klass->parent_set = NULL;
887 klass->hierarchy_changed = NULL;
888 klass->style_set = gtk_widget_real_style_set;
889 klass->direction_changed = gtk_widget_real_direction_changed;
890 klass->grab_notify = NULL;
891 klass->child_notify = NULL;
893 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
894 klass->grab_focus = gtk_widget_real_grab_focus;
895 klass->focus = gtk_widget_real_focus;
896 klass->move_focus = gtk_widget_real_move_focus;
897 klass->keynav_failed = gtk_widget_real_keynav_failed;
899 klass->button_press_event = NULL;
900 klass->button_release_event = NULL;
901 klass->motion_notify_event = NULL;
902 klass->delete_event = NULL;
903 klass->destroy_event = NULL;
904 klass->key_press_event = gtk_widget_real_key_press_event;
905 klass->key_release_event = gtk_widget_real_key_release_event;
906 klass->enter_notify_event = NULL;
907 klass->leave_notify_event = NULL;
908 klass->configure_event = NULL;
909 klass->focus_in_event = gtk_widget_real_focus_in_event;
910 klass->focus_out_event = gtk_widget_real_focus_out_event;
911 klass->map_event = NULL;
912 klass->unmap_event = NULL;
913 klass->window_state_event = NULL;
914 klass->property_notify_event = _gtk_selection_property_notify;
915 klass->selection_clear_event = _gtk_selection_clear;
916 klass->selection_request_event = _gtk_selection_request;
917 klass->selection_notify_event = _gtk_selection_notify;
918 klass->selection_received = NULL;
919 klass->proximity_in_event = NULL;
920 klass->proximity_out_event = NULL;
921 klass->drag_begin = NULL;
922 klass->drag_end = NULL;
923 klass->drag_data_delete = NULL;
924 klass->drag_leave = NULL;
925 klass->drag_motion = NULL;
926 klass->drag_drop = NULL;
927 klass->drag_data_received = NULL;
928 klass->screen_changed = NULL;
929 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
930 klass->grab_broken_event = NULL;
931 klass->query_tooltip = gtk_widget_real_query_tooltip;
932 klass->style_updated = gtk_widget_real_style_updated;
934 klass->show_help = gtk_widget_real_show_help;
936 /* Accessibility support */
937 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
938 klass->priv->accessible_role = ATK_ROLE_INVALID;
939 klass->get_accessible = gtk_widget_real_get_accessible;
941 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
942 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
944 g_object_class_install_property (gobject_class,
946 g_param_spec_string ("name",
948 P_("The name of the widget"),
950 GTK_PARAM_READWRITE));
951 g_object_class_install_property (gobject_class,
953 g_param_spec_object ("parent",
955 P_("The parent widget of this widget. Must be a Container widget"),
957 GTK_PARAM_READWRITE));
959 g_object_class_install_property (gobject_class,
961 g_param_spec_int ("width-request",
963 P_("Override for width request of the widget, or -1 if natural request should be used"),
967 GTK_PARAM_READWRITE));
968 g_object_class_install_property (gobject_class,
970 g_param_spec_int ("height-request",
971 P_("Height request"),
972 P_("Override for height request of the widget, or -1 if natural request should be used"),
976 GTK_PARAM_READWRITE));
977 g_object_class_install_property (gobject_class,
979 g_param_spec_boolean ("visible",
981 P_("Whether the widget is visible"),
983 GTK_PARAM_READWRITE));
984 g_object_class_install_property (gobject_class,
986 g_param_spec_boolean ("sensitive",
988 P_("Whether the widget responds to input"),
990 GTK_PARAM_READWRITE));
991 g_object_class_install_property (gobject_class,
993 g_param_spec_boolean ("app-paintable",
994 P_("Application paintable"),
995 P_("Whether the application will paint directly on the widget"),
997 GTK_PARAM_READWRITE));
998 g_object_class_install_property (gobject_class,
1000 g_param_spec_boolean ("can-focus",
1002 P_("Whether the widget can accept the input focus"),
1004 GTK_PARAM_READWRITE));
1005 g_object_class_install_property (gobject_class,
1007 g_param_spec_boolean ("has-focus",
1009 P_("Whether the widget has the input focus"),
1011 GTK_PARAM_READWRITE));
1012 g_object_class_install_property (gobject_class,
1014 g_param_spec_boolean ("is-focus",
1016 P_("Whether the widget is the focus widget within the toplevel"),
1018 GTK_PARAM_READWRITE));
1019 g_object_class_install_property (gobject_class,
1021 g_param_spec_boolean ("can-default",
1023 P_("Whether the widget can be the default widget"),
1025 GTK_PARAM_READWRITE));
1026 g_object_class_install_property (gobject_class,
1028 g_param_spec_boolean ("has-default",
1030 P_("Whether the widget is the default widget"),
1032 GTK_PARAM_READWRITE));
1033 g_object_class_install_property (gobject_class,
1034 PROP_RECEIVES_DEFAULT,
1035 g_param_spec_boolean ("receives-default",
1036 P_("Receives default"),
1037 P_("If TRUE, the widget will receive the default action when it is focused"),
1039 GTK_PARAM_READWRITE));
1040 g_object_class_install_property (gobject_class,
1041 PROP_COMPOSITE_CHILD,
1042 g_param_spec_boolean ("composite-child",
1043 P_("Composite child"),
1044 P_("Whether the widget is part of a composite widget"),
1046 GTK_PARAM_READABLE));
1047 g_object_class_install_property (gobject_class,
1049 g_param_spec_object ("style",
1051 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1053 GTK_PARAM_READWRITE));
1054 g_object_class_install_property (gobject_class,
1056 g_param_spec_flags ("events",
1058 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1059 GDK_TYPE_EVENT_MASK,
1061 GTK_PARAM_READWRITE));
1062 g_object_class_install_property (gobject_class,
1064 g_param_spec_boolean ("no-show-all",
1066 P_("Whether gtk_widget_show_all() should not affect this widget"),
1068 GTK_PARAM_READWRITE));
1071 * GtkWidget:has-tooltip:
1073 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1074 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1075 * the widget will be queried using #GtkWidget::query-tooltip to determine
1076 * whether it will provide a tooltip or not.
1078 * Note that setting this property to %TRUE for the first time will change
1079 * the event masks of the GdkWindows of this widget to include leave-notify
1080 * and motion-notify events. This cannot and will not be undone when the
1081 * property is set to %FALSE again.
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_boolean ("has-tooltip",
1089 P_("Whether this widget has a tooltip"),
1091 GTK_PARAM_READWRITE));
1093 * GtkWidget:tooltip-text:
1095 * Sets the text of tooltip to be the given string.
1097 * Also see gtk_tooltip_set_text().
1099 * This is a convenience property which will take care of getting the
1100 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1101 * will automatically be set to %TRUE and there will be taken care of
1102 * #GtkWidget::query-tooltip in the default signal handler.
1106 g_object_class_install_property (gobject_class,
1108 g_param_spec_string ("tooltip-text",
1110 P_("The contents of the tooltip for this widget"),
1112 GTK_PARAM_READWRITE));
1114 * GtkWidget:tooltip-markup:
1116 * Sets the text of tooltip to be the given string, which is marked up
1117 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1118 * Also see gtk_tooltip_set_markup().
1120 * This is a convenience property which will take care of getting the
1121 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1122 * will automatically be set to %TRUE and there will be taken care of
1123 * #GtkWidget::query-tooltip in the default signal handler.
1127 g_object_class_install_property (gobject_class,
1128 PROP_TOOLTIP_MARKUP,
1129 g_param_spec_string ("tooltip-markup",
1130 P_("Tooltip markup"),
1131 P_("The contents of the tooltip for this widget"),
1133 GTK_PARAM_READWRITE));
1138 * The widget's window if it is realized, %NULL otherwise.
1142 g_object_class_install_property (gobject_class,
1144 g_param_spec_object ("window",
1146 P_("The widget's window if it is realized"),
1148 GTK_PARAM_READABLE));
1151 * GtkWidget:double-buffered
1153 * Whether the widget is double buffered.
1157 g_object_class_install_property (gobject_class,
1158 PROP_DOUBLE_BUFFERED,
1159 g_param_spec_boolean ("double-buffered",
1160 P_("Double Buffered"),
1161 P_("Whether the widget is double buffered"),
1163 GTK_PARAM_READWRITE));
1168 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1172 g_object_class_install_property (gobject_class,
1174 g_param_spec_enum ("halign",
1175 P_("Horizontal Alignment"),
1176 P_("How to position in extra horizontal space"),
1179 GTK_PARAM_READWRITE));
1184 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1188 g_object_class_install_property (gobject_class,
1190 g_param_spec_enum ("valign",
1191 P_("Vertical Alignment"),
1192 P_("How to position in extra vertical space"),
1195 GTK_PARAM_READWRITE));
1198 * GtkWidget:margin-left
1200 * Margin on left side of widget.
1202 * This property adds margin outside of the widget's normal size
1203 * request, the margin will be added in addition to the size from
1204 * gtk_widget_set_size_request() for example.
1208 g_object_class_install_property (gobject_class,
1210 g_param_spec_int ("margin-left",
1211 P_("Margin on Left"),
1212 P_("Pixels of extra space on the left side"),
1216 GTK_PARAM_READWRITE));
1219 * GtkWidget:margin-right
1221 * Margin on right side of widget.
1223 * This property adds margin outside of the widget's normal size
1224 * request, the margin will be added in addition to the size from
1225 * gtk_widget_set_size_request() for example.
1229 g_object_class_install_property (gobject_class,
1231 g_param_spec_int ("margin-right",
1232 P_("Margin on Right"),
1233 P_("Pixels of extra space on the right side"),
1237 GTK_PARAM_READWRITE));
1240 * GtkWidget:margin-top
1242 * Margin on top side of widget.
1244 * This property adds margin outside of the widget's normal size
1245 * request, the margin will be added in addition to the size from
1246 * gtk_widget_set_size_request() for example.
1250 g_object_class_install_property (gobject_class,
1252 g_param_spec_int ("margin-top",
1253 P_("Margin on Top"),
1254 P_("Pixels of extra space on the top side"),
1258 GTK_PARAM_READWRITE));
1261 * GtkWidget:margin-bottom
1263 * Margin on bottom side of widget.
1265 * This property adds margin outside of the widget's normal size
1266 * request, the margin will be added in addition to the size from
1267 * gtk_widget_set_size_request() for example.
1271 g_object_class_install_property (gobject_class,
1273 g_param_spec_int ("margin-bottom",
1274 P_("Margin on Bottom"),
1275 P_("Pixels of extra space on the bottom side"),
1279 GTK_PARAM_READWRITE));
1284 * Sets all four sides' margin at once. If read, returns max
1285 * margin on any side.
1289 g_object_class_install_property (gobject_class,
1291 g_param_spec_int ("margin",
1293 P_("Pixels of extra space on all four sides"),
1297 GTK_PARAM_READWRITE));
1300 * GtkWidget::destroy:
1301 * @object: the object which received the signal
1303 * Signals that all holders of a reference to the widget should release
1304 * the reference that they hold. May result in finalization of the widget
1305 * if all references are released.
1307 widget_signals[DESTROY] =
1308 g_signal_new (I_("destroy"),
1309 G_TYPE_FROM_CLASS (gobject_class),
1310 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1311 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1313 _gtk_marshal_VOID__VOID,
1319 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1323 g_object_class_install_property (gobject_class,
1325 g_param_spec_boolean ("hexpand",
1326 P_("Horizontal Expand"),
1327 P_("Whether widget wants more horizontal space"),
1329 GTK_PARAM_READWRITE));
1332 * GtkWidget:hexpand-set
1334 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1338 g_object_class_install_property (gobject_class,
1340 g_param_spec_boolean ("hexpand-set",
1341 P_("Horizontal Expand Set"),
1342 P_("Whether to use the hexpand property"),
1344 GTK_PARAM_READWRITE));
1349 * Whether to expand vertically. See gtk_widget_set_vexpand().
1353 g_object_class_install_property (gobject_class,
1355 g_param_spec_boolean ("vexpand",
1356 P_("Vertical Expand"),
1357 P_("Whether widget wants more vertical space"),
1359 GTK_PARAM_READWRITE));
1362 * GtkWidget:vexpand-set
1364 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1368 g_object_class_install_property (gobject_class,
1370 g_param_spec_boolean ("vexpand-set",
1371 P_("Vertical Expand Set"),
1372 P_("Whether to use the vexpand property"),
1374 GTK_PARAM_READWRITE));
1379 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1383 g_object_class_install_property (gobject_class,
1385 g_param_spec_boolean ("expand",
1387 P_("Whether widget wants to expand in both directions"),
1389 GTK_PARAM_READWRITE));
1393 * @widget: the object which received the signal.
1395 widget_signals[SHOW] =
1396 g_signal_new (I_("show"),
1397 G_TYPE_FROM_CLASS (gobject_class),
1399 G_STRUCT_OFFSET (GtkWidgetClass, show),
1401 _gtk_marshal_VOID__VOID,
1406 * @widget: the object which received the signal.
1408 widget_signals[HIDE] =
1409 g_signal_new (I_("hide"),
1410 G_TYPE_FROM_CLASS (gobject_class),
1412 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1414 _gtk_marshal_VOID__VOID,
1419 * @widget: the object which received the signal.
1421 widget_signals[MAP] =
1422 g_signal_new (I_("map"),
1423 G_TYPE_FROM_CLASS (gobject_class),
1425 G_STRUCT_OFFSET (GtkWidgetClass, map),
1427 _gtk_marshal_VOID__VOID,
1432 * @widget: the object which received the signal.
1434 widget_signals[UNMAP] =
1435 g_signal_new (I_("unmap"),
1436 G_TYPE_FROM_CLASS (gobject_class),
1438 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1440 _gtk_marshal_VOID__VOID,
1444 * GtkWidget::realize:
1445 * @widget: the object which received the signal.
1447 widget_signals[REALIZE] =
1448 g_signal_new (I_("realize"),
1449 G_TYPE_FROM_CLASS (gobject_class),
1451 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1453 _gtk_marshal_VOID__VOID,
1457 * GtkWidget::unrealize:
1458 * @widget: the object which received the signal.
1460 widget_signals[UNREALIZE] =
1461 g_signal_new (I_("unrealize"),
1462 G_TYPE_FROM_CLASS (gobject_class),
1464 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1466 _gtk_marshal_VOID__VOID,
1470 * GtkWidget::size-allocate:
1471 * @widget: the object which received the signal.
1474 widget_signals[SIZE_ALLOCATE] =
1475 g_signal_new (I_("size-allocate"),
1476 G_TYPE_FROM_CLASS (gobject_class),
1478 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1480 _gtk_marshal_VOID__BOXED,
1482 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1485 * GtkWidget::state-changed:
1486 * @widget: the object which received the signal.
1487 * @state: the previous state
1489 * The ::state-changed signal is emitted when the widget state changes.
1490 * See gtk_widget_get_state().
1492 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1494 widget_signals[STATE_CHANGED] =
1495 g_signal_new (I_("state-changed"),
1496 G_TYPE_FROM_CLASS (gobject_class),
1498 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1500 _gtk_marshal_VOID__ENUM,
1502 GTK_TYPE_STATE_TYPE);
1505 * GtkWidget::state-flags-changed:
1506 * @widget: the object which received the signal.
1507 * @flags: The previous state flags.
1509 * The ::state-flags-changed signal is emitted when the widget state
1510 * changes, see gtk_widget_get_state_flags().
1514 widget_signals[STATE_FLAGS_CHANGED] =
1515 g_signal_new (I_("state-flags-changed"),
1516 G_TYPE_FROM_CLASS (gobject_class),
1518 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1520 _gtk_marshal_VOID__FLAGS,
1522 GTK_TYPE_STATE_FLAGS);
1525 * GtkWidget::parent-set:
1526 * @widget: the object on which the signal is emitted
1527 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1528 * just got its initial parent.
1530 * The ::parent-set signal is emitted when a new parent
1531 * has been set on a widget.
1533 widget_signals[PARENT_SET] =
1534 g_signal_new (I_("parent-set"),
1535 G_TYPE_FROM_CLASS (gobject_class),
1537 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1539 _gtk_marshal_VOID__OBJECT,
1544 * GtkWidget::hierarchy-changed:
1545 * @widget: the object on which the signal is emitted
1546 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1547 * if the widget was previously unanchored
1549 * The ::hierarchy-changed signal is emitted when the
1550 * anchored state of a widget changes. A widget is
1551 * <firstterm>anchored</firstterm> when its toplevel
1552 * ancestor is a #GtkWindow. This signal is emitted when
1553 * a widget changes from un-anchored to anchored or vice-versa.
1555 widget_signals[HIERARCHY_CHANGED] =
1556 g_signal_new (I_("hierarchy-changed"),
1557 G_TYPE_FROM_CLASS (gobject_class),
1559 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1561 _gtk_marshal_VOID__OBJECT,
1566 * GtkWidget::style-set:
1567 * @widget: the object on which the signal is emitted
1568 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1569 * just got its initial style
1571 * The ::style-set signal is emitted when a new style has been set
1572 * on a widget. Note that style-modifying functions like
1573 * gtk_widget_modify_base() also cause this signal to be emitted.
1575 * Note that this signal is emitted for changes to the deprecated
1576 * #GtkStyle. To track changes to the #GtkStyleContext associated
1577 * with a widget, use the #GtkWidget::style-updated signal.
1579 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1581 widget_signals[STYLE_SET] =
1582 g_signal_new (I_("style-set"),
1583 G_TYPE_FROM_CLASS (gobject_class),
1585 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1587 _gtk_marshal_VOID__OBJECT,
1592 * GtkWidget::style-updated:
1593 * @widget: the object on which the signal is emitted
1595 * The ::style-updated signal is emitted when the #GtkStyleContext
1596 * of a widget is changed. Note that style-modifying functions like
1597 * gtk_widget_override_color() also cause this signal to be emitted.
1601 widget_signals[STYLE_UPDATED] =
1602 g_signal_new (I_("style-updated"),
1603 G_TYPE_FROM_CLASS (gobject_class),
1605 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1607 g_cclosure_marshal_VOID__VOID,
1611 * GtkWidget::direction-changed:
1612 * @widget: the object on which the signal is emitted
1613 * @previous_direction: the previous text direction of @widget
1615 * The ::direction-changed signal is emitted when the text direction
1616 * of a widget changes.
1618 widget_signals[DIRECTION_CHANGED] =
1619 g_signal_new (I_("direction-changed"),
1620 G_TYPE_FROM_CLASS (gobject_class),
1622 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1624 _gtk_marshal_VOID__ENUM,
1626 GTK_TYPE_TEXT_DIRECTION);
1629 * GtkWidget::grab-notify:
1630 * @widget: the object which received the signal
1631 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1632 * if it becomes unshadowed
1634 * The ::grab-notify signal is emitted when a widget becomes
1635 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1636 * another widget, or when it becomes unshadowed due to a grab
1639 * A widget is shadowed by a gtk_grab_add() when the topmost
1640 * grab widget in the grab stack of its window group is not
1643 widget_signals[GRAB_NOTIFY] =
1644 g_signal_new (I_("grab-notify"),
1645 G_TYPE_FROM_CLASS (gobject_class),
1647 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1649 _gtk_marshal_VOID__BOOLEAN,
1654 * GtkWidget::child-notify:
1655 * @widget: the object which received the signal
1656 * @pspec: the #GParamSpec of the changed child property
1658 * The ::child-notify signal is emitted for each
1659 * <link linkend="child-properties">child property</link> that has
1660 * changed on an object. The signal's detail holds the property name.
1662 widget_signals[CHILD_NOTIFY] =
1663 g_signal_new (I_("child-notify"),
1664 G_TYPE_FROM_CLASS (gobject_class),
1665 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1666 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1668 g_cclosure_marshal_VOID__PARAM,
1674 * @widget: the object which received the signal
1675 * @cr: the cairo context to draw to
1677 * This signal is emitted when a widget is supposed to render itself.
1678 * The @widget's top left corner must be painted at the origin of
1679 * the passed in context and be sized to the values returned by
1680 * gtk_widget_get_allocated_width() and
1681 * gtk_widget_get_allocated_height().
1683 * Signal handlers connected to this signal can modify the cairo
1684 * context passed as @cr in any way they like and don't need to
1685 * restore it. The signal emission takes care of calling cairo_save()
1686 * before and cairo_restore() after invoking the handler.
1690 widget_signals[DRAW] =
1691 g_signal_new (I_("draw"),
1692 G_TYPE_FROM_CLASS (gobject_class),
1694 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1695 _gtk_boolean_handled_accumulator, NULL,
1696 gtk_widget_draw_marshaller,
1698 CAIRO_GOBJECT_TYPE_CONTEXT);
1701 * GtkWidget::mnemonic-activate:
1702 * @widget: the object which received the signal.
1705 widget_signals[MNEMONIC_ACTIVATE] =
1706 g_signal_new (I_("mnemonic-activate"),
1707 G_TYPE_FROM_CLASS (gobject_class),
1709 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1710 _gtk_boolean_handled_accumulator, NULL,
1711 _gtk_marshal_BOOLEAN__BOOLEAN,
1716 * GtkWidget::grab-focus:
1717 * @widget: the object which received the signal.
1719 widget_signals[GRAB_FOCUS] =
1720 g_signal_new (I_("grab-focus"),
1721 G_TYPE_FROM_CLASS (gobject_class),
1722 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1723 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1725 _gtk_marshal_VOID__VOID,
1730 * @widget: the object which received the signal.
1733 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1735 widget_signals[FOCUS] =
1736 g_signal_new (I_("focus"),
1737 G_TYPE_FROM_CLASS (klass),
1739 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1740 _gtk_boolean_handled_accumulator, NULL,
1741 _gtk_marshal_BOOLEAN__ENUM,
1743 GTK_TYPE_DIRECTION_TYPE);
1746 * GtkWidget::move-focus:
1747 * @widget: the object which received the signal.
1750 widget_signals[MOVE_FOCUS] =
1751 g_signal_new (I_("move-focus"),
1752 G_TYPE_FROM_CLASS (klass),
1753 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1754 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1756 _gtk_marshal_VOID__ENUM,
1759 GTK_TYPE_DIRECTION_TYPE);
1762 * GtkWidget::keynav-failed:
1763 * @widget: the object which received the signal
1764 * @direction: the direction of movement
1766 * Gets emitted if keyboard navigation fails.
1767 * See gtk_widget_keynav_failed() for details.
1769 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1770 * if the emitting widget should try to handle the keyboard
1771 * navigation attempt in its parent container(s).
1775 widget_signals[KEYNAV_FAILED] =
1776 g_signal_new (I_("keynav-failed"),
1777 G_TYPE_FROM_CLASS (klass),
1779 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1780 _gtk_boolean_handled_accumulator, NULL,
1781 _gtk_marshal_BOOLEAN__ENUM,
1783 GTK_TYPE_DIRECTION_TYPE);
1787 * @widget: the object which received the signal.
1788 * @event: the #GdkEvent which triggered this signal
1790 * The GTK+ main loop will emit three signals for each GDK event delivered
1791 * to a widget: one generic ::event signal, another, more specific,
1792 * signal that matches the type of event delivered (e.g.
1793 * #GtkWidget::key-press-event) and finally a generic
1794 * #GtkWidget::event-after signal.
1796 * Returns: %TRUE to stop other handlers from being invoked for the event
1797 * and to cancel the emission of the second specific ::event signal.
1798 * %FALSE to propagate the event further and to allow the emission of
1799 * the second signal. The ::event-after signal is emitted regardless of
1802 widget_signals[EVENT] =
1803 g_signal_new (I_("event"),
1804 G_TYPE_FROM_CLASS (klass),
1806 G_STRUCT_OFFSET (GtkWidgetClass, event),
1807 _gtk_boolean_handled_accumulator, NULL,
1808 _gtk_marshal_BOOLEAN__BOXED,
1810 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1813 * GtkWidget::event-after:
1814 * @widget: the object which received the signal.
1815 * @event: the #GdkEvent which triggered this signal
1817 * After the emission of the #GtkWidget::event signal and (optionally)
1818 * the second more specific signal, ::event-after will be emitted
1819 * regardless of the previous two signals handlers return values.
1822 widget_signals[EVENT_AFTER] =
1823 g_signal_new (I_("event-after"),
1824 G_TYPE_FROM_CLASS (klass),
1828 _gtk_marshal_VOID__BOXED,
1830 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1833 * GtkWidget::button-press-event:
1834 * @widget: the object which received the signal.
1835 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1838 * The ::button-press-event signal will be emitted when a button
1839 * (typically from a mouse) is pressed.
1841 * To receive this signal, the #GdkWindow associated to the
1842 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1844 * This signal will be sent to the grab widget if there is one.
1846 * Returns: %TRUE to stop other handlers from being invoked for the event.
1847 * %FALSE to propagate the event further.
1849 widget_signals[BUTTON_PRESS_EVENT] =
1850 g_signal_new (I_("button-press-event"),
1851 G_TYPE_FROM_CLASS (klass),
1853 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1854 _gtk_boolean_handled_accumulator, NULL,
1855 _gtk_marshal_BOOLEAN__BOXED,
1857 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1860 * GtkWidget::button-release-event:
1861 * @widget: the object which received the signal.
1862 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1865 * The ::button-release-event signal will be emitted when a button
1866 * (typically from a mouse) is released.
1868 * To receive this signal, the #GdkWindow associated to the
1869 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1871 * This signal will be sent to the grab widget if there is one.
1873 * Returns: %TRUE to stop other handlers from being invoked for the event.
1874 * %FALSE to propagate the event further.
1876 widget_signals[BUTTON_RELEASE_EVENT] =
1877 g_signal_new (I_("button-release-event"),
1878 G_TYPE_FROM_CLASS (klass),
1880 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1881 _gtk_boolean_handled_accumulator, NULL,
1882 _gtk_marshal_BOOLEAN__BOXED,
1884 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1887 * GtkWidget::scroll-event:
1888 * @widget: the object which received the signal.
1889 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1892 * The ::scroll-event signal is emitted when a button in the 4 to 7
1893 * range is pressed. Wheel mice are usually configured to generate
1894 * button press events for buttons 4 and 5 when the wheel is turned.
1896 * To receive this signal, the #GdkWindow associated to the widget needs
1897 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1899 * This signal will be sent to the grab widget if there is one.
1901 * Returns: %TRUE to stop other handlers from being invoked for the event.
1902 * %FALSE to propagate the event further.
1904 widget_signals[SCROLL_EVENT] =
1905 g_signal_new (I_("scroll-event"),
1906 G_TYPE_FROM_CLASS (klass),
1908 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1909 _gtk_boolean_handled_accumulator, NULL,
1910 _gtk_marshal_BOOLEAN__BOXED,
1912 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1915 * GtkWidget::motion-notify-event:
1916 * @widget: the object which received the signal.
1917 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1920 * The ::motion-notify-event signal is emitted when the pointer moves
1921 * over the widget's #GdkWindow.
1923 * To receive this signal, the #GdkWindow associated to the widget
1924 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1926 * This signal will be sent to the grab widget if there is one.
1928 * Returns: %TRUE to stop other handlers from being invoked for the event.
1929 * %FALSE to propagate the event further.
1931 widget_signals[MOTION_NOTIFY_EVENT] =
1932 g_signal_new (I_("motion-notify-event"),
1933 G_TYPE_FROM_CLASS (klass),
1935 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1936 _gtk_boolean_handled_accumulator, NULL,
1937 _gtk_marshal_BOOLEAN__BOXED,
1939 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1942 * GtkWidget::composited-changed:
1943 * @widget: the object on which the signal is emitted
1945 * The ::composited-changed signal is emitted when the composited
1946 * status of @widget<!-- -->s screen changes.
1947 * See gdk_screen_is_composited().
1949 widget_signals[COMPOSITED_CHANGED] =
1950 g_signal_new (I_("composited-changed"),
1951 G_TYPE_FROM_CLASS (klass),
1952 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1953 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1955 _gtk_marshal_VOID__VOID,
1959 * GtkWidget::delete-event:
1960 * @widget: the object which received the signal
1961 * @event: the event which triggered this signal
1963 * The ::delete-event signal is emitted if a user requests that
1964 * a toplevel window is closed. The default handler for this signal
1965 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1966 * this signal will cause the window to be hidden instead, so that
1967 * it can later be shown again without reconstructing it.
1969 * Returns: %TRUE to stop other handlers from being invoked for the event.
1970 * %FALSE to propagate the event further.
1972 widget_signals[DELETE_EVENT] =
1973 g_signal_new (I_("delete-event"),
1974 G_TYPE_FROM_CLASS (klass),
1976 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1977 _gtk_boolean_handled_accumulator, NULL,
1978 _gtk_marshal_BOOLEAN__BOXED,
1980 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1983 * GtkWidget::destroy-event:
1984 * @widget: the object which received the signal.
1985 * @event: the event which triggered this signal
1987 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1988 * You rarely get this signal, because most widgets disconnect themselves
1989 * from their window before they destroy it, so no widget owns the
1990 * window at destroy time.
1992 * To receive this signal, the #GdkWindow associated to the widget needs
1993 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1994 * automatically for all new windows.
1996 * Returns: %TRUE to stop other handlers from being invoked for the event.
1997 * %FALSE to propagate the event further.
1999 widget_signals[DESTROY_EVENT] =
2000 g_signal_new (I_("destroy-event"),
2001 G_TYPE_FROM_CLASS (klass),
2003 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2004 _gtk_boolean_handled_accumulator, NULL,
2005 _gtk_marshal_BOOLEAN__BOXED,
2007 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2010 * GtkWidget::key-press-event:
2011 * @widget: the object which received the signal
2012 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2014 * The ::key-press-event signal is emitted when a key is pressed. The signal
2015 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2017 * To receive this signal, the #GdkWindow associated to the widget needs
2018 * to enable the #GDK_KEY_PRESS_MASK mask.
2020 * This signal will be sent to the grab widget if there is one.
2022 * Returns: %TRUE to stop other handlers from being invoked for the event.
2023 * %FALSE to propagate the event further.
2025 widget_signals[KEY_PRESS_EVENT] =
2026 g_signal_new (I_("key-press-event"),
2027 G_TYPE_FROM_CLASS (klass),
2029 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2030 _gtk_boolean_handled_accumulator, NULL,
2031 _gtk_marshal_BOOLEAN__BOXED,
2033 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2036 * GtkWidget::key-release-event:
2037 * @widget: the object which received the signal
2038 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2040 * The ::key-release-event signal is emitted when a key is released.
2042 * To receive this signal, the #GdkWindow associated to the widget needs
2043 * to enable the #GDK_KEY_RELEASE_MASK mask.
2045 * This signal will be sent to the grab widget if there is one.
2047 * Returns: %TRUE to stop other handlers from being invoked for the event.
2048 * %FALSE to propagate the event further.
2050 widget_signals[KEY_RELEASE_EVENT] =
2051 g_signal_new (I_("key-release-event"),
2052 G_TYPE_FROM_CLASS (klass),
2054 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2055 _gtk_boolean_handled_accumulator, NULL,
2056 _gtk_marshal_BOOLEAN__BOXED,
2058 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2061 * GtkWidget::enter-notify-event:
2062 * @widget: the object which received the signal
2063 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2066 * The ::enter-notify-event will be emitted when the pointer enters
2067 * the @widget's window.
2069 * To receive this signal, the #GdkWindow associated to the widget needs
2070 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2072 * This signal will be sent to the grab widget if there is one.
2074 * Returns: %TRUE to stop other handlers from being invoked for the event.
2075 * %FALSE to propagate the event further.
2077 widget_signals[ENTER_NOTIFY_EVENT] =
2078 g_signal_new (I_("enter-notify-event"),
2079 G_TYPE_FROM_CLASS (klass),
2081 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2082 _gtk_boolean_handled_accumulator, NULL,
2083 _gtk_marshal_BOOLEAN__BOXED,
2085 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2088 * GtkWidget::leave-notify-event:
2089 * @widget: the object which received the signal
2090 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2093 * The ::leave-notify-event will be emitted when the pointer leaves
2094 * the @widget's window.
2096 * To receive this signal, the #GdkWindow associated to the widget needs
2097 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2099 * This signal will be sent to the grab widget if there is one.
2101 * Returns: %TRUE to stop other handlers from being invoked for the event.
2102 * %FALSE to propagate the event further.
2104 widget_signals[LEAVE_NOTIFY_EVENT] =
2105 g_signal_new (I_("leave-notify-event"),
2106 G_TYPE_FROM_CLASS (klass),
2108 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2109 _gtk_boolean_handled_accumulator, NULL,
2110 _gtk_marshal_BOOLEAN__BOXED,
2112 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2115 * GtkWidget::configure-event:
2116 * @widget: the object which received the signal
2117 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2120 * The ::configure-event signal will be emitted when the size, position or
2121 * stacking of the @widget's window has changed.
2123 * To receive this signal, the #GdkWindow associated to the widget needs
2124 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2125 * automatically for all new windows.
2127 * Returns: %TRUE to stop other handlers from being invoked for the event.
2128 * %FALSE to propagate the event further.
2130 widget_signals[CONFIGURE_EVENT] =
2131 g_signal_new (I_("configure-event"),
2132 G_TYPE_FROM_CLASS (klass),
2134 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2135 _gtk_boolean_handled_accumulator, NULL,
2136 _gtk_marshal_BOOLEAN__BOXED,
2138 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2141 * GtkWidget::focus-in-event:
2142 * @widget: the object which received the signal
2143 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2146 * The ::focus-in-event signal will be emitted when the keyboard focus
2147 * enters the @widget's window.
2149 * To receive this signal, the #GdkWindow associated to the widget needs
2150 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2152 * Returns: %TRUE to stop other handlers from being invoked for the event.
2153 * %FALSE to propagate the event further.
2155 widget_signals[FOCUS_IN_EVENT] =
2156 g_signal_new (I_("focus-in-event"),
2157 G_TYPE_FROM_CLASS (klass),
2159 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2160 _gtk_boolean_handled_accumulator, NULL,
2161 _gtk_marshal_BOOLEAN__BOXED,
2163 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2166 * GtkWidget::focus-out-event:
2167 * @widget: the object which received the signal
2168 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2171 * The ::focus-out-event signal will be emitted when the keyboard focus
2172 * leaves the @widget's window.
2174 * To receive this signal, the #GdkWindow associated to the widget needs
2175 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2177 * Returns: %TRUE to stop other handlers from being invoked for the event.
2178 * %FALSE to propagate the event further.
2180 widget_signals[FOCUS_OUT_EVENT] =
2181 g_signal_new (I_("focus-out-event"),
2182 G_TYPE_FROM_CLASS (klass),
2184 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2185 _gtk_boolean_handled_accumulator, NULL,
2186 _gtk_marshal_BOOLEAN__BOXED,
2188 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2191 * GtkWidget::map-event:
2192 * @widget: the object which received the signal
2193 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2195 * The ::map-event signal will be emitted when the @widget's window is
2196 * mapped. A window is mapped when it becomes visible on the screen.
2198 * To receive this signal, the #GdkWindow associated to the widget needs
2199 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2200 * automatically for all new windows.
2202 * Returns: %TRUE to stop other handlers from being invoked for the event.
2203 * %FALSE to propagate the event further.
2205 widget_signals[MAP_EVENT] =
2206 g_signal_new (I_("map-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2216 * GtkWidget::unmap-event:
2217 * @widget: the object which received the signal
2218 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2220 * The ::unmap-event signal will be emitted when the @widget's window is
2221 * unmapped. A window is unmapped when it becomes invisible on the screen.
2223 * To receive this signal, the #GdkWindow associated to the widget needs
2224 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2225 * automatically for all new windows.
2227 * Returns: %TRUE to stop other handlers from being invoked for the event.
2228 * %FALSE to propagate the event further.
2230 widget_signals[UNMAP_EVENT] =
2231 g_signal_new (I_("unmap-event"),
2232 G_TYPE_FROM_CLASS (klass),
2234 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2235 _gtk_boolean_handled_accumulator, NULL,
2236 _gtk_marshal_BOOLEAN__BOXED,
2238 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2241 * GtkWidget::property-notify-event:
2242 * @widget: the object which received the signal
2243 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2246 * The ::property-notify-event signal will be emitted when a property on
2247 * the @widget's window has been changed or deleted.
2249 * To receive this signal, the #GdkWindow associated to the widget needs
2250 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2252 * Returns: %TRUE to stop other handlers from being invoked for the event.
2253 * %FALSE to propagate the event further.
2255 widget_signals[PROPERTY_NOTIFY_EVENT] =
2256 g_signal_new (I_("property-notify-event"),
2257 G_TYPE_FROM_CLASS (klass),
2259 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2260 _gtk_boolean_handled_accumulator, NULL,
2261 _gtk_marshal_BOOLEAN__BOXED,
2263 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2266 * GtkWidget::selection-clear-event:
2267 * @widget: the object which received the signal
2268 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2271 * The ::selection-clear-event signal will be emitted when the
2272 * the @widget's window has lost ownership of a selection.
2274 * Returns: %TRUE to stop other handlers from being invoked for the event.
2275 * %FALSE to propagate the event further.
2277 widget_signals[SELECTION_CLEAR_EVENT] =
2278 g_signal_new (I_("selection-clear-event"),
2279 G_TYPE_FROM_CLASS (klass),
2281 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2282 _gtk_boolean_handled_accumulator, NULL,
2283 _gtk_marshal_BOOLEAN__BOXED,
2285 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2288 * GtkWidget::selection-request-event:
2289 * @widget: the object which received the signal
2290 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2293 * The ::selection-request-event signal will be emitted when
2294 * another client requests ownership of the selection owned by
2295 * the @widget's window.
2297 * Returns: %TRUE to stop other handlers from being invoked for the event.
2298 * %FALSE to propagate the event further.
2300 widget_signals[SELECTION_REQUEST_EVENT] =
2301 g_signal_new (I_("selection-request-event"),
2302 G_TYPE_FROM_CLASS (klass),
2304 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2305 _gtk_boolean_handled_accumulator, NULL,
2306 _gtk_marshal_BOOLEAN__BOXED,
2308 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2311 * GtkWidget::selection-notify-event:
2312 * @widget: the object which received the signal.
2313 * @event: (type Gdk.EventSelection):
2315 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2317 widget_signals[SELECTION_NOTIFY_EVENT] =
2318 g_signal_new (I_("selection-notify-event"),
2319 G_TYPE_FROM_CLASS (klass),
2321 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2322 _gtk_boolean_handled_accumulator, NULL,
2323 _gtk_marshal_BOOLEAN__BOXED,
2325 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2328 * GtkWidget::selection-received:
2329 * @widget: the object which received the signal.
2333 widget_signals[SELECTION_RECEIVED] =
2334 g_signal_new (I_("selection-received"),
2335 G_TYPE_FROM_CLASS (klass),
2337 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2339 _gtk_marshal_VOID__BOXED_UINT,
2341 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2345 * GtkWidget::selection-get:
2346 * @widget: the object which received the signal.
2351 widget_signals[SELECTION_GET] =
2352 g_signal_new (I_("selection-get"),
2353 G_TYPE_FROM_CLASS (klass),
2355 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2357 _gtk_marshal_VOID__BOXED_UINT_UINT,
2359 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2364 * GtkWidget::proximity-in-event:
2365 * @widget: the object which received the signal
2366 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2369 * To receive this signal the #GdkWindow associated to the widget needs
2370 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2372 * This signal will be sent to the grab widget if there is one.
2374 * Returns: %TRUE to stop other handlers from being invoked for the event.
2375 * %FALSE to propagate the event further.
2377 widget_signals[PROXIMITY_IN_EVENT] =
2378 g_signal_new (I_("proximity-in-event"),
2379 G_TYPE_FROM_CLASS (klass),
2381 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2382 _gtk_boolean_handled_accumulator, NULL,
2383 _gtk_marshal_BOOLEAN__BOXED,
2385 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2388 * GtkWidget::proximity-out-event:
2389 * @widget: the object which received the signal
2390 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2393 * To receive this signal the #GdkWindow associated to the widget needs
2394 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2396 * This signal will be sent to the grab widget if there is one.
2398 * Returns: %TRUE to stop other handlers from being invoked for the event.
2399 * %FALSE to propagate the event further.
2401 widget_signals[PROXIMITY_OUT_EVENT] =
2402 g_signal_new (I_("proximity-out-event"),
2403 G_TYPE_FROM_CLASS (klass),
2405 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2406 _gtk_boolean_handled_accumulator, NULL,
2407 _gtk_marshal_BOOLEAN__BOXED,
2409 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2412 * GtkWidget::drag-leave:
2413 * @widget: the object which received the signal.
2414 * @drag_context: the drag context
2415 * @time: the timestamp of the motion event
2417 * The ::drag-leave signal is emitted on the drop site when the cursor
2418 * leaves the widget. A typical reason to connect to this signal is to
2419 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2420 * with gtk_drag_unhighlight()
2422 widget_signals[DRAG_LEAVE] =
2423 g_signal_new (I_("drag-leave"),
2424 G_TYPE_FROM_CLASS (klass),
2426 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2428 _gtk_marshal_VOID__OBJECT_UINT,
2430 GDK_TYPE_DRAG_CONTEXT,
2434 * GtkWidget::drag-begin:
2435 * @widget: the object which received the signal
2436 * @drag_context: the drag context
2438 * The ::drag-begin signal is emitted on the drag source when a drag is
2439 * started. A typical reason to connect to this signal is to set up a
2440 * custom drag icon with gtk_drag_source_set_icon().
2442 * Note that some widgets set up a drag icon in the default handler of
2443 * this signal, so you may have to use g_signal_connect_after() to
2444 * override what the default handler did.
2446 widget_signals[DRAG_BEGIN] =
2447 g_signal_new (I_("drag-begin"),
2448 G_TYPE_FROM_CLASS (klass),
2450 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2452 _gtk_marshal_VOID__OBJECT,
2454 GDK_TYPE_DRAG_CONTEXT);
2457 * GtkWidget::drag-end:
2458 * @widget: the object which received the signal
2459 * @drag_context: the drag context
2461 * The ::drag-end signal is emitted on the drag source when a drag is
2462 * finished. A typical reason to connect to this signal is to undo
2463 * things done in #GtkWidget::drag-begin.
2465 widget_signals[DRAG_END] =
2466 g_signal_new (I_("drag-end"),
2467 G_TYPE_FROM_CLASS (klass),
2469 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2471 _gtk_marshal_VOID__OBJECT,
2473 GDK_TYPE_DRAG_CONTEXT);
2476 * GtkWidget::drag-data-delete:
2477 * @widget: the object which received the signal
2478 * @drag_context: the drag context
2480 * The ::drag-data-delete signal is emitted on the drag source when a drag
2481 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2482 * handler is responsible for deleting the data that has been dropped. What
2483 * "delete" means depends on the context of the drag operation.
2485 widget_signals[DRAG_DATA_DELETE] =
2486 g_signal_new (I_("drag-data-delete"),
2487 G_TYPE_FROM_CLASS (klass),
2489 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2491 _gtk_marshal_VOID__OBJECT,
2493 GDK_TYPE_DRAG_CONTEXT);
2496 * GtkWidget::drag-failed:
2497 * @widget: the object which received the signal
2498 * @drag_context: the drag context
2499 * @result: the result of the drag operation
2501 * The ::drag-failed signal is emitted on the drag source when a drag has
2502 * failed. The signal handler may hook custom code to handle a failed DND
2503 * operation based on the type of error, it returns %TRUE is the failure has
2504 * been already handled (not showing the default "drag operation failed"
2505 * animation), otherwise it returns %FALSE.
2507 * Return value: %TRUE if the failed drag operation has been already handled.
2511 widget_signals[DRAG_FAILED] =
2512 g_signal_new (I_("drag-failed"),
2513 G_TYPE_FROM_CLASS (klass),
2515 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2516 _gtk_boolean_handled_accumulator, NULL,
2517 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2519 GDK_TYPE_DRAG_CONTEXT,
2520 GTK_TYPE_DRAG_RESULT);
2523 * GtkWidget::drag-motion:
2524 * @widget: the object which received the signal
2525 * @drag_context: the drag context
2526 * @x: the x coordinate of the current cursor position
2527 * @y: the y coordinate of the current cursor position
2528 * @time: the timestamp of the motion event
2530 * The drag-motion signal is emitted on the drop site when the user
2531 * moves the cursor over the widget during a drag. The signal handler
2532 * must determine whether the cursor position is in a drop zone or not.
2533 * If it is not in a drop zone, it returns %FALSE and no further processing
2534 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2535 * handler is responsible for providing the necessary information for
2536 * displaying feedback to the user, by calling gdk_drag_status().
2538 * If the decision whether the drop will be accepted or rejected can't be
2539 * made based solely on the cursor position and the type of the data, the
2540 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2541 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2542 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2543 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2544 * when using the drag-motion signal that way.
2546 * Also note that there is no drag-enter signal. The drag receiver has to
2547 * keep track of whether he has received any drag-motion signals since the
2548 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2549 * an "enter" signal. Upon an "enter", the handler will typically highlight
2550 * the drop site with gtk_drag_highlight().
2553 * drag_motion (GtkWidget *widget,
2554 * GdkDragContext *context,
2561 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2563 * if (!private_data->drag_highlight)
2565 * private_data->drag_highlight = 1;
2566 * gtk_drag_highlight (widget);
2569 * target = gtk_drag_dest_find_target (widget, context, NULL);
2570 * if (target == GDK_NONE)
2571 * gdk_drag_status (context, 0, time);
2574 * private_data->pending_status = context->suggested_action;
2575 * gtk_drag_get_data (widget, context, target, time);
2582 * drag_data_received (GtkWidget *widget,
2583 * GdkDragContext *context,
2586 * GtkSelectionData *selection_data,
2590 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2592 * if (private_data->suggested_action)
2594 * private_data->suggested_action = 0;
2596 * /* We are getting this data due to a request in drag_motion,
2597 * * rather than due to a request in drag_drop, so we are just
2598 * * supposed to call gdk_drag_status (), not actually paste in
2601 * str = gtk_selection_data_get_text (selection_data);
2602 * if (!data_is_acceptable (str))
2603 * gdk_drag_status (context, 0, time);
2605 * gdk_drag_status (context, private_data->suggested_action, time);
2609 * /* accept the drop */
2614 * Returns: whether the cursor position is in a drop zone
2616 widget_signals[DRAG_MOTION] =
2617 g_signal_new (I_("drag-motion"),
2618 G_TYPE_FROM_CLASS (klass),
2620 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2621 _gtk_boolean_handled_accumulator, NULL,
2622 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2624 GDK_TYPE_DRAG_CONTEXT,
2630 * GtkWidget::drag-drop:
2631 * @widget: the object which received the signal
2632 * @drag_context: the drag context
2633 * @x: the x coordinate of the current cursor position
2634 * @y: the y coordinate of the current cursor position
2635 * @time: the timestamp of the motion event
2637 * The ::drag-drop signal is emitted on the drop site when the user drops
2638 * the data onto the widget. The signal handler must determine whether
2639 * the cursor position is in a drop zone or not. If it is not in a drop
2640 * zone, it returns %FALSE and no further processing is necessary.
2641 * Otherwise, the handler returns %TRUE. In this case, the handler must
2642 * ensure that gtk_drag_finish() is called to let the source know that
2643 * the drop is done. The call to gtk_drag_finish() can be done either
2644 * directly or in a #GtkWidget::drag-data-received handler which gets
2645 * triggered by calling gtk_drag_get_data() to receive the data for one
2646 * or more of the supported targets.
2648 * Returns: whether the cursor position is in a drop zone
2650 widget_signals[DRAG_DROP] =
2651 g_signal_new (I_("drag-drop"),
2652 G_TYPE_FROM_CLASS (klass),
2654 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2655 _gtk_boolean_handled_accumulator, NULL,
2656 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2658 GDK_TYPE_DRAG_CONTEXT,
2664 * GtkWidget::drag-data-get:
2665 * @widget: the object which received the signal
2666 * @drag_context: the drag context
2667 * @data: the #GtkSelectionData to be filled with the dragged data
2668 * @info: the info that has been registered with the target in the
2670 * @time: the timestamp at which the data was requested
2672 * The ::drag-data-get signal is emitted on the drag source when the drop
2673 * site requests the data which is dragged. It is the responsibility of
2674 * the signal handler to fill @data with the data in the format which
2675 * is indicated by @info. See gtk_selection_data_set() and
2676 * gtk_selection_data_set_text().
2678 widget_signals[DRAG_DATA_GET] =
2679 g_signal_new (I_("drag-data-get"),
2680 G_TYPE_FROM_CLASS (klass),
2682 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2684 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2686 GDK_TYPE_DRAG_CONTEXT,
2687 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2692 * GtkWidget::drag-data-received:
2693 * @widget: the object which received the signal
2694 * @drag_context: the drag context
2695 * @x: where the drop happened
2696 * @y: where the drop happened
2697 * @data: the received data
2698 * @info: the info that has been registered with the target in the
2700 * @time: the timestamp at which the data was received
2702 * The ::drag-data-received signal is emitted on the drop site when the
2703 * dragged data has been received. If the data was received in order to
2704 * determine whether the drop will be accepted, the handler is expected
2705 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2706 * If the data was received in response to a #GtkWidget::drag-drop signal
2707 * (and this is the last target to be received), the handler for this
2708 * signal is expected to process the received data and then call
2709 * gtk_drag_finish(), setting the @success parameter depending on whether
2710 * the data was processed successfully.
2712 * The handler may inspect and modify @drag_context->action before calling
2713 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2714 * following example:
2717 * drag_data_received (GtkWidget *widget,
2718 * GdkDragContext *drag_context,
2721 * GtkSelectionData *data,
2725 * if ((data->length >= 0) && (data->format == 8))
2727 * if (drag_context->action == GDK_ACTION_ASK)
2729 * GtkWidget *dialog;
2732 * dialog = gtk_message_dialog_new (NULL,
2733 * GTK_DIALOG_MODAL |
2734 * GTK_DIALOG_DESTROY_WITH_PARENT,
2736 * GTK_BUTTONS_YES_NO,
2737 * "Move the data ?\n");
2738 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2739 * gtk_widget_destroy (dialog);
2741 * if (response == GTK_RESPONSE_YES)
2742 * drag_context->action = GDK_ACTION_MOVE;
2744 * drag_context->action = GDK_ACTION_COPY;
2747 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2751 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2755 widget_signals[DRAG_DATA_RECEIVED] =
2756 g_signal_new (I_("drag-data-received"),
2757 G_TYPE_FROM_CLASS (klass),
2759 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2761 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2763 GDK_TYPE_DRAG_CONTEXT,
2766 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2771 * GtkWidget::visibility-notify-event:
2772 * @widget: the object which received the signal
2773 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2774 * triggered this signal.
2776 * The ::visibility-notify-event will be emitted when the @widget's window
2777 * is obscured or unobscured.
2779 * To receive this signal the #GdkWindow associated to the widget needs
2780 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2782 * Returns: %TRUE to stop other handlers from being invoked for the event.
2783 * %FALSE to propagate the event further.
2785 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2786 g_signal_new (I_("visibility-notify-event"),
2787 G_TYPE_FROM_CLASS (klass),
2789 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2790 _gtk_boolean_handled_accumulator, NULL,
2791 _gtk_marshal_BOOLEAN__BOXED,
2793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2796 * GtkWidget::window-state-event:
2797 * @widget: the object which received the signal
2798 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2799 * triggered this signal.
2801 * The ::window-state-event will be emitted when the state of the
2802 * toplevel window associated to the @widget changes.
2804 * To receive this signal the #GdkWindow associated to the widget
2805 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2806 * this mask automatically for all new windows.
2808 * Returns: %TRUE to stop other handlers from being invoked for the
2809 * event. %FALSE to propagate the event further.
2811 widget_signals[WINDOW_STATE_EVENT] =
2812 g_signal_new (I_("window-state-event"),
2813 G_TYPE_FROM_CLASS (klass),
2815 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2816 _gtk_boolean_handled_accumulator, NULL,
2817 _gtk_marshal_BOOLEAN__BOXED,
2819 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2822 * GtkWidget::damage-event:
2823 * @widget: the object which received the signal
2824 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
2826 * Emitted when a redirected window belonging to @widget gets drawn into.
2827 * The region/area members of the event shows what area of the redirected
2828 * drawable was drawn into.
2830 * Returns: %TRUE to stop other handlers from being invoked for the event.
2831 * %FALSE to propagate the event further.
2835 widget_signals[DAMAGE_EVENT] =
2836 g_signal_new (I_("damage-event"),
2837 G_TYPE_FROM_CLASS (klass),
2839 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2840 _gtk_boolean_handled_accumulator, NULL,
2841 _gtk_marshal_BOOLEAN__BOXED,
2843 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2846 * GtkWidget::grab-broken-event:
2847 * @widget: the object which received the signal
2848 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
2850 * Emitted when a pointer or keyboard grab on a window belonging
2851 * to @widget gets broken.
2853 * On X11, this happens when the grab window becomes unviewable
2854 * (i.e. it or one of its ancestors is unmapped), or if the same
2855 * application grabs the pointer or keyboard again.
2857 * Returns: %TRUE to stop other handlers from being invoked for
2858 * the event. %FALSE to propagate the event further.
2862 widget_signals[GRAB_BROKEN_EVENT] =
2863 g_signal_new (I_("grab-broken-event"),
2864 G_TYPE_FROM_CLASS (klass),
2866 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2867 _gtk_boolean_handled_accumulator, NULL,
2868 _gtk_marshal_BOOLEAN__BOXED,
2870 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2873 * GtkWidget::query-tooltip:
2874 * @widget: the object which received the signal
2875 * @x: the x coordinate of the cursor position where the request has
2876 * been emitted, relative to @widget's left side
2877 * @y: the y coordinate of the cursor position where the request has
2878 * been emitted, relative to @widget's top
2879 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2880 * @tooltip: a #GtkTooltip
2882 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2883 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2884 * focus in keyboard mode.
2886 * Using the given coordinates, the signal handler should determine
2887 * whether a tooltip should be shown for @widget. If this is the case
2888 * %TRUE should be returned, %FALSE otherwise. Note that if
2889 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2890 * should not be used.
2892 * The signal handler is free to manipulate @tooltip with the therefore
2893 * destined function calls.
2895 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2899 widget_signals[QUERY_TOOLTIP] =
2900 g_signal_new (I_("query-tooltip"),
2901 G_TYPE_FROM_CLASS (klass),
2903 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2904 _gtk_boolean_handled_accumulator, NULL,
2905 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2913 * GtkWidget::popup-menu
2914 * @widget: the object which received the signal
2916 * This signal gets emitted whenever a widget should pop up a context
2917 * menu. This usually happens through the standard key binding mechanism;
2918 * by pressing a certain key while a widget is focused, the user can cause
2919 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2920 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2921 * for an example of how to use this signal.
2923 * Returns: %TRUE if a menu was activated
2925 widget_signals[POPUP_MENU] =
2926 g_signal_new (I_("popup-menu"),
2927 G_TYPE_FROM_CLASS (klass),
2928 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2929 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2930 _gtk_boolean_handled_accumulator, NULL,
2931 _gtk_marshal_BOOLEAN__VOID,
2935 * GtkWidget::show-help:
2936 * @widget: the object which received the signal.
2939 widget_signals[SHOW_HELP] =
2940 g_signal_new (I_("show-help"),
2941 G_TYPE_FROM_CLASS (klass),
2942 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2943 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2944 _gtk_boolean_handled_accumulator, NULL,
2945 _gtk_marshal_BOOLEAN__ENUM,
2947 GTK_TYPE_WIDGET_HELP_TYPE);
2950 * GtkWidget::accel-closures-changed:
2951 * @widget: the object which received the signal.
2953 widget_signals[ACCEL_CLOSURES_CHANGED] =
2954 g_signal_new (I_("accel-closures-changed"),
2955 G_TYPE_FROM_CLASS (klass),
2959 _gtk_marshal_VOID__VOID,
2963 * GtkWidget::screen-changed:
2964 * @widget: the object on which the signal is emitted
2965 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2966 * widget was not associated with a screen before
2968 * The ::screen-changed signal gets emitted when the
2969 * screen of a widget has changed.
2971 widget_signals[SCREEN_CHANGED] =
2972 g_signal_new (I_("screen-changed"),
2973 G_TYPE_FROM_CLASS (klass),
2975 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2977 _gtk_marshal_VOID__OBJECT,
2982 * GtkWidget::can-activate-accel:
2983 * @widget: the object which received the signal
2984 * @signal_id: the ID of a signal installed on @widget
2986 * Determines whether an accelerator that activates the signal
2987 * identified by @signal_id can currently be activated.
2988 * This signal is present to allow applications and derived
2989 * widgets to override the default #GtkWidget handling
2990 * for determining whether an accelerator can be activated.
2992 * Returns: %TRUE if the signal can be activated.
2994 widget_signals[CAN_ACTIVATE_ACCEL] =
2995 g_signal_new (I_("can-activate-accel"),
2996 G_TYPE_FROM_CLASS (klass),
2998 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2999 _gtk_boolean_handled_accumulator, NULL,
3000 _gtk_marshal_BOOLEAN__UINT,
3001 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3003 binding_set = gtk_binding_set_by_class (klass);
3004 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3006 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3009 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3011 GTK_TYPE_WIDGET_HELP_TYPE,
3012 GTK_WIDGET_HELP_TOOLTIP);
3013 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3015 GTK_TYPE_WIDGET_HELP_TYPE,
3016 GTK_WIDGET_HELP_TOOLTIP);
3017 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3019 GTK_TYPE_WIDGET_HELP_TYPE,
3020 GTK_WIDGET_HELP_WHATS_THIS);
3021 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3023 GTK_TYPE_WIDGET_HELP_TYPE,
3024 GTK_WIDGET_HELP_WHATS_THIS);
3026 gtk_widget_class_install_style_property (klass,
3027 g_param_spec_boolean ("interior-focus",
3028 P_("Interior Focus"),
3029 P_("Whether to draw the focus indicator inside widgets"),
3031 GTK_PARAM_READABLE));
3033 gtk_widget_class_install_style_property (klass,
3034 g_param_spec_int ("focus-line-width",
3035 P_("Focus linewidth"),
3036 P_("Width, in pixels, of the focus indicator line"),
3038 GTK_PARAM_READABLE));
3040 gtk_widget_class_install_style_property (klass,
3041 g_param_spec_string ("focus-line-pattern",
3042 P_("Focus line dash pattern"),
3043 P_("Dash pattern used to draw the focus indicator"),
3045 GTK_PARAM_READABLE));
3046 gtk_widget_class_install_style_property (klass,
3047 g_param_spec_int ("focus-padding",
3048 P_("Focus padding"),
3049 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3051 GTK_PARAM_READABLE));
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_boxed ("cursor-color",
3055 P_("Color with which to draw insertion cursor"),
3057 GTK_PARAM_READABLE));
3058 gtk_widget_class_install_style_property (klass,
3059 g_param_spec_boxed ("secondary-cursor-color",
3060 P_("Secondary cursor color"),
3061 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3063 GTK_PARAM_READABLE));
3064 gtk_widget_class_install_style_property (klass,
3065 g_param_spec_float ("cursor-aspect-ratio",
3066 P_("Cursor line aspect ratio"),
3067 P_("Aspect ratio with which to draw insertion cursor"),
3069 GTK_PARAM_READABLE));
3071 gtk_widget_class_install_style_property (klass,
3072 g_param_spec_boolean ("window-dragging",
3073 P_("Window dragging"),
3074 P_("Whether windows can be dragged by clicking on empty areas"),
3076 GTK_PARAM_READABLE));
3079 * GtkWidget:link-color:
3081 * The "link-color" style property defines the color of unvisited links.
3085 gtk_widget_class_install_style_property (klass,
3086 g_param_spec_boxed ("link-color",
3087 P_("Unvisited Link Color"),
3088 P_("Color of unvisited links"),
3090 GTK_PARAM_READABLE));
3093 * GtkWidget:visited-link-color:
3095 * The "visited-link-color" style property defines the color of visited links.
3099 gtk_widget_class_install_style_property (klass,
3100 g_param_spec_boxed ("visited-link-color",
3101 P_("Visited Link Color"),
3102 P_("Color of visited links"),
3104 GTK_PARAM_READABLE));
3107 * GtkWidget:wide-separators:
3109 * The "wide-separators" style property defines whether separators have
3110 * configurable width and should be drawn using a box instead of a line.
3114 gtk_widget_class_install_style_property (klass,
3115 g_param_spec_boolean ("wide-separators",
3116 P_("Wide Separators"),
3117 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3119 GTK_PARAM_READABLE));
3122 * GtkWidget:separator-width:
3124 * The "separator-width" style property defines the width of separators.
3125 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3129 gtk_widget_class_install_style_property (klass,
3130 g_param_spec_int ("separator-width",
3131 P_("Separator Width"),
3132 P_("The width of separators if wide-separators is TRUE"),
3134 GTK_PARAM_READABLE));
3137 * GtkWidget:separator-height:
3139 * The "separator-height" style property defines the height of separators.
3140 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3144 gtk_widget_class_install_style_property (klass,
3145 g_param_spec_int ("separator-height",
3146 P_("Separator Height"),
3147 P_("The height of separators if \"wide-separators\" is TRUE"),
3149 GTK_PARAM_READABLE));
3152 * GtkWidget:scroll-arrow-hlength:
3154 * The "scroll-arrow-hlength" style property defines the length of
3155 * horizontal scroll arrows.
3159 gtk_widget_class_install_style_property (klass,
3160 g_param_spec_int ("scroll-arrow-hlength",
3161 P_("Horizontal Scroll Arrow Length"),
3162 P_("The length of horizontal scroll arrows"),
3164 GTK_PARAM_READABLE));
3167 * GtkWidget:scroll-arrow-vlength:
3169 * The "scroll-arrow-vlength" style property defines the length of
3170 * vertical scroll arrows.
3174 gtk_widget_class_install_style_property (klass,
3175 g_param_spec_int ("scroll-arrow-vlength",
3176 P_("Vertical Scroll Arrow Length"),
3177 P_("The length of vertical scroll arrows"),
3179 GTK_PARAM_READABLE));
3181 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3183 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3187 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3191 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3192 for (node = list; node; node = node->next)
3194 GParamSpec *pspec = node->data;
3196 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3197 g_param_spec_unref (pspec);
3203 gtk_widget_set_property (GObject *object,
3205 const GValue *value,
3208 GtkWidget *widget = GTK_WIDGET (object);
3213 gchar *tooltip_markup;
3214 const gchar *tooltip_text;
3215 GtkWindow *tooltip_window;
3218 gtk_widget_set_name (widget, g_value_get_string (value));
3221 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3223 case PROP_WIDTH_REQUEST:
3224 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3226 case PROP_HEIGHT_REQUEST:
3227 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3230 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3232 case PROP_SENSITIVE:
3233 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3235 case PROP_APP_PAINTABLE:
3236 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3238 case PROP_CAN_FOCUS:
3239 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3241 case PROP_HAS_FOCUS:
3242 if (g_value_get_boolean (value))
3243 gtk_widget_grab_focus (widget);
3246 if (g_value_get_boolean (value))
3247 gtk_widget_grab_focus (widget);
3249 case PROP_CAN_DEFAULT:
3250 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3252 case PROP_HAS_DEFAULT:
3253 if (g_value_get_boolean (value))
3254 gtk_widget_grab_default (widget);
3256 case PROP_RECEIVES_DEFAULT:
3257 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3260 gtk_widget_set_style (widget, g_value_get_object (value));
3263 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3264 gtk_widget_set_events (widget, g_value_get_flags (value));
3266 case PROP_NO_SHOW_ALL:
3267 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3269 case PROP_HAS_TOOLTIP:
3270 gtk_widget_real_set_has_tooltip (widget,
3271 g_value_get_boolean (value), FALSE);
3273 case PROP_TOOLTIP_MARKUP:
3274 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3275 tooltip_markup = g_value_dup_string (value);
3277 /* Treat an empty string as a NULL string,
3278 * because an empty string would be useless for a tooltip:
3280 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3282 g_free (tooltip_markup);
3283 tooltip_markup = NULL;
3286 g_object_set_qdata_full (object, quark_tooltip_markup,
3287 tooltip_markup, g_free);
3289 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3290 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3291 if (gtk_widget_get_visible (widget))
3292 gtk_widget_queue_tooltip_query (widget);
3294 case PROP_TOOLTIP_TEXT:
3295 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3297 tooltip_text = g_value_get_string (value);
3299 /* Treat an empty string as a NULL string,
3300 * because an empty string would be useless for a tooltip:
3302 if (tooltip_text && (strlen (tooltip_text) == 0))
3303 tooltip_text = NULL;
3305 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3307 g_object_set_qdata_full (object, quark_tooltip_markup,
3308 tooltip_markup, g_free);
3310 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3311 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3312 if (gtk_widget_get_visible (widget))
3313 gtk_widget_queue_tooltip_query (widget);
3315 case PROP_DOUBLE_BUFFERED:
3316 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3319 gtk_widget_set_halign (widget, g_value_get_enum (value));
3322 gtk_widget_set_valign (widget, g_value_get_enum (value));
3324 case PROP_MARGIN_LEFT:
3325 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3327 case PROP_MARGIN_RIGHT:
3328 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3330 case PROP_MARGIN_TOP:
3331 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3333 case PROP_MARGIN_BOTTOM:
3334 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3337 g_object_freeze_notify (G_OBJECT (widget));
3338 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3339 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3340 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3341 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3342 g_object_thaw_notify (G_OBJECT (widget));
3345 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3347 case PROP_HEXPAND_SET:
3348 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3351 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3353 case PROP_VEXPAND_SET:
3354 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3357 g_object_freeze_notify (G_OBJECT (widget));
3358 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3359 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3360 g_object_thaw_notify (G_OBJECT (widget));
3363 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3369 gtk_widget_get_property (GObject *object,
3374 GtkWidget *widget = GTK_WIDGET (object);
3375 GtkWidgetPrivate *priv = widget->priv;
3383 g_value_set_string (value, priv->name);
3385 g_value_set_static_string (value, "");
3388 g_value_set_object (value, priv->parent);
3390 case PROP_WIDTH_REQUEST:
3393 gtk_widget_get_size_request (widget, &w, NULL);
3394 g_value_set_int (value, w);
3397 case PROP_HEIGHT_REQUEST:
3400 gtk_widget_get_size_request (widget, NULL, &h);
3401 g_value_set_int (value, h);
3405 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3407 case PROP_SENSITIVE:
3408 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3410 case PROP_APP_PAINTABLE:
3411 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3413 case PROP_CAN_FOCUS:
3414 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3416 case PROP_HAS_FOCUS:
3417 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3420 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3422 case PROP_CAN_DEFAULT:
3423 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3425 case PROP_HAS_DEFAULT:
3426 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3428 case PROP_RECEIVES_DEFAULT:
3429 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3431 case PROP_COMPOSITE_CHILD:
3432 g_value_set_boolean (value, widget->priv->composite_child);
3435 g_value_set_object (value, gtk_widget_get_style (widget));
3438 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3439 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3441 case PROP_NO_SHOW_ALL:
3442 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3444 case PROP_HAS_TOOLTIP:
3445 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3447 case PROP_TOOLTIP_TEXT:
3449 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3452 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3453 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3455 g_value_take_string (value, text);
3458 case PROP_TOOLTIP_MARKUP:
3459 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3462 g_value_set_object (value, gtk_widget_get_window (widget));
3464 case PROP_DOUBLE_BUFFERED:
3465 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3468 g_value_set_enum (value, gtk_widget_get_halign (widget));
3471 g_value_set_enum (value, gtk_widget_get_valign (widget));
3473 case PROP_MARGIN_LEFT:
3474 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3476 case PROP_MARGIN_RIGHT:
3477 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3479 case PROP_MARGIN_TOP:
3480 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3482 case PROP_MARGIN_BOTTOM:
3483 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3487 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3488 if (aux_info == NULL)
3490 g_value_set_int (value, 0);
3494 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3495 aux_info->margin.right),
3496 MAX (aux_info->margin.top,
3497 aux_info->margin.bottom)));
3502 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3504 case PROP_HEXPAND_SET:
3505 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3508 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3510 case PROP_VEXPAND_SET:
3511 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3514 g_value_set_boolean (value,
3515 gtk_widget_get_hexpand (widget) &&
3516 gtk_widget_get_vexpand (widget));
3519 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3525 gtk_widget_init (GtkWidget *widget)
3527 GtkWidgetPrivate *priv;
3529 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3532 priv = widget->priv;
3534 priv->child_visible = TRUE;
3536 priv->allocation.x = -1;
3537 priv->allocation.y = -1;
3538 priv->allocation.width = 1;
3539 priv->allocation.height = 1;
3540 priv->window = NULL;
3541 priv->parent = NULL;
3543 priv->sensitive = TRUE;
3544 priv->composite_child = composite_child_stack != 0;
3545 priv->double_buffered = TRUE;
3546 priv->redraw_on_alloc = TRUE;
3547 priv->width_request_needed = TRUE;
3548 priv->height_request_needed = TRUE;
3549 priv->alloc_needed = TRUE;
3551 /* this will be set to TRUE if the widget gets a child or if the
3552 * expand flag is set on the widget, but until one of those happen
3553 * we know the expand is already properly FALSE.
3555 * We really want to default FALSE here to avoid computing expand
3556 * all over the place while initially building a widget tree.
3558 priv->need_compute_expand = FALSE;
3560 priv->style = gtk_widget_get_default_style ();
3561 g_object_ref (priv->style);
3566 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3568 GParamSpec **pspecs)
3570 GtkWidgetPrivate *priv = widget->priv;
3571 GtkWidget *container = priv->parent;
3574 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3575 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3579 * gtk_widget_freeze_child_notify:
3580 * @widget: a #GtkWidget
3582 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3583 * signals are queued until gtk_widget_thaw_child_notify() is called
3586 * This is the analogue of g_object_freeze_notify() for child properties.
3589 gtk_widget_freeze_child_notify (GtkWidget *widget)
3591 g_return_if_fail (GTK_IS_WIDGET (widget));
3593 if (!G_OBJECT (widget)->ref_count)
3596 g_object_ref (widget);
3597 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3598 g_object_unref (widget);
3602 * gtk_widget_child_notify:
3603 * @widget: a #GtkWidget
3604 * @child_property: the name of a child property installed on the
3605 * class of @widget<!-- -->'s parent
3607 * Emits a #GtkWidget::child-notify signal for the
3608 * <link linkend="child-properties">child property</link> @child_property
3611 * This is the analogue of g_object_notify() for child properties.
3613 * Also see gtk_container_child_notify().
3616 gtk_widget_child_notify (GtkWidget *widget,
3617 const gchar *child_property)
3619 if (widget->priv->parent == NULL)
3622 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3626 * gtk_widget_thaw_child_notify:
3627 * @widget: a #GtkWidget
3629 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3630 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3634 gtk_widget_thaw_child_notify (GtkWidget *widget)
3636 GObjectNotifyQueue *nqueue;
3638 g_return_if_fail (GTK_IS_WIDGET (widget));
3640 if (!G_OBJECT (widget)->ref_count)
3643 g_object_ref (widget);
3644 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3645 if (!nqueue || !nqueue->freeze_count)
3646 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3647 G_OBJECT_TYPE_NAME (widget), widget);
3649 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3650 g_object_unref (widget);
3656 * @type: type ID of the widget to create
3657 * @first_property_name: name of first property to set
3658 * @...: value of first property, followed by more properties,
3661 * This is a convenience function for creating a widget and setting
3662 * its properties in one go. For example you might write:
3663 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3664 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3665 * g_object_new(), but returns a widget so you don't have to
3666 * cast the object yourself.
3668 * Return value: a new #GtkWidget of type @widget_type
3671 gtk_widget_new (GType type,
3672 const gchar *first_property_name,
3678 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3680 va_start (var_args, first_property_name);
3681 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3688 gtk_widget_queue_draw_child (GtkWidget *widget)
3690 GtkWidgetPrivate *priv = widget->priv;
3693 parent = priv->parent;
3694 if (parent && gtk_widget_is_drawable (parent))
3695 gtk_widget_queue_draw_area (parent,
3698 priv->allocation.width,
3699 priv->allocation.height);
3703 * gtk_widget_unparent:
3704 * @widget: a #GtkWidget
3706 * This function is only for use in widget implementations.
3707 * Should be called by implementations of the remove method
3708 * on #GtkContainer, to dissociate a child from the container.
3711 gtk_widget_unparent (GtkWidget *widget)
3713 GtkWidgetPrivate *priv;
3714 GObjectNotifyQueue *nqueue;
3715 GtkWidget *toplevel;
3716 GtkWidget *old_parent;
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3720 priv = widget->priv;
3722 if (priv->parent == NULL)
3725 /* keep this function in sync with gtk_menu_detach() */
3727 gtk_widget_push_verify_invariants (widget);
3729 g_object_freeze_notify (G_OBJECT (widget));
3730 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3732 toplevel = gtk_widget_get_toplevel (widget);
3733 if (gtk_widget_is_toplevel (toplevel))
3734 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3736 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3737 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3739 gtk_widget_queue_draw_child (widget);
3741 /* Reset the width and height here, to force reallocation if we
3742 * get added back to a new parent. This won't work if our new
3743 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3744 * (would 0x0 be OK here?)
3746 priv->allocation.width = 1;
3747 priv->allocation.height = 1;
3749 if (gtk_widget_get_realized (widget))
3751 if (priv->in_reparent)
3752 gtk_widget_unmap (widget);
3754 gtk_widget_unrealize (widget);
3757 /* If we are unanchoring the child, we save around the toplevel
3758 * to emit hierarchy changed
3760 if (priv->parent->priv->anchored)
3761 g_object_ref (toplevel);
3765 /* Removing a widget from a container restores the child visible
3766 * flag to the default state, so it doesn't affect the child
3767 * in the next parent.
3769 priv->child_visible = TRUE;
3771 old_parent = priv->parent;
3772 priv->parent = NULL;
3774 /* parent may no longer expand if the removed
3775 * child was expand=TRUE and could therefore
3778 if (gtk_widget_get_visible (widget) &&
3779 (priv->need_compute_expand ||
3780 priv->computed_hexpand ||
3781 priv->computed_vexpand))
3783 gtk_widget_queue_compute_expand (old_parent);
3786 /* Unset window-unfocused since we are no longer inside a toplevel window */
3787 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_WINDOW_UNFOCUSED);
3789 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3792 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3793 g_object_unref (toplevel);
3796 /* Now that the parent pointer is nullified and the hierarchy-changed
3797 * already passed, go ahead and unset the parent window, if we are unparenting
3798 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3799 * will fire again for the new subhierarchy.
3801 gtk_widget_set_parent_window (widget, NULL);
3803 g_object_notify (G_OBJECT (widget), "parent");
3804 g_object_thaw_notify (G_OBJECT (widget));
3806 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3807 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3809 gtk_widget_pop_verify_invariants (widget);
3810 g_object_unref (widget);
3814 * gtk_widget_destroy:
3815 * @widget: a #GtkWidget
3817 * Destroys a widget.
3820 * destroyed, it will break any references it holds to other objects.
3821 * If the widget is inside a container, the widget will be removed
3822 * from the container. If the widget is a toplevel (derived from
3823 * #GtkWindow), it will be removed from the list of toplevels, and the
3824 * reference GTK+ holds to it will be removed. Removing a
3825 * widget from its container or the list of toplevels results in the
3826 * widget being finalized, unless you've added additional references
3827 * to the widget with g_object_ref().
3829 * In most cases, only toplevel widgets (windows) require explicit
3830 * destruction, because when you destroy a toplevel its children will
3831 * be destroyed as well.
3834 gtk_widget_destroy (GtkWidget *widget)
3836 g_return_if_fail (GTK_IS_WIDGET (widget));
3838 if (!widget->priv->in_destruction)
3839 g_object_run_dispose (G_OBJECT (widget));
3843 * gtk_widget_destroyed:
3844 * @widget: a #GtkWidget
3845 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3847 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3848 * %NULL. It's intended to be used as a callback connected to the
3849 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3850 * as a signal handler, and pass the address of your widget variable
3851 * as user data. Then when the widget is destroyed, the variable will
3852 * be set to %NULL. Useful for example to avoid multiple copies
3853 * of the same dialog.
3856 gtk_widget_destroyed (GtkWidget *widget,
3857 GtkWidget **widget_pointer)
3859 /* Don't make any assumptions about the
3861 * Even check widget_pointer.
3864 *widget_pointer = NULL;
3869 * @widget: a #GtkWidget
3871 * Flags a widget to be displayed. Any widget that isn't shown will
3872 * not appear on the screen. If you want to show all the widgets in a
3873 * container, it's easier to call gtk_widget_show_all() on the
3874 * container, instead of individually showing the widgets.
3876 * Remember that you have to show the containers containing a widget,
3877 * in addition to the widget itself, before it will appear onscreen.
3879 * When a toplevel container is shown, it is immediately realized and
3880 * mapped; other shown widgets are realized and mapped when their
3881 * toplevel container is realized and mapped.
3884 gtk_widget_show (GtkWidget *widget)
3886 g_return_if_fail (GTK_IS_WIDGET (widget));
3888 if (!gtk_widget_get_visible (widget))
3890 g_object_ref (widget);
3891 gtk_widget_push_verify_invariants (widget);
3893 if (!gtk_widget_is_toplevel (widget))
3894 gtk_widget_queue_resize (widget);
3896 /* see comment in set_parent() for why this should and can be
3899 if (widget->priv->need_compute_expand ||
3900 widget->priv->computed_hexpand ||
3901 widget->priv->computed_vexpand)
3903 if (widget->priv->parent != NULL)
3904 gtk_widget_queue_compute_expand (widget->priv->parent);
3907 g_signal_emit (widget, widget_signals[SHOW], 0);
3908 g_object_notify (G_OBJECT (widget), "visible");
3910 gtk_widget_pop_verify_invariants (widget);
3911 g_object_unref (widget);
3916 gtk_widget_real_show (GtkWidget *widget)
3918 GtkWidgetPrivate *priv = widget->priv;
3920 if (!gtk_widget_get_visible (widget))
3922 priv->visible = TRUE;
3925 gtk_widget_get_mapped (priv->parent) &&
3926 gtk_widget_get_child_visible (widget) &&
3927 !gtk_widget_get_mapped (widget))
3928 gtk_widget_map (widget);
3933 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3936 g_signal_handlers_disconnect_by_func (widget,
3937 gtk_widget_show_map_callback,
3942 * gtk_widget_show_now:
3943 * @widget: a #GtkWidget
3945 * Shows a widget. If the widget is an unmapped toplevel widget
3946 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3947 * loop and wait for the window to actually be mapped. Be careful;
3948 * because the main loop is running, anything can happen during
3952 gtk_widget_show_now (GtkWidget *widget)
3956 g_return_if_fail (GTK_IS_WIDGET (widget));
3958 /* make sure we will get event */
3959 if (!gtk_widget_get_mapped (widget) &&
3960 gtk_widget_is_toplevel (widget))
3962 gtk_widget_show (widget);
3964 g_signal_connect (widget, "map-event",
3965 G_CALLBACK (gtk_widget_show_map_callback),
3969 gtk_main_iteration ();
3972 gtk_widget_show (widget);
3977 * @widget: a #GtkWidget
3979 * Reverses the effects of gtk_widget_show(), causing the widget to be
3980 * hidden (invisible to the user).
3983 gtk_widget_hide (GtkWidget *widget)
3985 g_return_if_fail (GTK_IS_WIDGET (widget));
3987 if (gtk_widget_get_visible (widget))
3989 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3991 g_object_ref (widget);
3992 gtk_widget_push_verify_invariants (widget);
3994 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3995 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3997 /* a parent may now be expand=FALSE since we're hidden. */
3998 if (widget->priv->need_compute_expand ||
3999 widget->priv->computed_hexpand ||
4000 widget->priv->computed_vexpand)
4002 gtk_widget_queue_compute_expand (widget);
4005 g_signal_emit (widget, widget_signals[HIDE], 0);
4006 if (!gtk_widget_is_toplevel (widget))
4007 gtk_widget_queue_resize (widget);
4008 g_object_notify (G_OBJECT (widget), "visible");
4010 gtk_widget_pop_verify_invariants (widget);
4011 g_object_unref (widget);
4016 gtk_widget_real_hide (GtkWidget *widget)
4018 if (gtk_widget_get_visible (widget))
4020 widget->priv->visible = FALSE;
4022 if (gtk_widget_get_mapped (widget))
4023 gtk_widget_unmap (widget);
4028 * gtk_widget_hide_on_delete:
4029 * @widget: a #GtkWidget
4031 * Utility function; intended to be connected to the #GtkWidget::delete-event
4032 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4033 * argument, then returns %TRUE. If connected to ::delete-event, the
4034 * result is that clicking the close button for a window (on the
4035 * window frame, top right corner usually) will hide but not destroy
4036 * the window. By default, GTK+ destroys windows when ::delete-event
4039 * Return value: %TRUE
4042 gtk_widget_hide_on_delete (GtkWidget *widget)
4044 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4046 gtk_widget_hide (widget);
4052 * gtk_widget_show_all:
4053 * @widget: a #GtkWidget
4055 * Recursively shows a widget, and any child widgets (if the widget is
4059 gtk_widget_show_all (GtkWidget *widget)
4061 GtkWidgetClass *class;
4063 g_return_if_fail (GTK_IS_WIDGET (widget));
4065 if (gtk_widget_get_no_show_all (widget))
4068 class = GTK_WIDGET_GET_CLASS (widget);
4070 if (class->show_all)
4071 class->show_all (widget);
4075 _gtk_widget_notify_state_change (GtkWidget *widget,
4083 case GTK_STATE_FLAG_ACTIVE:
4084 state = GTK_STATE_ACTIVE;
4086 case GTK_STATE_FLAG_PRELIGHT:
4087 state = GTK_STATE_PRELIGHT;
4089 case GTK_STATE_FLAG_SELECTED:
4090 state = GTK_STATE_SELECTED;
4092 case GTK_STATE_FLAG_INSENSITIVE:
4093 state = GTK_STATE_INSENSITIVE;
4095 case GTK_STATE_FLAG_INCONSISTENT:
4096 state = GTK_STATE_INCONSISTENT;
4098 case GTK_STATE_FLAG_FOCUSED:
4099 state = GTK_STATE_FOCUSED;
4105 gtk_style_context_notify_state_change (widget->priv->context,
4106 gtk_widget_get_window (widget),
4107 NULL, state, target);
4110 /* Initializes state transitions for those states that
4111 * were enabled before mapping and have a looping animation.
4114 _gtk_widget_start_state_transitions (GtkWidget *widget)
4116 GtkStateFlags state, flag;
4118 if (!widget->priv->context)
4121 state = gtk_widget_get_state_flags (widget);
4122 flag = GTK_STATE_FLAG_FOCUSED;
4126 GtkAnimationDescription *animation_desc;
4128 if ((state & flag) == 0)
4134 gtk_style_context_get (widget->priv->context, state,
4135 "transition", &animation_desc,
4140 if (_gtk_animation_description_get_loop (animation_desc))
4141 _gtk_widget_notify_state_change (widget, flag, TRUE);
4143 _gtk_animation_description_unref (animation_desc);
4152 * @widget: a #GtkWidget
4154 * This function is only for use in widget implementations. Causes
4155 * a widget to be mapped if it isn't already.
4158 gtk_widget_map (GtkWidget *widget)
4160 GtkWidgetPrivate *priv;
4162 g_return_if_fail (GTK_IS_WIDGET (widget));
4163 g_return_if_fail (gtk_widget_get_visible (widget));
4164 g_return_if_fail (gtk_widget_get_child_visible (widget));
4166 priv = widget->priv;
4168 if (!gtk_widget_get_mapped (widget))
4170 gtk_widget_push_verify_invariants (widget);
4172 if (!gtk_widget_get_realized (widget))
4173 gtk_widget_realize (widget);
4175 g_signal_emit (widget, widget_signals[MAP], 0);
4177 if (!gtk_widget_get_has_window (widget))
4178 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4180 gtk_widget_pop_verify_invariants (widget);
4182 _gtk_widget_start_state_transitions (widget);
4188 * @widget: a #GtkWidget
4190 * This function is only for use in widget implementations. Causes
4191 * a widget to be unmapped if it's currently mapped.
4194 gtk_widget_unmap (GtkWidget *widget)
4196 GtkWidgetPrivate *priv;
4198 g_return_if_fail (GTK_IS_WIDGET (widget));
4200 priv = widget->priv;
4202 if (gtk_widget_get_mapped (widget))
4204 gtk_widget_push_verify_invariants (widget);
4206 if (!gtk_widget_get_has_window (widget))
4207 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4208 _gtk_tooltip_hide (widget);
4209 g_signal_emit (widget, widget_signals[UNMAP], 0);
4211 gtk_widget_pop_verify_invariants (widget);
4214 gtk_style_context_cancel_animations (priv->context, NULL);
4216 /* Unset pointer/window info */
4217 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4222 _gtk_widget_enable_device_events (GtkWidget *widget)
4224 GHashTable *device_events;
4225 GHashTableIter iter;
4226 gpointer key, value;
4228 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4233 g_hash_table_iter_init (&iter, device_events);
4235 while (g_hash_table_iter_next (&iter, &key, &value))
4238 GdkEventMask event_mask;
4241 event_mask = GPOINTER_TO_UINT (value);
4242 gtk_widget_add_events_internal (widget, device, event_mask);
4247 get_widget_windows (GtkWidget *widget)
4249 GList *window_list, *last, *l, *children, *ret;
4251 if (gtk_widget_get_has_window (widget))
4252 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4254 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4256 last = g_list_last (window_list);
4259 for (l = window_list; l; l = l->next)
4261 GtkWidget *window_widget = NULL;
4263 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4265 if (widget != window_widget)
4268 ret = g_list_prepend (ret, l->data);
4269 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4273 last = g_list_concat (last, children);
4274 last = g_list_last (last);
4278 g_list_free (window_list);
4284 device_enable_foreach (GtkWidget *widget,
4287 GdkDevice *device = user_data;
4288 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4292 device_disable_foreach (GtkWidget *widget,
4295 GdkDevice *device = user_data;
4296 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4300 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4305 GList *window_list, *l;
4307 window_list = get_widget_windows (widget);
4309 for (l = window_list; l; l = l->next)
4311 GdkEventMask events = 0;
4317 events = gdk_window_get_events (window);
4319 gdk_window_set_device_events (window, device, events);
4322 if (recurse && GTK_IS_CONTAINER (widget))
4325 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4327 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4330 g_list_free (window_list);
4334 gtk_widget_update_devices_mask (GtkWidget *widget,
4337 GList *enabled_devices, *l;
4339 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4341 for (l = enabled_devices; l; l = l->next)
4342 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4346 * gtk_widget_realize:
4347 * @widget: a #GtkWidget
4349 * Creates the GDK (windowing system) resources associated with a
4350 * widget. For example, @widget->window will be created when a widget
4351 * is realized. Normally realization happens implicitly; if you show
4352 * a widget and all its parent containers, then the widget will be
4353 * realized and mapped automatically.
4355 * Realizing a widget requires all
4356 * the widget's parent widgets to be realized; calling
4357 * gtk_widget_realize() realizes the widget's parents in addition to
4358 * @widget itself. If a widget is not yet inside a toplevel window
4359 * when you realize it, bad things will happen.
4361 * This function is primarily used in widget implementations, and
4362 * isn't very useful otherwise. Many times when you think you might
4363 * need it, a better approach is to connect to a signal that will be
4364 * called after the widget is realized automatically, such as
4365 * #GtkWidget::draw. Or simply g_signal_connect () to the
4366 * #GtkWidget::realize signal.
4369 gtk_widget_realize (GtkWidget *widget)
4371 GtkWidgetPrivate *priv;
4372 cairo_region_t *region;
4374 g_return_if_fail (GTK_IS_WIDGET (widget));
4375 g_return_if_fail (widget->priv->anchored ||
4376 GTK_IS_INVISIBLE (widget));
4378 priv = widget->priv;
4380 if (!gtk_widget_get_realized (widget))
4382 gtk_widget_push_verify_invariants (widget);
4385 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4386 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4389 if (priv->parent == NULL &&
4390 !gtk_widget_is_toplevel (widget))
4391 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4392 "inside a toplevel window is not going to work very well. "
4393 "Widgets must be inside a toplevel container before realizing them.");
4395 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4396 gtk_widget_realize (priv->parent);
4398 gtk_widget_ensure_style (widget);
4400 if (priv->style_update_pending)
4401 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4403 g_signal_emit (widget, widget_signals[REALIZE], 0);
4405 gtk_widget_real_set_has_tooltip (widget,
4406 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4409 if (priv->has_shape_mask)
4411 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4412 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4415 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4417 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4419 if (priv->multidevice)
4420 gdk_window_set_support_multidevice (priv->window, TRUE);
4422 _gtk_widget_enable_device_events (widget);
4423 gtk_widget_update_devices_mask (widget, TRUE);
4425 gtk_widget_pop_verify_invariants (widget);
4430 * gtk_widget_unrealize:
4431 * @widget: a #GtkWidget
4433 * This function is only useful in widget implementations.
4434 * Causes a widget to be unrealized (frees all GDK resources
4435 * associated with the widget, such as @widget->window).
4438 gtk_widget_unrealize (GtkWidget *widget)
4440 g_return_if_fail (GTK_IS_WIDGET (widget));
4442 gtk_widget_push_verify_invariants (widget);
4444 if (widget->priv->has_shape_mask)
4445 gtk_widget_shape_combine_region (widget, NULL);
4447 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4448 gtk_widget_input_shape_combine_region (widget, NULL);
4450 if (gtk_widget_get_realized (widget))
4452 g_object_ref (widget);
4454 if (widget->priv->mapped)
4455 gtk_widget_unmap (widget);
4457 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4458 g_assert (!widget->priv->mapped);
4459 gtk_widget_set_realized (widget, FALSE);
4461 g_object_unref (widget);
4464 gtk_widget_pop_verify_invariants (widget);
4467 /*****************************************
4469 *****************************************/
4472 * gtk_widget_queue_draw_region:
4473 * @widget: a #GtkWidget
4474 * @region: region to draw
4476 * Invalidates the rectangular area of @widget defined by @region by
4477 * calling gdk_window_invalidate_region() on the widget's window and
4478 * all its child windows. Once the main loop becomes idle (after the
4479 * current batch of events has been processed, roughly), the window
4480 * will receive expose events for the union of all regions that have
4483 * Normally you would only use this function in widget
4484 * implementations. You might also use it to schedule a redraw of a
4485 * #GtkDrawingArea or some portion thereof.
4490 gtk_widget_queue_draw_region (GtkWidget *widget,
4491 const cairo_region_t *region)
4493 GtkWidgetPrivate *priv;
4496 g_return_if_fail (GTK_IS_WIDGET (widget));
4498 priv = widget->priv;
4500 if (!gtk_widget_get_realized (widget))
4503 /* Just return if the widget or one of its ancestors isn't mapped */
4504 for (w = widget; w != NULL; w = w->priv->parent)
4505 if (!gtk_widget_get_mapped (w))
4508 gdk_window_invalidate_region (priv->window, region, TRUE);
4512 * gtk_widget_queue_draw_area:
4513 * @widget: a #GtkWidget
4514 * @x: x coordinate of upper-left corner of rectangle to redraw
4515 * @y: y coordinate of upper-left corner of rectangle to redraw
4516 * @width: width of region to draw
4517 * @height: height of region to draw
4519 * Convenience function that calls gtk_widget_queue_draw_region() on
4520 * the region created from the given coordinates.
4522 * The region here is specified in widget coordinates.
4523 * Widget coordinates are a bit odd; for historical reasons, they are
4524 * defined as @widget->window coordinates for widgets that are not
4525 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4526 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4529 gtk_widget_queue_draw_area (GtkWidget *widget,
4536 cairo_region_t *region;
4538 g_return_if_fail (GTK_IS_WIDGET (widget));
4543 rect.height = height;
4545 region = cairo_region_create_rectangle (&rect);
4546 gtk_widget_queue_draw_region (widget, region);
4547 cairo_region_destroy (region);
4551 * gtk_widget_queue_draw:
4552 * @widget: a #GtkWidget
4554 * Equivalent to calling gtk_widget_queue_draw_area() for the
4555 * entire area of a widget.
4558 gtk_widget_queue_draw (GtkWidget *widget)
4562 g_return_if_fail (GTK_IS_WIDGET (widget));
4564 gtk_widget_get_allocation (widget, &rect);
4566 if (!gtk_widget_get_has_window (widget))
4567 gtk_widget_queue_draw_area (widget,
4568 rect.x, rect.y, rect.width, rect.height);
4570 gtk_widget_queue_draw_area (widget,
4571 0, 0, rect.width, rect.height);
4575 * gtk_widget_queue_resize:
4576 * @widget: a #GtkWidget
4578 * This function is only for use in widget implementations.
4579 * Flags a widget to have its size renegotiated; should
4580 * be called when a widget for some reason has a new size request.
4581 * For example, when you change the text in a #GtkLabel, #GtkLabel
4582 * queues a resize to ensure there's enough space for the new text.
4584 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4585 * from inside its implementation of the GtkWidgetClass::size_allocate
4586 * virtual method. Calls to gtk_widget_queue_resize() from inside
4587 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4590 gtk_widget_queue_resize (GtkWidget *widget)
4592 g_return_if_fail (GTK_IS_WIDGET (widget));
4594 if (gtk_widget_get_realized (widget))
4595 gtk_widget_queue_shallow_draw (widget);
4597 _gtk_size_group_queue_resize (widget, 0);
4601 * gtk_widget_queue_resize_no_redraw:
4602 * @widget: a #GtkWidget
4604 * This function works like gtk_widget_queue_resize(),
4605 * except that the widget is not invalidated.
4610 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4612 g_return_if_fail (GTK_IS_WIDGET (widget));
4614 _gtk_size_group_queue_resize (widget, 0);
4618 * gtk_widget_size_request:
4619 * @widget: a #GtkWidget
4620 * @requisition: (out): a #GtkRequisition to be filled in
4622 * This function is typically used when implementing a #GtkContainer
4623 * subclass. Obtains the preferred size of a widget. The container
4624 * uses this information to arrange its child widgets and decide what
4625 * size allocations to give them with gtk_widget_size_allocate().
4627 * You can also call this function from an application, with some
4628 * caveats. Most notably, getting a size request requires the widget
4629 * to be associated with a screen, because font information may be
4630 * needed. Multihead-aware applications should keep this in mind.
4632 * Also remember that the size request is not necessarily the size
4633 * a widget will actually be allocated.
4635 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4638 gtk_widget_size_request (GtkWidget *widget,
4639 GtkRequisition *requisition)
4641 g_return_if_fail (GTK_IS_WIDGET (widget));
4643 gtk_widget_get_preferred_size (widget, requisition, NULL);
4647 * gtk_widget_get_child_requisition:
4648 * @widget: a #GtkWidget
4649 * @requisition: (out): a #GtkRequisition to be filled in
4651 * This function is only for use in widget implementations. Obtains
4652 * @widget->requisition, unless someone has forced a particular
4653 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4654 * in which case it returns that geometry instead of the widget's
4657 * This function differs from gtk_widget_size_request() in that
4658 * it retrieves the last size request value from @widget->requisition,
4659 * while gtk_widget_size_request() actually calls the "size_request" method
4660 * on @widget to compute the size request and fill in @widget->requisition,
4661 * and only then returns @widget->requisition.
4663 * Because this function does not call the "size_request" method, it
4664 * can only be used when you know that @widget->requisition is
4665 * up-to-date, that is, gtk_widget_size_request() has been called
4666 * since the last time a resize was queued. In general, only container
4667 * implementations have this information; applications should use
4668 * gtk_widget_size_request().
4671 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4674 gtk_widget_get_child_requisition (GtkWidget *widget,
4675 GtkRequisition *requisition)
4677 gtk_widget_get_preferred_size (widget, requisition, NULL);
4681 invalidate_predicate (GdkWindow *window,
4686 gdk_window_get_user_data (window, &user_data);
4688 return (user_data == data);
4691 /* Invalidate @region in widget->window and all children
4692 * of widget->window owned by widget. @region is in the
4693 * same coordinates as widget->allocation and will be
4694 * modified by this call.
4697 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4698 cairo_region_t *region)
4700 GtkWidgetPrivate *priv = widget->priv;
4702 if (!gtk_widget_get_realized (widget))
4705 if (gtk_widget_get_has_window (widget) && priv->parent)
4709 gdk_window_get_position (priv->window, &x, &y);
4710 cairo_region_translate (region, -x, -y);
4713 gdk_window_invalidate_maybe_recurse (priv->window, region,
4714 invalidate_predicate, widget);
4718 * gtk_widget_queue_shallow_draw:
4719 * @widget: a #GtkWidget
4721 * Like gtk_widget_queue_draw(), but only windows owned
4722 * by @widget are invalidated.
4725 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4728 cairo_region_t *region;
4730 if (!gtk_widget_get_realized (widget))
4733 gtk_widget_get_allocation (widget, &rect);
4735 region = cairo_region_create_rectangle (&rect);
4736 gtk_widget_invalidate_widget_windows (widget, region);
4737 cairo_region_destroy (region);
4741 * gtk_widget_size_allocate:
4742 * @widget: a #GtkWidget
4743 * @allocation: position and size to be allocated to @widget
4745 * This function is only used by #GtkContainer subclasses, to assign a size
4746 * and position to their child widgets.
4748 * In this function, the allocation may be adjusted. It will be forced
4749 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4750 * method on the child will be used to adjust the allocation. Standard
4751 * adjustments include removing the widget's margins, and applying the
4752 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4755 gtk_widget_size_allocate (GtkWidget *widget,
4756 GtkAllocation *allocation)
4758 GtkWidgetPrivate *priv;
4759 GdkRectangle real_allocation;
4760 GdkRectangle old_allocation;
4761 GdkRectangle adjusted_allocation;
4762 gboolean alloc_needed;
4763 gboolean size_changed;
4764 gboolean position_changed;
4765 gint natural_width, natural_height, dummy;
4766 gint min_width, min_height;
4768 priv = widget->priv;
4770 g_return_if_fail (GTK_IS_WIDGET (widget));
4772 gtk_widget_push_verify_invariants (widget);
4774 #ifdef G_ENABLE_DEBUG
4775 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4786 parent = gtk_widget_get_parent (parent);
4789 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4790 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4791 2 * depth, " ", name,
4792 allocation->width, allocation->height);
4794 #endif /* G_ENABLE_DEBUG */
4796 alloc_needed = priv->alloc_needed;
4797 if (!priv->width_request_needed && !priv->height_request_needed)
4798 /* Preserve request/allocate ordering */
4799 priv->alloc_needed = FALSE;
4801 old_allocation = priv->allocation;
4802 real_allocation = *allocation;
4804 adjusted_allocation = real_allocation;
4805 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4807 /* Go ahead and request the height for allocated width, note that the internals
4808 * of get_height_for_width will internally limit the for_size to natural size
4809 * when aligning implicitly.
4811 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4812 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4816 /* Go ahead and request the width for allocated height, note that the internals
4817 * of get_width_for_height will internally limit the for_size to natural size
4818 * when aligning implicitly.
4820 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4821 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4824 #ifdef G_ENABLE_DEBUG
4825 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4827 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4828 !GTK_IS_SCROLLABLE (widget))
4829 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4830 "Allocation is %dx%d, but minimum required size is %dx%d.",
4831 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4832 G_OBJECT_TYPE_NAME (widget), widget,
4833 real_allocation.width, real_allocation.height,
4834 min_width, min_height);
4837 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4838 * allocated sizes and possibly limit them to the natural sizes */
4839 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4840 GTK_ORIENTATION_HORIZONTAL,
4843 &adjusted_allocation.x,
4844 &adjusted_allocation.width);
4845 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4846 GTK_ORIENTATION_VERTICAL,
4849 &adjusted_allocation.y,
4850 &adjusted_allocation.height);
4852 if (adjusted_allocation.x < real_allocation.x ||
4853 adjusted_allocation.y < real_allocation.y ||
4854 (adjusted_allocation.x + adjusted_allocation.width) >
4855 (real_allocation.x + real_allocation.width) ||
4856 (adjusted_allocation.y + adjusted_allocation.height >
4857 real_allocation.y + real_allocation.height))
4859 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",
4860 G_OBJECT_TYPE_NAME (widget), widget,
4861 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4862 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4863 adjusted_allocation = real_allocation; /* veto it */
4867 real_allocation = adjusted_allocation;
4870 if (real_allocation.width < 0 || real_allocation.height < 0)
4872 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4873 real_allocation.width,
4874 real_allocation.height);
4877 real_allocation.width = MAX (real_allocation.width, 1);
4878 real_allocation.height = MAX (real_allocation.height, 1);
4880 size_changed = (old_allocation.width != real_allocation.width ||
4881 old_allocation.height != real_allocation.height);
4882 position_changed = (old_allocation.x != real_allocation.x ||
4883 old_allocation.y != real_allocation.y);
4885 if (!alloc_needed && !size_changed && !position_changed)
4888 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4890 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4891 priv->width_request_needed = FALSE;
4892 priv->height_request_needed = FALSE;
4893 priv->alloc_needed = FALSE;
4895 if (gtk_widget_get_mapped (widget))
4897 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4899 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4901 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4902 cairo_region_union_rectangle (invalidate, &old_allocation);
4904 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4905 cairo_region_destroy (invalidate);
4910 if (priv->redraw_on_alloc)
4912 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4914 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4915 cairo_region_union_rectangle (invalidate, &old_allocation);
4917 gtk_widget_invalidate_widget_windows (widget, invalidate);
4918 cairo_region_destroy (invalidate);
4922 if (size_changed || position_changed)
4924 GtkStyleContext *context;
4926 context = gtk_widget_get_style_context (widget);
4927 _gtk_style_context_invalidate_animation_areas (context);
4931 if ((size_changed || position_changed) && priv->parent &&
4932 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4934 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4935 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4936 cairo_region_destroy (invalidate);
4940 gtk_widget_pop_verify_invariants (widget);
4944 * gtk_widget_common_ancestor:
4945 * @widget_a: a #GtkWidget
4946 * @widget_b: a #GtkWidget
4948 * Find the common ancestor of @widget_a and @widget_b that
4949 * is closest to the two widgets.
4951 * Return value: the closest common ancestor of @widget_a and
4952 * @widget_b or %NULL if @widget_a and @widget_b do not
4953 * share a common ancestor.
4956 gtk_widget_common_ancestor (GtkWidget *widget_a,
4957 GtkWidget *widget_b)
4959 GtkWidget *parent_a;
4960 GtkWidget *parent_b;
4964 parent_a = widget_a;
4965 while (parent_a->priv->parent)
4967 parent_a = parent_a->priv->parent;
4971 parent_b = widget_b;
4972 while (parent_b->priv->parent)
4974 parent_b = parent_b->priv->parent;
4978 if (parent_a != parent_b)
4981 while (depth_a > depth_b)
4983 widget_a = widget_a->priv->parent;
4987 while (depth_b > depth_a)
4989 widget_b = widget_b->priv->parent;
4993 while (widget_a != widget_b)
4995 widget_a = widget_a->priv->parent;
4996 widget_b = widget_b->priv->parent;
5003 * gtk_widget_translate_coordinates:
5004 * @src_widget: a #GtkWidget
5005 * @dest_widget: a #GtkWidget
5006 * @src_x: X position relative to @src_widget
5007 * @src_y: Y position relative to @src_widget
5008 * @dest_x: (out): location to store X position relative to @dest_widget
5009 * @dest_y: (out): location to store Y position relative to @dest_widget
5011 * Translate coordinates relative to @src_widget's allocation to coordinates
5012 * relative to @dest_widget's allocations. In order to perform this
5013 * operation, both widgets must be realized, and must share a common
5016 * Return value: %FALSE if either widget was not realized, or there
5017 * was no common ancestor. In this case, nothing is stored in
5018 * *@dest_x and *@dest_y. Otherwise %TRUE.
5021 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5022 GtkWidget *dest_widget,
5028 GtkWidgetPrivate *src_priv = src_widget->priv;
5029 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5030 GtkWidget *ancestor;
5032 GList *dest_list = NULL;
5034 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5035 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5037 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5038 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5041 /* Translate from allocation relative to window relative */
5042 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5045 gdk_window_get_position (src_priv->window, &wx, &wy);
5047 src_x -= wx - src_priv->allocation.x;
5048 src_y -= wy - src_priv->allocation.y;
5052 src_x += src_priv->allocation.x;
5053 src_y += src_priv->allocation.y;
5056 /* Translate to the common ancestor */
5057 window = src_priv->window;
5058 while (window != ancestor->priv->window)
5062 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5067 window = gdk_window_get_effective_parent (window);
5069 if (!window) /* Handle GtkHandleBox */
5074 window = dest_priv->window;
5075 while (window != ancestor->priv->window)
5077 dest_list = g_list_prepend (dest_list, window);
5079 window = gdk_window_get_effective_parent (window);
5081 if (!window) /* Handle GtkHandleBox */
5083 g_list_free (dest_list);
5092 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5097 dest_list = g_list_remove (dest_list, dest_list->data);
5100 /* Translate from window relative to allocation relative */
5101 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5104 gdk_window_get_position (dest_priv->window, &wx, &wy);
5106 src_x += wx - dest_priv->allocation.x;
5107 src_y += wy - dest_priv->allocation.y;
5111 src_x -= dest_priv->allocation.x;
5112 src_y -= dest_priv->allocation.y;
5124 gtk_widget_real_size_allocate (GtkWidget *widget,
5125 GtkAllocation *allocation)
5127 GtkWidgetPrivate *priv = widget->priv;
5129 priv->allocation = *allocation;
5131 if (gtk_widget_get_realized (widget) &&
5132 gtk_widget_get_has_window (widget))
5134 gdk_window_move_resize (priv->window,
5135 allocation->x, allocation->y,
5136 allocation->width, allocation->height);
5140 /* translate initial/final into start/end */
5142 effective_align (GtkAlign align,
5143 GtkTextDirection direction)
5147 case GTK_ALIGN_START:
5148 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5150 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5157 adjust_for_align (GtkAlign align,
5159 gint *allocated_pos,
5160 gint *allocated_size)
5164 case GTK_ALIGN_FILL:
5165 /* change nothing */
5167 case GTK_ALIGN_START:
5168 /* keep *allocated_pos where it is */
5169 *allocated_size = MIN (*allocated_size, *natural_size);
5172 if (*allocated_size > *natural_size)
5174 *allocated_pos += (*allocated_size - *natural_size);
5175 *allocated_size = *natural_size;
5178 case GTK_ALIGN_CENTER:
5179 if (*allocated_size > *natural_size)
5181 *allocated_pos += (*allocated_size - *natural_size) / 2;
5182 *allocated_size = MIN (*allocated_size, *natural_size);
5189 adjust_for_margin(gint start_margin,
5193 gint *allocated_pos,
5194 gint *allocated_size)
5196 *minimum_size -= (start_margin + end_margin);
5197 *natural_size -= (start_margin + end_margin);
5198 *allocated_pos += start_margin;
5199 *allocated_size -= (start_margin + end_margin);
5203 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5204 GtkOrientation orientation,
5207 gint *allocated_pos,
5208 gint *allocated_size)
5210 const GtkWidgetAuxInfo *aux_info;
5212 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5214 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5216 adjust_for_margin (aux_info->margin.left,
5217 aux_info->margin.right,
5218 minimum_size, natural_size,
5219 allocated_pos, allocated_size);
5220 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5221 natural_size, allocated_pos, allocated_size);
5225 adjust_for_margin (aux_info->margin.top,
5226 aux_info->margin.bottom,
5227 minimum_size, natural_size,
5228 allocated_pos, allocated_size);
5229 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5230 natural_size, allocated_pos, allocated_size);
5235 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5238 GtkWidgetPrivate *priv = widget->priv;
5240 /* widgets must be onscreen for accels to take effect */
5241 return gtk_widget_is_sensitive (widget) &&
5242 gtk_widget_is_drawable (widget) &&
5243 gdk_window_is_viewable (priv->window);
5247 * gtk_widget_can_activate_accel:
5248 * @widget: a #GtkWidget
5249 * @signal_id: the ID of a signal installed on @widget
5251 * Determines whether an accelerator that activates the signal
5252 * identified by @signal_id can currently be activated.
5253 * This is done by emitting the #GtkWidget::can-activate-accel
5254 * signal on @widget; if the signal isn't overridden by a
5255 * handler or in a derived widget, then the default check is
5256 * that the widget must be sensitive, and the widget and all
5257 * its ancestors mapped.
5259 * Return value: %TRUE if the accelerator can be activated.
5264 gtk_widget_can_activate_accel (GtkWidget *widget,
5267 gboolean can_activate = FALSE;
5268 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5269 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5270 return can_activate;
5279 closure_accel_activate (GClosure *closure,
5280 GValue *return_value,
5281 guint n_param_values,
5282 const GValue *param_values,
5283 gpointer invocation_hint,
5284 gpointer marshal_data)
5286 AccelClosure *aclosure = (AccelClosure*) closure;
5287 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5290 g_signal_emit (closure->data, aclosure->signal_id, 0);
5292 /* whether accelerator was handled */
5293 g_value_set_boolean (return_value, can_activate);
5297 closures_destroy (gpointer data)
5299 GSList *slist, *closures = data;
5301 for (slist = closures; slist; slist = slist->next)
5303 g_closure_invalidate (slist->data);
5304 g_closure_unref (slist->data);
5306 g_slist_free (closures);
5310 widget_new_accel_closure (GtkWidget *widget,
5313 AccelClosure *aclosure;
5314 GClosure *closure = NULL;
5315 GSList *slist, *closures;
5317 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5318 for (slist = closures; slist; slist = slist->next)
5319 if (!gtk_accel_group_from_accel_closure (slist->data))
5321 /* reuse this closure */
5322 closure = slist->data;
5327 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5328 closures = g_slist_prepend (closures, g_closure_ref (closure));
5329 g_closure_sink (closure);
5330 g_closure_set_marshal (closure, closure_accel_activate);
5332 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5334 aclosure = (AccelClosure*) closure;
5335 g_assert (closure->data == widget);
5336 g_assert (closure->marshal == closure_accel_activate);
5337 aclosure->signal_id = signal_id;
5343 * gtk_widget_add_accelerator
5344 * @widget: widget to install an accelerator on
5345 * @accel_signal: widget signal to emit on accelerator activation
5346 * @accel_group: accel group for this widget, added to its toplevel
5347 * @accel_key: GDK keyval of the accelerator
5348 * @accel_mods: modifier key combination of the accelerator
5349 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5351 * Installs an accelerator for this @widget in @accel_group that causes
5352 * @accel_signal to be emitted if the accelerator is activated.
5353 * The @accel_group needs to be added to the widget's toplevel via
5354 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5355 * Accelerators added through this function are not user changeable during
5356 * runtime. If you want to support accelerators that can be changed by the
5357 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5358 * gtk_menu_item_set_accel_path() instead.
5361 gtk_widget_add_accelerator (GtkWidget *widget,
5362 const gchar *accel_signal,
5363 GtkAccelGroup *accel_group,
5365 GdkModifierType accel_mods,
5366 GtkAccelFlags accel_flags)
5371 g_return_if_fail (GTK_IS_WIDGET (widget));
5372 g_return_if_fail (accel_signal != NULL);
5373 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5375 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5376 if (!query.signal_id ||
5377 !(query.signal_flags & G_SIGNAL_ACTION) ||
5378 query.return_type != G_TYPE_NONE ||
5381 /* hmm, should be elaborate enough */
5382 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5383 G_OBJECT_TYPE_NAME (widget), accel_signal);
5387 closure = widget_new_accel_closure (widget, query.signal_id);
5389 g_object_ref (widget);
5391 /* install the accelerator. since we don't map this onto an accel_path,
5392 * the accelerator will automatically be locked.
5394 gtk_accel_group_connect (accel_group,
5397 accel_flags | GTK_ACCEL_LOCKED,
5400 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5402 g_object_unref (widget);
5406 * gtk_widget_remove_accelerator:
5407 * @widget: widget to install an accelerator on
5408 * @accel_group: accel group for this widget
5409 * @accel_key: GDK keyval of the accelerator
5410 * @accel_mods: modifier key combination of the accelerator
5412 * Removes an accelerator from @widget, previously installed with
5413 * gtk_widget_add_accelerator().
5415 * Returns: whether an accelerator was installed and could be removed
5418 gtk_widget_remove_accelerator (GtkWidget *widget,
5419 GtkAccelGroup *accel_group,
5421 GdkModifierType accel_mods)
5423 GtkAccelGroupEntry *ag_entry;
5424 GList *slist, *clist;
5427 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5428 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5430 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5431 clist = gtk_widget_list_accel_closures (widget);
5432 for (slist = clist; slist; slist = slist->next)
5436 for (i = 0; i < n; i++)
5437 if (slist->data == (gpointer) ag_entry[i].closure)
5439 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5441 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5443 g_list_free (clist);
5448 g_list_free (clist);
5450 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5451 accel_key, accel_mods, accel_group,
5452 G_OBJECT_TYPE_NAME (widget), widget);
5458 * gtk_widget_list_accel_closures:
5459 * @widget: widget to list accelerator closures for
5461 * Lists the closures used by @widget for accelerator group connections
5462 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5463 * The closures can be used to monitor accelerator changes on @widget,
5464 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5465 * #GtkAccelGroup of a closure which can be found out with
5466 * gtk_accel_group_from_accel_closure().
5468 * Return value: (transfer container) (element-type GClosure):
5469 * a newly allocated #GList of closures
5472 gtk_widget_list_accel_closures (GtkWidget *widget)
5475 GList *clist = NULL;
5477 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5479 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5480 if (gtk_accel_group_from_accel_closure (slist->data))
5481 clist = g_list_prepend (clist, slist->data);
5487 GtkAccelGroup *accel_group;
5492 destroy_accel_path (gpointer data)
5494 AccelPath *apath = data;
5496 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5498 /* closures_destroy takes care of unrefing the closure */
5499 g_object_unref (apath->accel_group);
5501 g_slice_free (AccelPath, apath);
5506 * gtk_widget_set_accel_path:
5507 * @widget: a #GtkWidget
5508 * @accel_path: (allow-none): path used to look up the accelerator
5509 * @accel_group: (allow-none): a #GtkAccelGroup.
5511 * Given an accelerator group, @accel_group, and an accelerator path,
5512 * @accel_path, sets up an accelerator in @accel_group so whenever the
5513 * key binding that is defined for @accel_path is pressed, @widget
5514 * will be activated. This removes any accelerators (for any
5515 * accelerator group) installed by previous calls to
5516 * gtk_widget_set_accel_path(). Associating accelerators with
5517 * paths allows them to be modified by the user and the modifications
5518 * to be saved for future use. (See gtk_accel_map_save().)
5520 * This function is a low level function that would most likely
5521 * be used by a menu creation system like #GtkUIManager. If you
5522 * use #GtkUIManager, setting up accelerator paths will be done
5525 * Even when you you aren't using #GtkUIManager, if you only want to
5526 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5527 * provides a somewhat more convenient interface.
5529 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5530 * pass a static string, you can save some memory by interning it first with
5531 * g_intern_static_string().
5534 gtk_widget_set_accel_path (GtkWidget *widget,
5535 const gchar *accel_path,
5536 GtkAccelGroup *accel_group)
5540 g_return_if_fail (GTK_IS_WIDGET (widget));
5541 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5545 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5546 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5548 gtk_accel_map_add_entry (accel_path, 0, 0);
5549 apath = g_slice_new (AccelPath);
5550 apath->accel_group = g_object_ref (accel_group);
5551 apath->path_quark = g_quark_from_string (accel_path);
5552 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5557 /* also removes possible old settings */
5558 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5561 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5563 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5567 _gtk_widget_get_accel_path (GtkWidget *widget,
5572 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5574 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5576 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5577 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5581 * gtk_widget_mnemonic_activate:
5582 * @widget: a #GtkWidget
5583 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5585 * Emits the #GtkWidget::mnemonic-activate signal.
5587 * The default handler for this signal activates the @widget if
5588 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5591 * Returns: %TRUE if the signal has been handled
5594 gtk_widget_mnemonic_activate (GtkWidget *widget,
5595 gboolean group_cycling)
5599 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5601 group_cycling = group_cycling != FALSE;
5602 if (!gtk_widget_is_sensitive (widget))
5605 g_signal_emit (widget,
5606 widget_signals[MNEMONIC_ACTIVATE],
5614 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5615 gboolean group_cycling)
5617 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5618 gtk_widget_activate (widget);
5619 else if (gtk_widget_get_can_focus (widget))
5620 gtk_widget_grab_focus (widget);
5623 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5624 G_OBJECT_TYPE_NAME (widget));
5625 gtk_widget_error_bell (widget);
5630 static const cairo_user_data_key_t event_key;
5633 _gtk_cairo_get_event (cairo_t *cr)
5635 g_return_val_if_fail (cr != NULL, NULL);
5637 return cairo_get_user_data (cr, &event_key);
5641 gtk_cairo_set_event (cairo_t *cr,
5642 GdkEventExpose *event)
5644 cairo_set_user_data (cr, &event_key, event, NULL);
5648 * gtk_cairo_should_draw_window:
5649 * @cr: a cairo context
5650 * @window: the window to check. @window may not be an input-only
5653 * This function is supposed to be called in #GtkWidget::draw
5654 * implementations for widgets that support multiple windows.
5655 * @cr must be untransformed from invoking of the draw function.
5656 * This function will return %TRUE if the contents of the given
5657 * @window are supposed to be drawn and %FALSE otherwise. Note
5658 * that when the drawing was not initiated by the windowing
5659 * system this function will return %TRUE for all windows, so
5660 * you need to draw the bottommost window first. Also, do not
5661 * use "else if" statements to check which window should be drawn.
5663 * Returns: %TRUE if @window should be drawn
5668 gtk_cairo_should_draw_window (cairo_t *cr,
5671 GdkEventExpose *event;
5673 g_return_val_if_fail (cr != NULL, FALSE);
5674 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5676 event = _gtk_cairo_get_event (cr);
5678 return event == NULL ||
5679 event->window == window;
5683 gtk_widget_get_clip_draw (GtkWidget *widget)
5685 /* labels are not clipped, because clipping them would cause
5686 * mnemonics to not appear on characters that go beyond the
5688 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5690 if (GTK_IS_LABEL (widget))
5696 /* code shared by gtk_container_propagate_draw() and
5700 _gtk_widget_draw_internal (GtkWidget *widget,
5702 gboolean clip_to_size)
5704 GtkStyleContext *context;
5706 if (!gtk_widget_is_drawable (widget))
5709 clip_to_size &= gtk_widget_get_clip_draw (widget);
5713 cairo_rectangle (cr,
5715 widget->priv->allocation.width,
5716 widget->priv->allocation.height);
5720 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5724 g_signal_emit (widget, widget_signals[DRAW],
5729 context = gtk_widget_get_style_context (widget);
5730 _gtk_style_context_coalesce_animation_areas (context, widget);
5735 * @widget: the widget to draw. It must be drawable (see
5736 * gtk_widget_is_drawable()) and a size must have been allocated.
5737 * @cr: a cairo context to draw to
5739 * Draws @widget to @cr. The top left corner of the widget will be
5740 * drawn to the currently set origin point of @cr.
5742 * You should pass a cairo context as @cr argument that is in an
5743 * original state. Otherwise the resulting drawing is undefined. For
5744 * example changing the operator using cairo_set_operator() or the
5745 * line width using cairo_set_line_width() might have unwanted side
5747 * You may however change the context's transform matrix - like with
5748 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5749 * region with cairo_clip() prior to calling this function. Also, it
5750 * is fine to modify the context with cairo_save() and
5751 * cairo_push_group() prior to calling this function.
5753 * <note><para>Special purpose widgets may contain special code for
5754 * rendering to the screen and might appear differently on screen
5755 * and when rendered using gtk_widget_draw().</para></note>
5760 gtk_widget_draw (GtkWidget *widget,
5763 GdkEventExpose *tmp_event;
5765 g_return_if_fail (GTK_IS_WIDGET (widget));
5766 g_return_if_fail (!widget->priv->alloc_needed);
5767 g_return_if_fail (cr != NULL);
5770 /* We have to reset the event here so that draw functions can call
5771 * gtk_widget_draw() on random other widgets and get the desired
5772 * effect: Drawing all contents, not just the current window.
5774 tmp_event = _gtk_cairo_get_event (cr);
5775 gtk_cairo_set_event (cr, NULL);
5777 _gtk_widget_draw_internal (widget, cr, TRUE);
5779 gtk_cairo_set_event (cr, tmp_event);
5784 gtk_widget_real_key_press_event (GtkWidget *widget,
5787 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5791 gtk_widget_real_key_release_event (GtkWidget *widget,
5794 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5798 gtk_widget_real_focus_in_event (GtkWidget *widget,
5799 GdkEventFocus *event)
5801 gtk_widget_queue_shallow_draw (widget);
5807 gtk_widget_real_focus_out_event (GtkWidget *widget,
5808 GdkEventFocus *event)
5810 gtk_widget_queue_shallow_draw (widget);
5815 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5816 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5820 * @widget: a #GtkWidget
5821 * @event: a #GdkEvent
5823 * Rarely-used function. This function is used to emit
5824 * the event signals on a widget (those signals should never
5825 * be emitted without using this function to do so).
5826 * If you want to synthesize an event though, don't use this function;
5827 * instead, use gtk_main_do_event() so the event will behave as if
5828 * it were in the event queue. Don't synthesize expose events; instead,
5829 * use gdk_window_invalidate_rect() to invalidate a region of the
5832 * Return value: return from the event signal emission (%TRUE if
5833 * the event was handled)
5836 gtk_widget_event (GtkWidget *widget,
5839 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5840 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5842 if (event->type == GDK_EXPOSE)
5844 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5845 "the same effect, call gdk_window_invalidate_rect/region(), "
5846 "followed by gdk_window_process_updates().");
5850 return gtk_widget_event_internal (widget, event);
5853 /* Returns TRUE if a translation should be done */
5855 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5860 GdkWindow *w, *widget_window;
5862 if (!gtk_widget_get_has_window (widget))
5864 *x = -widget->priv->allocation.x;
5865 *y = -widget->priv->allocation.y;
5873 widget_window = gtk_widget_get_window (widget);
5875 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5878 gdk_window_get_position (w, &wx, &wy);
5895 * gtk_cairo_transform_to_window:
5896 * @cr: the cairo context to transform
5897 * @widget: the widget the context is currently centered for
5898 * @window: the window to transform the context to
5900 * Transforms the given cairo context @cr that from @widget-relative
5901 * coordinates to @window-relative coordinates.
5902 * If the @widget's window is not an ancestor of @window, no
5903 * modification will be applied.
5905 * This is the inverse to the transformation GTK applies when
5906 * preparing an expose event to be emitted with the #GtkWidget::draw
5907 * signal. It is intended to help porting multiwindow widgets from
5908 * GTK+ 2 to the rendering architecture of GTK+ 3.
5913 gtk_cairo_transform_to_window (cairo_t *cr,
5919 g_return_if_fail (cr != NULL);
5920 g_return_if_fail (GTK_IS_WIDGET (widget));
5921 g_return_if_fail (GDK_IS_WINDOW (window));
5923 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5924 cairo_translate (cr, x, y);
5928 * gtk_widget_send_expose:
5929 * @widget: a #GtkWidget
5930 * @event: a expose #GdkEvent
5932 * Very rarely-used function. This function is used to emit
5933 * an expose event on a widget. This function is not normally used
5934 * directly. The only time it is used is when propagating an expose
5935 * event to a child %NO_WINDOW widget, and that is normally done
5936 * using gtk_container_propagate_draw().
5938 * If you want to force an area of a window to be redrawn,
5939 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5940 * To cause the redraw to be done immediately, follow that call
5941 * with a call to gdk_window_process_updates().
5943 * Return value: return from the event signal emission (%TRUE if
5944 * the event was handled)
5947 gtk_widget_send_expose (GtkWidget *widget,
5950 gboolean result = FALSE;
5955 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5956 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5957 g_return_val_if_fail (event != NULL, TRUE);
5958 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5960 cr = gdk_cairo_create (event->expose.window);
5961 gtk_cairo_set_event (cr, &event->expose);
5963 gdk_cairo_region (cr, event->expose.region);
5966 do_clip = _gtk_widget_get_translation_to_window (widget,
5967 event->expose.window,
5969 cairo_translate (cr, -x, -y);
5971 _gtk_widget_draw_internal (widget, cr, do_clip);
5973 /* unset here, so if someone keeps a reference to cr we
5974 * don't leak the window. */
5975 gtk_cairo_set_event (cr, NULL);
5982 event_window_is_still_viewable (GdkEvent *event)
5984 /* Check that we think the event's window is viewable before
5985 * delivering the event, to prevent suprises. We do this here
5986 * at the last moment, since the event may have been queued
5987 * up behind other events, held over a recursive main loop, etc.
5989 switch (event->type)
5992 case GDK_MOTION_NOTIFY:
5993 case GDK_BUTTON_PRESS:
5994 case GDK_2BUTTON_PRESS:
5995 case GDK_3BUTTON_PRESS:
5997 case GDK_ENTER_NOTIFY:
5998 case GDK_PROXIMITY_IN:
6000 return event->any.window && gdk_window_is_viewable (event->any.window);
6003 /* The following events are the second half of paired events;
6004 * we always deliver them to deal with widgets that clean up
6005 * on the second half.
6007 case GDK_BUTTON_RELEASE:
6008 case GDK_KEY_RELEASE:
6009 case GDK_LEAVE_NOTIFY:
6010 case GDK_PROXIMITY_OUT:
6014 /* Remaining events would make sense on an not-viewable window,
6015 * or don't have an associated window.
6022 gtk_widget_event_internal (GtkWidget *widget,
6025 gboolean return_val = FALSE;
6027 /* We check only once for is-still-visible; if someone
6028 * hides the window in on of the signals on the widget,
6029 * they are responsible for returning TRUE to terminate
6032 if (!event_window_is_still_viewable (event))
6035 g_object_ref (widget);
6037 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6038 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6043 switch (event->type)
6049 case GDK_BUTTON_PRESS:
6050 case GDK_2BUTTON_PRESS:
6051 case GDK_3BUTTON_PRESS:
6052 signal_num = BUTTON_PRESS_EVENT;
6055 signal_num = SCROLL_EVENT;
6057 case GDK_BUTTON_RELEASE:
6058 signal_num = BUTTON_RELEASE_EVENT;
6060 case GDK_MOTION_NOTIFY:
6061 signal_num = MOTION_NOTIFY_EVENT;
6064 signal_num = DELETE_EVENT;
6067 signal_num = DESTROY_EVENT;
6068 _gtk_tooltip_hide (widget);
6071 signal_num = KEY_PRESS_EVENT;
6073 case GDK_KEY_RELEASE:
6074 signal_num = KEY_RELEASE_EVENT;
6076 case GDK_ENTER_NOTIFY:
6077 signal_num = ENTER_NOTIFY_EVENT;
6079 case GDK_LEAVE_NOTIFY:
6080 signal_num = LEAVE_NOTIFY_EVENT;
6082 case GDK_FOCUS_CHANGE:
6083 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6084 if (event->focus_change.in)
6085 _gtk_tooltip_focus_in (widget);
6087 _gtk_tooltip_focus_out (widget);
6090 signal_num = CONFIGURE_EVENT;
6093 signal_num = MAP_EVENT;
6096 signal_num = UNMAP_EVENT;
6098 case GDK_WINDOW_STATE:
6099 signal_num = WINDOW_STATE_EVENT;
6101 case GDK_PROPERTY_NOTIFY:
6102 signal_num = PROPERTY_NOTIFY_EVENT;
6104 case GDK_SELECTION_CLEAR:
6105 signal_num = SELECTION_CLEAR_EVENT;
6107 case GDK_SELECTION_REQUEST:
6108 signal_num = SELECTION_REQUEST_EVENT;
6110 case GDK_SELECTION_NOTIFY:
6111 signal_num = SELECTION_NOTIFY_EVENT;
6113 case GDK_PROXIMITY_IN:
6114 signal_num = PROXIMITY_IN_EVENT;
6116 case GDK_PROXIMITY_OUT:
6117 signal_num = PROXIMITY_OUT_EVENT;
6119 case GDK_VISIBILITY_NOTIFY:
6120 signal_num = VISIBILITY_NOTIFY_EVENT;
6122 case GDK_GRAB_BROKEN:
6123 signal_num = GRAB_BROKEN_EVENT;
6126 signal_num = DAMAGE_EVENT;
6129 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6133 if (signal_num != -1)
6134 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6136 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6137 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6141 g_object_unref (widget);
6147 * gtk_widget_activate:
6148 * @widget: a #GtkWidget that's activatable
6150 * For widgets that can be "activated" (buttons, menu items, etc.)
6151 * this function activates them. Activation is what happens when you
6152 * press Enter on a widget during key navigation. If @widget isn't
6153 * activatable, the function returns %FALSE.
6155 * Return value: %TRUE if the widget was activatable
6158 gtk_widget_activate (GtkWidget *widget)
6160 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6162 if (WIDGET_CLASS (widget)->activate_signal)
6164 /* FIXME: we should eventually check the signals signature here */
6165 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6174 gtk_widget_reparent_subwindows (GtkWidget *widget,
6175 GdkWindow *new_window)
6177 GtkWidgetPrivate *priv = widget->priv;
6179 if (!gtk_widget_get_has_window (widget))
6181 GList *children = gdk_window_get_children (priv->window);
6184 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6186 GdkWindow *window = tmp_list->data;
6189 gdk_window_get_user_data (window, &child);
6190 while (child && child != widget)
6191 child = ((GtkWidget*) child)->priv->parent;
6194 gdk_window_reparent (window, new_window, 0, 0);
6197 g_list_free (children);
6202 GList *tmp_list, *children;
6204 parent = gdk_window_get_parent (priv->window);
6207 gdk_window_reparent (priv->window, new_window, 0, 0);
6210 children = gdk_window_get_children (parent);
6212 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6214 GdkWindow *window = tmp_list->data;
6217 gdk_window_get_user_data (window, &child);
6219 if (child == widget)
6220 gdk_window_reparent (window, new_window, 0, 0);
6223 g_list_free (children);
6229 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6230 gpointer client_data)
6232 GtkWidgetPrivate *priv = widget->priv;
6234 g_assert (client_data != NULL);
6236 if (!gtk_widget_get_has_window (widget))
6239 g_object_unref (priv->window);
6240 priv->window = (GdkWindow*) client_data;
6242 g_object_ref (priv->window);
6244 if (GTK_IS_CONTAINER (widget))
6245 gtk_container_forall (GTK_CONTAINER (widget),
6246 gtk_widget_reparent_fixup_child,
6252 * gtk_widget_reparent:
6253 * @widget: a #GtkWidget
6254 * @new_parent: a #GtkContainer to move the widget into
6256 * Moves a widget from one #GtkContainer to another, handling reference
6257 * count issues to avoid destroying the widget.
6260 gtk_widget_reparent (GtkWidget *widget,
6261 GtkWidget *new_parent)
6263 GtkWidgetPrivate *priv;
6265 g_return_if_fail (GTK_IS_WIDGET (widget));
6266 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6267 priv = widget->priv;
6268 g_return_if_fail (priv->parent != NULL);
6270 if (priv->parent != new_parent)
6272 /* First try to see if we can get away without unrealizing
6273 * the widget as we reparent it. if so we set a flag so
6274 * that gtk_widget_unparent doesn't unrealize widget
6276 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6277 priv->in_reparent = TRUE;
6279 g_object_ref (widget);
6280 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6281 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6282 g_object_unref (widget);
6284 if (priv->in_reparent)
6286 priv->in_reparent = FALSE;
6288 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6289 gtk_widget_reparent_fixup_child (widget,
6290 gtk_widget_get_parent_window (widget));
6293 g_object_notify (G_OBJECT (widget), "parent");
6298 * gtk_widget_intersect:
6299 * @widget: a #GtkWidget
6300 * @area: a rectangle
6301 * @intersection: rectangle to store intersection of @widget and @area
6303 * Computes the intersection of a @widget's area and @area, storing
6304 * the intersection in @intersection, and returns %TRUE if there was
6305 * an intersection. @intersection may be %NULL if you're only
6306 * interested in whether there was an intersection.
6308 * Return value: %TRUE if there was an intersection
6311 gtk_widget_intersect (GtkWidget *widget,
6312 const GdkRectangle *area,
6313 GdkRectangle *intersection)
6315 GtkWidgetPrivate *priv;
6320 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6321 g_return_val_if_fail (area != NULL, FALSE);
6323 priv = widget->priv;
6326 dest = intersection;
6330 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6332 if (return_val && intersection && gtk_widget_get_has_window (widget))
6334 intersection->x -= priv->allocation.x;
6335 intersection->y -= priv->allocation.y;
6342 * gtk_widget_region_intersect:
6343 * @widget: a #GtkWidget
6344 * @region: a #cairo_region_t, in the same coordinate system as
6345 * @widget->allocation. That is, relative to @widget->window
6346 * for %NO_WINDOW widgets; relative to the parent window
6347 * of @widget->window for widgets with their own window.
6349 * Computes the intersection of a @widget's area and @region, returning
6350 * the intersection. The result may be empty, use cairo_region_is_empty() to
6353 * Returns: A newly allocated region holding the intersection of @widget
6354 * and @region. The coordinates of the return value are relative to
6355 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6356 * window of @widget->window for widgets with their own window.
6359 gtk_widget_region_intersect (GtkWidget *widget,
6360 const cairo_region_t *region)
6363 cairo_region_t *dest;
6365 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6366 g_return_val_if_fail (region != NULL, NULL);
6368 gtk_widget_get_allocation (widget, &rect);
6370 dest = cairo_region_create_rectangle (&rect);
6372 cairo_region_intersect (dest, region);
6378 * _gtk_widget_grab_notify:
6379 * @widget: a #GtkWidget
6380 * @was_grabbed: whether a grab is now in effect
6382 * Emits the #GtkWidget::grab-notify signal on @widget.
6387 _gtk_widget_grab_notify (GtkWidget *widget,
6388 gboolean was_grabbed)
6390 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6394 * gtk_widget_grab_focus:
6395 * @widget: a #GtkWidget
6397 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6398 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6399 * something like #GtkFrame won't work.
6401 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6402 * gtk_widget_set_can_focus() to modify that flag.
6404 * The widget also needs to be realized and mapped. This is indicated by the
6405 * related signals. Grabbing the focus immediately after creating the widget
6406 * will likely fail and cause critical warnings.
6409 gtk_widget_grab_focus (GtkWidget *widget)
6411 g_return_if_fail (GTK_IS_WIDGET (widget));
6413 if (!gtk_widget_is_sensitive (widget))
6416 g_object_ref (widget);
6417 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6418 g_object_notify (G_OBJECT (widget), "has-focus");
6419 g_object_unref (widget);
6423 reset_focus_recurse (GtkWidget *widget,
6426 if (GTK_IS_CONTAINER (widget))
6428 GtkContainer *container;
6430 container = GTK_CONTAINER (widget);
6431 gtk_container_set_focus_child (container, NULL);
6433 gtk_container_foreach (container,
6434 reset_focus_recurse,
6440 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6442 if (gtk_widget_get_can_focus (focus_widget))
6444 GtkWidget *toplevel;
6447 /* clear the current focus setting, break if the current widget
6448 * is the focus widget's parent, since containers above that will
6449 * be set by the next loop.
6451 toplevel = gtk_widget_get_toplevel (focus_widget);
6452 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6454 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6456 if (widget == focus_widget)
6458 /* We call _gtk_window_internal_set_focus() here so that the
6459 * toplevel window can request the focus if necessary.
6460 * This is needed when the toplevel is a GtkPlug
6462 if (!gtk_widget_has_focus (widget))
6463 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6470 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6472 if (widget != common_ancestor)
6474 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6476 widget = widget->priv->parent;
6477 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6482 else if (toplevel != focus_widget)
6484 /* gtk_widget_grab_focus() operates on a tree without window...
6485 * actually, this is very questionable behaviour.
6488 gtk_container_foreach (GTK_CONTAINER (toplevel),
6489 reset_focus_recurse,
6493 /* now propagate the new focus up the widget tree and finally
6494 * set it on the window
6496 widget = focus_widget;
6497 while (widget->priv->parent)
6499 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6500 widget = widget->priv->parent;
6502 if (GTK_IS_WINDOW (widget))
6503 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6508 gtk_widget_real_query_tooltip (GtkWidget *widget,
6511 gboolean keyboard_tip,
6512 GtkTooltip *tooltip)
6514 gchar *tooltip_markup;
6515 gboolean has_tooltip;
6517 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6518 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6520 if (has_tooltip && tooltip_markup)
6522 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6530 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6531 GtkStateFlags old_state)
6533 gtk_widget_update_pango_context (widget);
6537 gtk_widget_real_style_updated (GtkWidget *widget)
6539 GtkWidgetPrivate *priv = widget->priv;
6541 gtk_widget_update_pango_context (widget);
6543 if (priv->style != NULL &&
6544 priv->style != gtk_widget_get_default_style ())
6546 /* Trigger ::style-set for old
6547 * widgets not listening to this
6549 g_signal_emit (widget,
6550 widget_signals[STYLE_SET],
6552 widget->priv->style);
6555 if (widget->priv->context)
6557 if (gtk_widget_get_realized (widget) &&
6558 gtk_widget_get_has_window (widget))
6559 gtk_style_context_set_background (widget->priv->context,
6560 widget->priv->window);
6563 if (widget->priv->anchored)
6564 gtk_widget_queue_resize (widget);
6568 gtk_widget_real_show_help (GtkWidget *widget,
6569 GtkWidgetHelpType help_type)
6571 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6573 _gtk_tooltip_toggle_keyboard_mode (widget);
6582 gtk_widget_real_focus (GtkWidget *widget,
6583 GtkDirectionType direction)
6585 if (!gtk_widget_get_can_focus (widget))
6588 if (!gtk_widget_is_focus (widget))
6590 gtk_widget_grab_focus (widget);
6598 gtk_widget_real_move_focus (GtkWidget *widget,
6599 GtkDirectionType direction)
6601 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6603 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6605 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6611 gtk_widget_real_keynav_failed (GtkWidget *widget,
6612 GtkDirectionType direction)
6614 gboolean cursor_only;
6618 case GTK_DIR_TAB_FORWARD:
6619 case GTK_DIR_TAB_BACKWARD:
6626 g_object_get (gtk_widget_get_settings (widget),
6627 "gtk-keynav-cursor-only", &cursor_only,
6634 gtk_widget_error_bell (widget);
6640 * gtk_widget_set_can_focus:
6641 * @widget: a #GtkWidget
6642 * @can_focus: whether or not @widget can own the input focus.
6644 * Specifies whether @widget can own the input focus. See
6645 * gtk_widget_grab_focus() for actually setting the input focus on a
6651 gtk_widget_set_can_focus (GtkWidget *widget,
6654 g_return_if_fail (GTK_IS_WIDGET (widget));
6656 if (widget->priv->can_focus != can_focus)
6658 widget->priv->can_focus = can_focus;
6660 gtk_widget_queue_resize (widget);
6661 g_object_notify (G_OBJECT (widget), "can-focus");
6666 * gtk_widget_get_can_focus:
6667 * @widget: a #GtkWidget
6669 * Determines whether @widget can own the input focus. See
6670 * gtk_widget_set_can_focus().
6672 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6677 gtk_widget_get_can_focus (GtkWidget *widget)
6679 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6681 return widget->priv->can_focus;
6685 * gtk_widget_has_focus:
6686 * @widget: a #GtkWidget
6688 * Determines if the widget has the global input focus. See
6689 * gtk_widget_is_focus() for the difference between having the global
6690 * input focus, and only having the focus within a toplevel.
6692 * Return value: %TRUE if the widget has the global input focus.
6697 gtk_widget_has_focus (GtkWidget *widget)
6699 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6701 return widget->priv->has_focus;
6705 * gtk_widget_has_visible_focus:
6706 * @widget: a #GtkWidget
6708 * Determines if the widget should show a visible indication that
6709 * it has the global input focus. This is a convenience function for
6710 * use in ::draw handlers that takes into account whether focus
6711 * indication should currently be shown in the toplevel window of
6712 * @widget. See gtk_window_get_focus_visible() for more information
6713 * about focus indication.
6715 * To find out if the widget has the global input focus, use
6716 * gtk_widget_has_focus().
6718 * Return value: %TRUE if the widget should display a 'focus rectangle'
6723 gtk_widget_has_visible_focus (GtkWidget *widget)
6725 gboolean draw_focus;
6727 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6729 if (widget->priv->has_focus)
6731 GtkWidget *toplevel;
6733 toplevel = gtk_widget_get_toplevel (widget);
6735 if (GTK_IS_WINDOW (toplevel))
6736 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
6747 * gtk_widget_is_focus:
6748 * @widget: a #GtkWidget
6750 * Determines if the widget is the focus widget within its
6751 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6752 * necessarily set; %HAS_FOCUS will only be set if the
6753 * toplevel widget additionally has the global input focus.)
6755 * Return value: %TRUE if the widget is the focus widget.
6758 gtk_widget_is_focus (GtkWidget *widget)
6760 GtkWidget *toplevel;
6762 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6764 toplevel = gtk_widget_get_toplevel (widget);
6766 if (GTK_IS_WINDOW (toplevel))
6767 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6773 * gtk_widget_set_can_default:
6774 * @widget: a #GtkWidget
6775 * @can_default: whether or not @widget can be a default widget.
6777 * Specifies whether @widget can be a default widget. See
6778 * gtk_widget_grab_default() for details about the meaning of
6784 gtk_widget_set_can_default (GtkWidget *widget,
6785 gboolean can_default)
6787 g_return_if_fail (GTK_IS_WIDGET (widget));
6789 if (widget->priv->can_default != can_default)
6791 widget->priv->can_default = can_default;
6793 gtk_widget_queue_resize (widget);
6794 g_object_notify (G_OBJECT (widget), "can-default");
6799 * gtk_widget_get_can_default:
6800 * @widget: a #GtkWidget
6802 * Determines whether @widget can be a default widget. See
6803 * gtk_widget_set_can_default().
6805 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6810 gtk_widget_get_can_default (GtkWidget *widget)
6812 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6814 return widget->priv->can_default;
6818 * gtk_widget_has_default:
6819 * @widget: a #GtkWidget
6821 * Determines whether @widget is the current default widget within its
6822 * toplevel. See gtk_widget_set_can_default().
6824 * Return value: %TRUE if @widget is the current default widget within
6825 * its toplevel, %FALSE otherwise
6830 gtk_widget_has_default (GtkWidget *widget)
6832 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6834 return widget->priv->has_default;
6838 _gtk_widget_set_has_default (GtkWidget *widget,
6839 gboolean has_default)
6841 widget->priv->has_default = has_default;
6845 * gtk_widget_grab_default:
6846 * @widget: a #GtkWidget
6848 * Causes @widget to become the default widget. @widget must have the
6849 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6850 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6851 * %TRUE)</literal>. The default widget is activated when
6852 * the user presses Enter in a window. Default widgets must be
6853 * activatable, that is, gtk_widget_activate() should affect them. Note
6854 * that #GtkEntry widgets require the "activates-default" property
6855 * set to %TRUE before they activate the default widget when Enter
6856 * is pressed and the #GtkEntry is focused.
6859 gtk_widget_grab_default (GtkWidget *widget)
6863 g_return_if_fail (GTK_IS_WIDGET (widget));
6864 g_return_if_fail (gtk_widget_get_can_default (widget));
6866 window = gtk_widget_get_toplevel (widget);
6868 if (window && gtk_widget_is_toplevel (window))
6869 gtk_window_set_default (GTK_WINDOW (window), widget);
6871 g_warning (G_STRLOC ": widget not within a GtkWindow");
6875 * gtk_widget_set_receives_default:
6876 * @widget: a #GtkWidget
6877 * @receives_default: whether or not @widget can be a default widget.
6879 * Specifies whether @widget will be treated as the default widget
6880 * within its toplevel when it has the focus, even if another widget
6883 * See gtk_widget_grab_default() for details about the meaning of
6889 gtk_widget_set_receives_default (GtkWidget *widget,
6890 gboolean receives_default)
6892 g_return_if_fail (GTK_IS_WIDGET (widget));
6894 if (widget->priv->receives_default != receives_default)
6896 widget->priv->receives_default = receives_default;
6898 g_object_notify (G_OBJECT (widget), "receives-default");
6903 * gtk_widget_get_receives_default:
6904 * @widget: a #GtkWidget
6906 * Determines whether @widget is alyways treated as default widget
6907 * withing its toplevel when it has the focus, even if another widget
6910 * See gtk_widget_set_receives_default().
6912 * Return value: %TRUE if @widget acts as default widget when focussed,
6918 gtk_widget_get_receives_default (GtkWidget *widget)
6920 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6922 return widget->priv->receives_default;
6926 * gtk_widget_has_grab:
6927 * @widget: a #GtkWidget
6929 * Determines whether the widget is currently grabbing events, so it
6930 * is the only widget receiving input events (keyboard and mouse).
6932 * See also gtk_grab_add().
6934 * Return value: %TRUE if the widget is in the grab_widgets stack
6939 gtk_widget_has_grab (GtkWidget *widget)
6941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6943 return widget->priv->has_grab;
6947 _gtk_widget_set_has_grab (GtkWidget *widget,
6950 widget->priv->has_grab = has_grab;
6954 * gtk_widget_device_is_shadowed:
6955 * @widget: a #GtkWidget
6956 * @device: a #GdkDevice
6958 * Returns %TRUE if @device has been shadowed by a GTK+
6959 * device grab on another widget, so it would stop sending
6960 * events to @widget. This may be used in the
6961 * #GtkWidget::grab-notify signal to check for specific
6962 * devices. See gtk_device_grab_add().
6964 * Returns: %TRUE if there is an ongoing grab on @device
6965 * by another #GtkWidget than @widget.
6970 gtk_widget_device_is_shadowed (GtkWidget *widget,
6973 GtkWindowGroup *group;
6974 GtkWidget *grab_widget, *toplevel;
6976 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6977 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6979 if (!gtk_widget_get_realized (widget))
6982 toplevel = gtk_widget_get_toplevel (widget);
6984 if (GTK_IS_WINDOW (toplevel))
6985 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6987 group = gtk_window_get_group (NULL);
6989 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6991 /* Widget not inside the hierarchy of grab_widget */
6993 widget != grab_widget &&
6994 !gtk_widget_is_ancestor (widget, grab_widget))
6997 grab_widget = gtk_window_group_get_current_grab (group);
6998 if (grab_widget && widget != grab_widget &&
6999 !gtk_widget_is_ancestor (widget, grab_widget))
7006 * gtk_widget_set_name:
7007 * @widget: a #GtkWidget
7008 * @name: name for the widget
7010 * Widgets can be named, which allows you to refer to them from a
7011 * CSS file. You can apply a style to widgets with a particular name
7012 * in the CSS file. See the documentation for the CSS syntax (on the
7013 * same page as the docs for #GtkStyleContext).
7015 * Note that the CSS syntax has certain special characters to delimit
7016 * and represent elements in a selector (period, #, >, *...),
7017 * so using these will make your widget impossible to match by name.
7018 * Any combination of alphanumeric symbols, dashes and underscores will
7022 gtk_widget_set_name (GtkWidget *widget,
7025 GtkWidgetPrivate *priv;
7028 g_return_if_fail (GTK_IS_WIDGET (widget));
7030 priv = widget->priv;
7032 new_name = g_strdup (name);
7033 g_free (priv->name);
7034 priv->name = new_name;
7036 gtk_widget_reset_style (widget);
7038 g_object_notify (G_OBJECT (widget), "name");
7042 * gtk_widget_get_name:
7043 * @widget: a #GtkWidget
7045 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7046 * significance of widget names.
7048 * Return value: name of the widget. This string is owned by GTK+ and
7049 * should not be modified or freed
7052 gtk_widget_get_name (GtkWidget *widget)
7054 GtkWidgetPrivate *priv;
7056 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7058 priv = widget->priv;
7062 return G_OBJECT_TYPE_NAME (widget);
7066 _gtk_widget_update_state_flags (GtkWidget *widget,
7067 GtkStateFlags flags,
7070 GtkWidgetPrivate *priv;
7072 priv = widget->priv;
7074 /* Handle insensitive first, since it is propagated
7075 * differently throughout the widget hierarchy.
7077 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_UNSET))
7078 gtk_widget_set_sensitive (widget, TRUE);
7079 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags & GTK_STATE_FLAG_INSENSITIVE) && (operation != STATE_CHANGE_UNSET))
7080 gtk_widget_set_sensitive (widget, FALSE);
7081 else if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && !(flags & GTK_STATE_FLAG_INSENSITIVE) && (operation == STATE_CHANGE_REPLACE))
7082 gtk_widget_set_sensitive (widget, TRUE);
7084 if (operation != STATE_CHANGE_REPLACE)
7085 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
7088 operation == STATE_CHANGE_REPLACE)
7093 data.operation = operation;
7095 gtk_widget_propagate_state (widget, &data);
7097 gtk_widget_queue_resize (widget);
7102 * gtk_widget_set_state_flags:
7103 * @widget: a #GtkWidget
7104 * @flags: State flags to turn on
7105 * @clear: Whether to clear state before turning on @flags
7107 * This function is for use in widget implementations. Turns on flag
7108 * values in the current widget state (insensitive, prelighted, etc.).
7110 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7111 * will be propagated down to all non-internal children if @widget is a
7112 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7113 * down to all #GtkContainer children by different means than turning on the
7114 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7115 * gtk_widget_is_sensitive() will make use of these.
7120 gtk_widget_set_state_flags (GtkWidget *widget,
7121 GtkStateFlags flags,
7124 g_return_if_fail (GTK_IS_WIDGET (widget));
7126 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7127 (clear && widget->priv->state_flags == flags))
7131 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7133 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
7137 * gtk_widget_unset_state_flags:
7138 * @widget: a #GtkWidget
7139 * @flags: State flags to turn off
7141 * This function is for use in widget implementations. Turns off flag
7142 * values for the current widget state (insensitive, prelighted, etc.).
7143 * See gtk_widget_set_state_flags().
7148 gtk_widget_unset_state_flags (GtkWidget *widget,
7149 GtkStateFlags flags)
7151 g_return_if_fail (GTK_IS_WIDGET (widget));
7153 if ((widget->priv->state_flags & flags) == 0)
7156 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
7160 * gtk_widget_get_state_flags:
7161 * @widget: a #GtkWidget
7163 * Returns the widget state as a flag set. It is worth mentioning
7164 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7165 * returned, that is, also based on parent insensitivity, even if
7166 * @widget itself is sensitive.
7168 * Returns: The state flags for widget
7173 gtk_widget_get_state_flags (GtkWidget *widget)
7175 GtkStateFlags flags;
7177 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7179 flags = widget->priv->state_flags;
7181 if (gtk_widget_has_focus (widget))
7182 flags |= GTK_STATE_FLAG_FOCUSED;
7188 * gtk_widget_set_state:
7189 * @widget: a #GtkWidget
7190 * @state: new state for @widget
7192 * This function is for use in widget implementations. Sets the state
7193 * of a widget (insensitive, prelighted, etc.) Usually you should set
7194 * the state using wrapper functions such as gtk_widget_set_sensitive().
7196 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7199 gtk_widget_set_state (GtkWidget *widget,
7202 GtkStateFlags flags;
7204 if (state == gtk_widget_get_state (widget))
7209 case GTK_STATE_ACTIVE:
7210 flags = GTK_STATE_FLAG_ACTIVE;
7212 case GTK_STATE_PRELIGHT:
7213 flags = GTK_STATE_FLAG_PRELIGHT;
7215 case GTK_STATE_SELECTED:
7216 flags = GTK_STATE_FLAG_SELECTED;
7218 case GTK_STATE_INSENSITIVE:
7219 flags = GTK_STATE_FLAG_INSENSITIVE;
7221 case GTK_STATE_INCONSISTENT:
7222 flags = GTK_STATE_FLAG_INCONSISTENT;
7224 case GTK_STATE_FOCUSED:
7225 flags = GTK_STATE_FLAG_FOCUSED;
7227 case GTK_STATE_NORMAL:
7233 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7237 * gtk_widget_get_state:
7238 * @widget: a #GtkWidget
7240 * Returns the widget's state. See gtk_widget_set_state().
7242 * Returns: the state of @widget.
7246 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7249 gtk_widget_get_state (GtkWidget *widget)
7251 GtkStateFlags flags;
7253 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7255 flags = gtk_widget_get_state_flags (widget);
7257 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7258 return GTK_STATE_INSENSITIVE;
7259 else if (flags & GTK_STATE_FLAG_ACTIVE)
7260 return GTK_STATE_ACTIVE;
7261 else if (flags & GTK_STATE_FLAG_SELECTED)
7262 return GTK_STATE_SELECTED;
7263 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7264 return GTK_STATE_PRELIGHT;
7266 return GTK_STATE_NORMAL;
7270 * gtk_widget_set_visible:
7271 * @widget: a #GtkWidget
7272 * @visible: whether the widget should be shown or not
7274 * Sets the visibility state of @widget. Note that setting this to
7275 * %TRUE doesn't mean the widget is actually viewable, see
7276 * gtk_widget_get_visible().
7278 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7279 * but is nicer to use when the visibility of the widget depends on
7285 gtk_widget_set_visible (GtkWidget *widget,
7288 g_return_if_fail (GTK_IS_WIDGET (widget));
7290 if (visible != gtk_widget_get_visible (widget))
7293 gtk_widget_show (widget);
7295 gtk_widget_hide (widget);
7300 _gtk_widget_set_visible_flag (GtkWidget *widget,
7303 widget->priv->visible = visible;
7307 * gtk_widget_get_visible:
7308 * @widget: a #GtkWidget
7310 * Determines whether the widget is visible. Note that this doesn't
7311 * take into account whether the widget's parent is also visible
7312 * or the widget is obscured in any way.
7314 * See gtk_widget_set_visible().
7316 * Return value: %TRUE if the widget is visible
7321 gtk_widget_get_visible (GtkWidget *widget)
7323 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7325 return widget->priv->visible;
7329 * gtk_widget_set_has_window:
7330 * @widget: a #GtkWidget
7331 * @has_window: whether or not @widget has a window.
7333 * Specifies whether @widget has a #GdkWindow of its own. Note that
7334 * all realized widgets have a non-%NULL "window" pointer
7335 * (gtk_widget_get_window() never returns a %NULL window when a widget
7336 * is realized), but for many of them it's actually the #GdkWindow of
7337 * one of its parent widgets. Widgets that do not create a %window for
7338 * themselves in #GtkWidget::realize must announce this by
7339 * calling this function with @has_window = %FALSE.
7341 * This function should only be called by widget implementations,
7342 * and they should call it in their init() function.
7347 gtk_widget_set_has_window (GtkWidget *widget,
7348 gboolean has_window)
7350 g_return_if_fail (GTK_IS_WIDGET (widget));
7352 widget->priv->no_window = !has_window;
7356 * gtk_widget_get_has_window:
7357 * @widget: a #GtkWidget
7359 * Determines whether @widget has a #GdkWindow of its own. See
7360 * gtk_widget_set_has_window().
7362 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7367 gtk_widget_get_has_window (GtkWidget *widget)
7369 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7371 return ! widget->priv->no_window;
7375 * gtk_widget_is_toplevel:
7376 * @widget: a #GtkWidget
7378 * Determines whether @widget is a toplevel widget.
7380 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7381 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7384 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7389 gtk_widget_is_toplevel (GtkWidget *widget)
7391 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7393 return widget->priv->toplevel;
7397 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7398 gboolean is_toplevel)
7400 widget->priv->toplevel = is_toplevel;
7404 * gtk_widget_is_drawable:
7405 * @widget: a #GtkWidget
7407 * Determines whether @widget can be drawn to. A widget can be drawn
7408 * to if it is mapped and visible.
7410 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7415 gtk_widget_is_drawable (GtkWidget *widget)
7417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7419 return (gtk_widget_get_visible (widget) &&
7420 gtk_widget_get_mapped (widget));
7424 * gtk_widget_get_realized:
7425 * @widget: a #GtkWidget
7427 * Determines whether @widget is realized.
7429 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7434 gtk_widget_get_realized (GtkWidget *widget)
7436 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7438 return widget->priv->realized;
7442 * gtk_widget_set_realized:
7443 * @widget: a #GtkWidget
7444 * @realized: %TRUE to mark the widget as realized
7446 * Marks the widget as being realized.
7448 * This function should only ever be called in a derived widget's
7449 * "realize" or "unrealize" implementation.
7454 gtk_widget_set_realized (GtkWidget *widget,
7457 g_return_if_fail (GTK_IS_WIDGET (widget));
7459 widget->priv->realized = realized;
7463 * gtk_widget_get_mapped:
7464 * @widget: a #GtkWidget
7466 * Whether the widget is mapped.
7468 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7473 gtk_widget_get_mapped (GtkWidget *widget)
7475 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7477 return widget->priv->mapped;
7481 * gtk_widget_set_mapped:
7482 * @widget: a #GtkWidget
7483 * @mapped: %TRUE to mark the widget as mapped
7485 * Marks the widget as being realized.
7487 * This function should only ever be called in a derived widget's
7488 * "map" or "unmap" implementation.
7493 gtk_widget_set_mapped (GtkWidget *widget,
7496 g_return_if_fail (GTK_IS_WIDGET (widget));
7498 widget->priv->mapped = mapped;
7502 * gtk_widget_set_app_paintable:
7503 * @widget: a #GtkWidget
7504 * @app_paintable: %TRUE if the application will paint on the widget
7506 * Sets whether the application intends to draw on the widget in
7507 * an #GtkWidget::draw handler.
7509 * This is a hint to the widget and does not affect the behavior of
7510 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7511 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7512 * the effect is to suppress default themed drawing of the widget's
7513 * background. (Children of the widget will still be drawn.) The application
7514 * is then entirely responsible for drawing the widget background.
7516 * Note that the background is still drawn when the widget is mapped.
7519 gtk_widget_set_app_paintable (GtkWidget *widget,
7520 gboolean app_paintable)
7522 g_return_if_fail (GTK_IS_WIDGET (widget));
7524 app_paintable = (app_paintable != FALSE);
7526 if (widget->priv->app_paintable != app_paintable)
7528 widget->priv->app_paintable = app_paintable;
7530 if (gtk_widget_is_drawable (widget))
7531 gtk_widget_queue_draw (widget);
7533 g_object_notify (G_OBJECT (widget), "app-paintable");
7538 * gtk_widget_get_app_paintable:
7539 * @widget: a #GtkWidget
7541 * Determines whether the application intends to draw on the widget in
7542 * an #GtkWidget::draw handler.
7544 * See gtk_widget_set_app_paintable()
7546 * Return value: %TRUE if the widget is app paintable
7551 gtk_widget_get_app_paintable (GtkWidget *widget)
7553 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7555 return widget->priv->app_paintable;
7559 * gtk_widget_set_double_buffered:
7560 * @widget: a #GtkWidget
7561 * @double_buffered: %TRUE to double-buffer a widget
7563 * Widgets are double buffered by default; you can use this function
7564 * to turn off the buffering. "Double buffered" simply means that
7565 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7566 * automatically around expose events sent to the
7567 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7568 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7569 * buffer to the screen. The result is that users see the window
7570 * update in one smooth step, and don't see individual graphics
7571 * primitives being rendered.
7573 * In very simple terms, double buffered widgets don't flicker,
7574 * so you would only use this function to turn off double buffering
7575 * if you had special needs and really knew what you were doing.
7577 * Note: if you turn off double-buffering, you have to handle
7578 * expose events, since even the clearing to the background color or
7579 * pixmap will not happen automatically (as it is done in
7580 * gdk_window_begin_paint()).
7583 gtk_widget_set_double_buffered (GtkWidget *widget,
7584 gboolean double_buffered)
7586 g_return_if_fail (GTK_IS_WIDGET (widget));
7588 double_buffered = (double_buffered != FALSE);
7590 if (widget->priv->double_buffered != double_buffered)
7592 widget->priv->double_buffered = double_buffered;
7594 g_object_notify (G_OBJECT (widget), "double-buffered");
7599 * gtk_widget_get_double_buffered:
7600 * @widget: a #GtkWidget
7602 * Determines whether the widget is double buffered.
7604 * See gtk_widget_set_double_buffered()
7606 * Return value: %TRUE if the widget is double buffered
7611 gtk_widget_get_double_buffered (GtkWidget *widget)
7613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7615 return widget->priv->double_buffered;
7619 * gtk_widget_set_redraw_on_allocate:
7620 * @widget: a #GtkWidget
7621 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7622 * when it is allocated to a new size. Otherwise, only the
7623 * new portion of the widget will be redrawn.
7625 * Sets whether the entire widget is queued for drawing when its size
7626 * allocation changes. By default, this setting is %TRUE and
7627 * the entire widget is redrawn on every size change. If your widget
7628 * leaves the upper left unchanged when made bigger, turning this
7629 * setting off will improve performance.
7631 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7632 * off all allocation on resizing: the widget will not even redraw if
7633 * its position changes; this is to allow containers that don't draw
7634 * anything to avoid excess invalidations. If you set this flag on a
7635 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7636 * you are responsible for invalidating both the old and new allocation
7637 * of the widget when the widget is moved and responsible for invalidating
7638 * regions newly when the widget increases size.
7641 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7642 gboolean redraw_on_allocate)
7644 g_return_if_fail (GTK_IS_WIDGET (widget));
7646 widget->priv->redraw_on_alloc = redraw_on_allocate;
7650 * gtk_widget_set_sensitive:
7651 * @widget: a #GtkWidget
7652 * @sensitive: %TRUE to make the widget sensitive
7654 * Sets the sensitivity of a widget. A widget is sensitive if the user
7655 * can interact with it. Insensitive widgets are "grayed out" and the
7656 * user can't interact with them. Insensitive widgets are known as
7657 * "inactive", "disabled", or "ghosted" in some other toolkits.
7660 gtk_widget_set_sensitive (GtkWidget *widget,
7663 GtkWidgetPrivate *priv;
7665 g_return_if_fail (GTK_IS_WIDGET (widget));
7667 priv = widget->priv;
7669 sensitive = (sensitive != FALSE);
7671 if (priv->sensitive == sensitive)
7674 priv->sensitive = sensitive;
7676 if (priv->parent == NULL
7677 || gtk_widget_is_sensitive (priv->parent))
7681 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7684 data.operation = STATE_CHANGE_UNSET;
7686 data.operation = STATE_CHANGE_SET;
7688 gtk_widget_propagate_state (widget, &data);
7690 gtk_widget_queue_resize (widget);
7693 g_object_notify (G_OBJECT (widget), "sensitive");
7697 * gtk_widget_get_sensitive:
7698 * @widget: a #GtkWidget
7700 * Returns the widget's sensitivity (in the sense of returning
7701 * the value that has been set using gtk_widget_set_sensitive()).
7703 * The effective sensitivity of a widget is however determined by both its
7704 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7706 * Returns: %TRUE if the widget is sensitive
7711 gtk_widget_get_sensitive (GtkWidget *widget)
7713 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7715 return widget->priv->sensitive;
7719 * gtk_widget_is_sensitive:
7720 * @widget: a #GtkWidget
7722 * Returns the widget's effective sensitivity, which means
7723 * it is sensitive itself and also its parent widget is sensitive
7725 * Returns: %TRUE if the widget is effectively sensitive
7730 gtk_widget_is_sensitive (GtkWidget *widget)
7732 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7734 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
7738 _gtk_widget_update_path (GtkWidget *widget)
7740 if (widget->priv->path)
7742 gtk_widget_path_free (widget->priv->path);
7743 widget->priv->path = NULL;
7746 gtk_widget_get_path (widget);
7750 * gtk_widget_set_parent:
7751 * @widget: a #GtkWidget
7752 * @parent: parent container
7754 * This function is useful only when implementing subclasses of
7756 * Sets the container as the parent of @widget, and takes care of
7757 * some details such as updating the state and style of the child
7758 * to reflect its new location. The opposite function is
7759 * gtk_widget_unparent().
7762 gtk_widget_set_parent (GtkWidget *widget,
7765 GtkStateFlags parent_flags;
7766 GtkWidgetPrivate *priv;
7769 g_return_if_fail (GTK_IS_WIDGET (widget));
7770 g_return_if_fail (GTK_IS_WIDGET (parent));
7771 g_return_if_fail (widget != parent);
7773 priv = widget->priv;
7775 if (priv->parent != NULL)
7777 g_warning ("Can't set a parent on widget which has a parent\n");
7780 if (gtk_widget_is_toplevel (widget))
7782 g_warning ("Can't set a parent on a toplevel widget\n");
7786 /* keep this function in sync with gtk_menu_attach_to_widget()
7789 g_object_ref_sink (widget);
7791 gtk_widget_push_verify_invariants (widget);
7793 priv->parent = parent;
7795 parent_flags = gtk_widget_get_state_flags (parent);
7797 /* Merge both old state and current parent state,
7798 * making sure to only propagate the right states */
7799 data.flags = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
7800 data.flags |= priv->state_flags;
7802 data.operation = STATE_CHANGE_REPLACE;
7803 gtk_widget_propagate_state (widget, &data);
7805 gtk_widget_reset_style (widget);
7807 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7808 if (priv->parent->priv->anchored)
7809 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7810 g_object_notify (G_OBJECT (widget), "parent");
7812 /* Enforce realized/mapped invariants
7814 if (gtk_widget_get_realized (priv->parent))
7815 gtk_widget_realize (widget);
7817 if (gtk_widget_get_visible (priv->parent) &&
7818 gtk_widget_get_visible (widget))
7820 if (gtk_widget_get_child_visible (widget) &&
7821 gtk_widget_get_mapped (priv->parent))
7822 gtk_widget_map (widget);
7824 gtk_widget_queue_resize (widget);
7827 /* child may cause parent's expand to change, if the child is
7828 * expanded. If child is not expanded, then it can't modify the
7829 * parent's expand. If the child becomes expanded later then it will
7830 * queue compute_expand then. This optimization plus defaulting
7831 * newly-constructed widgets to need_compute_expand=FALSE should
7832 * mean that initially building a widget tree doesn't have to keep
7833 * walking up setting need_compute_expand on parents over and over.
7835 * We can't change a parent to need to expand unless we're visible.
7837 if (gtk_widget_get_visible (widget) &&
7838 (priv->need_compute_expand ||
7839 priv->computed_hexpand ||
7840 priv->computed_vexpand))
7842 gtk_widget_queue_compute_expand (parent);
7845 gtk_widget_pop_verify_invariants (widget);
7849 * gtk_widget_get_parent:
7850 * @widget: a #GtkWidget
7852 * Returns the parent container of @widget.
7854 * Return value: (transfer none): the parent container of @widget, or %NULL
7857 gtk_widget_get_parent (GtkWidget *widget)
7859 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7861 return widget->priv->parent;
7865 modifier_style_changed (GtkModifierStyle *style,
7868 GtkStyleContext *context;
7870 context = gtk_widget_get_style_context (widget);
7871 gtk_style_context_invalidate (context);
7874 static GtkModifierStyle *
7875 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7877 GtkModifierStyle *style;
7879 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7881 if (G_UNLIKELY (!style))
7883 GtkStyleContext *context;
7885 style = _gtk_modifier_style_new ();
7886 g_object_set_qdata_full (G_OBJECT (widget),
7887 quark_modifier_style,
7889 (GDestroyNotify) g_object_unref);
7891 g_signal_connect (style, "changed",
7892 G_CALLBACK (modifier_style_changed), widget);
7894 context = gtk_widget_get_style_context (widget);
7896 gtk_style_context_add_provider (context,
7897 GTK_STYLE_PROVIDER (style),
7898 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7905 * gtk_widget_override_color:
7906 * @widget: a #GtkWidget
7907 * @state: the state for which to set the color
7908 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7909 * of previous calls to gtk_widget_override_color()
7911 * Sets the color to use for a widget.
7913 * All other style values are left untouched.
7916 * This API is mostly meant as a quick way for applications to
7917 * change a widget appearance. If you are developing a widgets
7918 * library and intend this change to be themeable, it is better
7919 * done by setting meaningful CSS classes and regions in your
7920 * widget/container implementation through gtk_style_context_add_class()
7921 * and gtk_style_context_add_region().
7923 * This way, your widget library can install a #GtkCssProvider
7924 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
7925 * to provide a default styling for those widgets that need so, and
7926 * this theming may fully overridden by the user's theme.
7929 * Note that for complex widgets this may bring in undesired
7930 * results (such as uniform background color everywhere), in
7931 * these cases it is better to fully style such widgets through a
7932 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7939 gtk_widget_override_color (GtkWidget *widget,
7940 GtkStateFlags state,
7941 const GdkRGBA *color)
7943 GtkModifierStyle *style;
7945 g_return_if_fail (GTK_IS_WIDGET (widget));
7947 style = _gtk_widget_get_modifier_properties (widget);
7948 _gtk_modifier_style_set_color (style, state, color);
7952 * gtk_widget_override_background_color:
7953 * @widget: a #GtkWidget
7954 * @state: the state for which to set the background color
7955 * @color: (allow-none): the color to assign, or %NULL to undo the effect
7956 * of previous calls to gtk_widget_override_background_color()
7958 * Sets the background color to use for a widget.
7960 * All other style values are left untouched.
7961 * See gtk_widget_override_color().
7966 gtk_widget_override_background_color (GtkWidget *widget,
7967 GtkStateFlags state,
7968 const GdkRGBA *color)
7970 GtkModifierStyle *style;
7972 g_return_if_fail (GTK_IS_WIDGET (widget));
7974 style = _gtk_widget_get_modifier_properties (widget);
7975 _gtk_modifier_style_set_background_color (style, state, color);
7979 * gtk_widget_override_font:
7980 * @widget: a #GtkWidget
7981 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
7982 * the effect of previous calls to gtk_widget_override_font()
7984 * Sets the font to use for a widget. All other style values are
7985 * left untouched. See gtk_widget_override_color().
7990 gtk_widget_override_font (GtkWidget *widget,
7991 const PangoFontDescription *font_desc)
7993 GtkModifierStyle *style;
7995 g_return_if_fail (GTK_IS_WIDGET (widget));
7997 style = _gtk_widget_get_modifier_properties (widget);
7998 _gtk_modifier_style_set_font (style, font_desc);
8002 * gtk_widget_override_symbolic_color:
8003 * @widget: a #GtkWidget
8004 * @name: the name of the symbolic color to modify
8005 * @color: (allow-none): the color to assign (does not need
8006 * to be allocated), or %NULL to undo the effect of previous
8007 * calls to gtk_widget_override_symbolic_color()
8009 * Sets a symbolic color for a widget.
8011 * All other style values are left untouched.
8012 * See gtk_widget_override_color() for overriding the foreground
8013 * or background color.
8018 gtk_widget_override_symbolic_color (GtkWidget *widget,
8020 const GdkRGBA *color)
8022 GtkModifierStyle *style;
8024 g_return_if_fail (GTK_IS_WIDGET (widget));
8026 style = _gtk_widget_get_modifier_properties (widget);
8027 _gtk_modifier_style_map_color (style, name, color);
8031 * gtk_widget_override_cursor:
8032 * @widget: a #GtkWidget
8033 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8034 * allocated), or %NULL to undo the effect of previous calls to
8035 * of gtk_widget_override_cursor().
8036 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8037 * need to be allocated), or %NULL to undo the effect of previous
8038 * calls to of gtk_widget_override_cursor().
8040 * Sets the cursor color to use in a widget, overriding the
8041 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8042 * style properties. All other style values are left untouched.
8043 * See also gtk_widget_modify_style().
8045 * Note that the underlying properties have the #GdkColor type,
8046 * so the alpha value in @primary and @secondary will be ignored.
8051 gtk_widget_override_cursor (GtkWidget *widget,
8052 const GdkRGBA *cursor,
8053 const GdkRGBA *secondary_cursor)
8055 GtkModifierStyle *style;
8057 g_return_if_fail (GTK_IS_WIDGET (widget));
8059 style = _gtk_widget_get_modifier_properties (widget);
8060 _gtk_modifier_style_set_color_property (style,
8062 "cursor-color", cursor);
8063 _gtk_modifier_style_set_color_property (style,
8065 "secondary-cursor-color",
8070 gtk_widget_real_direction_changed (GtkWidget *widget,
8071 GtkTextDirection previous_direction)
8073 gtk_widget_queue_resize (widget);
8077 gtk_widget_real_style_set (GtkWidget *widget,
8078 GtkStyle *previous_style)
8083 GtkWidget *previous_toplevel;
8084 GdkScreen *previous_screen;
8085 GdkScreen *new_screen;
8086 } HierarchyChangedInfo;
8089 do_screen_change (GtkWidget *widget,
8090 GdkScreen *old_screen,
8091 GdkScreen *new_screen)
8093 if (old_screen != new_screen)
8095 GtkWidgetPrivate *priv = widget->priv;
8099 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8101 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8104 _gtk_tooltip_hide (widget);
8106 if (new_screen && priv->context)
8107 gtk_style_context_set_screen (priv->context, new_screen);
8109 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8114 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8115 gpointer client_data)
8117 GtkWidgetPrivate *priv = widget->priv;
8118 HierarchyChangedInfo *info = client_data;
8119 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8120 (priv->parent && priv->parent->priv->anchored);
8122 if (priv->anchored != new_anchored)
8124 g_object_ref (widget);
8126 priv->anchored = new_anchored;
8128 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8129 do_screen_change (widget, info->previous_screen, info->new_screen);
8131 if (GTK_IS_CONTAINER (widget))
8132 gtk_container_forall (GTK_CONTAINER (widget),
8133 gtk_widget_propagate_hierarchy_changed_recurse,
8136 g_object_unref (widget);
8141 * _gtk_widget_propagate_hierarchy_changed:
8142 * @widget: a #GtkWidget
8143 * @previous_toplevel: Previous toplevel
8145 * Propagates changes in the anchored state to a widget and all
8146 * children, unsetting or setting the %ANCHORED flag, and
8147 * emitting #GtkWidget::hierarchy-changed.
8150 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8151 GtkWidget *previous_toplevel)
8153 GtkWidgetPrivate *priv = widget->priv;
8154 HierarchyChangedInfo info;
8156 info.previous_toplevel = previous_toplevel;
8157 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8159 if (gtk_widget_is_toplevel (widget) ||
8160 (priv->parent && priv->parent->priv->anchored))
8161 info.new_screen = gtk_widget_get_screen (widget);
8163 info.new_screen = NULL;
8165 if (info.previous_screen)
8166 g_object_ref (info.previous_screen);
8167 if (previous_toplevel)
8168 g_object_ref (previous_toplevel);
8170 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8172 if (previous_toplevel)
8173 g_object_unref (previous_toplevel);
8174 if (info.previous_screen)
8175 g_object_unref (info.previous_screen);
8179 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8180 gpointer client_data)
8182 HierarchyChangedInfo *info = client_data;
8184 g_object_ref (widget);
8186 do_screen_change (widget, info->previous_screen, info->new_screen);
8188 if (GTK_IS_CONTAINER (widget))
8189 gtk_container_forall (GTK_CONTAINER (widget),
8190 gtk_widget_propagate_screen_changed_recurse,
8193 g_object_unref (widget);
8197 * gtk_widget_is_composited:
8198 * @widget: a #GtkWidget
8200 * Whether @widget can rely on having its alpha channel
8201 * drawn correctly. On X11 this function returns whether a
8202 * compositing manager is running for @widget's screen.
8204 * Please note that the semantics of this call will change
8205 * in the future if used on a widget that has a composited
8206 * window in its hierarchy (as set by gdk_window_set_composited()).
8208 * Return value: %TRUE if the widget can rely on its alpha
8209 * channel being drawn correctly.
8214 gtk_widget_is_composited (GtkWidget *widget)
8218 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8220 screen = gtk_widget_get_screen (widget);
8222 return gdk_screen_is_composited (screen);
8226 propagate_composited_changed (GtkWidget *widget,
8229 if (GTK_IS_CONTAINER (widget))
8231 gtk_container_forall (GTK_CONTAINER (widget),
8232 propagate_composited_changed,
8236 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8240 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8242 propagate_composited_changed (widget, NULL);
8246 * _gtk_widget_propagate_screen_changed:
8247 * @widget: a #GtkWidget
8248 * @previous_screen: Previous screen
8250 * Propagates changes in the screen for a widget to all
8251 * children, emitting #GtkWidget::screen-changed.
8254 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8255 GdkScreen *previous_screen)
8257 HierarchyChangedInfo info;
8259 info.previous_screen = previous_screen;
8260 info.new_screen = gtk_widget_get_screen (widget);
8262 if (previous_screen)
8263 g_object_ref (previous_screen);
8265 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8267 if (previous_screen)
8268 g_object_unref (previous_screen);
8272 reset_style_recurse (GtkWidget *widget, gpointer data)
8274 _gtk_widget_update_path (widget);
8276 if (GTK_IS_CONTAINER (widget))
8277 gtk_container_forall (GTK_CONTAINER (widget),
8278 reset_style_recurse,
8283 * gtk_widget_reset_style:
8284 * @widget: a #GtkWidget
8286 * Updates the style context of @widget and all descendents
8287 * by updating its widget path. #GtkContainer<!-- -->s may want
8288 * to use this on a child when reordering it in a way that a different
8289 * style might apply to it. See also gtk_container_get_path_for_child().
8294 gtk_widget_reset_style (GtkWidget *widget)
8296 g_return_if_fail (GTK_IS_WIDGET (widget));
8298 reset_style_recurse (widget, NULL);
8301 #ifdef G_ENABLE_DEBUG
8303 /* Verify invariants, see docs/widget_system.txt for notes on much of
8304 * this. Invariants may be temporarily broken while we're in the
8305 * process of updating state, of course, so you can only
8306 * verify_invariants() after a given operation is complete.
8307 * Use push/pop_verify_invariants to help with that.
8310 gtk_widget_verify_invariants (GtkWidget *widget)
8314 if (widget->priv->verifying_invariants_count > 0)
8317 parent = widget->priv->parent;
8319 if (widget->priv->mapped)
8321 /* Mapped implies ... */
8323 if (!widget->priv->realized)
8324 g_warning ("%s %p is mapped but not realized",
8325 G_OBJECT_TYPE_NAME (widget), widget);
8327 if (!widget->priv->visible)
8328 g_warning ("%s %p is mapped but not visible",
8329 G_OBJECT_TYPE_NAME (widget), widget);
8331 if (!widget->priv->toplevel)
8333 if (!widget->priv->child_visible)
8334 g_warning ("%s %p is mapped but not child_visible",
8335 G_OBJECT_TYPE_NAME (widget), widget);
8340 /* Not mapped implies... */
8343 /* This check makes sense for normal toplevels, but for
8344 * something like a toplevel that is embedded within a clutter
8345 * state, mapping may depend on external factors.
8347 if (widget->priv->toplevel)
8349 if (widget->priv->visible)
8350 g_warning ("%s %p toplevel is visible but not mapped",
8351 G_OBJECT_TYPE_NAME (widget), widget);
8356 /* Parent related checks aren't possible if parent has
8357 * verifying_invariants_count > 0 because parent needs to recurse
8358 * children first before the invariants will hold.
8360 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8363 parent->priv->realized)
8365 /* Parent realized implies... */
8368 /* This is in widget_system.txt but appears to fail
8369 * because there's no gtk_container_realize() that
8370 * realizes all children... instead we just lazily
8371 * wait for map to fix things up.
8373 if (!widget->priv->realized)
8374 g_warning ("%s %p is realized but child %s %p is not realized",
8375 G_OBJECT_TYPE_NAME (parent), parent,
8376 G_OBJECT_TYPE_NAME (widget), widget);
8379 else if (!widget->priv->toplevel)
8381 /* No parent or parent not realized on non-toplevel implies... */
8383 if (widget->priv->realized && !widget->priv->in_reparent)
8384 g_warning ("%s %p is not realized but child %s %p is realized",
8385 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8386 G_OBJECT_TYPE_NAME (widget), widget);
8390 parent->priv->mapped &&
8391 widget->priv->visible &&
8392 widget->priv->child_visible)
8394 /* Parent mapped and we are visible implies... */
8396 if (!widget->priv->mapped)
8397 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8398 G_OBJECT_TYPE_NAME (parent), parent,
8399 G_OBJECT_TYPE_NAME (widget), widget);
8401 else if (!widget->priv->toplevel)
8403 /* No parent or parent not mapped on non-toplevel implies... */
8405 if (widget->priv->mapped && !widget->priv->in_reparent)
8406 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8407 G_OBJECT_TYPE_NAME (widget), widget,
8408 widget->priv->visible,
8409 widget->priv->child_visible,
8410 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8411 parent ? parent->priv->mapped : FALSE);
8415 if (!widget->priv->realized)
8417 /* Not realized implies... */
8420 /* widget_system.txt says these hold, but they don't. */
8421 if (widget->priv->resize_pending)
8422 g_warning ("%s %p resize pending but not realized",
8423 G_OBJECT_TYPE_NAME (widget), widget);
8425 if (widget->priv->alloc_needed)
8426 g_warning ("%s %p alloc needed but not realized",
8427 G_OBJECT_TYPE_NAME (widget), widget);
8429 if (widget->priv->width_request_needed)
8430 g_warning ("%s %p width request needed but not realized",
8431 G_OBJECT_TYPE_NAME (widget), widget);
8433 if (widget->priv->height_request_needed)
8434 g_warning ("%s %p height request needed but not realized",
8435 G_OBJECT_TYPE_NAME (widget), widget);
8440 /* The point of this push/pop is that invariants may not hold while
8441 * we're busy making changes. So we only check at the outermost call
8442 * on the call stack, after we finish updating everything.
8445 gtk_widget_push_verify_invariants (GtkWidget *widget)
8447 widget->priv->verifying_invariants_count += 1;
8451 gtk_widget_verify_child_invariants (GtkWidget *widget,
8452 gpointer client_data)
8454 /* We don't recurse further; this is a one-level check. */
8455 gtk_widget_verify_invariants (widget);
8459 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8461 g_assert (widget->priv->verifying_invariants_count > 0);
8463 widget->priv->verifying_invariants_count -= 1;
8465 if (widget->priv->verifying_invariants_count == 0)
8467 gtk_widget_verify_invariants (widget);
8469 if (GTK_IS_CONTAINER (widget))
8471 /* Check one level of children, because our
8472 * push_verify_invariants() will have prevented some of the
8473 * checks. This does not recurse because if recursion is
8474 * needed, it will happen naturally as each child has a
8475 * push/pop on that child. For example if we're recursively
8476 * mapping children, we'll push/pop on each child as we map
8479 gtk_container_forall (GTK_CONTAINER (widget),
8480 gtk_widget_verify_child_invariants,
8485 #endif /* G_ENABLE_DEBUG */
8487 static PangoContext *
8488 gtk_widget_peek_pango_context (GtkWidget *widget)
8490 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8494 * gtk_widget_get_pango_context:
8495 * @widget: a #GtkWidget
8497 * Gets a #PangoContext with the appropriate font map, font description,
8498 * and base direction for this widget. Unlike the context returned
8499 * by gtk_widget_create_pango_context(), this context is owned by
8500 * the widget (it can be used until the screen for the widget changes
8501 * or the widget is removed from its toplevel), and will be updated to
8502 * match any changes to the widget's attributes.
8504 * If you create and keep a #PangoLayout using this context, you must
8505 * deal with changes to the context by calling pango_layout_context_changed()
8506 * on the layout in response to the #GtkWidget::style-updated and
8507 * #GtkWidget::direction-changed signals for the widget.
8509 * Return value: (transfer none): the #PangoContext for the widget.
8512 gtk_widget_get_pango_context (GtkWidget *widget)
8514 PangoContext *context;
8516 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8518 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8521 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8522 g_object_set_qdata_full (G_OBJECT (widget),
8523 quark_pango_context,
8532 update_pango_context (GtkWidget *widget,
8533 PangoContext *context)
8535 const PangoFontDescription *font_desc;
8536 GtkStyleContext *style_context;
8538 style_context = gtk_widget_get_style_context (widget);
8540 font_desc = gtk_style_context_get_font (style_context,
8541 gtk_widget_get_state_flags (widget));
8543 pango_context_set_font_description (context, font_desc);
8544 pango_context_set_base_dir (context,
8545 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8546 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8550 gtk_widget_update_pango_context (GtkWidget *widget)
8552 PangoContext *context = gtk_widget_peek_pango_context (widget);
8558 update_pango_context (widget, context);
8560 screen = gtk_widget_get_screen_unchecked (widget);
8563 pango_cairo_context_set_resolution (context,
8564 gdk_screen_get_resolution (screen));
8565 pango_cairo_context_set_font_options (context,
8566 gdk_screen_get_font_options (screen));
8572 * gtk_widget_create_pango_context:
8573 * @widget: a #GtkWidget
8575 * Creates a new #PangoContext with the appropriate font map,
8576 * font description, and base direction for drawing text for
8577 * this widget. See also gtk_widget_get_pango_context().
8579 * Return value: (transfer full): the new #PangoContext
8582 gtk_widget_create_pango_context (GtkWidget *widget)
8585 PangoContext *context;
8587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8589 screen = gtk_widget_get_screen_unchecked (widget);
8592 GTK_NOTE (MULTIHEAD,
8593 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8595 screen = gdk_screen_get_default ();
8598 context = gdk_pango_context_get_for_screen (screen);
8600 update_pango_context (widget, context);
8601 pango_context_set_language (context, gtk_get_default_language ());
8607 * gtk_widget_create_pango_layout:
8608 * @widget: a #GtkWidget
8609 * @text: text to set on the layout (can be %NULL)
8611 * Creates a new #PangoLayout with the appropriate font map,
8612 * font description, and base direction for drawing text for
8615 * If you keep a #PangoLayout created in this way around, in order to
8616 * notify the layout of changes to the base direction or font of this
8617 * widget, you must call pango_layout_context_changed() in response to
8618 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8621 * Return value: (transfer full): the new #PangoLayout
8624 gtk_widget_create_pango_layout (GtkWidget *widget,
8627 PangoLayout *layout;
8628 PangoContext *context;
8630 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8632 context = gtk_widget_get_pango_context (widget);
8633 layout = pango_layout_new (context);
8636 pango_layout_set_text (layout, text, -1);
8642 * gtk_widget_render_icon_pixbuf:
8643 * @widget: a #GtkWidget
8644 * @stock_id: a stock ID
8645 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8646 * render at the size of the source and don't scale (if there are
8647 * multiple source sizes, GTK+ picks one of the available sizes).
8649 * A convenience function that uses the theme engine and style
8650 * settings for @widget to look up @stock_id and render it to
8651 * a pixbuf. @stock_id should be a stock icon ID such as
8652 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8653 * such as #GTK_ICON_SIZE_MENU.
8655 * The pixels in the returned #GdkPixbuf are shared with the rest of
8656 * the application and should not be modified. The pixbuf should be freed
8657 * after use with g_object_unref().
8659 * Return value: (transfer full): a new pixbuf, or %NULL if the
8660 * stock ID wasn't known
8665 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8666 const gchar *stock_id,
8669 GtkStyleContext *context;
8670 GtkIconSet *icon_set;
8672 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8673 g_return_val_if_fail (stock_id != NULL, NULL);
8674 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8676 context = gtk_widget_get_style_context (widget);
8677 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8679 if (icon_set == NULL)
8682 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
8686 * gtk_widget_set_parent_window:
8687 * @widget: a #GtkWidget.
8688 * @parent_window: the new parent window.
8690 * Sets a non default parent window for @widget.
8692 * For GtkWindow classes, setting a @parent_window effects whether
8693 * the window is a toplevel window or can be embedded into other
8697 * For GtkWindow classes, this needs to be called before the
8698 * window is realized.
8703 gtk_widget_set_parent_window (GtkWidget *widget,
8704 GdkWindow *parent_window)
8706 GdkWindow *old_parent_window;
8708 g_return_if_fail (GTK_IS_WIDGET (widget));
8710 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8711 quark_parent_window);
8713 if (parent_window != old_parent_window)
8717 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8719 if (old_parent_window)
8720 g_object_unref (old_parent_window);
8722 g_object_ref (parent_window);
8724 /* Unset toplevel flag when adding a parent window to a widget,
8725 * this is the primary entry point to allow toplevels to be
8728 #ifdef GDK_WINDOWING_X11
8729 is_plug = GTK_IS_PLUG (widget);
8733 if (GTK_IS_WINDOW (widget) && !is_plug)
8734 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
8739 * gtk_widget_get_parent_window:
8740 * @widget: a #GtkWidget.
8742 * Gets @widget's parent window.
8744 * Returns: (transfer none): the parent window of @widget.
8747 gtk_widget_get_parent_window (GtkWidget *widget)
8749 GtkWidgetPrivate *priv;
8750 GdkWindow *parent_window;
8752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8754 priv = widget->priv;
8756 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8758 return (parent_window != NULL) ? parent_window :
8759 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8764 * gtk_widget_set_child_visible:
8765 * @widget: a #GtkWidget
8766 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8768 * Sets whether @widget should be mapped along with its when its parent
8769 * is mapped and @widget has been shown with gtk_widget_show().
8771 * The child visibility can be set for widget before it is added to
8772 * a container with gtk_widget_set_parent(), to avoid mapping
8773 * children unnecessary before immediately unmapping them. However
8774 * it will be reset to its default state of %TRUE when the widget
8775 * is removed from a container.
8777 * Note that changing the child visibility of a widget does not
8778 * queue a resize on the widget. Most of the time, the size of
8779 * a widget is computed from all visible children, whether or
8780 * not they are mapped. If this is not the case, the container
8781 * can queue a resize itself.
8783 * This function is only useful for container implementations and
8784 * never should be called by an application.
8787 gtk_widget_set_child_visible (GtkWidget *widget,
8788 gboolean is_visible)
8790 GtkWidgetPrivate *priv;
8792 g_return_if_fail (GTK_IS_WIDGET (widget));
8793 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8795 priv = widget->priv;
8797 g_object_ref (widget);
8798 gtk_widget_verify_invariants (widget);
8801 priv->child_visible = TRUE;
8804 GtkWidget *toplevel;
8806 priv->child_visible = FALSE;
8808 toplevel = gtk_widget_get_toplevel (widget);
8809 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8810 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8813 if (priv->parent && gtk_widget_get_realized (priv->parent))
8815 if (gtk_widget_get_mapped (priv->parent) &&
8816 priv->child_visible &&
8817 gtk_widget_get_visible (widget))
8818 gtk_widget_map (widget);
8820 gtk_widget_unmap (widget);
8823 gtk_widget_verify_invariants (widget);
8824 g_object_unref (widget);
8828 * gtk_widget_get_child_visible:
8829 * @widget: a #GtkWidget
8831 * Gets the value set with gtk_widget_set_child_visible().
8832 * If you feel a need to use this function, your code probably
8833 * needs reorganization.
8835 * This function is only useful for container implementations and
8836 * never should be called by an application.
8838 * Return value: %TRUE if the widget is mapped with the parent.
8841 gtk_widget_get_child_visible (GtkWidget *widget)
8843 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8845 return widget->priv->child_visible;
8849 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8851 GtkWidget *toplevel;
8853 toplevel = gtk_widget_get_toplevel (widget);
8855 if (gtk_widget_is_toplevel (toplevel))
8857 if (GTK_IS_WINDOW (toplevel))
8858 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8859 else if (GTK_IS_INVISIBLE (toplevel))
8860 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8867 * gtk_widget_get_screen:
8868 * @widget: a #GtkWidget
8870 * Get the #GdkScreen from the toplevel window associated with
8871 * this widget. This function can only be called after the widget
8872 * has been added to a widget hierarchy with a #GtkWindow
8875 * In general, you should only create screen specific
8876 * resources when a widget has been realized, and you should
8877 * free those resources when the widget is unrealized.
8879 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8884 gtk_widget_get_screen (GtkWidget *widget)
8888 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8890 screen = gtk_widget_get_screen_unchecked (widget);
8897 g_warning (G_STRLOC ": Can't get associated screen"
8898 " for a widget unless it is inside a toplevel GtkWindow\n"
8899 " widget type is %s associated top level type is %s",
8900 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8901 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8903 return gdk_screen_get_default ();
8908 * gtk_widget_has_screen:
8909 * @widget: a #GtkWidget
8911 * Checks whether there is a #GdkScreen is associated with
8912 * this widget. All toplevel widgets have an associated
8913 * screen, and all widgets added into a hierarchy with a toplevel
8914 * window at the top.
8916 * Return value: %TRUE if there is a #GdkScreen associcated
8922 gtk_widget_has_screen (GtkWidget *widget)
8924 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8926 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8930 * gtk_widget_get_display:
8931 * @widget: a #GtkWidget
8933 * Get the #GdkDisplay for the toplevel window associated with
8934 * this widget. This function can only be called after the widget
8935 * has been added to a widget hierarchy with a #GtkWindow at the top.
8937 * In general, you should only create display specific
8938 * resources when a widget has been realized, and you should
8939 * free those resources when the widget is unrealized.
8941 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8946 gtk_widget_get_display (GtkWidget *widget)
8948 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8950 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8954 * gtk_widget_get_root_window:
8955 * @widget: a #GtkWidget
8957 * Get the root window where this widget is located. This function can
8958 * only be called after the widget has been added to a widget
8959 * hierarchy with #GtkWindow at the top.
8961 * The root window is useful for such purposes as creating a popup
8962 * #GdkWindow associated with the window. In general, you should only
8963 * create display specific resources when a widget has been realized,
8964 * and you should free those resources when the widget is unrealized.
8966 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8971 gtk_widget_get_root_window (GtkWidget *widget)
8973 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8975 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8979 * gtk_widget_child_focus:
8980 * @widget: a #GtkWidget
8981 * @direction: direction of focus movement
8983 * This function is used by custom widget implementations; if you're
8984 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8985 * to a particular widget, and gtk_container_set_focus_chain() to
8986 * change the focus tab order. So you may want to investigate those
8987 * functions instead.
8989 * gtk_widget_child_focus() is called by containers as the user moves
8990 * around the window using keyboard shortcuts. @direction indicates
8991 * what kind of motion is taking place (up, down, left, right, tab
8992 * forward, tab backward). gtk_widget_child_focus() emits the
8993 * #GtkWidget::focus signal; widgets override the default handler
8994 * for this signal in order to implement appropriate focus behavior.
8996 * The default ::focus handler for a widget should return %TRUE if
8997 * moving in @direction left the focus on a focusable location inside
8998 * that widget, and %FALSE if moving in @direction moved the focus
8999 * outside the widget. If returning %TRUE, widgets normally
9000 * call gtk_widget_grab_focus() to place the focus accordingly;
9001 * if returning %FALSE, they don't modify the current focus location.
9003 * Return value: %TRUE if focus ended up inside @widget
9006 gtk_widget_child_focus (GtkWidget *widget,
9007 GtkDirectionType direction)
9009 gboolean return_val;
9011 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9013 if (!gtk_widget_get_visible (widget) ||
9014 !gtk_widget_is_sensitive (widget))
9017 /* child widgets must set CAN_FOCUS, containers
9018 * don't have to though.
9020 if (!GTK_IS_CONTAINER (widget) &&
9021 !gtk_widget_get_can_focus (widget))
9024 g_signal_emit (widget,
9025 widget_signals[FOCUS],
9027 direction, &return_val);
9033 * gtk_widget_keynav_failed:
9034 * @widget: a #GtkWidget
9035 * @direction: direction of focus movement
9037 * This function should be called whenever keyboard navigation within
9038 * a single widget hits a boundary. The function emits the
9039 * #GtkWidget::keynav-failed signal on the widget and its return
9040 * value should be interpreted in a way similar to the return value of
9041 * gtk_widget_child_focus():
9043 * When %TRUE is returned, stay in the widget, the failed keyboard
9044 * navigation is Ok and/or there is nowhere we can/should move the
9047 * When %FALSE is returned, the caller should continue with keyboard
9048 * navigation outside the widget, e.g. by calling
9049 * gtk_widget_child_focus() on the widget's toplevel.
9051 * The default ::keynav-failed handler returns %TRUE for
9052 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9053 * values of #GtkDirectionType, it looks at the
9054 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9055 * if the setting is %TRUE. This way the entire user interface
9056 * becomes cursor-navigatable on input devices such as mobile phones
9057 * which only have cursor keys but no tab key.
9059 * Whenever the default handler returns %TRUE, it also calls
9060 * gtk_widget_error_bell() to notify the user of the failed keyboard
9063 * A use case for providing an own implementation of ::keynav-failed
9064 * (either by connecting to it or by overriding it) would be a row of
9065 * #GtkEntry widgets where the user should be able to navigate the
9066 * entire row with the cursor keys, as e.g. known from user interfaces
9067 * that require entering license keys.
9069 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9070 * if the emitting widget should try to handle the keyboard
9071 * navigation attempt in its parent container(s).
9076 gtk_widget_keynav_failed (GtkWidget *widget,
9077 GtkDirectionType direction)
9079 gboolean return_val;
9081 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9083 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9084 direction, &return_val);
9090 * gtk_widget_error_bell:
9091 * @widget: a #GtkWidget
9093 * Notifies the user about an input-related error on this widget.
9094 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9095 * gdk_window_beep(), otherwise it does nothing.
9097 * Note that the effect of gdk_window_beep() can be configured in many
9098 * ways, depending on the windowing backend and the desktop environment
9099 * or window manager that is used.
9104 gtk_widget_error_bell (GtkWidget *widget)
9106 GtkWidgetPrivate *priv;
9107 GtkSettings* settings;
9110 g_return_if_fail (GTK_IS_WIDGET (widget));
9112 priv = widget->priv;
9114 settings = gtk_widget_get_settings (widget);
9118 g_object_get (settings,
9119 "gtk-error-bell", &beep,
9122 if (beep && priv->window)
9123 gdk_window_beep (priv->window);
9127 gtk_widget_set_usize_internal (GtkWidget *widget,
9130 GtkQueueResizeFlags flags)
9132 GtkWidgetAuxInfo *aux_info;
9133 gboolean changed = FALSE;
9135 g_object_freeze_notify (G_OBJECT (widget));
9137 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9139 if (width > -2 && aux_info->width != width)
9141 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9142 g_object_notify (G_OBJECT (widget), "width-request");
9143 aux_info->width = width;
9146 if (height > -2 && aux_info->height != height)
9148 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9149 g_object_notify (G_OBJECT (widget), "height-request");
9150 aux_info->height = height;
9154 if (gtk_widget_get_visible (widget) && changed)
9156 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9157 gtk_widget_queue_resize (widget);
9159 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9162 g_object_thaw_notify (G_OBJECT (widget));
9166 * gtk_widget_set_size_request:
9167 * @widget: a #GtkWidget
9168 * @width: width @widget should request, or -1 to unset
9169 * @height: height @widget should request, or -1 to unset
9171 * Sets the minimum size of a widget; that is, the widget's size
9172 * request will be @width by @height. You can use this function to
9173 * force a widget to be either larger or smaller than it normally
9176 * In most cases, gtk_window_set_default_size() is a better choice for
9177 * toplevel windows than this function; setting the default size will
9178 * still allow users to shrink the window. Setting the size request
9179 * will force them to leave the window at least as large as the size
9180 * request. When dealing with window sizes,
9181 * gtk_window_set_geometry_hints() can be a useful function as well.
9183 * Note the inherent danger of setting any fixed size - themes,
9184 * translations into other languages, different fonts, and user action
9185 * can all change the appropriate size for a given widget. So, it's
9186 * basically impossible to hardcode a size that will always be
9189 * The size request of a widget is the smallest size a widget can
9190 * accept while still functioning well and drawing itself correctly.
9191 * However in some strange cases a widget may be allocated less than
9192 * its requested size, and in many cases a widget may be allocated more
9193 * space than it requested.
9195 * If the size request in a given direction is -1 (unset), then
9196 * the "natural" size request of the widget will be used instead.
9198 * Widgets can't actually be allocated a size less than 1 by 1, but
9199 * you can pass 0,0 to this function to mean "as small as possible."
9201 * The size request set here does not include any margin from the
9202 * #GtkWidget properties margin-left, margin-right, margin-top, and
9203 * margin-bottom, but it does include pretty much all other padding
9204 * or border properties set by any subclass of #GtkWidget.
9207 gtk_widget_set_size_request (GtkWidget *widget,
9211 g_return_if_fail (GTK_IS_WIDGET (widget));
9212 g_return_if_fail (width >= -1);
9213 g_return_if_fail (height >= -1);
9220 gtk_widget_set_usize_internal (widget, width, height, 0);
9225 * gtk_widget_get_size_request:
9226 * @widget: a #GtkWidget
9227 * @width: (out) (allow-none): return location for width, or %NULL
9228 * @height: (out) (allow-none): return location for height, or %NULL
9230 * Gets the size request that was explicitly set for the widget using
9231 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9232 * @height indicates that that dimension has not been set explicitly
9233 * and the natural requisition of the widget will be used intead. See
9234 * gtk_widget_set_size_request(). To get the size a widget will
9235 * actually request, call gtk_widget_get_preferred_size() instead of
9239 gtk_widget_get_size_request (GtkWidget *widget,
9243 const GtkWidgetAuxInfo *aux_info;
9245 g_return_if_fail (GTK_IS_WIDGET (widget));
9247 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9250 *width = aux_info->width;
9253 *height = aux_info->height;
9257 * _gtk_widget_override_size_request:
9258 * @widget: a #GtkWidget
9259 * @width: new forced minimum width
9260 * @height: new forced minimum height
9261 * @old_width: location to store previous forced minimum width
9262 * @old_width: location to store previous forced minumum height
9264 * Temporarily establishes a forced minimum size for a widget; this
9265 * is used by GtkWindow when calculating the size to add to the
9266 * window's geometry widget. Cached sizes for the widget and its
9267 * parents are invalidated, so that subsequent calls to the size
9268 * negotiation machinery produce the overriden result, but the
9269 * widget is not queued for relayout or redraw. The old size must
9270 * be restored with _gtk_widget_restore_size_request() or things
9274 _gtk_widget_override_size_request (GtkWidget *widget,
9280 gtk_widget_get_size_request (widget, old_width, old_height);
9281 gtk_widget_set_usize_internal (widget, width, height,
9282 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9286 * _gtk_widget_restore_size_request:
9287 * @widget: a #GtkWidget
9288 * @old_width: saved forced minimum size
9289 * @old_height: saved forced minimum size
9291 * Undoes the operation of_gtk_widget_override_size_request().
9294 _gtk_widget_restore_size_request (GtkWidget *widget,
9298 gtk_widget_set_usize_internal (widget, old_width, old_height,
9299 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9303 * gtk_widget_set_events:
9304 * @widget: a #GtkWidget
9305 * @events: event mask
9307 * Sets the event mask (see #GdkEventMask) for a widget. The event
9308 * mask determines which events a widget will receive. Keep in mind
9309 * that different widgets have different default event masks, and by
9310 * changing the event mask you may disrupt a widget's functionality,
9311 * so be careful. This function must be called while a widget is
9312 * unrealized. Consider gtk_widget_add_events() for widgets that are
9313 * already realized, or if you want to preserve the existing event
9314 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9315 * to get events on those widgets, place them inside a #GtkEventBox
9316 * and receive events on the event box.
9319 gtk_widget_set_events (GtkWidget *widget,
9322 g_return_if_fail (GTK_IS_WIDGET (widget));
9323 g_return_if_fail (!gtk_widget_get_realized (widget));
9325 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9326 GINT_TO_POINTER (events));
9327 g_object_notify (G_OBJECT (widget), "events");
9331 * gtk_widget_set_device_events:
9332 * @widget: a #GtkWidget
9333 * @device: a #GdkDevice
9334 * @events: event mask
9336 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9337 * mask determines which events a widget will receive from @device. Keep
9338 * in mind that different widgets have different default event masks, and by
9339 * changing the event mask you may disrupt a widget's functionality,
9340 * so be careful. This function must be called while a widget is
9341 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9342 * already realized, or if you want to preserve the existing event
9343 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9344 * to get events on those widgets, place them inside a #GtkEventBox
9345 * and receive events on the event box.
9350 gtk_widget_set_device_events (GtkWidget *widget,
9352 GdkEventMask events)
9354 GHashTable *device_events;
9356 g_return_if_fail (GTK_IS_WIDGET (widget));
9357 g_return_if_fail (GDK_IS_DEVICE (device));
9358 g_return_if_fail (!gtk_widget_get_realized (widget));
9360 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9362 if (G_UNLIKELY (!device_events))
9364 device_events = g_hash_table_new (NULL, NULL);
9365 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9366 (GDestroyNotify) g_hash_table_unref);
9369 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9373 * gtk_widget_set_device_enabled:
9374 * @widget: a #GtkWidget
9375 * @device: a #GdkDevice
9376 * @enabled: whether to enable the device
9378 * Enables or disables a #GdkDevice to interact with @widget
9379 * and all its children.
9381 * It does so by descending through the #GdkWindow hierarchy
9382 * and enabling the same mask that is has for core events
9383 * (i.e. the one that gdk_window_get_events() returns).
9388 gtk_widget_set_device_enabled (GtkWidget *widget,
9392 GList *enabled_devices;
9394 g_return_if_fail (GTK_IS_WIDGET (widget));
9395 g_return_if_fail (GDK_IS_DEVICE (device));
9397 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9398 enabled_devices = g_list_append (enabled_devices, device);
9400 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9401 enabled_devices, (GDestroyNotify) g_list_free);;
9403 if (gtk_widget_get_realized (widget))
9404 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9408 * gtk_widget_get_device_enabled:
9409 * @widget: a #GtkWidget
9410 * @device: a #GdkDevice
9412 * Returns whether @device can interact with @widget and its
9413 * children. See gtk_widget_set_device_enabled().
9415 * Return value: %TRUE is @device is enabled for @widget
9420 gtk_widget_get_device_enabled (GtkWidget *widget,
9423 GList *enabled_devices;
9425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9426 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9428 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9430 return g_list_find (enabled_devices, device) != NULL;
9434 gtk_widget_add_events_internal_list (GtkWidget *widget,
9441 for (l = window_list; l != NULL; l = l->next)
9443 GdkWindow *window = l->data;
9446 gdk_window_get_user_data (window, &user_data);
9447 if (user_data == widget)
9452 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9454 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9456 children = gdk_window_get_children (window);
9457 gtk_widget_add_events_internal_list (widget, device, events, children);
9458 g_list_free (children);
9464 gtk_widget_add_events_internal (GtkWidget *widget,
9468 GtkWidgetPrivate *priv = widget->priv;
9471 if (!gtk_widget_get_has_window (widget))
9472 window_list = gdk_window_get_children (priv->window);
9474 window_list = g_list_prepend (NULL, priv->window);
9476 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9478 g_list_free (window_list);
9482 * gtk_widget_add_events:
9483 * @widget: a #GtkWidget
9484 * @events: an event mask, see #GdkEventMask
9486 * Adds the events in the bitfield @events to the event mask for
9487 * @widget. See gtk_widget_set_events() for details.
9490 gtk_widget_add_events (GtkWidget *widget,
9495 g_return_if_fail (GTK_IS_WIDGET (widget));
9497 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9498 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9499 GINT_TO_POINTER (old_events | events));
9501 if (gtk_widget_get_realized (widget))
9503 gtk_widget_add_events_internal (widget, NULL, events);
9504 gtk_widget_update_devices_mask (widget, FALSE);
9507 g_object_notify (G_OBJECT (widget), "events");
9511 * gtk_widget_add_device_events:
9512 * @widget: a #GtkWidget
9513 * @device: a #GdkDevice
9514 * @events: an event mask, see #GdkEventMask
9516 * Adds the device events in the bitfield @events to the event mask for
9517 * @widget. See gtk_widget_set_device_events() for details.
9522 gtk_widget_add_device_events (GtkWidget *widget,
9524 GdkEventMask events)
9526 GdkEventMask old_events;
9527 GHashTable *device_events;
9529 g_return_if_fail (GTK_IS_WIDGET (widget));
9530 g_return_if_fail (GDK_IS_DEVICE (device));
9532 old_events = gtk_widget_get_device_events (widget, device);
9534 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9536 if (G_UNLIKELY (!device_events))
9538 device_events = g_hash_table_new (NULL, NULL);
9539 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9540 (GDestroyNotify) g_hash_table_unref);
9543 g_hash_table_insert (device_events, device,
9544 GUINT_TO_POINTER (old_events | events));
9546 if (gtk_widget_get_realized (widget))
9547 gtk_widget_add_events_internal (widget, device, events);
9549 g_object_notify (G_OBJECT (widget), "events");
9553 * gtk_widget_get_toplevel:
9554 * @widget: a #GtkWidget
9556 * This function returns the topmost widget in the container hierarchy
9557 * @widget is a part of. If @widget has no parent widgets, it will be
9558 * returned as the topmost widget. No reference will be added to the
9559 * returned widget; it should not be unreferenced.
9561 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9562 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9564 * %NULL if @widget wasn't inside a toplevel window, and if the
9565 * window was inside a #GtkWindow-derived widget which was in turn
9566 * inside the toplevel #GtkWindow. While the second case may
9567 * seem unlikely, it actually happens when a #GtkPlug is embedded
9568 * inside a #GtkSocket within the same application.
9570 * To reliably find the toplevel #GtkWindow, use
9571 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9572 * is set on the result.
9574 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9575 * if (gtk_widget_is_toplevel (toplevel))
9577 * /* Perform action on toplevel. */
9581 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9582 * if there's no ancestor.
9585 gtk_widget_get_toplevel (GtkWidget *widget)
9587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9589 while (widget->priv->parent)
9590 widget = widget->priv->parent;
9596 * gtk_widget_get_ancestor:
9597 * @widget: a #GtkWidget
9598 * @widget_type: ancestor type
9600 * Gets the first ancestor of @widget with type @widget_type. For example,
9601 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9602 * the first #GtkBox that's an ancestor of @widget. No reference will be
9603 * added to the returned widget; it should not be unreferenced. See note
9604 * about checking for a toplevel #GtkWindow in the docs for
9605 * gtk_widget_get_toplevel().
9607 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9608 * considers @widget to be an ancestor of itself.
9610 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9613 gtk_widget_get_ancestor (GtkWidget *widget,
9616 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9618 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9619 widget = widget->priv->parent;
9621 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9628 * gtk_widget_set_visual:
9629 * @widget: a #GtkWidget
9630 * @visual: visual to be used or %NULL to unset a previous one
9632 * Sets the visual that should be used for by widget and its children for
9633 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9634 * returned by gdk_widget_get_screen(), so handling the
9635 * #GtkWidget::screen-changed signal is necessary.
9637 * Setting a new @visual will not cause @widget to recreate its windows,
9638 * so you should call this function before @widget is realized.
9641 gtk_widget_set_visual (GtkWidget *widget,
9644 g_return_if_fail (GTK_IS_WIDGET (widget));
9645 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9648 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9651 g_object_set_qdata_full (G_OBJECT (widget),
9653 g_object_ref (visual),
9658 * gtk_widget_get_visual:
9659 * @widget: a #GtkWidget
9661 * Gets the visual that will be used to render @widget.
9663 * Return value: (transfer none): the visual for @widget
9666 gtk_widget_get_visual (GtkWidget *widget)
9672 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9674 if (gtk_widget_get_has_window (widget) &&
9675 widget->priv->window)
9676 return gdk_window_get_visual (widget->priv->window);
9678 screen = gtk_widget_get_screen (widget);
9680 for (w = widget; w != NULL; w = w->priv->parent)
9682 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9685 if (gdk_visual_get_screen (visual) == screen)
9688 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9689 gtk_widget_get_name (widget));
9693 return gdk_screen_get_system_visual (screen);
9697 * gtk_widget_get_settings:
9698 * @widget: a #GtkWidget
9700 * Gets the settings object holding the settings used for this widget.
9702 * Note that this function can only be called when the #GtkWidget
9703 * is attached to a toplevel, since the settings object is specific
9704 * to a particular #GdkScreen.
9706 * Return value: (transfer none): the relevant #GtkSettings object
9709 gtk_widget_get_settings (GtkWidget *widget)
9711 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9713 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9717 * gtk_widget_get_events:
9718 * @widget: a #GtkWidget
9720 * Returns the event mask for the widget (a bitfield containing flags
9721 * from the #GdkEventMask enumeration). These are the events that the widget
9724 * Return value: event mask for @widget
9727 gtk_widget_get_events (GtkWidget *widget)
9729 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9731 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9735 * gtk_widget_get_device_events:
9736 * @widget: a #GtkWidget
9737 * @device: a #GdkDevice
9739 * Returns the events mask for the widget corresponding to an specific device. These
9740 * are the events that the widget will receive when @device operates on it.
9742 * Returns: device event mask for @widget
9747 gtk_widget_get_device_events (GtkWidget *widget,
9750 GHashTable *device_events;
9752 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9753 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9755 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9760 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9764 * gtk_widget_get_pointer:
9765 * @widget: a #GtkWidget
9766 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9767 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9769 * Obtains the location of the mouse pointer in widget coordinates.
9770 * Widget coordinates are a bit odd; for historical reasons, they are
9771 * defined as @widget->window coordinates for widgets that are not
9772 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9773 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9775 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
9778 gtk_widget_get_pointer (GtkWidget *widget,
9782 GtkWidgetPrivate *priv;
9784 g_return_if_fail (GTK_IS_WIDGET (widget));
9786 priv = widget->priv;
9793 if (gtk_widget_get_realized (widget))
9795 gdk_window_get_device_position (priv->window,
9796 gdk_device_manager_get_client_pointer (
9797 gdk_display_get_device_manager (
9798 gtk_widget_get_display (widget))),
9801 if (!gtk_widget_get_has_window (widget))
9804 *x -= priv->allocation.x;
9806 *y -= priv->allocation.y;
9812 * gtk_widget_is_ancestor:
9813 * @widget: a #GtkWidget
9814 * @ancestor: another #GtkWidget
9816 * Determines whether @widget is somewhere inside @ancestor, possibly with
9817 * intermediate containers.
9819 * Return value: %TRUE if @ancestor contains @widget as a child,
9820 * grandchild, great grandchild, etc.
9823 gtk_widget_is_ancestor (GtkWidget *widget,
9824 GtkWidget *ancestor)
9826 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9827 g_return_val_if_fail (ancestor != NULL, FALSE);
9831 if (widget->priv->parent == ancestor)
9833 widget = widget->priv->parent;
9839 static GQuark quark_composite_name = 0;
9842 * gtk_widget_set_composite_name:
9843 * @widget: a #GtkWidget.
9844 * @name: the name to set
9846 * Sets a widgets composite name. The widget must be
9847 * a composite child of its parent; see gtk_widget_push_composite_child().
9850 gtk_widget_set_composite_name (GtkWidget *widget,
9853 g_return_if_fail (GTK_IS_WIDGET (widget));
9854 g_return_if_fail (widget->priv->composite_child);
9855 g_return_if_fail (name != NULL);
9857 if (!quark_composite_name)
9858 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9860 g_object_set_qdata_full (G_OBJECT (widget),
9861 quark_composite_name,
9867 * gtk_widget_get_composite_name:
9868 * @widget: a #GtkWidget
9870 * Obtains the composite name of a widget.
9872 * Returns: the composite name of @widget, or %NULL if @widget is not
9873 * a composite child. The string should be freed when it is no
9877 gtk_widget_get_composite_name (GtkWidget *widget)
9879 GtkWidgetPrivate *priv;
9881 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9883 priv = widget->priv;
9885 if (widget->priv->composite_child && priv->parent)
9886 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9893 * gtk_widget_push_composite_child:
9895 * Makes all newly-created widgets as composite children until
9896 * the corresponding gtk_widget_pop_composite_child() call.
9898 * A composite child is a child that's an implementation detail of the
9899 * container it's inside and should not be visible to people using the
9900 * container. Composite children aren't treated differently by GTK (but
9901 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9902 * builders might want to treat them in a different way.
9904 * Here is a simple example:
9906 * gtk_widget_push_composite_child ();
9907 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9908 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9909 * gtk_widget_pop_composite_child ();
9910 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9911 * GTK_WIDGET (scrolled_window));
9912 * g_object_ref (scrolled_window->hscrollbar);
9916 gtk_widget_push_composite_child (void)
9918 composite_child_stack++;
9922 * gtk_widget_pop_composite_child:
9924 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9927 gtk_widget_pop_composite_child (void)
9929 if (composite_child_stack)
9930 composite_child_stack--;
9934 gtk_widget_emit_direction_changed (GtkWidget *widget,
9935 GtkTextDirection old_dir)
9937 gtk_widget_update_pango_context (widget);
9939 if (widget->priv->context)
9940 gtk_style_context_set_direction (widget->priv->context,
9941 gtk_widget_get_direction (widget));
9943 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9947 * gtk_widget_set_direction:
9948 * @widget: a #GtkWidget
9949 * @dir: the new direction
9951 * Sets the reading direction on a particular widget. This direction
9952 * controls the primary direction for widgets containing text,
9953 * and also the direction in which the children of a container are
9954 * packed. The ability to set the direction is present in order
9955 * so that correct localization into languages with right-to-left
9956 * reading directions can be done. Generally, applications will
9957 * let the default reading direction present, except for containers
9958 * where the containers are arranged in an order that is explicitely
9959 * visual rather than logical (such as buttons for text justification).
9961 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9962 * set by gtk_widget_set_default_direction() will be used.
9965 gtk_widget_set_direction (GtkWidget *widget,
9966 GtkTextDirection dir)
9968 GtkTextDirection old_dir;
9970 g_return_if_fail (GTK_IS_WIDGET (widget));
9971 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9973 old_dir = gtk_widget_get_direction (widget);
9975 widget->priv->direction = dir;
9977 if (old_dir != gtk_widget_get_direction (widget))
9978 gtk_widget_emit_direction_changed (widget, old_dir);
9982 * gtk_widget_get_direction:
9983 * @widget: a #GtkWidget
9985 * Gets the reading direction for a particular widget. See
9986 * gtk_widget_set_direction().
9988 * Return value: the reading direction for the widget.
9991 gtk_widget_get_direction (GtkWidget *widget)
9993 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9995 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9996 return gtk_default_direction;
9998 return widget->priv->direction;
10002 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10004 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10006 g_object_ref (widget);
10008 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10009 gtk_widget_emit_direction_changed (widget, old_dir);
10011 if (GTK_IS_CONTAINER (widget))
10012 gtk_container_forall (GTK_CONTAINER (widget),
10013 gtk_widget_set_default_direction_recurse,
10016 g_object_unref (widget);
10020 * gtk_widget_set_default_direction:
10021 * @dir: the new default direction. This cannot be
10022 * %GTK_TEXT_DIR_NONE.
10024 * Sets the default reading direction for widgets where the
10025 * direction has not been explicitly set by gtk_widget_set_direction().
10028 gtk_widget_set_default_direction (GtkTextDirection dir)
10030 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10032 if (dir != gtk_default_direction)
10034 GList *toplevels, *tmp_list;
10035 GtkTextDirection old_dir = gtk_default_direction;
10037 gtk_default_direction = dir;
10039 tmp_list = toplevels = gtk_window_list_toplevels ();
10040 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10044 gtk_widget_set_default_direction_recurse (tmp_list->data,
10045 GUINT_TO_POINTER (old_dir));
10046 g_object_unref (tmp_list->data);
10047 tmp_list = tmp_list->next;
10050 g_list_free (toplevels);
10055 * gtk_widget_get_default_direction:
10057 * Obtains the current default reading direction. See
10058 * gtk_widget_set_default_direction().
10060 * Return value: the current default direction.
10063 gtk_widget_get_default_direction (void)
10065 return gtk_default_direction;
10069 gtk_widget_dispose (GObject *object)
10071 GtkWidget *widget = GTK_WIDGET (object);
10072 GtkWidgetPrivate *priv = widget->priv;
10075 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10076 else if (gtk_widget_get_visible (widget))
10077 gtk_widget_hide (widget);
10079 priv->visible = FALSE;
10080 if (gtk_widget_get_realized (widget))
10081 gtk_widget_unrealize (widget);
10083 if (!priv->in_destruction)
10085 priv->in_destruction = TRUE;
10086 g_signal_emit (object, widget_signals[DESTROY], 0);
10087 priv->in_destruction = FALSE;
10090 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10094 gtk_widget_real_destroy (GtkWidget *object)
10096 /* gtk_object_destroy() will already hold a refcount on object */
10097 GtkWidget *widget = GTK_WIDGET (object);
10098 GtkWidgetPrivate *priv = widget->priv;
10100 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10102 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10106 gtk_accessible_set_widget (accessible, NULL);
10107 g_object_unref (accessible);
10111 /* wipe accelerator closures (keep order) */
10112 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10113 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10115 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10116 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10118 gtk_grab_remove (widget);
10121 g_object_unref (priv->style);
10122 priv->style = gtk_widget_get_default_style ();
10123 g_object_ref (priv->style);
10127 gtk_widget_finalize (GObject *object)
10129 GtkWidget *widget = GTK_WIDGET (object);
10130 GtkWidgetPrivate *priv = widget->priv;
10131 GtkWidgetAuxInfo *aux_info;
10132 GtkAccessible *accessible;
10134 gtk_grab_remove (widget);
10136 g_object_unref (priv->style);
10137 priv->style = NULL;
10139 g_free (priv->name);
10141 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10143 gtk_widget_aux_info_destroy (aux_info);
10145 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10147 g_object_unref (accessible);
10150 gtk_widget_path_free (priv->path);
10153 g_object_unref (priv->context);
10155 _gtk_widget_free_cached_sizes (widget);
10157 if (g_object_is_floating (object))
10158 g_warning ("A floating object was finalized. This means that someone\n"
10159 "called g_object_unref() on an object that had only a floating\n"
10160 "reference; the initial floating reference is not owned by anyone\n"
10161 "and must be removed with g_object_ref_sink().");
10163 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10166 /*****************************************
10167 * gtk_widget_real_map:
10172 *****************************************/
10175 gtk_widget_real_map (GtkWidget *widget)
10177 GtkWidgetPrivate *priv = widget->priv;
10179 g_assert (gtk_widget_get_realized (widget));
10181 if (!gtk_widget_get_mapped (widget))
10183 gtk_widget_set_mapped (widget, TRUE);
10185 if (gtk_widget_get_has_window (widget))
10186 gdk_window_show (priv->window);
10190 /*****************************************
10191 * gtk_widget_real_unmap:
10196 *****************************************/
10199 gtk_widget_real_unmap (GtkWidget *widget)
10201 GtkWidgetPrivate *priv = widget->priv;
10203 if (gtk_widget_get_mapped (widget))
10205 gtk_widget_set_mapped (widget, FALSE);
10207 if (gtk_widget_get_has_window (widget))
10208 gdk_window_hide (priv->window);
10212 /*****************************************
10213 * gtk_widget_real_realize:
10218 *****************************************/
10221 gtk_widget_real_realize (GtkWidget *widget)
10223 GtkWidgetPrivate *priv = widget->priv;
10225 g_assert (!gtk_widget_get_has_window (widget));
10227 gtk_widget_set_realized (widget, TRUE);
10230 priv->window = gtk_widget_get_parent_window (widget);
10231 g_object_ref (priv->window);
10235 /*****************************************
10236 * gtk_widget_real_unrealize:
10241 *****************************************/
10244 gtk_widget_real_unrealize (GtkWidget *widget)
10246 GtkWidgetPrivate *priv = widget->priv;
10248 g_assert (!widget->priv->mapped);
10250 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10253 /* We must do unrealize child widget BEFORE container widget.
10254 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10255 * So, unrealizing container widget bofore its children causes the problem
10256 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10259 if (GTK_IS_CONTAINER (widget))
10260 gtk_container_forall (GTK_CONTAINER (widget),
10261 (GtkCallback) gtk_widget_unrealize,
10264 if (gtk_widget_get_has_window (widget))
10266 gdk_window_set_user_data (priv->window, NULL);
10267 gdk_window_destroy (priv->window);
10268 priv->window = NULL;
10272 g_object_unref (priv->window);
10273 priv->window = NULL;
10276 gtk_selection_remove_all (widget);
10278 gtk_widget_set_realized (widget, FALSE);
10282 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10283 GtkOrientation orientation,
10284 gint *minimum_size,
10285 gint *natural_size)
10287 const GtkWidgetAuxInfo *aux_info;
10289 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10291 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10292 aux_info->width > 0)
10294 *minimum_size = MAX (*minimum_size, aux_info->width);
10296 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10297 aux_info->height > 0)
10299 *minimum_size = MAX (*minimum_size, aux_info->height);
10302 /* Fix it if set_size_request made natural size smaller than min size.
10303 * This would also silently fix broken widgets, but we warn about them
10304 * in gtksizerequest.c when calling their size request vfuncs.
10306 *natural_size = MAX (*natural_size, *minimum_size);
10308 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10310 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10311 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10315 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10316 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10321 * _gtk_widget_peek_request_cache:
10323 * Returns the address of the widget's request cache (strictly for
10324 * internal use in gtksizerequest.c)
10326 * Return value: the address of @widget's size request cache.
10329 _gtk_widget_peek_request_cache (GtkWidget *widget)
10331 /* Don't bother slowing things down with the return_if_fail guards here */
10332 return &widget->priv->requests;
10336 * _gtk_widget_set_device_window:
10337 * @widget: a #GtkWidget
10338 * @device: a #GdkDevice
10339 * @window: the new device window
10341 * Sets pointer window for @widget and @device.
10342 * Does not ref @window.
10345 _gtk_widget_set_device_window (GtkWidget *widget,
10349 GHashTable *device_window;
10351 g_return_if_fail (GTK_IS_WIDGET (widget));
10352 g_return_if_fail (GDK_IS_DEVICE (device));
10353 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10355 if (!gtk_widget_get_mapped (widget))
10358 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10360 if (!device_window && window)
10362 device_window = g_hash_table_new (NULL, NULL);
10363 g_object_set_qdata_full (G_OBJECT (widget),
10364 quark_pointer_window,
10366 (GDestroyNotify) g_hash_table_destroy);
10370 g_hash_table_insert (device_window, device, window);
10371 else if (device_window)
10373 g_hash_table_remove (device_window, device);
10375 if (g_hash_table_size (device_window) == 0)
10376 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10381 * _gtk_widget_get_device_window:
10382 * @widget: a #GtkWidget
10383 * @device: a #GdkDevice
10385 * Return value: the device window set on @widget, or %NULL
10388 _gtk_widget_get_device_window (GtkWidget *widget,
10391 GHashTable *device_window;
10393 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10394 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10396 if (!gtk_widget_get_mapped (widget))
10399 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10401 if (!device_window)
10404 return g_hash_table_lookup (device_window, device);
10408 * _gtk_widget_list_devices:
10409 * @widget: a #GtkWidget
10411 * Returns the list of #GdkDevices that is currently on top
10412 * of any window belonging to @widget.
10413 * Free the list with g_list_free(), the elements are owned
10414 * by GTK+ and must not be freed.
10417 _gtk_widget_list_devices (GtkWidget *widget)
10419 GHashTableIter iter;
10420 GHashTable *device_window;
10421 GList *devices = NULL;
10422 gpointer key, value;
10424 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10426 if (!gtk_widget_get_mapped (widget))
10429 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10431 if (G_UNLIKELY (!device_window))
10434 g_hash_table_iter_init (&iter, device_window);
10436 while (g_hash_table_iter_next (&iter, &key, &value))
10437 devices = g_list_prepend (devices, key);
10443 synth_crossing (GtkWidget *widget,
10447 GdkCrossingMode mode,
10448 GdkNotifyType detail)
10452 event = gdk_event_new (type);
10454 event->crossing.window = g_object_ref (window);
10455 event->crossing.send_event = TRUE;
10456 event->crossing.subwindow = g_object_ref (window);
10457 event->crossing.time = GDK_CURRENT_TIME;
10458 event->crossing.x = event->crossing.y = 0;
10459 event->crossing.x_root = event->crossing.y_root = 0;
10460 event->crossing.mode = mode;
10461 event->crossing.detail = detail;
10462 event->crossing.focus = FALSE;
10463 event->crossing.state = 0;
10464 gdk_event_set_device (event, device);
10467 widget = gtk_get_event_widget (event);
10470 gtk_widget_event_internal (widget, event);
10472 gdk_event_free (event);
10476 * _gtk_widget_synthesize_crossing:
10477 * @from: the #GtkWidget the virtual pointer is leaving.
10478 * @to: the #GtkWidget the virtual pointer is moving to.
10479 * @mode: the #GdkCrossingMode to place on the synthesized events.
10481 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10483 * The real pointer window is the window that most recently received an enter notify
10484 * event. Windows that don't select for crossing events can't become the real
10485 * poiner window. The real pointer widget that owns the real pointer window. The
10486 * effective pointer window is the same as the real pointer window unless the real
10487 * pointer widget is either insensitive or there is a grab on a widget that is not
10488 * an ancestor of the real pointer widget (in which case the effective pointer
10489 * window should be the root window).
10491 * When the effective pointer window is the same as the real poiner window, we
10492 * receive crossing events from the windowing system. When the effective pointer
10493 * window changes to become different from the real pointer window we synthesize
10494 * crossing events, attempting to follow X protocol rules:
10496 * When the root window becomes the effective pointer window:
10497 * - leave notify on real pointer window, detail Ancestor
10498 * - leave notify on all of its ancestors, detail Virtual
10499 * - enter notify on root window, detail Inferior
10501 * When the root window ceases to be the effective pointer window:
10502 * - leave notify on root window, detail Inferior
10503 * - enter notify on all ancestors of real pointer window, detail Virtual
10504 * - enter notify on real pointer window, detail Ancestor
10507 _gtk_widget_synthesize_crossing (GtkWidget *from,
10510 GdkCrossingMode mode)
10512 GdkWindow *from_window = NULL, *to_window = NULL;
10514 g_return_if_fail (from != NULL || to != NULL);
10518 from_window = _gtk_widget_get_device_window (from, device);
10521 from_window = from->priv->window;
10526 to_window = _gtk_widget_get_device_window (to, device);
10529 to_window = to->priv->window;
10532 if (from_window == NULL && to_window == NULL)
10534 else if (from_window != NULL && to_window == NULL)
10536 GList *from_ancestors = NULL, *list;
10537 GdkWindow *from_ancestor = from_window;
10539 while (from_ancestor != NULL)
10541 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10542 if (from_ancestor == NULL)
10544 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10547 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10548 device, mode, GDK_NOTIFY_ANCESTOR);
10549 for (list = g_list_last (from_ancestors); list; list = list->prev)
10551 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10552 device, mode, GDK_NOTIFY_VIRTUAL);
10555 /* XXX: enter/inferior on root window? */
10557 g_list_free (from_ancestors);
10559 else if (from_window == NULL && to_window != NULL)
10561 GList *to_ancestors = NULL, *list;
10562 GdkWindow *to_ancestor = to_window;
10564 while (to_ancestor != NULL)
10566 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10567 if (to_ancestor == NULL)
10569 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10572 /* XXX: leave/inferior on root window? */
10574 for (list = to_ancestors; list; list = list->next)
10576 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10577 device, mode, GDK_NOTIFY_VIRTUAL);
10579 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10580 device, mode, GDK_NOTIFY_ANCESTOR);
10582 g_list_free (to_ancestors);
10584 else if (from_window == to_window)
10588 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10589 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10591 while (from_ancestor != NULL || to_ancestor != NULL)
10593 if (from_ancestor != NULL)
10595 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10596 if (from_ancestor == to_window)
10599 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10601 if (to_ancestor != NULL)
10603 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10604 if (to_ancestor == from_window)
10607 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10610 if (to_ancestor == from_window)
10612 if (mode != GDK_CROSSING_GTK_UNGRAB)
10613 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10614 device, mode, GDK_NOTIFY_INFERIOR);
10615 for (list = to_ancestors; list; list = list->next)
10616 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10617 device, mode, GDK_NOTIFY_VIRTUAL);
10618 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10619 device, mode, GDK_NOTIFY_ANCESTOR);
10621 else if (from_ancestor == to_window)
10623 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10624 device, mode, GDK_NOTIFY_ANCESTOR);
10625 for (list = g_list_last (from_ancestors); list; list = list->prev)
10627 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10628 device, mode, GDK_NOTIFY_VIRTUAL);
10630 if (mode != GDK_CROSSING_GTK_GRAB)
10631 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10632 device, mode, GDK_NOTIFY_INFERIOR);
10636 while (from_ancestors != NULL && to_ancestors != NULL
10637 && from_ancestors->data == to_ancestors->data)
10639 from_ancestors = g_list_delete_link (from_ancestors,
10641 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10644 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10645 device, mode, GDK_NOTIFY_NONLINEAR);
10647 for (list = g_list_last (from_ancestors); list; list = list->prev)
10649 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10650 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10652 for (list = to_ancestors; list; list = list->next)
10654 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10655 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10657 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10658 device, mode, GDK_NOTIFY_NONLINEAR);
10660 g_list_free (from_ancestors);
10661 g_list_free (to_ancestors);
10666 gtk_widget_propagate_state (GtkWidget *widget,
10667 GtkStateData *data)
10669 GtkWidgetPrivate *priv = widget->priv;
10670 GtkStateFlags new_flags, old_flags = priv->state_flags;
10671 GtkStateType old_state;
10673 old_state = gtk_widget_get_state (widget);
10675 switch (data->operation)
10677 case STATE_CHANGE_REPLACE:
10678 priv->state_flags = data->flags;
10680 case STATE_CHANGE_SET:
10681 priv->state_flags |= data->flags;
10683 case STATE_CHANGE_UNSET:
10684 priv->state_flags &= ~(data->flags);
10688 /* make insensitivity unoverridable */
10689 if (!priv->sensitive)
10690 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
10692 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10696 window = gtk_widget_get_toplevel (widget);
10698 if (window && gtk_widget_is_toplevel (window))
10699 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10702 new_flags = priv->state_flags;
10704 if (old_flags != new_flags)
10706 g_object_ref (widget);
10708 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10709 gtk_grab_remove (widget);
10711 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
10713 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10714 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10716 if (!priv->shadowed &&
10717 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
10719 GList *event_windows = NULL;
10720 GList *devices, *d;
10722 devices = _gtk_widget_list_devices (widget);
10724 for (d = devices; d; d = d->next)
10730 window = _gtk_widget_get_device_window (widget, device);
10732 /* Do not propagate more than once to the
10733 * same window if non-multidevice aware.
10735 if (!gdk_window_get_support_multidevice (window) &&
10736 g_list_find (event_windows, window))
10739 if (!gtk_widget_is_sensitive (widget))
10740 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10741 GDK_CROSSING_STATE_CHANGED);
10743 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10744 GDK_CROSSING_STATE_CHANGED);
10746 event_windows = g_list_prepend (event_windows, window);
10749 g_list_free (event_windows);
10750 g_list_free (devices);
10753 if (GTK_IS_CONTAINER (widget))
10755 GtkStateData child_data = *data;
10757 /* Make sure to only propate the right states further */
10758 child_data.flags &= GTK_STATE_FLAGS_DO_PROPAGATE;
10760 gtk_container_forall (GTK_CONTAINER (widget),
10761 (GtkCallback) gtk_widget_propagate_state,
10765 /* Trigger state change transitions for the widget */
10766 if (priv->context &&
10767 gtk_widget_get_mapped (widget))
10769 gint diff, flag = 1;
10771 diff = old_flags ^ new_flags;
10775 if ((diff & flag) != 0)
10779 target = ((new_flags & flag) != 0);
10780 _gtk_widget_notify_state_change (widget, flag, target);
10789 g_object_unref (widget);
10793 static const GtkWidgetAuxInfo default_aux_info = {
10801 * gtk_widget_get_aux_info:
10802 * @widget: a #GtkWidget
10803 * @create: if %TRUE, create the structure if it doesn't exist
10805 * Get the #GtkWidgetAuxInfo structure for the widget.
10807 * Return value: the #GtkAuxInfo structure for the widget, or
10808 * %NULL if @create is %FALSE and one doesn't already exist.
10810 static GtkWidgetAuxInfo *
10811 gtk_widget_get_aux_info (GtkWidget *widget,
10814 GtkWidgetAuxInfo *aux_info;
10816 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10817 if (!aux_info && create)
10819 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10821 *aux_info = default_aux_info;
10823 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10829 static const GtkWidgetAuxInfo*
10830 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10832 GtkWidgetAuxInfo *aux_info;
10834 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10835 if (aux_info == NULL)
10837 return &default_aux_info;
10845 /*****************************************
10846 * gtk_widget_aux_info_destroy:
10851 *****************************************/
10854 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10856 g_slice_free (GtkWidgetAuxInfo, aux_info);
10860 * gtk_widget_shape_combine_region:
10861 * @widget: a #GtkWidget
10862 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10864 * Sets a shape for this widget's GDK window. This allows for
10865 * transparent windows etc., see gdk_window_shape_combine_region()
10866 * for more information.
10871 gtk_widget_shape_combine_region (GtkWidget *widget,
10872 cairo_region_t *region)
10874 GtkWidgetPrivate *priv;
10876 g_return_if_fail (GTK_IS_WIDGET (widget));
10877 /* set_shape doesn't work on widgets without gdk window */
10878 g_return_if_fail (gtk_widget_get_has_window (widget));
10880 priv = widget->priv;
10882 if (region == NULL)
10884 priv->has_shape_mask = FALSE;
10887 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10889 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10893 priv->has_shape_mask = TRUE;
10895 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10896 cairo_region_copy (region),
10897 (GDestroyNotify) cairo_region_destroy);
10899 /* set shape if widget has a gdk window already.
10900 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10903 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10908 * gtk_widget_input_shape_combine_region:
10909 * @widget: a #GtkWidget
10910 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10912 * Sets an input shape for this widget's GDK window. This allows for
10913 * windows which react to mouse click in a nonrectangular region, see
10914 * gdk_window_input_shape_combine_region() for more information.
10919 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10920 cairo_region_t *region)
10922 GtkWidgetPrivate *priv;
10924 g_return_if_fail (GTK_IS_WIDGET (widget));
10925 /* set_shape doesn't work on widgets without gdk window */
10926 g_return_if_fail (gtk_widget_get_has_window (widget));
10928 priv = widget->priv;
10930 if (region == NULL)
10933 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10935 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10939 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10940 cairo_region_copy (region),
10941 (GDestroyNotify) cairo_region_destroy);
10943 /* set shape if widget has a gdk window already.
10944 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10947 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10952 /* style properties
10956 * gtk_widget_class_install_style_property_parser: (skip)
10957 * @klass: a #GtkWidgetClass
10958 * @pspec: the #GParamSpec for the style property
10959 * @parser: the parser for the style property
10961 * Installs a style property on a widget class.
10964 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10966 GtkRcPropertyParser parser)
10968 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10969 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10970 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10971 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10973 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10975 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10976 G_OBJECT_CLASS_NAME (klass),
10981 g_param_spec_ref_sink (pspec);
10982 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10983 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10987 * gtk_widget_class_install_style_property:
10988 * @klass: a #GtkWidgetClass
10989 * @pspec: the #GParamSpec for the property
10991 * Installs a style property on a widget class. The parser for the
10992 * style property is determined by the value type of @pspec.
10995 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10998 GtkRcPropertyParser parser;
11000 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11001 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11003 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11005 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11009 * gtk_widget_class_find_style_property:
11010 * @klass: a #GtkWidgetClass
11011 * @property_name: the name of the style property to find
11013 * Finds a style property of a widget class by name.
11015 * Returns: (transfer none): the #GParamSpec of the style property or
11016 * %NULL if @class has no style property with that name.
11021 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11022 const gchar *property_name)
11024 g_return_val_if_fail (property_name != NULL, NULL);
11026 return g_param_spec_pool_lookup (style_property_spec_pool,
11028 G_OBJECT_CLASS_TYPE (klass),
11033 * gtk_widget_class_list_style_properties:
11034 * @klass: a #GtkWidgetClass
11035 * @n_properties: location to return the number of style properties found
11037 * Returns all style properties of a widget class.
11039 * Returns: (array length=n_properties) (transfer container): a
11040 * newly allocated array of #GParamSpec*. The array must be
11041 * freed with g_free().
11046 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11047 guint *n_properties)
11049 GParamSpec **pspecs;
11052 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11053 G_OBJECT_CLASS_TYPE (klass),
11062 * gtk_widget_style_get_property:
11063 * @widget: a #GtkWidget
11064 * @property_name: the name of a style property
11065 * @value: location to return the property value
11067 * Gets the value of a style property of @widget.
11070 gtk_widget_style_get_property (GtkWidget *widget,
11071 const gchar *property_name,
11076 g_return_if_fail (GTK_IS_WIDGET (widget));
11077 g_return_if_fail (property_name != NULL);
11078 g_return_if_fail (G_IS_VALUE (value));
11080 g_object_ref (widget);
11081 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11083 G_OBJECT_TYPE (widget),
11086 g_warning ("%s: widget class `%s' has no property named `%s'",
11088 G_OBJECT_TYPE_NAME (widget),
11092 GtkStyleContext *context;
11093 const GValue *peek_value;
11094 GtkStateFlags state;
11096 context = gtk_widget_get_style_context (widget);
11097 state = gtk_widget_get_state_flags (widget);
11099 peek_value = _gtk_style_context_peek_style_property (context,
11100 G_OBJECT_TYPE (widget),
11103 /* auto-conversion of the caller's value type
11105 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11106 g_value_copy (peek_value, value);
11107 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11108 g_value_transform (peek_value, value);
11110 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11112 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11113 G_VALUE_TYPE_NAME (value));
11115 g_object_unref (widget);
11119 * gtk_widget_style_get_valist:
11120 * @widget: a #GtkWidget
11121 * @first_property_name: the name of the first property to get
11122 * @var_args: a <type>va_list</type> of pairs of property names and
11123 * locations to return the property values, starting with the location
11124 * for @first_property_name.
11126 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11130 gtk_widget_style_get_valist (GtkWidget *widget,
11131 const gchar *first_property_name,
11134 GtkStyleContext *context;
11135 GtkStateFlags state;
11138 g_return_if_fail (GTK_IS_WIDGET (widget));
11140 g_object_ref (widget);
11141 context = gtk_widget_get_style_context (widget);
11142 state = gtk_widget_get_state_flags (widget);
11144 name = first_property_name;
11147 const GValue *peek_value;
11151 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11153 G_OBJECT_TYPE (widget),
11157 g_warning ("%s: widget class `%s' has no property named `%s'",
11159 G_OBJECT_TYPE_NAME (widget),
11163 /* style pspecs are always readable so we can spare that check here */
11165 peek_value = _gtk_style_context_peek_style_property (context,
11166 G_OBJECT_TYPE (widget),
11169 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11172 g_warning ("%s: %s", G_STRLOC, error);
11177 name = va_arg (var_args, gchar*);
11180 g_object_unref (widget);
11184 * gtk_widget_style_get:
11185 * @widget: a #GtkWidget
11186 * @first_property_name: the name of the first property to get
11187 * @...: pairs of property names and locations to return the
11188 * property values, starting with the location for
11189 * @first_property_name, terminated by %NULL.
11191 * Gets the values of a multiple style properties of @widget.
11194 gtk_widget_style_get (GtkWidget *widget,
11195 const gchar *first_property_name,
11200 g_return_if_fail (GTK_IS_WIDGET (widget));
11202 va_start (var_args, first_property_name);
11203 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11208 * gtk_requisition_new:
11210 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11212 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11213 * be freed with gtk_requisition_free().
11218 gtk_requisition_new (void)
11220 return g_slice_new0 (GtkRequisition);
11224 * gtk_requisition_copy:
11225 * @requisition: a #GtkRequisition
11227 * Copies a #GtkRequisition.
11229 * Returns: a copy of @requisition
11232 gtk_requisition_copy (const GtkRequisition *requisition)
11234 return g_slice_dup (GtkRequisition, requisition);
11238 * gtk_requisition_free:
11239 * @requisition: a #GtkRequisition
11241 * Frees a #GtkRequisition.
11244 gtk_requisition_free (GtkRequisition *requisition)
11246 g_slice_free (GtkRequisition, requisition);
11249 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11250 gtk_requisition_copy,
11251 gtk_requisition_free)
11254 * gtk_widget_class_set_accessible_type:
11255 * @widget_class: class to set the accessible type for
11256 * @type: The object type that implements the accessible for @widget_class
11258 * Sets the type to be used for creating accessibles for widgets of
11259 * @widget_class. The given @type must be a subtype of the type used for
11260 * accessibles of the parent class.
11262 * This function should only be called from class init functions of widgets.
11267 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11270 GtkWidgetClassPrivate *priv;
11272 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11273 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11275 priv = widget_class->priv;
11277 priv->accessible_type = type;
11278 /* reset this - honoring the type's role is better. */
11279 priv->accessible_role = ATK_ROLE_INVALID;
11283 * gtk_widget_class_set_accessible_role:
11284 * @widget_class: class to set the accessible role for
11285 * @role: The role to use for accessibles created for @widget_class
11287 * Sets the default #AtkRole to be set on accessibles created for
11288 * widgets of @widget_class. Accessibles may decide to not honor this
11289 * setting if their role reporting is more refined. Calls to
11290 * gtk_widget_class_set_accessible_type() will reset this value.
11292 * In cases where you want more fine-grained control over the role of
11293 * accessibles created for @widget_class, you should provide your own
11294 * accessible type and use gtk_widget_class_set_accessible_type()
11297 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11298 * and the accessible's default role will be used instead.
11300 * This function should only be called from class init functions of widgets.
11305 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11308 GtkWidgetClassPrivate *priv;
11310 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11312 priv = widget_class->priv;
11314 priv->accessible_role = role;
11318 * _gtk_widget_peek_accessible:
11319 * @widget: a #GtkWidget
11321 * Gets the accessible for @widget, if it has been created yet.
11322 * Otherwise, this function returns %NULL. If the @widget's implementation
11323 * does not use the default way to create accessibles, %NULL will always be
11326 * Returns: the accessible for @widget or %NULL if none has been
11330 _gtk_widget_peek_accessible (GtkWidget *widget)
11332 return g_object_get_qdata (G_OBJECT (widget),
11333 quark_accessible_object);
11337 * gtk_widget_get_accessible:
11338 * @widget: a #GtkWidget
11340 * Returns the accessible object that describes the widget to an
11341 * assistive technology.
11343 * If accessibility support is not available, this #AtkObject
11344 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11345 * implementation is available for the widget instance in question,
11346 * it will inherit an #AtkObject implementation from the first ancestor
11347 * class for which such an implementation is defined.
11349 * The documentation of the
11350 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11351 * library contains more information about accessible objects and their uses.
11353 * Returns: (transfer none): the #AtkObject associated with @widget
11356 gtk_widget_get_accessible (GtkWidget *widget)
11358 GtkWidgetClass *klass;
11360 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11362 klass = GTK_WIDGET_GET_CLASS (widget);
11364 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11366 return klass->get_accessible (widget);
11370 gtk_widget_real_get_accessible (GtkWidget *widget)
11372 AtkObject* accessible;
11374 accessible = g_object_get_qdata (G_OBJECT (widget),
11375 quark_accessible_object);
11378 GtkWidgetClass *widget_class;
11379 GtkWidgetClassPrivate *priv;
11380 AtkObjectFactory *factory;
11381 AtkRegistry *default_registry;
11383 widget_class = GTK_WIDGET_GET_CLASS (widget);
11384 priv = widget_class->priv;
11386 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11388 default_registry = atk_get_default_registry ();
11389 factory = atk_registry_get_factory (default_registry,
11390 G_TYPE_FROM_INSTANCE (widget));
11392 atk_object_factory_create_accessible (factory,
11393 G_OBJECT (widget));
11395 if (priv->accessible_role != ATK_ROLE_INVALID)
11396 atk_object_set_role (accessible, priv->accessible_role);
11398 g_object_set_qdata (G_OBJECT (widget),
11399 quark_accessible_object,
11404 accessible = g_object_new (priv->accessible_type,
11407 if (priv->accessible_role != ATK_ROLE_INVALID)
11408 atk_object_set_role (accessible, priv->accessible_role);
11410 g_object_set_qdata (G_OBJECT (widget),
11411 quark_accessible_object,
11414 atk_object_initialize (accessible, widget);
11416 /* Set the role again, since we don't want a role set
11417 * in some parent initialize() function to override
11420 if (priv->accessible_role != ATK_ROLE_INVALID)
11421 atk_object_set_role (accessible, priv->accessible_role);
11428 * Initialize a AtkImplementorIface instance's virtual pointers as
11429 * appropriate to this implementor's class (GtkWidget).
11432 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11434 iface->ref_accessible = gtk_widget_ref_accessible;
11438 gtk_widget_ref_accessible (AtkImplementor *implementor)
11440 AtkObject *accessible;
11442 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11444 g_object_ref (accessible);
11449 * Expand flag management
11453 gtk_widget_update_computed_expand (GtkWidget *widget)
11455 GtkWidgetPrivate *priv;
11457 priv = widget->priv;
11459 if (priv->need_compute_expand)
11463 if (priv->hexpand_set)
11468 if (priv->vexpand_set)
11473 /* we don't need to use compute_expand if both expands are
11474 * forced by the app
11476 if (!(priv->hexpand_set && priv->vexpand_set))
11478 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11482 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11483 priv->hexpand_set ? &ignored : &h,
11484 priv->vexpand_set ? &ignored : &v);
11488 priv->need_compute_expand = FALSE;
11489 priv->computed_hexpand = h != FALSE;
11490 priv->computed_vexpand = v != FALSE;
11495 * gtk_widget_queue_compute_expand:
11496 * @widget: a #GtkWidget
11498 * Mark @widget as needing to recompute its expand flags. Call
11499 * this function when setting legacy expand child properties
11500 * on the child of a container.
11502 * See gtk_widget_compute_expand().
11505 gtk_widget_queue_compute_expand (GtkWidget *widget)
11508 gboolean changed_anything;
11510 if (widget->priv->need_compute_expand)
11513 changed_anything = FALSE;
11515 while (parent != NULL)
11517 if (!parent->priv->need_compute_expand)
11519 parent->priv->need_compute_expand = TRUE;
11520 changed_anything = TRUE;
11523 /* Note: if we had an invariant that "if a child needs to
11524 * compute expand, its parents also do" then we could stop going
11525 * up when we got to a parent that already needed to
11526 * compute. However, in general we compute expand lazily (as
11527 * soon as we see something in a subtree that is expand, we know
11528 * we're expanding) and so this invariant does not hold and we
11529 * have to always walk all the way up in case some ancestor
11530 * is not currently need_compute_expand.
11533 parent = parent->priv->parent;
11536 /* recomputing expand always requires
11537 * a relayout as well
11539 if (changed_anything)
11540 gtk_widget_queue_resize (widget);
11544 * gtk_widget_compute_expand:
11545 * @widget: the widget
11546 * @orientation: expand direction
11548 * Computes whether a container should give this widget extra space
11549 * when possible. Containers should check this, rather than
11550 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11552 * This function already checks whether the widget is visible, so
11553 * visibility does not need to be checked separately. Non-visible
11554 * widgets are not expanded.
11556 * The computed expand value uses either the expand setting explicitly
11557 * set on the widget itself, or, if none has been explicitly set,
11558 * the widget may expand if some of its children do.
11560 * Return value: whether widget tree rooted here should be expanded
11563 gtk_widget_compute_expand (GtkWidget *widget,
11564 GtkOrientation orientation)
11566 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11568 /* We never make a widget expand if not even showing. */
11569 if (!gtk_widget_get_visible (widget))
11572 gtk_widget_update_computed_expand (widget);
11574 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11576 return widget->priv->computed_hexpand;
11580 return widget->priv->computed_vexpand;
11585 gtk_widget_set_expand (GtkWidget *widget,
11586 GtkOrientation orientation,
11589 const char *expand_prop;
11590 const char *expand_set_prop;
11592 GtkWidgetPrivate *priv;
11594 g_return_if_fail (GTK_IS_WIDGET (widget));
11596 priv = widget->priv;
11598 expand = expand != FALSE;
11600 was_both = priv->hexpand && priv->vexpand;
11602 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11604 if (priv->hexpand_set &&
11605 priv->hexpand == expand)
11608 priv->hexpand_set = TRUE;
11609 priv->hexpand = expand;
11611 expand_prop = "hexpand";
11612 expand_set_prop = "hexpand-set";
11616 if (priv->vexpand_set &&
11617 priv->vexpand == expand)
11620 priv->vexpand_set = TRUE;
11621 priv->vexpand = expand;
11623 expand_prop = "vexpand";
11624 expand_set_prop = "vexpand-set";
11627 gtk_widget_queue_compute_expand (widget);
11629 g_object_freeze_notify (G_OBJECT (widget));
11630 g_object_notify (G_OBJECT (widget), expand_prop);
11631 g_object_notify (G_OBJECT (widget), expand_set_prop);
11632 if (was_both != (priv->hexpand && priv->vexpand))
11633 g_object_notify (G_OBJECT (widget), "expand");
11634 g_object_thaw_notify (G_OBJECT (widget));
11638 gtk_widget_set_expand_set (GtkWidget *widget,
11639 GtkOrientation orientation,
11642 GtkWidgetPrivate *priv;
11645 priv = widget->priv;
11647 set = set != FALSE;
11649 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11651 if (set == priv->hexpand_set)
11654 priv->hexpand_set = set;
11655 prop = "hexpand-set";
11659 if (set == priv->vexpand_set)
11662 priv->vexpand_set = set;
11663 prop = "vexpand-set";
11666 gtk_widget_queue_compute_expand (widget);
11668 g_object_notify (G_OBJECT (widget), prop);
11672 * gtk_widget_get_hexpand:
11673 * @widget: the widget
11675 * Gets whether the widget would like any available extra horizontal
11676 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11677 * generally receive the extra space. For example, a list or
11678 * scrollable area or document in your window would often be set to
11681 * Containers should use gtk_widget_compute_expand() rather than
11682 * this function, to see whether a widget, or any of its children,
11683 * has the expand flag set. If any child of a widget wants to
11684 * expand, the parent may ask to expand also.
11686 * This function only looks at the widget's own hexpand flag, rather
11687 * than computing whether the entire widget tree rooted at this widget
11690 * Return value: whether hexpand flag is set
11693 gtk_widget_get_hexpand (GtkWidget *widget)
11695 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11697 return widget->priv->hexpand;
11701 * gtk_widget_set_hexpand:
11702 * @widget: the widget
11703 * @expand: whether to expand
11705 * Sets whether the widget would like any available extra horizontal
11706 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11707 * generally receive the extra space. For example, a list or
11708 * scrollable area or document in your window would often be set to
11711 * Call this function to set the expand flag if you would like your
11712 * widget to become larger horizontally when the window has extra
11715 * By default, widgets automatically expand if any of their children
11716 * want to expand. (To see if a widget will automatically expand given
11717 * its current children and state, call gtk_widget_compute_expand(). A
11718 * container can decide how the expandability of children affects the
11719 * expansion of the container by overriding the compute_expand virtual
11720 * method on #GtkWidget.).
11722 * Setting hexpand explicitly with this function will override the
11723 * automatic expand behavior.
11725 * This function forces the widget to expand or not to expand,
11726 * regardless of children. The override occurs because
11727 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11728 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11729 * value to be used, rather than looking at children and widget state.
11732 gtk_widget_set_hexpand (GtkWidget *widget,
11735 g_return_if_fail (GTK_IS_WIDGET (widget));
11737 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11741 * gtk_widget_get_hexpand_set:
11742 * @widget: the widget
11744 * Gets whether gtk_widget_set_hexpand() has been used to
11745 * explicitly set the expand flag on this widget.
11747 * If hexpand is set, then it overrides any computed
11748 * expand value based on child widgets. If hexpand is not
11749 * set, then the expand value depends on whether any
11750 * children of the widget would like to expand.
11752 * There are few reasons to use this function, but it's here
11753 * for completeness and consistency.
11755 * Return value: whether hexpand has been explicitly set
11758 gtk_widget_get_hexpand_set (GtkWidget *widget)
11760 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11762 return widget->priv->hexpand_set;
11766 * gtk_widget_set_hexpand_set:
11767 * @widget: the widget
11768 * @set: value for hexpand-set property
11770 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11773 * The hexpand-set property will be set automatically when you call
11774 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11775 * reason to use this function would be to unset an explicit expand
11778 * If hexpand is set, then it overrides any computed
11779 * expand value based on child widgets. If hexpand is not
11780 * set, then the expand value depends on whether any
11781 * children of the widget would like to expand.
11783 * There are few reasons to use this function, but it's here
11784 * for completeness and consistency.
11787 gtk_widget_set_hexpand_set (GtkWidget *widget,
11790 g_return_if_fail (GTK_IS_WIDGET (widget));
11792 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11797 * gtk_widget_get_vexpand:
11798 * @widget: the widget
11800 * Gets whether the widget would like any available extra vertical
11803 * See gtk_widget_get_hexpand() for more detail.
11805 * Return value: whether vexpand flag is set
11808 gtk_widget_get_vexpand (GtkWidget *widget)
11810 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11812 return widget->priv->vexpand;
11816 * gtk_widget_set_vexpand:
11817 * @widget: the widget
11818 * @expand: whether to expand
11820 * Sets whether the widget would like any available extra vertical
11823 * See gtk_widget_set_hexpand() for more detail.
11826 gtk_widget_set_vexpand (GtkWidget *widget,
11829 g_return_if_fail (GTK_IS_WIDGET (widget));
11831 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11835 * gtk_widget_get_vexpand_set:
11836 * @widget: the widget
11838 * Gets whether gtk_widget_set_vexpand() has been used to
11839 * explicitly set the expand flag on this widget.
11841 * See gtk_widget_get_hexpand_set() for more detail.
11843 * Return value: whether vexpand has been explicitly set
11846 gtk_widget_get_vexpand_set (GtkWidget *widget)
11848 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11850 return widget->priv->vexpand_set;
11854 * gtk_widget_set_vexpand_set:
11855 * @widget: the widget
11856 * @set: value for vexpand-set property
11858 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11861 * See gtk_widget_set_hexpand_set() for more detail.
11864 gtk_widget_set_vexpand_set (GtkWidget *widget,
11867 g_return_if_fail (GTK_IS_WIDGET (widget));
11869 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11873 * GtkBuildable implementation
11875 static GQuark quark_builder_has_default = 0;
11876 static GQuark quark_builder_has_focus = 0;
11877 static GQuark quark_builder_atk_relations = 0;
11878 static GQuark quark_builder_set_name = 0;
11881 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11883 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11884 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11885 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11886 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11888 iface->set_name = gtk_widget_buildable_set_name;
11889 iface->get_name = gtk_widget_buildable_get_name;
11890 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11891 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11892 iface->parser_finished = gtk_widget_buildable_parser_finished;
11893 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11894 iface->custom_finished = gtk_widget_buildable_custom_finished;
11898 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11901 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11902 g_strdup (name), g_free);
11905 static const gchar *
11906 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11908 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11912 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11913 GtkBuilder *builder,
11914 const gchar *childname)
11916 if (strcmp (childname, "accessible") == 0)
11917 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11923 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11924 GtkBuilder *builder,
11926 const GValue *value)
11928 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11929 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11930 GINT_TO_POINTER (TRUE));
11931 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11932 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11933 GINT_TO_POINTER (TRUE));
11935 g_object_set_property (G_OBJECT (buildable), name, value);
11940 gchar *action_name;
11941 GString *description;
11943 gboolean translatable;
11953 free_action (AtkActionData *data, gpointer user_data)
11955 g_free (data->action_name);
11956 g_string_free (data->description, TRUE);
11957 g_free (data->context);
11958 g_slice_free (AtkActionData, data);
11962 free_relation (AtkRelationData *data, gpointer user_data)
11964 g_free (data->target);
11965 g_free (data->type);
11966 g_slice_free (AtkRelationData, data);
11970 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11971 GtkBuilder *builder)
11973 GSList *atk_relations;
11975 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11976 gtk_widget_grab_default (GTK_WIDGET (buildable));
11977 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11978 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11980 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11981 quark_builder_atk_relations);
11984 AtkObject *accessible;
11985 AtkRelationSet *relation_set;
11988 AtkRelationType relation_type;
11989 AtkObject *target_accessible;
11991 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11992 relation_set = atk_object_ref_relation_set (accessible);
11994 for (l = atk_relations; l; l = l->next)
11996 AtkRelationData *relation = (AtkRelationData*)l->data;
11998 target = gtk_builder_get_object (builder, relation->target);
12001 g_warning ("Target object %s in <relation> does not exist",
12005 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12006 g_assert (target_accessible != NULL);
12008 relation_type = atk_relation_type_for_name (relation->type);
12009 if (relation_type == ATK_RELATION_NULL)
12011 g_warning ("<relation> type %s not found",
12015 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12016 target_accessible);
12018 g_object_unref (relation_set);
12020 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12021 g_slist_free (atk_relations);
12022 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12031 } AccessibilitySubParserData;
12034 accessibility_start_element (GMarkupParseContext *context,
12035 const gchar *element_name,
12036 const gchar **names,
12037 const gchar **values,
12038 gpointer user_data,
12041 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12043 gint line_number, char_number;
12045 if (strcmp (element_name, "relation") == 0)
12047 gchar *target = NULL;
12048 gchar *type = NULL;
12049 AtkRelationData *relation;
12051 for (i = 0; names[i]; i++)
12053 if (strcmp (names[i], "target") == 0)
12054 target = g_strdup (values[i]);
12055 else if (strcmp (names[i], "type") == 0)
12056 type = g_strdup (values[i]);
12059 g_markup_parse_context_get_position (context,
12062 g_set_error (error,
12064 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12065 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12067 line_number, char_number, names[i], "relation");
12074 if (!target || !type)
12076 g_markup_parse_context_get_position (context,
12079 g_set_error (error,
12081 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12082 "%s:%d:%d <%s> requires attribute \"%s\"",
12084 line_number, char_number, "relation",
12085 type ? "target" : "type");
12091 relation = g_slice_new (AtkRelationData);
12092 relation->target = target;
12093 relation->type = type;
12095 data->relations = g_slist_prepend (data->relations, relation);
12097 else if (strcmp (element_name, "action") == 0)
12099 const gchar *action_name = NULL;
12100 const gchar *description = NULL;
12101 const gchar *msg_context = NULL;
12102 gboolean translatable = FALSE;
12103 AtkActionData *action;
12105 for (i = 0; names[i]; i++)
12107 if (strcmp (names[i], "action_name") == 0)
12108 action_name = values[i];
12109 else if (strcmp (names[i], "description") == 0)
12110 description = values[i];
12111 else if (strcmp (names[i], "translatable") == 0)
12113 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12116 else if (strcmp (names[i], "comments") == 0)
12118 /* do nothing, comments are for translators */
12120 else if (strcmp (names[i], "context") == 0)
12121 msg_context = values[i];
12124 g_markup_parse_context_get_position (context,
12127 g_set_error (error,
12129 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12130 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12132 line_number, char_number, names[i], "action");
12139 g_markup_parse_context_get_position (context,
12142 g_set_error (error,
12144 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12145 "%s:%d:%d <%s> requires attribute \"%s\"",
12147 line_number, char_number, "action",
12152 action = g_slice_new (AtkActionData);
12153 action->action_name = g_strdup (action_name);
12154 action->description = g_string_new (description);
12155 action->context = g_strdup (msg_context);
12156 action->translatable = translatable;
12158 data->actions = g_slist_prepend (data->actions, action);
12160 else if (strcmp (element_name, "accessibility") == 0)
12163 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12167 accessibility_text (GMarkupParseContext *context,
12170 gpointer user_data,
12173 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12175 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12177 AtkActionData *action = data->actions->data;
12179 g_string_append_len (action->description, text, text_len);
12183 static const GMarkupParser accessibility_parser =
12185 accessibility_start_element,
12187 accessibility_text,
12196 } AccelGroupParserData;
12199 accel_group_start_element (GMarkupParseContext *context,
12200 const gchar *element_name,
12201 const gchar **names,
12202 const gchar **values,
12203 gpointer user_data,
12208 guint modifiers = 0;
12209 gchar *signal = NULL;
12210 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12212 for (i = 0; names[i]; i++)
12214 if (strcmp (names[i], "key") == 0)
12215 key = gdk_keyval_from_name (values[i]);
12216 else if (strcmp (names[i], "modifiers") == 0)
12218 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12224 else if (strcmp (names[i], "signal") == 0)
12225 signal = g_strdup (values[i]);
12228 if (key == 0 || signal == NULL)
12230 g_warning ("<accelerator> requires key and signal attributes");
12233 parser_data->key = key;
12234 parser_data->modifiers = modifiers;
12235 parser_data->signal = signal;
12238 static const GMarkupParser accel_group_parser =
12240 accel_group_start_element,
12249 style_start_element (GMarkupParseContext *context,
12250 const gchar *element_name,
12251 const gchar **names,
12252 const gchar **values,
12253 gpointer user_data,
12256 StyleParserData *style_data = (StyleParserData *)user_data;
12259 if (strcmp (element_name, "class") == 0)
12261 if (g_markup_collect_attributes (element_name,
12265 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12266 G_MARKUP_COLLECT_INVALID))
12268 style_data->classes = g_slist_append (style_data->classes, class_name);
12271 else if (strcmp (element_name, "style") == 0)
12274 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12277 static const GMarkupParser style_parser =
12279 style_start_element,
12283 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12284 GtkBuilder *builder,
12286 const gchar *tagname,
12287 GMarkupParser *parser,
12290 g_assert (buildable);
12292 if (strcmp (tagname, "accelerator") == 0)
12294 AccelGroupParserData *parser_data;
12296 parser_data = g_slice_new0 (AccelGroupParserData);
12297 parser_data->object = g_object_ref (buildable);
12298 *parser = accel_group_parser;
12299 *data = parser_data;
12302 if (strcmp (tagname, "accessibility") == 0)
12304 AccessibilitySubParserData *parser_data;
12306 parser_data = g_slice_new0 (AccessibilitySubParserData);
12307 *parser = accessibility_parser;
12308 *data = parser_data;
12311 if (strcmp (tagname, "style") == 0)
12313 StyleParserData *parser_data;
12315 parser_data = g_slice_new0 (StyleParserData);
12316 *parser = style_parser;
12317 *data = parser_data;
12325 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12326 GtkWidget *toplevel,
12327 gpointer user_data)
12329 AccelGroupParserData *accel_data;
12330 GSList *accel_groups;
12331 GtkAccelGroup *accel_group;
12333 g_return_if_fail (GTK_IS_WIDGET (widget));
12334 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12335 g_return_if_fail (user_data != NULL);
12337 accel_data = (AccelGroupParserData*)user_data;
12338 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12339 if (g_slist_length (accel_groups) == 0)
12341 accel_group = gtk_accel_group_new ();
12342 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12346 g_assert (g_slist_length (accel_groups) == 1);
12347 accel_group = g_slist_nth_data (accel_groups, 0);
12350 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12351 accel_data->signal,
12354 accel_data->modifiers,
12355 GTK_ACCEL_VISIBLE);
12357 g_object_unref (accel_data->object);
12358 g_free (accel_data->signal);
12359 g_slice_free (AccelGroupParserData, accel_data);
12363 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12364 GtkBuilder *builder,
12366 const gchar *tagname,
12367 gpointer user_data)
12369 if (strcmp (tagname, "accelerator") == 0)
12371 AccelGroupParserData *accel_data;
12372 GtkWidget *toplevel;
12374 accel_data = (AccelGroupParserData*)user_data;
12375 g_assert (accel_data->object);
12377 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12379 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12381 else if (strcmp (tagname, "accessibility") == 0)
12383 AccessibilitySubParserData *a11y_data;
12385 a11y_data = (AccessibilitySubParserData*)user_data;
12387 if (a11y_data->actions)
12389 AtkObject *accessible;
12394 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12396 if (ATK_IS_ACTION (accessible))
12398 action = ATK_ACTION (accessible);
12399 n_actions = atk_action_get_n_actions (action);
12401 for (l = a11y_data->actions; l; l = l->next)
12403 AtkActionData *action_data = (AtkActionData*)l->data;
12405 for (i = 0; i < n_actions; i++)
12406 if (strcmp (atk_action_get_name (action, i),
12407 action_data->action_name) == 0)
12412 gchar *description;
12414 if (action_data->translatable && action_data->description->len)
12415 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12416 action_data->context,
12417 action_data->description->str);
12419 description = action_data->description->str;
12421 atk_action_set_description (action, i, description);
12426 g_warning ("accessibility action on a widget that does not implement AtkAction");
12428 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12429 g_slist_free (a11y_data->actions);
12432 if (a11y_data->relations)
12433 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12434 a11y_data->relations);
12436 g_slice_free (AccessibilitySubParserData, a11y_data);
12438 else if (strcmp (tagname, "style") == 0)
12440 StyleParserData *style_data = (StyleParserData *)user_data;
12441 GtkStyleContext *context;
12444 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12446 for (l = style_data->classes; l; l = l->next)
12447 gtk_style_context_add_class (context, (const gchar *)l->data);
12449 gtk_widget_reset_style (GTK_WIDGET (buildable));
12451 g_slist_free_full (style_data->classes, g_free);
12452 g_slice_free (StyleParserData, style_data);
12456 static GtkSizeRequestMode
12457 gtk_widget_real_get_request_mode (GtkWidget *widget)
12459 /* By default widgets dont trade size at all. */
12460 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12464 gtk_widget_real_get_width (GtkWidget *widget,
12465 gint *minimum_size,
12466 gint *natural_size)
12476 gtk_widget_real_get_height (GtkWidget *widget,
12477 gint *minimum_size,
12478 gint *natural_size)
12488 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12490 gint *minimum_height,
12491 gint *natural_height)
12493 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12497 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12499 gint *minimum_width,
12500 gint *natural_width)
12502 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12506 * gtk_widget_get_halign:
12507 * @widget: a #GtkWidget
12509 * Gets the value of the #GtkWidget:halign property.
12511 * Returns: the horizontal alignment of @widget
12514 gtk_widget_get_halign (GtkWidget *widget)
12516 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12517 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12521 * gtk_widget_set_halign:
12522 * @widget: a #GtkWidget
12523 * @align: the horizontal alignment
12525 * Sets the horizontal alignment of @widget.
12526 * See the #GtkWidget:halign property.
12529 gtk_widget_set_halign (GtkWidget *widget,
12532 GtkWidgetAuxInfo *aux_info;
12534 g_return_if_fail (GTK_IS_WIDGET (widget));
12536 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12538 if (aux_info->halign == align)
12541 aux_info->halign = align;
12542 gtk_widget_queue_resize (widget);
12543 g_object_notify (G_OBJECT (widget), "halign");
12547 * gtk_widget_get_valign:
12548 * @widget: a #GtkWidget
12550 * Gets the value of the #GtkWidget:valign property.
12552 * Returns: the vertical alignment of @widget
12555 gtk_widget_get_valign (GtkWidget *widget)
12557 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12558 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12562 * gtk_widget_set_valign:
12563 * @widget: a #GtkWidget
12564 * @align: the vertical alignment
12566 * Sets the vertical alignment of @widget.
12567 * See the #GtkWidget:valign property.
12570 gtk_widget_set_valign (GtkWidget *widget,
12573 GtkWidgetAuxInfo *aux_info;
12575 g_return_if_fail (GTK_IS_WIDGET (widget));
12577 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12579 if (aux_info->valign == align)
12582 aux_info->valign = align;
12583 gtk_widget_queue_resize (widget);
12584 g_object_notify (G_OBJECT (widget), "valign");
12588 * gtk_widget_get_margin_left:
12589 * @widget: a #GtkWidget
12591 * Gets the value of the #GtkWidget:margin-left property.
12593 * Returns: The left margin of @widget
12598 gtk_widget_get_margin_left (GtkWidget *widget)
12600 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12602 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12606 * gtk_widget_set_margin_left:
12607 * @widget: a #GtkWidget
12608 * @margin: the left margin
12610 * Sets the left margin of @widget.
12611 * See the #GtkWidget:margin-left property.
12616 gtk_widget_set_margin_left (GtkWidget *widget,
12619 GtkWidgetAuxInfo *aux_info;
12621 g_return_if_fail (GTK_IS_WIDGET (widget));
12622 g_return_if_fail (margin <= G_MAXINT16);
12624 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12626 if (aux_info->margin.left == margin)
12629 aux_info->margin.left = margin;
12630 gtk_widget_queue_resize (widget);
12631 g_object_notify (G_OBJECT (widget), "margin-left");
12635 * gtk_widget_get_margin_right:
12636 * @widget: a #GtkWidget
12638 * Gets the value of the #GtkWidget:margin-right property.
12640 * Returns: The right margin of @widget
12645 gtk_widget_get_margin_right (GtkWidget *widget)
12647 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12649 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12653 * gtk_widget_set_margin_right:
12654 * @widget: a #GtkWidget
12655 * @margin: the right margin
12657 * Sets the right margin of @widget.
12658 * See the #GtkWidget:margin-right property.
12663 gtk_widget_set_margin_right (GtkWidget *widget,
12666 GtkWidgetAuxInfo *aux_info;
12668 g_return_if_fail (GTK_IS_WIDGET (widget));
12669 g_return_if_fail (margin <= G_MAXINT16);
12671 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12673 if (aux_info->margin.right == margin)
12676 aux_info->margin.right = margin;
12677 gtk_widget_queue_resize (widget);
12678 g_object_notify (G_OBJECT (widget), "margin-right");
12682 * gtk_widget_get_margin_top:
12683 * @widget: a #GtkWidget
12685 * Gets the value of the #GtkWidget:margin-top property.
12687 * Returns: The top margin of @widget
12692 gtk_widget_get_margin_top (GtkWidget *widget)
12694 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12696 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12700 * gtk_widget_set_margin_top:
12701 * @widget: a #GtkWidget
12702 * @margin: the top margin
12704 * Sets the top margin of @widget.
12705 * See the #GtkWidget:margin-top property.
12710 gtk_widget_set_margin_top (GtkWidget *widget,
12713 GtkWidgetAuxInfo *aux_info;
12715 g_return_if_fail (GTK_IS_WIDGET (widget));
12716 g_return_if_fail (margin <= G_MAXINT16);
12718 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12720 if (aux_info->margin.top == margin)
12723 aux_info->margin.top = margin;
12724 gtk_widget_queue_resize (widget);
12725 g_object_notify (G_OBJECT (widget), "margin-top");
12729 * gtk_widget_get_margin_bottom:
12730 * @widget: a #GtkWidget
12732 * Gets the value of the #GtkWidget:margin-bottom property.
12734 * Returns: The bottom margin of @widget
12739 gtk_widget_get_margin_bottom (GtkWidget *widget)
12741 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12743 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12747 * gtk_widget_set_margin_bottom:
12748 * @widget: a #GtkWidget
12749 * @margin: the bottom margin
12751 * Sets the bottom margin of @widget.
12752 * See the #GtkWidget:margin-bottom property.
12757 gtk_widget_set_margin_bottom (GtkWidget *widget,
12760 GtkWidgetAuxInfo *aux_info;
12762 g_return_if_fail (GTK_IS_WIDGET (widget));
12763 g_return_if_fail (margin <= G_MAXINT16);
12765 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12767 if (aux_info->margin.bottom == margin)
12770 aux_info->margin.bottom = margin;
12771 gtk_widget_queue_resize (widget);
12772 g_object_notify (G_OBJECT (widget), "margin-bottom");
12776 * gtk_widget_get_clipboard:
12777 * @widget: a #GtkWidget
12778 * @selection: a #GdkAtom which identifies the clipboard
12779 * to use. %GDK_SELECTION_CLIPBOARD gives the
12780 * default clipboard. Another common value
12781 * is %GDK_SELECTION_PRIMARY, which gives
12782 * the primary X selection.
12784 * Returns the clipboard object for the given selection to
12785 * be used with @widget. @widget must have a #GdkDisplay
12786 * associated with it, so must be attached to a toplevel
12789 * Return value: (transfer none): the appropriate clipboard object. If no
12790 * clipboard already exists, a new one will
12791 * be created. Once a clipboard object has
12792 * been created, it is persistent for all time.
12797 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12799 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12800 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12802 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12807 * gtk_widget_list_mnemonic_labels:
12808 * @widget: a #GtkWidget
12810 * Returns a newly allocated list of the widgets, normally labels, for
12811 * which this widget is the target of a mnemonic (see for example,
12812 * gtk_label_set_mnemonic_widget()).
12814 * The widgets in the list are not individually referenced. If you
12815 * want to iterate through the list and perform actions involving
12816 * callbacks that might destroy the widgets, you
12817 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12818 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12819 * widgets afterwards.
12821 * Return value: (element-type GtkWidget) (transfer container): the list of
12822 * mnemonic labels; free this list
12823 * with g_list_free() when you are done with it.
12828 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12830 GList *list = NULL;
12833 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12835 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12836 list = g_list_prepend (list, l->data);
12842 * gtk_widget_add_mnemonic_label:
12843 * @widget: a #GtkWidget
12844 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12846 * Adds a widget to the list of mnemonic labels for
12847 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12848 * list of mnemonic labels for the widget is cleared when the
12849 * widget is destroyed, so the caller must make sure to update
12850 * its internal state at this point as well, by using a connection
12851 * to the #GtkWidget::destroy signal or a weak notifier.
12856 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12859 GSList *old_list, *new_list;
12861 g_return_if_fail (GTK_IS_WIDGET (widget));
12862 g_return_if_fail (GTK_IS_WIDGET (label));
12864 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12865 new_list = g_slist_prepend (old_list, label);
12867 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12868 new_list, (GDestroyNotify) g_slist_free);
12872 * gtk_widget_remove_mnemonic_label:
12873 * @widget: a #GtkWidget
12874 * @label: a #GtkWidget that was previously set as a mnemnic label for
12875 * @widget with gtk_widget_add_mnemonic_label().
12877 * Removes a widget from the list of mnemonic labels for
12878 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12879 * must have previously been added to the list with
12880 * gtk_widget_add_mnemonic_label().
12885 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12888 GSList *old_list, *new_list;
12890 g_return_if_fail (GTK_IS_WIDGET (widget));
12891 g_return_if_fail (GTK_IS_WIDGET (label));
12893 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12894 new_list = g_slist_remove (old_list, label);
12897 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12898 new_list, (GDestroyNotify) g_slist_free);
12902 * gtk_widget_get_no_show_all:
12903 * @widget: a #GtkWidget
12905 * Returns the current value of the #GtkWidget:no-show-all property,
12906 * which determines whether calls to gtk_widget_show_all()
12907 * will affect this widget.
12909 * Return value: the current value of the "no-show-all" property.
12914 gtk_widget_get_no_show_all (GtkWidget *widget)
12916 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12918 return widget->priv->no_show_all;
12922 * gtk_widget_set_no_show_all:
12923 * @widget: a #GtkWidget
12924 * @no_show_all: the new value for the "no-show-all" property
12926 * Sets the #GtkWidget:no-show-all property, which determines whether
12927 * calls to gtk_widget_show_all() will affect this widget.
12929 * This is mostly for use in constructing widget hierarchies with externally
12930 * controlled visibility, see #GtkUIManager.
12935 gtk_widget_set_no_show_all (GtkWidget *widget,
12936 gboolean no_show_all)
12938 g_return_if_fail (GTK_IS_WIDGET (widget));
12940 no_show_all = (no_show_all != FALSE);
12942 if (widget->priv->no_show_all != no_show_all)
12944 widget->priv->no_show_all = no_show_all;
12946 g_object_notify (G_OBJECT (widget), "no-show-all");
12952 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12953 gboolean has_tooltip,
12956 GtkWidgetPrivate *priv = widget->priv;
12957 gboolean priv_has_tooltip;
12959 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12960 quark_has_tooltip));
12962 if (priv_has_tooltip != has_tooltip || force)
12964 priv_has_tooltip = has_tooltip;
12966 if (priv_has_tooltip)
12968 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12969 gdk_window_set_events (priv->window,
12970 gdk_window_get_events (priv->window) |
12971 GDK_LEAVE_NOTIFY_MASK |
12972 GDK_POINTER_MOTION_MASK |
12973 GDK_POINTER_MOTION_HINT_MASK);
12975 if (gtk_widget_get_has_window (widget))
12976 gtk_widget_add_events (widget,
12977 GDK_LEAVE_NOTIFY_MASK |
12978 GDK_POINTER_MOTION_MASK |
12979 GDK_POINTER_MOTION_HINT_MASK);
12982 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12983 GUINT_TO_POINTER (priv_has_tooltip));
12988 * gtk_widget_set_tooltip_window:
12989 * @widget: a #GtkWidget
12990 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12992 * Replaces the default, usually yellow, window used for displaying
12993 * tooltips with @custom_window. GTK+ will take care of showing and
12994 * hiding @custom_window at the right moment, to behave likewise as
12995 * the default tooltip window. If @custom_window is %NULL, the default
12996 * tooltip window will be used.
12998 * If the custom window should have the default theming it needs to
12999 * have the name "gtk-tooltip", see gtk_widget_set_name().
13004 gtk_widget_set_tooltip_window (GtkWidget *widget,
13005 GtkWindow *custom_window)
13007 gboolean has_tooltip;
13008 gchar *tooltip_markup;
13010 g_return_if_fail (GTK_IS_WIDGET (widget));
13011 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13013 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13016 g_object_ref (custom_window);
13018 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13019 custom_window, g_object_unref);
13021 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13022 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13024 if (has_tooltip && gtk_widget_get_visible (widget))
13025 gtk_widget_queue_tooltip_query (widget);
13029 * gtk_widget_get_tooltip_window:
13030 * @widget: a #GtkWidget
13032 * Returns the #GtkWindow of the current tooltip. This can be the
13033 * GtkWindow created by default, or the custom tooltip window set
13034 * using gtk_widget_set_tooltip_window().
13036 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13041 gtk_widget_get_tooltip_window (GtkWidget *widget)
13043 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13045 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13049 * gtk_widget_trigger_tooltip_query:
13050 * @widget: a #GtkWidget
13052 * Triggers a tooltip query on the display where the toplevel of @widget
13053 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13059 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13061 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13064 static guint tooltip_query_id;
13065 static GSList *tooltip_query_displays;
13068 tooltip_query_idle (gpointer data)
13070 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13071 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13072 g_slist_free (tooltip_query_displays);
13074 tooltip_query_displays = NULL;
13075 tooltip_query_id = 0;
13081 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13083 GdkDisplay *display;
13085 display = gtk_widget_get_display (widget);
13087 if (!g_slist_find (tooltip_query_displays, display))
13088 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13090 if (tooltip_query_id == 0)
13091 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13095 * gtk_widget_set_tooltip_text:
13096 * @widget: a #GtkWidget
13097 * @text: the contents of the tooltip for @widget
13099 * Sets @text as the contents of the tooltip. This function will take
13100 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13101 * handler for the #GtkWidget::query-tooltip signal.
13103 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13108 gtk_widget_set_tooltip_text (GtkWidget *widget,
13111 g_return_if_fail (GTK_IS_WIDGET (widget));
13113 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13117 * gtk_widget_get_tooltip_text:
13118 * @widget: a #GtkWidget
13120 * Gets the contents of the tooltip for @widget.
13122 * Return value: the tooltip text, or %NULL. You should free the
13123 * returned string with g_free() when done.
13128 gtk_widget_get_tooltip_text (GtkWidget *widget)
13130 gchar *text = NULL;
13132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13134 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13140 * gtk_widget_set_tooltip_markup:
13141 * @widget: a #GtkWidget
13142 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13144 * Sets @markup as the contents of the tooltip, which is marked up with
13145 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13147 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13148 * and of the default handler for the #GtkWidget::query-tooltip signal.
13150 * See also the #GtkWidget:tooltip-markup property and
13151 * gtk_tooltip_set_markup().
13156 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13157 const gchar *markup)
13159 g_return_if_fail (GTK_IS_WIDGET (widget));
13161 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13165 * gtk_widget_get_tooltip_markup:
13166 * @widget: a #GtkWidget
13168 * Gets the contents of the tooltip for @widget.
13170 * Return value: the tooltip text, or %NULL. You should free the
13171 * returned string with g_free() when done.
13176 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13178 gchar *text = NULL;
13180 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13182 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13188 * gtk_widget_set_has_tooltip:
13189 * @widget: a #GtkWidget
13190 * @has_tooltip: whether or not @widget has a tooltip.
13192 * Sets the has-tooltip property on @widget to @has_tooltip. See
13193 * #GtkWidget:has-tooltip for more information.
13198 gtk_widget_set_has_tooltip (GtkWidget *widget,
13199 gboolean has_tooltip)
13201 g_return_if_fail (GTK_IS_WIDGET (widget));
13203 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13207 * gtk_widget_get_has_tooltip:
13208 * @widget: a #GtkWidget
13210 * Returns the current value of the has-tooltip property. See
13211 * #GtkWidget:has-tooltip for more information.
13213 * Return value: current value of has-tooltip on @widget.
13218 gtk_widget_get_has_tooltip (GtkWidget *widget)
13220 gboolean has_tooltip = FALSE;
13222 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13224 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13226 return has_tooltip;
13230 * gtk_widget_get_allocation:
13231 * @widget: a #GtkWidget
13232 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13234 * Retrieves the widget's allocation.
13236 * Note, when implementing a #GtkContainer: a widget's allocation will
13237 * be its "adjusted" allocation, that is, the widget's parent
13238 * container typically calls gtk_widget_size_allocate() with an
13239 * allocation, and that allocation is then adjusted (to handle margin
13240 * and alignment for example) before assignment to the widget.
13241 * gtk_widget_get_allocation() returns the adjusted allocation that
13242 * was actually assigned to the widget. The adjusted allocation is
13243 * guaranteed to be completely contained within the
13244 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13245 * is guaranteed that its children stay inside the assigned bounds,
13246 * but not that they have exactly the bounds the container assigned.
13247 * There is no way to get the original allocation assigned by
13248 * gtk_widget_size_allocate(), since it isn't stored; if a container
13249 * implementation needs that information it will have to track it itself.
13254 gtk_widget_get_allocation (GtkWidget *widget,
13255 GtkAllocation *allocation)
13257 GtkWidgetPrivate *priv;
13259 g_return_if_fail (GTK_IS_WIDGET (widget));
13260 g_return_if_fail (allocation != NULL);
13262 priv = widget->priv;
13264 *allocation = priv->allocation;
13268 * gtk_widget_set_allocation:
13269 * @widget: a #GtkWidget
13270 * @allocation: a pointer to a #GtkAllocation to copy from
13272 * Sets the widget's allocation. This should not be used
13273 * directly, but from within a widget's size_allocate method.
13275 * The allocation set should be the "adjusted" or actual
13276 * allocation. If you're implementing a #GtkContainer, you want to use
13277 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13278 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13279 * allocation inside gtk_widget_size_allocate() to create an adjusted
13285 gtk_widget_set_allocation (GtkWidget *widget,
13286 const GtkAllocation *allocation)
13288 GtkWidgetPrivate *priv;
13290 g_return_if_fail (GTK_IS_WIDGET (widget));
13291 g_return_if_fail (allocation != NULL);
13293 priv = widget->priv;
13295 priv->allocation = *allocation;
13299 * gtk_widget_get_allocated_width:
13300 * @widget: the widget to query
13302 * Returns the width that has currently been allocated to @widget.
13303 * This function is intended to be used when implementing handlers
13304 * for the #GtkWidget::draw function.
13306 * Returns: the width of the @widget
13309 gtk_widget_get_allocated_width (GtkWidget *widget)
13311 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13313 return widget->priv->allocation.width;
13317 * gtk_widget_get_allocated_height:
13318 * @widget: the widget to query
13320 * Returns the height that has currently been allocated to @widget.
13321 * This function is intended to be used when implementing handlers
13322 * for the #GtkWidget::draw function.
13324 * Returns: the height of the @widget
13327 gtk_widget_get_allocated_height (GtkWidget *widget)
13329 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13331 return widget->priv->allocation.height;
13335 * gtk_widget_get_requisition:
13336 * @widget: a #GtkWidget
13337 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13339 * Retrieves the widget's requisition.
13341 * This function should only be used by widget implementations in
13342 * order to figure whether the widget's requisition has actually
13343 * changed after some internal state change (so that they can call
13344 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13346 * Normally, gtk_widget_size_request() should be used.
13350 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13351 * removed, If you need to cache sizes across requests and allocations,
13352 * add an explicit cache to the widget in question instead.
13355 gtk_widget_get_requisition (GtkWidget *widget,
13356 GtkRequisition *requisition)
13358 g_return_if_fail (GTK_IS_WIDGET (widget));
13359 g_return_if_fail (requisition != NULL);
13361 gtk_widget_get_preferred_size (widget, requisition, NULL);
13365 * gtk_widget_set_window:
13366 * @widget: a #GtkWidget
13367 * @window: (transfer full): a #GdkWindow
13369 * Sets a widget's window. This function should only be used in a
13370 * widget's #GtkWidget::realize implementation. The %window passed is
13371 * usually either new window created with gdk_window_new(), or the
13372 * window of its parent widget as returned by
13373 * gtk_widget_get_parent_window().
13375 * Widgets must indicate whether they will create their own #GdkWindow
13376 * by calling gtk_widget_set_has_window(). This is usually done in the
13377 * widget's init() function.
13379 * <note><para>This function does not add any reference to @window.</para></note>
13384 gtk_widget_set_window (GtkWidget *widget,
13387 GtkWidgetPrivate *priv;
13389 g_return_if_fail (GTK_IS_WIDGET (widget));
13390 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13392 priv = widget->priv;
13394 if (priv->window != window)
13396 priv->window = window;
13397 g_object_notify (G_OBJECT (widget), "window");
13402 * gtk_widget_get_window:
13403 * @widget: a #GtkWidget
13405 * Returns the widget's window if it is realized, %NULL otherwise
13407 * Return value: (transfer none): @widget's window.
13412 gtk_widget_get_window (GtkWidget *widget)
13414 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13416 return widget->priv->window;
13420 * gtk_widget_get_support_multidevice:
13421 * @widget: a #GtkWidget
13423 * Returns %TRUE if @widget is multiple pointer aware. See
13424 * gtk_widget_set_support_multidevice() for more information.
13426 * Returns: %TRUE if @widget is multidevice aware.
13429 gtk_widget_get_support_multidevice (GtkWidget *widget)
13431 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13433 return widget->priv->multidevice;
13437 * gtk_widget_set_support_multidevice:
13438 * @widget: a #GtkWidget
13439 * @support_multidevice: %TRUE to support input from multiple devices.
13441 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13442 * @widget will start receiving multiple, per device enter/leave events. Note
13443 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13444 * gdk_window_set_support_multidevice() will have to be called manually on them.
13449 gtk_widget_set_support_multidevice (GtkWidget *widget,
13450 gboolean support_multidevice)
13452 GtkWidgetPrivate *priv;
13454 g_return_if_fail (GTK_IS_WIDGET (widget));
13456 priv = widget->priv;
13457 priv->multidevice = (support_multidevice == TRUE);
13459 if (gtk_widget_get_realized (widget))
13460 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13464 _gtk_widget_set_has_focus (GtkWidget *widget,
13465 gboolean has_focus)
13467 widget->priv->has_focus = has_focus;
13470 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
13472 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
13476 * gtk_widget_send_focus_change:
13477 * @widget: a #GtkWidget
13478 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13480 * Sends the focus change @event to @widget
13482 * This function is not meant to be used by applications. The only time it
13483 * should be used is when it is necessary for a #GtkWidget to assign focus
13484 * to a widget that is semantically owned by the first widget even though
13485 * it's not a direct child - for instance, a search entry in a floating
13486 * window similar to the quick search in #GtkTreeView.
13488 * An example of its usage is:
13491 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13493 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13494 * fevent->focus_change.in = TRUE;
13495 * fevent->focus_change.window = gtk_widget_get_window (widget);
13496 * if (fevent->focus_change.window != NULL)
13497 * g_object_ref (fevent->focus_change.window);
13499 * gtk_widget_send_focus_change (widget, fevent);
13501 * gdk_event_free (event);
13504 * Return value: the return value from the event signal emission: %TRUE
13505 * if the event was handled, and %FALSE otherwise
13510 gtk_widget_send_focus_change (GtkWidget *widget,
13515 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13516 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13518 g_object_ref (widget);
13520 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13522 res = gtk_widget_event (widget, event);
13524 g_object_notify (G_OBJECT (widget), "has-focus");
13526 g_object_unref (widget);
13532 * gtk_widget_in_destruction:
13533 * @widget: a #GtkWidget
13535 * Returns whether the widget is currently being destroyed.
13536 * This information can sometimes be used to avoid doing
13537 * unnecessary work.
13539 * Returns: %TRUE if @widget is being destroyed
13542 gtk_widget_in_destruction (GtkWidget *widget)
13544 return widget->priv->in_destruction;
13548 _gtk_widget_get_resize_pending (GtkWidget *widget)
13550 return widget->priv->resize_pending;
13554 _gtk_widget_set_resize_pending (GtkWidget *widget,
13555 gboolean resize_pending)
13557 widget->priv->resize_pending = resize_pending;
13561 _gtk_widget_get_in_reparent (GtkWidget *widget)
13563 return widget->priv->in_reparent;
13567 _gtk_widget_set_in_reparent (GtkWidget *widget,
13568 gboolean in_reparent)
13570 widget->priv->in_reparent = in_reparent;
13574 _gtk_widget_get_anchored (GtkWidget *widget)
13576 return widget->priv->anchored;
13580 _gtk_widget_set_anchored (GtkWidget *widget,
13583 widget->priv->anchored = anchored;
13587 _gtk_widget_get_shadowed (GtkWidget *widget)
13589 return widget->priv->shadowed;
13593 _gtk_widget_set_shadowed (GtkWidget *widget,
13596 widget->priv->shadowed = shadowed;
13600 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13602 return widget->priv->alloc_needed;
13606 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13607 gboolean alloc_needed)
13609 widget->priv->alloc_needed = alloc_needed;
13613 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13615 return widget->priv->width_request_needed;
13619 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13620 gboolean width_request_needed)
13622 widget->priv->width_request_needed = width_request_needed;
13626 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13628 return widget->priv->height_request_needed;
13632 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13633 gboolean height_request_needed)
13635 widget->priv->height_request_needed = height_request_needed;
13639 _gtk_widget_get_sizegroup_visited (GtkWidget *widget)
13641 return widget->priv->sizegroup_visited;
13645 _gtk_widget_set_sizegroup_visited (GtkWidget *widget,
13648 widget->priv->sizegroup_visited = visited;
13652 _gtk_widget_get_sizegroup_bumping (GtkWidget *widget)
13654 return widget->priv->sizegroup_bumping;
13658 _gtk_widget_set_sizegroup_bumping (GtkWidget *widget,
13661 widget->priv->sizegroup_bumping = bumping;
13665 _gtk_widget_add_sizegroup (GtkWidget *widget,
13670 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13671 groups = g_slist_prepend (groups, group);
13672 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13674 widget->priv->have_size_groups = TRUE;
13678 _gtk_widget_remove_sizegroup (GtkWidget *widget,
13683 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13684 groups = g_slist_remove (groups, group);
13685 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
13687 widget->priv->have_size_groups = groups != NULL;
13691 _gtk_widget_get_sizegroups (GtkWidget *widget)
13693 if (widget->priv->have_size_groups)
13694 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
13700 * gtk_widget_path_append_for_widget:
13701 * @path: a widget path
13702 * @widget: the widget to append to the widget path
13704 * Appends the data from @widget to the widget hierarchy represented
13705 * by @path. This function is a shortcut for adding information from
13706 * @widget to the given @path. This includes setting the name or
13707 * adding the style classes from @widget.
13709 * Returns: the position where the data was inserted
13714 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
13719 g_return_val_if_fail (path != NULL, 0);
13720 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13722 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
13724 if (widget->priv->name)
13725 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
13727 if (widget->priv->context)
13729 GList *classes, *l;
13731 /* Also add any persistent classes in
13732 * the style context the widget path
13734 classes = gtk_style_context_list_classes (widget->priv->context);
13736 for (l = classes; l; l = l->next)
13737 gtk_widget_path_iter_add_class (path, pos, l->data);
13739 g_list_free (classes);
13746 * gtk_widget_get_path:
13747 * @widget: a #GtkWidget
13749 * Returns the #GtkWidgetPath representing @widget, if the widget
13750 * is not connected to a toplevel widget, a partial path will be
13753 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13756 gtk_widget_get_path (GtkWidget *widget)
13758 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13760 /* As strange as it may seem, this may happen on object construction.
13761 * init() implementations of parent types may eventually call this function,
13762 * each with its corresponding GType, which could leave a child
13763 * implementation with a wrong widget type in the widget path
13765 if (widget->priv->path &&
13766 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13768 gtk_widget_path_free (widget->priv->path);
13769 widget->priv->path = NULL;
13772 if (!widget->priv->path)
13776 parent = widget->priv->parent;
13779 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13782 /* Widget is either toplevel or unparented, treat both
13783 * as toplevels style wise, since there are situations
13784 * where style properties might be retrieved on that
13787 widget->priv->path = gtk_widget_path_new ();
13789 gtk_widget_path_append_for_widget (widget->priv->path, widget);
13792 if (widget->priv->context)
13793 gtk_style_context_set_path (widget->priv->context,
13794 widget->priv->path);
13797 return widget->priv->path;
13801 style_context_changed (GtkStyleContext *context,
13802 gpointer user_data)
13804 GtkWidget *widget = user_data;
13806 if (gtk_widget_get_realized (widget))
13807 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13810 /* Compress all style updates so it
13811 * is only emitted once pre-realize.
13813 widget->priv->style_update_pending = TRUE;
13816 if (widget->priv->anchored)
13817 gtk_widget_queue_resize (widget);
13821 * gtk_widget_get_style_context:
13822 * @widget: a #GtkWidget
13824 * Returns the style context associated to @widget.
13826 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13827 * must not be freed.
13830 gtk_widget_get_style_context (GtkWidget *widget)
13832 GtkWidgetPrivate *priv;
13833 GtkWidgetPath *path;
13835 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13837 priv = widget->priv;
13839 /* updates style context if it exists already */
13840 path = gtk_widget_get_path (widget);
13842 if (G_UNLIKELY (priv->context == NULL))
13846 priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13847 "direction", gtk_widget_get_direction (widget),
13850 g_signal_connect (widget->priv->context, "changed",
13851 G_CALLBACK (style_context_changed), widget);
13853 screen = gtk_widget_get_screen (widget);
13856 gtk_style_context_set_screen (priv->context, screen);
13858 gtk_style_context_set_path (priv->context, path);
13861 return widget->priv->context;
13865 * gtk_widget_get_modifier_mask:
13866 * @widget: a #GtkWidget
13867 * @intent: the use case for the modifier mask
13869 * Returns the modifier mask the @widget's windowing system backend
13870 * uses for a particular purpose.
13872 * See gdk_keymap_get_modifier_mask().
13874 * Returns: the modifier mask used for @intent.
13879 gtk_widget_get_modifier_mask (GtkWidget *widget,
13880 GdkModifierIntent intent)
13882 GdkDisplay *display;
13884 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13886 display = gtk_widget_get_display (widget);
13888 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
13893 _gtk_widget_get_style (GtkWidget *widget)
13895 return widget->priv->style;
13899 _gtk_widget_set_style (GtkWidget *widget,
13902 widget->priv->style = style;